From b24ce4bd1494feb54af203c7ea2df4f94b1fc4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 4 Apr 2025 15:26:02 +0200 Subject: [PATCH] Simplifications --- Core/Core.cpp | 11 +++--- Core/Debugger/Breakpoints.cpp | 5 ++- Core/HW/AsyncIOManager.h | 1 + Windows/EmuThread.cpp | 65 +++++++---------------------------- 4 files changed, 19 insertions(+), 63 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 11b6f3edf8..b8cb71450e 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -213,16 +213,13 @@ void Core_RunLoopUntil(u64 globalticks) { case DLResult::DebugBreak: GPUStepping::EnterStepping(coreState); break; - case DLResult::Error: - // We should elegantly report the error somehow, or I guess ignore it. - hleFinishSyscallAfterGe(); - coreState = preGeCoreState; - break; - case DLResult::Done: - // Done executing for now + + case DLResult::Error: // We should elegantly report the error somehow, or I guess ignore it. + case DLResult::Done: // Done executing for now hleFinishSyscallAfterGe(); coreState = preGeCoreState; break; + default: // Not a valid return value. _dbg_assert_(false); diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index 176a172e7c..5e6849ced9 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -63,10 +63,9 @@ BreakAction MemCheck::Apply(u32 addr, bool write, int size, u32 pc) { BreakAction MemCheck::Action(u32 addr, bool write, int size, u32 pc, const char *reason) { // Conditions have always already been checked if we get here. Log(addr, write, size, pc, reason); - if ((result & BREAK_ACTION_PAUSE) && coreState != CORE_POWERUP) { + if (result & BREAK_ACTION_PAUSE) { Core_Break(BreakReason::MemoryBreakpoint, start); } - return result; } @@ -291,7 +290,7 @@ BreakAction BreakpointManager::ExecBreakPoint(u32 addr) { NOTICE_LOG(Log::JIT, "BKP PC=%08x: %s", addr, formatted.c_str()); } } - if ((info.result & BREAK_ACTION_PAUSE) && coreState != CORE_POWERUP) { + if (info.result & BREAK_ACTION_PAUSE) { Core_Break(BreakReason::CpuBreakpoint, info.addr); } diff --git a/Core/HW/AsyncIOManager.h b/Core/HW/AsyncIOManager.h index 47eff66362..2a319dfd76 100644 --- a/Core/HW/AsyncIOManager.h +++ b/Core/HW/AsyncIOManager.h @@ -263,6 +263,7 @@ private: void Write(u32 handle, const u8 *buf, size_t bytes); void EventResult(u32 handle, const AsyncIOResult &result); + bool threadEnabled_ = false; bool eventsRunning_ = false; bool eventsHaveRun_ = false; diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index d4bcc8e15c..2d395223c5 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -68,6 +68,7 @@ void MainThread_Stop() { // Already stopped? UpdateUIState(UISTATE_EXIT); Core_Stop(); + _dbg_assert_(mainThread.joinable()); mainThread.join(); } @@ -75,52 +76,6 @@ bool MainThread_Ready() { return g_inLoop; } -static bool Run(GraphicsContext *ctx) { - System_Notify(SystemNotification::DISASSEMBLY); - while (true) { - if (GetUIState() != UISTATE_INGAME) { - Core_StateProcessed(); - if (GetUIState() == UISTATE_EXIT) { - // Not sure why we do a final frame here? - NativeFrame(ctx); - return false; - } - NativeFrame(ctx); - continue; - } - - switch (coreState) { - case CORE_RUNNING_CPU: - case CORE_STEPPING_CPU: - case CORE_RUNNING_GE: // Shouldn't be in this state between frames - case CORE_STEPPING_GE: // This is OK though. - // enter a fast runloop - NativeFrame(ctx); - if (coreState == CORE_POWERDOWN) { - return true; - } - break; - case CORE_POWERUP: - case CORE_POWERDOWN: - // Need to step the loop. - NativeFrame(ctx); - return true; - - case CORE_RUNTIME_ERROR: - // Need to step the loop. - NativeFrame(ctx); - break; - - case CORE_BOOT_ERROR: - // Exit loop!! - return true; - - case CORE_NEXTFRAME: - return true; - } - } -} - static void EmuThreadFunc(GraphicsContext *graphicsContext) { SetCurrentThreadName("EmuThread"); @@ -133,9 +88,14 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) { while (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED) { // We're here again, so the game quit. Restart Run() which controls the UI. // This way they can load a new game. - if (!Core_IsActive()) + if (!Core_IsActive()) { UpdateUIState(UISTATE_MENU); - if (!Run(g_graphicsContext)) { + } + + Core_StateProcessed(); + NativeFrame(graphicsContext); + + if (GetUIState() == UISTATE_EXIT) { emuThreadState = (int)EmuThreadState::QUIT_REQUESTED; } } @@ -343,16 +303,15 @@ void MainThreadFunc() { // This way they can load a new game. if (!Core_IsActive()) UpdateUIState(UISTATE_MENU); - Run(g_graphicsContext); - if (coreState == CORE_BOOT_ERROR) { - break; - } + Core_StateProcessed(); + NativeFrame(graphicsContext); } } Core_Stop(); if (!useEmuThread) { // Process the shutdown. Without this, non-GL delays 800ms on shutdown. - Run(g_graphicsContext); + Core_StateProcessed(); + NativeFrame(graphicsContext); } Core_WaitInactive();