--- BasiliskII/src/rom_patches.cpp 2000/10/09 17:45:58 1.18 +++ BasiliskII/src/rom_patches.cpp 2010/02/21 12:00:01 1.28 @@ -1,7 +1,7 @@ /* * rom_patches.cpp - ROM patches * - * Basilisk II (C) 1997-2000 Christian Bauer + * Basilisk II (C) Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,9 +40,11 @@ // Global variables uint32 UniversalInfo; // ROM offset of UniversalInfo -uint32 PutScrapPatch; // Mac address of PutScrap() patch +uint32 PutScrapPatch = 0; // Mac address of PutScrap() patch +uint32 GetScrapPatch = 0; // Mac address of GetScrap() patch uint32 ROMBreakpoint = 0; // ROM offset of breakpoint (0 = disabled, 0x2310 = CritError) bool PrintROMInfo = false; // Flag: print ROM information in PatchROM() +bool PatchHWBases = true; // Flag: patch hardware base addresses static uint32 sony_offset; // ROM offset of .Sony driver static uint32 serd_offset; // ROM offset of SERD resource (serial drivers) @@ -52,12 +54,8 @@ static uint32 debugutil_offset; // ROM // Prototypes uint16 ROMVersion; - /* - * Convenience functions for retrieving a particular 16-bit word from - * a 32-bit word value. - * - * gb-- probably put those elsewhere... + * Macros used to extract one of the 16-bit words from a 32-bit word value */ #define HiWord(X) (((X) >> 16) & 0xffff) @@ -186,7 +184,7 @@ static void list_rom_resources(void) // Mapping of Model IDs to Model names struct mac_desc { - char *name; + const char *name; int32 id; }; @@ -260,7 +258,7 @@ static void print_universal_info(uint32 uint16 rom85 = ReadMacInt16(info + 20); // Find model name - char *name = "unknown"; + const char *name = "unknown"; for (int i=0; MacDesc[i].id >= 0; i++) if (MacDesc[i].id == id + 6) { name = MacDesc[i].name; @@ -1001,7 +999,9 @@ static bool patch_rom_classic(void) *wp++ = htons(M68K_NOP); *wp = htons(M68K_NOP); - wp = (uint16 *)(ROMBaseHost + 0x2be8); // 60Hz handler (handles everything) + wp = (uint16 *)(ROMBaseHost + 0x2be4); // 60Hz handler (handles everything) + *wp++ = htons(M68K_NOP); + *wp++ = htons(M68K_NOP); *wp++ = htons(M68K_EMUL_OP_IRQ); *wp++ = htons(0x4a80); // tst.l d0 *wp = htons(0x67f4); // beq 0x402be2 @@ -1032,6 +1032,31 @@ static bool patch_rom_32(void) bp = ROMBaseHost + UniversalInfo + 18; // productKind *bp = PrefsFindInt32("modelid"); +#if !ROM_IS_WRITE_PROTECTED +#if defined(USE_SCRATCHMEM_SUBTERFUGE) + // Set hardware base addresses to scratch memory area + if (PatchHWBases) { + extern uint8 *ScratchMem; + const uint32 ScratchMemBase = Host2MacAddr(ScratchMem); + + D(bug("LMGlob\tOfs/4\tBase\n")); + base = ROMBaseMac + UniversalInfo + ReadMacInt32(ROMBaseMac + UniversalInfo); // decoderInfoPtr + wp = (uint16 *)(ROMBaseHost + 0x94a); + while (*wp != 0xffff) { + int16 ofs = ntohs(*wp++); // offset in decoderInfo (/4) + int16 lmg = ntohs(*wp++); // address of LowMem global + D(bug("0x%04x\t%d\t0x%08x\n", lmg, ofs, ReadMacInt32(base + ofs*4))); + + // Fake address only if this is not the ASC base + if (lmg != 0xcc0) + WriteMacInt32(base + ofs*4, ScratchMemBase); + } + } +#else +#error System specific handling for writable ROM is required here +#endif +#endif + // Make FPU optional if (FPUType == 0) { bp = ROMBaseHost + UniversalInfo + 22; // defaultRSRCs @@ -1601,6 +1626,15 @@ static bool patch_rom_32(void) *wp++ = htons(base >> 16); *wp = htons(base & 0xffff); + // Install GetScrap() patch for clipboard data exchange (the patch is activated by EMUL_OP_INSTALL_DRIVERS) + GetScrapPatch = ROMBaseMac + sony_offset + 0xd00; + base = ROMBaseMac + find_rom_trap(0xa9fd); + wp = (uint16 *)(ROMBaseHost + sony_offset + 0xd00); + *wp++ = htons(M68K_EMUL_OP_GET_SCRAP); + *wp++ = htons(M68K_JMP); + *wp++ = htons(base >> 16); + *wp = htons(base & 0xffff); + // Look for double PACK 4 resources if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4)) == 0) return false; if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4, true)) == 0 && FPUType == 0) @@ -1614,7 +1648,9 @@ static bool patch_rom_32(void) *wp++ = htons(M68K_NOP); *wp = htons(M68K_NOP); - wp = (uint16 *)(ROMBaseHost + 0xa29a); // 60Hz handler (handles everything) + wp = (uint16 *)(ROMBaseHost + 0xa296); // 60Hz handler (handles everything) + *wp++ = htons(M68K_NOP); + *wp++ = htons(M68K_NOP); *wp++ = htons(M68K_EMUL_OP_IRQ); *wp++ = htons(0x4a80); // tst.l d0 *wp = htons(0x67f4); // beq 0x4080a294