Browse code

Made the uxn stacks private again

Devine Lu Linvega authored on 11/04/2023 17:14:29
Showing 3 changed files
... ...
@@ -48,8 +48,8 @@ system_cmd(Uint8 *ram, Uint16 addr)
48 48
 void
49 49
 system_inspect(Uxn *u)
50 50
 {
51
-	system_print(u->wst, "wst");
52
-	system_print(u->rst, "rst");
51
+	system_print(&u->wst, "wst");
52
+	system_print(&u->rst, "rst");
53 53
 }
54 54
 
55 55
 int
... ...
@@ -89,11 +89,11 @@ uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
89 89
 	Uint8 *d = &u->dev[0x00];
90 90
 	Uint16 handler = PEEK2(d);
91 91
 	if(handler) {
92
-		u->wst->ptr = 4;
93
-		u->wst->dat[0] = addr >> 0x8;
94
-		u->wst->dat[1] = addr & 0xff;
95
-		u->wst->dat[2] = instr;
96
-		u->wst->dat[3] = err;
92
+		u->wst.ptr = 4;
93
+		u->wst.dat[0] = addr >> 0x8;
94
+		u->wst.dat[1] = addr & 0xff;
95
+		u->wst.dat[2] = instr;
96
+		u->wst.dat[3] = err;
97 97
 		return uxn_eval(u, handler);
98 98
 	} else {
99 99
 		system_inspect(u);
... ...
@@ -31,8 +31,8 @@ WITH REGARD TO THIS SOFTWARE.
31 31
 #define SET(mul, add) { if(mul > s->ptr) HALT(1) tmp = s->ptr + k * mul + add; if(tmp > 254) HALT(2) s->ptr = tmp; }
32 32
 #define PUT(o, v) { s->dat[(Uint8)(s->ptr - 1 - (o))] = (v); }
33 33
 #define PUT2(o, v) { tmp = (v); s->dat[(Uint8)(s->ptr - o - 2)] = tmp >> 8; s->dat[(Uint8)(s->ptr - o - 1)] = tmp; }
34
-#define PUSH(stack, v) { if(s->ptr > 254) HALT(2) stack->dat[stack->ptr++] = (v); }
35
-#define PUSH2(stack, v) { if(s->ptr > 253) HALT(2) tmp = (v); stack->dat[stack->ptr] = tmp >> 8; stack->dat[stack->ptr + 1] = tmp; stack->ptr += 2; }
34
+#define PUSH(stack, v) { if((stack)->ptr > 254) HALT(2) (stack)->dat[(stack)->ptr++] = (v); }
35
+#define PUSH2(stack, v) { if((stack)->ptr > 253) HALT(2) tmp = (v); (stack)->dat[(stack)->ptr] = tmp >> 8; (stack)->dat[(stack)->ptr + 1] = tmp; (stack)->ptr += 2; }
36 36
 #define DEO(a, b) { u->dev[(a)] = (b); if((deo_mask[(a) >> 4] >> ((a) & 0xf)) & 0x1) uxn_deo(u, (a)); }
37 37
 #define DEI(a, b) { PUT((a), ((dei_mask[(b) >> 4] >> ((b) & 0xf)) & 0x1) ? uxn_dei(u, (b)) : u->dev[(b)])  }
38 38
 
... ...
@@ -46,14 +46,14 @@ uxn_eval(Uxn *u, Uint16 pc)
46 46
 	for(;;) {
47 47
 		ins = u->ram[pc++];
48 48
 		k = !!(ins & 0x80);
49
-		s = ins & 0x40 ? u->rst : u->wst;
49
+		s = ins & 0x40 ? &u->rst : &u->wst;
50 50
 		opc = !(ins & 0x1f) ? 0 - (ins >> 5) : ins & 0x3f;
51 51
 		switch(opc) {
52 52
 			/* IMM */
53 53
 			case 0x00: /* BRK   */ return 1;
54 54
 			case 0xff: /* JCI   */ pc += !!s->dat[--s->ptr] * PEEK2(u->ram + pc) + 2; break;
55 55
 			case 0xfe: /* JMI   */ pc += PEEK2(u->ram + pc) + 2; break;
56
-			case 0xfd: /* JSI   */ PUSH2(u->rst, pc + 2) pc += PEEK2(u->ram + pc) + 2; break;
56
+			case 0xfd: /* JSI   */ PUSH2(&u->rst, pc + 2) pc += PEEK2(u->ram + pc) + 2; break;
57 57
 			case 0xfc: /* LIT   */ PUSH(s, u->ram[pc++]) break;
58 58
 			case 0xfb: /* LIT2  */ PUSH2(s, PEEK2(u->ram + pc)) pc += 2; break;
59 59
 			case 0xfa: /* LITr  */ PUSH(s, u->ram[pc++]) break;
... ...
@@ -72,8 +72,8 @@ uxn_eval(Uxn *u, Uint16 pc)
72 72
 			case 0x0b: /* LTH  */ t=T;n=N;     SET(2,-1) PUT(0, n < t) break;                           case 0x2b: t=T2;n=N2;      SET(4,-3) PUT(0, n < t) break;
73 73
 			case 0x0c: /* JMP  */ t=T;         SET(1,-1) pc += (Sint8)t; break;                         case 0x2c: t=T2;           SET(2,-2) pc = t; break;
74 74
 			case 0x0d: /* JCN  */ t=T;n=N;     SET(2,-2) pc += !!n * (Sint8)t; break;                   case 0x2d: t=T2;n=L;       SET(3,-3) if(n) pc = t; break;
75
-			case 0x0e: /* JSR  */ t=T;         SET(1,-1) PUSH2(u->rst, pc) pc += (Sint8)t; break;       case 0x2e: t=T2;           SET(2,-2) PUSH2(u->rst, pc) pc = t; break;
76
-			case 0x0f: /* STH  */ t=T;         SET(1,-1) PUSH((ins & 0x40 ? u->wst : u->rst), t) break; case 0x2f: t=T2;           SET(2,-2) PUSH2((ins & 0x40 ? u->wst : u->rst), t) break;
75
+			case 0x0e: /* JSR  */ t=T;         SET(1,-1) PUSH2(&u->rst, pc) pc += (Sint8)t; break;       case 0x2e: t=T2;           SET(2,-2) PUSH2(&u->rst, pc) pc = t; break;
76
+			case 0x0f: /* STH  */ t=T;         SET(1,-1) PUSH((ins & 0x40 ? &u->wst : &u->rst), t) break; case 0x2f: t=T2;           SET(2,-2) PUSH2((ins & 0x40 ? &u->wst : &u->rst), t) break;
77 77
 			case 0x10: /* LDZ  */ t=T;         SET(1, 0) PUT(0, u->ram[t]) break;                       case 0x30: t=T;            SET(1, 1) PUT2(0, PEEK2(u->ram + t)) break;
78 78
 			case 0x11: /* STZ  */ t=T;n=N;     SET(2,-2) u->ram[t] = n; break;                          case 0x31: t=T;n=H2;       SET(3,-3) POKE2(u->ram + t, n) break;
79 79
 			case 0x12: /* LDR  */ t=T;         SET(1, 0) PUT(0, u->ram[pc + (Sint8)t]) break;           case 0x32: t=T;            SET(1, 1) PUT2(0, PEEK2(u->ram + pc + (Sint8)t)) break;
... ...
@@ -101,8 +101,6 @@ uxn_boot(Uxn *u, Uint8 *ram)
101 101
 	char *cptr = (char *)u;
102 102
 	for(i = 0; i < sizeof(*u); i++)
103 103
 		cptr[i] = 0;
104
-	u->wst = (Stack *)(ram + 0xf0000);
105
-	u->rst = (Stack *)(ram + 0xf0100);
106 104
 	u->ram = ram;
107 105
 	return 1;
108 106
 }
... ...
@@ -30,7 +30,7 @@ typedef struct {
30 30
 
31 31
 typedef struct Uxn {
32 32
 	Uint8 *ram, dev[256];
33
-	Stack *wst, *rst;
33
+	Stack wst, rst;
34 34
 	Uint8 (*dei)(struct Uxn *u, Uint8 addr);
35 35
 	void (*deo)(struct Uxn *u, Uint8 addr);
36 36
 } Uxn;