Move the core loop to Core.cpp

This commit is contained in:
Henrik Rydgård 2024-12-08 11:47:12 +01:00
parent b3d08977d5
commit df91f699fc
5 changed files with 54 additions and 56 deletions

View file

@ -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<std::mutex> 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.

View file

@ -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,

View file

@ -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) {

View file

@ -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.

View file

@ -1354,7 +1354,7 @@ namespace Libretro
gpu->BeginHostFrame();
coreState = CORE_RUNNING_CPU;
PSP_RunLoopUntil(UINT64_MAX);
PSP_RunLoopWhileState();
gpu->EndHostFrame();