From 6b335197da7267cd09df6f6d3146ec42f681897e Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 15 Jul 2024 11:42:00 -0700 Subject: [PATCH] Standardized boot sequence --- README.md | 7 +++++-- src/uxn11.c | 8 +++----- src/uxncli.c | 53 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index e73e76f..23153ad 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,11 @@ The file device is _sandboxed_, meaning that it should not be able to read or wr ## Emulator Controls -- `F2` toggle on-screen debugger -- `F4` load boot.rom, or reload rom +- `F1` toggle zoom +- `F2` toggle debugger +- `F3` quit +- `F4` reboot +- `F5` reboot(soft) ### Buttons diff --git a/src/uxn11.c b/src/uxn11.c index f089083..781869d 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -268,7 +268,7 @@ main(int argc, char **argv) int i = 1; char *rom; if(i != argc && argv[i][0] == '-' && argv[i][1] == 'v') { - fprintf(stdout, "Uxn11 - Varvara Emulator, 2 Jul 2024.\n"); + fprintf(stdout, "Uxn11 - Varvara Emulator, 15 Jul 2024.\n"); i++; } rom = i == argc ? "boot.rom" : argv[i++]; @@ -278,9 +278,7 @@ main(int argc, char **argv) return !fprintf(stdout, "Could not open display.\n"); /* Event Loop */ uxn.dev[0x17] = argc - i; - if(uxn_eval(PAGE_PROGRAM)) { - console_listen(i, argc, argv); - emu_run(); - } + if(uxn_eval(PAGE_PROGRAM)) + console_listen(i, argc, argv), emu_run(); return emu_end(); } diff --git a/src/uxncli.c b/src/uxncli.c index f31da65..9ca2e06 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -43,30 +43,41 @@ emu_deo(Uint8 addr, Uint8 value) } } +static void +emu_run(void) +{ + while(!uxn.dev[0x0f]) { + int c = fgetc(stdin); + if(c == EOF) { + console_input(0x00, CONSOLE_END); + break; + } + console_input(c, CONSOLE_STD); + } +} + +static int +emu_end(void) +{ + free(uxn.ram); + return uxn.dev[0x0f] & 0x7f; +} + int main(int argc, char **argv) { 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 !printf("Uxncli - Console Varvara Emulator, 2 Jul 2024\n"); - if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) - return system_error("Init", "Failed to initialize uxn."); - /* Game Loop */ - uxn.dev[0x17] = argc - i; - if(uxn_eval(PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) { - console_listen(i, argc, argv); - while(!uxn.dev[0x0f]) { - int c = fgetc(stdin); - if(c == EOF) { - console_input(0x00, CONSOLE_END); - break; - } - console_input(c, CONSOLE_STD); - } + char *rom; + if(i != argc && argv[i][0] == '-' && argv[i][1] == 'v') { + fprintf(stdout, "Uxncli - Console Varvara Emulator, 15 Jul 2024.\n"); + i++; } - free(uxn.ram); - return uxn.dev[0x0f] & 0x7f; + rom = i == argc ? "boot.rom" : argv[i++]; + if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom)) + return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]); + /* Event Loop */ + uxn.dev[0x17] = argc - i; + if(uxn_eval(PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) + console_listen(i, argc, argv), emu_run(); + return emu_end(); }