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 |
30 |
|
#include "disk.h" |
31 |
|
#include "cdrom.h" |
32 |
|
#include "video.h" |
33 |
+ |
#include "extfs.h" |
34 |
|
#include "prefs.h" |
35 |
|
#include "rom_patches.h" |
36 |
|
|
38 |
|
#include "debug.h" |
39 |
|
|
40 |
|
|
40 |
– |
// Breakpoint |
41 |
– |
//#define M68K_BREAKPOINT 0x2310 // CritError |
42 |
– |
//#define M68K_BREAKPOINT 0x1d10 // BootMe |
43 |
– |
|
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 |
50 |
< |
static uint32 memory_dispatch_offset; // ROM offset of MemoryDispatch() replacement routine |
50 |
> |
static uint32 debugutil_offset; // ROM offset of DebugUtil() replacement routine |
51 |
|
|
52 |
|
// Prototypes |
53 |
|
uint16 ROMVersion; |
82 |
|
|
83 |
|
if (!cont) |
84 |
|
rsrc_ptr = x; |
85 |
+ |
else |
86 |
+ |
rsrc_ptr = ReadMacInt32(ROMBaseMac + rsrc_ptr + 8); |
87 |
|
|
88 |
|
for (;;) { |
89 |
|
lp = ROMBaseMac + rsrc_ptr; |
142 |
|
|
143 |
|
|
144 |
|
/* |
145 |
+ |
* Print ROM information to stream, |
146 |
+ |
*/ |
147 |
+ |
|
148 |
+ |
static void list_rom_resources(void) |
149 |
+ |
{ |
150 |
+ |
printf("ROM Resources:\n"); |
151 |
+ |
printf("Offset\t Type\tID\tSize\tName\n"); |
152 |
+ |
printf("------------------------------------------------\n"); |
153 |
+ |
|
154 |
+ |
uint32 lp = ROMBaseMac + ReadMacInt32(ROMBaseMac + 0x1a); |
155 |
+ |
uint32 rsrc_ptr = ReadMacInt32(lp); |
156 |
+ |
|
157 |
+ |
for (;;) { |
158 |
+ |
lp = ROMBaseMac + rsrc_ptr; |
159 |
+ |
uint32 data = ReadMacInt32(lp + 12); |
160 |
+ |
|
161 |
+ |
char name[32]; |
162 |
+ |
int name_len = ReadMacInt8(lp + 23), i; |
163 |
+ |
for (i=0; i<name_len; i++) |
164 |
+ |
name[i] = ReadMacInt8(lp + 24 + i); |
165 |
+ |
name[i] = 0; |
166 |
+ |
|
167 |
+ |
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); |
168 |
+ |
|
169 |
+ |
rsrc_ptr = ReadMacInt32(lp + 8); |
170 |
+ |
if (!rsrc_ptr) |
171 |
+ |
break; |
172 |
+ |
} |
173 |
+ |
printf("\n"); |
174 |
+ |
} |
175 |
+ |
|
176 |
+ |
// Mapping of Model IDs to Model names |
177 |
+ |
struct mac_desc { |
178 |
+ |
char *name; |
179 |
+ |
int32 id; |
180 |
+ |
}; |
181 |
+ |
|
182 |
+ |
static mac_desc MacDesc[] = { |
183 |
+ |
{"Classic" , 1}, |
184 |
+ |
{"Mac XL" , 2}, |
185 |
+ |
{"Mac 512KE" , 3}, |
186 |
+ |
{"Mac Plus" , 4}, |
187 |
+ |
{"Mac SE" , 5}, |
188 |
+ |
{"Mac II" , 6}, |
189 |
+ |
{"Mac IIx" , 7}, |
190 |
+ |
{"Mac IIcx" , 8}, |
191 |
+ |
{"Mac SE/030" , 9}, |
192 |
+ |
{"Mac Portable" , 10}, |
193 |
+ |
{"Mac IIci" , 11}, |
194 |
+ |
{"Mac IIfx" , 13}, |
195 |
+ |
{"Mac Classic" , 17}, |
196 |
+ |
{"Mac IIsi" , 18}, |
197 |
+ |
{"Mac LC" , 19}, |
198 |
+ |
{"Quadra 900" , 20}, |
199 |
+ |
{"PowerBook 170" , 21}, |
200 |
+ |
{"Quadra 700" , 22}, |
201 |
+ |
{"Classic II" , 23}, |
202 |
+ |
{"PowerBook 100" , 24}, |
203 |
+ |
{"PowerBook 140" , 25}, |
204 |
+ |
{"Quadra 950" , 26}, |
205 |
+ |
{"Mac LCIII/Performa 450", 27}, |
206 |
+ |
{"PowerBook Duo 210" , 29}, |
207 |
+ |
{"Centris 650" , 30}, |
208 |
+ |
{"PowerBook Duo 230" , 32}, |
209 |
+ |
{"PowerBook 180" , 33}, |
210 |
+ |
{"PowerBook 160" , 34}, |
211 |
+ |
{"Quadra 800" , 35}, |
212 |
+ |
{"Quadra 650" , 36}, |
213 |
+ |
{"Mac LCII" , 37}, |
214 |
+ |
{"PowerBook Duo 250" , 38}, |
215 |
+ |
{"Mac IIvi" , 44}, |
216 |
+ |
{"Mac IIvm/Performa 600", 45}, |
217 |
+ |
{"Mac IIvx" , 48}, |
218 |
+ |
{"Color Classic/Performa 250", 49}, |
219 |
+ |
{"PowerBook 165c" , 50}, |
220 |
+ |
{"Centris 610" , 52}, |
221 |
+ |
{"Quadra 610" , 53}, |
222 |
+ |
{"PowerBook 145" , 54}, |
223 |
+ |
{"Mac LC520" , 56}, |
224 |
+ |
{"Quadra/Centris 660AV" , 60}, |
225 |
+ |
{"Performa 46x" , 62}, |
226 |
+ |
{"PowerBook 180c" , 71}, |
227 |
+ |
{"PowerBook 520/520c/540/540c", 72}, |
228 |
+ |
{"PowerBook Duo 270c" , 77}, |
229 |
+ |
{"Quadra 840AV" , 78}, |
230 |
+ |
{"Performa 550" , 80}, |
231 |
+ |
{"PowerBook 165" , 84}, |
232 |
+ |
{"PowerBook 190" , 85}, |
233 |
+ |
{"Mac TV" , 88}, |
234 |
+ |
{"Mac LC475/Performa 47x", 89}, |
235 |
+ |
{"Mac LC575" , 92}, |
236 |
+ |
{"Quadra 605" , 94}, |
237 |
+ |
{"Quadra 630" , 98}, |
238 |
+ |
{"Mac LC580" , 99}, |
239 |
+ |
{"PowerBook Duo 280" , 102}, |
240 |
+ |
{"PowerBook Duo 280c" , 103}, |
241 |
+ |
{"PowerBook 150" , 115}, |
242 |
+ |
{"unknown", -1} |
243 |
+ |
}; |
244 |
+ |
|
245 |
+ |
static void print_universal_info(uint32 info) |
246 |
+ |
{ |
247 |
+ |
uint8 id = ReadMacInt8(info + 18); |
248 |
+ |
uint16 hwcfg = ReadMacInt16(info + 16); |
249 |
+ |
uint16 rom85 = ReadMacInt16(info + 20); |
250 |
+ |
|
251 |
+ |
// Find model name |
252 |
+ |
char *name = "unknown"; |
253 |
+ |
for (int i=0; MacDesc[i].id >= 0; i++) |
254 |
+ |
if (MacDesc[i].id == id + 6) { |
255 |
+ |
name = MacDesc[i].name; |
256 |
+ |
break; |
257 |
+ |
} |
258 |
+ |
|
259 |
+ |
printf("%08x %02x\t%04x\t%04x\t%s\n", info - ROMBaseMac, id, hwcfg, rom85, name); |
260 |
+ |
} |
261 |
+ |
|
262 |
+ |
static void list_universal_infos(void) |
263 |
+ |
{ |
264 |
+ |
uint32 ofs = 0x3000; |
265 |
+ |
for (int i=0; i<0x2000; i+=2, ofs+=2) |
266 |
+ |
if (ReadMacInt32(ROMBaseMac + ofs) == 0xdc000505) { |
267 |
+ |
ofs -= 16; |
268 |
+ |
uint32 q; |
269 |
+ |
for (q=ofs; q > 0 && ReadMacInt32(ROMBaseMac + q) != ofs - q; q-=4) ; |
270 |
+ |
if (q > 0) { |
271 |
+ |
printf("Universal Table at %08x:\n", q); |
272 |
+ |
printf("Offset\t ID\tHWCfg\tROM85\tModel\n"); |
273 |
+ |
printf("------------------------------------------------\n"); |
274 |
+ |
while ((ofs = ReadMacInt32(ROMBaseMac + q))) { |
275 |
+ |
print_universal_info(ROMBaseMac + ofs + q); |
276 |
+ |
q += 4; |
277 |
+ |
} |
278 |
+ |
} |
279 |
+ |
break; |
280 |
+ |
} |
281 |
+ |
printf("\n"); |
282 |
+ |
} |
283 |
+ |
|
284 |
+ |
static void print_rom_info(void) |
285 |
+ |
{ |
286 |
+ |
printf("\nROM Info:\n"); |
287 |
+ |
printf("Checksum : %08x\n", ReadMacInt32(ROMBaseMac)); |
288 |
+ |
printf("Version : %04x\n", ROMVersion); |
289 |
+ |
printf("Sub Version : %04x\n", ReadMacInt16(ROMBaseMac + 18)); |
290 |
+ |
printf("Resource Map: %08x\n", ReadMacInt32(ROMBaseMac + 26)); |
291 |
+ |
printf("Trap Tables : %08x\n\n", ReadMacInt32(ROMBaseMac + 34)); |
292 |
+ |
if (ROMVersion == ROM_VERSION_32) { |
293 |
+ |
list_rom_resources(); |
294 |
+ |
list_universal_infos(); |
295 |
+ |
} |
296 |
+ |
} |
297 |
+ |
|
298 |
+ |
|
299 |
+ |
/* |
300 |
|
* Driver stubs |
301 |
|
*/ |
302 |
|
|
303 |
|
static const uint8 sony_driver[] = { // Replacement for .Sony driver |
304 |
|
// Driver header |
305 |
< |
SonyDriverFlags >> 8, SonyDriverFlags & 0xff, SonyDriverDelay >> 8, SonyDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00, |
305 |
> |
SonyDriverFlags >> 8, SonyDriverFlags & 0xff, 0, 0, 0, 0, 0, 0, |
306 |
|
0x00, 0x18, // Open() offset |
307 |
|
0x00, 0x1c, // Prime() offset |
308 |
|
0x00, 0x20, // Control() offset |
350 |
|
|
351 |
|
static const uint8 disk_driver[] = { // Generic disk driver |
352 |
|
// Driver header |
353 |
< |
DiskDriverFlags >> 8, DiskDriverFlags & 0xff, DiskDriverDelay >> 8, DiskDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00, |
353 |
> |
DiskDriverFlags >> 8, DiskDriverFlags & 0xff, 0, 0, 0, 0, 0, 0, |
354 |
|
0x00, 0x18, // Open() offset |
355 |
|
0x00, 0x1c, // Prime() offset |
356 |
|
0x00, 0x20, // Control() offset |
398 |
|
|
399 |
|
static const uint8 cdrom_driver[] = { // CD-ROM driver |
400 |
|
// Driver header |
401 |
< |
CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, CDROMDriverDelay >> 8, CDROMDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00, |
401 |
> |
CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, 0, 0, 0, 0, 0, 0, |
402 |
|
0x00, 0x1c, // Open() offset |
403 |
|
0x00, 0x20, // Prime() offset |
404 |
|
0x00, 0x24, // Control() offset |
694 |
|
|
695 |
|
void InstallDrivers(uint32 pb) |
696 |
|
{ |
697 |
< |
D(bug("InstallDrivers\n")); |
697 |
> |
D(bug("InstallDrivers, pb %08x\n", pb)); |
698 |
|
M68kRegisters r; |
699 |
|
|
700 |
|
// Install Microseconds() replacement routine |
702 |
|
r.d[0] = 0xa093; |
703 |
|
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
704 |
|
|
705 |
+ |
// Install DebugUtil() replacement routine |
706 |
+ |
r.a[0] = ROMBaseMac + debugutil_offset; |
707 |
+ |
r.d[0] = 0xa08d; |
708 |
+ |
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
709 |
+ |
|
710 |
|
// Install disk driver |
711 |
|
r.a[0] = ROMBaseMac + sony_offset + 0x100; |
712 |
|
r.d[0] = (uint32)DiskRefNum; |
716 |
|
uint32 dce = ReadMacInt32(r.a[0]); |
717 |
|
WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x100); |
718 |
|
WriteMacInt16(dce + dCtlFlags, DiskDriverFlags); |
558 |
– |
WriteMacInt16(dce + dCtlDelay, DiskDriverDelay); |
719 |
|
|
720 |
|
// Open disk driver |
721 |
|
WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x112); |
734 |
|
dce = ReadMacInt32(r.a[0]); |
735 |
|
WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x200); |
736 |
|
WriteMacInt16(dce + dCtlFlags, CDROMDriverFlags); |
577 |
– |
WriteMacInt16(dce + dCtlDelay, CDROMDriverDelay); |
737 |
|
|
738 |
|
// Open CD-ROM driver |
739 |
|
WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x212); |
802 |
|
|
803 |
|
void PatchAfterStartup(void) |
804 |
|
{ |
805 |
< |
// Install MemoryDispatch() replacement routine |
806 |
< |
M68kRegisters r; |
807 |
< |
r.a[0] = ROMBaseMac + memory_dispatch_offset; |
808 |
< |
r.d[0] = 0xa05c; |
650 |
< |
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
805 |
> |
#if SUPPORTS_EXTFS |
806 |
> |
// Install external file system |
807 |
> |
InstallExtFS(); |
808 |
> |
#endif |
809 |
|
} |
810 |
|
|
811 |
|
|
822 |
|
// Real addressing mode requires a 32-bit clean ROM |
823 |
|
return ROMVersion == ROM_VERSION_32; |
824 |
|
#else |
825 |
< |
// Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs (experimental) |
825 |
> |
// Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs |
826 |
|
return (ROMVersion == ROM_VERSION_CLASSIC) || (ROMVersion == ROM_VERSION_32); |
827 |
|
#endif |
828 |
|
} |
936 |
|
*wp++ = htons(M68K_RTS); |
937 |
|
microseconds_offset = (uint8 *)wp - ROMBaseHost; |
938 |
|
*wp++ = htons(M68K_EMUL_OP_MICROSECONDS); |
939 |
+ |
*wp++ = htons(M68K_RTS); |
940 |
+ |
|
941 |
+ |
// Replace DebugUtil |
942 |
+ |
debugutil_offset = (uint8 *)wp - ROMBaseHost; |
943 |
+ |
*wp++ = htons(M68K_EMUL_OP_DEBUGUTIL); |
944 |
|
*wp = htons(M68K_RTS); |
945 |
|
|
946 |
|
// Replace SCSIDispatch() |
1000 |
|
// ROM patches for 32-bit clean Mac-II ROMs (version $067c) |
1001 |
|
static bool patch_rom_32(void) |
1002 |
|
{ |
1003 |
+ |
uint32 *lp; |
1004 |
|
uint16 *wp; |
1005 |
|
uint8 *bp; |
1006 |
|
uint32 base; |
1203 |
|
*wp = htons(M68K_RTS); |
1204 |
|
|
1205 |
|
// Fake CPU speed test (SetupTimeK) |
1206 |
+ |
// *** increased jl : MacsBug uses TimeDBRA for kbd repeat timing |
1207 |
|
wp = (uint16 *)(ROMBaseHost + 0x800); |
1208 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeDBRA |
1209 |
< |
*wp++ = htons(100); |
1209 |
> |
*wp++ = htons(10000); |
1210 |
|
*wp++ = htons(0x0d00); |
1211 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeSCCDBRA |
1212 |
< |
*wp++ = htons(100); |
1212 |
> |
*wp++ = htons(10000); |
1213 |
|
*wp++ = htons(0x0d02); |
1214 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeSCSIDBRA |
1215 |
< |
*wp++ = htons(100); |
1215 |
> |
*wp++ = htons(10000); |
1216 |
|
*wp++ = htons(0x0b24); |
1217 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeRAMDBRA |
1218 |
< |
*wp++ = htons(100); |
1218 |
> |
*wp++ = htons(10000); |
1219 |
|
*wp++ = htons(0x0cea); |
1220 |
|
*wp = htons(M68K_RTS); |
1221 |
|
|
1317 |
|
*wp++ = htons(M68K_NOP); |
1318 |
|
*wp = htons(M68K_NOP); |
1319 |
|
|
1320 |
< |
// Fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!) |
1321 |
< |
static const uint8 fix_memsize_dat[] = {0x4e, 0x75}; |
1322 |
< |
if ((base = find_rom_data(0x490, 0x4b0, fix_memsize_dat, sizeof(fix_memsize_dat))) == 0) return false; |
1323 |
< |
D(bug("fix_memsize %08lx\n", base)); |
1324 |
< |
wp = (uint16 *)(ROMBaseHost + base); |
1320 |
> |
// Compute boot stack pointer and fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!) |
1321 |
> |
wp = (uint16 *)(ROMBaseHost + 0x490); |
1322 |
> |
*wp++ = htons(0x2038); // move.l $10c,d0 |
1323 |
> |
*wp++ = htons(0x010c); |
1324 |
> |
*wp++ = htons(0xd0b8); // add.l $2a6,d0 |
1325 |
> |
*wp++ = htons(0x02a6); |
1326 |
> |
*wp++ = htons(0xe288); // lsr.l #1,d0 |
1327 |
> |
*wp++ = htons(0x0880); // bclr #0,d0 |
1328 |
> |
*wp++ = htons(0x0000); |
1329 |
> |
*wp++ = htons(0x0440); // subi.w #$400,d0 |
1330 |
> |
*wp++ = htons(0x0400); |
1331 |
> |
*wp++ = htons(0x2040); // move.l d0,a0 |
1332 |
|
*wp++ = htons(M68K_EMUL_OP_FIX_MEMSIZE); |
1333 |
< |
*wp = htons(M68K_RTS); |
1333 |
> |
*wp++ = htons(M68K_RTS); |
1334 |
|
|
1335 |
|
static const uint8 fix_memsize2_dat[] = {0x22, 0x30, 0x81, 0xe2, 0x0d, 0xdc, 0xff, 0xba, 0xd2, 0xb0, 0x81, 0xe2, 0x0d, 0xdc, 0xff, 0xec, 0x21, 0xc1, 0x1e, 0xf8}; |
1336 |
|
base = find_rom_data(0x4c000, 0x4c080, fix_memsize2_dat, sizeof(fix_memsize2_dat)); |
1463 |
|
} |
1464 |
|
} |
1465 |
|
|
1466 |
+ |
// Don't set MemoryDispatch() to unimplemented trap |
1467 |
+ |
static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47}; |
1468 |
+ |
base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat)); |
1469 |
+ |
D(bug("memdisp %08lx\n", base)); |
1470 |
+ |
if (base) { // ROM15/22/23/26/27/32 |
1471 |
+ |
wp = (uint16 *)(ROMBaseHost + base + 10); |
1472 |
+ |
*wp = htons(M68K_NOP); |
1473 |
+ |
} |
1474 |
+ |
|
1475 |
|
// Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000) |
1476 |
< |
uint32 edisk_offset = find_rom_resource('DRVR', 51); |
1476 |
> |
uint32 edisk_offset = find_rom_resource(FOURCC('D','R','V','R'), 51); |
1477 |
|
if (edisk_offset) { |
1478 |
|
static const uint8 edisk_dat[] = {0xd5, 0xfc, 0x00, 0x01, 0x00, 0x00, 0xb5, 0xfc, 0x00, 0xe0, 0x00, 0x00}; |
1479 |
|
base = find_rom_data(edisk_offset, edisk_offset + 0x10000, edisk_dat, sizeof(edisk_dat)); |
1486 |
|
} |
1487 |
|
|
1488 |
|
// Replace .Sony driver |
1489 |
< |
sony_offset = find_rom_resource('DRVR', 4); |
1489 |
> |
sony_offset = find_rom_resource(FOURCC('D','R','V','R'), 4); |
1490 |
|
D(bug("sony %08lx\n", sony_offset)); |
1491 |
|
memcpy(ROMBaseHost + sony_offset, sony_driver, sizeof(sony_driver)); |
1492 |
|
|
1505 |
|
memcpy(ROMBaseHost + sony_offset + 0xa00, CDROMIcon, sizeof(CDROMIcon)); |
1506 |
|
|
1507 |
|
// Install SERD patch and serial drivers |
1508 |
< |
serd_offset = find_rom_resource('SERD', 0); |
1508 |
> |
serd_offset = find_rom_resource(FOURCC('S','E','R','D'), 0); |
1509 |
|
D(bug("serd %08lx\n", serd_offset)); |
1510 |
|
wp = (uint16 *)(ROMBaseHost + serd_offset + 12); |
1511 |
|
*wp++ = htons(M68K_EMUL_OP_SERD); |
1538 |
|
*wp++ = htons(M68K_RTS); |
1539 |
|
microseconds_offset = (uint8 *)wp - ROMBaseHost; |
1540 |
|
*wp++ = htons(M68K_EMUL_OP_MICROSECONDS); |
1541 |
+ |
*wp++ = htons(M68K_RTS); |
1542 |
+ |
|
1543 |
+ |
// Replace DebugUtil |
1544 |
+ |
debugutil_offset = (uint8 *)wp - ROMBaseHost; |
1545 |
+ |
*wp++ = htons(M68K_EMUL_OP_DEBUGUTIL); |
1546 |
|
*wp = htons(M68K_RTS); |
1547 |
|
|
1548 |
|
// Replace SCSIDispatch() |
1578 |
|
*wp++ = htons(base >> 16); |
1579 |
|
*wp = htons(base & 0xffff); |
1580 |
|
|
1581 |
< |
// Install MemoryDispatch() replacement routine (activated in PatchAfterStartup()) |
1582 |
< |
memory_dispatch_offset = sony_offset + 0xc20; |
1583 |
< |
wp = (uint16 *)(ROMBaseHost + memory_dispatch_offset); |
1584 |
< |
*wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH); |
1581 |
> |
#if EMULATED_68K |
1582 |
> |
// Replace BlockMove() |
1583 |
> |
wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e)); // BlockMove() |
1584 |
> |
*wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE); |
1585 |
> |
*wp++ = htons(0x7000); |
1586 |
|
*wp = htons(M68K_RTS); |
1587 |
+ |
#endif |
1588 |
+ |
|
1589 |
+ |
// Look for double PACK 4 resources |
1590 |
+ |
if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4)) == 0) return false; |
1591 |
+ |
if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4, true)) == 0 && FPUType == 0) |
1592 |
+ |
printf("WARNING: This ROM seems to require an FPU\n"); |
1593 |
|
|
1594 |
|
// Patch VIA interrupt handler |
1595 |
|
wp = (uint16 *)(ROMBaseHost + 0x9bc4); // Level 1 handler |
1608 |
|
|
1609 |
|
bool PatchROM(void) |
1610 |
|
{ |
1611 |
< |
// Print ROM info |
1612 |
< |
D(bug("ROM Info:\n")); |
1613 |
< |
D(bug("Checksum: %08lx\n", ReadMacInt32(ROMBaseMac))); |
1421 |
< |
D(bug("Version: %04x\n", ROMVersion)); |
1422 |
< |
D(bug("Sub Version: %04x\n", ReadMacInt16(ROMBaseMac + 18))); |
1611 |
> |
// Print some information about the ROM |
1612 |
> |
if (PrintROMInfo) |
1613 |
> |
print_rom_info(); |
1614 |
|
|
1615 |
|
// Patch ROM depending on version |
1616 |
|
switch (ROMVersion) { |
1626 |
|
return false; |
1627 |
|
} |
1628 |
|
|
1438 |
– |
#ifdef M68K_BREAKPOINT |
1629 |
|
// Install breakpoint |
1630 |
< |
uint16 *wp = (uint16 *)(ROMBaseHost + M68K_BREAKPOINT); |
1631 |
< |
*wp = htons(M68K_EMUL_BREAK); |
1632 |
< |
#endif |
1630 |
> |
if (ROMBreakpoint) { |
1631 |
> |
uint16 *wp = (uint16 *)(ROMBaseHost + ROMBreakpoint); |
1632 |
> |
*wp = htons(M68K_EMUL_BREAK); |
1633 |
> |
} |
1634 |
|
|
1635 |
|
// Clear caches as we loaded and patched code |
1636 |
|
FlushCodeCache(ROMBaseHost, ROMSize); |