1 |
|
/* |
2 |
|
* rom_patches.cpp - ROM patches |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2000 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 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 |
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 |
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 debugutil_offset; // ROM offset of DebugUtil() replacement routine |
51 |
|
|
52 |
|
// Prototypes |
53 |
|
uint16 ROMVersion; |
54 |
|
|
55 |
|
|
56 |
|
/* |
57 |
+ |
* Convenience functions for retrieving a particular 16-bit word from |
58 |
+ |
* a 32-bit word value. |
59 |
+ |
* |
60 |
+ |
* gb-- probably put those elsewhere... |
61 |
+ |
*/ |
62 |
+ |
|
63 |
+ |
#define HiWord(X) (((X) >> 16) & 0xffff) |
64 |
+ |
#define LoWord(X) ((X) & 0xffff) |
65 |
+ |
|
66 |
+ |
|
67 |
+ |
/* |
68 |
|
* Search ROM for byte string, return ROM offset (or 0) |
69 |
|
*/ |
70 |
|
|
282 |
|
printf("Universal Table at %08x:\n", q); |
283 |
|
printf("Offset\t ID\tHWCfg\tROM85\tModel\n"); |
284 |
|
printf("------------------------------------------------\n"); |
285 |
< |
while (ofs = ReadMacInt32(ROMBaseMac + q)) { |
285 |
> |
while ((ofs = ReadMacInt32(ROMBaseMac + q))) { |
286 |
|
print_universal_info(ROMBaseMac + ofs + q); |
287 |
|
q += 4; |
288 |
|
} |
705 |
|
|
706 |
|
void InstallDrivers(uint32 pb) |
707 |
|
{ |
708 |
< |
D(bug("InstallDrivers\n")); |
708 |
> |
D(bug("InstallDrivers, pb %08x\n", pb)); |
709 |
|
M68kRegisters r; |
710 |
|
|
711 |
|
// Install Microseconds() replacement routine |
713 |
|
r.d[0] = 0xa093; |
714 |
|
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
715 |
|
|
716 |
+ |
// Install DebugUtil() replacement routine |
717 |
+ |
r.a[0] = ROMBaseMac + debugutil_offset; |
718 |
+ |
r.d[0] = 0xa08d; |
719 |
+ |
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
720 |
+ |
|
721 |
|
// Install disk driver |
722 |
|
r.a[0] = ROMBaseMac + sony_offset + 0x100; |
723 |
|
r.d[0] = (uint32)DiskRefNum; |
829 |
|
// Read version |
830 |
|
ROMVersion = ntohs(*(uint16 *)(ROMBaseHost + 8)); |
831 |
|
|
832 |
< |
#if REAL_ADDRESSING |
833 |
< |
// Real addressing mode requires a 32-bit clean ROM |
832 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
833 |
> |
// Real and direct addressing modes require a 32-bit clean ROM |
834 |
|
return ROMVersion == ROM_VERSION_32; |
835 |
|
#else |
836 |
|
// Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs |
947 |
|
*wp++ = htons(M68K_RTS); |
948 |
|
microseconds_offset = (uint8 *)wp - ROMBaseHost; |
949 |
|
*wp++ = htons(M68K_EMUL_OP_MICROSECONDS); |
950 |
+ |
*wp++ = htons(M68K_RTS); |
951 |
+ |
|
952 |
+ |
// Replace DebugUtil |
953 |
+ |
debugutil_offset = (uint8 *)wp - ROMBaseHost; |
954 |
+ |
*wp++ = htons(M68K_EMUL_OP_DEBUGUTIL); |
955 |
|
*wp = htons(M68K_RTS); |
956 |
|
|
957 |
|
// Replace SCSIDispatch() |
1214 |
|
*wp = htons(M68K_RTS); |
1215 |
|
|
1216 |
|
// Fake CPU speed test (SetupTimeK) |
1217 |
+ |
// *** increased jl : MacsBug uses TimeDBRA for kbd repeat timing |
1218 |
|
wp = (uint16 *)(ROMBaseHost + 0x800); |
1219 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeDBRA |
1220 |
< |
*wp++ = htons(100); |
1220 |
> |
*wp++ = htons(10000); |
1221 |
|
*wp++ = htons(0x0d00); |
1222 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeSCCDBRA |
1223 |
< |
*wp++ = htons(100); |
1223 |
> |
*wp++ = htons(10000); |
1224 |
|
*wp++ = htons(0x0d02); |
1225 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeSCSIDBRA |
1226 |
< |
*wp++ = htons(100); |
1226 |
> |
*wp++ = htons(10000); |
1227 |
|
*wp++ = htons(0x0b24); |
1228 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeRAMDBRA |
1229 |
< |
*wp++ = htons(100); |
1229 |
> |
*wp++ = htons(10000); |
1230 |
|
*wp++ = htons(0x0cea); |
1231 |
|
*wp = htons(M68K_RTS); |
1232 |
|
|
1233 |
|
#if REAL_ADDRESSING |
1234 |
|
// Move system zone to start of Mac RAM |
1235 |
< |
lp = (uint32 *)(ROMBaseHost + 0x50a); |
1236 |
< |
*lp++ = htonl(RAMBaseMac); |
1237 |
< |
*lp = htonl(RAMBaseMac + 0x1800); |
1235 |
> |
wp = (uint16 *)(ROMBaseHost + 0x50a); |
1236 |
> |
*wp++ = htons(HiWord(RAMBaseMac + 0x2000)); |
1237 |
> |
*wp++ = htons(LoWord(RAMBaseMac + 0x2000)); |
1238 |
> |
*wp++ = htons(HiWord(RAMBaseMac + 0x3800)); |
1239 |
> |
*wp = htons(LoWord(RAMBaseMac + 0x3800)); |
1240 |
|
#endif |
1241 |
|
|
1242 |
|
#if !ROM_IS_WRITE_PROTECTED |
1243 |
< |
#if defined(AMIGA) |
1243 |
> |
#if defined(USE_SCRATCHMEM_SUBTERFUGE) |
1244 |
|
// Set fake handle at 0x0000 to scratch memory area (so broken Mac programs won't write into Mac ROM) |
1245 |
< |
extern uint32 ScratchMem; |
1245 |
> |
extern uint8 *ScratchMem; |
1246 |
> |
const uint32 ScratchMemBase = Host2MacAddr(ScratchMem); |
1247 |
|
wp = (uint16 *)(ROMBaseHost + 0xccaa); |
1248 |
|
*wp++ = htons(0x203c); // move.l #ScratchMem,d0 |
1249 |
< |
*wp++ = htons(ScratchMem >> 16); |
1250 |
< |
*wp = htons(ScratchMem); |
1249 |
> |
*wp++ = htons(ScratchMemBase >> 16); |
1250 |
> |
*wp = htons(ScratchMemBase); |
1251 |
|
#else |
1252 |
|
#error System specific handling for writable ROM is required here |
1253 |
|
#endif |
1259 |
|
*wp++ = htons(M68K_NOP); |
1260 |
|
*wp = htons(M68K_NOP); |
1261 |
|
#endif |
1262 |
< |
|
1262 |
> |
|
1263 |
> |
#if REAL_ADDRESSING && !defined(AMIGA) |
1264 |
> |
// gb-- Temporary hack to get rid of crashes in Speedometer |
1265 |
> |
wp = (uint16 *)(ROMBaseHost + 0xdba2); |
1266 |
> |
if (ntohs(*wp) == 0x662c) // bne.b #$2c |
1267 |
> |
*wp = htons(0x602c); // bra.b #$2c |
1268 |
> |
#endif |
1269 |
> |
|
1270 |
|
// Don't write to VIA in InitTimeMgr |
1271 |
|
wp = (uint16 *)(ROMBaseHost + 0xb0e2); |
1272 |
|
*wp++ = htons(0x4cdf); // movem.l (sp)+,d0-d5/a0-a4 |
1462 |
|
if (ROMSize > 0x80000) { |
1463 |
|
|
1464 |
|
// BlockMove() |
1465 |
< |
static const uint8 ptest_dat[] = {0xa0, 0x8d, 0x0c, 0x81, 0x00, 0x00, 0x0c, 0x00, 0x6d, 0x06, 0x4e, 0x71, 0xf4, 0xf8}; |
1466 |
< |
base = find_rom_data(0x87000, 0x87800, ptest_dat, sizeof(ptest_dat)); |
1467 |
< |
D(bug("ptest %08lx\n", base)); |
1465 |
> |
static const uint8 bmove_dat[] = {0x20, 0x5f, 0x22, 0x5f, 0x0c, 0x38, 0x00, 0x04, 0x01, 0x2f}; |
1466 |
> |
base = find_rom_data(0x87000, 0x87800, bmove_dat, sizeof(bmove_dat)); |
1467 |
> |
D(bug("block_move %08lx\n", base)); |
1468 |
|
if (base) { // ROM15/22/23/26/27/32 |
1469 |
< |
wp = (uint16 *)(ROMBaseHost + base + 8); |
1470 |
< |
*wp = htons(M68K_NOP); |
1469 |
> |
wp = (uint16 *)(ROMBaseHost + base + 4); |
1470 |
> |
*wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE); |
1471 |
> |
*wp++ = htons(0x7000); |
1472 |
> |
*wp = htons(M68K_RTS); |
1473 |
|
} |
1474 |
|
|
1475 |
|
// SANE |
1496 |
|
} |
1497 |
|
|
1498 |
|
// Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000) |
1499 |
< |
uint32 edisk_offset = find_rom_resource('DRVR', 51); |
1499 |
> |
uint32 edisk_offset = find_rom_resource(FOURCC('D','R','V','R'), 51); |
1500 |
|
if (edisk_offset) { |
1501 |
|
static const uint8 edisk_dat[] = {0xd5, 0xfc, 0x00, 0x01, 0x00, 0x00, 0xb5, 0xfc, 0x00, 0xe0, 0x00, 0x00}; |
1502 |
|
base = find_rom_data(edisk_offset, edisk_offset + 0x10000, edisk_dat, sizeof(edisk_dat)); |
1509 |
|
} |
1510 |
|
|
1511 |
|
// Replace .Sony driver |
1512 |
< |
sony_offset = find_rom_resource('DRVR', 4); |
1512 |
> |
sony_offset = find_rom_resource(FOURCC('D','R','V','R'), 4); |
1513 |
|
D(bug("sony %08lx\n", sony_offset)); |
1514 |
|
memcpy(ROMBaseHost + sony_offset, sony_driver, sizeof(sony_driver)); |
1515 |
|
|
1528 |
|
memcpy(ROMBaseHost + sony_offset + 0xa00, CDROMIcon, sizeof(CDROMIcon)); |
1529 |
|
|
1530 |
|
// Install SERD patch and serial drivers |
1531 |
< |
serd_offset = find_rom_resource('SERD', 0); |
1531 |
> |
serd_offset = find_rom_resource(FOURCC('S','E','R','D'), 0); |
1532 |
|
D(bug("serd %08lx\n", serd_offset)); |
1533 |
|
wp = (uint16 *)(ROMBaseHost + serd_offset + 12); |
1534 |
|
*wp++ = htons(M68K_EMUL_OP_SERD); |
1561 |
|
*wp++ = htons(M68K_RTS); |
1562 |
|
microseconds_offset = (uint8 *)wp - ROMBaseHost; |
1563 |
|
*wp++ = htons(M68K_EMUL_OP_MICROSECONDS); |
1564 |
+ |
*wp++ = htons(M68K_RTS); |
1565 |
+ |
|
1566 |
+ |
// Replace DebugUtil |
1567 |
+ |
debugutil_offset = (uint8 *)wp - ROMBaseHost; |
1568 |
+ |
*wp++ = htons(M68K_EMUL_OP_DEBUGUTIL); |
1569 |
|
*wp = htons(M68K_RTS); |
1570 |
|
|
1571 |
|
// Replace SCSIDispatch() |
1601 |
|
*wp++ = htons(base >> 16); |
1602 |
|
*wp = htons(base & 0xffff); |
1603 |
|
|
1564 |
– |
#if EMULATED_68K |
1565 |
– |
// Replace BlockMove() |
1566 |
– |
wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e)); // BlockMove() |
1567 |
– |
*wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE); |
1568 |
– |
*wp++ = htons(0x7000); |
1569 |
– |
*wp = htons(M68K_RTS); |
1570 |
– |
#endif |
1571 |
– |
|
1604 |
|
// Look for double PACK 4 resources |
1605 |
< |
if ((base = find_rom_resource('PACK', 4)) == 0) return false; |
1606 |
< |
if ((base = find_rom_resource('PACK', 4, true)) == 0 && FPUType == 0) |
1605 |
> |
if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4)) == 0) return false; |
1606 |
> |
if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4, true)) == 0 && FPUType == 0) |
1607 |
|
printf("WARNING: This ROM seems to require an FPU\n"); |
1608 |
|
|
1609 |
|
// Patch VIA interrupt handler |