From 7f42f70283eb370a641f9a6357e7bbb739bed6df Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 19 Oct 2023 10:28:25 +1030 Subject: [PATCH] Core: Make R4300iOp::ExecuteCPU() and R4300iOp::ExecuteOps(int32_t Cycles) non static --- .../N64System/Interpreter/InterpreterOps.cpp | 41 ++++++------------- .../N64System/Interpreter/InterpreterOps.h | 22 +++++----- .../N64System/Mips/MemoryVirtualMem.cpp | 17 ++++++++ .../N64System/Mips/MemoryVirtualMem.h | 6 ++- Source/Project64-core/N64System/N64System.cpp | 7 +--- Source/Project64-core/N64System/N64System.h | 1 + .../N64System/Recompiler/Recompiler.cpp | 4 +- .../Recompiler/x86/x86RecompilerOps.cpp | 14 +++---- .../N64System/SystemGlobals.cpp | 2 +- 9 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp index 6cf81d93a..9735bc8df 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp @@ -15,7 +15,6 @@ #include bool R4300iOp::m_TestTimer = false; -R4300iOp::Func * R4300iOp::m_R4300i_Opcode = nullptr; R4300iOpcode R4300iOp::m_Opcode; R4300iOp::Func R4300iOp::Jump_Opcode[64]; @@ -41,10 +40,14 @@ const int32_t R4300iOp::SWR_SHIFT[4] = {24, 16, 8, 0}; const int32_t R4300iOp::LWL_SHIFT[4] = {0, 8, 16, 24}; const int32_t R4300iOp::LWR_SHIFT[4] = {24, 16, 8, 0}; -void R4300iOp::BuildCPU() +R4300iOp::R4300iOp() +{ + m_TestTimer = false; + BuildInterpreter(); +} + +R4300iOp::~R4300iOp() { - R4300iOp::m_TestTimer = false; - m_R4300i_Opcode = R4300iOp::BuildInterpreter(); } void R4300iOp::InPermLoop() @@ -77,10 +80,9 @@ void R4300iOp::ExecuteCPU() bool & Done = g_System->m_EndEmulation; PIPELINE_STAGE & PipelineStage = g_System->m_PipelineStage; uint32_t & PROGRAM_COUNTER = *_PROGRAM_COUNTER; - R4300iOpcode & Opcode = R4300iOp::m_Opcode; uint32_t & JumpToLocation = g_System->m_JumpToLocation; uint32_t & JumpDelayLocation = g_System->m_JumpDelayLocation; - bool & TestTimer = R4300iOp::m_TestTimer; + bool & TestTimer = m_TestTimer; const int32_t & bDoSomething = g_SystemEvents->DoSomething(); uint32_t CountPerOp = g_System->CountPerOp(); int32_t & NextTimer = *g_NextTimer; @@ -90,7 +92,7 @@ void R4300iOp::ExecuteCPU() { while (!Done) { - if (!g_MMU->MemoryValue32(PROGRAM_COUNTER, Opcode.Value)) + if (!g_MMU->MemoryValue32(PROGRAM_COUNTER, m_Opcode.Value)) { g_Reg->TriggerAddressException(PROGRAM_COUNTER, EXC_RMISS); PROGRAM_COUNTER = JumpToLocation; @@ -130,7 +132,7 @@ void R4300iOp::ExecuteCPU() // WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",*_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType()); } */ - m_R4300i_Opcode[Opcode.op](); + Jump_Opcode[m_Opcode.op](); _GPR[0].DW = 0; // MIPS $zero hard-wired to 0 NextTimer -= CountPerOp; @@ -237,7 +239,7 @@ void R4300iOp::ExecuteOps(int32_t Cycles) //WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s t9: %08X v1: %08X",*_PROGRAM_COUNTER,R4300iInstruction(*_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str(),_GPR[0x19].UW[0],_GPR[0x03].UW[0]); //WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",*_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType()); }*/ - m_R4300i_Opcode[Opcode.op](); + Jump_Opcode[Opcode.op](); _GPR[0].DW = 0; /* MIPS $zero hard-wired to 0 */ Cycles -= CountPerOp; @@ -376,7 +378,7 @@ void R4300iOp::COP1_L() Jump_CoP1_L[m_Opcode.funct](); } -R4300iOp::Func * R4300iOp::BuildInterpreter() +void R4300iOp::BuildInterpreter() { Jump_Opcode[0] = SPECIAL; Jump_Opcode[1] = REGIMM; @@ -996,8 +998,6 @@ R4300iOp::Func * R4300iOp::BuildInterpreter() Jump_CoP2[29] = CPO2_INVALID_OP; Jump_CoP2[30] = CPO2_INVALID_OP; Jump_CoP2[31] = CPO2_INVALID_OP; - - return Jump_Opcode; } // Opcode functions @@ -3323,23 +3323,6 @@ void R4300iOp::UnknownOpcode() } } -bool R4300iOp::MemoryBreakpoint() -{ - if (g_Settings->LoadBool(Debugger_SteppingOps)) - { - return false; - } - g_Settings->SaveBool(Debugger_SteppingOps, true); - g_Debugger->WaitForStep(); - if (SkipOp()) - { - // Skip command if instructed by the debugger - g_Settings->SaveBool(Debugger_SkipOp, false); - return true; - } - return false; -} - bool R4300iOp::TestCop1UsableException(void) { if (g_Reg->STATUS_REGISTER.CU1 == 0) diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.h b/Source/Project64-core/N64System/Interpreter/InterpreterOps.h index 5cff65d9e..bec2446f0 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.h +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.h @@ -8,15 +8,17 @@ class CX86RecompilerOps; class R4300iOp : public CLogging, - protected CDebugSettings, - protected CSystemRegisters + private CDebugSettings, + private CSystemRegisters { friend CX86RecompilerOps; public: - static void BuildCPU(); - static void ExecuteCPU(); - static void ExecuteOps(int32_t Cycles); + R4300iOp(); + ~R4300iOp(void); + + void ExecuteCPU(); + void ExecuteOps(int32_t Cycles); static void InPermLoop(); typedef void (*Func)(); @@ -232,14 +234,15 @@ public: static void ReservedInstruction(); static void UnknownOpcode(); - static Func * BuildInterpreter(); - static bool m_TestTimer; static R4300iOpcode m_Opcode; - static bool MemoryBreakpoint(); +private: + R4300iOp(const R4300iOp &); + R4300iOp & operator=(const R4300iOp &); + + void BuildInterpreter(void); -protected: static void SPECIAL(); static void REGIMM(); static void COP0(); @@ -279,5 +282,4 @@ protected: static const uint32_t SWL_MASK[4], SWR_MASK[4], LWL_MASK[4], LWR_MASK[4]; static const int32_t SWL_SHIFT[4], SWR_SHIFT[4], LWL_SHIFT[4], LWR_SHIFT[4]; - static R4300iOp::Func * m_R4300i_Opcode; }; diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp index 116649396..7070b5841 100755 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp @@ -625,6 +625,23 @@ bool CMipsMemoryVM::VAddrToPAddr(uint32_t VAddr, uint32_t & PAddr) const return true; } +bool CMipsMemoryVM::MemoryBreakpoint() +{ + if (g_Settings->LoadBool(Debugger_SteppingOps)) + { + return false; + } + g_Settings->SaveBool(Debugger_SteppingOps, true); + g_Debugger->WaitForStep(); + if (SkipOp()) + { + // Skip command if instructed by the debugger + g_Settings->SaveBool(Debugger_SkipOp, false); + return true; + } + return false; +} + bool CMipsMemoryVM::LB_VAddr32(uint32_t VAddr, uint8_t & Value) { uint32_t BaseAddress = m_TLB_ReadMap[VAddr >> 12]; diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h index a42602f8e..49f0368bd 100644 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h @@ -48,8 +48,8 @@ class CArmRecompilerOps; #endif class CMipsMemoryVM : - private R4300iOp, - private CGameSettings + private CGameSettings, + private CDebugSettings { public: CMipsMemoryVM(CN64System & System, bool SavesReadOnly); @@ -163,6 +163,8 @@ private: static void RdramChanged(CMipsMemoryVM * _this); static void ChangeMiIntrMask(); + bool MemoryBreakpoint(); + bool LB_VAddr32(uint32_t VAddr, uint8_t & Value); bool LH_VAddr32(uint32_t VAddr, uint16_t & Value); bool LW_VAddr32(uint32_t VAddr, uint32_t & Value); diff --git a/Source/Project64-core/N64System/N64System.cpp b/Source/Project64-core/N64System/N64System.cpp index efe12f98a..70a0fa702 100644 --- a/Source/Project64-core/N64System/N64System.cpp +++ b/Source/Project64-core/N64System/N64System.cpp @@ -61,9 +61,6 @@ CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesR } m_Limiter.SetHertz(gameHertz); g_Settings->SaveDword(GameRunning_ScreenHertz, gameHertz); - WriteTrace(TraceN64System, TraceDebug, "Setting up system"); - R4300iOp::BuildCPU(); - if (!m_MMU_VM.Initialize(SyncSystem)) { WriteTrace(TraceN64System, TraceWarning, "MMU failed to initialize"); @@ -1077,7 +1074,7 @@ void CN64System::ExecuteCPU() void CN64System::ExecuteInterpret() { SetActiveSystem(); - R4300iOp::ExecuteCPU(); + m_OpCodes.ExecuteCPU(); } void CN64System::ExecuteRecompiler() @@ -1123,7 +1120,7 @@ void CN64System::UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycl } SecondCPU->SetActiveSystem(true); - R4300iOp::ExecuteOps(Cycles); + m_OpCodes.ExecuteOps(Cycles); SetActiveSystem(true); } diff --git a/Source/Project64-core/N64System/N64System.h b/Source/Project64-core/N64System/N64System.h index 00b2b92aa..f76d428a1 100644 --- a/Source/Project64-core/N64System/N64System.h +++ b/Source/Project64-core/N64System/N64System.h @@ -180,6 +180,7 @@ private: CMipsMemoryVM m_MMU_VM; CRegisters m_Reg; CTLB m_TLB; + R4300iOp m_OpCodes; CMempak m_Mempak; CFramePerSecond m_FPS; CProfiling m_CPU_Usage; // Used to track the CPU usage diff --git a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp index bbad69fce..1929cec86 100644 --- a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp +++ b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp @@ -183,7 +183,7 @@ void CRecompiler::RecompilerMain_Lookup() while (m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) { - R4300iOp::ExecuteOps(g_System->CountPerOp()); + g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp()); opsExecuted += g_System->CountPerOp(); } @@ -296,7 +296,7 @@ void CRecompiler::RecompilerMain_Lookup_validate() while (m_MMU.VAddrToPAddr(PC, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) { - R4300iOp::ExecuteOps(g_System->CountPerOp()); + g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp()); opsExecuted += g_System->CountPerOp(); } diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index d2ba8f65e..7860e4dba 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -56,7 +56,7 @@ void CX86RecompilerOps::x86CompilerBreakPoint() } continue; } - R4300iOp::ExecuteOps(g_System->CountPerOp()); + g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp()); if (g_SyncSystem) { g_System->UpdateSyncCPU(g_SyncSystem, g_System->CountPerOp()); @@ -67,7 +67,7 @@ void CX86RecompilerOps::x86CompilerBreakPoint() if (g_System->PipelineStage() != PIPELINE_STAGE_NORMAL) { - R4300iOp::ExecuteOps(g_System->CountPerOp()); + g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp()); if (g_SyncSystem) { g_System->UpdateSyncCPU(g_SyncSystem, g_System->CountPerOp()); @@ -78,7 +78,7 @@ void CX86RecompilerOps::x86CompilerBreakPoint() void CX86RecompilerOps::x86BreakPointDelaySlot() { - R4300iOp::ExecuteOps(g_System->CountPerOp()); + g_SyncSystem->m_OpCodes.ExecuteOps(g_System->CountPerOp()); if (g_SyncSystem) { g_System->UpdateSyncCPU(g_SyncSystem, g_System->CountPerOp()); @@ -90,7 +90,7 @@ void CX86RecompilerOps::x86BreakPointDelaySlot() } if (g_System->PipelineStage() != PIPELINE_STAGE_NORMAL) { - R4300iOp::ExecuteOps(g_System->CountPerOp()); + g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp()); if (g_SyncSystem) { g_System->UpdateSyncCPU(g_SyncSystem, g_System->CountPerOp()); @@ -110,7 +110,7 @@ void CX86RecompilerOps::x86MemoryBreakPoint() { g_Reg->m_PROGRAM_COUNTER -= 4; *g_NextTimer += g_System->CountPerOp(); - R4300iOp::ExecuteOps(g_System->CountPerOp()); + g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp()); } x86CompilerBreakPoint(); } @@ -9576,9 +9576,7 @@ void CX86RecompilerOps::OverflowDelaySlot(bool TestTimer) } m_Assembler.PushImm32("g_System->CountPerOp()", g_System->CountPerOp()); - m_Assembler.CallFunc((uint32_t)R4300iOp::ExecuteOps, "R4300iOp::ExecuteOps"); - m_Assembler.AddConstToX86Reg(asmjit::x86::esp, 4); - + m_Assembler.CallThis((uint32_t)&g_System->m_OpCodes, AddressOf(&R4300iOp::ExecuteOps), "R4300iOp::ExecuteOps", 8); if (g_System->bFastSP() && g_Recompiler) { m_Assembler.CallThis((uint32_t)g_Recompiler, AddressOf(&CRecompiler::ResetMemoryStackPos), "CRecompiler::ResetMemoryStackPos", 4); diff --git a/Source/Project64-core/N64System/SystemGlobals.cpp b/Source/Project64-core/N64System/SystemGlobals.cpp index c64fe08e7..647e978e4 100644 --- a/Source/Project64-core/N64System/SystemGlobals.cpp +++ b/Source/Project64-core/N64System/SystemGlobals.cpp @@ -24,4 +24,4 @@ CMempak * g_Mempak = nullptr; CRandom * g_Random = nullptr; CEnhancements * g_Enhancements = nullptr; -int * g_NextTimer; \ No newline at end of file +int32_t * g_NextTimer; \ No newline at end of file