From 7938707cbe6960a74d3fdf587b5890d3b0663034 Mon Sep 17 00:00:00 2001 From: Jonne Ransijn Date: Sat, 7 Jun 2025 13:26:00 +0200 Subject: [PATCH] Add a `PAGE_SIZE` macro --- src/devices/system.c | 16 ++++++++-------- src/uxn.h | 1 + src/uxncli.c | 2 +- src/uxnemu.c | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/devices/system.c b/src/devices/system.c index 432a28b..e41daa4 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -31,9 +31,9 @@ system_load(Uint8 *ram, char *rom_path) { FILE *f = fopen(rom_path, "rb"); if(f) { - int i = 0, l = fread(ram, 0x10000 - PAGE_PROGRAM, 1, f); + int i = 0, l = fread(ram, PAGE_SIZE - PAGE_PROGRAM, 1, f); while(l && ++i < RAM_PAGES) - l = fread(ram + 0x10000 * i - PAGE_PROGRAM, 0x10000, 1, f); + l = fread(ram + PAGE_SIZE * i - PAGE_PROGRAM, PAGE_SIZE, 1, f); fclose(f); } return !!f; @@ -62,7 +62,7 @@ system_reboot(int soft) { int i; for(i = 0x0; i < 0x100; i++) uxn.dev[i] = 0; - for(i = soft ? 0x100 : 0; i < 0x10000; i++) uxn.ram[i] = 0; + for(i = soft ? 0x100 : 0; i < PAGE_SIZE; i++) uxn.ram[i] = 0; uxn.wst.ptr = uxn.rst.ptr = 0; return system_boot(uxn.ram, boot_path, 0); } @@ -89,19 +89,19 @@ system_deo(Uint8 port) Uint8 *aptr = uxn.ram + addr; Uint16 length = PEEK2(aptr + 1); if(uxn.ram[addr] == 0x0) { - unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5); + unsigned int a = PEEK2(aptr + 3) * PAGE_SIZE + PEEK2(aptr + 5); unsigned int b = a + length; value = uxn.ram[addr + 7]; for(; a < b; uxn.ram[a++] = value); } else if(uxn.ram[addr] == 0x1) { - unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5); + unsigned int a = PEEK2(aptr + 3) * PAGE_SIZE + PEEK2(aptr + 5); unsigned int b = a + length; - unsigned int c = PEEK2(aptr + 7) * 0x10000 + PEEK2(aptr + 9); + unsigned int c = PEEK2(aptr + 7) * PAGE_SIZE + PEEK2(aptr + 9); for(; a < b; uxn.ram[c++] = uxn.ram[a++]); } else if(uxn.ram[addr] == 0x2) { - unsigned int a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5); + unsigned int a = PEEK2(aptr + 3) * PAGE_SIZE + PEEK2(aptr + 5); unsigned int b = a + length; - unsigned int c = PEEK2(aptr + 7) * 0x10000 + PEEK2(aptr + 9); + unsigned int c = PEEK2(aptr + 7) * PAGE_SIZE + PEEK2(aptr + 9); unsigned int d = c + length; for(; b >= a; uxn.ram[--d] = uxn.ram[--b]); } else diff --git a/src/uxn.h b/src/uxn.h index 066c661..1b7e660 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -18,6 +18,7 @@ WITH REGARD TO THIS SOFTWARE. #define STEP_MAX 0x80000000 #define PAGE_PROGRAM 0x0100 +#define PAGE_SIZE 0x10000 typedef unsigned char Uint8; typedef signed char Sint8; diff --git a/src/uxncli.c b/src/uxncli.c index 37d7eeb..384d858 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -51,7 +51,7 @@ main(int argc, char **argv) return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 31 Jan 2025.\n"); else if(argc == 1) return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]); - else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2)) + else if(!system_boot((Uint8 *)calloc(PAGE_SIZE * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2)) return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]); if(console_vector) { console_arguments(i, argc, argv); diff --git a/src/uxnemu.c b/src/uxnemu.c index f1518cd..d70f82a 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -482,7 +482,7 @@ main(int argc, char **argv) rom_path = i == argc ? "boot.rom" : argv[i++]; if(!emu_init()) return system_error("Init", "Failed to initialize varvara."); - if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES + 1, sizeof(Uint8)), rom_path, argc > i)) + if(!system_boot((Uint8 *)calloc(PAGE_SIZE * RAM_PAGES + 1, sizeof(Uint8)), rom_path, argc > i)) return system_error("usage:", "uxnemu [-v | -f | -2x | -3x] file.rom [args...]"); /* start */ console_arguments(i, argc, argv);