From b987a1693cf557bd6b38c4ee7bab228b05a9f8b3 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 1 Aug 2022 10:59:16 +0930 Subject: [PATCH] Core: Do not end emulation by default on perm loop --- Source/Android/Bridge/jniBridgeSettings.cpp | 1 + .../N64System/Interpreter/InterpreterCPU.cpp | 20 +++++++------------ Source/Project64-core/Settings.cpp | 1 + .../Project64-core/Settings/DebugSettings.cpp | 4 ++++ .../Project64-core/Settings/DebugSettings.h | 2 ++ Source/Project64-core/Settings/SettingsID.h | 1 + Source/Project64/UserInterface/MainMenu.cpp | 10 ++++++++++ Source/Project64/UserInterface/MainMenu.h | 1 + 8 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Source/Android/Bridge/jniBridgeSettings.cpp b/Source/Android/Bridge/jniBridgeSettings.cpp index 33744d881..7cde86084 100644 --- a/Source/Android/Bridge/jniBridgeSettings.cpp +++ b/Source/Android/Bridge/jniBridgeSettings.cpp @@ -245,6 +245,7 @@ CJniBridegSettings::CJniBridegSettings() // Debugger ADD_SETTING(Debugger_Enabled); + ADD_SETTING(Debugger_EndOnPermLoop); ADD_SETTING(Debugger_BreakOnUnhandledMemory); ADD_SETTING(Debugger_BreakOnAddressError); ADD_SETTING(Debugger_ShowPifErrors); diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterCPU.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterCPU.cpp index b2a9c8923..68d385bea 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterCPU.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterCPU.cpp @@ -34,30 +34,24 @@ void CInterpreterCPU::BuildCPU() void CInterpreterCPU::InPermLoop() { - // Interrupts enabled - if ((g_Reg->STATUS_REGISTER & STATUS_IE) == 0 || + if (EndOnPermLoop() && + ((g_Reg->STATUS_REGISTER & STATUS_IE) == 0 || (g_Reg->STATUS_REGISTER & STATUS_EXL) != 0 || (g_Reg->STATUS_REGISTER & STATUS_ERL) != 0 || - (g_Reg->STATUS_REGISTER & 0xFF00) == 0) + (g_Reg->STATUS_REGISTER & 0xFF00) == 0)) { if (g_Plugins->Gfx()->UpdateScreen != nullptr) { g_Plugins->Gfx()->UpdateScreen(); } - //CurrentFrame = 0; - //CurrentPercent = 0; - //DisplayFPS(); g_Notify->DisplayError(GS(MSG_PERM_LOOP)); g_System->CloseCpu(); } - else + else if (*g_NextTimer > 0) { - if (*g_NextTimer > 0) - { - g_SystemTimer->UpdateTimers(); - *g_NextTimer = 0 - g_System->CountPerOp(); - g_SystemTimer->UpdateTimers(); - } + g_SystemTimer->UpdateTimers(); + *g_NextTimer = 0 - g_System->CountPerOp(); + g_SystemTimer->UpdateTimers(); } } diff --git a/Source/Project64-core/Settings.cpp b/Source/Project64-core/Settings.cpp index 222e23155..8222516ec 100644 --- a/Source/Project64-core/Settings.cpp +++ b/Source/Project64-core/Settings.cpp @@ -319,6 +319,7 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(File_DiskIPLTOOLPath, new CSettingTypeApplicationPath("Settings", "Disk IPL TOOL ROM Path", Default_None)); AddHandler(Debugger_Enabled, new CSettingTypeApplication("Debugger", "Debugger", false)); + AddHandler(Debugger_EndOnPermLoop, new CSettingTypeApplication("Debugger", "End On Perm Loop", false)); AddHandler(Debugger_BreakOnUnhandledMemory, new CSettingTypeApplication("Debugger", "Break On Unhandled Memory", false)); AddHandler(Debugger_BreakOnAddressError, new CSettingTypeApplication("Debugger", "Break On Address Error", false)); AddHandler(Debugger_ShowPifErrors, new CSettingTypeApplication("Debugger", "Show Pif Errors", false)); diff --git a/Source/Project64-core/Settings/DebugSettings.cpp b/Source/Project64-core/Settings/DebugSettings.cpp index 1e332c9b1..8823d3660 100644 --- a/Source/Project64-core/Settings/DebugSettings.cpp +++ b/Source/Project64-core/Settings/DebugSettings.cpp @@ -23,6 +23,7 @@ uint32_t CDebugSettings::m_ExceptionBreakpoints = 0; uint32_t CDebugSettings::m_FpExceptionBreakpoints = 0; uint32_t CDebugSettings::m_IntrBreakpoints = 0; uint32_t CDebugSettings::m_RcpIntrBreakpoints = 0; +bool CDebugSettings::m_EndOnPermLoop = false; bool CDebugSettings::m_BreakOnUnhandledMemory = false; bool CDebugSettings::m_BreakOnAddressError = false; @@ -48,6 +49,7 @@ CDebugSettings::CDebugSettings() g_Settings->RegisterChangeCB(Debugger_FpExceptionBreakpoints, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); g_Settings->RegisterChangeCB(Debugger_IntrBreakpoints, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); g_Settings->RegisterChangeCB(Debugger_RcpIntrBreakpoints, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); + g_Settings->RegisterChangeCB(Debugger_EndOnPermLoop, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); g_Settings->RegisterChangeCB(Debugger_BreakOnUnhandledMemory, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); g_Settings->RegisterChangeCB(Debugger_BreakOnAddressError, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); @@ -75,6 +77,7 @@ CDebugSettings::~CDebugSettings() g_Settings->UnregisterChangeCB(Debugger_FpExceptionBreakpoints, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); g_Settings->UnregisterChangeCB(Debugger_IntrBreakpoints, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); g_Settings->UnregisterChangeCB(Debugger_RcpIntrBreakpoints, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); + g_Settings->UnregisterChangeCB(Debugger_EndOnPermLoop, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); g_Settings->UnregisterChangeCB(Debugger_BreakOnUnhandledMemory, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); g_Settings->UnregisterChangeCB(Debugger_BreakOnAddressError, this, (CSettings::SettingChangedFunc)StaticRefreshSettings); } @@ -98,6 +101,7 @@ void CDebugSettings::RefreshSettings() m_FpExceptionBreakpoints = m_HaveDebugger ? g_Settings->LoadDword(Debugger_FpExceptionBreakpoints) : 0; m_IntrBreakpoints = m_HaveDebugger ? g_Settings->LoadDword(Debugger_IntrBreakpoints) : 0; m_RcpIntrBreakpoints = m_HaveDebugger ? g_Settings->LoadDword(Debugger_RcpIntrBreakpoints) : 0; + m_EndOnPermLoop = m_HaveDebugger && g_Settings->LoadBool(Debugger_EndOnPermLoop); m_BreakOnUnhandledMemory = m_HaveDebugger && g_Settings->LoadBool(Debugger_BreakOnUnhandledMemory); m_BreakOnAddressError = m_HaveDebugger && g_Settings->LoadBool(Debugger_BreakOnAddressError); diff --git a/Source/Project64-core/Settings/DebugSettings.h b/Source/Project64-core/Settings/DebugSettings.h index 12bc80712..3f0b689cb 100644 --- a/Source/Project64-core/Settings/DebugSettings.h +++ b/Source/Project64-core/Settings/DebugSettings.h @@ -26,6 +26,7 @@ public: static inline uint32_t FpExceptionBreakpoints(void) { return m_FpExceptionBreakpoints; } static inline uint32_t IntrBreakpoints(void) { return m_IntrBreakpoints; } static inline uint32_t RcpIntrBreakpoints(void) { return m_RcpIntrBreakpoints; } + static inline bool EndOnPermLoop(void) { return m_EndOnPermLoop; } static inline bool BreakOnUnhandledMemory(void) { return m_BreakOnUnhandledMemory; } static inline bool BreakOnAddressError(void) { return m_BreakOnAddressError; } @@ -55,6 +56,7 @@ private: static uint32_t m_FpExceptionBreakpoints; static uint32_t m_IntrBreakpoints; static uint32_t m_RcpIntrBreakpoints; + static bool m_EndOnPermLoop; static bool m_BreakOnUnhandledMemory; static bool m_BreakOnAddressError; diff --git a/Source/Project64-core/Settings/SettingsID.h b/Source/Project64-core/Settings/SettingsID.h index 683201f56..4f6716439 100644 --- a/Source/Project64-core/Settings/SettingsID.h +++ b/Source/Project64-core/Settings/SettingsID.h @@ -236,6 +236,7 @@ enum SettingID // Debugger Debugger_Enabled, + Debugger_EndOnPermLoop, Debugger_BreakOnUnhandledMemory, Debugger_BreakOnAddressError, Debugger_ShowPifErrors, diff --git a/Source/Project64/UserInterface/MainMenu.cpp b/Source/Project64/UserInterface/MainMenu.cpp index f1a1f5b84..2a85c5eac 100644 --- a/Source/Project64/UserInterface/MainMenu.cpp +++ b/Source/Project64/UserInterface/MainMenu.cpp @@ -24,6 +24,7 @@ CMainMenu::CMainMenu(CMainGui * hMainWindow) : m_ChangeSettingList.push_back(UserInterface_ShowCPUPer); m_ChangeSettingList.push_back(Logging_GenerateLog); m_ChangeSettingList.push_back(Debugger_RecordExecutionTimes); + m_ChangeSettingList.push_back(Debugger_EndOnPermLoop); m_ChangeSettingList.push_back(Debugger_BreakOnUnhandledMemory); m_ChangeSettingList.push_back(Debugger_BreakOnAddressError); m_ChangeSettingList.push_back(Debugger_ShowPifErrors); @@ -497,6 +498,9 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI break; case ID_PROFILE_RESETCOUNTER: g_BaseSystem->ExternalEvent(SysEvent_ResetFunctionTimes); break; case ID_PROFILE_GENERATELOG: g_BaseSystem->ExternalEvent(SysEvent_DumpFunctionTimes); break; + case ID_DEBUG_END_ON_PERM_LOOP: + g_Settings->SaveBool(Debugger_EndOnPermLoop, !g_Settings->LoadBool(Debugger_EndOnPermLoop)); + break; case ID_DEBUG_BREAK_ON_UNHANDLED_MEM: g_Settings->SaveBool(Debugger_BreakOnUnhandledMemory, !g_Settings->LoadBool(Debugger_BreakOnUnhandledMemory)); break; @@ -1221,6 +1225,12 @@ void CMainMenu::FillOutMenu(HMENU hMenu) } // Notification menu + Item.Reset(ID_DEBUG_END_ON_PERM_LOOP, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"End on perm loop"); + if (g_Settings->LoadBool(Debugger_EndOnPermLoop)) + { + Item.SetItemTicked(true); + } + DebugNotificationMenu.push_back(Item); Item.Reset(ID_DEBUG_BREAK_ON_UNHANDLED_MEM, EMPTY_STRING, EMPTY_STDSTR, nullptr, L"Break on unhandled memory actions"); if (g_Settings->LoadBool(Debugger_BreakOnUnhandledMemory)) { diff --git a/Source/Project64/UserInterface/MainMenu.h b/Source/Project64/UserInterface/MainMenu.h index d75cdfdd6..b7e7606c6 100644 --- a/Source/Project64/UserInterface/MainMenu.h +++ b/Source/Project64/UserInterface/MainMenu.h @@ -33,6 +33,7 @@ enum MainMenuID ID_OPTIONS_DECREASE_SPEED, // Debugger menu + ID_DEBUG_END_ON_PERM_LOOP, ID_DEBUG_BREAK_ON_UNHANDLED_MEM, ID_DEBUG_BREAK_ON_ADDRESS_ERROR, ID_DEBUG_SHOW_PIF_ERRORS, ID_DEBUG_SHOW_DLIST_COUNT, ID_DEBUG_SHOW_RECOMP_MEM_SIZE, ID_DEBUG_SHOW_DIV_BY_ZERO, ID_DEBUG_RECORD_RECOMPILER_ASM, ID_DEBUG_DISABLE_GAMEFIX, ID_DEBUG_LANGUAGE,