--- BasiliskII/src/rom_patches.cpp 2000/07/22 16:07:17 1.15 +++ BasiliskII/src/rom_patches.cpp 2000/09/22 17:17:21 1.17 @@ -44,15 +44,27 @@ uint32 PutScrapPatch; // Mac address of uint32 ROMBreakpoint = 0; // ROM offset of breakpoint (0 = disabled, 0x2310 = CritError) bool PrintROMInfo = false; // Flag: print ROM information in PatchROM() -static uint32 sony_offset; // ROM offset of .Sony driver -static uint32 serd_offset; // ROM offset of SERD resource (serial drivers) -static uint32 microseconds_offset; // ROM offset of Microseconds() replacement routine +static uint32 sony_offset; // ROM offset of .Sony driver +static uint32 serd_offset; // ROM offset of SERD resource (serial drivers) +static uint32 microseconds_offset; // ROM offset of Microseconds() replacement routine +static uint32 debugutil_offset; // ROM offset of DebugUtil() replacement routine // Prototypes uint16 ROMVersion; /* + * Convenience functions for retrieving a particular 16-bit word from + * a 32-bit word value. + * + * gb-- probably put those elsewhere... + */ + +#define HiWord(X) (((X) >> 16) & 0xffff) +#define LoWord(X) ((X) & 0xffff) + + +/* * Search ROM for byte string, return ROM offset (or 0) */ @@ -701,6 +713,11 @@ void InstallDrivers(uint32 pb) r.d[0] = 0xa093; Execute68kTrap(0xa247, &r); // SetOSTrapAddress() + // Install DebugUtil() replacement routine + r.a[0] = ROMBaseMac + debugutil_offset; + r.d[0] = 0xa08d; + Execute68kTrap(0xa247, &r); // SetOSTrapAddress() + // Install disk driver r.a[0] = ROMBaseMac + sony_offset + 0x100; r.d[0] = (uint32)DiskRefNum; @@ -812,8 +829,8 @@ bool CheckROM(void) // Read version ROMVersion = ntohs(*(uint16 *)(ROMBaseHost + 8)); -#if REAL_ADDRESSING - // Real addressing mode requires a 32-bit clean ROM +#if REAL_ADDRESSING || DIRECT_ADDRESSING + // Real and direct addressing modes require a 32-bit clean ROM return ROMVersion == ROM_VERSION_32; #else // Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs @@ -930,6 +947,11 @@ static bool patch_rom_classic(void) *wp++ = htons(M68K_RTS); microseconds_offset = (uint8 *)wp - ROMBaseHost; *wp++ = htons(M68K_EMUL_OP_MICROSECONDS); + *wp++ = htons(M68K_RTS); + + // Replace DebugUtil + debugutil_offset = (uint8 *)wp - ROMBaseHost; + *wp++ = htons(M68K_EMUL_OP_DEBUGUTIL); *wp = htons(M68K_RTS); // Replace SCSIDispatch() @@ -1192,36 +1214,40 @@ static bool patch_rom_32(void) *wp = htons(M68K_RTS); // Fake CPU speed test (SetupTimeK) + // *** increased jl : MacsBug uses TimeDBRA for kbd repeat timing wp = (uint16 *)(ROMBaseHost + 0x800); *wp++ = htons(0x31fc); // move.w #xxx,TimeDBRA - *wp++ = htons(100); + *wp++ = htons(10000); *wp++ = htons(0x0d00); *wp++ = htons(0x31fc); // move.w #xxx,TimeSCCDBRA - *wp++ = htons(100); + *wp++ = htons(10000); *wp++ = htons(0x0d02); *wp++ = htons(0x31fc); // move.w #xxx,TimeSCSIDBRA - *wp++ = htons(100); + *wp++ = htons(10000); *wp++ = htons(0x0b24); *wp++ = htons(0x31fc); // move.w #xxx,TimeRAMDBRA - *wp++ = htons(100); + *wp++ = htons(10000); *wp++ = htons(0x0cea); *wp = htons(M68K_RTS); #if REAL_ADDRESSING // Move system zone to start of Mac RAM - lp = (uint32 *)(ROMBaseHost + 0x50a); - *lp++ = htonl(RAMBaseMac); - *lp = htonl(RAMBaseMac + 0x1800); + wp = (uint16 *)(ROMBaseHost + 0x50a); + *wp++ = htons(HiWord(RAMBaseMac + 0x2000)); + *wp++ = htons(LoWord(RAMBaseMac + 0x2000)); + *wp++ = htons(HiWord(RAMBaseMac + 0x3800)); + *wp = htons(LoWord(RAMBaseMac + 0x3800)); #endif #if !ROM_IS_WRITE_PROTECTED -#if defined(AMIGA) || defined(__NetBSD__) +#if defined(AMIGA) || defined(USE_SCRATCHMEM_SUBTERFUGE) // Set fake handle at 0x0000 to scratch memory area (so broken Mac programs won't write into Mac ROM) - extern uint32 ScratchMem; + extern uint8 *ScratchMem; + const uint32 ScratchMemBase = Host2MacAddr(ScratchMem); wp = (uint16 *)(ROMBaseHost + 0xccaa); *wp++ = htons(0x203c); // move.l #ScratchMem,d0 - *wp++ = htons(ScratchMem >> 16); - *wp = htons(ScratchMem); + *wp++ = htons(ScratchMemBase >> 16); + *wp = htons(ScratchMemBase); #else #error System specific handling for writable ROM is required here #endif @@ -1233,7 +1259,14 @@ static bool patch_rom_32(void) *wp++ = htons(M68K_NOP); *wp = htons(M68K_NOP); #endif - + +#if REAL_ADDRESSING && !defined(AMIGA) + // gb-- Temporary hack to get rid of crashes in Speedometer + wp = (uint16 *)(ROMBaseHost + 0xdba2); + if (ntohs(*wp) == 0x662c) // bne.b #$2c + *wp = htons(0x602c); // bra.b #$2c +#endif + // Don't write to VIA in InitTimeMgr wp = (uint16 *)(ROMBaseHost + 0xb0e2); *wp++ = htons(0x4cdf); // movem.l (sp)+,d0-d5/a0-a4 @@ -1526,6 +1559,11 @@ static bool patch_rom_32(void) *wp++ = htons(M68K_RTS); microseconds_offset = (uint8 *)wp - ROMBaseHost; *wp++ = htons(M68K_EMUL_OP_MICROSECONDS); + *wp++ = htons(M68K_RTS); + + // Replace DebugUtil + debugutil_offset = (uint8 *)wp - ROMBaseHost; + *wp++ = htons(M68K_EMUL_OP_DEBUGUTIL); *wp = htons(M68K_RTS); // Replace SCSIDispatch()