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.11 by cebix, 1999-10-27T16:59:38Z

# 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
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
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 >
47 > static uint32 sony_offset;                              // ROM offset of .Sony driver
48 > static uint32 serd_offset;                              // ROM offset of SERD resource (serial drivers)
49 > static uint32 microseconds_offset;              // ROM offset of Microseconds() replacement routine
50   static uint32 memory_dispatch_offset;   // ROM offset of MemoryDispatch() replacement routine
51  
52   // Prototypes
# Line 141 | Line 140 | again:
140  
141  
142   /*
143 + *  Print ROM information to stream,
144 + */
145 +
146 + static void list_rom_resources(void)
147 + {
148 +        printf("ROM Resources:\n");
149 +        printf("Offset\t Type\tID\tSize\tName\n");
150 +        printf("------------------------------------------------\n");
151 +
152 +        uint32 lp = ROMBaseMac + ReadMacInt32(ROMBaseMac + 0x1a);
153 +        uint32 rsrc_ptr = ReadMacInt32(lp);
154 +
155 +        for (;;) {
156 +                lp = ROMBaseMac + rsrc_ptr;
157 +                uint32 data = ReadMacInt32(lp + 12);
158 +
159 +                char name[32];
160 +                int name_len = ReadMacInt8(lp + 23), i;
161 +                for (i=0; i<name_len; i++)
162 +                        name[i] = ReadMacInt8(lp + 24 + i);
163 +                name[i] = 0;
164 +
165 +                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);
166 +
167 +                rsrc_ptr = ReadMacInt32(lp + 8);
168 +                if (!rsrc_ptr)
169 +                        break;
170 +        }
171 +        printf("\n");
172 + }
173 +
174 + // Mapping of Model IDs to Model names
175 + struct mac_desc {
176 +        char *name;
177 +        int32 id;
178 + };
179 +
180 + static mac_desc MacDesc[] = {
181 +        {"Classic"                              , 1},
182 +        {"Mac XL"                               , 2},
183 +        {"Mac 512KE"                    , 3},
184 +        {"Mac Plus"                             , 4},
185 +        {"Mac SE"                               , 5},
186 +        {"Mac II"                               , 6},
187 +        {"Mac IIx"                              , 7},
188 +        {"Mac IIcx"                             , 8},
189 +        {"Mac SE/030"                   , 9},
190 +        {"Mac Portable"                 , 10},
191 +        {"Mac IIci"                             , 11},
192 +        {"Mac IIfx"                             , 13},
193 +        {"Mac Classic"                  , 17},
194 +        {"Mac IIsi"                             , 18},
195 +        {"Mac LC"                               , 19},
196 +        {"Quadra 900"                   , 20},
197 +        {"PowerBook 170"                , 21},
198 +        {"Quadra 700"                   , 22},
199 +        {"Classic II"                   , 23},
200 +        {"PowerBook 100"                , 24},
201 +        {"PowerBook 140"                , 25},
202 +        {"Quadra 950"                   , 26},
203 +        {"Mac LCIII/Performa 450", 27},
204 +        {"PowerBook Duo 210"    , 29},
205 +        {"Centris 650"                  , 30},
206 +        {"PowerBook Duo 230"    , 32},
207 +        {"PowerBook 180"                , 33},
208 +        {"PowerBook 160"                , 34},
209 +        {"Quadra 800"                   , 35},
210 +        {"Quadra 650"                   , 36},
211 +        {"Mac LCII"                             , 37},
212 +        {"PowerBook Duo 250"    , 38},
213 +        {"Mac IIvi"                             , 44},
214 +        {"Mac IIvm/Performa 600", 45},
215 +        {"Mac IIvx"                             , 48},
216 +        {"Color Classic/Performa 250", 49},
217 +        {"PowerBook 165c"               , 50},
218 +        {"Centris 610"                  , 52},
219 +        {"Quadra 610"                   , 53},
220 +        {"PowerBook 145"                , 54},
221 +        {"Mac LC520"                    , 56},
222 +        {"Quadra/Centris 660AV" , 60},
223 +        {"Performa 46x"                 , 62},
224 +        {"PowerBook 180c"               , 71},
225 +        {"PowerBook 520/520c/540/540c", 72},
226 +        {"PowerBook Duo 270c"   , 77},
227 +        {"Quadra 840AV"                 , 78},
228 +        {"Performa 550"                 , 80},
229 +        {"PowerBook 165"                , 84},
230 +        {"PowerBook 190"                , 85},
231 +        {"Mac TV"                               , 88},
232 +        {"Mac LC475/Performa 47x", 89},
233 +        {"Mac LC575"                    , 92},
234 +        {"Quadra 605"                   , 94},
235 +        {"Quadra 630"                   , 98},
236 +        {"Mac LC580"                    , 99},
237 +        {"PowerBook Duo 280"    , 102},
238 +        {"PowerBook Duo 280c"   , 103},
239 +        {"PowerBook 150"                , 115},
240 +        {"unknown", -1}
241 + };
242 +
243 + static void print_universal_info(uint32 info)
244 + {
245 +        uint8 id = ReadMacInt8(info + 18);
246 +        uint16 hwcfg = ReadMacInt16(info + 16);
247 +        uint16 rom85 = ReadMacInt16(info + 20);
248 +
249 +        // Find model name
250 +        char *name = "unknown";
251 +        for (int i=0; MacDesc[i].id >= 0; i++)
252 +                if (MacDesc[i].id == id + 6) {
253 +                        name = MacDesc[i].name;
254 +                        break;
255 +                }
256 +
257 +        printf("%08x %02x\t%04x\t%04x\t%s\n", info - ROMBaseMac, id, hwcfg, rom85, name);
258 + }
259 +
260 + static void list_universal_infos(void)
261 + {
262 +        uint32 ofs = 0x3000;
263 +        for (int i=0; i<0x2000; i+=2, ofs+=2)
264 +                if (ReadMacInt32(ROMBaseMac + ofs) == 0xdc000505) {
265 +                        ofs -= 16;
266 +                        uint32 q;
267 +                        for (q=ofs; q > 0 && ReadMacInt32(ROMBaseMac + q) != ofs - q; q-=4) ;
268 +                        if (q > 0) {
269 +                                printf("Universal Table at %08x:\n", q);
270 +                                printf("Offset\t ID\tHWCfg\tROM85\tModel\n");
271 +                                printf("------------------------------------------------\n");
272 +                                while (ofs = ReadMacInt32(ROMBaseMac + q)) {
273 +                                        print_universal_info(ROMBaseMac + ofs + q);
274 +                                        q += 4;
275 +                                }
276 +                        }
277 +                        break;
278 +                }
279 +        printf("\n");
280 + }
281 +
282 + static void print_rom_info(void)
283 + {
284 +        printf("\nROM Info:\n");
285 +        printf("Checksum    : %08x\n", ReadMacInt32(ROMBaseMac));
286 +        printf("Version     : %04x\n", ROMVersion);
287 +        printf("Sub Version : %04x\n", ReadMacInt16(ROMBaseMac + 18));
288 +        printf("Resource Map: %08x\n", ReadMacInt32(ROMBaseMac + 26));
289 +        printf("Trap Tables : %08x\n\n", ReadMacInt32(ROMBaseMac + 34));
290 +        if (ROMVersion == ROM_VERSION_32) {
291 +                list_rom_resources();
292 +                list_universal_infos();
293 +        }
294 + }
295 +
296 +
297 + /*
298   *  Driver stubs
299   */
300  
301   static const uint8 sony_driver[] = {    // Replacement for .Sony driver
302          // Driver header
303 <        SonyDriverFlags >> 8, SonyDriverFlags & 0xff, SonyDriverDelay >> 8, SonyDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
303 >        SonyDriverFlags >> 8, SonyDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
304          0x00, 0x18,                                                     // Open() offset
305          0x00, 0x1c,                                                     // Prime() offset
306          0x00, 0x20,                                                     // Control() offset
# Line 194 | Line 348 | static const uint8 sony_driver[] = {   //
348  
349   static const uint8 disk_driver[] = {    // Generic disk driver
350          // Driver header
351 <        DiskDriverFlags >> 8, DiskDriverFlags & 0xff, DiskDriverDelay >> 8, DiskDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
351 >        DiskDriverFlags >> 8, DiskDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
352          0x00, 0x18,                                                     // Open() offset
353          0x00, 0x1c,                                                     // Prime() offset
354          0x00, 0x20,                                                     // Control() offset
# Line 242 | Line 396 | static const uint8 disk_driver[] = {   //
396  
397   static const uint8 cdrom_driver[] = {   // CD-ROM driver
398          // Driver header
399 <        CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, CDROMDriverDelay >> 8, CDROMDriverDelay & 0xff, 0x00, 0x00, 0x00, 0x00,
399 >        CDROMDriverFlags >> 8, CDROMDriverFlags & 0xff, 0, 0, 0, 0, 0, 0,
400          0x00, 0x1c,                                                     // Open() offset
401          0x00, 0x20,                                                     // Prime() offset
402          0x00, 0x24,                                                     // Control() offset
# Line 546 | Line 700 | void InstallDrivers(uint32 pb)
700          r.d[0] = 0xa093;
701          Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
702  
703 +        // Install MemoryDispatch() replacement routine
704 +        r.a[0] = ROMBaseMac + memory_dispatch_offset;
705 +        r.d[0] = 0xa05c;
706 +        Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
707 +
708          // Install disk driver
709          r.a[0] = ROMBaseMac + sony_offset + 0x100;
710          r.d[0] = (uint32)DiskRefNum;
# Line 555 | Line 714 | void InstallDrivers(uint32 pb)
714          uint32 dce = ReadMacInt32(r.a[0]);
715          WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x100);
716          WriteMacInt16(dce + dCtlFlags, DiskDriverFlags);
558        WriteMacInt16(dce + dCtlDelay, DiskDriverDelay);
717  
718          // Open disk driver
719          WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x112);
# Line 574 | Line 732 | void InstallDrivers(uint32 pb)
732                  dce = ReadMacInt32(r.a[0]);
733                  WriteMacInt32(dce + dCtlDriver, ROMBaseMac + sony_offset + 0x200);
734                  WriteMacInt16(dce + dCtlFlags, CDROMDriverFlags);
577                WriteMacInt16(dce + dCtlDelay, CDROMDriverDelay);
735  
736                  // Open CD-ROM driver
737                  WriteMacInt32(pb + ioNamePtr, ROMBaseMac + sony_offset + 0x212);
# Line 643 | Line 800 | void InstallSERD(void)
800  
801   void PatchAfterStartup(void)
802   {
803 <        // Install MemoryDispatch() replacement routine
804 <        M68kRegisters r;
805 <        r.a[0] = ROMBaseMac + memory_dispatch_offset;
806 <        r.d[0] = 0xa05c;
650 <        Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
803 > #if SUPPORTS_EXTFS
804 >        // Install external file system
805 >        InstallExtFS();
806 > #endif
807   }
808  
809  
# Line 664 | Line 820 | bool CheckROM(void)
820          // Real addressing mode requires a 32-bit clean ROM
821          return ROMVersion == ROM_VERSION_32;
822   #else
823 <        // Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs (experimental)
823 >        // Virtual addressing mode works with 32-bit clean Mac II ROMs and Classic ROMs
824          return (ROMVersion == ROM_VERSION_CLASSIC) || (ROMVersion == ROM_VERSION_32);
825   #endif
826   }
# Line 1153 | Line 1309 | static bool patch_rom_32(void)
1309          *wp++ = htons(M68K_NOP);
1310          *wp = htons(M68K_NOP);
1311  
1312 <        // Fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!)
1313 <        static const uint8 fix_memsize_dat[] = {0x4e, 0x75};
1314 <        if ((base = find_rom_data(0x490, 0x4b0, fix_memsize_dat, sizeof(fix_memsize_dat))) == 0) return false;
1315 <        D(bug("fix_memsize %08lx\n", base));
1316 <        wp = (uint16 *)(ROMBaseHost + base);
1312 >        // Compute boot stack pointer and fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!)
1313 >        wp = (uint16 *)(ROMBaseHost + 0x490);
1314 >        *wp++ = htons(0x2038);  // move.l       $10c,d0
1315 >        *wp++ = htons(0x010c);
1316 >        *wp++ = htons(0xd0b8);  // add.l        $2a6,d0
1317 >        *wp++ = htons(0x02a6);
1318 >        *wp++ = htons(0xe288);  // lsr.l        #1,d0
1319 >        *wp++ = htons(0x0880);  // bclr         #0,d0
1320 >        *wp++ = htons(0x0000);
1321 >        *wp++ = htons(0x0440);  // subi.w       #$400,d0
1322 >        *wp++ = htons(0x0400);
1323 >        *wp++ = htons(0x2040);  // move.l       d0,a0
1324          *wp++ = htons(M68K_EMUL_OP_FIX_MEMSIZE);
1325 <        *wp = htons(M68K_RTS);
1325 >        *wp++ = htons(M68K_RTS);
1326  
1327          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};
1328          base = find_rom_data(0x4c000, 0x4c080, fix_memsize2_dat, sizeof(fix_memsize2_dat));
# Line 1292 | Line 1455 | static bool patch_rom_32(void)
1455                  }
1456          }
1457  
1458 +        // Don't set MemoryDispatch() to unimplemented trap
1459 +        static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47};
1460 +        base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat));
1461 +        D(bug("memdisp %08lx\n", base));
1462 +        if (base) {     // ROM15/32
1463 +                wp = (uint16 *)(ROMBaseHost + base + 10);
1464 +                *wp = htons(M68K_NOP);
1465 +        }
1466 +
1467          // Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000)
1468          uint32 edisk_offset = find_rom_resource('DRVR', 51);
1469          if (edisk_offset) {
# Line 1399 | Line 1571 | static bool patch_rom_32(void)
1571          *wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH);
1572          *wp = htons(M68K_RTS);
1573  
1574 + #if EMULATED_68K
1575 +        // Replace BlockMove()
1576 +        wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e));   // BlockMove()
1577 +        *wp++ = htons(M68K_EMUL_OP_BLOCK_MOVE);
1578 +        *wp++ = htons(0x7000);
1579 +        *wp = htons(M68K_RTS);
1580 + #endif
1581 +
1582          // Patch VIA interrupt handler
1583          wp = (uint16 *)(ROMBaseHost + 0x9bc4);  // Level 1 handler
1584          *wp++ = htons(0x7002);          // moveq        #2,d0 (always 60Hz interrupt)
# Line 1416 | Line 1596 | static bool patch_rom_32(void)
1596  
1597   bool PatchROM(void)
1598   {
1599 <        // Print ROM info
1600 <        D(bug("ROM Info:\n"));
1601 <        D(bug("Checksum: %08lx\n", ReadMacInt32(ROMBaseMac)));
1422 <        D(bug("Version: %04x\n", ROMVersion));
1423 <        D(bug("Sub Version: %04x\n", ReadMacInt16(ROMBaseMac + 18)));
1599 >        // Print some information about the ROM
1600 >        if (PrintROMInfo)
1601 >                print_rom_info();
1602  
1603          // Patch ROM depending on version
1604          switch (ROMVersion) {
# Line 1436 | Line 1614 | bool PatchROM(void)
1614                          return false;
1615          }
1616  
1439 #ifdef M68K_BREAKPOINT
1617          // Install breakpoint
1618 <        uint16 *wp = (uint16 *)(ROMBaseHost + M68K_BREAKPOINT);
1619 <        *wp = htons(M68K_EMUL_BREAK);
1620 < #endif
1618 >        if (ROMBreakpoint) {
1619 >                uint16 *wp = (uint16 *)(ROMBaseHost + ROMBreakpoint);
1620 >                *wp = htons(M68K_EMUL_BREAK);
1621 >        }
1622  
1623          // Clear caches as we loaded and patched code
1624          FlushCodeCache(ROMBaseHost, ROMSize);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines