From 24b30cc709a01d077c1c405a7fa9af5a0d7be4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 4 Apr 2025 15:49:17 +0200 Subject: [PATCH] Mostly remove coreState management from System.cpp --- Core/Core.cpp | 15 +++++++++++++++ Core/Core.h | 3 +-- Core/System.cpp | 32 ++------------------------------ UI/EmuScreen.cpp | 11 +++++++++++ headless/Headless.cpp | 1 + libretro/libretro.cpp | 1 + 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index b8cb71450e..4e8cb0c1ac 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -91,6 +91,21 @@ BreakReason Core_BreakReason() { return g_breakReason; } +const char *CoreStateToString(CoreState state) { + switch (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"; + default: return "N/A"; + } +} + const char *BreakReasonToString(BreakReason reason) { switch (reason) { case BreakReason::None: return "None"; diff --git a/Core/Core.h b/Core/Core.h index 643725ceac..2cd7484ec9 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -130,6 +130,7 @@ enum CoreState { // Running the GPU. When done, will switch over to RUNNING_CPU. CORE_RUNNING_GE, }; +const char *CoreStateToString(CoreState state); // Callback is called on the Emu thread. typedef void (* CoreLifecycleFunc)(CoreLifecycle stage); @@ -150,8 +151,6 @@ bool Core_GetPowerSaving(); void Core_RunLoopUntil(u64 globalticks); -const char *CoreStateToString(CoreState state); - extern volatile CoreState coreState; extern volatile bool coreStatePending; diff --git a/Core/System.cpp b/Core/System.cpp index ba7d498aee..26d1315654 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -436,7 +436,6 @@ static bool CPU_Init(FileLoader *fileLoader, IdentifiedFileType type, std::strin default: GetBootError(type, errorString); - coreState = CORE_BOOT_ERROR; g_CoreParameter.fileToStart.clear(); return false; } @@ -514,8 +513,6 @@ bool PSP_InitStart(const CoreParameter &coreParam) { return false; } - coreState = CORE_POWERUP; - g_bootState = BootState::Booting; GraphicsContext *temp = g_CoreParameter.graphicsContext; @@ -569,7 +566,6 @@ bool PSP_InitStart(const CoreParameter &coreParam) { // it gets written to from the loader thread that gets spawned. if (!CPU_Init(loadedFile, type, &g_CoreParameter.errorString)) { CPU_Shutdown(false); - coreState = CORE_BOOT_ERROR; g_CoreParameter.fileToStart.clear(); *error_string = g_CoreParameter.errorString; if (error_string->empty()) { @@ -579,13 +575,6 @@ bool PSP_InitStart(const CoreParameter &coreParam) { return; } - if (PSP_CoreParameter().startBreak) { - coreState = CORE_STEPPING_CPU; - System_Notify(SystemNotification::DEBUG_MODE_CHANGE); - } else { - coreState = CORE_RUNNING_CPU; - } - g_bootState = BootState::Complete; }); @@ -594,7 +583,7 @@ bool PSP_InitStart(const CoreParameter &coreParam) { BootState PSP_InitUpdate(std::string *error_string) { if (g_bootState == BootState::Booting || g_bootState == BootState::Off) { - // We're done already. + // Nothing to do right now. return g_bootState; } @@ -612,7 +601,6 @@ BootState PSP_InitUpdate(std::string *error_string) { } // Ok, async boot completed, let's finish up things on the main thread. - if (!gpu) { // should be! INFO_LOG(Log::System, "Starting graphics..."); Draw::DrawContext *draw = g_CoreParameter.graphicsContext ? g_CoreParameter.graphicsContext->GetDrawContext() : nullptr; @@ -664,8 +652,7 @@ void PSP_Shutdown(bool success) { return; } - if (coreState == CORE_RUNNING_CPU) - Core_Stop(); + Core_Stop(); if (g_Config.bFuncHashMap) { MIPSAnalyst::StoreHashMap(); @@ -836,21 +823,6 @@ bool CreateSysDirectories() { return true; } -const char *CoreStateToString(CoreState state) { - switch (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"; - default: return "N/A"; - } -} - const char *DumpFileTypeToString(DumpFileType type) { switch (type) { case DumpFileType::EBOOT: return "EBOOT"; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index b0c6d21dab..0801ef9768 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -264,6 +264,7 @@ 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: @@ -271,7 +272,16 @@ void EmuScreen::ProcessGameBoot(const Path &filename) { g_BackgroundAudio.SetGame(Path()); bootPending_ = false; errorMessage_.clear(); + + if (PSP_CoreParameter().startBreak) { + coreState = CORE_STEPPING_CPU; + System_Notify(SystemNotification::DEBUG_MODE_CHANGE); + } else { + coreState = CORE_RUNNING_CPU; + } + bootComplete(); + // Reset views in case controls are in a different place. RecreateViews(); return; @@ -332,6 +342,7 @@ 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()); diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 40b57e9877..2a7c51d192 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -185,6 +185,7 @@ 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/libretro/libretro.cpp b/libretro/libretro.cpp index d1fe05183d..d11c2809b7 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -1480,6 +1480,7 @@ bool retro_load_game(const struct retro_game_info *game) g_pendingBoot = true; std::string error_string; + coreState = CORE_POWERUP; if (!PSP_InitStart(coreParam)) { // Can't really fail, the errors happen later during InitUpdate ERROR_LOG(Log::Boot, "%s", error_string.c_str());