commit 9b9392e

Devine Lu Linvega  ·  2024-11-14 23:31:10 +0000 UTC
parent 62c1433
(uxncli) Removed core indirections
3 files changed,  +34, -35
+3, -3
 1@@ -125,21 +125,21 @@ system_deo(Uxn *u, Uint8 port)
 2 			Uint8 value = u->ram[addr + 7];
 3 			Uint16 i, length = PEEK2(u->ram + addr + 1);
 4 			Uint16 dst_page = PEEK2(u->ram + addr + 3), dst_addr = PEEK2(u->ram + addr + 5);
 5-			int dst = (dst_page % (RAM_PAGES+1)) * 0x10000;
 6+			int dst = (dst_page % (RAM_PAGES + 1)) * 0x10000;
 7 			for(i = 0; i < length; i++)
 8 				uxn.ram[dst + (Uint16)(dst_addr + i)] = value;
 9 		} else if(u->ram[addr] == 0x1) {
10 			Uint16 i, length = PEEK2(u->ram + addr + 1);
11 			Uint16 a_page = PEEK2(u->ram + addr + 3), a_addr = PEEK2(u->ram + addr + 5);
12 			Uint16 b_page = PEEK2(u->ram + addr + 7), b_addr = PEEK2(u->ram + addr + 9);
13-			int src = (a_page % (RAM_PAGES+1)) * 0x10000, dst = (b_page % (RAM_PAGES+1)) * 0x10000;
14+			int src = (a_page % (RAM_PAGES + 1)) * 0x10000, dst = (b_page % (RAM_PAGES + 1)) * 0x10000;
15 			for(i = 0; i < length; i++)
16 				uxn.ram[dst + (Uint16)(b_addr + i)] = uxn.ram[src + (Uint16)(a_addr + i)];
17 		} else if(u->ram[addr] == 0x2) {
18 			Uint16 i, length = PEEK2(u->ram + addr + 1);
19 			Uint16 a_page = PEEK2(u->ram + addr + 3), a_addr = PEEK2(u->ram + addr + 5);
20 			Uint16 b_page = PEEK2(u->ram + addr + 7), b_addr = PEEK2(u->ram + addr + 9);
21-			int src = (a_page % (RAM_PAGES+1)) * 0x10000, dst = (b_page % (RAM_PAGES+1)) * 0x10000;
22+			int src = (a_page % (RAM_PAGES + 1)) * 0x10000, dst = (b_page % (RAM_PAGES + 1)) * 0x10000;
23 			for(i = length - 1; i != 0xffff; i--)
24 				uxn.ram[dst + (Uint16)(b_addr + i)] = uxn.ram[src + (Uint16)(a_addr + i)];
25 		} else
+2, -2
 1@@ -17,8 +17,8 @@ void system_inspect(void);
 2 int system_error(char *msg, const char *err);
 3 int system_boot(Uint8 *ram, char *rom);
 4 
 5-Uint8 system_dei(Uxn*u,Uint8 addr);
 6-void system_deo(Uxn*u,Uint8 addr);
 7+Uint8 system_dei(Uxn *u, Uint8 addr);
 8+void system_deo(Uxn *u, Uint8 addr);
 9 
10 extern char *boot_rom;
11 extern Uxn bios;
+29, -30
  1@@ -34,7 +34,7 @@ typedef struct {
  2 	Uint8 dat[0x100], ptr;
  3 } Stack;
  4 
  5-typedef struct Uxn {
  6+typedef struct {
  7 	Uint8 *ram, dev[0x100];
  8 	Stack wst, rst;
  9 } Uxn;
 10@@ -44,8 +44,8 @@ typedef struct Uxn {
 11 */
 12 
 13 Uxn uxn;
 14-Uint8 emu_dei(Uxn *u, Uint8 addr);
 15-void emu_deo(Uxn *u, Uint8 addr, Uint8 value);
 16+Uint8 emu_dei(Uint8 addr);
 17+void emu_deo(Uint8 addr, Uint8 value);
 18 
 19 /* clang-format off */
 20 
 21@@ -57,16 +57,16 @@ void emu_deo(Uxn *u, Uint8 addr, Uint8 value);
 22 	case 0x20|opc: {const int _2=1,_r=0;init body;} break;\
 23 	case 0x40|opc: {const int _2=0,_r=1;init body;} break;\
 24 	case 0x60|opc: {const int _2=1,_r=1;init body;} break;\
 25-	case 0x80|opc: {const int _2=0,_r=0,k=u->wst.ptr;init u->wst.ptr=k;body;} break;\
 26-	case 0xa0|opc: {const int _2=1,_r=0,k=u->wst.ptr;init u->wst.ptr=k;body;} break;\
 27-	case 0xc0|opc: {const int _2=0,_r=1,k=u->rst.ptr;init u->rst.ptr=k;body;} break;\
 28-	case 0xe0|opc: {const int _2=1,_r=1,k=u->rst.ptr;init u->rst.ptr=k;body;} break;\
 29+	case 0x80|opc: {const int _2=0,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\
 30+	case 0xa0|opc: {const int _2=1,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\
 31+	case 0xc0|opc: {const int _2=0,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\
 32+	case 0xe0|opc: {const int _2=1,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\
 33 }
 34 
 35-#define JMI a = u->ram[pc] << 8 | u->ram[pc + 1], pc += a + 2;
 36-#define REM if(_r) u->rst.ptr -= 1 + _2; else u->wst.ptr -= 1 + _2;
 37-#define INC(s) u->s.dat[u->s.ptr++]
 38-#define DEC(s) u->s.dat[--u->s.ptr]
 39+#define JMI a = uxn.ram[pc] << 8 | uxn.ram[pc + 1], pc += a + 2;
 40+#define REM if(_r) uxn.rst.ptr -= 1 + _2; else uxn.wst.ptr -= 1 + _2;
 41+#define INC(s) uxn.s.dat[uxn.s.ptr++]
 42+#define DEC(s) uxn.s.dat[--uxn.s.ptr]
 43 #define JMP(i) pc = _2 ? i : pc + (Sint8)i;
 44 #define PO1(o) o = _r ? DEC(rst) : DEC(wst);
 45 #define PO2(o) o = _r ? DEC(rst) | DEC(rst) << 8 : DEC(wst) | DEC(wst) << 8;
 46@@ -76,26 +76,26 @@ void emu_deo(Uxn *u, Uint8 addr, Uint8 value);
 47 #define PUx(i) { if(_2) { c = (i); PU1(c >> 8) PU1(c) } else PU1(i) }
 48 #define GET(o) { if(_2) PO1(o[1]) PO1(o[0]) }
 49 #define PUT(i) { PU1(i[0]) if(_2) PU1(i[1]) }
 50-#define DEI(i,o) o[0] = emu_dei(u, i); if(_2) o[1] = emu_dei(u, i + 1); PUT(o)
 51-#define DEO(i,j) emu_deo(u, i, j[0]); if(_2) emu_deo(u, i + 1, j[1]);
 52-#define PEK(i,o,m) o[0] = u->ram[i]; if(_2) o[1] = u->ram[(i + 1) & m]; PUT(o)
 53-#define POK(i,j,m) u->ram[i] = j[0]; if(_2) u->ram[(i + 1) & m] = j[1];
 54+#define DEI(i,o) o[0] = emu_dei(i); if(_2) o[1] = emu_dei(i + 1); PUT(o)
 55+#define DEO(i,j) emu_deo(i, j[0]); if(_2) emu_deo(i + 1, j[1]);
 56+#define PEK(i,o,m) o[0] = uxn.ram[i]; if(_2) o[1] = uxn.ram[(i + 1) & m]; PUT(o)
 57+#define POK(i,j,m) uxn.ram[i] = j[0]; if(_2) uxn.ram[(i + 1) & m] = j[1];
 58 
 59 int
 60-uxn_eval(Uxn *u, Uint16 pc)
 61+uxn_eval(Uint16 pc)
 62 {
 63 	unsigned int a, b, c, x[2], y[2], z[2], step;
 64-	if(!pc || u->dev[0x0f]) return 0;
 65+	if(!pc || uxn.dev[0x0f]) return 0;
 66 	for(step = STEP_MAX; step; step--) {
 67-		switch(u->ram[pc++]) {
 68+		switch(uxn.ram[pc++]) {
 69 		/* BRK */ case 0x00: return 1;
 70 		/* JCI */ case 0x20: if(DEC(wst)) { JMI break; } pc += 2; break;
 71 		/* JMI */ case 0x40: JMI break;
 72 		/* JSI */ case 0x60: c = pc + 2; INC(rst) = c >> 8; INC(rst) = c; JMI break;
 73-		/* LI2 */ case 0xa0: INC(wst) = u->ram[pc++]; /* fall-through */
 74-		/* LIT */ case 0x80: INC(wst) = u->ram[pc++]; break;
 75-		/* L2r */ case 0xe0: INC(rst) = u->ram[pc++]; /* fall-through */
 76-		/* LIr */ case 0xc0: INC(rst) = u->ram[pc++]; break;
 77+		/* LI2 */ case 0xa0: INC(wst) = uxn.ram[pc++]; /* fall-through */
 78+		/* LIT */ case 0x80: INC(wst) = uxn.ram[pc++]; break;
 79+		/* L2r */ case 0xe0: INC(rst) = uxn.ram[pc++]; /* fall-through */
 80+		/* LIr */ case 0xc0: INC(rst) = uxn.ram[pc++]; break;
 81 		/* INC */ OPC(0x01,POx(a),PUx(a + 1))
 82 		/* POP */ OPC(0x02,REM ,{})
 83 		/* NIP */ OPC(0x03,GET(x) REM ,PUT(x))
 84@@ -209,8 +209,7 @@ system_deo(Uint8 port)
 85 		uxn.rst.ptr = uxn.dev[5];
 86 		break;
 87 	case 0xe:
 88-		system_printstack("WST", &uxn.wst);
 89-		system_printstack("RST", &uxn.rst);
 90+		system_printstack("WST", &uxn.wst), system_printstack("RST", &uxn.rst);
 91 		break;
 92 	}
 93 }
 94@@ -229,7 +228,7 @@ console_input(Uint8 c, int type)
 95 {
 96 	uxn.dev[0x12] = c;
 97 	uxn.dev[0x17] = type;
 98-	return uxn_eval(&uxn, PEEK2(&uxn.dev[0x10]));
 99+	return uxn_eval(PEEK2(&uxn.dev[0x10]));
100 }
101 
102 static void
103@@ -614,19 +613,19 @@ datetime_dei(Uint8 addr)
104 */
105 
106 Uint8
107-emu_dei(Uxn *u, Uint8 addr)
108+emu_dei(Uint8 addr)
109 {
110 	switch(addr & 0xf0) {
111 	case 0x00: return system_dei(addr);
112 	case 0xc0: return datetime_dei(addr);
113 	}
114-	return u->dev[addr];
115+	return uxn.dev[addr];
116 }
117 
118 void
119-emu_deo(Uxn *u, Uint8 addr, Uint8 value)
120+emu_deo(Uint8 addr, Uint8 value)
121 {
122-	u->dev[addr] = value;
123+	uxn.dev[addr] = value;
124 	switch(addr & 0xf0) {
125 	case 0x00: system_deo(addr); break;
126 	case 0x10: console_deo(addr); break;
127@@ -646,7 +645,7 @@ main(int argc, char **argv)
128 	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
129 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
130 	uxn.dev[0x17] = argc - 2;
131-	if(uxn_eval(&uxn, PAGE_PROGRAM) && uxn.dev[0x10]) {
132+	if(uxn_eval(PAGE_PROGRAM) && uxn.dev[0x10]) {
133 		/* arguments input */
134 		for(; i < argc; i++) {
135 			char *p = argv[i];