commit 828a81c

Devine Lu Linvega  ·  2024-11-13 00:20:24 +0000 UTC
parent 64fed1c
Booting bios
2 files changed,  +31, -21
+29, -20
 1@@ -15,28 +15,29 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 2 WITH REGARD TO THIS SOFTWARE.
 3 */
 4 
 5+Uxn bios;
 6 char *boot_rom;
 7 Uint8 bios_ram[0x10000];
 8 
 9 static void
10-system_zero(int soft)
11+system_zero(Uxn *u, int soft)
12 {
13 	int i;
14 	for(i = soft ? 0x100 : 0; i < 0x10000; i++)
15-		uxn.ram[i] = 0;
16+		u->ram[i] = 0;
17 	for(i = 0x0; i < 0x100; i++)
18-		uxn.dev[i] = 0;
19-	uxn.wst.ptr = uxn.rst.ptr = 0;
20+		u->dev[i] = 0;
21+	u->wst.ptr = u->rst.ptr = 0;
22 }
23 
24 static int
25-system_load(char *filename)
26+system_load(Uint8 *ram, char *filename)
27 {
28 	FILE *f = fopen(filename, "rb");
29 	if(f) {
30-		int i = 0, l = fread(&uxn.ram[PAGE_PROGRAM], 0x10000 - PAGE_PROGRAM, 1, f);
31+		int i = 0, l = fread(ram, 0x10000 - PAGE_PROGRAM, 1, f);
32 		while(l && ++i < RAM_PAGES)
33-			l = fread(uxn.ram + 0x10000 * i, 0x10000, 1, f);
34+			l = fread(ram + 0x10000 * i, 0x10000, 1, f);
35 		fclose(f);
36 	}
37 	return !!f;
38@@ -69,25 +70,33 @@ system_error(char *msg, const char *err)
39 void
40 system_reboot(char *rom, int soft)
41 {
42-	system_zero(soft);
43-	if(system_load(boot_rom))
44+	system_zero(&uxn, soft);
45+	if(system_load(&uxn.ram[PAGE_PROGRAM], boot_rom))
46 		if(uxn_eval(&uxn, PAGE_PROGRAM))
47 			boot_rom = rom;
48 }
49 
50 int
51-system_boot(Uint8 *ram, char *rom)
52+system_boot(Uint8 *ram, char *boot)
53 {
54-	uxn.ram = ram;
55-	uxn.dev = bios_ram + 0x8000;
56-	uxn.wst.dat = bios_ram + 0x8100;
57-	uxn.rst.dat = bios_ram + 0x8200;
58-	system_zero(0);
59-	if(!system_load(rom))
60-		if(!system_load("boot.rom"))
61-			return system_error("Could not load rom", rom);
62-	boot_rom = rom;
63-	return 1;
64+	/* Load rom(bios) */
65+	if(system_load(&bios_ram[PAGE_PROGRAM], "bios.rom")) {
66+		bios.ram = bios_ram;
67+		bios.dev = bios_ram + 0x8300;
68+		bios.wst.dat = bios_ram + 0x8400;
69+		bios.rst.dat = bios_ram + 0x8500;
70+		bios.dev[0xe] = 0xff;
71+	}
72+	/* Load rom(main) */
73+	if(system_load(&ram[PAGE_PROGRAM], boot)) {
74+		uxn.ram = ram;
75+		uxn.dev = bios_ram + 0x8000;
76+		uxn.wst.dat = bios_ram + 0x8100;
77+		uxn.rst.dat = bios_ram + 0x8200;
78+		boot_rom = boot;
79+		return 1;
80+	}
81+	return system_error("Could not load rom", boot);
82 }
83 
84 /* IO */
+2, -1
1@@ -19,4 +19,5 @@ int system_boot(Uint8 *ram, char *rom);
2 Uint8 system_dei(Uint8 addr);
3 void system_deo(Uint8 addr);
4 
5-extern char *boot_rom;
6+extern char *boot_rom;
7+extern Uxn bios;