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.10 by cebix, 1999-10-26T16:28:27Z vs.
Revision 1.16 by jlachmann, 2000-08-20T14:08:40Z

# 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-2000 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 (offset into ROM)
42 uint32 ROMBreakpoint = 0;       // 0 = disabled, 0x2310 = CritError
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
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 >
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 debugutil_offset;         // ROM offset of DebugUtil() replacement routine
51  
52   // Prototypes
53   uint16 ROMVersion;
# Line 83 | Line 82 | static uint32 find_rom_resource(uint32 s
82  
83          if (!cont)
84                  rsrc_ptr = x;
85 +        else
86 +                rsrc_ptr = ReadMacInt32(ROMBaseMac + rsrc_ptr + 8);
87  
88          for (;;) {
89                  lp = ROMBaseMac + rsrc_ptr;
# Line 141 | Line 142 | again:
142  
143  
144   /*
145 + *  Print ROM information to stream,
146 + */
147 +
148 + static void list_rom_resources(void)
149 + {
150 +        printf("ROM Resources:\n");
151 +        printf("Offset\t Type\tID\tSize\tName\n");
152 +        printf("------------------------------------------------\n");
153 +
154 +        uint32 lp = ROMBaseMac + ReadMacInt32(ROMBaseMac + 0x1a);
155 +        uint32 rsrc_ptr = ReadMacInt32(lp);
156 +
157 +        for (;;) {
158 +                lp = ROMBaseMac + rsrc_ptr;
159 +                uint32 data = ReadMacInt32(lp + 12);
160 +
161 +                char name[32];
162 +                int name_len = ReadMacInt8(lp + 23), i;
163 +                for (i=0; i<name_len; i++)
164 +                        name[i] = ReadMacInt8(lp + 24 + i);
165 +                name[i] = 0;
166 +
167 +                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);
168 +
169 +                rsrc_ptr = ReadMacInt32(lp + 8);
170 +                if (!rsrc_ptr)
171 +                        break;
172 +        }
173 +        printf("\n");
174 + }
175 +
176 + // Mapping of Model IDs to Model names
177 + struct mac_desc {
178 +        char *name;
179 +        int32 id;
180 + };
181 +
182 + static mac_desc MacDesc[] = {
183 +        {"Classic"                              , 1},
184 +        {"Mac XL"                               , 2},
185 +        {"Mac 512KE"                    , 3},
186 +        {"Mac Plus"                             , 4},
187 +        {"Mac SE"                               , 5},
188 +        {"Mac II"                               , 6},
189 +        {"Mac IIx"                              , 7},
190 +        {"Mac IIcx"                             , 8},
191 +        {"Mac SE/030"                   , 9},
192 +        {"Mac Portable"                 , 10},
193 +        {"Mac IIci"                             , 11},
194 +        {"Mac IIfx"                             , 13},
195 +        {"Mac Classic"                  , 17},
196 +        {"Mac IIsi"                             , 18},
197 +        {"Mac LC"                               , 19},
198 +        {"Quadra 900"                   , 20},
199 +        {"PowerBook 170"                , 21},
200 +        {"Quadra 700"                   , 22},
201 +        {"Classic II"                   , 23},
202 +        {"PowerBook 100"                , 24},
203 +        {"PowerBook 140"                , 25},
204 +        {"Quadra 950"                   , 26},
205 +        {"Mac LCIII/Performa 450", 27},
206 +        {"PowerBook Duo 210"    , 29},
207 +        {"Centris 650"                  , 30},
208 +        {"PowerBook Duo 230"    , 32},
209 +        {"PowerBook 180"                , 33},
210 +        {"PowerBook 160"                , 34},
211 +        {"Quadra 800"                   , 35},
212 +        {"Quadra 650"                   , 36},
213 +        {"Mac LCII"                             , 37},
214 +        {"PowerBook Duo 250"    , 38},
215 +        {"Mac IIvi"                             , 44},
216 +        {"Mac IIvm/Performa 600", 45},
217 +        {"Mac IIvx"                             , 48},
218 +        {"Color Classic/Performa 250", 49},
219 +        {"PowerBook 165c"               , 50},
220 +        {"Centris 610"                  , 52},
221 +        {"Quadra 610"                   , 53},
222 +        {"PowerBook 145"                , 54},
223 +        {"Mac LC520"                    , 56},
224 +        {"Quadra/Centris 660AV" , 60},
225 +        {"Performa 46x"                 , 62},
226 +        {"PowerBook 180c"               , 71},
227 +        {"PowerBook 520/520c/540/540c", 72},
228 +        {"PowerBook Duo 270c"   , 77},
229 +        {"Quadra 840AV"                 , 78},
230 +        {"Performa 550"                 , 80},
231 +        {"PowerBook 165"                , 84},
232 +        {"PowerBook 190"                , 85},
233 +        {"Mac TV"                               , 88},
234 +        {"Mac LC475/Performa 47x", 89},
235 +        {"Mac LC575"                    , 92},
236 +        {"Quadra 605"                   , 94},
237 +        {"Quadra 630"                   , 98},
238 +        {"Mac LC580"                    , 99},
239 +        {"PowerBook Duo 280"    , 102},
240 +        {"PowerBook Duo 280c"   , 103},
241 +        {"PowerBook 150"                , 115},
242 +        {"unknown", -1}
243 + };
244 +
245 + static void print_universal_info(uint32 info)
246 + {
247 +        uint8 id = ReadMacInt8(info + 18);
248 +        uint16 hwcfg = ReadMacInt16(info + 16);
249 +        uint16 rom85 = ReadMacInt16(info + 20);
250 +
251 +        // Find model name
252 +        char *name = "unknown";
253 +        for (int i=0; MacDesc[i].id >= 0; i++)
254 +                if (MacDesc[i].id == id + 6) {
255 +                        name = MacDesc[i].name;
256 +                        break;
257 +                }
258 +
259 +        printf("%08x %02x\t%04x\t%04x\t%s\n", info - ROMBaseMac, id, hwcfg, rom85, name);
260 + }
261 +
262 + static void list_universal_infos(void)
263 + {
264 +        uint32 ofs = 0x3000;
265 +        for (int i=0; i<0x2000; i+=2, ofs+=2)
266 +                if (ReadMacInt32(ROMBaseMac + ofs) == 0xdc000505) {
267 +                        ofs -= 16;
268 +                        uint32 q;
269 +                        for (q=ofs; q > 0 && ReadMacInt32(ROMBaseMac + q) != ofs - q; q-=4) ;
270 +                        if (q > 0) {
271 +                                printf("Universal Table at %08x:\n", q);
272 +                                printf("Offset\t ID\tHWCfg\tROM85\tModel\n");
273 +                                printf("------------------------------------------------\n");
274 +                                while ((ofs = ReadMacInt32(ROMBaseMac + q))) {
275 +                                        print_universal_info(ROMBaseMac + ofs + q);
276 +                                        q += 4;
277 +                                }
278 +                        }
279 +                        break;
280 +                }
281 +        printf("\n");
282 + }
283 +
284 + static void print_rom_info(void)
285 + {
286 +        printf("\nROM Info:\n");
287 +        printf("Checksum    : %08x\n", ReadMacInt32(ROMBaseMac));
288 +        printf("Version     : %04x\n", ROMVersion);
289 +        printf("Sub Version : %04x\n", ReadMacInt16(ROMBaseMac + 18));
290 +        printf("Resource Map: %08x\n", ReadMacInt32(ROMBaseMac + 26));
291 +        printf("Trap Tables : %08x\n\n", ReadMacInt32(ROMBaseMac + 34));
292 +        if (ROMVersion == ROM_VERSION_32) {
293 +                list_rom_resources();
294 +                list_universal_infos();
295 +        }
296 + }
297 +
298 +
299 + /*
300   *  Driver stubs
301   */
302  
# Line 538 | Line 694 | static const uint8 adbop_patch[] = {   //
694  
695   void InstallDrivers(uint32 pb)
696   {
697 <        D(bug("InstallDrivers\n"));
697 >        D(bug("InstallDrivers, pb %08x\n", pb));
698          M68kRegisters r;
699  
700          // Install Microseconds() replacement routine
# Line 546 | Line 702 | void InstallDrivers(uint32 pb)
702          r.d[0] = 0xa093;
703          Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
704  
705 <        // Install MemoryDispatch() replacement routine
706 <        r.a[0] = ROMBaseMac + memory_dispatch_offset;
707 <        r.d[0] = 0xa05c;
705 >        // Install DebugUtil() replacement routine
706 >        r.a[0] = ROMBaseMac + debugutil_offset;
707 >        r.d[0] = 0xa08d;
708          Execute68kTrap(0xa247, &r);             // SetOSTrapAddress()
709  
710          // Install disk driver
# Line 780 | Line 936 | static bool patch_rom_classic(void)
936          *wp++ = htons(M68K_RTS);
937          microseconds_offset = (uint8 *)wp - ROMBaseHost;
938          *wp++ = htons(M68K_EMUL_OP_MICROSECONDS);
939 +        *wp++ = htons(M68K_RTS);
940 +
941 +        // Replace DebugUtil
942 +        debugutil_offset = (uint8 *)wp - ROMBaseHost;
943 +        *wp++ = htons(M68K_EMUL_OP_DEBUGUTIL);
944          *wp = htons(M68K_RTS);
945  
946          // Replace SCSIDispatch()
# Line 1042 | Line 1203 | static bool patch_rom_32(void)
1203          *wp = htons(M68K_RTS);
1204  
1205          // Fake CPU speed test (SetupTimeK)
1206 +        // *** increased jl : MacsBug uses TimeDBRA for kbd repeat timing
1207          wp = (uint16 *)(ROMBaseHost + 0x800);
1208          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeDBRA
1209 <        *wp++ = htons(100);
1209 >        *wp++ = htons(10000);
1210          *wp++ = htons(0x0d00);
1211          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeSCCDBRA
1212 <        *wp++ = htons(100);
1212 >        *wp++ = htons(10000);
1213          *wp++ = htons(0x0d02);
1214          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeSCSIDBRA
1215 <        *wp++ = htons(100);
1215 >        *wp++ = htons(10000);
1216          *wp++ = htons(0x0b24);
1217          *wp++ = htons(0x31fc);                  // move.w       #xxx,TimeRAMDBRA
1218 <        *wp++ = htons(100);
1218 >        *wp++ = htons(10000);
1219          *wp++ = htons(0x0cea);
1220          *wp = htons(M68K_RTS);
1221  
# Line 1305 | Line 1467 | static bool patch_rom_32(void)
1467          static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47};
1468          base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat));
1469          D(bug("memdisp %08lx\n", base));
1470 <        if (base) {     // ROM15/32
1470 >        if (base) {     // ROM15/22/23/26/27/32
1471                  wp = (uint16 *)(ROMBaseHost + base + 10);
1472                  *wp = htons(M68K_NOP);
1473          }
1474  
1475          // Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000)
1476 <        uint32 edisk_offset = find_rom_resource('DRVR', 51);
1476 >        uint32 edisk_offset = find_rom_resource(FOURCC('D','R','V','R'), 51);
1477          if (edisk_offset) {
1478                  static const uint8 edisk_dat[] = {0xd5, 0xfc, 0x00, 0x01, 0x00, 0x00, 0xb5, 0xfc, 0x00, 0xe0, 0x00, 0x00};
1479                  base = find_rom_data(edisk_offset, edisk_offset + 0x10000, edisk_dat, sizeof(edisk_dat));
# Line 1324 | Line 1486 | static bool patch_rom_32(void)
1486          }
1487  
1488          // Replace .Sony driver
1489 <        sony_offset = find_rom_resource('DRVR', 4);
1489 >        sony_offset = find_rom_resource(FOURCC('D','R','V','R'), 4);
1490          D(bug("sony %08lx\n", sony_offset));
1491          memcpy(ROMBaseHost + sony_offset, sony_driver, sizeof(sony_driver));
1492  
# Line 1343 | Line 1505 | static bool patch_rom_32(void)
1505          memcpy(ROMBaseHost + sony_offset + 0xa00, CDROMIcon, sizeof(CDROMIcon));
1506  
1507          // Install SERD patch and serial drivers
1508 <        serd_offset = find_rom_resource('SERD', 0);
1508 >        serd_offset = find_rom_resource(FOURCC('S','E','R','D'), 0);
1509          D(bug("serd %08lx\n", serd_offset));
1510          wp = (uint16 *)(ROMBaseHost + serd_offset + 12);
1511          *wp++ = htons(M68K_EMUL_OP_SERD);
# Line 1376 | Line 1538 | static bool patch_rom_32(void)
1538          *wp++ = htons(M68K_RTS);
1539          microseconds_offset = (uint8 *)wp - ROMBaseHost;
1540          *wp++ = htons(M68K_EMUL_OP_MICROSECONDS);
1541 +        *wp++ = htons(M68K_RTS);
1542 +
1543 +        // Replace DebugUtil
1544 +        debugutil_offset = (uint8 *)wp - ROMBaseHost;
1545 +        *wp++ = htons(M68K_EMUL_OP_DEBUGUTIL);
1546          *wp = htons(M68K_RTS);
1547  
1548          // Replace SCSIDispatch()
# Line 1411 | Line 1578 | static bool patch_rom_32(void)
1578          *wp++ = htons(base >> 16);
1579          *wp = htons(base & 0xffff);
1580  
1414        // Install MemoryDispatch() replacement routine (activated in PatchAfterStartup())
1415        memory_dispatch_offset = sony_offset + 0xc20;
1416        wp = (uint16 *)(ROMBaseHost + memory_dispatch_offset);
1417        *wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH);
1418        *wp = htons(M68K_RTS);
1419
1581   #if EMULATED_68K
1582          // Replace BlockMove()
1583          wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e));   // BlockMove()
# Line 1425 | Line 1586 | static bool patch_rom_32(void)
1586          *wp = htons(M68K_RTS);
1587   #endif
1588  
1589 +        // Look for double PACK 4 resources
1590 +        if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4)) == 0) return false;
1591 +        if ((base = find_rom_resource(FOURCC('P','A','C','K'), 4, true)) == 0 && FPUType == 0)
1592 +                printf("WARNING: This ROM seems to require an FPU\n");
1593 +
1594          // Patch VIA interrupt handler
1595          wp = (uint16 *)(ROMBaseHost + 0x9bc4);  // Level 1 handler
1596          *wp++ = htons(0x7002);          // moveq        #2,d0 (always 60Hz interrupt)
# Line 1442 | Line 1608 | static bool patch_rom_32(void)
1608  
1609   bool PatchROM(void)
1610   {
1611 <        // Print ROM info
1612 <        D(bug("ROM Info:\n"));
1613 <        D(bug("Checksum: %08lx\n", ReadMacInt32(ROMBaseMac)));
1448 <        D(bug("Version: %04x\n", ROMVersion));
1449 <        D(bug("Sub Version: %04x\n", ReadMacInt16(ROMBaseMac + 18)));
1611 >        // Print some information about the ROM
1612 >        if (PrintROMInfo)
1613 >                print_rom_info();
1614  
1615          // Patch ROM depending on version
1616          switch (ROMVersion) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines