From 02f7add4ac241f62c5d9e8b4e3b0b140b1ff0a6a Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 2 Jan 2024 19:20:16 -0800 Subject: [PATCH] Housekeeping --- src/devices/system.c | 29 +++++++++++------------------ src/devices/system.h | 3 +-- src/uxn.h | 1 - src/uxncli.c | 5 ++--- src/uxnemu.c | 32 +++++++++++++++----------------- 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/devices/system.c b/src/devices/system.c index 0714328..ca832ec 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -49,6 +49,17 @@ system_print(Stack *s, char *name) fprintf(stderr, "\n"); } +static void +system_zero(Uxn *u, int soft) +{ + int 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 = u->rst.ptr = 0; +} + void system_inspect(Uxn *u) { @@ -64,24 +75,6 @@ system_error(char *msg, const char *err) return 0; } -int -system_version(char *name, char *date) -{ - printf("%s, %s.\n", name, date); - return 0; -} - -void -system_zero(Uxn *u, int soft) -{ - int 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 = u->rst.ptr = 0; -} - void system_reboot(Uxn *u, char *rom, int soft) { diff --git a/src/devices/system.h b/src/devices/system.h index cae4111..bea865e 100644 --- a/src/devices/system.h +++ b/src/devices/system.h @@ -15,10 +15,9 @@ WITH REGARD TO THIS SOFTWARE. extern char *boot_rom; +int system_error(char *msg, const char *err); void system_reboot(Uxn *u, char *rom, int soft); void system_inspect(Uxn *u); -int system_version(char *emulator, char *date); -int system_error(char *msg, const char *err); int system_init(Uxn *u, Uint8 *ram, char *rom); Uint8 system_dei(Uxn *u, Uint8 addr); diff --git a/src/uxn.h b/src/uxn.h index b76b99f..6a0dc97 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -35,7 +35,6 @@ typedef struct Uxn { /* required functions */ -extern Uxn u; extern Uint8 emu_dei(Uxn *u, Uint8 addr); extern void emu_deo(Uxn *u, Uint8 addr, Uint8 value); diff --git a/src/uxncli.c b/src/uxncli.c index 15f00b0..c9030d7 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -18,8 +18,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -Uxn u; - Uint8 emu_dei(Uxn *u, Uint8 addr) { @@ -47,12 +45,13 @@ int main(int argc, char **argv) { int i = 1; + Uxn u = {0}; Uint8 dev[0x100] = {0}; u.dev = (Uint8 *)&dev; if(i == argc) return system_error("usage", "uxncli [-v] file.rom [args..]"); if(argv[i][0] == '-' && argv[i][1] == 'v') - return system_version("Uxncli - Console Varvara Emulator", "2 Jan 2024"); + return system_error("Uxncli - Varvara Emulator(CLI)", "2 Jan 2024."); if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) return system_error("Init", "Failed to initialize uxn."); /* eval */ diff --git a/src/uxnemu.c b/src/uxnemu.c index 90ea51b..7ea7e17 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -46,8 +46,6 @@ WITH REGARD TO THIS SOFTWARE. #define HEIGHT 40 * 8 #define TIMEOUT_MS 334 -Uxn u; - static SDL_Window *emu_window; static SDL_Texture *emu_texture; static SDL_Renderer *emu_renderer; @@ -490,34 +488,34 @@ main(int argc, char **argv) { Uint8 *ram; char *rom; + Uxn u = {0}; Uint8 dev[0x100] = {0}; Uxn u_audio = {0}; u.dev = (Uint8 *)&dev; u_audio.dev = (Uint8 *)&dev; int i = 1; - if(i == argc) - return system_error("usage", "uxnemu [-v] | uxnemu [-f | -2x | -3x | --] file.rom [args...]"); - /* 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", "2 Jan 2024"); - if(argv[i][1] == '-') - i++; - if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0) - set_zoom(argv[i++][1] - '0', 0); - if(strcmp(argv[i], "-f") == 0) { - i++; + /* flags */ + if(argc > 1 && argv[i][0] == '-') { + if(!strcmp(argv[i], "-v")) + return system_error("Uxnemu - Varvara Emulator(GUI)", "2 Jan 2024."); + else if(!strcmp(argv[i], "-2x")) + set_zoom(2, 0); + else if(!strcmp(argv[i], "-3x")) + set_zoom(3, 0); + else if(strcmp(argv[i], "-f") == 0) set_fullscreen(1, 0); - } + i++; } - /* Start system. */ + if(i == argc) + return system_error("usage", "uxnemu [-v | -f | -2x | -3x] file.rom [args...]"); + /* start */ ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)); rom = argv[i++]; if(!system_init(&u, ram, rom) || !system_init(&u_audio, ram, rom)) return system_error("Init", "Failed to initialize uxn."); if(!emu_init(&u_audio)) return system_error("Init", "Failed to initialize varvara."); - /* Game Loop */ + /* loop */ u.dev[0x17] = argc - i; if(uxn_eval(&u, PAGE_PROGRAM)) { console_listen(&u, i, argc, argv);