Try loading rom during system init

This commit is contained in:
neauoire 2023-08-15 16:06:29 -07:00
parent 9a7a11003f
commit c0d45d1440
4 changed files with 11 additions and 17 deletions

View File

@ -95,9 +95,11 @@ system_version(char *name, char *date)
}
int
system_boot(Uxn *u, Uint8 *ram)
system_init(Uxn *u, Uint8 *ram, char *rom)
{
u->ram = ram;
if(!system_load(u, rom))
return system_error("Init", "Failed to load rom.");
return 1;
}

View File

@ -20,5 +20,5 @@ int system_version(char *emulator, char *date);
int system_load(Uxn *u, char *filename);
void system_inspect(Uxn *u);
int system_error(char *msg, const char *err);
int system_boot(Uxn *u, Uint8 *ram);
int system_init(Uxn *u, Uint8 *ram, char *rom);
void system_deo(Uxn *u, Uint8 *d, Uint8 port);

View File

@ -57,12 +57,8 @@ main(int argc, char **argv)
/* Read flags */
if(argv[i][0] == '-' && argv[i][1] == 'v')
return system_version("Uxncli - Console Varvara Emulator", "9 Aug 2023");
/* Continue.. */
if(!system_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
return system_error("Boot", "Failed");
/* Load rom */
if(!system_load(&u, argv[i++]))
return system_error("Load", "Failed");
if(!system_init(&u, (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)) {

View File

@ -257,11 +257,6 @@ emu_init(void)
static int
emu_start(Uxn *u, char *rom, int queue)
{
free(u->ram);
if(!system_boot(u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
return system_error("Boot", "Failed to start uxn.");
if(!system_load(u, rom))
return system_error("Boot", "Failed to load rom.");
u->dev[0x17] = queue;
exec_deadline = SDL_GetPerformanceCounter() + deadline_interval;
screen_resize(WIDTH, HEIGHT);
@ -545,11 +540,12 @@ main(int argc, char **argv)
return system_version("Uxnemu - Graphical Varvara Emulator", "10 Aug 2023");
if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)
set_zoom(argv[i++][1] - '0', 0);
/* Continue.. */
if(!emu_init())
return system_error("Init", "Failed to initialize emulator.");
/* load rom */
rom_path = argv[i++];
if(!emu_init())
return system_error("Init", "Failed to initialize varvara.");
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom_path))
return system_error("Init", "Failed to initialize uxn.");
/* load rom */
if(!emu_start(&u, rom_path, argc - i))
return system_error("Start", "Failed");
/* read arguments */