SaveState: Allow loading save state in exception.

And allow saving as well, since we can maybe resume.
This commit is contained in:
Unknown W. Brackets 2021-08-08 23:15:27 -07:00
parent eb8a239616
commit 32c7ff8436
3 changed files with 19 additions and 4 deletions

View file

@ -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;
}

View file

@ -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,

View file

@ -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;