ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/rom_patches.cpp
(Generate patch)

Comparing BasiliskII/src/rom_patches.cpp (file contents):
Revision 1.16 by jlachmann, 2000-08-20T14:08:40Z vs.
Revision 1.23 by cebix, 2004-01-12T15:29:22Z

# Line 1 | Line 1
1   /*
2   *  rom_patches.cpp - ROM patches
3   *
4 < *  Basilisk II (C) 1997-2000 Christian Bauer
4 > *  Basilisk II (C) 1997-2004 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
# Line 43 | Line 43 | uint32 UniversalInfo;          // ROM offset of
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)
# Line 52 | Line 53 | static uint32 debugutil_offset;                // ROM
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)
# Line 818 | Line 826 | bool CheckROM(void)
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
# Line 990 | Line 998 | static bool patch_rom_classic(void)
998          *wp++ = htons(M68K_NOP);
999          *wp = htons(M68K_NOP);
1000  
1001 <        wp = (uint16 *)(ROMBaseHost + 0x2be8);  // 60Hz handler (handles everything)
1001 >        wp = (uint16 *)(ROMBaseHost + 0x2be4);  // 60Hz handler (handles everything)
1002 >        *wp++ = htons(M68K_NOP);
1003 >        *wp++ = htons(M68K_NOP);
1004          *wp++ = htons(M68K_EMUL_OP_IRQ);
1005          *wp++ = htons(0x4a80);          // tst.l        d0
1006          *wp = htons(0x67f4);            // beq          0x402be2
# Line 1021 | Line 1031 | static bool patch_rom_32(void)
1031          bp = ROMBaseHost + UniversalInfo + 18;          // productKind
1032          *bp = PrefsFindInt32("modelid");
1033  
1034 + #if !ROM_IS_WRITE_PROTECTED
1035 + #if defined(USE_SCRATCHMEM_SUBTERFUGE)
1036 +        // Set hardware base addresses to scratch memory area
1037 +        if (PatchHWBases) {
1038 +                extern uint8 *ScratchMem;
1039 +                const uint32 ScratchMemBase = Host2MacAddr(ScratchMem);
1040 +                
1041 +                D(bug("LMGlob\tOfs/4\tBase\n"));
1042 +                base = ROMBaseMac + UniversalInfo + ReadMacInt32(ROMBaseMac + UniversalInfo); // decoderInfoPtr
1043 +                wp = (uint16 *)(ROMBaseHost + 0x94a);
1044 +                while (*wp != 0xffff) {
1045 +                        int16 ofs = ntohs(*wp++);                       // offset in decoderInfo (/4)
1046 +                        int16 lmg = ntohs(*wp++);                       // address of LowMem global
1047 +                        D(bug("0x%04x\t%d\t0x%08x\n", lmg, ofs, ReadMacInt32(base + ofs*4)));
1048 +                        
1049 +                        // Fake address only if this is not the ASC base
1050 +                        if (lmg != 0xcc0)
1051 +                                WriteMacInt32(base + ofs*4, ScratchMemBase);
1052 +                }
1053 +        }
1054 + #else
1055 + #error System specific handling for writable ROM is required here
1056 + #endif
1057 + #endif
1058 +
1059          // Make FPU optional
1060          if (FPUType == 0) {
1061                  bp = ROMBaseHost + UniversalInfo + 22;  // defaultRSRCs
# Line 1221 | Line 1256 | static bool patch_rom_32(void)
1256  
1257   #if REAL_ADDRESSING
1258          // Move system zone to start of Mac RAM
1259 <        lp = (uint32 *)(ROMBaseHost + 0x50a);
1260 <        *lp++ = htonl(RAMBaseMac);
1261 <        *lp = htonl(RAMBaseMac + 0x1800);
1259 >        wp = (uint16 *)(ROMBaseHost + 0x50a);
1260 >        *wp++ = htons(HiWord(RAMBaseMac + 0x2000));
1261 >        *wp++ = htons(LoWord(RAMBaseMac + 0x2000));
1262 >        *wp++ = htons(HiWord(RAMBaseMac + 0x3800));
1263 >        *wp = htons(LoWord(RAMBaseMac + 0x3800));
1264   #endif
1265  
1266   #if !ROM_IS_WRITE_PROTECTED
1267 < #if defined(AMIGA)
1267 > #if defined(USE_SCRATCHMEM_SUBTERFUGE)
1268          // Set fake handle at 0x0000 to scratch memory area (so broken Mac programs won't write into Mac ROM)
1269 <        extern uint32 ScratchMem;
1269 >        extern uint8 *ScratchMem;
1270 >        const uint32 ScratchMemBase = Host2MacAddr(ScratchMem);
1271          wp = (uint16 *)(ROMBaseHost + 0xccaa);
1272          *wp++ = htons(0x203c);                  // move.l       #ScratchMem,d0
1273 <        *wp++ = htons(ScratchMem >> 16);
1274 <        *wp = htons(ScratchMem);
1273 >        *wp++ = htons(ScratchMemBase >> 16);
1274 >        *wp = htons(ScratchMemBase);
1275   #else
1276   #error System specific handling for writable ROM is required here
1277   #endif
# Line 1245 | Line 1283 | static bool patch_rom_32(void)
1283          *wp++ = htons(M68K_NOP);
1284          *wp = htons(M68K_NOP);
1285   #endif
1286 <
1286 >        
1287 > #if REAL_ADDRESSING && !defined(AMIGA)
1288 >        // gb-- Temporary hack to get rid of crashes in Speedometer
1289 >        wp = (uint16 *)(ROMBaseHost + 0xdba2);
1290 >        if (ntohs(*wp) == 0x662c)               // bne.b        #$2c
1291 >                *wp = htons(0x602c);            // bra.b        #$2c
1292 > #endif
1293 >        
1294          // Don't write to VIA in InitTimeMgr
1295          wp = (uint16 *)(ROMBaseHost + 0xb0e2);
1296          *wp++ = htons(0x4cdf);                  // movem.l      (sp)+,d0-d5/a0-a4
# Line 1441 | Line 1486 | static bool patch_rom_32(void)
1486          if (ROMSize > 0x80000) {
1487  
1488                  // BlockMove()
1489 <                static const uint8 ptest_dat[] = {0xa0, 0x8d, 0x0c, 0x81, 0x00, 0x00, 0x0c, 0x00, 0x6d, 0x06, 0x4e, 0x71, 0xf4, 0xf8};
1490 <                base = find_rom_data(0x87000, 0x87800, ptest_dat, sizeof(ptest_dat));
1491 <                D(bug("ptest %08lx\n", base));
1489 >                static const uint8 bmove_dat[] = {0x20, 0x5f, 0x22, 0x5f, 0x0c, 0x38, 0x00, 0x04, 0x01, 0x2f};
1490 >                base = find_rom_data(0x87000, 0x87800, bmove_dat, sizeof(bmove_dat));
1491 >                D(bug("block_move %08lx\n", base));
1492                  if (base) {             // ROM15/22/23/26/27/32
1493 <                        wp = (uint16 *)(ROMBaseHost + base + 8);
1494 <                        *wp = htons(M68K_NOP);
1493 >                        wp = (uint16 *)(ROMBaseHost + base + 4);
1494 >                        *wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE);
1495 >                        *wp++ = htons(0x7000);
1496 >                        *wp = htons(M68K_RTS);
1497                  }
1498  
1499                  // SANE
# Line 1578 | Line 1625 | static bool patch_rom_32(void)
1625          *wp++ = htons(base >> 16);
1626          *wp = htons(base & 0xffff);
1627  
1581 #if EMULATED_68K
1582        // Replace BlockMove()
1583        wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e));   // BlockMove()
1584        *wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE);
1585        *wp++ = htons(0x7000);
1586        *wp = htons(M68K_RTS);
1587 #endif
1588
1628          // Look for double PACK 4 resources
1629          if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4)) == 0) return false;
1630          if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4, true)) == 0 && FPUType == 0)
# Line 1599 | Line 1638 | static bool patch_rom_32(void)
1638          *wp++ = htons(M68K_NOP);
1639          *wp = htons(M68K_NOP);
1640  
1641 <        wp = (uint16 *)(ROMBaseHost + 0xa29a);  // 60Hz handler (handles everything)
1641 >        wp = (uint16 *)(ROMBaseHost + 0xa296);  // 60Hz handler (handles everything)
1642 >        *wp++ = htons(M68K_NOP);
1643 >        *wp++ = htons(M68K_NOP);
1644          *wp++ = htons(M68K_EMUL_OP_IRQ);
1645          *wp++ = htons(0x4a80);          // tst.l        d0
1646          *wp = htons(0x67f4);            // beq          0x4080a294

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines