From b27a022e7cb51bbb04ab2199ef8196f3a5eb64d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 4 Apr 2025 16:11:31 +0200 Subject: [PATCH] Remove two states from the CoreState enum. --- Core/Core.cpp | 8 ++------ Core/Core.h | 6 +----- Core/HLE/sceIo.cpp | 4 +++- Core/HW/AsyncIOManager.h | 2 +- Core/MIPS/MIPSDebugInterface.cpp | 2 +- UI/EmuScreen.cpp | 13 +++++-------- Windows/EmuThread.cpp | 9 ++------- Windows/MainWindow.cpp | 1 - Windows/MainWindowMenu.cpp | 2 +- headless/Headless.cpp | 1 - unittest/JitHarness.cpp | 2 +- 11 files changed, 17 insertions(+), 33 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 4e8cb0c1ac..41d486131e 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -73,8 +73,8 @@ static int steppingCounter = 0; static std::set lifecycleFuncs; // This can be read and written from ANYWHERE. -volatile CoreState coreState = CORE_STEPPING_CPU; -CoreState preGeCoreState = CORE_BOOT_ERROR; +volatile CoreState coreState = CORE_POWERDOWN; +CoreState preGeCoreState = CORE_POWERDOWN; // If true, core state has been changed, but JIT has probably not noticed yet. volatile bool coreStatePending = false; @@ -96,9 +96,7 @@ const char *CoreStateToString(CoreState state) { case CORE_RUNNING_CPU: return "RUNNING_CPU"; case CORE_NEXTFRAME: return "NEXTFRAME"; case CORE_STEPPING_CPU: return "STEPPING_CPU"; - case CORE_POWERUP: return "POWERUP"; case CORE_POWERDOWN: return "POWERDOWN"; - case CORE_BOOT_ERROR: return "BOOT_ERROR"; case CORE_RUNTIME_ERROR: return "RUNTIME_ERROR"; case CORE_STEPPING_GE: return "STEPPING_GE"; case CORE_RUNNING_GE: return "RUNNING_GE"; @@ -203,9 +201,7 @@ bool Core_GetPowerSaving() { void Core_RunLoopUntil(u64 globalticks) { while (true) { switch (coreState) { - case CORE_POWERUP: case CORE_POWERDOWN: - case CORE_BOOT_ERROR: case CORE_RUNTIME_ERROR: case CORE_NEXTFRAME: return; diff --git a/Core/Core.h b/Core/Core.h index 2cd7484ec9..008c83408f 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -117,12 +117,8 @@ enum CoreState { CORE_NEXTFRAME = 1, // Emulation is paused, CPU thread is sleeping. CORE_STEPPING_CPU, // Can be used for recoverable runtime errors (ignored memory exceptions) - // Core is being powered up. - CORE_POWERUP, - // Core is being powered down. + // Core is not running. CORE_POWERDOWN, - // An error happened at boot. - CORE_BOOT_ERROR, // Unrecoverable runtime error. Recoverable errors should use CORE_STEPPING. CORE_RUNTIME_ERROR, // Stepping the GPU. When done, will switch over to STEPPING_CPU. diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index a8c754e9ad..71bbe5408e 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -582,10 +582,12 @@ static void __IoAsyncEndCallback(SceUID threadID, SceUID prevCallbackId) { static void __IoManagerThread() { SetCurrentThreadName("IO"); + INFO_LOG(Log::sceIo, "Entering __IoManagerThread"); AndroidJNIThreadContext jniContext; - while (ioManagerThreadEnabled && coreState != CORE_BOOT_ERROR && coreState != CORE_RUNTIME_ERROR && coreState != CORE_POWERDOWN) { + while (ioManagerThreadEnabled) { ioManager.RunEventsUntil(CoreTiming::GetTicks() + msToCycles(1000)); } + INFO_LOG(Log::sceIo, "Leaving __IoManagerThread"); } static void __IoWakeManager(CoreLifecycle stage) { diff --git a/Core/HW/AsyncIOManager.h b/Core/HW/AsyncIOManager.h index c2e2b499c8..00170dc4f6 100644 --- a/Core/HW/AsyncIOManager.h +++ b/Core/HW/AsyncIOManager.h @@ -201,7 +201,7 @@ public: // Don't run if it's not running, but wait for startup. if (!eventsRunning_) { - if (eventsHaveRun_ || coreState == CORE_BOOT_ERROR || coreState == CORE_RUNTIME_ERROR || coreState == CORE_POWERDOWN) { + if (eventsHaveRun_ || coreState == CORE_RUNTIME_ERROR || coreState == CORE_POWERDOWN) { return false; } } diff --git a/Core/MIPS/MIPSDebugInterface.cpp b/Core/MIPS/MIPSDebugInterface.cpp index 14d814b2a5..20939f205a 100644 --- a/Core/MIPS/MIPSDebugInterface.cpp +++ b/Core/MIPS/MIPSDebugInterface.cpp @@ -210,7 +210,7 @@ unsigned int MIPSDebugInterface::readMemory(unsigned int address) { bool MIPSDebugInterface::isAlive() { - return PSP_GetBootState() == BootState::Complete && coreState != CORE_BOOT_ERROR && coreState != CORE_RUNTIME_ERROR && coreState != CORE_POWERDOWN; + return PSP_GetBootState() == BootState::Complete && coreState != CORE_RUNTIME_ERROR && coreState != CORE_POWERDOWN; } bool MIPSDebugInterface::isBreakpoint(unsigned int address) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 0801ef9768..db544f6c74 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -201,10 +201,7 @@ EmuScreen::EmuScreen(const Path &filename) &SetPSPAnalog, nullptr); - // Make sure we don't leave it at powerdown after the last game. - // TODO: This really should be handled elsewhere if it isn't. - if (coreState == CORE_POWERDOWN) - coreState = CORE_STEPPING_CPU; + _dbg_assert_(coreState == CORE_POWERDOWN); OnDevMenu.Handle(this, &EmuScreen::OnDevTools); OnChatMenu.Handle(this, &EmuScreen::OnChat); @@ -264,7 +261,6 @@ void EmuScreen::ProcessGameBoot(const Path &filename) { g_BackgroundAudio.SetGame(Path()); bootPending_ = false; errorMessage_ = error_string; - coreState = CORE_BOOT_ERROR; ERROR_LOG(Log::Boot, "Boot failed: %s", errorMessage_.c_str()); return; case BootState::Complete: @@ -342,7 +338,6 @@ void EmuScreen::ProcessGameBoot(const Path &filename) { coreParam.pixelHeight = g_display.pixel_yres; // PSP_InitStart can't really fail anymore, unless it's called at the wrong time. It just starts the loader thread. - coreState = CORE_POWERUP; if (!PSP_InitStart(coreParam)) { bootPending_ = false; ERROR_LOG(Log::Boot, "InitStart ProcessGameBoot error: %s", errorMessage_.c_str()); @@ -445,10 +440,14 @@ EmuScreen::~EmuScreen() { std::string gameID = g_paramSFO.GetValueString("DISC_ID"); g_Config.TimeTracker().Stop(gameID); + // Should not be able to quit during boot, as boot can't be cancelled. + _dbg_assert_(!bootPending_); if (!bootPending_) { PSP_Shutdown(true); } + _dbg_assert_(coreState == CORE_POWERDOWN); + System_PostUIMessage(UIMessage::GAME_SELECTED, ""); g_OSD.ClearAchievementStuff(); @@ -568,8 +567,6 @@ void EmuScreen::sendMessage(UIMessage message, const char *value) { PSP_Shutdown(true); bootPending_ = true; gamePath_ = Path(value); - // Don't leave it on CORE_POWERDOWN, we'll sometimes aggressively bail. - Core_UpdateState(CORE_POWERUP); } } else if (message == UIMessage::CONFIG_LOADED) { // In case we need to position touch controls differently. diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 2d395223c5..08d839034d 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -276,8 +276,6 @@ void MainThreadFunc() { DEBUG_LOG(Log::Boot, "Done."); - _dbg_assert_(coreState != CORE_POWERDOWN); - g_inLoop = true; if (useEmuThread) { @@ -285,10 +283,9 @@ void MainThreadFunc() { } graphicsContext->ThreadStart(); - if (g_Config.bBrowse) + if (g_Config.bBrowse) { PostMessage(MainWindow::GetHWND(), WM_COMMAND, ID_FILE_LOAD, 0); - - Core_Resume(); + } if (useEmuThread) { while (emuThreadState != (int)EmuThreadState::DISABLED) { @@ -326,8 +323,6 @@ void MainThreadFunc() { EmuThreadJoin(); } -shutdown: - if (!useEmuThread) { NativeShutdownGraphics(); } diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 2b0c00a90c..38ceb67ede 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -1166,7 +1166,6 @@ namespace MainWindow NativeSetRestarting(); InputDevice::StopPolling(); MainThread_Stop(); - coreState = CORE_POWERUP; UpdateUIState(UISTATE_MENU); MainThread_Start(g_Config.iGPUBackend == (int)GPUBackend::OPENGL); InputDevice::BeginPolling(); diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index ccbda4e0f4..1097dc28ff 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -1246,7 +1246,7 @@ namespace MainWindow { void UpdateCommands() { static GlobalUIState lastGlobalUIState = UISTATE_PAUSEMENU; - static CoreState lastCoreState = CORE_BOOT_ERROR; + static CoreState lastCoreState = CORE_POWERDOWN; HMENU menu = GetMenu(GetHWND()); EnableMenuItem(menu, ID_DEBUG_LOG, g_Config.bEnableLogging ? MF_ENABLED : MF_GRAYED); diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 2a7c51d192..40b57e9877 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -185,7 +185,6 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const if (opt.compare || opt.bench) coreParameter.collectDebugOutput = &output; - coreState = CORE_POWERUP; if (!PSP_InitStart(coreParameter)) { // Shouldn't really happen anymore, the errors happen later in PSP_InitUpdate. fprintf(stderr, "Failed to start '%s'.\n", coreParameter.fileToStart.c_str()); diff --git a/unittest/JitHarness.cpp b/unittest/JitHarness.cpp index 0cf90b668c..b7ab4137a5 100644 --- a/unittest/JitHarness.cpp +++ b/unittest/JitHarness.cpp @@ -100,7 +100,7 @@ static void SetupJitHarness() { RegisterHLEModule("UnitTestFakeSyscalls", ARRAY_SIZE(UnitTestFakeSyscalls), UnitTestFakeSyscalls); // This is pretty much the bare minimum required to setup jit. - coreState = CORE_POWERUP; + coreState = CORE_RUNNING_CPU; currentMIPS = &mipsr4k; g_symbolMap = new SymbolMap(); Memory::g_MemorySize = Memory::RAM_NORMAL_SIZE;