0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-05 22:05:04 +00:00

Make uxn instance public

This commit is contained in:
Devine Lu Linvega 2024-01-02 11:54:12 -08:00
parent 8c212fed3e
commit 78526d56e3
3 changed files with 18 additions and 27 deletions

View file

@ -35,6 +35,7 @@ typedef struct Uxn {
/* required functions */ /* required functions */
extern Uxn u;
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);

View file

@ -8,7 +8,7 @@
#include "devices/datetime.h" #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 Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above 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. WITH REGARD TO THIS SOFTWARE.
*/ */
Uxn u;
Uint8 Uint8
emu_dei(Uxn *u, Uint8 addr) 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 int
main(int argc, char **argv) main(int argc, char **argv)
{ {
Uxn u = {0};
int i = 1; int i = 1;
Uint8 dev[0x100] = {0}; Uint8 dev[0x100] = {0};
u.dev = (Uint8 *)&dev; u.dev = (Uint8 *)&dev;
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 */
if(argv[i][0] == '-' && argv[i][1] == 'v') if(argv[i][0] == '-' && argv[i][1] == 'v')
return system_version("Uxncli - Console Varvara Emulator", "2 Jan 2024"); return system_version("Uxncli - Console Varvara Emulator", "2 Jan 2024");
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) if(!system_init(&u, (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 */ /* eval */
u.dev[0x17] = argc - i; u.dev[0x17] = argc - i;
if(uxn_eval(&u, PAGE_PROGRAM)) { if(uxn_eval(&u, PAGE_PROGRAM)) {
console_listen(&u, i, argc, argv); 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;
} }
return emu_end(&u); console_input(&u, (Uint8)c, CONSOLE_STD);
}
}
free(u.ram);
return u.dev[0x0f] & 0x7f;
} }

View file

@ -46,6 +46,8 @@ WITH REGARD TO THIS SOFTWARE.
#define HEIGHT 40 * 8 #define HEIGHT 40 * 8
#define TIMEOUT_MS 334 #define TIMEOUT_MS 334
Uxn u;
static SDL_Window *emu_window; static SDL_Window *emu_window;
static SDL_Texture *emu_texture; static SDL_Texture *emu_texture;
static SDL_Renderer *emu_renderer; static SDL_Renderer *emu_renderer;
@ -489,7 +491,7 @@ main(int argc, char **argv)
Uint8 *ram; Uint8 *ram;
char *rom; char *rom;
Uint8 dev[0x100] = {0}; Uint8 dev[0x100] = {0};
Uxn u = {0}, u_audio = {0}; Uxn u_audio = {0};
u.dev = (Uint8 *)&dev; u.dev = (Uint8 *)&dev;
u_audio.dev = (Uint8 *)&dev; u_audio.dev = (Uint8 *)&dev;
int i = 1; int i = 1;