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 |
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 |
+ |
bool PatchHWBases = true; // Flag: patch hardware base addresses |
47 |
|
|
48 |
< |
static uint32 sony_offset; // ROM offset of .Sony driver |
49 |
< |
static uint32 serd_offset; // ROM offset of SERD resource (serial drivers) |
50 |
< |
static uint32 microseconds_offset; // ROM offset of Microseconds() replacement routine |
48 |
> |
static uint32 sony_offset; // ROM offset of .Sony driver |
49 |
> |
static uint32 serd_offset; // ROM offset of SERD resource (serial drivers) |
50 |
> |
static uint32 microseconds_offset; // ROM offset of Microseconds() replacement routine |
51 |
> |
static uint32 debugutil_offset; // ROM offset of DebugUtil() replacement routine |
52 |
|
|
53 |
|
// Prototypes |
54 |
|
uint16 ROMVersion; |
55 |
|
|
56 |
+ |
/* |
57 |
+ |
* Macros used to extract one of the 16-bit words from a 32-bit word value |
58 |
+ |
*/ |
59 |
+ |
|
60 |
+ |
#define HiWord(X) (((X) >> 16) & 0xffff) |
61 |
+ |
#define LoWord(X) ((X) & 0xffff) |
62 |
+ |
|
63 |
|
|
64 |
|
/* |
65 |
|
* Search ROM for byte string, return ROM offset (or 0) |
710 |
|
r.d[0] = 0xa093; |
711 |
|
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
712 |
|
|
713 |
+ |
// Install DebugUtil() replacement routine |
714 |
+ |
r.a[0] = ROMBaseMac + debugutil_offset; |
715 |
+ |
r.d[0] = 0xa08d; |
716 |
+ |
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
717 |
+ |
|
718 |
|
// Install disk driver |
719 |
|
r.a[0] = ROMBaseMac + sony_offset + 0x100; |
720 |
|
r.d[0] = (uint32)DiskRefNum; |
826 |
|
// Read version |
827 |
|
ROMVersion = ntohs(*(uint16 *)(ROMBaseHost + 8)); |
828 |
|
|
829 |
< |
#if REAL_ADDRESSING |
830 |
< |
// Real addressing mode requires a 32-bit clean ROM |
829 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
830 |
> |
// Real and direct addressing modes require a 32-bit clean ROM |
831 |
|
return ROMVersion == ROM_VERSION_32; |
832 |
|
#else |
833 |
|
// Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs |
944 |
|
*wp++ = htons(M68K_RTS); |
945 |
|
microseconds_offset = (uint8 *)wp - ROMBaseHost; |
946 |
|
*wp++ = htons(M68K_EMUL_OP_MICROSECONDS); |
947 |
+ |
*wp++ = htons(M68K_RTS); |
948 |
+ |
|
949 |
+ |
// Replace DebugUtil |
950 |
+ |
debugutil_offset = (uint8 *)wp - ROMBaseHost; |
951 |
+ |
*wp++ = htons(M68K_EMUL_OP_DEBUGUTIL); |
952 |
|
*wp = htons(M68K_RTS); |
953 |
|
|
954 |
|
// Replace SCSIDispatch() |
1029 |
|
bp = ROMBaseHost + UniversalInfo + 18; // productKind |
1030 |
|
*bp = PrefsFindInt32("modelid"); |
1031 |
|
|
1032 |
+ |
#if !ROM_IS_WRITE_PROTECTED |
1033 |
+ |
#if defined(USE_SCRATCHMEM_SUBTERFUGE) |
1034 |
+ |
// Set hardware base addresses to scratch memory area |
1035 |
+ |
if (PatchHWBases) { |
1036 |
+ |
extern uint8 *ScratchMem; |
1037 |
+ |
const uint32 ScratchMemBase = Host2MacAddr(ScratchMem); |
1038 |
+ |
|
1039 |
+ |
D(bug("LMGlob\tOfs/4\tBase\n")); |
1040 |
+ |
base = ROMBaseMac + UniversalInfo + ReadMacInt32(ROMBaseMac + UniversalInfo); // decoderInfoPtr |
1041 |
+ |
wp = (uint16 *)(ROMBaseHost + 0x94a); |
1042 |
+ |
while (*wp != 0xffff) { |
1043 |
+ |
int16 ofs = ntohs(*wp++); // offset in decoderInfo (/4) |
1044 |
+ |
int16 lmg = ntohs(*wp++); // address of LowMem global |
1045 |
+ |
D(bug("0x%04x\t%d\t0x%08x\n", lmg, ofs, ReadMacInt32(base + ofs*4))); |
1046 |
+ |
|
1047 |
+ |
// Fake address only if this is not the ASC base |
1048 |
+ |
if (lmg != 0xcc0) |
1049 |
+ |
WriteMacInt32(base + ofs*4, ScratchMemBase); |
1050 |
+ |
} |
1051 |
+ |
} |
1052 |
+ |
#else |
1053 |
+ |
#error System specific handling for writable ROM is required here |
1054 |
+ |
#endif |
1055 |
+ |
#endif |
1056 |
+ |
|
1057 |
|
// Make FPU optional |
1058 |
|
if (FPUType == 0) { |
1059 |
|
bp = ROMBaseHost + UniversalInfo + 22; // defaultRSRCs |
1236 |
|
*wp = htons(M68K_RTS); |
1237 |
|
|
1238 |
|
// Fake CPU speed test (SetupTimeK) |
1239 |
+ |
// *** increased jl : MacsBug uses TimeDBRA for kbd repeat timing |
1240 |
|
wp = (uint16 *)(ROMBaseHost + 0x800); |
1241 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeDBRA |
1242 |
< |
*wp++ = htons(100); |
1242 |
> |
*wp++ = htons(10000); |
1243 |
|
*wp++ = htons(0x0d00); |
1244 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeSCCDBRA |
1245 |
< |
*wp++ = htons(100); |
1245 |
> |
*wp++ = htons(10000); |
1246 |
|
*wp++ = htons(0x0d02); |
1247 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeSCSIDBRA |
1248 |
< |
*wp++ = htons(100); |
1248 |
> |
*wp++ = htons(10000); |
1249 |
|
*wp++ = htons(0x0b24); |
1250 |
|
*wp++ = htons(0x31fc); // move.w #xxx,TimeRAMDBRA |
1251 |
< |
*wp++ = htons(100); |
1251 |
> |
*wp++ = htons(10000); |
1252 |
|
*wp++ = htons(0x0cea); |
1253 |
|
*wp = htons(M68K_RTS); |
1254 |
|
|
1255 |
|
#if REAL_ADDRESSING |
1256 |
|
// Move system zone to start of Mac RAM |
1257 |
< |
lp = (uint32 *)(ROMBaseHost + 0x50a); |
1258 |
< |
*lp++ = htonl(RAMBaseMac); |
1259 |
< |
*lp = htonl(RAMBaseMac + 0x1800); |
1257 |
> |
wp = (uint16 *)(ROMBaseHost + 0x50a); |
1258 |
> |
*wp++ = htons(HiWord(RAMBaseMac + 0x2000)); |
1259 |
> |
*wp++ = htons(LoWord(RAMBaseMac + 0x2000)); |
1260 |
> |
*wp++ = htons(HiWord(RAMBaseMac + 0x3800)); |
1261 |
> |
*wp = htons(LoWord(RAMBaseMac + 0x3800)); |
1262 |
|
#endif |
1263 |
|
|
1264 |
|
#if !ROM_IS_WRITE_PROTECTED |
1265 |
< |
#if defined(AMIGA) || defined(__NetBSD__) |
1265 |
> |
#if defined(USE_SCRATCHMEM_SUBTERFUGE) |
1266 |
|
// Set fake handle at 0x0000 to scratch memory area (so broken Mac programs won't write into Mac ROM) |
1267 |
< |
extern uint32 ScratchMem; |
1267 |
> |
extern uint8 *ScratchMem; |
1268 |
> |
const uint32 ScratchMemBase = Host2MacAddr(ScratchMem); |
1269 |
|
wp = (uint16 *)(ROMBaseHost + 0xccaa); |
1270 |
|
*wp++ = htons(0x203c); // move.l #ScratchMem,d0 |
1271 |
< |
*wp++ = htons(ScratchMem >> 16); |
1272 |
< |
*wp = htons(ScratchMem); |
1271 |
> |
*wp++ = htons(ScratchMemBase >> 16); |
1272 |
> |
*wp = htons(ScratchMemBase); |
1273 |
|
#else |
1274 |
|
#error System specific handling for writable ROM is required here |
1275 |
|
#endif |
1281 |
|
*wp++ = htons(M68K_NOP); |
1282 |
|
*wp = htons(M68K_NOP); |
1283 |
|
#endif |
1284 |
< |
|
1284 |
> |
|
1285 |
> |
#if REAL_ADDRESSING && !defined(AMIGA) |
1286 |
> |
// gb-- Temporary hack to get rid of crashes in Speedometer |
1287 |
> |
wp = (uint16 *)(ROMBaseHost + 0xdba2); |
1288 |
> |
if (ntohs(*wp) == 0x662c) // bne.b #$2c |
1289 |
> |
*wp = htons(0x602c); // bra.b #$2c |
1290 |
> |
#endif |
1291 |
> |
|
1292 |
|
// Don't write to VIA in InitTimeMgr |
1293 |
|
wp = (uint16 *)(ROMBaseHost + 0xb0e2); |
1294 |
|
*wp++ = htons(0x4cdf); // movem.l (sp)+,d0-d5/a0-a4 |
1484 |
|
if (ROMSize > 0x80000) { |
1485 |
|
|
1486 |
|
// BlockMove() |
1487 |
< |
static const uint8 ptest_dat[] = {0xa0, 0x8d, 0x0c, 0x81, 0x00, 0x00, 0x0c, 0x00, 0x6d, 0x06, 0x4e, 0x71, 0xf4, 0xf8}; |
1488 |
< |
base = find_rom_data(0x87000, 0x87800, ptest_dat, sizeof(ptest_dat)); |
1489 |
< |
D(bug("ptest %08lx\n", base)); |
1487 |
> |
static const uint8 bmove_dat[] = {0x20, 0x5f, 0x22, 0x5f, 0x0c, 0x38, 0x00, 0x04, 0x01, 0x2f}; |
1488 |
> |
base = find_rom_data(0x87000, 0x87800, bmove_dat, sizeof(bmove_dat)); |
1489 |
> |
D(bug("block_move %08lx\n", base)); |
1490 |
|
if (base) { // ROM15/22/23/26/27/32 |
1491 |
< |
wp = (uint16 *)(ROMBaseHost + base + 8); |
1492 |
< |
*wp = htons(M68K_NOP); |
1491 |
> |
wp = (uint16 *)(ROMBaseHost + base + 4); |
1492 |
> |
*wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE); |
1493 |
> |
*wp++ = htons(0x7000); |
1494 |
> |
*wp = htons(M68K_RTS); |
1495 |
|
} |
1496 |
|
|
1497 |
|
// SANE |
1583 |
|
*wp++ = htons(M68K_RTS); |
1584 |
|
microseconds_offset = (uint8 *)wp - ROMBaseHost; |
1585 |
|
*wp++ = htons(M68K_EMUL_OP_MICROSECONDS); |
1586 |
+ |
*wp++ = htons(M68K_RTS); |
1587 |
+ |
|
1588 |
+ |
// Replace DebugUtil |
1589 |
+ |
debugutil_offset = (uint8 *)wp - ROMBaseHost; |
1590 |
+ |
*wp++ = htons(M68K_EMUL_OP_DEBUGUTIL); |
1591 |
|
*wp = htons(M68K_RTS); |
1592 |
|
|
1593 |
|
// Replace SCSIDispatch() |
1623 |
|
*wp++ = htons(base >> 16); |
1624 |
|
*wp = htons(base & 0xffff); |
1625 |
|
|
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 |
– |
|
1626 |
|
// Look for double PACK 4 resources |
1627 |
|
if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4)) == 0) return false; |
1628 |
|
if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4, true)) == 0 && FPUType == 0) |