From f2029445665a21d113c054748cbd5c1c11814f26 Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Thu, 12 Jan 2023 13:22:21 +0000 Subject: [PATCH] Make JMI, JCI and JSI relative. --- src/uxn.c | 6 +++--- src/uxnasm.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/uxn.c b/src/uxn.c index 444a06d..1d1b12f 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -50,9 +50,9 @@ uxn_eval(Uxn *u, Uint16 pc) switch(opcode - (!opcode * (instr >> 5))) { /* Literals/Calls */ case -0x0: /* BRK */ return 1; - case -0x1: /* JMI */ PEEK16(a, pc) pc = a; break; - case -0x2: /* JCI */ sp = &u->wst->ptr; src = u->wst; POP8(b) if(b) { PEEK16(a, pc) pc = a; } else pc += 2; break; - case -0x3: /* JSI */ PUSH16(u->rst, pc + 2) PEEK16(a, pc) pc = a; break; + case -0x1: /* JMI */ PEEK16(a, pc) pc += a + 2; break; + case -0x2: /* JCI */ sp = &u->wst->ptr; src = u->wst; POP8(b) if(b) { PEEK16(a, pc) pc += a + 2; } else pc += 2; break; + case -0x3: /* JSI */ PUSH16(u->rst, pc + 2) PEEK16(a, pc) pc += a + 2; break; case -0x4: /* LIT */ case -0x6: /* LITr */ a = u->ram[pc++]; PUSH8(src, a) break; case -0x5: /* LIT2 */ diff --git a/src/uxnasm.c b/src/uxnasm.c index f97d2a1..68718bb 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -360,6 +360,7 @@ resolve(void) { Label *l; int i; + Uint16 a; for(i = 0; i < p.rlen; i++) { Reference *r = &p.refs[i]; switch(r->rune) { @@ -382,13 +383,20 @@ resolve(void) case ':': case '=': case ';': + if(!(l = findlabel(r->name))) + return error("Unknown absolute reference", r->name); + p.data[r->addr] = l->addr >> 0x8; + p.data[r->addr + 1] = l->addr & 0xff; + l->refs++; + break; case '?': case '!': default: if(!(l = findlabel(r->name))) return error("Unknown absolute reference", r->name); - p.data[r->addr] = l->addr >> 0x8; - p.data[r->addr + 1] = l->addr & 0xff; + a = l->addr - r->addr - 2; + p.data[r->addr] = a >> 0x8; + p.data[r->addr + 1] = a & 0xff; l->refs++; break; }