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.1.1.1 by cebix, 1999-10-03T14:16:25Z vs.
Revision 1.28 by cebix, 2010-02-21T12:00:01Z

# Line 1 | Line 1
1   /*
2   *  rom_patches.cpp - ROM patches
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 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 30 | Line 30
30   #include "disk.h"
31   #include "cdrom.h"
32   #include "video.h"
33 + #include "extfs.h"
34   #include "prefs.h"
35   #include "rom_patches.h"
36  
# Line 37 | Line 38
38   #include "debug.h"
39  
40  
40 // Breakpoint
41 //#define M68K_BREAKPOINT 0x2310        // CritError
42 //#define M68K_BREAKPOINT 0x1d10        // BootMe
43
41   // Global variables
42 < uint32 UniversalInfo;   // ROM offset of UniversalInfo
43 < uint32 PutScrapPatch;   // Mac address of PutScrap() patch
42 > uint32 UniversalInfo;           // ROM offset of UniversalInfo
43 > uint32 PutScrapPatch = 0;       // Mac address of PutScrap() patch
44 > uint32 GetScrapPatch = 0;       // Mac address of GetScrap() patch
45 > uint32 ROMBreakpoint = 0;       // ROM offset of breakpoint (0 = disabled, 0x2310 = CritError)
46 > bool PrintROMInfo = false;      // Flag: print ROM information in PatchROM()
47 > bool PatchHWBases = true;       // Flag: patch hardware base addresses
48  
49   static uint32 sony_offset;              // ROM offset of .Sony driver
50   static uint32 serd_offset;              // ROM offset of SERD resource (serial drivers)
51   static uint32 microseconds_offset;      // ROM offset of Microseconds() replacement routine
52 < static uint32 memory_dispatch_offset;   // ROM offset of MemoryDispatch() replacement routine
52 > static uint32 debugutil_offset;         // ROM offset of DebugUtil() replacement routine
53  
54   // Prototypes
55   uint16 ROMVersion;
56  
57 + /*
58 + *  Macros used to extract one of the 16-bit words from a 32-bit word value
59 + */
60 +
61 + #define HiWord(X) (((X) >> 16) & 0xffff)
62 + #define LoWord(X) ((X) & 0xffff)
63 +
64  
65   /*
66   *  Search ROM for byte string, return ROM offset (or 0)
# Line 83 | Line 91 | static uint32 find_rom_resource(uint32 s
91  
92          if (!cont)
93                  rsrc_ptr = x;
94 +        else
95 +                rsrc_ptr = ReadMacInt32(ROMBaseMac + rsrc_ptr + 8);
96  
97          for (;;) {
98                  lp = ROMBaseMac + rsrc_ptr;
# Line 141 | Line 151 | again:
151  
152  
153   /*
154 + *  Print ROM information to stream,
155 + */
156 +
157 + static void list_rom_resources(void)
158 + {
159 +        printf("ROM Resources:\n");
160 +        printf("Offset\t Type\tID\tSize\tName\n");
161 +        printf("------------------------------------------------\n");
162 +
163 +        uint32 lp = ROMBaseMac + ReadMacInt32(ROMBaseMac + 0x1a);
164 +        uint32 rsrc_ptr = ReadMacInt32(lp);
165 +
166 +        for (;;) {
167 +                lp = ROMBaseMac + rsrc_ptr;
168 +                uint32 data = ReadMacInt32(lp + 12);
169 +
170 +                char name[32];
171 +                int name_len = ReadMacInt8(lp + 23), i;
172 +                for (i=0; i<name_len; i++)
173 +                        name[i] = ReadMacInt8(lp + 24 + i);
174 +                name[i] = 0;
175 +
176 +                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);
177 +
178 +                rsrc_ptr = ReadMacInt32(lp + 8);
179 +                if (!rsrc_ptr)
180 +                        break;
181 +        }
182 +        printf("\n");
183 + }
184 +
185 + // Mapping of Model IDs to Model names
186 + struct mac_desc {
187 +        const char *name;
188 +        int32 id;
189 + };
190 +
191 + static mac_desc MacDesc[] = {
192 +        {"Classic"                              , 1},
193 +        {"Mac XL"                               , 2},
194 +        {"Mac 512KE"                    , 3},
195 +        {"Mac Plus"                             , 4},
196 +        {"Mac SE"                               , 5},
197 +        {"Mac II"                               , 6},
198 +        {"Mac IIx"                              , 7},
199 +        {"Mac IIcx"                             , 8},
200 +        {"Mac SE/030"                   , 9},
201 +        {"Mac Portable"                 , 10},
202 +        {"Mac IIci"                             , 11},
203 +        {"Mac IIfx"                             , 13},
204 +        {"Mac Classic"                  , 17},
205 +        {"Mac IIsi"                             , 18},
206 +        {"Mac LC"                               , 19},
207 +        {"Quadra 900"                   , 20},
208 +        {"PowerBook 170"                , 21},
209 +        {"Quadra 700"                   , 22},
210 +        {"Classic II"                   , 23},
211 +        {"PowerBook 100"                , 24},
212 +        {"PowerBook 140"                , 25},
213 +        {"Quadra 950"                   , 26},
214 +        {"Mac LCIII/Performa 450", 27},
215 +        {"PowerBook Duo 210"    , 29},
216 +        {"Centris 650"                  , 30},
217 +        {"PowerBook Duo 230"    , 32},
218 +        {"PowerBook 180"                , 33},
219 +        {"PowerBook 160"                , 34},
220 +        {"Quadra 800"                   , 35},
221 +        {"Quadra 650"                   , 36},
222 +        {"Mac LCII"                             , 37},
223 +        {"PowerBook Duo 250"    , 38},
224 +        {"Mac IIvi"                             , 44},
225 +        {"Mac IIvm/Performa 600", 45},
226 +        {"Mac IIvx"                             , 48},
227 +        {"Color Classic/Performa 250", 49},
228 +        {"PowerBook 165c"               , 50},
229 +        {"Centris 610"                  , 52},
230 +        {"Quadra 610"                   , 53},
231 +        {"PowerBook 145"                , 54},
232 +        {"Mac LC520"                    , 56},
233 +        {"Quadra/Centris 660AV" , 60},
234 +        {"Performa 46x"                 , 62},
235 +        {"PowerBook 180c"               , 71},
236 +        {"PowerBook 520/520c/540/540c", 72},
237 +        {"PowerBook Duo 270c"   , 77},
238 +        {"Quadra 840AV"                 , 78},
239 +        {"Performa 550"                 , 80},
240 +        {"PowerBook 165"                , 84},
241 +        {"PowerBook 190"                , 85},
242 +        {"Mac TV"                               , 88},
243 +        {"Mac LC475/Performa 47x", 89},
244 +        {"Mac LC575"                    , 92},
245 +        {"Quadra 605"                   , 94},
246 +        {"Quadra 630"                   , 98},
247 +        {"Mac LC580"                    , 99},
248 +        {"PowerBook Duo 280"    , 102},
249 +        {"PowerBook Duo 280c"   , 103},
250 +        {"PowerBook 150"                , 115},
251 +        {"unknown", -1}
252 + };
253 +
254 + static void print_universal_info(uint32 info)
255 + {
256 +        uint8 id = ReadMacInt8(info + 18);
257 +        uint16 hwcfg = ReadMacInt16(info + 16);
258 +        uint16 rom85 = ReadMacInt16(info + 20);
259 +
260 +        // Find model name
261 +        const char *name = "unknown";
262 +        for (int i=0; MacDesc[i].id >= 0; i++)
263 +                if (MacDesc[i].id == id + 6) {
264 +                        name = MacDesc[i].name;
265 +                        break;
266 +                }
267 +
268 +        printf("%08x %02x\t%04x\t%04x\t%s\n", info - ROMBaseMac, id, hwcfg, rom85, name);
269 + }
270 +
271 + static void list_universal_infos(void)
272 + {
273 +        uint32 ofs = 0x3000;
274 +        for (int i=0; i<0x2000; i+=2, ofs+=2)
275 +                if (ReadMacInt32(ROMBaseMac + ofs) == 0xdc000505) {
276 +                        ofs -= 16;
277 +                        uint32 q;
278 +                        for (q=ofs; q > 0 && ReadMacInt32(ROMBaseMac + q) != ofs - q; q-=4) ;
279 +                        if (q > 0) {
280 +                                printf("Universal Table at %08x:\n", q);
281 +                                printf("Offset\t ID\tHWCfg\tROM85\tModel\n");
282 +                                printf("------------------------------------------------\n");
283 +                                while ((ofs = ReadMacInt32(ROMBaseMac + q))) {
284 +                                        print_universal_info(ROMBaseMac + ofs + q);
285 +                                        q += 4;
286 +                                }
287 +                        }
288 +                        break;
289 +                }
290 +        printf("\n");
291 + }
292 +
293 + static void print_rom_info(void)
294 + {
295 +        printf("\nROM Info:\n");
296 +        printf("Checksum    : %08x\n", ReadMacInt32(ROMBaseMac));
297 +        printf("Version     : %04x\n", ROMVersion);
298 +        printf("Sub Version : %04x\n", ReadMacInt16(ROMBaseMac + 18));
299 +        printf("Resource Map: %08x\n", ReadMacInt32(ROMBaseMac + 26));
300 +        printf("Trap Tables : %08x\n\n", ReadMacInt32(ROMBaseMac + 34));
301 +        if (ROMVersion == ROM_VERSION_32) {
302 +                list_rom_resources();
303 +                list_universal_infos();
304 +        }
305 + }
306 +
307 +
308 + /*
309   *  Driver stubs
310   */
311  
312   static const uint8 sony_driver[] = {    // Replacement for .Sony driver
313          // Driver header
314 <        SonyDriverFlags >> 8, SonyDriverFlags & 0xff, SonyDriverDelay >> 8, SonyDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
314 >        SonyDriverFlags >> 8, SonyDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
315          0x00, 0x18,                                                     // Open() offset
316          0x00, 0x1c,                                                     // Prime() offset
317          0x00, 0x20,                                                     // Control() offset
# Line 194 | Line 359 | static const uint8 sony_driver[] = {   //
359  
360   static const uint8 disk_driver[] = {    // Generic disk driver
361          // Driver header
362 <        DiskDriverFlags >> 8, DiskDriverFlags & 0xff, DiskDriverDelay >> 8, DiskDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
362 >        DiskDriverFlags >> 8, DiskDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
363          0x00, 0x18,                                                     // Open() offset
364          0x00, 0x1c,                                                     // Prime() offset
365          0x00, 0x20,                                                     // Control() offset
# Line 242 | Line 407 | static const uint8 disk_driver[] = {   //
407  
408   static const uint8 cdrom_driver[] = {   // CD-ROM driver
409          // Driver header
410 <        CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, CDROMDriverDelay >> 8, CDROMDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
410 >        CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
411          0x00, 0x1c,                                                     // Open() offset
412          0x00, 0x20,                                                     // Prime() offset
413          0x00, 0x24,                                                     // Control() offset
# Line 538 | Line 703 | static const uint8 adbop_patch[] = {   //
703  
704   void InstallDrivers(uint32 pb)
705   {
706 <        D(bug("InstallDrivers\n"));
706 >        D(bug("InstallDrivers, pb %08x\n", pb));
707          M68kRegisters r;
708  
709          // Install Microseconds() replacement routine
# Line 546 | Line 711 | void InstallDrivers(uint32 pb)
711          r.d[0] = 0xa093;
712          Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
713  
714 +        // Install DebugUtil() replacement routine
715 +        r.a[0] = ROMBaseMac + debugutil_offset;
716 +        r.d[0] = 0xa08d;
717 +        Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
718 +
719          // Install disk driver
720          r.a[0] = ROMBaseMac + sony_offset + 0x100;
721          r.d[0] = (uint32)DiskRefNum;
# Line 555 | Line 725 | void InstallDrivers(uint32 pb)
725          uint32 dce = ReadMacInt32(r.a[0]);
726          WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x100);
727          WriteMacInt16(dce + dCtlFlags, DiskDriverFlags);
558        WriteMacInt16(dce + dCtlDelay, DiskDriverDelay);
728  
729          // Open disk driver
730          WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x112);
# Line 574 | Line 743 | void InstallDrivers(uint32 pb)
743                  dce = ReadMacInt32(r.a[0]);
744                  WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x200);
745                  WriteMacInt16(dce + dCtlFlags, CDROMDriverFlags);
577                WriteMacInt16(dce + dCtlDelay, CDROMDriverDelay);
746  
747                  // Open CD-ROM driver
748                  WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x212);
# Line 643 | Line 811 | void InstallSERD(void)
811  
812   void PatchAfterStartup(void)
813   {
814 <        // Install MemoryDispatch() replacement routine
815 <        M68kRegisters r;
816 <        r.a[0] = ROMBaseMac + memory_dispatch_offset;
817 <        r.d[0] = 0xa05c;
650 <        Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
814 > #if SUPPORTS_EXTFS
815 >        // Install external file system
816 >        InstallExtFS();
817 > #endif
818   }
819  
820  
# Line 660 | Line 827 | bool CheckROM(void)
827          // Read version
828          ROMVersion = ntohs(*(uint16 *)(ROMBaseHost + 8));
829  
830 < #if REAL_ADDRESSING
831 <        // Real addressing mode requires a 32-bit clean ROM
830 > #if REAL_ADDRESSING || DIRECT_ADDRESSING
831 >        // Real and direct addressing modes require a 32-bit clean ROM
832          return ROMVersion == ROM_VERSION_32;
833   #else
834 <        // Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs (experimental)
834 >        // Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs
835          return (ROMVersion == ROM_VERSION_CLASSIC) || (ROMVersion == ROM_VERSION_32);
836   #endif
837   }
# Line 778 | Line 945 | static bool patch_rom_classic(void)
945          *wp++ = htons(M68K_RTS);
946          microseconds_offset = (uint8 *)wp - ROMBaseHost;
947          *wp++ = htons(M68K_EMUL_OP_MICROSECONDS);
948 +        *wp++ = htons(M68K_RTS);
949 +
950 +        // Replace DebugUtil
951 +        debugutil_offset = (uint8 *)wp - ROMBaseHost;
952 +        *wp++ = htons(M68K_EMUL_OP_DEBUGUTIL);
953          *wp = htons(M68K_RTS);
954  
955          // Replace SCSIDispatch()
# Line 827 | Line 999 | static bool patch_rom_classic(void)
999          *wp++ = htons(M68K_NOP);
1000          *wp = htons(M68K_NOP);
1001  
1002 <        wp = (uint16 *)(ROMBaseHost + 0x2be8);  // 60Hz handler (handles everything)
1002 >        wp = (uint16 *)(ROMBaseHost + 0x2be4);  // 60Hz handler (handles everything)
1003 >        *wp++ = htons(M68K_NOP);
1004 >        *wp++ = htons(M68K_NOP);
1005          *wp++ = htons(M68K_EMUL_OP_IRQ);
1006          *wp++ = htons(0x4a80);          // tst.l        d0
1007          *wp = htons(0x67f4);            // beq          0x402be2
# Line 858 | Line 1032 | static bool patch_rom_32(void)
1032          bp = ROMBaseHost + UniversalInfo + 18;          // productKind
1033          *bp = PrefsFindInt32("modelid");
1034  
1035 + #if !ROM_IS_WRITE_PROTECTED
1036 + #if defined(USE_SCRATCHMEM_SUBTERFUGE)
1037 +        // Set hardware base addresses to scratch memory area
1038 +        if (PatchHWBases) {
1039 +                extern uint8 *ScratchMem;
1040 +                const uint32 ScratchMemBase = Host2MacAddr(ScratchMem);
1041 +                
1042 +                D(bug("LMGlob\tOfs/4\tBase\n"));
1043 +                base = ROMBaseMac + UniversalInfo + ReadMacInt32(ROMBaseMac + UniversalInfo); // decoderInfoPtr
1044 +                wp = (uint16 *)(ROMBaseHost + 0x94a);
1045 +                while (*wp != 0xffff) {
1046 +                        int16 ofs = ntohs(*wp++);                       // offset in decoderInfo (/4)
1047 +                        int16 lmg = ntohs(*wp++);                       // address of LowMem global
1048 +                        D(bug("0x%04x\t%d\t0x%08x\n", lmg, ofs, ReadMacInt32(base + ofs*4)));
1049 +                        
1050 +                        // Fake address only if this is not the ASC base
1051 +                        if (lmg != 0xcc0)
1052 +                                WriteMacInt32(base + ofs*4, ScratchMemBase);
1053 +                }
1054 +        }
1055 + #else
1056 + #error System specific handling for writable ROM is required here
1057 + #endif
1058 + #endif
1059 +
1060          // Make FPU optional
1061          if (FPUType == 0) {
1062                  bp = ROMBaseHost + UniversalInfo + 22;  // defaultRSRCs
# Line 1040 | Line 1239 | static bool patch_rom_32(void)
1239          *wp = htons(M68K_RTS);
1240  
1241          // Fake CPU speed test (SetupTimeK)
1242 +        // *** increased jl : MacsBug uses TimeDBRA for kbd repeat timing
1243          wp = (uint16 *)(ROMBaseHost + 0x800);
1244          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeDBRA
1245 <        *wp++ = htons(100);
1245 >        *wp++ = htons(10000);
1246          *wp++ = htons(0x0d00);
1247          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeSCCDBRA
1248 <        *wp++ = htons(100);
1248 >        *wp++ = htons(10000);
1249          *wp++ = htons(0x0d02);
1250          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeSCSIDBRA
1251 <        *wp++ = htons(100);
1251 >        *wp++ = htons(10000);
1252          *wp++ = htons(0x0b24);
1253          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeRAMDBRA
1254 <        *wp++ = htons(100);
1254 >        *wp++ = htons(10000);
1255          *wp++ = htons(0x0cea);
1256          *wp = htons(M68K_RTS);
1257  
1258   #if REAL_ADDRESSING
1259          // Move system zone to start of Mac RAM
1260 <        lp = (uint32 *)(ROMBaseHost + 0x50a);
1261 <        *lp++ = htonl(RAMBaseMac);
1262 <        *lp = htonl(RAMBaseMac + 0x1800);
1260 >        wp = (uint16 *)(ROMBaseHost + 0x50a);
1261 >        *wp++ = htons(HiWord(RAMBaseMac + 0x2000));
1262 >        *wp++ = htons(LoWord(RAMBaseMac + 0x2000));
1263 >        *wp++ = htons(HiWord(RAMBaseMac + 0x3800));
1264 >        *wp = htons(LoWord(RAMBaseMac + 0x3800));
1265   #endif
1266  
1267   #if !ROM_IS_WRITE_PROTECTED
1268 < #if defined(AMIGA)
1268 > #if defined(USE_SCRATCHMEM_SUBTERFUGE)
1269          // Set fake handle at 0x0000 to scratch memory area (so broken Mac programs won't write into Mac ROM)
1270 <        extern uint32 ScratchMem;
1270 >        extern uint8 *ScratchMem;
1271 >        const uint32 ScratchMemBase = Host2MacAddr(ScratchMem);
1272          wp = (uint16 *)(ROMBaseHost + 0xccaa);
1273          *wp++ = htons(0x203c);                  // move.l       #ScratchMem,d0
1274 <        *wp++ = htons(ScratchMem >> 16);
1275 <        *wp = htons(ScratchMem);
1274 >        *wp++ = htons(ScratchMemBase >> 16);
1275 >        *wp = htons(ScratchMemBase);
1276   #else
1277   #error System specific handling for writable ROM is required here
1278   #endif
# Line 1081 | Line 1284 | static bool patch_rom_32(void)
1284          *wp++ = htons(M68K_NOP);
1285          *wp = htons(M68K_NOP);
1286   #endif
1287 <
1287 >        
1288 > #if REAL_ADDRESSING && !defined(AMIGA)
1289 >        // gb-- Temporary hack to get rid of crashes in Speedometer
1290 >        wp = (uint16 *)(ROMBaseHost + 0xdba2);
1291 >        if (ntohs(*wp) == 0x662c)               // bne.b        #$2c
1292 >                *wp = htons(0x602c);            // bra.b        #$2c
1293 > #endif
1294 >        
1295          // Don't write to VIA in InitTimeMgr
1296          wp = (uint16 *)(ROMBaseHost + 0xb0e2);
1297          *wp++ = htons(0x4cdf);                  // movem.l      (sp)+,d0-d5/a0-a4
# Line 1153 | Line 1363 | static bool patch_rom_32(void)
1363          *wp++ = htons(M68K_NOP);
1364          *wp = htons(M68K_NOP);
1365  
1366 <        // Fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!)
1367 <        static const uint8 fix_memsize_dat[] = {0x4e, 0x75};
1368 <        if ((base = find_rom_data(0x490, 0x4b0, fix_memsize_dat, sizeof(fix_memsize_dat))) == 0) return false;
1369 <        D(bug("fix_memsize %08lx\n", base));
1370 <        wp = (uint16 *)(ROMBaseHost + base);
1366 >        // Compute boot stack pointer and fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!)
1367 >        wp = (uint16 *)(ROMBaseHost + 0x490);
1368 >        *wp++ = htons(0x2038);  // move.l       $10c,d0
1369 >        *wp++ = htons(0x010c);
1370 >        *wp++ = htons(0xd0b8);  // add.l        $2a6,d0
1371 >        *wp++ = htons(0x02a6);
1372 >        *wp++ = htons(0xe288);  // lsr.l        #1,d0
1373 >        *wp++ = htons(0x0880);  // bclr         #0,d0
1374 >        *wp++ = htons(0x0000);
1375 >        *wp++ = htons(0x0440);  // subi.w       #$400,d0
1376 >        *wp++ = htons(0x0400);
1377 >        *wp++ = htons(0x2040);  // move.l       d0,a0
1378          *wp++ = htons(M68K_EMUL_OP_FIX_MEMSIZE);
1379 <        *wp = htons(M68K_RTS);
1379 >        *wp++ = htons(M68K_RTS);
1380  
1381          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};
1382          base = find_rom_data(0x4c000, 0x4c080, fix_memsize2_dat, sizeof(fix_memsize2_dat));
# Line 1270 | Line 1487 | static bool patch_rom_32(void)
1487          if (ROMSize > 0x80000) {
1488  
1489                  // BlockMove()
1490 <                static const uint8 ptest_dat[] = {0xa0, 0x8d, 0x0c, 0x81, 0x00, 0x00, 0x0c, 0x00, 0x6d, 0x06, 0x4e, 0x71, 0xf4, 0xf8};
1491 <                base = find_rom_data(0x87000, 0x87800, ptest_dat, sizeof(ptest_dat));
1492 <                D(bug("ptest %08lx\n", base));
1490 >                static const uint8 bmove_dat[] = {0x20, 0x5f, 0x22, 0x5f, 0x0c, 0x38, 0x00, 0x04, 0x01, 0x2f};
1491 >                base = find_rom_data(0x87000, 0x87800, bmove_dat, sizeof(bmove_dat));
1492 >                D(bug("block_move %08lx\n", base));
1493                  if (base) {             // ROM15/22/23/26/27/32
1494 <                        wp = (uint16 *)(ROMBaseHost + base + 8);
1495 <                        *wp = htons(M68K_NOP);
1494 >                        wp = (uint16 *)(ROMBaseHost + base + 4);
1495 >                        *wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE);
1496 >                        *wp++ = htons(0x7000);
1497 >                        *wp = htons(M68K_RTS);
1498                  }
1499  
1500                  // SANE
# Line 1292 | Line 1511 | static bool patch_rom_32(void)
1511                  }
1512          }
1513  
1514 +        // Don't set MemoryDispatch() to unimplemented trap
1515 +        static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47};
1516 +        base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat));
1517 +        D(bug("memdisp %08lx\n", base));
1518 +        if (base) {     // ROM15/22/23/26/27/32
1519 +                wp = (uint16 *)(ROMBaseHost + base + 10);
1520 +                *wp = htons(M68K_NOP);
1521 +        }
1522 +
1523          // Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000)
1524 <        uint32 edisk_offset = find_rom_resource('DRVR', 51);
1524 >        uint32 edisk_offset = find_rom_resource(FOURCC('D','R','V','R'), 51);
1525          if (edisk_offset) {
1526                  static const uint8 edisk_dat[] = {0xd5, 0xfc, 0x00, 0x01, 0x00, 0x00, 0xb5, 0xfc, 0x00, 0xe0, 0x00, 0x00};
1527                  base = find_rom_data(edisk_offset, edisk_offset + 0x10000, edisk_dat, sizeof(edisk_dat));
# Line 1306 | Line 1534 | static bool patch_rom_32(void)
1534          }
1535  
1536          // Replace .Sony driver
1537 <        sony_offset = find_rom_resource('DRVR', 4);
1537 >        sony_offset = find_rom_resource(FOURCC('D','R','V','R'), 4);
1538          D(bug("sony %08lx\n", sony_offset));
1539          memcpy(ROMBaseHost + sony_offset, sony_driver, sizeof(sony_driver));
1540  
# Line 1325 | Line 1553 | static bool patch_rom_32(void)
1553          memcpy(ROMBaseHost + sony_offset + 0xa00, CDROMIcon, sizeof(CDROMIcon));
1554  
1555          // Install SERD patch and serial drivers
1556 <        serd_offset = find_rom_resource('SERD', 0);
1556 >        serd_offset = find_rom_resource(FOURCC('S','E','R','D'), 0);
1557          D(bug("serd %08lx\n", serd_offset));
1558          wp = (uint16 *)(ROMBaseHost + serd_offset + 12);
1559          *wp++ = htons(M68K_EMUL_OP_SERD);
# Line 1358 | Line 1586 | static bool patch_rom_32(void)
1586          *wp++ = htons(M68K_RTS);
1587          microseconds_offset = (uint8 *)wp - ROMBaseHost;
1588          *wp++ = htons(M68K_EMUL_OP_MICROSECONDS);
1589 +        *wp++ = htons(M68K_RTS);
1590 +
1591 +        // Replace DebugUtil
1592 +        debugutil_offset = (uint8 *)wp - ROMBaseHost;
1593 +        *wp++ = htons(M68K_EMUL_OP_DEBUGUTIL);
1594          *wp = htons(M68K_RTS);
1595  
1596          // Replace SCSIDispatch()
# Line 1393 | Line 1626 | static bool patch_rom_32(void)
1626          *wp++ = htons(base >> 16);
1627          *wp = htons(base & 0xffff);
1628  
1629 <        // Install MemoryDispatch() replacement routine (activated in PatchAfterStartup())
1630 <        memory_dispatch_offset = sony_offset + 0xc20;
1631 <        wp = (uint16 *)(ROMBaseHost + memory_dispatch_offset);
1632 <        *wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH);
1633 <        *wp = htons(M68K_RTS);
1629 >        // Install GetScrap() patch for clipboard data exchange (the patch is activated by EMUL_OP_INSTALL_DRIVERS)
1630 >        GetScrapPatch = ROMBaseMac + sony_offset + 0xd00;
1631 >        base = ROMBaseMac + find_rom_trap(0xa9fd);
1632 >        wp = (uint16 *)(ROMBaseHost + sony_offset + 0xd00);
1633 >        *wp++ = htons(M68K_EMUL_OP_GET_SCRAP);
1634 >        *wp++ = htons(M68K_JMP);
1635 >        *wp++ = htons(base >> 16);
1636 >        *wp = htons(base & 0xffff);
1637 >
1638 >        // Look for double PACK 4 resources
1639 >        if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4)) == 0) return false;
1640 >        if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4, true)) == 0 && FPUType == 0)
1641 >                printf("WARNING: This ROM seems to require an FPU\n");
1642  
1643          // Patch VIA interrupt handler
1644          wp = (uint16 *)(ROMBaseHost + 0x9bc4);  // Level 1 handler
# Line 1407 | Line 1648 | static bool patch_rom_32(void)
1648          *wp++ = htons(M68K_NOP);
1649          *wp = htons(M68K_NOP);
1650  
1651 <        wp = (uint16 *)(ROMBaseHost + 0xa29a);  // 60Hz handler (handles everything)
1651 >        wp = (uint16 *)(ROMBaseHost + 0xa296);  // 60Hz handler (handles everything)
1652 >        *wp++ = htons(M68K_NOP);
1653 >        *wp++ = htons(M68K_NOP);
1654          *wp++ = htons(M68K_EMUL_OP_IRQ);
1655          *wp++ = htons(0x4a80);          // tst.l        d0
1656          *wp = htons(0x67f4);            // beq          0x4080a294
# Line 1416 | Line 1659 | static bool patch_rom_32(void)
1659  
1660   bool PatchROM(void)
1661   {
1662 <        // Print ROM info
1663 <        D(bug("ROM Info:\n"));
1664 <        D(bug("Checksum: %08lx\n", ReadMacInt32(ROMBaseMac)));
1422 <        D(bug("Version: %04x\n", ROMVersion));
1423 <        D(bug("Sub Version: %04x\n", ReadMacInt16(ROMBaseMac + 18)));
1662 >        // Print some information about the ROM
1663 >        if (PrintROMInfo)
1664 >                print_rom_info();
1665  
1666          // Patch ROM depending on version
1667          switch (ROMVersion) {
# Line 1436 | Line 1677 | bool PatchROM(void)
1677                          return false;
1678          }
1679  
1439 #ifdef M68K_BREAKPOINT
1680          // Install breakpoint
1681 <        uint16 *wp = (uint16 *)(ROMBaseHost + M68K_BREAKPOINT);
1682 <        *wp = htons(M68K_EMUL_BREAK);
1683 < #endif
1681 >        if (ROMBreakpoint) {
1682 >                uint16 *wp = (uint16 *)(ROMBaseHost + ROMBreakpoint);
1683 >                *wp = htons(M68K_EMUL_BREAK);
1684 >        }
1685  
1686          // Clear caches as we loaded and patched code
1687          FlushCodeCache(ROMBaseHost, ROMSize);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines