1 |
|
/* |
2 |
|
* rom_patches.cpp - ROM patches |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2000 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
38 |
|
#include "debug.h" |
39 |
|
|
40 |
|
|
41 |
– |
// Breakpoint |
42 |
– |
//#define M68K_BREAKPOINT 0x2310 // CritError |
43 |
– |
//#define M68K_BREAKPOINT 0x1d10 // BootMe |
44 |
– |
|
41 |
|
// Global variables |
42 |
< |
uint32 UniversalInfo; // ROM offset of UniversalInfo |
43 |
< |
uint32 PutScrapPatch; // Mac address of PutScrap() patch |
42 |
> |
uint32 UniversalInfo; // ROM offset of UniversalInfo |
43 |
> |
uint32 PutScrapPatch; // Mac address of PutScrap() patch |
44 |
> |
uint32 ROMBreakpoint = 0; // ROM offset of breakpoint (0 = disabled, 0x2310 = CritError) |
45 |
> |
bool PrintROMInfo = false; // Flag: print ROM information in PatchROM() |
46 |
|
|
47 |
|
static uint32 sony_offset; // ROM offset of .Sony driver |
48 |
|
static uint32 serd_offset; // ROM offset of SERD resource (serial drivers) |
49 |
|
static uint32 microseconds_offset; // ROM offset of Microseconds() replacement routine |
52 |
– |
static uint32 memory_dispatch_offset; // ROM offset of MemoryDispatch() replacement routine |
50 |
|
|
51 |
|
// Prototypes |
52 |
|
uint16 ROMVersion; |
81 |
|
|
82 |
|
if (!cont) |
83 |
|
rsrc_ptr = x; |
84 |
+ |
else |
85 |
+ |
rsrc_ptr = ReadMacInt32(ROMBaseMac + rsrc_ptr + 8); |
86 |
|
|
87 |
|
for (;;) { |
88 |
|
lp = ROMBaseMac + rsrc_ptr; |
141 |
|
|
142 |
|
|
143 |
|
/* |
144 |
+ |
* Print ROM information to stream, |
145 |
+ |
*/ |
146 |
+ |
|
147 |
+ |
static void list_rom_resources(void) |
148 |
+ |
{ |
149 |
+ |
printf("ROM Resources:\n"); |
150 |
+ |
printf("Offset\t Type\tID\tSize\tName\n"); |
151 |
+ |
printf("------------------------------------------------\n"); |
152 |
+ |
|
153 |
+ |
uint32 lp = ROMBaseMac + ReadMacInt32(ROMBaseMac + 0x1a); |
154 |
+ |
uint32 rsrc_ptr = ReadMacInt32(lp); |
155 |
+ |
|
156 |
+ |
for (;;) { |
157 |
+ |
lp = ROMBaseMac + rsrc_ptr; |
158 |
+ |
uint32 data = ReadMacInt32(lp + 12); |
159 |
+ |
|
160 |
+ |
char name[32]; |
161 |
+ |
int name_len = ReadMacInt8(lp + 23), i; |
162 |
+ |
for (i=0; i<name_len; i++) |
163 |
+ |
name[i] = ReadMacInt8(lp + 24 + i); |
164 |
+ |
name[i] = 0; |
165 |
+ |
|
166 |
+ |
printf("%08x %c%c%c%c\t%d\t%d\t%s\n", data, ReadMacInt8(lp + 16), ReadMacInt8(lp + 17), ReadMacInt8(lp + 18), ReadMacInt8(lp + 19), ReadMacInt16(lp + 20), ReadMacInt32(ROMBaseMac + data - 8), name); |
167 |
+ |
|
168 |
+ |
rsrc_ptr = ReadMacInt32(lp + 8); |
169 |
+ |
if (!rsrc_ptr) |
170 |
+ |
break; |
171 |
+ |
} |
172 |
+ |
printf("\n"); |
173 |
+ |
} |
174 |
+ |
|
175 |
+ |
// Mapping of Model IDs to Model names |
176 |
+ |
struct mac_desc { |
177 |
+ |
char *name; |
178 |
+ |
int32 id; |
179 |
+ |
}; |
180 |
+ |
|
181 |
+ |
static mac_desc MacDesc[] = { |
182 |
+ |
{"Classic" , 1}, |
183 |
+ |
{"Mac XL" , 2}, |
184 |
+ |
{"Mac 512KE" , 3}, |
185 |
+ |
{"Mac Plus" , 4}, |
186 |
+ |
{"Mac SE" , 5}, |
187 |
+ |
{"Mac II" , 6}, |
188 |
+ |
{"Mac IIx" , 7}, |
189 |
+ |
{"Mac IIcx" , 8}, |
190 |
+ |
{"Mac SE/030" , 9}, |
191 |
+ |
{"Mac Portable" , 10}, |
192 |
+ |
{"Mac IIci" , 11}, |
193 |
+ |
{"Mac IIfx" , 13}, |
194 |
+ |
{"Mac Classic" , 17}, |
195 |
+ |
{"Mac IIsi" , 18}, |
196 |
+ |
{"Mac LC" , 19}, |
197 |
+ |
{"Quadra 900" , 20}, |
198 |
+ |
{"PowerBook 170" , 21}, |
199 |
+ |
{"Quadra 700" , 22}, |
200 |
+ |
{"Classic II" , 23}, |
201 |
+ |
{"PowerBook 100" , 24}, |
202 |
+ |
{"PowerBook 140" , 25}, |
203 |
+ |
{"Quadra 950" , 26}, |
204 |
+ |
{"Mac LCIII/Performa 450", 27}, |
205 |
+ |
{"PowerBook Duo 210" , 29}, |
206 |
+ |
{"Centris 650" , 30}, |
207 |
+ |
{"PowerBook Duo 230" , 32}, |
208 |
+ |
{"PowerBook 180" , 33}, |
209 |
+ |
{"PowerBook 160" , 34}, |
210 |
+ |
{"Quadra 800" , 35}, |
211 |
+ |
{"Quadra 650" , 36}, |
212 |
+ |
{"Mac LCII" , 37}, |
213 |
+ |
{"PowerBook Duo 250" , 38}, |
214 |
+ |
{"Mac IIvi" , 44}, |
215 |
+ |
{"Mac IIvm/Performa 600", 45}, |
216 |
+ |
{"Mac IIvx" , 48}, |
217 |
+ |
{"Color Classic/Performa 250", 49}, |
218 |
+ |
{"PowerBook 165c" , 50}, |
219 |
+ |
{"Centris 610" , 52}, |
220 |
+ |
{"Quadra 610" , 53}, |
221 |
+ |
{"PowerBook 145" , 54}, |
222 |
+ |
{"Mac LC520" , 56}, |
223 |
+ |
{"Quadra/Centris 660AV" , 60}, |
224 |
+ |
{"Performa 46x" , 62}, |
225 |
+ |
{"PowerBook 180c" , 71}, |
226 |
+ |
{"PowerBook 520/520c/540/540c", 72}, |
227 |
+ |
{"PowerBook Duo 270c" , 77}, |
228 |
+ |
{"Quadra 840AV" , 78}, |
229 |
+ |
{"Performa 550" , 80}, |
230 |
+ |
{"PowerBook 165" , 84}, |
231 |
+ |
{"PowerBook 190" , 85}, |
232 |
+ |
{"Mac TV" , 88}, |
233 |
+ |
{"Mac LC475/Performa 47x", 89}, |
234 |
+ |
{"Mac LC575" , 92}, |
235 |
+ |
{"Quadra 605" , 94}, |
236 |
+ |
{"Quadra 630" , 98}, |
237 |
+ |
{"Mac LC580" , 99}, |
238 |
+ |
{"PowerBook Duo 280" , 102}, |
239 |
+ |
{"PowerBook Duo 280c" , 103}, |
240 |
+ |
{"PowerBook 150" , 115}, |
241 |
+ |
{"unknown", -1} |
242 |
+ |
}; |
243 |
+ |
|
244 |
+ |
static void print_universal_info(uint32 info) |
245 |
+ |
{ |
246 |
+ |
uint8 id = ReadMacInt8(info + 18); |
247 |
+ |
uint16 hwcfg = ReadMacInt16(info + 16); |
248 |
+ |
uint16 rom85 = ReadMacInt16(info + 20); |
249 |
+ |
|
250 |
+ |
// Find model name |
251 |
+ |
char *name = "unknown"; |
252 |
+ |
for (int i=0; MacDesc[i].id >= 0; i++) |
253 |
+ |
if (MacDesc[i].id == id + 6) { |
254 |
+ |
name = MacDesc[i].name; |
255 |
+ |
break; |
256 |
+ |
} |
257 |
+ |
|
258 |
+ |
printf("%08x %02x\t%04x\t%04x\t%s\n", info - ROMBaseMac, id, hwcfg, rom85, name); |
259 |
+ |
} |
260 |
+ |
|
261 |
+ |
static void list_universal_infos(void) |
262 |
+ |
{ |
263 |
+ |
uint32 ofs = 0x3000; |
264 |
+ |
for (int i=0; i<0x2000; i+=2, ofs+=2) |
265 |
+ |
if (ReadMacInt32(ROMBaseMac + ofs) == 0xdc000505) { |
266 |
+ |
ofs -= 16; |
267 |
+ |
uint32 q; |
268 |
+ |
for (q=ofs; q > 0 && ReadMacInt32(ROMBaseMac + q) != ofs - q; q-=4) ; |
269 |
+ |
if (q > 0) { |
270 |
+ |
printf("Universal Table at %08x:\n", q); |
271 |
+ |
printf("Offset\t ID\tHWCfg\tROM85\tModel\n"); |
272 |
+ |
printf("------------------------------------------------\n"); |
273 |
+ |
while (ofs = ReadMacInt32(ROMBaseMac + q)) { |
274 |
+ |
print_universal_info(ROMBaseMac + ofs + q); |
275 |
+ |
q += 4; |
276 |
+ |
} |
277 |
+ |
} |
278 |
+ |
break; |
279 |
+ |
} |
280 |
+ |
printf("\n"); |
281 |
+ |
} |
282 |
+ |
|
283 |
+ |
static void print_rom_info(void) |
284 |
+ |
{ |
285 |
+ |
printf("\nROM Info:\n"); |
286 |
+ |
printf("Checksum : %08x\n", ReadMacInt32(ROMBaseMac)); |
287 |
+ |
printf("Version : %04x\n", ROMVersion); |
288 |
+ |
printf("Sub Version : %04x\n", ReadMacInt16(ROMBaseMac + 18)); |
289 |
+ |
printf("Resource Map: %08x\n", ReadMacInt32(ROMBaseMac + 26)); |
290 |
+ |
printf("Trap Tables : %08x\n\n", ReadMacInt32(ROMBaseMac + 34)); |
291 |
+ |
if (ROMVersion == ROM_VERSION_32) { |
292 |
+ |
list_rom_resources(); |
293 |
+ |
list_universal_infos(); |
294 |
+ |
} |
295 |
+ |
} |
296 |
+ |
|
297 |
+ |
|
298 |
+ |
/* |
299 |
|
* Driver stubs |
300 |
|
*/ |
301 |
|
|
796 |
|
|
797 |
|
void PatchAfterStartup(void) |
798 |
|
{ |
645 |
– |
// Install MemoryDispatch() replacement routine |
646 |
– |
M68kRegisters r; |
647 |
– |
r.a[0] = ROMBaseMac + memory_dispatch_offset; |
648 |
– |
r.d[0] = 0xa05c; |
649 |
– |
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
650 |
– |
|
799 |
|
#if SUPPORTS_EXTFS |
800 |
|
// Install external file system |
801 |
|
InstallExtFS(); |
1451 |
|
} |
1452 |
|
} |
1453 |
|
|
1454 |
+ |
// Don't set MemoryDispatch() to unimplemented trap |
1455 |
+ |
static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47}; |
1456 |
+ |
base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat)); |
1457 |
+ |
D(bug("memdisp %08lx\n", base)); |
1458 |
+ |
if (base) { // ROM15/22/23/26/27/32 |
1459 |
+ |
wp = (uint16 *)(ROMBaseHost + base + 10); |
1460 |
+ |
*wp = htons(M68K_NOP); |
1461 |
+ |
} |
1462 |
+ |
|
1463 |
|
// Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000) |
1464 |
|
uint32 edisk_offset = find_rom_resource('DRVR', 51); |
1465 |
|
if (edisk_offset) { |
1561 |
|
*wp++ = htons(base >> 16); |
1562 |
|
*wp = htons(base & 0xffff); |
1563 |
|
|
1407 |
– |
// Install MemoryDispatch() replacement routine (activated in PatchAfterStartup()) |
1408 |
– |
memory_dispatch_offset = sony_offset + 0xc20; |
1409 |
– |
wp = (uint16 *)(ROMBaseHost + memory_dispatch_offset); |
1410 |
– |
*wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH); |
1411 |
– |
*wp = htons(M68K_RTS); |
1412 |
– |
|
1564 |
|
#if EMULATED_68K |
1565 |
|
// Replace BlockMove() |
1566 |
|
wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e)); // BlockMove() |
1569 |
|
*wp = htons(M68K_RTS); |
1570 |
|
#endif |
1571 |
|
|
1572 |
+ |
// Look for double PACK 4 resources |
1573 |
+ |
if ((base = find_rom_resource('PACK', 4)) == 0) return false; |
1574 |
+ |
if ((base = find_rom_resource('PACK', 4, true)) == 0 && FPUType == 0) |
1575 |
+ |
printf("WARNING: This ROM seems to require an FPU\n"); |
1576 |
+ |
|
1577 |
|
// Patch VIA interrupt handler |
1578 |
|
wp = (uint16 *)(ROMBaseHost + 0x9bc4); // Level 1 handler |
1579 |
|
*wp++ = htons(0x7002); // moveq #2,d0 (always 60Hz interrupt) |
1591 |
|
|
1592 |
|
bool PatchROM(void) |
1593 |
|
{ |
1594 |
< |
// Print ROM info |
1595 |
< |
D(bug("ROM Info:\n")); |
1596 |
< |
D(bug("Checksum: %08lx\n", ReadMacInt32(ROMBaseMac))); |
1441 |
< |
D(bug("Version: %04x\n", ROMVersion)); |
1442 |
< |
D(bug("Sub Version: %04x\n", ReadMacInt16(ROMBaseMac + 18))); |
1594 |
> |
// Print some information about the ROM |
1595 |
> |
if (PrintROMInfo) |
1596 |
> |
print_rom_info(); |
1597 |
|
|
1598 |
|
// Patch ROM depending on version |
1599 |
|
switch (ROMVersion) { |
1609 |
|
return false; |
1610 |
|
} |
1611 |
|
|
1458 |
– |
#ifdef M68K_BREAKPOINT |
1612 |
|
// Install breakpoint |
1613 |
< |
uint16 *wp = (uint16 *)(ROMBaseHost + M68K_BREAKPOINT); |
1614 |
< |
*wp = htons(M68K_EMUL_BREAK); |
1615 |
< |
#endif |
1613 |
> |
if (ROMBreakpoint) { |
1614 |
> |
uint16 *wp = (uint16 *)(ROMBaseHost + ROMBreakpoint); |
1615 |
> |
*wp = htons(M68K_EMUL_BREAK); |
1616 |
> |
} |
1617 |
|
|
1618 |
|
// Clear caches as we loaded and patched code |
1619 |
|
FlushCodeCache(ROMBaseHost, ROMSize); |