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.7 by cebix, 1999-10-22T15:08:12Z 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-1999 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 38 | Line 38
38   #include "debug.h"
39  
40  
41 // Breakpoint
42 //#define M68K_BREAKPOINT 0x2310        // CritError
43 //#define M68K_BREAKPOINT 0x1d10        // BootMe
44
41   // Global variables
42 < uint32 UniversalInfo;   // ROM offset of UniversalInfo
43 < uint32 PutScrapPatch;   // Mac address of PutScrap() patch
44 <
45 < static uint32 sony_offset;                              // ROM offset of .Sony driver
46 < static uint32 serd_offset;                              // ROM offset of SERD resource (serial drivers)
47 < static uint32 microseconds_offset;              // ROM offset of Microseconds() replacement routine
48 < static uint32 memory_dispatch_offset;   // ROM offset of MemoryDispatch() replacement routine
42 > uint32 UniversalInfo;           // ROM offset of UniversalInfo
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
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)
# Line 84 | Line 90 | static uint32 find_rom_resource(uint32 s
90  
91          if (!cont)
92                  rsrc_ptr = x;
93 +        else
94 +                rsrc_ptr = ReadMacInt32(ROMBaseMac + rsrc_ptr + 8);
95  
96          for (;;) {
97                  lp = ROMBaseMac + rsrc_ptr;
# Line 142 | Line 150 | again:
150  
151  
152   /*
153 + *  Print ROM information to stream,
154 + */
155 +
156 + static void list_rom_resources(void)
157 + {
158 +        printf("ROM Resources:\n");
159 +        printf("Offset\t Type\tID\tSize\tName\n");
160 +        printf("------------------------------------------------\n");
161 +
162 +        uint32 lp = ROMBaseMac + ReadMacInt32(ROMBaseMac + 0x1a);
163 +        uint32 rsrc_ptr = ReadMacInt32(lp);
164 +
165 +        for (;;) {
166 +                lp = ROMBaseMac + rsrc_ptr;
167 +                uint32 data = ReadMacInt32(lp + 12);
168 +
169 +                char name[32];
170 +                int name_len = ReadMacInt8(lp + 23), i;
171 +                for (i=0; i<name_len; i++)
172 +                        name[i] = ReadMacInt8(lp + 24 + i);
173 +                name[i] = 0;
174 +
175 +                printf("%08x %c%c%c%c\t%d\t%d\t%s\n", data, ReadMacInt8(lp + 16), ReadMacInt8(lp + 17), ReadMacInt8(lp + 18), ReadMacInt8(lp + 19), ReadMacInt16(lp + 20), ReadMacInt32(ROMBaseMac + data - 8), name);
176 +
177 +                rsrc_ptr = ReadMacInt32(lp + 8);
178 +                if (!rsrc_ptr)
179 +                        break;
180 +        }
181 +        printf("\n");
182 + }
183 +
184 + // Mapping of Model IDs to Model names
185 + struct mac_desc {
186 +        char *name;
187 +        int32 id;
188 + };
189 +
190 + static mac_desc MacDesc[] = {
191 +        {"Classic"                              , 1},
192 +        {"Mac XL"                               , 2},
193 +        {"Mac 512KE"                    , 3},
194 +        {"Mac Plus"                             , 4},
195 +        {"Mac SE"                               , 5},
196 +        {"Mac II"                               , 6},
197 +        {"Mac IIx"                              , 7},
198 +        {"Mac IIcx"                             , 8},
199 +        {"Mac SE/030"                   , 9},
200 +        {"Mac Portable"                 , 10},
201 +        {"Mac IIci"                             , 11},
202 +        {"Mac IIfx"                             , 13},
203 +        {"Mac Classic"                  , 17},
204 +        {"Mac IIsi"                             , 18},
205 +        {"Mac LC"                               , 19},
206 +        {"Quadra 900"                   , 20},
207 +        {"PowerBook 170"                , 21},
208 +        {"Quadra 700"                   , 22},
209 +        {"Classic II"                   , 23},
210 +        {"PowerBook 100"                , 24},
211 +        {"PowerBook 140"                , 25},
212 +        {"Quadra 950"                   , 26},
213 +        {"Mac LCIII/Performa 450", 27},
214 +        {"PowerBook Duo 210"    , 29},
215 +        {"Centris 650"                  , 30},
216 +        {"PowerBook Duo 230"    , 32},
217 +        {"PowerBook 180"                , 33},
218 +        {"PowerBook 160"                , 34},
219 +        {"Quadra 800"                   , 35},
220 +        {"Quadra 650"                   , 36},
221 +        {"Mac LCII"                             , 37},
222 +        {"PowerBook Duo 250"    , 38},
223 +        {"Mac IIvi"                             , 44},
224 +        {"Mac IIvm/Performa 600", 45},
225 +        {"Mac IIvx"                             , 48},
226 +        {"Color Classic/Performa 250", 49},
227 +        {"PowerBook 165c"               , 50},
228 +        {"Centris 610"                  , 52},
229 +        {"Quadra 610"                   , 53},
230 +        {"PowerBook 145"                , 54},
231 +        {"Mac LC520"                    , 56},
232 +        {"Quadra/Centris 660AV" , 60},
233 +        {"Performa 46x"                 , 62},
234 +        {"PowerBook 180c"               , 71},
235 +        {"PowerBook 520/520c/540/540c", 72},
236 +        {"PowerBook Duo 270c"   , 77},
237 +        {"Quadra 840AV"                 , 78},
238 +        {"Performa 550"                 , 80},
239 +        {"PowerBook 165"                , 84},
240 +        {"PowerBook 190"                , 85},
241 +        {"Mac TV"                               , 88},
242 +        {"Mac LC475/Performa 47x", 89},
243 +        {"Mac LC575"                    , 92},
244 +        {"Quadra 605"                   , 94},
245 +        {"Quadra 630"                   , 98},
246 +        {"Mac LC580"                    , 99},
247 +        {"PowerBook Duo 280"    , 102},
248 +        {"PowerBook Duo 280c"   , 103},
249 +        {"PowerBook 150"                , 115},
250 +        {"unknown", -1}
251 + };
252 +
253 + static void print_universal_info(uint32 info)
254 + {
255 +        uint8 id = ReadMacInt8(info + 18);
256 +        uint16 hwcfg = ReadMacInt16(info + 16);
257 +        uint16 rom85 = ReadMacInt16(info + 20);
258 +
259 +        // Find model name
260 +        char *name = "unknown";
261 +        for (int i=0; MacDesc[i].id >= 0; i++)
262 +                if (MacDesc[i].id == id + 6) {
263 +                        name = MacDesc[i].name;
264 +                        break;
265 +                }
266 +
267 +        printf("%08x %02x\t%04x\t%04x\t%s\n", info - ROMBaseMac, id, hwcfg, rom85, name);
268 + }
269 +
270 + static void list_universal_infos(void)
271 + {
272 +        uint32 ofs = 0x3000;
273 +        for (int i=0; i<0x2000; i+=2, ofs+=2)
274 +                if (ReadMacInt32(ROMBaseMac + ofs) == 0xdc000505) {
275 +                        ofs -= 16;
276 +                        uint32 q;
277 +                        for (q=ofs; q > 0 && ReadMacInt32(ROMBaseMac + q) != ofs - q; q-=4) ;
278 +                        if (q > 0) {
279 +                                printf("Universal Table at %08x:\n", q);
280 +                                printf("Offset\t ID\tHWCfg\tROM85\tModel\n");
281 +                                printf("------------------------------------------------\n");
282 +                                while ((ofs = ReadMacInt32(ROMBaseMac + q))) {
283 +                                        print_universal_info(ROMBaseMac + ofs + q);
284 +                                        q += 4;
285 +                                }
286 +                        }
287 +                        break;
288 +                }
289 +        printf("\n");
290 + }
291 +
292 + static void print_rom_info(void)
293 + {
294 +        printf("\nROM Info:\n");
295 +        printf("Checksum    : %08x\n", ReadMacInt32(ROMBaseMac));
296 +        printf("Version     : %04x\n", ROMVersion);
297 +        printf("Sub Version : %04x\n", ReadMacInt16(ROMBaseMac + 18));
298 +        printf("Resource Map: %08x\n", ReadMacInt32(ROMBaseMac + 26));
299 +        printf("Trap Tables : %08x\n\n", ReadMacInt32(ROMBaseMac + 34));
300 +        if (ROMVersion == ROM_VERSION_32) {
301 +                list_rom_resources();
302 +                list_universal_infos();
303 +        }
304 + }
305 +
306 +
307 + /*
308   *  Driver stubs
309   */
310  
# Line 539 | Line 702 | static const uint8 adbop_patch[] = {   //
702  
703   void InstallDrivers(uint32 pb)
704   {
705 <        D(bug("InstallDrivers\n"));
705 >        D(bug("InstallDrivers, pb %08x\n", pb));
706          M68kRegisters r;
707  
708          // Install Microseconds() replacement routine
# Line 547 | Line 710 | void InstallDrivers(uint32 pb)
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;
# Line 642 | Line 810 | void InstallSERD(void)
810  
811   void PatchAfterStartup(void)
812   {
645        // Install MemoryDispatch() replacement routine
646        M68kRegisters r;
647        r.a[0] = ROMBaseMac + memory_dispatch_offset;
648        r.d[0] = 0xa05c;
649        Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
650
813   #if SUPPORTS_EXTFS
814          // Install external file system
815          InstallExtFS();
# Line 664 | 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 782 | Line 944 | static bool patch_rom_classic(void)
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()
# Line 831 | 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 862 | 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 1044 | Line 1238 | static bool patch_rom_32(void)
1238          *wp = htons(M68K_RTS);
1239  
1240          // Fake CPU speed test (SetupTimeK)
1241 +        // *** increased jl : MacsBug uses TimeDBRA for kbd repeat timing
1242          wp = (uint16 *)(ROMBaseHost + 0x800);
1243          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeDBRA
1244 <        *wp++ = htons(100);
1244 >        *wp++ = htons(10000);
1245          *wp++ = htons(0x0d00);
1246          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeSCCDBRA
1247 <        *wp++ = htons(100);
1247 >        *wp++ = htons(10000);
1248          *wp++ = htons(0x0d02);
1249          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeSCSIDBRA
1250 <        *wp++ = htons(100);
1250 >        *wp++ = htons(10000);
1251          *wp++ = htons(0x0b24);
1252          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeRAMDBRA
1253 <        *wp++ = htons(100);
1253 >        *wp++ = htons(10000);
1254          *wp++ = htons(0x0cea);
1255          *wp = htons(M68K_RTS);
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 1085 | 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 1157 | Line 1362 | static bool patch_rom_32(void)
1362          *wp++ = htons(M68K_NOP);
1363          *wp = htons(M68K_NOP);
1364  
1365 <        // Fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!)
1366 <        static const uint8 fix_memsize_dat[] = {0x4e, 0x75};
1367 <        if ((base = find_rom_data(0x490, 0x4b0, fix_memsize_dat, sizeof(fix_memsize_dat))) == 0) return false;
1368 <        D(bug("fix_memsize %08lx\n", base));
1369 <        wp = (uint16 *)(ROMBaseHost + base);
1365 >        // Compute boot stack pointer and fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!)
1366 >        wp = (uint16 *)(ROMBaseHost + 0x490);
1367 >        *wp++ = htons(0x2038);  // move.l       $10c,d0
1368 >        *wp++ = htons(0x010c);
1369 >        *wp++ = htons(0xd0b8);  // add.l        $2a6,d0
1370 >        *wp++ = htons(0x02a6);
1371 >        *wp++ = htons(0xe288);  // lsr.l        #1,d0
1372 >        *wp++ = htons(0x0880);  // bclr         #0,d0
1373 >        *wp++ = htons(0x0000);
1374 >        *wp++ = htons(0x0440);  // subi.w       #$400,d0
1375 >        *wp++ = htons(0x0400);
1376 >        *wp++ = htons(0x2040);  // move.l       d0,a0
1377          *wp++ = htons(M68K_EMUL_OP_FIX_MEMSIZE);
1378 <        *wp = htons(M68K_RTS);
1378 >        *wp++ = htons(M68K_RTS);
1379  
1380          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};
1381          base = find_rom_data(0x4c000, 0x4c080, fix_memsize2_dat, sizeof(fix_memsize2_dat));
# Line 1274 | 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 1296 | Line 1510 | static bool patch_rom_32(void)
1510                  }
1511          }
1512  
1513 +        // Don't set MemoryDispatch() to unimplemented trap
1514 +        static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47};
1515 +        base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat));
1516 +        D(bug("memdisp %08lx\n", base));
1517 +        if (base) {     // ROM15/22/23/26/27/32
1518 +                wp = (uint16 *)(ROMBaseHost + base + 10);
1519 +                *wp = htons(M68K_NOP);
1520 +        }
1521 +
1522          // Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000)
1523 <        uint32 edisk_offset = find_rom_resource('DRVR', 51);
1523 >        uint32 edisk_offset = find_rom_resource(FOURCC('D','R','V','R'), 51);
1524          if (edisk_offset) {
1525                  static const uint8 edisk_dat[] = {0xd5, 0xfc, 0x00, 0x01, 0x00, 0x00, 0xb5, 0xfc, 0x00, 0xe0, 0x00, 0x00};
1526                  base = find_rom_data(edisk_offset, edisk_offset + 0x10000, edisk_dat, sizeof(edisk_dat));
# Line 1310 | Line 1533 | static bool patch_rom_32(void)
1533          }
1534  
1535          // Replace .Sony driver
1536 <        sony_offset = find_rom_resource('DRVR', 4);
1536 >        sony_offset = find_rom_resource(FOURCC('D','R','V','R'), 4);
1537          D(bug("sony %08lx\n", sony_offset));
1538          memcpy(ROMBaseHost + sony_offset, sony_driver, sizeof(sony_driver));
1539  
# Line 1329 | Line 1552 | static bool patch_rom_32(void)
1552          memcpy(ROMBaseHost + sony_offset + 0xa00, CDROMIcon, sizeof(CDROMIcon));
1553  
1554          // Install SERD patch and serial drivers
1555 <        serd_offset = find_rom_resource('SERD', 0);
1555 >        serd_offset = find_rom_resource(FOURCC('S','E','R','D'), 0);
1556          D(bug("serd %08lx\n", serd_offset));
1557          wp = (uint16 *)(ROMBaseHost + serd_offset + 12);
1558          *wp++ = htons(M68K_EMUL_OP_SERD);
# Line 1362 | Line 1585 | static bool patch_rom_32(void)
1585          *wp++ = htons(M68K_RTS);
1586          microseconds_offset = (uint8 *)wp - ROMBaseHost;
1587          *wp++ = htons(M68K_EMUL_OP_MICROSECONDS);
1588 +        *wp++ = htons(M68K_RTS);
1589 +
1590 +        // Replace DebugUtil
1591 +        debugutil_offset = (uint8 *)wp - ROMBaseHost;
1592 +        *wp++ = htons(M68K_EMUL_OP_DEBUGUTIL);
1593          *wp = htons(M68K_RTS);
1594  
1595          // Replace SCSIDispatch()
# Line 1397 | Line 1625 | static bool patch_rom_32(void)
1625          *wp++ = htons(base >> 16);
1626          *wp = htons(base & 0xffff);
1627  
1628 <        // Install MemoryDispatch() replacement routine (activated in PatchAfterStartup())
1629 <        memory_dispatch_offset = sony_offset + 0xc20;
1630 <        wp = (uint16 *)(ROMBaseHost + memory_dispatch_offset);
1631 <        *wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH);
1404 <        *wp = htons(M68K_RTS);
1405 <
1406 < #if EMULATED_68K
1407 <        // Replace BlockMove()
1408 <        wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e));   // BlockMove()
1409 <        *wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE);
1410 <        *wp++ = htons(0x7000);
1411 <        *wp = htons(M68K_RTS);
1412 < #endif
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)
1631 >                printf("WARNING: This ROM seems to require an FPU\n");
1632  
1633          // Patch VIA interrupt handler
1634          wp = (uint16 *)(ROMBaseHost + 0x9bc4);  // Level 1 handler
# Line 1419 | 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
# Line 1428 | Line 1649 | static bool patch_rom_32(void)
1649  
1650   bool PatchROM(void)
1651   {
1652 <        // Print ROM info
1653 <        D(bug("ROM Info:\n"));
1654 <        D(bug("Checksum: %08lx\n", ReadMacInt32(ROMBaseMac)));
1434 <        D(bug("Version: %04x\n", ROMVersion));
1435 <        D(bug("Sub Version: %04x\n", ReadMacInt16(ROMBaseMac + 18)));
1652 >        // Print some information about the ROM
1653 >        if (PrintROMInfo)
1654 >                print_rom_info();
1655  
1656          // Patch ROM depending on version
1657          switch (ROMVersion) {
# Line 1448 | Line 1667 | bool PatchROM(void)
1667                          return false;
1668          }
1669  
1451 #ifdef M68K_BREAKPOINT
1670          // Install breakpoint
1671 <        uint16 *wp = (uint16 *)(ROMBaseHost + M68K_BREAKPOINT);
1672 <        *wp = htons(M68K_EMUL_BREAK);
1673 < #endif
1671 >        if (ROMBreakpoint) {
1672 >                uint16 *wp = (uint16 *)(ROMBaseHost + ROMBreakpoint);
1673 >                *wp = htons(M68K_EMUL_BREAK);
1674 >        }
1675  
1676          // Clear caches as we loaded and patched code
1677          FlushCodeCache(ROMBaseHost, ROMSize);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines