Making uxn global

This commit is contained in:
Devine Lu Linvega 2024-06-29 10:45:23 -08:00
parent 01c983bfb7
commit 20b41ab70d
3 changed files with 16 additions and 13 deletions

View File

@ -37,6 +37,7 @@ typedef struct Uxn {
extern Uint8 emu_dei(Uxn *u, Uint8 addr); extern Uint8 emu_dei(Uxn *u, Uint8 addr);
extern void emu_deo(Uxn *u, Uint8 addr, Uint8 value); extern void emu_deo(Uxn *u, Uint8 addr, Uint8 value);
extern Uxn uxn;
/* built-ins */ /* built-ins */

View File

@ -16,6 +16,8 @@
#include "devices/file.h" #include "devices/file.h"
#include "devices/datetime.h" #include "devices/datetime.h"
Uxn uxn;
/* /*
Copyright (c) 2022 Devine Lu Linvega Copyright (c) 2022 Devine Lu Linvega
@ -267,7 +269,6 @@ emu_run(Uxn *u)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
Uxn u = {0};
int i = 1; int i = 1;
char *rom; char *rom;
if(i != argc && argv[i][0] == '-' && argv[i][1] == 'v') { if(i != argc && argv[i][0] == '-' && argv[i][1] == 'v') {
@ -275,7 +276,7 @@ main(int argc, char **argv)
i++; i++;
} }
rom = i == argc ? "boot.rom" : 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]); fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
return 0; return 0;
} }
@ -285,9 +286,9 @@ main(int argc, char **argv)
} }
/* Game Loop */ /* Game Loop */
u.dev[0x17] = argc - i; u.dev[0x17] = argc - i;
if(uxn_eval(&u, PAGE_PROGRAM)) { if(uxn_eval(&uxn, PAGE_PROGRAM)) {
console_listen(&u, i, argc, argv); console_listen(&uxn, i, argc, argv);
emu_run(&u); emu_run(&uxn);
} }
return emu_end(&u); return emu_end(&uxn);
} }

View File

@ -18,6 +18,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE. WITH REGARD TO THIS SOFTWARE.
*/ */
Uxn uxn;
Uint8 Uint8
emu_dei(Uxn *u, Uint8 addr) emu_dei(Uxn *u, Uint8 addr)
{ {
@ -65,20 +67,19 @@ emu_end(Uxn *u)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
Uxn u = {0};
int i = 1; int i = 1;
if(i == argc) if(i == argc)
return system_error("usage", "uxncli [-v] file.rom [args..]"); return system_error("usage", "uxncli [-v] file.rom [args..]");
/* Read flags */ /* Read flags */
if(argv[i][0] == '-' && argv[i][1] == 'v') if(argv[i][0] == '-' && argv[i][1] == 'v')
return system_version("Uxncli - Console Varvara Emulator", "18 Mar 2024"); 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."); return system_error("Init", "Failed to initialize uxn.");
/* Game Loop */ /* Game Loop */
u.dev[0x17] = argc - i; uxn.dev[0x17] = argc - i;
if(uxn_eval(&u, PAGE_PROGRAM) && PEEK2(u.dev + 0x10)) { if(uxn_eval(&uxn, PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) {
console_listen(&u, i, argc, argv); console_listen(&uxn, i, argc, argv);
emu_run(&u); emu_run(&uxn);
} }
return emu_end(&u); return emu_end(&uxn);
} }