From cfc8349d5448376b21d8100ed627a3d7cb37d0cd Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sat, 29 Jun 2024 11:35:34 -0800 Subject: [PATCH] Removed indirection in uxn_eval call --- src/devices/console.c | 2 +- src/devices/controller.c | 6 +++--- src/devices/mouse.c | 8 ++++---- src/devices/system.c | 2 +- src/uxn.c | 39 ++++++++++++++++++++------------------- src/uxn.h | 2 +- src/uxn11.c | 4 ++-- src/uxncli.c | 2 +- 8 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/devices/console.c b/src/devices/console.c index aaad677..4bb848c 100644 --- a/src/devices/console.c +++ b/src/devices/console.c @@ -87,7 +87,7 @@ console_input(char c, int type) Uint8 *d = &uxn.dev[0x10]; d[0x2] = c; d[0x7] = type; - return uxn_eval(&uxn, PEEK2(d)); + return uxn_eval(PEEK2(d)); } void diff --git a/src/devices/controller.c b/src/devices/controller.c index d7f8f4b..9602cc7 100644 --- a/src/devices/controller.c +++ b/src/devices/controller.c @@ -17,7 +17,7 @@ controller_down(Uint8 *d, Uint8 mask) { if(mask) { d[2] |= mask; - uxn_eval(&uxn, PEEK2(d)); + uxn_eval(PEEK2(d)); } } @@ -26,7 +26,7 @@ controller_up(Uint8 *d, Uint8 mask) { if(mask) { d[2] &= (~mask); - uxn_eval(&uxn, PEEK2(d)); + uxn_eval(PEEK2(d)); } } @@ -35,7 +35,7 @@ controller_key(Uint8 *d, Uint8 key) { if(key) { d[3] = key; - uxn_eval(&uxn, PEEK2(d)); + uxn_eval(PEEK2(d)); d[3] = 0x00; } } diff --git a/src/devices/mouse.c b/src/devices/mouse.c index 814bb6e..b01d5d6 100644 --- a/src/devices/mouse.c +++ b/src/devices/mouse.c @@ -16,14 +16,14 @@ void mouse_down(Uint8 *d, Uint8 mask) { d[6] |= mask; - uxn_eval(&uxn, PEEK2(d)); + uxn_eval(PEEK2(d)); } void mouse_up(Uint8 *d, Uint8 mask) { d[6] &= (~mask); - uxn_eval(&uxn, PEEK2(d)); + uxn_eval(PEEK2(d)); } void @@ -31,7 +31,7 @@ mouse_pos(Uint8 *d, Uint16 x, Uint16 y) { *(d + 2) = x >> 8, *(d + 3) = x; *(d + 4) = y >> 8, *(d + 5) = y; - uxn_eval(&uxn, PEEK2(d)); + uxn_eval(PEEK2(d)); } void @@ -39,7 +39,7 @@ mouse_scroll(Uint8 *d, Uint16 x, Uint16 y) { *(d + 0xa) = x >> 8, *(d + 0xb) = x; *(d + 0xc) = -y >> 8, *(d + 0xd) = -y; - uxn_eval(&uxn, PEEK2(d)); + uxn_eval(PEEK2(d)); *(d + 0xa) = 0, *(d + 0xb) = 0; *(d + 0xc) = 0, *(d + 0xd) = 0; } diff --git a/src/devices/system.c b/src/devices/system.c index e7367bd..3850ea9 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -72,7 +72,7 @@ system_reboot(char *rom, int soft) { system_zero(soft); if(system_load(boot_rom)) - if(uxn_eval(&uxn, PAGE_PROGRAM)) + if(uxn_eval(PAGE_PROGRAM)) boot_rom = rom; } diff --git a/src/uxn.c b/src/uxn.c index 7b6fc8f..7994ccb 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -35,13 +35,14 @@ WITH REGARD TO THIS SOFTWARE. #define SET(x, y) { SHIFT((ins & 0x80) ? x + y : y) } int -uxn_eval(Uxn *u, Uint16 pc) +uxn_eval(Uint16 pc) { + Uxn *u = &uxn; Uint16 t, n, l, r; - Uint8 *ram = u->ram, *rr; + Uint8 *rr; if(!pc || u->dev[0x0f]) return 0; for(;;) { - Uint8 ins = ram[pc++]; + Uint8 ins = uxn.ram[pc++]; Stack *s = ins & 0x40 ? &u->rst : &u->wst; switch(ins & 0x3f) { /* IMM */ @@ -49,10 +50,10 @@ uxn_eval(Uxn *u, Uint16 pc) switch(ins) { case 0x00: /* BRK */ return 1; case 0x20: /* JCI */ t=T; SHIFT(-1) if(!t) { pc += 2; break; } /* fall-through */ - case 0x40: /* JMI */ rr = ram + pc; pc += 2 + PEEK2(rr); break; - case 0x60: /* JSI */ SHIFT( 2) rr = ram + pc; pc += 2; T2_(pc); pc += PEEK2(rr); break; - case 0x80: /* LIT */ case 0xc0: SHIFT( 1) T = ram[pc++]; break; - case 0xa0: /* LIT2 */ case 0xe0: SHIFT( 2) N = ram[pc++]; T = ram[pc++]; break; + case 0x40: /* JMI */ rr = uxn.ram + pc; pc += 2 + PEEK2(rr); break; + case 0x60: /* JSI */ SHIFT( 2) rr = uxn.ram + pc; pc += 2; T2_(pc); pc += PEEK2(rr); break; + case 0x80: /* LIT */ case 0xc0: SHIFT( 1) T = uxn.ram[pc++]; break; + case 0xa0: /* LIT2 */ case 0xe0: SHIFT( 2) N = uxn.ram[pc++]; T = uxn.ram[pc++]; break; } break; /* ALU */ case 0x01: /* INC */ t=T; SET(1, 0) T = t + 1; break; @@ -85,18 +86,18 @@ uxn_eval(Uxn *u, Uint16 pc) case 0x2e: /* JSR2 */ t=T2; SET(2,-2) FLIP SHIFT(2) T2_(pc) pc = t; break; case 0x0f: /* STH */ t=T; SET(1,-1) FLIP SHIFT(1) T = t; break; case 0x2f: /* STH2 */ t=T2; SET(2,-2) FLIP SHIFT(2) T2_(t) break; - case 0x10: /* LDZ */ t=T; SET(1, 0) T = ram[t]; break; - case 0x30: /* LDZ2 */ t=T; SET(1, 1) N = ram[t++]; T = ram[(Uint8)t]; break; - case 0x11: /* STZ */ t=T;n=N; SET(2,-2) ram[t] = n; break; - case 0x31: /* STZ2 */ t=T;n=H2; SET(3,-3) ram[t++] = n >> 8; ram[(Uint8)t] = n; break; - case 0x12: /* LDR */ t=T; SET(1, 0) r = pc + (Sint8)t; T = ram[r]; break; - case 0x32: /* LDR2 */ t=T; SET(1, 1) r = pc + (Sint8)t; N = ram[r++]; T = ram[r]; break; - case 0x13: /* STR */ t=T;n=N; SET(2,-2) r = pc + (Sint8)t; ram[r] = n; break; - case 0x33: /* STR2 */ t=T;n=H2; SET(3,-3) r = pc + (Sint8)t; ram[r++] = n >> 8; ram[r] = n; break; - case 0x14: /* LDA */ t=T2; SET(2,-1) T = ram[t]; break; - case 0x34: /* LDA2 */ t=T2; SET(2, 0) N = ram[t++]; T = ram[t]; break; - case 0x15: /* STA */ t=T2;n=L; SET(3,-3) ram[t] = n; break; - case 0x35: /* STA2 */ t=T2;n=N2; SET(4,-4) ram[t++] = n >> 8; ram[t] = n; break; + case 0x10: /* LDZ */ t=T; SET(1, 0) T = uxn.ram[t]; break; + case 0x30: /* LDZ2 */ t=T; SET(1, 1) N = uxn.ram[t++]; T = uxn.ram[(Uint8)t]; break; + case 0x11: /* STZ */ t=T;n=N; SET(2,-2) uxn.ram[t] = n; break; + case 0x31: /* STZ2 */ t=T;n=H2; SET(3,-3) uxn.ram[t++] = n >> 8; uxn.ram[(Uint8)t] = n; break; + case 0x12: /* LDR */ t=T; SET(1, 0) r = pc + (Sint8)t; T = uxn.ram[r]; break; + case 0x32: /* LDR2 */ t=T; SET(1, 1) r = pc + (Sint8)t; N = uxn.ram[r++]; T = uxn.ram[r]; break; + case 0x13: /* STR */ t=T;n=N; SET(2,-2) r = pc + (Sint8)t; uxn.ram[r] = n; break; + case 0x33: /* STR2 */ t=T;n=H2; SET(3,-3) r = pc + (Sint8)t; uxn.ram[r++] = n >> 8; uxn.ram[r] = n; break; + case 0x14: /* LDA */ t=T2; SET(2,-1) T = uxn.ram[t]; break; + case 0x34: /* LDA2 */ t=T2; SET(2, 0) N = uxn.ram[t++]; T = uxn.ram[t]; break; + case 0x15: /* STA */ t=T2;n=L; SET(3,-3) uxn.ram[t] = n; break; + case 0x35: /* STA2 */ t=T2;n=N2; SET(4,-4) uxn.ram[t++] = n >> 8; uxn.ram[t] = n; break; case 0x16: /* DEI */ t=T; SET(1, 0) T = emu_dei(t); break; case 0x36: /* DEI2 */ t=T; SET(1, 1) N = emu_dei(t++); T = emu_dei(t); break; case 0x17: /* DEO */ t=T;n=N; SET(2,-2) emu_deo(t, n); break; diff --git a/src/uxn.h b/src/uxn.h index 25d12db..c63e6bf 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -41,4 +41,4 @@ extern Uxn uxn; /* built-ins */ -int uxn_eval(Uxn *u, Uint16 pc); +int uxn_eval(Uint16 pc); diff --git a/src/uxn11.c b/src/uxn11.c index 4ca0c35..3f18107 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -248,7 +248,7 @@ emu_run(void) emu_event(); if(poll(&fds[1], 1, 0)) { read(fds[1].fd, expirations, 8); - uxn_eval(&uxn, uxn.dev[0x20] << 8 | uxn.dev[0x21]); + uxn_eval(uxn.dev[0x20] << 8 | uxn.dev[0x21]); if(screen_changed()) { int x = uxn_screen.x1 * uxn_screen.scale, y = uxn_screen.y1 * uxn_screen.scale; int w = uxn_screen.x2 * uxn_screen.scale - x, h = uxn_screen.y2 * uxn_screen.scale - y; @@ -286,7 +286,7 @@ main(int argc, char **argv) } /* Game Loop */ uxn.dev[0x17] = argc - i; - if(uxn_eval(&uxn, PAGE_PROGRAM)) { + if(uxn_eval(PAGE_PROGRAM)) { console_listen(i, argc, argv); emu_run(); } diff --git a/src/uxncli.c b/src/uxncli.c index 0465225..9fb8377 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -77,7 +77,7 @@ main(int argc, char **argv) return system_error("Init", "Failed to initialize uxn."); /* Game Loop */ uxn.dev[0x17] = argc - i; - if(uxn_eval(&uxn, PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) { + if(uxn_eval(PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) { console_listen(i, argc, argv); emu_run(); }