--- BasiliskII/src/rom_patches.cpp 1999/10/03 14:16:25 1.1 +++ BasiliskII/src/rom_patches.cpp 1999/10/26 16:28:27 1.10 @@ -30,6 +30,7 @@ #include "disk.h" #include "cdrom.h" #include "video.h" +#include "extfs.h" #include "prefs.h" #include "rom_patches.h" @@ -37,17 +38,16 @@ #include "debug.h" -// Breakpoint -//#define M68K_BREAKPOINT 0x2310 // CritError -//#define M68K_BREAKPOINT 0x1d10 // BootMe +// Breakpoint (offset into ROM) +uint32 ROMBreakpoint = 0; // 0 = disabled, 0x2310 = CritError // Global variables uint32 UniversalInfo; // ROM offset of UniversalInfo uint32 PutScrapPatch; // Mac address of PutScrap() patch -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 memory_dispatch_offset; // ROM offset of MemoryDispatch() replacement routine // Prototypes @@ -146,7 +146,7 @@ again: static const uint8 sony_driver[] = { // Replacement for .Sony driver // Driver header - SonyDriverFlags >> 8, SonyDriverFlags & 0xff, SonyDriverDelay >> 8, SonyDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00, + SonyDriverFlags >> 8, SonyDriverFlags & 0xff, 0, 0, 0, 0, 0, 0, 0x00, 0x18, // Open() offset 0x00, 0x1c, // Prime() offset 0x00, 0x20, // Control() offset @@ -194,7 +194,7 @@ static const uint8 sony_driver[] = { // static const uint8 disk_driver[] = { // Generic disk driver // Driver header - DiskDriverFlags >> 8, DiskDriverFlags & 0xff, DiskDriverDelay >> 8, DiskDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00, + DiskDriverFlags >> 8, DiskDriverFlags & 0xff, 0, 0, 0, 0, 0, 0, 0x00, 0x18, // Open() offset 0x00, 0x1c, // Prime() offset 0x00, 0x20, // Control() offset @@ -242,7 +242,7 @@ static const uint8 disk_driver[] = { // static const uint8 cdrom_driver[] = { // CD-ROM driver // Driver header - CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, CDROMDriverDelay >> 8, CDROMDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00, + CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, 0, 0, 0, 0, 0, 0, 0x00, 0x1c, // Open() offset 0x00, 0x20, // Prime() offset 0x00, 0x24, // Control() offset @@ -546,6 +546,11 @@ void InstallDrivers(uint32 pb) r.d[0] = 0xa093; Execute68kTrap(0xa247, &r); // SetOSTrapAddress() + // Install MemoryDispatch() replacement routine + r.a[0] = ROMBaseMac + memory_dispatch_offset; + r.d[0] = 0xa05c; + Execute68kTrap(0xa247, &r); // SetOSTrapAddress() + // Install disk driver r.a[0] = ROMBaseMac + sony_offset + 0x100; r.d[0] = (uint32)DiskRefNum; @@ -555,7 +560,6 @@ void InstallDrivers(uint32 pb) uint32 dce = ReadMacInt32(r.a[0]); WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x100); WriteMacInt16(dce + dCtlFlags, DiskDriverFlags); - WriteMacInt16(dce + dCtlDelay, DiskDriverDelay); // Open disk driver WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x112); @@ -574,7 +578,6 @@ void InstallDrivers(uint32 pb) dce = ReadMacInt32(r.a[0]); WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x200); WriteMacInt16(dce + dCtlFlags, CDROMDriverFlags); - WriteMacInt16(dce + dCtlDelay, CDROMDriverDelay); // Open CD-ROM driver WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x212); @@ -643,11 +646,10 @@ void InstallSERD(void) void PatchAfterStartup(void) { - // Install MemoryDispatch() replacement routine - M68kRegisters r; - r.a[0] = ROMBaseMac + memory_dispatch_offset; - r.d[0] = 0xa05c; - Execute68kTrap(0xa247, &r); // SetOSTrapAddress() +#if SUPPORTS_EXTFS + // Install external file system + InstallExtFS(); +#endif } @@ -664,7 +666,7 @@ bool CheckROM(void) // Real addressing mode requires 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 (experimental) + // Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs return (ROMVersion == ROM_VERSION_CLASSIC) || (ROMVersion == ROM_VERSION_32); #endif } @@ -1153,13 +1155,20 @@ static bool patch_rom_32(void) *wp++ = htons(M68K_NOP); *wp = htons(M68K_NOP); - // Fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!) - static const uint8 fix_memsize_dat[] = {0x4e, 0x75}; - if ((base = find_rom_data(0x490, 0x4b0, fix_memsize_dat, sizeof(fix_memsize_dat))) == 0) return false; - D(bug("fix_memsize %08lx\n", base)); - wp = (uint16 *)(ROMBaseHost + base); + // Compute boot stack pointer and fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!) + wp = (uint16 *)(ROMBaseHost + 0x490); + *wp++ = htons(0x2038); // move.l $10c,d0 + *wp++ = htons(0x010c); + *wp++ = htons(0xd0b8); // add.l $2a6,d0 + *wp++ = htons(0x02a6); + *wp++ = htons(0xe288); // lsr.l #1,d0 + *wp++ = htons(0x0880); // bclr #0,d0 + *wp++ = htons(0x0000); + *wp++ = htons(0x0440); // subi.w #$400,d0 + *wp++ = htons(0x0400); + *wp++ = htons(0x2040); // move.l d0,a0 *wp++ = htons(M68K_EMUL_OP_FIX_MEMSIZE); - *wp = htons(M68K_RTS); + *wp++ = htons(M68K_RTS); 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}; base = find_rom_data(0x4c000, 0x4c080, fix_memsize2_dat, sizeof(fix_memsize2_dat)); @@ -1292,6 +1301,15 @@ static bool patch_rom_32(void) } } + // Don't set MemoryDispatch() to unimplemented trap + static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47}; + base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat)); + D(bug("memdisp %08lx\n", base)); + if (base) { // ROM15/32 + wp = (uint16 *)(ROMBaseHost + base + 10); + *wp = htons(M68K_NOP); + } + // Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000) uint32 edisk_offset = find_rom_resource('DRVR', 51); if (edisk_offset) { @@ -1399,6 +1417,14 @@ static bool patch_rom_32(void) *wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH); *wp = htons(M68K_RTS); +#if EMULATED_68K + // Replace BlockMove() + wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e)); // BlockMove() + *wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE); + *wp++ = htons(0x7000); + *wp = htons(M68K_RTS); +#endif + // Patch VIA interrupt handler wp = (uint16 *)(ROMBaseHost + 0x9bc4); // Level 1 handler *wp++ = htons(0x7002); // moveq #2,d0 (always 60Hz interrupt) @@ -1436,11 +1462,11 @@ bool PatchROM(void) return false; } -#ifdef M68K_BREAKPOINT // Install breakpoint - uint16 *wp = (uint16 *)(ROMBaseHost + M68K_BREAKPOINT); - *wp = htons(M68K_EMUL_BREAK); -#endif + if (ROMBreakpoint) { + uint16 *wp = (uint16 *)(ROMBaseHost + ROMBreakpoint); + *wp = htons(M68K_EMUL_BREAK); + } // Clear caches as we loaded and patched code FlushCodeCache(ROMBaseHost, ROMSize);