commit 05d6556
Devine Lu Linvega
·
2026-01-07 16:57:22 +0000 UTC
parent 6761181
(core) Opt
1 files changed,
+40,
-39
+40,
-39
1@@ -41,54 +41,55 @@ static Window window;
2 #define PEEK2(d) (*(d) << 8 | (d)[1])
3 #define NEXT if(--cycles) goto step; else return 0;
4
5-#define OPC(opc, A, B) {\
6- case 0x00|opc: {const int _2=0,_r=0;A B;} NEXT\
7- case 0x20|opc: {const int _2=1,_r=0;A B;} NEXT\
8- case 0x40|opc: {const int _2=0,_r=1;A B;} NEXT\
9- case 0x60|opc: {const int _2=1,_r=1;A B;} NEXT\
10- case 0x80|opc: {const int _2=0,_r=0;int k=ptr[0];A ptr[0]=k;B;} NEXT\
11- case 0xa0|opc: {const int _2=1,_r=0;int k=ptr[0];A ptr[0]=k;B;} NEXT\
12- case 0xc0|opc: {const int _2=0,_r=1;int k=ptr[1];A ptr[1]=k;B;} NEXT\
13- case 0xe0|opc: {const int _2=1,_r=1;int k=ptr[1];A ptr[1]=k;B;} NEXT\
14-}
15+Uint8 *ram, dev[0x100], ptr[2], stk[2][0x100], emu_dei(const Uint8 port);
16+void emu_deo(const Uint8 port, const Uint8 value);
17
18-#define REM ptr[_r] -= 1 + _2;
19-#define DEC(m) stk[m][--ptr[m]]
20-#define INC(m) stk[m][ptr[m]++]
21-#define IMM(r) { r = ram[pc++] << 8, r |= ram[pc++]; }
22-#define MOV(x) { if(_2) pc = x; else pc += (signed char)x; }
23-#define PO1(o) o = DEC(_r);
24-#define PO2(o) { o = DEC(_r), o |= DEC(_r) << 8; }
25-#define POx(o) if(_2) PO2(o) else PO1(o)
26+#define REM *sp -= 1 + _2;
27+#define DEC s[--(*sp)]
28+#define INC s[(*sp)++]
29+#define MOV { if(_2) pc = a; else pc += (signed char)a; }
30+#define JMP(x) { c = ram[pc] << 8, c |= ram[pc+1]; pc += x + 2; }
31+#define STK(m) Uint8 *s = stk[m], *sp = &ptr[m];
32+#define PO1(o) o = DEC;
33+#define PO2(o) { PO1(o) o |= DEC << 8; }
34+#define POx(o) { PO1(o) if(_2) o |= DEC << 8; }
35+#define RP1(i) stk[!_r][ptr[!_r]++] = i;
36+#define PU1(i) INC = i;
37+#define PUx(i) c = (i); if(_2) PU1(c >> 8) PU1(c)
38 #define GOT(o) if(_2) PO1(o[1]) PO1(o[0])
39-#define DEO(o,r) emu_deo(o, r[0]); if(_2) emu_deo(o + 1, r[1]);
40-#define POK(o,r,m) ram[o] = r[0]; if(_2) ram[(o + 1) & m] = r[1];
41-#define RP1(i) INC(!_r) = i;
42-#define PU1(i) INC(_r) = i;
43-#define PUx(i) if(_2) { c = (i); PU1(c >> 8) PU1(c) } else PU1(i)
44 #define PUT(i) PU1(i[0]) if(_2) PU1(i[1])
45+#define DEO(o,r) emu_deo(o, r[0]); if(_2) emu_deo(o + 1, r[1]);
46 #define DEI(i,r) r[0] = emu_dei(i); if(_2) r[1] = emu_dei(i + 1); PUT(r)
47+#define POK(o,r,m) ram[o] = r[0]; if(_2) ram[(o + 1) & m] = r[1];
48 #define PEK(i,r,m) r[0] = ram[i]; if(_2) r[1] = ram[(i + 1) & m]; PUT(r)
49
50-Uint8 *ram, dev[0x100], ptr[2], stk[2][0x100], emu_dei(const Uint8 port);
51-void emu_deo(const Uint8 port, const Uint8 value);
52+#define OPC(opc, A, B) {\
53+ case 0x00|opc: {const int _2=0,_r=0;STK(_r)A B} goto step;\
54+ case 0x20|opc: {const int _2=1,_r=0;STK(_r)A B} goto step;\
55+ case 0x40|opc: {const int _2=0,_r=1;STK(_r)A B} goto step;\
56+ case 0x60|opc: {const int _2=1,_r=1;STK(_r)A B} goto step;\
57+ case 0x80|opc: {const int _2=0,_r=0;STK(_r)int k=*sp;A *sp=k;B} goto step;\
58+ case 0xa0|opc: {const int _2=1,_r=0;STK(_r)int k=*sp;A *sp=k;B} goto step;\
59+ case 0xc0|opc: {const int _2=0,_r=1;STK(_r)int k=*sp;A *sp=k;B} goto step;\
60+ case 0xe0|opc: {const int _2=1,_r=1;STK(_r)int k=*sp;A *sp=k;B} goto step; }
61+
62
63-unsigned int
64+static unsigned int
65 uxn_eval(Uint16 pc)
66 {
67- unsigned int a, b, c, x[2], y[2], z[2], cycles = 0x80000000;
68+ Uint16 a, b, c, x[2], y[2], z[2];
69 step:
70 switch(ram[pc++]) {
71 /* BRK */ case 0x00: return 1;
72- /* JCI */ case 0x20: if(DEC(0)) { IMM(c) pc += c; } else pc += 2; NEXT
73- /* JMI */ case 0x40: IMM(c) pc += c; NEXT
74- /* JSI */ case 0x60: IMM(c) INC(1) = pc >> 8, INC(1) = pc, pc += c; NEXT
75- /* LI2 */ case 0xa0: INC(0) = ram[pc++]; /* fall-through */
76- /* LIT */ case 0x80: INC(0) = ram[pc++]; NEXT
77- /* L2r */ case 0xe0: INC(1) = ram[pc++]; /* fall-through */
78- /* LIr */ case 0xc0: INC(1) = ram[pc++]; NEXT
79+ /* JCI */ case 0x20: if(stk[0][--ptr[0]]) JMP(c) else pc += 2; goto step;
80+ /* JMI */ case 0x40: JMP(c) goto step;
81+ /* JSI */ case 0x60: { STK(1) JMP(0) INC = pc >> 8; INC = pc; pc += c; } goto step;
82+ /* LI2 */ case 0xa0: { STK(0) INC = ram[pc++]; INC = ram[pc++]; } goto step;
83+ /* LIT */ case 0x80: { stk[0][ptr[0]++] = ram[pc++]; } goto step;
84+ /* L2r */ case 0xe0: { STK(1) INC = ram[pc++]; INC = ram[pc++]; } goto step;
85+ /* LIr */ case 0xc0: { stk[1][ptr[1]++] = ram[pc++]; } goto step;
86 /* INC */ OPC(0x01,POx(a),PUx(a + 1))
87- /* POP */ OPC(0x02,REM,{})
88+ /* POP */ OPC(0x02,REM,(void)s;)
89 /* NIP */ OPC(0x03,GOT(x) REM,PUT(x))
90 /* SWP */ OPC(0x04,GOT(x) GOT(y),PUT(x) PUT(y))
91 /* ROT */ OPC(0x05,GOT(x) GOT(y) GOT(z),PUT(y) PUT(x) PUT(z))
92@@ -98,9 +99,9 @@ step:
93 /* NEQ */ OPC(0x09,POx(a) POx(b),PU1(b != a))
94 /* GTH */ OPC(0x0a,POx(a) POx(b),PU1(b > a))
95 /* LTH */ OPC(0x0b,POx(a) POx(b),PU1(b < a))
96- /* JMP */ OPC(0x0c,POx(a),MOV(a))
97- /* JCN */ OPC(0x0d,POx(a) PO1(b),if(b) MOV(a))
98- /* JSR */ OPC(0x0e,POx(a),RP1(pc >> 8) RP1(pc) MOV(a))
99+ /* JMP */ OPC(0x0c,POx(a),MOV)
100+ /* JCN */ OPC(0x0d,POx(a) PO1(b),if(b) MOV)
101+ /* JSR */ OPC(0x0e,POx(a),RP1(pc >> 8) RP1(pc) MOV)
102 /* STH */ OPC(0x0f,GOT(x),RP1(x[0]) if(_2) RP1(x[1]))
103 /* LDZ */ OPC(0x10,PO1(a),PEK(a, x, 0xff))
104 /* STZ */ OPC(0x11,PO1(a) GOT(y),POK(a, y, 0xff))
105@@ -1268,7 +1269,7 @@ main(int argc, char **argv)
106 {
107 int i = 1;
108 if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
109- return !fprintf(stdout, "%s - Varvara Emulator, 3 Jan 2026.\n", argv[0]);
110+ return !fprintf(stdout, "%s - Varvara Emulator, 7 Jan 2026.\n", argv[0]);
111 else if(argc == 1)
112 return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
113 else if(!system_boot(argv[i++], argc > 2))