diff --git a/Core/Core.cpp b/Core/Core.cpp index 3b2753e0f7..e24d6ea401 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -34,23 +34,20 @@ #include "Common/Log.h" #include "Core/Core.h" #include "Core/Config.h" -#include "Core/MemMap.h" +#include "Core/HLE/HLE.h" #include "Core/MIPS/MIPSDebugInterface.h" #include "Core/SaveState.h" #include "Core/System.h" #include "Core/MemFault.h" #include "Core/Debugger/Breakpoints.h" -#include "Core/HW/Display.h" #include "Core/MIPS/MIPS.h" #include "Core/MIPS/MIPSAnalyst.h" #include "Core/HLE/sceNetAdhoc.h" -#include "GPU/Debugger/Stepping.h" #include "Core/MIPS/MIPSTracer.h" -#ifdef _WIN32 -#include "Common/CommonWindows.h" -#include "Windows/InputDevice.h" -#endif +#include "GPU/Debugger/Stepping.h" +#include "GPU/GPU.h" +#include "GPU/GPUCommon.h" // Step command to execute next static std::mutex g_stepMutex; @@ -85,6 +82,9 @@ static bool powerSaving = false; static MIPSExceptionInfo g_exceptionInfo; +// This is called on EmuThread before RunLoop. +static void Core_ProcessStepping(MIPSDebugInterface *cpu); + void Core_SetGraphicsContext(GraphicsContext *ctx) { PSP_CoreParameter().graphicsContext = ctx; } @@ -159,6 +159,48 @@ bool Core_GetPowerSaving() { return powerSaving; } +void Core_RunLoopUntil(u64 globalticks) { + while (true) { + switch (coreState) { + case CORE_POWERDOWN: + case CORE_BOOT_ERROR: + case CORE_RUNTIME_ERROR: + case CORE_NEXTFRAME: + return; + case CORE_STEPPING_CPU: + case CORE_STEPPING_GE: + Core_ProcessStepping(currentDebugMIPS); + return; + case CORE_RUNNING_CPU: + mipsr4k.RunLoopUntil(globalticks); + break; // Will loop around to go to RUNNING_GE or NEXTFRAME, which will exit. + case CORE_RUNNING_GE: + switch (gpu->ProcessDLQueue()) { + case DLResult::Break: + GPUStepping::EnterStepping(); + break; + case DLResult::Error: + // We should elegantly report the error, or I guess ignore it. + hleFinishSyscallAfterGe(); + coreState = CORE_RUNNING_CPU; + break; + case DLResult::Stall: + case DLResult::Done: + // Done executing for now + hleFinishSyscallAfterGe(); + coreState = CORE_RUNNING_CPU; + break; + default: + _dbg_assert_(false); + hleFinishSyscallAfterGe(); + coreState = CORE_RUNNING_CPU; + break; + } + break; + } + } +} + bool Core_RequestCPUStep(CPUStepType type, int stepSize) { std::lock_guard guard(g_stepMutex); if (g_cpuStepCommand.type != CPUStepType::None) { @@ -268,7 +310,7 @@ void Core_SwitchToGe() { coreState = CORE_RUNNING_GE; } -void Core_ProcessStepping(MIPSDebugInterface *cpu) { +static void Core_ProcessStepping(MIPSDebugInterface *cpu) { Core_StateProcessed(); // Check if there's any pending save state actions. diff --git a/Core/Core.h b/Core/Core.h index 4b9cb2abd9..976ca04372 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -102,6 +102,8 @@ void Core_WaitInactive(); void Core_SetPowerSaving(bool mode); bool Core_GetPowerSaving(); +void Core_RunLoopUntil(u64 globalticks); + enum class MemoryExceptionType { NONE, UNKNOWN, diff --git a/Core/System.cpp b/Core/System.cpp index 243ba6b36a..d72423e601 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -109,9 +109,6 @@ static volatile bool pspIsIniting = false; static volatile bool pspIsQuitting = false; static volatile bool pspIsRebooting = false; -// This is called on EmuThread before RunLoop. -void Core_ProcessStepping(MIPSDebugInterface *cpu); - void ResetUIState() { globalUIState = UISTATE_MENU; } @@ -612,50 +609,8 @@ void PSP_RunLoopWhileState() { PSP_RunLoopFor(blockTicks); } -void PSP_RunLoopUntil(u64 globalticks) { - while (true) { - switch (coreState) { - case CORE_POWERDOWN: - case CORE_BOOT_ERROR: - case CORE_RUNTIME_ERROR: - case CORE_NEXTFRAME: - return; - case CORE_STEPPING_CPU: - case CORE_STEPPING_GE: - Core_ProcessStepping(currentDebugMIPS); - return; - case CORE_RUNNING_CPU: - mipsr4k.RunLoopUntil(globalticks); - break; // Will loop around to go to RUNNING_GE or NEXTFRAME, which will exit. - case CORE_RUNNING_GE: - switch (gpu->ProcessDLQueue()) { - case DLResult::Break: - GPUStepping::EnterStepping(); - break; - case DLResult::Error: - // We should elegantly report the error, or I guess ignore it. - hleFinishSyscallAfterGe(); - coreState = CORE_RUNNING_CPU; - break; - case DLResult::Stall: - case DLResult::Done: - // Done executing for now - hleFinishSyscallAfterGe(); - coreState = CORE_RUNNING_CPU; - break; - default: - _dbg_assert_(false); - hleFinishSyscallAfterGe(); - coreState = CORE_RUNNING_CPU; - break; - } - break; - } - } -} - void PSP_RunLoopFor(int cycles) { - PSP_RunLoopUntil(CoreTiming::GetTicks() + cycles); + Core_RunLoopUntil(CoreTiming::GetTicks() + cycles); } Path GetSysDirectory(PSPDirectories directoryType) { diff --git a/Core/System.h b/Core/System.h index a46c265e4d..22eae2a3ef 100644 --- a/Core/System.h +++ b/Core/System.h @@ -83,7 +83,6 @@ bool PSP_Reboot(std::string *error_string); void PSP_BeginHostFrame(); void PSP_EndHostFrame(); void PSP_RunLoopWhileState(); -void PSP_RunLoopUntil(u64 globalticks); void PSP_RunLoopFor(int cycles); // Used to wait for background loading thread. diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index bb08fab4f4..923dc4206e 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -1354,7 +1354,7 @@ namespace Libretro gpu->BeginHostFrame(); coreState = CORE_RUNNING_CPU; - PSP_RunLoopUntil(UINT64_MAX); + PSP_RunLoopWhileState(); gpu->EndHostFrame();