From 2e2d8f29893fdadf5d81e2cee77f49c724ad41b0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 29 Apr 2018 18:38:17 -0700 Subject: [PATCH] Core: Process stepping on other platforms. This includes Android. --- Core/Core.cpp | 24 +++++++++++++----------- Core/System.cpp | 14 ++++++++++++++ Core/System.h | 1 + UI/EmuScreen.cpp | 9 +-------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 3c9bf93018..2370f9d603 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -239,6 +239,8 @@ void Core_UpdateSingleStep() { void Core_SingleStep() { currentMIPS->SingleStep(); + if (coreState == CORE_STEPPING) + steppingCounter++; } static inline void CoreStateProcessed() { @@ -249,10 +251,14 @@ static inline void CoreStateProcessed() { } } -static inline void Core_WaitStepping() { +static inline bool Core_WaitStepping() { std::unique_lock guard(m_hStepMutex); if (!singleStepPending && coreState == CORE_STEPPING) m_StepCond.wait(guard); + + bool result = singleStepPending; + singleStepPending = false; + return result; } void Core_ProcessStepping() { @@ -268,12 +274,10 @@ void Core_ProcessStepping() { host->UpdateMemView(); // Need to check inside the lock to avoid races. - Core_WaitStepping(); + bool doStep = Core_WaitStepping(); // We may still be stepping without singleStepPending to process a save state. - if (singleStepPending && coreState == CORE_STEPPING) { - singleStepPending = false; - + if (doStep && coreState == CORE_STEPPING) { Core_SingleStep(); // Update disasm dialog. host->UpdateDisassembly(); @@ -298,15 +302,13 @@ void Core_Run(GraphicsContext *ctx) { switch (coreState) { case CORE_RUNNING: + case CORE_STEPPING: // enter a fast runloop Core_RunLoop(ctx); - break; - - // We should never get here on Android. - case CORE_STEPPING: - Core_ProcessStepping(); - if (coreState == CORE_POWERDOWN) + if (coreState == CORE_POWERDOWN) { + CoreStateProcessed(); return; + } break; case CORE_POWERUP: diff --git a/Core/System.cpp b/Core/System.cpp index afe1ac76ea..6355c66dd3 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -430,10 +430,24 @@ void PSP_EndHostFrame() { } } +void PSP_RunLoopWhileState() { + // We just run the CPU until we get to vblank. This will quickly sync up pretty nicely. + // The actual number of cycles doesn't matter so much here as we will break due to CORE_NEXTFRAME, most of the time hopefully... + int blockTicks = usToCycles(1000000 / 10); + + // Run until CORE_NEXTFRAME + while (coreState == CORE_RUNNING || coreState == CORE_STEPPING) { + PSP_RunLoopFor(blockTicks); + } +} + void PSP_RunLoopUntil(u64 globalticks) { SaveState::Process(); if (coreState == CORE_POWERDOWN || coreState == CORE_ERROR) { return; + } else if (coreState == CORE_STEPPING) { + Core_ProcessStepping(); + return; } mipsr4k.RunLoopUntil(globalticks); diff --git a/Core/System.h b/Core/System.h index a2a3ed5c48..32182c3bc2 100644 --- a/Core/System.h +++ b/Core/System.h @@ -70,6 +70,7 @@ void PSP_Shutdown(); void PSP_BeginHostFrame(); void PSP_EndHostFrame(); +void PSP_RunLoopWhileState(); void PSP_RunLoopUntil(u64 globalticks); void PSP_RunLoopFor(int cycles); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 8064883ada..35cf6a0e0e 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1193,14 +1193,7 @@ void EmuScreen::render() { PSP_BeginHostFrame(); - // We just run the CPU until we get to vblank. This will quickly sync up pretty nicely. - // The actual number of cycles doesn't matter so much here as we will break due to CORE_NEXTFRAME, most of the time hopefully... - int blockTicks = usToCycles(1000000 / 10); - - // Run until CORE_NEXTFRAME - while (coreState == CORE_RUNNING) { - PSP_RunLoopFor(blockTicks); - } + PSP_RunLoopWhileState(); // Hopefully coreState is now CORE_NEXTFRAME if (coreState == CORE_NEXTFRAME) {