Do not share stacks

This commit is contained in:
Devine Lu Linvega 2023-04-11 09:25:31 -07:00
parent bdd6c19576
commit bc055f37b8
3 changed files with 12 additions and 14 deletions

View File

@ -58,11 +58,11 @@ uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
Uint8 *d = &u->dev[0x00]; Uint8 *d = &u->dev[0x00];
Uint16 handler = PEEK2(d); Uint16 handler = PEEK2(d);
if(handler) { if(handler) {
u->wst->ptr = 4; u->wst.ptr = 4;
u->wst->dat[0] = addr >> 0x8; u->wst.dat[0] = addr >> 0x8;
u->wst->dat[1] = addr & 0xff; u->wst.dat[1] = addr & 0xff;
u->wst->dat[2] = instr; u->wst.dat[2] = instr;
u->wst->dat[3] = err; u->wst.dat[3] = err;
return uxn_eval(u, handler); return uxn_eval(u, handler);
} else { } else {
system_inspect(u); system_inspect(u);
@ -74,8 +74,8 @@ uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
void void
system_inspect(Uxn *u) system_inspect(Uxn *u)
{ {
system_print(u->wst, "wst"); system_print(&u->wst, "wst");
system_print(u->rst, "rst"); system_print(&u->rst, "rst");
} }
int int

View File

@ -41,14 +41,14 @@ uxn_eval(Uxn *u, Uint16 pc)
instr = u->ram[pc++]; instr = u->ram[pc++];
opcode = instr & 0x1f; opcode = instr & 0x1f;
/* 2 Mode */ m2 = instr & 0x20; /* 2 Mode */ m2 = instr & 0x20;
/* r Mode */ s = instr & 0x40 ? u->rst : u->wst; /* r Mode */ s = instr & 0x40 ? &u->rst : &u->wst;
/* k Mode */ if(instr & 0x80) { ksp = s->ptr; sp = &ksp; } else sp = &s->ptr; /* k Mode */ if(instr & 0x80) { ksp = s->ptr; sp = &ksp; } else sp = &s->ptr;
switch(opcode - (!opcode * (instr >> 5))) { switch(opcode - (!opcode * (instr >> 5))) {
/* Immediate */ /* Immediate */
case -0x0: /* BRK */ return 1; case -0x0: /* BRK */ return 1;
case -0x1: /* JCI */ POP8(b) if(!b) { pc += 2; break; } case -0x1: /* JCI */ POP8(b) if(!b) { pc += 2; break; }
case -0x2: /* JMI */ PEEK16(a, pc) pc += a + 2; break; case -0x2: /* JMI */ PEEK16(a, pc) pc += a + 2; break;
case -0x3: /* JSI */ s = u->rst; PUSH16(pc + 2) PEEK16(a, pc) pc += a + 2; break; case -0x3: /* JSI */ s = &u->rst; PUSH16(pc + 2) PEEK16(a, pc) pc += a + 2; break;
case -0x4: /* LIT */ case -0x4: /* LIT */
case -0x6: /* LITr */ a = u->ram[pc++]; PUSH8(a) break; case -0x6: /* LITr */ a = u->ram[pc++]; PUSH8(a) break;
case -0x5: /* LIT2 */ case -0x5: /* LIT2 */
@ -67,8 +67,8 @@ uxn_eval(Uxn *u, Uint16 pc)
case 0x0b: /* LTH */ POP(a) POP(b) PUSH8(b < a) break; case 0x0b: /* LTH */ POP(a) POP(b) PUSH8(b < a) break;
case 0x0c: /* JMP */ POP(a) JUMP(a) break; case 0x0c: /* JMP */ POP(a) JUMP(a) break;
case 0x0d: /* JCN */ POP(a) POP8(b) if(b) JUMP(a) break; case 0x0d: /* JCN */ POP(a) POP8(b) if(b) JUMP(a) break;
case 0x0e: /* JSR */ POP(a) s = (instr & 0x40) ? u->wst : u->rst; PUSH16(pc) JUMP(a) break; case 0x0e: /* JSR */ POP(a) s = (instr & 0x40) ? &u->wst : &u->rst; PUSH16(pc) JUMP(a) break;
case 0x0f: /* STH */ POP(a) s = (instr & 0x40) ? u->wst : u->rst; PUSH(a) break; case 0x0f: /* STH */ POP(a) s = (instr & 0x40) ? &u->wst : &u->rst; PUSH(a) break;
case 0x10: /* LDZ */ POP8(a) PEEK(b, a) PUSH(b) break; case 0x10: /* LDZ */ POP8(a) PEEK(b, a) PUSH(b) break;
case 0x11: /* STZ */ POP8(a) POP(b) POKE(a, b) break; case 0x11: /* STZ */ POP8(a) POP(b) POKE(a, b) break;
case 0x12: /* LDR */ POP8(a) PEEK(b, pc + (Sint8)a) PUSH(b) break; case 0x12: /* LDR */ POP8(a) PEEK(b, pc + (Sint8)a) PUSH(b) break;
@ -96,8 +96,6 @@ uxn_boot(Uxn *u, Uint8 *ram)
char *cptr = (char *)u; char *cptr = (char *)u;
for(i = 0; i < sizeof(*u); i++) for(i = 0; i < sizeof(*u); i++)
cptr[i] = 0; cptr[i] = 0;
u->wst = (Stack *)(ram + 0xf0000);
u->rst = (Stack *)(ram + 0xf0100);
u->ram = ram; u->ram = ram;
return 1; return 1;
} }

View File

@ -30,7 +30,7 @@ typedef struct {
typedef struct Uxn { typedef struct Uxn {
Uint8 *ram, dev[256]; Uint8 *ram, dev[256];
Stack *wst, *rst; Stack wst, rst;
Uint8 (*dei)(struct Uxn *u, Uint8 addr); Uint8 (*dei)(struct Uxn *u, Uint8 addr);
void (*deo)(struct Uxn *u, Uint8 addr); void (*deo)(struct Uxn *u, Uint8 addr);
} Uxn; } Uxn;