--- SheepShaver/src/emul_op.cpp 2003/09/07 14:33:51 1.2 +++ SheepShaver/src/emul_op.cpp 2005/03/05 19:07:35 1.19 @@ -1,7 +1,7 @@ /* * emul_op.cpp - 68k opcodes for ROM patches * - * SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig + * SheepShaver (C) 1997-2005 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 @@ -45,20 +45,14 @@ #include "name_registry.h" #include "user_strings.h" #include "emul_op.h" +#include "thunks.h" #define DEBUG 0 #include "debug.h" -#if __BEOS__ -#define PRECISE_TIMING 1 -#else -#define PRECISE_TIMING 0 -#endif - - // TVector of MakeExecutable -static uint32 *MakeExecutableTvec; +static uint32 MakeExecutableTvec; /* @@ -257,25 +251,22 @@ void EmulOp(M68kRegisters *r, uint32 pc, // Install drivers InstallDrivers(); -#if !EMULATED_PPC // Patch MakeExecutable() - MakeExecutableTvec = (uint32 *)FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable"); - D(bug("MakeExecutable TVECT at %p\n", MakeExecutableTvec)); -#ifdef __BEOS__ - MakeExecutableTvec[0] = ((uint32 *)MakeExecutable)[0]; -#else - MakeExecutableTvec[0] = (uint32)MakeExecutable; -#endif - MakeExecutableTvec[1] = (uint32)TOC; + MakeExecutableTvec = FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable"); + D(bug("MakeExecutable TVECT at %08x\n", MakeExecutableTvec)); + WriteMacInt32(MakeExecutableTvec, NativeFunction(NATIVE_MAKE_EXECUTABLE)); +#if !EMULATED_PPC + WriteMacInt32(MakeExecutableTvec + 4, (uint32)TOC); #endif // Patch DebugStr() - static const uint8 proc[] = { - M68K_EMUL_OP_DEBUG_STR >> 8, M68K_EMUL_OP_DEBUG_STR & 0xff, + 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; } @@ -290,15 +281,18 @@ void EmulOp(M68kRegisters *r, uint32 pc, TimerReset(); MacOSUtilReset(); AudioReset(); -#if 0 - printf("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 + 0x1b00, DR_CACHE_BASE + 0x10000); - memcpy((void *)(DR_CACHE_BASE + 0x10000), (void *)(ROM_BASE + 0x370000), 0x10000); - clear_caches((void *)(DR_CACHE_BASE + 0x10000), 0x10000, B_INVALIDATE_ICACHE | B_FLUSH_DCACHE); -#endif + + // Enable DR emulator + if (PrefsFindBool("jit68k")) { + 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, DR_EMULATOR_BASE, DR_EMULATOR_SIZE); + } break; case OP_IRQ: // Level 1 interrupt @@ -310,11 +304,7 @@ void EmulOp(M68kRegisters *r, uint32 pc, #if !PRECISE_TIMING TimerInterrupt(); #endif -#if EMULATED_PPC ExecuteNative(NATIVE_VIDEO_VBL); -#else - ExecutePPC(VideoVBL); -#endif static int tick_counter = 0; if (++tick_counter >= 60) { @@ -332,11 +322,7 @@ void EmulOp(M68kRegisters *r, uint32 pc, } if (InterruptFlags & INTFLAG_ETHER) { ClearInterruptFlag(INTFLAG_ETHER); -#if EMULATED_PPC ExecuteNative(NATIVE_ETHER_IRQ); -#else - ExecutePPC(EtherIRQ); -#endif } if (InterruptFlags & INTFLAG_TIMER) { ClearInterruptFlag(INTFLAG_TIMER); @@ -443,6 +429,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; @@ -467,15 +461,19 @@ void EmulOp(M68kRegisters *r, uint32 pc, break; case OP_IDLE_TIME: -#if __BEOS__ // Sleep if no events pending - if (ReadMacInt32(0x14c) == 0) { - sleep(16667); - } -#endif + if (ReadMacInt32(0x14c) == 0) + Delay_usec(16667); r->a[0] = ReadMacInt32(0x2b6); break; + case OP_IDLE_TIME_2: + // Sleep if no events pending + if (ReadMacInt32(0x14c) == 0) + Delay_usec(16667); + r->d[0] = (uint32)-2; + break; + default: printf("FATAL: EMUL_OP called with bogus selector %08x\n", selector); QuitEmulator();