Make terminal ui binaries work well everywhere

Here's some screenshots of an emulator tui program that was compiled on
Linux, then scp'd it to Windows, Mac, and FreeBSD.

https://justine.storage.googleapis.com/blinkenlights-cmdexe.png
https://justine.storage.googleapis.com/blinkenlights-imac.png
https://justine.storage.googleapis.com/blinkenlights-freebsd.png
https://justine.storage.googleapis.com/blinkenlights-lisp.png

How is this even possible that we have a nontrivial ui binary that just
works on Mac, Windows, Linux, and BSD? Surely a first ever achievement.

Fixed many bugs. Bootstrapped John McCarthy's metacircular evaluator on
bare metal in half the size of Altair BASIC (about 2.5kb) and ran it in
emulator for fun and profit.
This commit is contained in:
Justine Tunney 2020-10-10 21:18:53 -07:00
parent 680daf1210
commit 9e3e985ae5
276 changed files with 7026 additions and 3790 deletions

View file

@ -178,9 +178,9 @@ static long DisAppendOpLines(struct Dis *d, struct Machine *m, int64_t addr) {
void *r;
int64_t ip;
unsigned k;
uint8_t b[15];
struct DisOp op;
long i, n, symbol;
uint8_t *p, b[15];
n = 15;
ip = addr - Read64(m->cs);
if ((symbol = DisFindSym(d, ip)) != -1) {
@ -202,8 +202,9 @@ static long DisAppendOpLines(struct Dis *d, struct Machine *m, int64_t addr) {
if (!(r = FindReal(m, addr))) return -1;
k = 0x1000 - (addr & 0xfff);
if (n <= k) {
memcpy(b, r, n);
p = r;
} else {
p = b;
memcpy(b, r, k);
if ((r = FindReal(m, addr + k))) {
memcpy(b + k, r, n - k);
@ -212,7 +213,7 @@ static long DisAppendOpLines(struct Dis *d, struct Machine *m, int64_t addr) {
}
}
xed_decoded_inst_zero_set_mode(d->xedd, m->mode);
xed_instruction_length_decode(d->xedd, b, n);
xed_instruction_length_decode(d->xedd, p, n);
n = d->xedd->op.error ? 1 : d->xedd->length;
op.addr = addr;
op.size = n;
@ -240,7 +241,6 @@ long Dis(struct Dis *d, struct Machine *m, uint64_t addr, uint64_t ip,
}
const char *DisGetLine(struct Dis *d, struct Machine *m, size_t i) {
char *p;
void *r[2];
uint8_t b[15];
if (i >= d->ops.i) return "";
@ -250,10 +250,9 @@ const char *DisGetLine(struct Dis *d, struct Machine *m, size_t i) {
xed_instruction_length_decode(
d->xedd, AccessRam(m, d->ops.p[i].addr, d->ops.p[i].size, r, b, true),
d->ops.p[i].size);
d->addr = d->ops.p[i].addr;
d->m = m;
p = DisLineCode(d, d->buf);
CHECK_LT(p - d->buf, sizeof(d->buf));
d->addr = d->ops.p[i].addr;
CHECK_LT(DisLineCode(d, d->buf) - d->buf, sizeof(d->buf));
return d->buf;
}