--- SheepShaver/src/emul_op.cpp 2004/05/31 11:00:13 1.12 +++ SheepShaver/src/emul_op.cpp 2009/08/18 18:26:10 1.24 @@ -1,7 +1,7 @@ /* * emul_op.cpp - 68k opcodes for ROM patches * - * SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig + * SheepShaver (C) 1997-2008 Christian Bauer and Marc Hellwig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,15 +51,8 @@ #include "debug.h" -#if __BEOS__ -#define PRECISE_TIMING 1 -#else -#define PRECISE_TIMING 0 -#endif - - // TVector of MakeExecutable -static uint32 *MakeExecutableTvec; +static uint32 MakeExecutableTvec; /* @@ -259,20 +252,21 @@ void EmulOp(M68kRegisters *r, uint32 pc, InstallDrivers(); // Patch MakeExecutable() - MakeExecutableTvec = (uint32 *)FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable"); - D(bug("MakeExecutable TVECT at %p\n", MakeExecutableTvec)); - MakeExecutableTvec[0] = htonl(NativeFunction(NATIVE_MAKE_EXECUTABLE)); + MakeExecutableTvec = FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable"); + D(bug("MakeExecutable TVECT at %08x\n", MakeExecutableTvec)); + WriteMacInt32(MakeExecutableTvec, NativeFunction(NATIVE_MAKE_EXECUTABLE)); #if !EMULATED_PPC - MakeExecutableTvec[1] = (uint32)TOC; + WriteMacInt32(MakeExecutableTvec + 4, (uint32)TOC); #endif // Patch DebugStr() - static const uint16 proc[] = { - PW(M68K_EMUL_OP_DEBUG_STR), - PW(0x4e74), // rtd #4 - PW(0x0004) + static const uint8 proc_template[] = { + M68K_EMUL_OP_DEBUG_STR >> 8, M68K_EMUL_OP_DEBUG_STR, + 0x4e, 0x74, // rtd #4 + 0x00, 0x04 }; - WriteMacInt32(0x1dfc, (uint32)proc); + BUILD_SHEEPSHAVER_PROCEDURE(proc); + WriteMacInt32(0x1dfc, proc); break; } @@ -287,17 +281,18 @@ void EmulOp(M68kRegisters *r, uint32 pc, TimerReset(); MacOSUtilReset(); AudioReset(); -#if 0 - // Enable DR emulator - D(bug("DR activated\n")); - WriteMacInt32(KernelDataAddr + 0x17a0, 3); // Prepare for DR emulator activation - WriteMacInt32(KernelDataAddr + 0x17c0, DR_CACHE_BASE); - WriteMacInt32(KernelDataAddr + 0x17c4, DR_CACHE_SIZE); - WriteMacInt32(KernelDataAddr + 0x1b04, DR_CACHE_BASE); - WriteMacInt32(KernelDataAddr + 0x1b00, DR_EMULATOR_BASE); - memcpy((void *)DR_EMULATOR_BASE, (void *)(ROM_BASE + 0x370000), DR_EMULATOR_SIZE); - MakeExecutable(0, (void *)DR_EMULATOR_BASE, DR_EMULATOR_SIZE); -#endif + + // Enable DR emulator (disabled for now) + if (PrefsFindBool("jit68k") && 0) { + D(bug("DR activated\n")); + WriteMacInt32(KernelDataAddr + 0x17a0, 3); // Prepare for DR emulator activation + WriteMacInt32(KernelDataAddr + 0x17c0, DR_CACHE_BASE); + WriteMacInt32(KernelDataAddr + 0x17c4, DR_CACHE_SIZE); + WriteMacInt32(KernelDataAddr + 0x1b04, DR_CACHE_BASE); + WriteMacInt32(KernelDataAddr + 0x1b00, DR_EMULATOR_BASE); + memcpy((void *)DR_EMULATOR_BASE, (void *)(ROMBase + 0x370000), DR_EMULATOR_SIZE); + MakeExecutable(0, DR_EMULATOR_BASE, DR_EMULATOR_SIZE); + } break; case OP_IRQ: // Level 1 interrupt @@ -414,6 +409,16 @@ void EmulOp(M68kRegisters *r, uint32 pc, r->d[0] = (uint32)-7887; break; + case OP_CHECK_SYSV: { // Check we are not using MacOS < 8.1 with a NewWorld ROM + r->a[1] = r->d[1]; + r->a[0] = ReadMacInt32(r->d[1]); + uint32 sysv = ReadMacInt16(r->a[0]); + D(bug("Detected MacOS version %d.%d.%d\n", (sysv >> 8) & 0xf, (sysv >> 4) & 0xf, sysv & 0xf)); + if (ROMType == ROMTYPE_NEWWORLD && sysv < 0x0801) + r->d[1] = 0; + break; + } + case OP_NTRB_17_PATCH: r->a[2] = ReadMacInt32(r->a[7]); r->a[7] += 4; @@ -434,6 +439,14 @@ void EmulOp(M68kRegisters *r, uint32 pc, PatchNativeResourceManager(); break; + case OP_NTRB_17_PATCH4: + r->d[0] = ReadMacInt16(r->a[7]); + r->a[7] += 2; + D(bug("%d %d\n", ReadMacInt16(r->a[2]), ReadMacInt16(r->a[2] + 6))); + if (ReadMacInt16(r->a[2]) == 11 && ReadMacInt16(r->a[2] + 6) == 17) + PatchNativeResourceManager(); + break; + case OP_CHECKLOAD: { // vCheckLoad() patch uint32 type = ReadMacInt32(r->a[7]); r->a[7] += 4; @@ -460,14 +473,14 @@ void EmulOp(M68kRegisters *r, uint32 pc, case OP_IDLE_TIME: // Sleep if no events pending if (ReadMacInt32(0x14c) == 0) - Delay_usec(16667); + idle_wait(); r->a[0] = ReadMacInt32(0x2b6); break; case OP_IDLE_TIME_2: // Sleep if no events pending if (ReadMacInt32(0x14c) == 0) - Delay_usec(16667); + idle_wait(); r->d[0] = (uint32)-2; break;