From dd9907ed9394fc411fe61f545ffc56738c5d1882 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 10 Jan 2023 19:06:02 +0100 Subject: [PATCH] PatchEngine: Avoid ppcState global. --- Source/Core/Core/PatchEngine.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/PatchEngine.cpp b/Source/Core/Core/PatchEngine.cpp index a4e0e9042b..0b07a604fd 100644 --- a/Source/Core/Core/PatchEngine.cpp +++ b/Source/Core/Core/PatchEngine.cpp @@ -33,6 +33,7 @@ #include "Core/GeckoCodeConfig.h" #include "Core/PowerPC/MMU.h" #include "Core/PowerPC/PowerPC.h" +#include "Core/System.h" namespace PatchEngine { @@ -277,10 +278,13 @@ static void ApplyMemoryPatches(std::span memory_patch_indices // We require at least 2 stack frames, if the stack is shallower than that then it won't work. static bool IsStackSane() { - DEBUG_ASSERT(PowerPC::ppcState.msr.DR && PowerPC::ppcState.msr.IR); + auto& system = Core::System::GetInstance(); + auto& ppc_state = system.GetPPCState(); + + DEBUG_ASSERT(ppc_state.msr.DR && ppc_state.msr.IR); // Check the stack pointer - u32 SP = PowerPC::ppcState.gpr[1]; + u32 SP = ppc_state.gpr[1]; if (!PowerPC::HostIsRAMAddress(SP)) return false; @@ -311,16 +315,19 @@ void RemoveMemoryPatch(std::size_t index) bool ApplyFramePatches() { + auto& system = Core::System::GetInstance(); + auto& ppc_state = system.GetPPCState(); + // Because we're using the VI Interrupt to time this instead of patching the game with a // callback hook we can end up catching the game in an exception vector. // We deal with this by returning false so that SystemTimers will reschedule us in a few cycles // where we can try again after the CPU hopefully returns back to the normal instruction flow. - if (!PowerPC::ppcState.msr.DR || !PowerPC::ppcState.msr.IR || !IsStackSane()) + if (!ppc_state.msr.DR || !ppc_state.msr.IR || !IsStackSane()) { DEBUG_LOG_FMT(ACTIONREPLAY, "Need to retry later. CPU configuration is currently incorrect. PC = {:#010x}, " "MSR = {:#010x}", - PowerPC::ppcState.pc, PowerPC::ppcState.msr.Hex); + ppc_state.pc, ppc_state.msr.Hex); return false; }