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 |
|
|
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 |
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; |
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; |
648 |
< |
Execute68kTrap(0xa247, &r); // SetOSTrapAddress() |
649 |
> |
#if SUPPORTS_EXTFS |
650 |
> |
// Install external file system |
651 |
> |
InstallExtFS(); |
652 |
> |
#endif |
653 |
|
} |
654 |
|
|
655 |
|
|
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 |
|
} |
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)); |
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) { |
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) |
1462 |
|
return false; |
1463 |
|
} |
1464 |
|
|
1437 |
– |
#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); |