Browse code

Try loading rom during system init

neauoire authored on 15/08/2023 23:06:29
Showing 4 changed files
... ...
@@ -95,9 +95,11 @@ system_version(char *name, char *date)
95 95
 }
96 96
 
97 97
 int
98
-system_boot(Uxn *u, Uint8 *ram)
98
+system_init(Uxn *u, Uint8 *ram, char *rom)
99 99
 {
100 100
 	u->ram = ram;
101
+	if(!system_load(u, rom))
102
+		return system_error("Init", "Failed to load rom.");
101 103
 	return 1;
102 104
 }
103 105
 
... ...
@@ -20,5 +20,5 @@ int system_version(char *emulator, char *date);
20 20
 int system_load(Uxn *u, char *filename);
21 21
 void system_inspect(Uxn *u);
22 22
 int system_error(char *msg, const char *err);
23
-int system_boot(Uxn *u, Uint8 *ram);
23
+int system_init(Uxn *u, Uint8 *ram, char *rom);
24 24
 void system_deo(Uxn *u, Uint8 *d, Uint8 port);
... ...
@@ -57,12 +57,8 @@ main(int argc, char **argv)
57 57
 	/* Read flags */
58 58
 	if(argv[i][0] == '-' && argv[i][1] == 'v')
59 59
 		return system_version("Uxncli - Console Varvara Emulator", "9 Aug 2023");
60
-	/* Continue.. */
61
-	if(!system_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
62
-		return system_error("Boot", "Failed");
63
-	/* Load rom */
64
-	if(!system_load(&u, argv[i++]))
65
-		return system_error("Load", "Failed");
60
+	if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
61
+		return system_error("Init", "Failed to initialize uxn.");
66 62
 	/* Game Loop */
67 63
 	u.dev[0x17] = argc - i;
68 64
 	if(uxn_eval(&u, PAGE_PROGRAM)) {
... ...
@@ -257,11 +257,6 @@ emu_init(void)
257 257
 static int
258 258
 emu_start(Uxn *u, char *rom, int queue)
259 259
 {
260
-	free(u->ram);
261
-	if(!system_boot(u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
262
-		return system_error("Boot", "Failed to start uxn.");
263
-	if(!system_load(u, rom))
264
-		return system_error("Boot", "Failed to load rom.");
265 260
 	u->dev[0x17] = queue;
266 261
 	exec_deadline = SDL_GetPerformanceCounter() + deadline_interval;
267 262
 	screen_resize(WIDTH, HEIGHT);
... ...
@@ -545,11 +540,12 @@ main(int argc, char **argv)
545 540
 		return system_version("Uxnemu - Graphical Varvara Emulator", "10 Aug 2023");
546 541
 	if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)
547 542
 		set_zoom(argv[i++][1] - '0', 0);
548
-	/* Continue.. */
543
+	rom_path = argv[i++];
549 544
 	if(!emu_init())
550
-		return system_error("Init", "Failed to initialize emulator.");
545
+		return system_error("Init", "Failed to initialize varvara.");
546
+	if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), rom_path))
547
+		return system_error("Init", "Failed to initialize uxn.");
551 548
 	/* load rom */
552
-	rom_path = argv[i++];
553 549
 	if(!emu_start(&u, rom_path, argc - i))
554 550
 		return system_error("Start", "Failed");
555 551
 	/* read arguments */