Housekeeping

This commit is contained in:
Devine Lu Linvega 2024-01-02 19:20:16 -08:00
parent 78526d56e3
commit 02f7add4ac
5 changed files with 29 additions and 41 deletions

View File

@ -49,6 +49,17 @@ system_print(Stack *s, char *name)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
static void
system_zero(Uxn *u, int soft)
{
int i;
for(i = PAGE_PROGRAM * soft; i < 0x10000; i++)
u->ram[i] = 0;
for(i = 0x0; i < 0x100; i++)
u->dev[i] = 0;
u->wst.ptr = u->rst.ptr = 0;
}
void void
system_inspect(Uxn *u) system_inspect(Uxn *u)
{ {
@ -64,24 +75,6 @@ system_error(char *msg, const char *err)
return 0; return 0;
} }
int
system_version(char *name, char *date)
{
printf("%s, %s.\n", name, date);
return 0;
}
void
system_zero(Uxn *u, int soft)
{
int i;
for(i = PAGE_PROGRAM * soft; i < 0x10000; i++)
u->ram[i] = 0;
for(i = 0x0; i < 0x100; i++)
u->dev[i] = 0;
u->wst.ptr = u->rst.ptr = 0;
}
void void
system_reboot(Uxn *u, char *rom, int soft) system_reboot(Uxn *u, char *rom, int soft)
{ {

View File

@ -15,10 +15,9 @@ WITH REGARD TO THIS SOFTWARE.
extern char *boot_rom; extern char *boot_rom;
int system_error(char *msg, const char *err);
void system_reboot(Uxn *u, char *rom, int soft); void system_reboot(Uxn *u, char *rom, int soft);
void system_inspect(Uxn *u); void system_inspect(Uxn *u);
int system_version(char *emulator, char *date);
int system_error(char *msg, const char *err);
int system_init(Uxn *u, Uint8 *ram, char *rom); int system_init(Uxn *u, Uint8 *ram, char *rom);
Uint8 system_dei(Uxn *u, Uint8 addr); Uint8 system_dei(Uxn *u, Uint8 addr);

View File

@ -35,7 +35,6 @@ 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

@ -18,8 +18,6 @@ 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)
{ {
@ -47,12 +45,13 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int i = 1; int i = 1;
Uxn u = {0};
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..]");
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_error("Uxncli - Varvara Emulator(CLI)", "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.");
/* eval */ /* eval */

View File

@ -46,8 +46,6 @@ 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;
@ -490,34 +488,34 @@ main(int argc, char **argv)
{ {
Uint8 *ram; Uint8 *ram;
char *rom; char *rom;
Uxn u = {0};
Uint8 dev[0x100] = {0}; Uint8 dev[0x100] = {0};
Uxn 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;
if(i == argc) /* flags */
return system_error("usage", "uxnemu [-v] | uxnemu [-f | -2x | -3x | --] file.rom [args...]"); if(argc > 1 && argv[i][0] == '-') {
/* Read flag. Right now, there can be only one. */ if(!strcmp(argv[i], "-v"))
if(argv[i][0] == '-') { return system_error("Uxnemu - Varvara Emulator(GUI)", "2 Jan 2024.");
if(argv[i][1] == 'v') else if(!strcmp(argv[i], "-2x"))
return system_version("Uxnemu - Graphical Varvara Emulator", "2 Jan 2024"); set_zoom(2, 0);
if(argv[i][1] == '-') else if(!strcmp(argv[i], "-3x"))
i++; set_zoom(3, 0);
if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0) else if(strcmp(argv[i], "-f") == 0)
set_zoom(argv[i++][1] - '0', 0);
if(strcmp(argv[i], "-f") == 0) {
i++;
set_fullscreen(1, 0); set_fullscreen(1, 0);
} i++;
} }
/* Start system. */ if(i == argc)
return system_error("usage", "uxnemu [-v | -f | -2x | -3x] file.rom [args...]");
/* start */
ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)); ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8));
rom = argv[i++]; rom = argv[i++];
if(!system_init(&u, ram, rom) || !system_init(&u_audio, ram, rom)) if(!system_init(&u, ram, rom) || !system_init(&u_audio, ram, rom))
return system_error("Init", "Failed to initialize uxn."); return system_error("Init", "Failed to initialize uxn.");
if(!emu_init(&u_audio)) if(!emu_init(&u_audio))
return system_error("Init", "Failed to initialize varvara."); return system_error("Init", "Failed to initialize varvara.");
/* Game Loop */ /* loop */
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);