PatchEngine: Avoid ppcState global.

This commit is contained in:
Admiral H. Curtiss 2023-01-10 19:06:02 +01:00
parent 4c349caabd
commit dd9907ed93
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
1 changed files with 11 additions and 4 deletions

View File

@ -33,6 +33,7 @@
#include "Core/GeckoCodeConfig.h" #include "Core/GeckoCodeConfig.h"
#include "Core/PowerPC/MMU.h" #include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
namespace PatchEngine namespace PatchEngine
{ {
@ -277,10 +278,13 @@ static void ApplyMemoryPatches(std::span<const std::size_t> memory_patch_indices
// We require at least 2 stack frames, if the stack is shallower than that then it won't work. // We require at least 2 stack frames, if the stack is shallower than that then it won't work.
static bool IsStackSane() 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 // Check the stack pointer
u32 SP = PowerPC::ppcState.gpr[1]; u32 SP = ppc_state.gpr[1];
if (!PowerPC::HostIsRAMAddress(SP)) if (!PowerPC::HostIsRAMAddress(SP))
return false; return false;
@ -311,16 +315,19 @@ void RemoveMemoryPatch(std::size_t index)
bool ApplyFramePatches() 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 // 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. // 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 // 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. // 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, DEBUG_LOG_FMT(ACTIONREPLAY,
"Need to retry later. CPU configuration is currently incorrect. PC = {:#010x}, " "Need to retry later. CPU configuration is currently incorrect. PC = {:#010x}, "
"MSR = {:#010x}", "MSR = {:#010x}",
PowerPC::ppcState.pc, PowerPC::ppcState.msr.Hex); ppc_state.pc, ppc_state.msr.Hex);
return false; return false;
} }