From 32c7ff84360a44124cb7c50920b26efe08c9965c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 8 Aug 2021 23:15:27 -0700 Subject: [PATCH] SaveState: Allow loading save state in exception. And allow saving as well, since we can maybe resume. --- Core/Core.cpp | 12 ++++++++---- Core/Core.h | 2 ++ Core/SaveState.cpp | 9 +++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 4a18bbb03e..b6af6456fd 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -86,7 +86,7 @@ void Core_ListenLifecycle(CoreLifecycleFunc func) { void Core_NotifyLifecycle(CoreLifecycle stage) { if (stage == CoreLifecycle::STARTING) { - g_exceptionInfo.type = ExceptionType::NONE; + Core_ResetException(); } for (auto func : lifecycleFuncs) { @@ -99,7 +99,7 @@ void Core_ListenStopRequest(CoreStopRequestFunc func) { } void Core_Stop() { - g_exceptionInfo.type = ExceptionType::NONE; + Core_ResetException(); Core_UpdateState(CORE_POWERDOWN); for (auto func : stopFuncs) { func(); @@ -267,7 +267,7 @@ void Core_UpdateSingleStep() { } void Core_SingleStep() { - g_exceptionInfo.type = ExceptionType::NONE; + Core_ResetException(); currentMIPS->SingleStep(); if (coreState == CORE_STEPPING) steppingCounter++; @@ -366,7 +366,7 @@ void Core_EnableStepping(bool step) { } else { host->SetDebugMode(false); // Clear the exception if we resume. - g_exceptionInfo.type = ExceptionType::NONE; + Core_ResetException(); coreState = CORE_RUNNING; coreStatePending = false; m_StepCond.notify_all(); @@ -489,6 +489,10 @@ void Core_Break() { } } +void Core_ResetException() { + g_exceptionInfo.type = ExceptionType::NONE; +} + const ExceptionInfo &Core_GetExceptionInfo() { return g_exceptionInfo; } diff --git a/Core/Core.h b/Core/Core.h index 21facdb735..a2acc66918 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -101,6 +101,8 @@ void Core_MemoryExceptionInfo(u32 address, u32 pc, MemoryExceptionType type, std void Core_ExecException(u32 address, u32 pc, ExecExceptionType type); void Core_Break(); +// Call when loading save states, etc. +void Core_ResetException(); enum class ExceptionType { NONE, diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index c133486442..b58325f9ca 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -335,11 +335,15 @@ namespace SaveState void Load(const Path &filename, int slot, Callback callback, void *cbUserData) { + if (coreState == CoreState::CORE_RUNTIME_ERROR) + Core_EnableStepping(true); Enqueue(Operation(SAVESTATE_LOAD, filename, slot, callback, cbUserData)); } void Save(const Path &filename, int slot, Callback callback, void *cbUserData) { + if (coreState == CoreState::CORE_RUNTIME_ERROR) + Core_EnableStepping(true); Enqueue(Operation(SAVESTATE_SAVE, filename, slot, callback, cbUserData)); } @@ -350,6 +354,8 @@ namespace SaveState void Rewind(Callback callback, void *cbUserData) { + if (coreState == CoreState::CORE_RUNTIME_ERROR) + Core_EnableStepping(true); Enqueue(Operation(SAVESTATE_REWIND, Path(), -1, callback, cbUserData)); } @@ -866,6 +872,7 @@ namespace SaveState callbackMessage = op.slot != LOAD_UNDO_SLOT ? sc->T("Loaded State") : sc->T("State load undone"); callbackResult = TriggerLoadWarnings(callbackMessage); hasLoadedState = true; + Core_ResetException(); if (!slot_prefix.empty()) callbackMessage = slot_prefix + callbackMessage; @@ -944,6 +951,7 @@ namespace SaveState callbackMessage = sc->T("Loaded State"); callbackResult = Status::SUCCESS; hasLoadedState = true; + Core_ResetException(); } else if (result == CChunkFileReader::ERROR_BROKEN_STATE) { // Cripes. Good news is, we might have more. Let's try those too, better than a reset. if (HandleLoadFailure()) { @@ -951,6 +959,7 @@ namespace SaveState callbackMessage = sc->T("Loaded State"); callbackResult = Status::SUCCESS; hasLoadedState = true; + Core_ResetException(); } else { callbackMessage = std::string(i18nLoadFailure) + ": " + errorString; callbackResult = Status::FAILURE;