uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit a4f4eb7460c4f5ddcb382401a8fa6592623f41e0
parent 3f252c0ee378933856b9b01be1b3c7da58cacad5
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Tue,  2 Jan 2024 09:55:52 -0800

Minor optimization in system

Diffstat:
Msrc/devices/system.c | 43+++++++++++++++++++++++--------------------
Msrc/uxnemu.c | 2+-
2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/devices/system.c b/src/devices/system.c @@ -39,13 +39,23 @@ system_print(Stack *s, char *name) fprintf(stderr, "%s ", name); for(i = 0; i < 9; i++) { Uint8 pos = s->ptr - 4 + i; - fprintf(stderr, !pos ? "[%02x]" : i == 4 ? "<%02x>" - : " %02x ", - s->dat[pos]); + if(!pos) + fprintf(stderr, "[%02x]", s->dat[pos]); + else if(i == 4) + fprintf(stderr, "<%02x>", s->dat[pos]); + else + fprintf(stderr, " %02x ", s->dat[pos]); } fprintf(stderr, "\n"); } +void +system_inspect(Uxn *u) +{ + system_print(&u->wst, "wst"); + system_print(&u->rst, "rst"); +} + int system_error(char *msg, const char *err) { @@ -54,13 +64,6 @@ system_error(char *msg, const char *err) return 0; } -void -system_inspect(Uxn *u) -{ - system_print(&u->wst, "wst"); - system_print(&u->rst, "rst"); -} - int system_version(char *name, char *date) { @@ -69,21 +72,20 @@ system_version(char *name, char *date) } void -system_boot(Uxn *u, int soft) +system_zero(Uxn *u, int soft) { int i; - for(i = 0x100 * soft; i < 0x10000; i++) + for(i = PAGE_PROGRAM * soft; i < 0x10000; i++) u->ram[i] = 0; for(i = 0x0; i < 0x100; i++) u->dev[i] = 0; - u->wst.ptr = 0; - u->rst.ptr = 0; + u->wst.ptr = u->rst.ptr = 0; } void system_reboot(Uxn *u, char *rom, int soft) { - system_boot(u, soft); + system_zero(u, soft); if(system_load(u, boot_rom)) if(uxn_eval(u, PAGE_PROGRAM)) boot_rom = rom; @@ -93,7 +95,7 @@ int system_init(Uxn *u, Uint8 *ram, char *rom) { u->ram = ram; - system_boot(u, 0); + system_zero(u, 0); if(!system_load(u, rom)) if(!system_load(u, "boot.rom")) return system_error("Init", "Failed to load rom."); @@ -123,10 +125,11 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port) ram = u->ram; addr = PEEK2(d + 2); if(ram[addr] == 0x1) { - Uint16 i, length = PEEK2(ram + addr + 1); - Uint16 a_page = PEEK2(ram + addr + 1 + 2), a_addr = PEEK2(ram + addr + 1 + 4); - Uint16 b_page = PEEK2(ram + addr + 1 + 6), b_addr = PEEK2(ram + addr + 1 + 8); - int src = (a_page % RAM_PAGES) * 0x10000, dst = (b_page % RAM_PAGES) * 0x10000; + Uint8 *cmd_addr = ram + addr + 1; + Uint16 i, length = PEEK2(cmd_addr); + Uint16 a_page = PEEK2(cmd_addr + 2), a_addr = PEEK2(cmd_addr + 4); + Uint16 b_page = PEEK2(cmd_addr + 6), b_addr = PEEK2(cmd_addr + 8); + int src = (a_page % RAM_PAGES) << 0x10, dst = (b_page % RAM_PAGES) << 0x10; for(i = 0; i < length; i++) ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)]; } diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -498,7 +498,7 @@ main(int argc, char **argv) /* Read flag. Right now, there can be only one. */ if(argv[i][0] == '-') { if(argv[i][1] == 'v') - return system_version("Uxnemu - Graphical Varvara Emulator", "18 Dec 2023"); + return system_version("Uxnemu - Graphical Varvara Emulator", "2 Jan 2024"); if(argv[i][1] == '-') i++; if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)