Browse code

Combined all system reboots

neauoire authored on 16/08/2023 02:19:06
Showing 4 changed files
... ...
@@ -28,5 +28,6 @@ void screen_resize(Uint16 width, Uint16 height);
28 28
 void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2);
29 29
 void screen_redraw(void);
30 30
 void screen_debugger(Uxn *u);
31
+
31 32
 Uint8 screen_dei(Uxn *u, Uint8 addr);
32 33
 void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port);
... ...
@@ -96,12 +96,28 @@ system_version(char *name, char *date)
96 96
 	return 0;
97 97
 }
98 98
 
99
+void
100
+system_reboot(Uxn *u, char *rom, int soft)
101
+{
102
+	int i;
103
+	for(i = 0x100 * soft; i < 0x10000; i++)
104
+		u->ram[i] = 0;
105
+	for(i = 0x0; i < 0x100; i++)
106
+		u->dev[i] = 0;
107
+	u->wst.ptr = 0;
108
+	u->rst.ptr = 0;
109
+	if(system_load(u, boot_rom))
110
+		if(uxn_eval(u, PAGE_PROGRAM))
111
+			boot_rom = rom;
112
+}
113
+
99 114
 int
100 115
 system_init(Uxn *u, Uint8 *ram, char *rom)
101 116
 {
102 117
 	u->ram = ram;
103 118
 	if(!system_load(u, rom))
104
-		return system_error("Init", "Failed to load rom.");
119
+		if(!system_load(u, "boot.rom"))
120
+			return system_error("Init", "Failed to load rom.");
105 121
 	boot_rom = rom;
106 122
 	return 1;
107 123
 }
... ...
@@ -18,9 +18,11 @@ WITH REGARD TO THIS SOFTWARE.
18 18
 extern char *boot_rom;
19 19
 
20 20
 void system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo);
21
+void system_reboot(Uxn *u, char *rom, int soft);
22
+void system_inspect(Uxn *u);
21 23
 int system_version(char *emulator, char *date);
22 24
 int system_load(Uxn *u, char *filename);
23
-void system_inspect(Uxn *u);
24 25
 int system_error(char *msg, const char *err);
25 26
 int system_init(Uxn *u, Uint8 *ram, char *rom);
27
+
26 28
 void system_deo(Uxn *u, Uint8 *d, Uint8 port);
... ...
@@ -255,43 +255,14 @@ emu_init(void)
255 255
 	return 1;
256 256
 }
257 257
 
258
-static int
259
-emu_start(Uxn *u, char *rom)
260
-{
261
-	exec_deadline = SDL_GetPerformanceCounter() + deadline_interval;
262
-	screen_resize(WIDTH, HEIGHT);
263
-	if(!uxn_eval(u, PAGE_PROGRAM))
264
-		return system_error("Boot", "Failed to eval rom.");
265
-	SDL_SetWindowTitle(emu_window, rom);
266
-	return 1;
267
-}
268
-
269 258
 static void
270
-emu_restart(Uxn *u)
259
+emu_restart(Uxn *u, char *rom, int soft)
271 260
 {
272 261
 	screen_resize(WIDTH, HEIGHT);
273
-	SDL_SetWindowTitle(emu_window, boot_rom);
274
-	if(!emu_start(u, "launcher.rom"))
275
-		emu_start(u, boot_rom);
276
-}
277
-
278
-static int
279
-emu_restart_soft(Uxn *u)
280
-{
281
-	int i;
282
-	for(i = 0x100; i < 0x10000; i++)
283
-		u->ram[i] = 0;
284
-	for(i = 0x0; i < 0x100; i++)
285
-		u->dev[i] = 0;
286
-	u->wst.ptr = 0;
287
-	u->rst.ptr = 0;
288 262
 	screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
289 263
 	screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
290
-	if(!system_load(u, boot_rom))
291
-		return system_error("Boot", "Failed to load rom.");
292
-	if(!uxn_eval(u, PAGE_PROGRAM))
293
-		return system_error("Boot", "Failed to eval rom.");
294
-	return 1;
264
+	system_reboot(u, rom, soft);
265
+	SDL_SetWindowTitle(emu_window, boot_rom);
295 266
 }
296 267
 
297 268
 static void
... ...
@@ -384,8 +355,7 @@ handle_events(Uxn *u)
384 355
 		else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED)
385 356
 			emu_redraw(u);
386 357
 		else if(event.type == SDL_DROPFILE) {
387
-			screen_resize(WIDTH, HEIGHT);
388
-			emu_start(u, event.drop.file);
358
+			emu_restart(u, event.drop.file, 0);
389 359
 			SDL_free(event.drop.file);
390 360
 		}
391 361
 		/* Audio */
... ...
@@ -416,9 +386,9 @@ handle_events(Uxn *u)
416 386
 			else if(event.key.keysym.sym == SDLK_F3)
417 387
 				capture_screen();
418 388
 			else if(event.key.keysym.sym == SDLK_F4)
419
-				emu_restart(u);
389
+				emu_restart(u, boot_rom, 0);
420 390
 			else if(event.key.keysym.sym == SDLK_F5)
421
-				emu_restart_soft(u);
391
+				emu_restart(u, boot_rom, 1);
422 392
 			ksym = event.key.keysym.sym;
423 393
 			if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYUP, SDL_KEYUP) == 1 && ksym == event.key.keysym.sym)
424 394
 				return 1;