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 void emu_deo(Uxn *u, Uint8 addr, Uint8 value);
extern Uxn uxn;
/* built-ins */

View File

@ -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);
}

View File

@ -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);
}