Make JMI, JCI and JSI relative.

This commit is contained in:
Andrew Alderwick 2023-01-12 13:22:21 +00:00
parent 7490666878
commit f202944566
2 changed files with 13 additions and 5 deletions

View File

@ -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 */

View File

@ -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;
}