diff --git a/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp b/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp index f0a1d2301..ddee0aa01 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp +++ b/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp @@ -1513,9 +1513,9 @@ void R4300iOp::SPECIAL_DIV (void) { _RegLO->DW = _GPR[m_Opcode.rs].W[0] / _GPR[m_Opcode.rt].W[0]; _RegHI->DW = _GPR[m_Opcode.rs].W[0] % _GPR[m_Opcode.rt].W[0]; } else { -#ifndef EXTERNAL_RELEASE - DisplayError("DIV by 0 ???"); -#endif + if (bShowDivByZero()) { DisplayError("DIV by 0 ???"); } + _RegLO->DW = 0; + _RegHI->DW = 0; } } @@ -1524,9 +1524,9 @@ void R4300iOp::SPECIAL_DIVU (void) { _RegLO->DW = (int)(_GPR[m_Opcode.rs].UW[0] / _GPR[m_Opcode.rt].UW[0]); _RegHI->DW = (int)(_GPR[m_Opcode.rs].UW[0] % _GPR[m_Opcode.rt].UW[0]); } else { -#ifndef EXTERNAL_RELEASE - DisplayError("DIVU by 0 ???"); -#endif + if (bShowDivByZero()) { DisplayError("DIVU by 0 ???"); } + _RegLO->DW = 0; + _RegHI->DW = 0; } } diff --git a/Source/Project64/N64 System/Recompiler/Code Section.cpp b/Source/Project64/N64 System/Recompiler/Code Section.cpp index 0308b5348..b43ef73e6 100644 --- a/Source/Project64/N64 System/Recompiler/Code Section.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Section.cpp @@ -290,6 +290,18 @@ void CCodeSection::CompileExit ( DWORD JumpPC, DWORD TargetPC, CRegInfo &ExitReg if (_SyncSystem) { Call_Direct(SyncSystem, "SyncSystem"); } ExitCodeBlock(); break; + case CExitInfo::DivByZero: + AddConstToVariable(4,_PROGRAM_COUNTER,"PROGRAM_COUNTER"); + if (!b32BitCore()) + { + MoveConstToVariable(0,&_RegHI->UW[1],"_RegHI->UW[1]"); + MoveConstToVariable(0,&_RegLO->UW[1],"_RegLO->UW[1]"); + } + MoveConstToVariable(0,&_RegHI->UW[0],"_RegHI->UW[0]"); + MoveConstToVariable(0,&_RegLO->UW[0],"_RegLO->UW[0]"); + if (_SyncSystem) { Call_Direct(SyncSystem, "SyncSystem"); } + ExitCodeBlock(); + break; default: DisplayError("how did you want to exit on reason (%d) ???",reason); } diff --git a/Source/Project64/N64 System/Recompiler/Exit Info.h b/Source/Project64/N64 System/Recompiler/Exit Info.h index f96ad376e..b9e69a4a0 100644 --- a/Source/Project64/N64 System/Recompiler/Exit Info.h +++ b/Source/Project64/N64 System/Recompiler/Exit Info.h @@ -10,7 +10,8 @@ public: DoSysCall = 4, TLBReadMiss = 5, TLBWriteMiss = 6, - ExitResetRecompCode = 7, + DivByZero = 7, + ExitResetRecompCode = 8, }; DWORD ID; diff --git a/Source/Project64/N64 System/Recompiler/Recompiler Ops.cpp b/Source/Project64/N64 System/Recompiler/Recompiler Ops.cpp index d48a312af..0a2b84534 100644 --- a/Source/Project64/N64 System/Recompiler/Recompiler Ops.cpp +++ b/Source/Project64/N64 System/Recompiler/Recompiler Ops.cpp @@ -2357,9 +2357,8 @@ void CRecompilerOps::SPECIAL_MULTU (void) { MoveX86regToVariable(x86_EDX,&_RegHI->UW[1],"_RegHI->UW[1]"); } -void CRecompilerOps::SPECIAL_DIV (void) { - BYTE *Jump[2]; - +void CRecompilerOps::SPECIAL_DIV (void) +{ CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(m_Opcode.Hex,m_CompilePC)); if (IsConst(m_Opcode.rt)) { @@ -2370,27 +2369,13 @@ void CRecompilerOps::SPECIAL_DIV (void) { MoveConstToVariable(0, &_RegHI->UW[1], "_RegHI->UW[1]"); return; } - Jump[1] = NULL; } else { if (IsMapped(m_Opcode.rt)) { CompConstToX86reg(cMipsRegMapLo(m_Opcode.rt),0); } else { CompConstToVariable(0, &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); } - JneLabel8("NoExcept", 0); - Jump[0] = m_RecompPos - 1; - - MoveConstToVariable(0, &_RegLO->UW[0], "_RegLO->UW[0]"); - MoveConstToVariable(0, &_RegLO->UW[1], "_RegLO->UW[1]"); - MoveConstToVariable(0, &_RegHI->UW[0], "_RegHI->UW[0]"); - MoveConstToVariable(0, &_RegHI->UW[1], "_RegHI->UW[1]"); - - JmpLabel8("EndDivu", 0); - Jump[1] = m_RecompPos - 1; - - CPU_Message(""); - CPU_Message(" NoExcept:"); - *((BYTE *)(Jump[0]))=(BYTE)(m_RecompPos - Jump[0] - 1); + m_Section->CompileExit(m_CompilePC, m_CompilePC,m_RegWorkingSet,CExitInfo::DivByZero,FALSE,JeLabel32); } /* lo = (SD)rs / (SD)rt; hi = (SD)rs % (SD)rt; */ @@ -2418,12 +2403,6 @@ void CRecompilerOps::SPECIAL_DIV (void) { ShiftRightSignImmed(x86_EDX,31); MoveX86regToVariable(x86_EAX,&_RegLO->UW[1],"_RegLO->UW[1]"); MoveX86regToVariable(x86_EDX,&_RegHI->UW[1],"_RegHI->UW[1]"); - - if( Jump[1] != NULL ) { - CPU_Message(""); - CPU_Message(" EndDivu:"); - *((BYTE *)(Jump[1]))=(BYTE)(m_RecompPos - Jump[1] - 1); - } } void CRecompilerOps::SPECIAL_DIVU ( void) { diff --git a/Source/Project64/Settings.h b/Source/Project64/Settings.h index 553d68a6a..cae608606 100644 --- a/Source/Project64/Settings.h +++ b/Source/Project64/Settings.h @@ -192,7 +192,7 @@ enum SettingID { Debugger_ShowTLBMisses, Debugger_ShowUnhandledMemory, Debugger_ShowPifErrors, - Debugger_ShowCheckOpUsageErrors, + Debugger_ShowDivByZero, Debugger_GenerateLogFiles, Debugger_ProfileCode, Debugger_DisableGameFixes, diff --git a/Source/Project64/Settings/Debug Settings.cpp b/Source/Project64/Settings/Debug Settings.cpp index b6e694841..f37d3eafa 100644 --- a/Source/Project64/Settings/Debug Settings.cpp +++ b/Source/Project64/Settings/Debug Settings.cpp @@ -5,6 +5,7 @@ int CDebugSettings::m_RefCount = 0; bool CDebugSettings::m_bHaveDebugger = false; bool CDebugSettings::m_bLogX86Code = false; bool CDebugSettings::m_bShowTLBMisses = false; +bool CDebugSettings::m_bShowDivByZero = false; CDebugSettings::CDebugSettings() { @@ -14,6 +15,7 @@ CDebugSettings::CDebugSettings() _Settings->RegisterChangeCB(Debugger_Enabled,this,(CSettings::SettingChangedFunc)StaticRefreshSettings); _Settings->RegisterChangeCB(Debugger_GenerateLogFiles,this,(CSettings::SettingChangedFunc)StaticRefreshSettings); _Settings->RegisterChangeCB(Debugger_ShowTLBMisses,this,(CSettings::SettingChangedFunc)StaticRefreshSettings); + _Settings->RegisterChangeCB(Debugger_ShowDivByZero,this,(CSettings::SettingChangedFunc)StaticRefreshSettings); RefreshSettings(); } @@ -27,12 +29,14 @@ CDebugSettings::~CDebugSettings() _Settings->UnregisterChangeCB(Debugger_Enabled,this,(CSettings::SettingChangedFunc)StaticRefreshSettings); _Settings->UnregisterChangeCB(Debugger_GenerateLogFiles,this,(CSettings::SettingChangedFunc)StaticRefreshSettings); _Settings->UnregisterChangeCB(Debugger_ShowTLBMisses,this,(CSettings::SettingChangedFunc)StaticRefreshSettings); + _Settings->UnregisterChangeCB(Debugger_ShowDivByZero,this,(CSettings::SettingChangedFunc)StaticRefreshSettings); } } void CDebugSettings::RefreshSettings() { m_bHaveDebugger = _Settings->LoadBool(Debugger_Enabled); - m_bLogX86Code = _Settings->LoadBool(Debugger_GenerateLogFiles); - m_bShowTLBMisses = _Settings->LoadBool(Debugger_ShowTLBMisses); + m_bLogX86Code = m_bHaveDebugger && _Settings->LoadBool(Debugger_GenerateLogFiles); + m_bShowTLBMisses = m_bHaveDebugger && _Settings->LoadBool(Debugger_ShowTLBMisses); + m_bShowDivByZero = m_bHaveDebugger && _Settings->LoadBool(Debugger_ShowDivByZero); } diff --git a/Source/Project64/Settings/Debug Settings.h b/Source/Project64/Settings/Debug Settings.h index 74ccabe6d..8f7d3fc1a 100644 --- a/Source/Project64/Settings/Debug Settings.h +++ b/Source/Project64/Settings/Debug Settings.h @@ -9,6 +9,7 @@ public: static inline bool bHaveDebugger ( void ) { return m_bHaveDebugger; } static inline bool bLogX86Code ( void ) { return m_bLogX86Code; } static inline bool bShowTLBMisses ( void ) { return m_bShowTLBMisses; } + static inline bool bShowDivByZero ( void ) { return m_bShowDivByZero; } private: static void StaticRefreshSettings (CDebugSettings * _this) @@ -22,6 +23,7 @@ private: static bool m_bHaveDebugger; static bool m_bLogX86Code; static bool m_bShowTLBMisses; + static bool m_bShowDivByZero; static int m_RefCount; }; \ No newline at end of file diff --git a/Source/Project64/Settings/Settings Class.cpp b/Source/Project64/Settings/Settings Class.cpp index e124ae69f..99f8cf8a9 100644 --- a/Source/Project64/Settings/Settings Class.cpp +++ b/Source/Project64/Settings/Settings Class.cpp @@ -254,7 +254,7 @@ void CSettings::AddHowToHandleSetting () AddHandler(Debugger_DisableGameFixes, new CSettingTypeApplication("Debugger","Disable Game Fixes",false)); AddHandler(Debugger_ShowDListAListCount, new CSettingTypeApplication("Debugger","Show Dlist Alist Count",false)); AddHandler(Debugger_ShowRecompMemSize, new CSettingTypeApplication("Debugger","Show Recompiler Memory size",false)); - AddHandler(Debugger_ShowCheckOpUsageErrors, new CSettingTypeApplication("Debugger","Show Check Op Usage Errors",false)); + AddHandler(Debugger_ShowDivByZero, new CSettingTypeApplication("Debugger","Show Div by zero",false)); AddHandler(Debugger_GenerateDebugLog, new CSettingTypeApplication("Debugger","Generate Debug Code",false)); AddHandler(Debugger_ProfileCode, new CSettingTypeApplication("Debugger","Profile Code", (DWORD)false)); AddHandler(Debugger_AppLogLevel, new CSettingTypeApplication("Logging","Log Level",(DWORD)TraceError)); diff --git a/Source/Project64/User Interface/Main Menu Class.cpp b/Source/Project64/User Interface/Main Menu Class.cpp index 8e3b70669..93de7c8a9 100644 --- a/Source/Project64/User Interface/Main Menu Class.cpp +++ b/Source/Project64/User Interface/Main Menu Class.cpp @@ -21,7 +21,7 @@ CMainMenu::CMainMenu ( CMainGui * hMainWindow ): m_ChangeSettingList.push_back(Debugger_ShowPifErrors); m_ChangeSettingList.push_back(Debugger_ShowDListAListCount); m_ChangeSettingList.push_back(Debugger_ShowRecompMemSize); - m_ChangeSettingList.push_back(Debugger_ShowCheckOpUsageErrors); + m_ChangeSettingList.push_back(Debugger_ShowDivByZero); m_ChangeSettingList.push_back(Debugger_GenerateLogFiles); m_ChangeSettingList.push_back(Debugger_DisableGameFixes); m_ChangeSettingList.push_back(Debugger_AppLogLevel); @@ -334,8 +334,8 @@ bool CMainMenu::ProcessMessage(WND_HANDLE hWnd, DWORD FromAccelerator, DWORD Men _Notify->DisplayMessage(0,""); _Settings->SaveBool(Debugger_ShowRecompMemSize,!_Settings->LoadBool(Debugger_ShowRecompMemSize)); break; - case ID_DEBUG_SHOW_CHECK_OPUSAGE: - _Settings->SaveBool(Debugger_ShowCheckOpUsageErrors,!_Settings->LoadBool(Debugger_ShowCheckOpUsageErrors)); + case ID_DEBUG_SHOW_DIV_BY_ZERO: + _Settings->SaveBool(Debugger_ShowDivByZero,!_Settings->LoadBool(Debugger_ShowDivByZero)); break; case ID_DEBUG_GENERATE_LOG_FILES: _Settings->SaveBool(Debugger_GenerateLogFiles,!_Settings->LoadBool(Debugger_GenerateLogFiles)); @@ -942,6 +942,7 @@ void CMainMenu::FillOutMenu ( MENU_HANDLE hMenu ) { MenuItemList DebugR4300Menu; MenuItemList DebugMemoryMenu; MenuItemList DebugInterrupt; + MenuItemList DebugNotificationMenu; if (bHaveDebugger()) { /* Debug - Interrupt *******************/ @@ -1069,6 +1070,24 @@ void CMainMenu::FillOutMenu ( MENU_HANDLE hMenu ) { DebugMenu.push_back(Item); } + /* Notification Menu + *******************/ + Item.Reset(ID_DEBUG_SHOW_UNHANDLED_MEM,EMPTY_STRING,EMPTY_STDSTR,NULL,"On Unhandled Memory Actions" ); + if (_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { + Item.ItemTicked = true; + } + DebugNotificationMenu.push_back(Item); + Item.Reset(ID_DEBUG_SHOW_PIF_ERRORS,EMPTY_STRING,EMPTY_STDSTR,NULL,"On PIF Errors" ); + if (_Settings->LoadBool(Debugger_ShowPifErrors)) { + Item.ItemTicked = true; + } + DebugNotificationMenu.push_back(Item); + Item.Reset(ID_DEBUG_SHOW_DIV_BY_ZERO,EMPTY_STRING,EMPTY_STDSTR,NULL,"On Div By Zero" ); + if (_Settings->LoadBool(Debugger_ShowDivByZero)) { + Item.ItemTicked = true; + } + DebugNotificationMenu.push_back(Item); + Item.Reset(SUB_MENU, EMPTY_STRING,EMPTY_STDSTR, &DebugR4300Menu,"&R4300i"); DebugMenu.push_back(Item); Item.Reset(SUB_MENU, EMPTY_STRING,EMPTY_STDSTR, &DebugMemoryMenu,"Memory"); @@ -1081,36 +1100,23 @@ void CMainMenu::FillOutMenu ( MENU_HANDLE hMenu ) { DebugMenu.push_back(Item); Item.Reset(SUB_MENU, EMPTY_STRING,EMPTY_STDSTR, &DebugLoggingMenu,"Logging"); DebugMenu.push_back(Item); + Item.Reset(SUB_MENU, EMPTY_STRING,EMPTY_STDSTR, &DebugNotificationMenu,"Notification"); + DebugMenu.push_back(Item); DebugMenu.push_back(MENU_ITEM(SPLITER)); Item.Reset(ID_DEBUG_SHOW_TLB_MISSES,EMPTY_STRING,EMPTY_STDSTR,NULL,"Show TLB Misses" ); if (_Settings->LoadBool(Debugger_ShowTLBMisses)) { Item.ItemTicked = true; } - Item.Reset(ID_DEBUG_SHOW_UNHANDLED_MEM,EMPTY_STRING,EMPTY_STDSTR,NULL,"Show Unhandled Memory Actions" ); - if (_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { - Item.ItemTicked = true; - } - DebugMenu.push_back(Item); - Item.Reset(ID_DEBUG_SHOW_PIF_ERRORS,EMPTY_STRING,EMPTY_STDSTR,NULL,"Show PIF Errors" ); - if (_Settings->LoadBool(Debugger_ShowPifErrors)) { - Item.ItemTicked = true; - } - DebugMenu.push_back(Item); - Item.Reset(ID_DEBUG_SHOW_DLIST_COUNT,EMPTY_STRING,EMPTY_STDSTR,NULL,"Show Alist/Dlist Counters" ); + Item.Reset(ID_DEBUG_SHOW_DLIST_COUNT,EMPTY_STRING,EMPTY_STDSTR,NULL,"Display Alist/Dlist Count" ); if (_Settings->LoadBool(Debugger_ShowDListAListCount)) { Item.ItemTicked = true; } DebugMenu.push_back(Item); - Item.Reset(ID_DEBUG_SHOW_RECOMP_MEM_SIZE,EMPTY_STRING,EMPTY_STDSTR,NULL,"Show Recompile Memory Buffer size" ); + Item.Reset(ID_DEBUG_SHOW_RECOMP_MEM_SIZE,EMPTY_STRING,EMPTY_STDSTR,NULL,"Display Recompiler Code Buffer Size" ); if (_Settings->LoadBool(Debugger_ShowRecompMemSize)) { Item.ItemTicked = true; } DebugMenu.push_back(Item); - Item.Reset(ID_DEBUG_SHOW_CHECK_OPUSAGE,EMPTY_STRING,EMPTY_STDSTR,NULL,"Show Check Opcode Usage Errors" ); - if (_Settings->LoadBool(Debugger_ShowCheckOpUsageErrors)) { - Item.ItemTicked = true; - } - DebugMenu.push_back(Item); DebugMenu.push_back(MENU_ITEM(SPLITER)); Item.Reset(ID_DEBUG_GENERATE_LOG_FILES,EMPTY_STRING,EMPTY_STDSTR,NULL,"Generate Log Files" ); if (_Settings->LoadBool(Debugger_GenerateLogFiles)) { diff --git a/Source/Project64/User Interface/Main Menu Class.h b/Source/Project64/User Interface/Main Menu Class.h index 0562af8e5..cc8db595d 100644 --- a/Source/Project64/User Interface/Main Menu Class.h +++ b/Source/Project64/User Interface/Main Menu Class.h @@ -30,7 +30,7 @@ enum MainMenuID { //Debugger Menu ID_DEBUG_SHOW_TLB_MISSES, ID_DEBUG_SHOW_UNHANDLED_MEM, ID_DEBUG_SHOW_PIF_ERRORS, - ID_DEBUG_SHOW_DLIST_COUNT, ID_DEBUG_SHOW_RECOMP_MEM_SIZE,ID_DEBUG_SHOW_CHECK_OPUSAGE, + ID_DEBUG_SHOW_DLIST_COUNT, ID_DEBUG_SHOW_RECOMP_MEM_SIZE,ID_DEBUG_SHOW_DIV_BY_ZERO, ID_DEBUG_GENERATE_LOG_FILES, ID_DEBUG_DISABLE_GAMEFIX, ID_DEBUGGER_LOGOPTIONS, ID_DEBUGGER_GENERATELOG, ID_DEBUGGER_DUMPMEMORY, ID_DEBUGGER_SEARCHMEMORY, ID_DEBUGGER_TLBENTRIES, ID_DEBUGGER_BREAKPOINTS, ID_DEBUGGER_MEMORY, ID_DEBUGGER_R4300REGISTERS,