commit 73eb4ab
Devine Lu Linvega
·
2026-01-21 18:11:41 +0000 UTC
parent 8612695
Removed PUr and STK macros
1 files changed,
+25,
-26
+25,
-26
1@@ -1034,47 +1034,47 @@ emu_deo(const Uint8 port, const Uint8 value)
2 #define REM *p -= 1 + _2;
3 #define DEC s[--(*p)]
4 #define INC s[(*p)++]
5+#define INV { s = stk[!r], p = &ptr[!r]; }
6 #define MOV { if(_2) pc = a; else pc += (signed char)a; }
7 #define JMP(x) { c = ram[pc] << 8, c |= ram[pc + 1]; pc += x + 2; }
8-#define STK(m) Uint8 *s = stk[m], *p = &ptr[m];
9-#define PO1(o) o = DEC;
10+#define PO1(o) o = s[--(*p)];
11 #define PO2(o) { PO1(o) o |= DEC << 8; }
12 #define POx(o) { PO1(o) if(_2) o |= DEC << 8; }
13 #define POt(o) if(_2) PO1(o[1]) PO1(o[0])
14-#define PU1(i) INC = i;
15+#define PU1(i) s[(*p)++] = i;
16 #define PU2(i) PU1(i >> 8) PU1(i)
17 #define PUx(i) c = (i); if(_2) PU1(c >> 8) PU1(c)
18 #define PUt(i) PU1(i[0]) if(_2) PU1(i[1])
19-#define PUr(i) stk[!_r][ptr[!_r]++] = i;
20 #define DEO(o,r) emu_deo(o, r[0]); if(_2) emu_deo(o + 1, r[1]);
21 #define DEI(i,r) r[0] = emu_dei(i); if(_2) r[1] = emu_dei(i + 1);
22 #define POK(o,r,m) ram[o] = r[0]; if(_2) ram[(o + 1) & m] = r[1];
23 #define PEK(i,r,m) r[0] = ram[i]; if(_2) r[1] = ram[(i + 1) & m];
24
25 #define OPC(opc, A, B) {\
26- case 0x00|opc: {const int _2=0,_r=0;STK(_r)A B} goto step;\
27- case 0x20|opc: {const int _2=1,_r=0;STK(_r)A B} goto step;\
28- case 0x40|opc: {const int _2=0,_r=1;STK(_r)A B} goto step;\
29- case 0x60|opc: {const int _2=1,_r=1;STK(_r)A B} goto step;\
30- case 0x80|opc: {const int _2=0,_r=0;STK(_r)int k=*p; A *p=k;B} goto step;\
31- case 0xa0|opc: {const int _2=1,_r=0;STK(_r)int k=*p; A *p=k;B} goto step;\
32- case 0xc0|opc: {const int _2=0,_r=1;STK(_r)int k=*p; A *p=k;B} goto step;\
33- case 0xe0|opc: {const int _2=1,_r=1;STK(_r)int k=*p; A *p=k;B} goto step;}
34-
35-static unsigned int
36+ case 0x00|opc: {const int _2=0;A B} goto step;\
37+ case 0x20|opc: {const int _2=1;A B} goto step;\
38+ case 0x40|opc: {const int _2=0;A B} goto step;\
39+ case 0x60|opc: {const int _2=1;A B} goto step;\
40+ case 0x80|opc: {const int _2=0;int k=*p; A *p=k;B} goto step;\
41+ case 0xa0|opc: {const int _2=1;int k=*p; A *p=k;B} goto step;\
42+ case 0xc0|opc: {const int _2=0;int k=*p; A *p=k;B} goto step;\
43+ case 0xe0|opc: {const int _2=1;int k=*p; A *p=k;B} goto step;}
44+
45+static unsigned
46 uxn_eval(Uint16 pc)
47 {
48 Uint16 a, b, c, x[2], y[2], z[2];
49-step:
50- switch(ram[pc++]) {
51+step: {
52+ Uint8 op = ram[pc++], r = (op >> 6) & 1, *s = stk[r], *p = &ptr[r];
53+ switch(op) {
54 /* BRK */ case 0x00: return 1;
55 /* JCI */ case 0x20: if(stk[0][--ptr[0]]) JMP(c) else pc += 2; goto step;
56 /* JMI */ case 0x40: JMP(c) goto step;
57- /* JSI */ case 0x60: { STK(1) JMP(0) PU2(pc) pc += c; } goto step;
58- /* LI2 */ case 0xa0: { STK(0) INC = ram[pc++]; INC = ram[pc++]; } goto step;
59- /* LIT */ case 0x80: { stk[0][ptr[0]++] = ram[pc++]; } goto step;
60- /* L2r */ case 0xe0: { STK(1) INC = ram[pc++]; INC = ram[pc++]; } goto step;
61- /* LIr */ case 0xc0: { stk[1][ptr[1]++] = ram[pc++]; } goto step;
62+ /* JSI */ case 0x60: { JMP(0) PU2(pc) pc += c; } goto step;
63+ /* LI2 */ case 0xa0: INC = ram[pc++]; /* fall through */
64+ /* LIT */ case 0x80: INC = ram[pc++]; goto step;
65+ /* L2r */ case 0xe0: INC = ram[pc++]; /* fall through */
66+ /* LIr */ case 0xc0: INC = ram[pc++]; goto step;
67 /* INC */ OPC(0x01,POx(a),PUx(a + 1))
68 /* POP */ OPC(0x02,REM,(void)s;)
69 /* NIP */ OPC(0x03,POt(x) REM,PUt(x))
70@@ -1088,8 +1088,8 @@ step:
71 /* LTH */ OPC(0x0b,POx(a) POx(b),PU1(b < a))
72 /* JMP */ OPC(0x0c,POx(a),MOV)
73 /* JCN */ OPC(0x0d,POx(a) PO1(b),if(b) MOV)
74- /* JSR */ OPC(0x0e,POx(a),PUr(pc >> 8) PUr(pc) MOV)
75- /* STH */ OPC(0x0f,POt(x),PUr(x[0]) if(_2) PUr(x[1]))
76+ /* JSR */ OPC(0x0e,POx(a),INV PU1(pc >> 8) PU1(pc) MOV)
77+ /* STH */ OPC(0x0f,POt(x),INV PU1(x[0]) if(_2) PU1(x[1]))
78 /* LDZ */ OPC(0x10,PO1(a),PEK(a, x, 0xff) PUt(x))
79 /* STZ */ OPC(0x11,PO1(a) POt(y),POK(a, y, 0xff))
80 /* LDR */ OPC(0x12,PO1(a),PEK(pc + (signed char)a, x, 0xffff) PUt(x))
81@@ -1106,8 +1106,7 @@ step:
82 /* ORA */ OPC(0x1d,POx(a) POx(b),PUx(b | a))
83 /* EOR */ OPC(0x1e,POx(a) POx(b),PUx(b ^ a))
84 /* SFT */ OPC(0x1f,PO1(a) POx(b),PUx(b >> (a & 0xf) << (a >> 4)))
85- }
86- return 0;
87+ }} return 0;
88 }
89
90 /* clang-format on */
91@@ -1320,7 +1319,7 @@ main(int argc, char **argv)
92 {
93 int i = 1;
94 if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
95- return !fprintf(stdout, "%s - Varvara Emulator, 20 Jan 2026.\n", argv[0]);
96+ return !fprintf(stdout, "%s - Varvara Emulator, 21 Jan 2026.\n", argv[0]);
97 else if(argc == 1)
98 return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
99 else if(!system_boot(argv[i++], argc > 2))