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 by cebix, 1999-10-03T14:16:25Z vs.
Revision 1.10 by cebix, 1999-10-26T16:28:27Z

# 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  
41 < // Breakpoint
42 < //#define M68K_BREAKPOINT 0x2310        // CritError
42 < //#define M68K_BREAKPOINT 0x1d10        // BootMe
41 > // Breakpoint (offset into ROM)
42 > uint32 ROMBreakpoint = 0;       // 0 = disabled, 0x2310 = CritError
43  
44   // Global variables
45   uint32 UniversalInfo;   // ROM offset of UniversalInfo
46   uint32 PutScrapPatch;   // Mac address of PutScrap() patch
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
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 memory_dispatch_offset;   // ROM offset of MemoryDispatch() replacement routine
52  
53   // Prototypes
# Line 146 | Line 146 | again:
146  
147   static const uint8 sony_driver[] = {    // Replacement for .Sony driver
148          // Driver header
149 <        SonyDriverFlags >> 8, SonyDriverFlags & 0xff, SonyDriverDelay >> 8, SonyDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
149 >        SonyDriverFlags >> 8, SonyDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
150          0x00, 0x18,                                                     // Open() offset
151          0x00, 0x1c,                                                     // Prime() offset
152          0x00, 0x20,                                                     // Control() offset
# Line 194 | Line 194 | static const uint8 sony_driver[] = {   //
194  
195   static const uint8 disk_driver[] = {    // Generic disk driver
196          // Driver header
197 <        DiskDriverFlags >> 8, DiskDriverFlags & 0xff, DiskDriverDelay >> 8, DiskDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
197 >        DiskDriverFlags >> 8, DiskDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
198          0x00, 0x18,                                                     // Open() offset
199          0x00, 0x1c,                                                     // Prime() offset
200          0x00, 0x20,                                                     // Control() offset
# Line 242 | Line 242 | static const uint8 disk_driver[] = {   //
242  
243   static const uint8 cdrom_driver[] = {   // CD-ROM driver
244          // Driver header
245 <        CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, CDROMDriverDelay >> 8, CDROMDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
245 >        CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
246          0x00, 0x1c,                                                     // Open() offset
247          0x00, 0x20,                                                     // Prime() offset
248          0x00, 0x24,                                                     // Control() offset
# Line 546 | Line 546 | void InstallDrivers(uint32 pb)
546          r.d[0] = 0xa093;
547          Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
548  
549 +        // Install MemoryDispatch() replacement routine
550 +        r.a[0] = ROMBaseMac + memory_dispatch_offset;
551 +        r.d[0] = 0xa05c;
552 +        Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
553 +
554          // Install disk driver
555          r.a[0] = ROMBaseMac + sony_offset + 0x100;
556          r.d[0] = (uint32)DiskRefNum;
# Line 555 | Line 560 | void InstallDrivers(uint32 pb)
560          uint32 dce = ReadMacInt32(r.a[0]);
561          WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x100);
562          WriteMacInt16(dce + dCtlFlags, DiskDriverFlags);
558        WriteMacInt16(dce + dCtlDelay, DiskDriverDelay);
563  
564          // Open disk driver
565          WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x112);
# Line 574 | Line 578 | void InstallDrivers(uint32 pb)
578                  dce = ReadMacInt32(r.a[0]);
579                  WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x200);
580                  WriteMacInt16(dce + dCtlFlags, CDROMDriverFlags);
577                WriteMacInt16(dce + dCtlDelay, CDROMDriverDelay);
581  
582                  // Open CD-ROM driver
583                  WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x212);
# Line 643 | Line 646 | void InstallSERD(void)
646  
647   void PatchAfterStartup(void)
648   {
649 <        // Install MemoryDispatch() replacement routine
650 <        M68kRegisters r;
651 <        r.a[0] = ROMBaseMac + memory_dispatch_offset;
652 <        r.d[0] = 0xa05c;
650 <        Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
649 > #if SUPPORTS_EXTFS
650 >        // Install external file system
651 >        InstallExtFS();
652 > #endif
653   }
654  
655  
# Line 664 | Line 666 | bool CheckROM(void)
666          // Real addressing mode requires a 32-bit clean ROM
667          return ROMVersion == ROM_VERSION_32;
668   #else
669 <        // Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs (experimental)
669 >        // Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs
670          return (ROMVersion == ROM_VERSION_CLASSIC) || (ROMVersion == ROM_VERSION_32);
671   #endif
672   }
# Line 1153 | Line 1155 | static bool patch_rom_32(void)
1155          *wp++ = htons(M68K_NOP);
1156          *wp = htons(M68K_NOP);
1157  
1158 <        // Fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!)
1159 <        static const uint8 fix_memsize_dat[] = {0x4e, 0x75};
1160 <        if ((base = find_rom_data(0x490, 0x4b0, fix_memsize_dat, sizeof(fix_memsize_dat))) == 0) return false;
1161 <        D(bug("fix_memsize %08lx\n", base));
1162 <        wp = (uint16 *)(ROMBaseHost + base);
1158 >        // Compute boot stack pointer and fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!)
1159 >        wp = (uint16 *)(ROMBaseHost + 0x490);
1160 >        *wp++ = htons(0x2038);  // move.l       $10c,d0
1161 >        *wp++ = htons(0x010c);
1162 >        *wp++ = htons(0xd0b8);  // add.l        $2a6,d0
1163 >        *wp++ = htons(0x02a6);
1164 >        *wp++ = htons(0xe288);  // lsr.l        #1,d0
1165 >        *wp++ = htons(0x0880);  // bclr         #0,d0
1166 >        *wp++ = htons(0x0000);
1167 >        *wp++ = htons(0x0440);  // subi.w       #$400,d0
1168 >        *wp++ = htons(0x0400);
1169 >        *wp++ = htons(0x2040);  // move.l       d0,a0
1170          *wp++ = htons(M68K_EMUL_OP_FIX_MEMSIZE);
1171 <        *wp = htons(M68K_RTS);
1171 >        *wp++ = htons(M68K_RTS);
1172  
1173          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};
1174          base = find_rom_data(0x4c000, 0x4c080, fix_memsize2_dat, sizeof(fix_memsize2_dat));
# Line 1292 | Line 1301 | static bool patch_rom_32(void)
1301                  }
1302          }
1303  
1304 +        // Don't set MemoryDispatch() to unimplemented trap
1305 +        static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47};
1306 +        base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat));
1307 +        D(bug("memdisp %08lx\n", base));
1308 +        if (base) {     // ROM15/32
1309 +                wp = (uint16 *)(ROMBaseHost + base + 10);
1310 +                *wp = htons(M68K_NOP);
1311 +        }
1312 +
1313          // Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000)
1314          uint32 edisk_offset = find_rom_resource('DRVR', 51);
1315          if (edisk_offset) {
# Line 1399 | Line 1417 | static bool patch_rom_32(void)
1417          *wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH);
1418          *wp = htons(M68K_RTS);
1419  
1420 + #if EMULATED_68K
1421 +        // Replace BlockMove()
1422 +        wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e));   // BlockMove()
1423 +        *wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE);
1424 +        *wp++ = htons(0x7000);
1425 +        *wp = htons(M68K_RTS);
1426 + #endif
1427 +
1428          // Patch VIA interrupt handler
1429          wp = (uint16 *)(ROMBaseHost + 0x9bc4);  // Level 1 handler
1430          *wp++ = htons(0x7002);          // moveq        #2,d0 (always 60Hz interrupt)
# Line 1436 | Line 1462 | bool PatchROM(void)
1462                          return false;
1463          }
1464  
1439 #ifdef M68K_BREAKPOINT
1465          // Install breakpoint
1466 <        uint16 *wp = (uint16 *)(ROMBaseHost + M68K_BREAKPOINT);
1467 <        *wp = htons(M68K_EMUL_BREAK);
1468 < #endif
1466 >        if (ROMBreakpoint) {
1467 >                uint16 *wp = (uint16 *)(ROMBaseHost + ROMBreakpoint);
1468 >                *wp = htons(M68K_EMUL_BREAK);
1469 >        }
1470  
1471          // Clear caches as we loaded and patched code
1472          FlushCodeCache(ROMBaseHost, ROMSize);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines