uxn

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

commit c0d45d144080de5e7b4131fb806906153a601bc5
parent 9a7a11003f4a908fe1294e68e124019d211216a8
Author: neauoire <aliceffekt@gmail.com>
Date:   Tue, 15 Aug 2023 16:06:29 -0700

Try loading rom during system init

Diffstat:
Msrc/devices/system.c | 4+++-
Msrc/devices/system.h | 2+-
Msrc/uxncli.c | 8++------
Msrc/uxnemu.c | 12++++--------
4 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/devices/system.c b/src/devices/system.c @@ -95,9 +95,11 @@ system_version(char *name, char *date) } int -system_boot(Uxn *u, Uint8 *ram) +system_init(Uxn *u, Uint8 *ram, char *rom) { u->ram = ram; + if(!system_load(u, rom)) + return system_error("Init", "Failed to load rom."); return 1; } diff --git a/src/devices/system.h b/src/devices/system.h @@ -20,5 +20,5 @@ int system_version(char *emulator, char *date); int system_load(Uxn *u, char *filename); void system_inspect(Uxn *u); int system_error(char *msg, const char *err); -int system_boot(Uxn *u, Uint8 *ram); +int system_init(Uxn *u, Uint8 *ram, char *rom); void system_deo(Uxn *u, Uint8 *d, Uint8 port); diff --git a/src/uxncli.c b/src/uxncli.c @@ -57,12 +57,8 @@ main(int argc, char **argv) /* Read flags */ if(argv[i][0] == '-' && argv[i][1] == 'v') return system_version("Uxncli - Console Varvara Emulator", "9 Aug 2023"); - /* Continue.. */ - if(!system_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)))) - return system_error("Boot", "Failed"); - /* Load rom */ - if(!system_load(&u, argv[i++])) - return system_error("Load", "Failed"); + if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) + return system_error("Init", "Failed to initialize uxn."); /* Game Loop */ u.dev[0x17] = argc - i; if(uxn_eval(&u, PAGE_PROGRAM)) { diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -257,11 +257,6 @@ emu_init(void) static int emu_start(Uxn *u, char *rom, int queue) { - free(u->ram); - if(!system_boot(u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)))) - return system_error("Boot", "Failed to start uxn."); - if(!system_load(u, rom)) - return system_error("Boot", "Failed to load rom."); u->dev[0x17] = queue; exec_deadline = SDL_GetPerformanceCounter() + deadline_interval; screen_resize(WIDTH, HEIGHT); @@ -545,11 +540,12 @@ main(int argc, char **argv) return system_version("Uxnemu - Graphical Varvara Emulator", "10 Aug 2023"); if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0) set_zoom(argv[i++][1] - '0', 0); - /* Continue.. */ + rom_path = argv[i++]; if(!emu_init()) - return system_error("Init", "Failed to initialize emulator."); + return system_error("Init", "Failed to initialize varvara."); + if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom_path)) + return system_error("Init", "Failed to initialize uxn."); /* load rom */ - rom_path = argv[i++]; if(!emu_start(&u, rom_path, argc - i)) return system_error("Start", "Failed"); /* read arguments */