From d49514e257261491ace79f1c38d03b0753c453bd Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sat, 29 Jun 2024 11:16:15 -0800 Subject: [PATCH] Removed indirection in system_deo --- src/devices/system.c | 40 +++++++++++++++++++--------------------- src/devices/system.h | 2 +- src/uxn11.c | 2 +- src/uxncli.c | 2 +- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/devices/system.c b/src/devices/system.c index 89a2f96..e7367bd 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -101,43 +101,41 @@ system_dei(Uint8 addr) } void -system_deo(Uxn *u, Uint8 *d, Uint8 port) +system_deo(Uint8 *d, Uint8 port) { - Uint8 *ram; Uint16 addr; switch(port) { case 0x3: - ram = u->ram; addr = PEEK2(d + 2); - if(ram[addr] == 0x0) { - Uint8 value = ram[addr + 7]; - Uint16 i, length = PEEK2(ram + addr + 1); - Uint16 dst_page = PEEK2(ram + addr + 3), dst_addr = PEEK2(ram + addr + 5); + if(uxn.ram[addr] == 0x0) { + Uint8 value = uxn.ram[addr + 7]; + Uint16 i, length = PEEK2(uxn.ram + addr + 1); + Uint16 dst_page = PEEK2(uxn.ram + addr + 3), dst_addr = PEEK2(uxn.ram + addr + 5); int dst = (dst_page % RAM_PAGES) * 0x10000; for(i = 0; i < length; i++) - ram[dst + (Uint16)(dst_addr + i)] = value; - } else if(ram[addr] == 0x1) { - Uint16 i, length = PEEK2(ram + addr + 1); - Uint16 a_page = PEEK2(ram + addr + 3), a_addr = PEEK2(ram + addr + 5); - Uint16 b_page = PEEK2(ram + addr + 7), b_addr = PEEK2(ram + addr + 9); + uxn.ram[dst + (Uint16)(dst_addr + i)] = value; + } else if(uxn.ram[addr] == 0x1) { + Uint16 i, length = PEEK2(uxn.ram + addr + 1); + Uint16 a_page = PEEK2(uxn.ram + addr + 3), a_addr = PEEK2(uxn.ram + addr + 5); + Uint16 b_page = PEEK2(uxn.ram + addr + 7), b_addr = PEEK2(uxn.ram + addr + 9); int src = (a_page % RAM_PAGES) * 0x10000, dst = (b_page % RAM_PAGES) * 0x10000; for(i = 0; i < length; i++) - ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)]; - } else if(ram[addr] == 0x2) { - Uint16 i, length = PEEK2(ram + addr + 1); - Uint16 a_page = PEEK2(ram + addr + 3), a_addr = PEEK2(ram + addr + 5); - Uint16 b_page = PEEK2(ram + addr + 7), b_addr = PEEK2(ram + addr + 9); + uxn.ram[dst + (Uint16)(b_addr + i)] = uxn.ram[src + (Uint16)(a_addr + i)]; + } else if(uxn.ram[addr] == 0x2) { + Uint16 i, length = PEEK2(uxn.ram + addr + 1); + Uint16 a_page = PEEK2(uxn.ram + addr + 3), a_addr = PEEK2(uxn.ram + addr + 5); + Uint16 b_page = PEEK2(uxn.ram + addr + 7), b_addr = PEEK2(uxn.ram + addr + 9); int src = (a_page % RAM_PAGES) * 0x10000, dst = (b_page % RAM_PAGES) * 0x10000; for(i = length - 1; i != 0xffff; i--) - ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)]; + uxn.ram[dst + (Uint16)(b_addr + i)] = uxn.ram[src + (Uint16)(a_addr + i)]; } else - fprintf(stderr, "Unknown Expansion Command 0x%02x\n", ram[addr]); + fprintf(stderr, "Unknown Expansion Command 0x%02x\n", uxn.ram[addr]); break; case 0x4: - u->wst.ptr = d[4]; + uxn.wst.ptr = d[4]; break; case 0x5: - u->rst.ptr = d[5]; + uxn.rst.ptr = d[5]; break; case 0xe: system_inspect(); diff --git a/src/devices/system.h b/src/devices/system.h index 39643ba..25449bb 100644 --- a/src/devices/system.h +++ b/src/devices/system.h @@ -18,6 +18,6 @@ int system_error(char *msg, const char *err); int system_boot(Uint8 *ram, char *rom); Uint8 system_dei(Uint8 addr); -void system_deo(Uxn *u, Uint8 *d, Uint8 port); +void system_deo(Uint8 *d, Uint8 port); extern char *boot_rom; \ No newline at end of file diff --git a/src/uxn11.c b/src/uxn11.c index df17a22..11e2db1 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -63,7 +63,7 @@ emu_deo(Uint8 addr, Uint8 value) uxn.dev[addr] = value; switch(d) { case 0x00: - system_deo(&uxn, &uxn.dev[d], p); + system_deo(&uxn.dev[d], p); if(p > 0x7 && p < 0xe) screen_palette(&uxn.dev[0x8]); break; diff --git a/src/uxncli.c b/src/uxncli.c index 2c07965..0808490 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -37,7 +37,7 @@ emu_deo(Uint8 addr, Uint8 value) Uint8 p = addr & 0x0f, d = addr & 0xf0; uxn.dev[addr] = value; switch(d) { - case 0x00: system_deo(&uxn, &uxn.dev[d], p); break; + case 0x00: system_deo(&uxn.dev[d], p); break; case 0x10: console_deo(&uxn, &uxn.dev[d], p); break; case 0xa0: file_deo(0, uxn.ram, &uxn.dev[d], p); break; case 0xb0: file_deo(1, uxn.ram, &uxn.dev[d], p); break;