diff --git a/src/uxn.h b/src/uxn.h index 04f4aa5..f7a88a3 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -37,6 +37,7 @@ typedef struct Uxn { extern Uint8 emu_dei(Uxn *u, Uint8 addr); extern void emu_deo(Uxn *u, Uint8 addr, Uint8 value); +extern Uxn uxn; /* built-ins */ diff --git a/src/uxn11.c b/src/uxn11.c index 633072a..dece440 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -16,6 +16,8 @@ #include "devices/file.h" #include "devices/datetime.h" +Uxn uxn; + /* Copyright (c) 2022 Devine Lu Linvega @@ -267,7 +269,6 @@ emu_run(Uxn *u) int main(int argc, char **argv) { - Uxn u = {0}; int i = 1; char *rom; if(i != argc && argv[i][0] == '-' && argv[i][1] == 'v') { @@ -275,7 +276,7 @@ main(int argc, char **argv) i++; } rom = i == argc ? "boot.rom" : argv[i++]; - if(!system_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom)) { + if(!system_boot(&uxn, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom)) { fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]); return 0; } @@ -285,9 +286,9 @@ main(int argc, char **argv) } /* Game Loop */ u.dev[0x17] = argc - i; - if(uxn_eval(&u, PAGE_PROGRAM)) { - console_listen(&u, i, argc, argv); - emu_run(&u); + if(uxn_eval(&uxn, PAGE_PROGRAM)) { + console_listen(&uxn, i, argc, argv); + emu_run(&uxn); } - return emu_end(&u); + return emu_end(&uxn); } diff --git a/src/uxncli.c b/src/uxncli.c index f7f9fc2..34ba894 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -18,6 +18,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +Uxn uxn; + Uint8 emu_dei(Uxn *u, Uint8 addr) { @@ -65,20 +67,19 @@ emu_end(Uxn *u) int main(int argc, char **argv) { - Uxn u = {0}; int i = 1; if(i == argc) return system_error("usage", "uxncli [-v] file.rom [args..]"); /* Read flags */ if(argv[i][0] == '-' && argv[i][1] == 'v') return system_version("Uxncli - Console Varvara Emulator", "18 Mar 2024"); - if(!system_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) + if(!system_boot(&uxn, (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) && PEEK2(u.dev + 0x10)) { - console_listen(&u, i, argc, argv); - emu_run(&u); + uxn.dev[0x17] = argc - i; + if(uxn_eval(&uxn, PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) { + console_listen(&uxn, i, argc, argv); + emu_run(&uxn); } - return emu_end(&u); + return emu_end(&uxn); }