Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reset button on crash screen, allow load state and related #14708

Merged
merged 4 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ void Core_ListenLifecycle(CoreLifecycleFunc func) {
}

void Core_NotifyLifecycle(CoreLifecycle stage) {
if (stage == CoreLifecycle::STARTING) {
Core_ResetException();
}

for (auto func : lifecycleFuncs) {
func(stage);
}
Expand All @@ -95,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();
Expand Down Expand Up @@ -263,7 +267,7 @@ void Core_UpdateSingleStep() {
}

void Core_SingleStep() {
g_exceptionInfo.type = ExceptionType::NONE;
Core_ResetException();
currentMIPS->SingleStep();
if (coreState == CORE_STEPPING)
steppingCounter++;
Expand Down Expand Up @@ -362,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();
Expand Down Expand Up @@ -485,6 +489,10 @@ void Core_Break() {
}
}

void Core_ResetException() {
g_exceptionInfo.type = ExceptionType::NONE;
}

const ExceptionInfo &Core_GetExceptionInfo() {
return g_exceptionInfo;
}
2 changes: 2 additions & 0 deletions Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions Core/SaveState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -944,13 +951,15 @@ 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()) {
// Well, we did rewind, even if too much...
callbackMessage = sc->T("Loaded State");
callbackResult = Status::SUCCESS;
hasLoadedState = true;
Core_ResetException();
} else {
callbackMessage = std::string(i18nLoadFailure) + ": " + errorString;
callbackResult = Status::FAILURE;
Expand Down
1 change: 1 addition & 0 deletions Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void UpdateUIState(GlobalUIState newState) {
case UISTATE_INGAME: state = "ingame"; break;
case UISTATE_MENU: state = "menu"; break;
case UISTATE_PAUSEMENU: state = "pausemenu"; break;
case UISTATE_EXCEPTION: state = "exception"; break;
}
if (state) {
System_SendMessage("uistate", state);
Expand Down
1 change: 1 addition & 0 deletions Core/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum GlobalUIState {
UISTATE_PAUSEMENU,
UISTATE_INGAME,
UISTATE_EXIT,
UISTATE_EXCEPTION,
};

// Use these in conjunction with GetSysDirectory.
Expand Down
23 changes: 20 additions & 3 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,19 @@ void EmuScreen::CreateViews() {
if (g_Config.bShowDeveloperMenu) {
root_->Add(new Button(dev->T("DevMenu")))->OnClick.Handle(this, &EmuScreen::OnDevTools);
}
resumeButton_ = root_->Add(new Button(dev->T("Resume"), new AnchorLayoutParams(bounds.centerX(), NONE, NONE, 60, true)));

LinearLayout *buttons = new LinearLayout(Orientation::ORIENT_HORIZONTAL, new AnchorLayoutParams(bounds.centerX(), NONE, NONE, 60, true));
buttons->SetSpacing(20.0f);
root_->Add(buttons);

resumeButton_ = buttons->Add(new Button(dev->T("Resume")));
resumeButton_->OnClick.Handle(this, &EmuScreen::OnResume);
resumeButton_->SetVisibility(V_GONE);

resetButton_ = buttons->Add(new Button(dev->T("Reset")));
resetButton_->OnClick.Handle(this, &EmuScreen::OnReset);
resetButton_->SetVisibility(V_GONE);

cardboardDisableButton_ = root_->Add(new Button(sc->T("Cardboard VR OFF"), new AnchorLayoutParams(bounds.centerX(), NONE, NONE, 30, true)));
cardboardDisableButton_->OnClick.Handle(this, &EmuScreen::OnDisableCardboard);
cardboardDisableButton_->SetVisibility(V_GONE);
Expand Down Expand Up @@ -914,12 +923,20 @@ UI::EventReturn EmuScreen::OnResume(UI::EventParams &params) {
return UI::EVENT_DONE;
}

UI::EventReturn EmuScreen::OnReset(UI::EventParams &params) {
if (coreState == CoreState::CORE_RUNTIME_ERROR) {
NativeMessageReceived("reset", "");
}
return UI::EVENT_DONE;
}

void EmuScreen::update() {
using namespace UI;

UIScreen::update();
onScreenMessagesView_->SetVisibility(g_Config.bShowOnScreenMessages ? V_VISIBLE : V_GONE);
resumeButton_->SetVisibility(coreState == CoreState::CORE_RUNTIME_ERROR && Memory::MemFault_MayBeResumable() ? V_VISIBLE : V_GONE);
resetButton_->SetVisibility(coreState == CoreState::CORE_RUNTIME_ERROR ? V_VISIBLE : V_GONE);

if (bootPending_) {
bootGame(gamePath_);
Expand All @@ -935,8 +952,8 @@ void EmuScreen::update() {
PSP_CoreParameter().pixelHeight = pixel_yres * bounds.h / dp_yres;
#endif

if (!invalid_ && coreState != CORE_RUNTIME_ERROR) {
UpdateUIState(UISTATE_INGAME);
if (!invalid_) {
UpdateUIState(coreState != CORE_RUNTIME_ERROR ? UISTATE_INGAME : UISTATE_EXCEPTION);
}

if (errorMessage_.size()) {
Expand Down
2 changes: 2 additions & 0 deletions UI/EmuScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class EmuScreen : public UIScreen {
UI::EventReturn OnDisableCardboard(UI::EventParams &params);
UI::EventReturn OnChat(UI::EventParams &params);
UI::EventReturn OnResume(UI::EventParams &params);
UI::EventReturn OnReset(UI::EventParams &params);

void bootGame(const Path &filename);
bool bootAllowStorage(const Path &filename);
Expand Down Expand Up @@ -98,6 +99,7 @@ class EmuScreen : public UIScreen {
UI::Spinner *loadingSpinner_ = nullptr;
UI::TextView *loadingTextView_ = nullptr;
UI::Button *resumeButton_ = nullptr;
UI::Button *resetButton_ = nullptr;
UI::View *chatButton_ = nullptr;

UI::Button *cardboardDisableButton_ = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions Windows/Debugger/Debugger_Disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,10 @@ void CDisasm::SavePosition()
void CDisasm::SetDebugMode(bool _bDebug, bool switchPC)
{
HWND hDlg = m_hDlg;
bool ingame = (GetUIState() == UISTATE_INGAME || GetUIState() == UISTATE_EXCEPTION) && PSP_IsInited();

// Update Dialog Windows
if (_bDebug && GetUIState() == UISTATE_INGAME && PSP_IsInited())
if (_bDebug && ingame)
{
Core_WaitInactive(TEMP_BREAKPOINT_WAIT_MS);
breakpointList->reloadBreakpoints();
Expand Down Expand Up @@ -827,7 +828,7 @@ void CDisasm::SetDebugMode(bool _bDebug, bool switchPC)
{
updateThreadLabel(true);

if (GetUIState() == UISTATE_INGAME && PSP_IsInited())
if (ingame)
{
SetDlgItemText(m_hDlg, IDC_STOPGO, L"Break");
EnableWindow(GetDlgItem(hDlg, IDC_STOPGO), TRUE);
Expand Down
7 changes: 4 additions & 3 deletions Windows/MainWindowMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ namespace MainWindow {
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

void SetIngameMenuItemStates(HMENU menu, const GlobalUIState state) {
UINT menuEnable = state == UISTATE_INGAME ? MF_ENABLED : MF_GRAYED;
UINT menuEnable = state == UISTATE_INGAME || state == UISTATE_EXCEPTION ? MF_ENABLED : MF_GRAYED;
UINT menuInGameEnable = state == UISTATE_INGAME ? MF_ENABLED : MF_GRAYED;
UINT umdSwitchEnable = state == UISTATE_INGAME && getUMDReplacePermit() ? MF_ENABLED : MF_GRAYED;

EnableMenuItem(menu, ID_FILE_SAVESTATEFILE, menuEnable);
Expand All @@ -86,7 +87,7 @@ namespace MainWindow {
EnableMenuItem(menu, ID_DEBUG_SAVESYMFILE, menuEnable);
EnableMenuItem(menu, ID_DEBUG_RESETSYMBOLTABLE, menuEnable);
EnableMenuItem(menu, ID_DEBUG_TAKESCREENSHOT, menuEnable);
EnableMenuItem(menu, ID_DEBUG_SHOWDEBUGSTATISTICS, menuEnable);
EnableMenuItem(menu, ID_DEBUG_SHOWDEBUGSTATISTICS, menuInGameEnable);
EnableMenuItem(menu, ID_DEBUG_EXTRACTFILE, menuEnable);

// While playing, this pop up doesn't work - and probably doesn't make sense.
Expand Down Expand Up @@ -394,7 +395,7 @@ namespace MainWindow {
Core_EnableStepping(false);
}
} else {
if (GetUIState() == UISTATE_INGAME || GetUIState() == UISTATE_PAUSEMENU) {
if (GetUIState() == UISTATE_INGAME || GetUIState() == UISTATE_EXCEPTION || GetUIState() == UISTATE_PAUSEMENU) {
Core_EnableStepping(false);
}

Expand Down