uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 78526d56e3f8c98814d943843037d1565be2f1d7
parent 8c212fed3e5398fb38b580160ea530015f0a2eab
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Tue,  2 Jan 2024 11:54:12 -0800

Make uxn instance public

Diffstat:
Msrc/uxn.h | 1+
Msrc/uxncli.c | 40++++++++++++++--------------------------
Msrc/uxnemu.c | 4+++-
3 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/src/uxn.h b/src/uxn.h @@ -35,6 +35,7 @@ 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 @@ -8,7 +8,7 @@ #include "devices/datetime.h" /* -Copyright (c) 2021-2023 Devine Lu Linvega, Andrew Alderwick +Copyright (c) 2021-2024 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -18,6 +18,8 @@ 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) { @@ -41,45 +43,31 @@ emu_deo(Uxn *u, Uint8 addr, Uint8 value) } } -static void -emu_run(Uxn *u) -{ - while(!u->dev[0x0f]) { - int c = fgetc(stdin); - if(c == EOF) { - console_input(u, 0x00, CONSOLE_END); - break; - } - console_input(u, (Uint8)c, CONSOLE_STD); - } -} - -static int -emu_end(Uxn *u) -{ - free(u->ram); - return u->dev[0x0f] & 0x7f; -} - int main(int argc, char **argv) { - Uxn u = {0}; int i = 1; Uint8 dev[0x100] = {0}; u.dev = (Uint8 *)&dev; 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", "2 Jan 2024"); if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) return system_error("Init", "Failed to initialize uxn."); - /* Game Loop */ + /* eval */ u.dev[0x17] = argc - i; if(uxn_eval(&u, PAGE_PROGRAM)) { console_listen(&u, i, argc, argv); - emu_run(&u); + while(!u.dev[0x0f]) { + char c = fgetc(stdin); + if(c == EOF) { + console_input(&u, 0x00, CONSOLE_END); + break; + } + console_input(&u, (Uint8)c, CONSOLE_STD); + } } - return emu_end(&u); + free(u.ram); + return u.dev[0x0f] & 0x7f; } diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -46,6 +46,8 @@ 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; @@ -489,7 +491,7 @@ main(int argc, char **argv) Uint8 *ram; char *rom; Uint8 dev[0x100] = {0}; - Uxn u = {0}, u_audio = {0}; + Uxn u_audio = {0}; u.dev = (Uint8 *)&dev; u_audio.dev = (Uint8 *)&dev; int i = 1;