diff --git a/Lang/Japanese.pj.Lang b/Lang/Japanese.pj.Lang index da0bd4885..779b3c9b8 100644 --- a/Lang/Japanese.pj.Lang +++ b/Lang/Japanese.pj.Lang @@ -177,7 +177,7 @@ #320# "ロムディレクトリを選択して下さい" //Messages -#340# "不明なロム? GoodN64を使用するかINIファイルをアップデートして下さい" +#340# "不明なロム? GoodN64を使用するかRDBファイルをアップデートして下さい" /********************************************************************************* * Options * @@ -233,9 +233,9 @@ #466# "表示形式によってフレームレートを変更する:" //ROM Browser Tab -#480# "最近開いたロムファイルの表示する数(最大10):" +#480# "最近開いたロムファイルの表示する数(0~10):" #481# "個" -#482# "最近開いたロムフォルダの表示する数(最大10):" +#482# "最近開いたロムフォルダの表示する数(0~10):" #483# "個" #484# "ロムブラウザを使用する(&U)" #485# "サブフォルダも検索(&S)" @@ -282,6 +282,9 @@ #534# "関数検索方法:" #535# "カスタム自己書換方法" #536# "オーディオに同期" +#537# "AIカウント/バイト" +#538# "32bitエンジン" +#539# "DP割り込み遅延" //Core Styles #540# "インタプリタ" @@ -348,6 +351,11 @@ #710# "スピードを上げる" #711# "スピードを下げる" +//Bottom page buttons +#720# "この項目のリセット" +#721# "すべてリセット" +#722# "適用" + /********************************************************************************* * ROM Information * *********************************************************************************/ @@ -359,7 +367,7 @@ #802# "ファイル名:" #803# "保存場所:" #804# "ロムサイズ:" -#805# "カートリッジID:" +#805# "カートリッジID:" #806# "製造元:" #807# "国情報:" #808# "CRC1:" diff --git a/Source/Project64/Multilanguage/Language Class.cpp b/Source/Project64/Multilanguage/Language Class.cpp index 5f093b445..1121f8766 100644 --- a/Source/Project64/Multilanguage/Language Class.cpp +++ b/Source/Project64/Multilanguage/Language Class.cpp @@ -535,7 +535,10 @@ void CLanguage::LoadCurrentStrings ( bool ShowSelectDialog ) //Process the file FILE *file = fopen(Filename.c_str(), "rb"); - if (file == NULL) { return; } + if (file == NULL) + { + return; + } //Search for utf8 file marker BYTE utf_bom[3]; @@ -549,7 +552,7 @@ void CLanguage::LoadCurrentStrings ( bool ShowSelectDialog ) } //String; - while(!feof(file)) + while (!feof(file)) { m_CurrentStrings.insert(GetNextLangString(file)); } @@ -564,7 +567,8 @@ DWORD CALLBACK LangSelectOkProc (HWND hWnd, DWORD uMsg, DWORD wParam, DWORD lPar static bool m_fPressed = false; static HBITMAP hOkButtonDown = NULL; - switch (uMsg) { + switch (uMsg) + { case WM_PAINT: { PAINTSTRUCT ps; @@ -590,7 +594,9 @@ DWORD CALLBACK LangSelectOkProc (HWND hWnd, DWORD uMsg, DWORD wParam, DWORD lPar SelectObject(memdc, save); DeleteDC(memdc); } - } else { + } + else + { if (hOkButton) { RECT rcClient; @@ -610,14 +616,14 @@ DWORD CALLBACK LangSelectOkProc (HWND hWnd, DWORD uMsg, DWORD wParam, DWORD lPar } break; case WM_MOUSEMOVE: - if(::GetCapture() == hWnd) + if (::GetCapture() == hWnd) { POINT ptCursor = { ((int)(short)LOWORD(lParam)), ((int)(short)HIWORD(lParam)) }; ClientToScreen(hWnd, &ptCursor); RECT rect; GetWindowRect(hWnd, &rect); bool uPressed = ::PtInRect(&rect, ptCursor)==TRUE; - if( m_fPressed != uPressed ) + if ( m_fPressed != uPressed ) { m_fPressed = uPressed; ::InvalidateRect(hWnd, NULL, TRUE); @@ -630,7 +636,7 @@ DWORD CALLBACK LangSelectOkProc (HWND hWnd, DWORD uMsg, DWORD wParam, DWORD lPar LRESULT lRet = 0; lRet = DefWindowProc(hWnd, uMsg, wParam, lParam); SetCapture(hWnd); - if( ::GetCapture()==hWnd ) + if ( ::GetCapture()==hWnd ) { m_fPressed = true; @@ -647,10 +653,10 @@ DWORD CALLBACK LangSelectOkProc (HWND hWnd, DWORD uMsg, DWORD wParam, DWORD lPar { LRESULT lRet = 0; lRet = DefWindowProc(hWnd, uMsg, wParam, lParam); - if(::GetCapture() == hWnd ) + if ( ::GetCapture() == hWnd ) { ::ReleaseCapture(); - if( m_fPressed ) + if ( m_fPressed ) { ::SendMessage(GetParent(hWnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hWnd), BN_CLICKED), (LPARAM)hWnd); } @@ -673,14 +679,18 @@ LRESULT CALLBACK LangSelectProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPa static HFONT hTextFont = NULL; static CLanguage * lngClass; - switch (uMsg) { + switch (uMsg) + { case WM_INITDIALOG: SetWindowPos(hDlg,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE); { lngClass = (CLanguage *)lParam; LanguageList LangList = lngClass->GetLangList(); - if (LangList.size() == 0) { EndDialog(hDlg,0); } + if (LangList.size() == 0) + { + EndDialog(hDlg,0); + } for (LanguageList::iterator Language = LangList.begin(); Language != LangList.end(); Language++) { int index = SendMessageW(GetDlgItem(hDlg,IDC_LANG_SEL),CB_ADDSTRING,0,(WPARAM)Language->LanguageName.c_str()); @@ -689,11 +699,12 @@ LRESULT CALLBACK LangSelectProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPa SendMessage(GetDlgItem(hDlg,IDC_LANG_SEL),CB_SETCURSEL,index,0); } } - int Index = SendMessage(GetDlgItem(hDlg,IDC_LANG_SEL),CB_GETCURSEL,0,0); - if (Index < 0) { SendMessage(GetDlgItem(hDlg,IDC_LANG_SEL),CB_SETCURSEL,0,0); } - + if (Index < 0) + { + SendMessage(GetDlgItem(hDlg,IDC_LANG_SEL),CB_SETCURSEL,0,0); + } enum { ROUND_EDGE = 15 }; @@ -842,7 +853,8 @@ LRESULT CALLBACK LangSelectProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPa } break; case WM_COMMAND: - switch (LOWORD(wParam)) { + switch (LOWORD(wParam)) + { case IDOK: if (hbmpBackgroundTop) { @@ -934,7 +946,10 @@ const std::wstring & CLanguage::GetString (LanguageStringID StringID) std::wstring CLanguage::GetLangString ( const char * FileName, LanguageStringID ID ) { FILE *file = fopen(FileName, "rb"); - if (file == NULL) { return L""; } + if (file == NULL) + { + return L""; + } //Search for utf8 file marker BYTE utf_bom[3]; @@ -947,7 +962,7 @@ std::wstring CLanguage::GetLangString ( const char * FileName, LanguageStringID } //String; - while(!feof(file)) + while (!feof(file)) { LANG_STR String = GetNextLangString(file); if (String.first == ID) @@ -969,31 +984,55 @@ LANG_STR CLanguage::GetNextLangString (void * OpenFile) FILE * file = (FILE *)OpenFile; //while(token!='#' && !feof(file)) { fread(&token, 1, 1, file); } - if(feof(file)){ return LANG_STR(0,L""); } + if (feof(file)) + { + return LANG_STR(0,L""); + } //Search for token # char token=0; - while(token!='#' && !feof(file)) { fread(&token, 1, 1, file); } - if(feof(file)){ return LANG_STR(0,L""); } + while (token!='#' && !feof(file)) + { + fread(&token, 1, 1, file); + } + if (feof(file)) + { + return LANG_STR(0,L""); + } //get StringID after token fscanf(file, "%d", &StringID); //Search for token # - while(token!='#' && !feof(file)) { fread(&token, 1, 1, file); } - if(feof(file)){ StringID = EMPTY_STRING; return LANG_STR(0,L""); } + while(token!='#' && !feof(file)) + { + fread(&token, 1, 1, file); + } + if (feof(file)) + { + StringID = EMPTY_STRING; return LANG_STR(0,L""); + } //Search for start of string '"' - while(token!='"' && !feof(file)) { fread(&token, 1, 1, file); } - if(feof(file)){ StringID = EMPTY_STRING; return LANG_STR(0,L""); } + while (token!='"' && !feof(file)) + { + fread(&token, 1, 1, file); + } + if (feof(file)) + { + StringID = EMPTY_STRING; return LANG_STR(0,L""); + } int pos = 0; fread(&token, 1, 1, file); - while(token!='"' && !feof(file)) + while (token!='"' && !feof(file)) { szString[pos++] = token; fread(&token, 1, 1, file); - if (pos == MAX_STRING_LEN - 2) { token = '"'; } + if (pos == MAX_STRING_LEN - 2) + { + token = '"'; + } } szString[pos++] = 0; stdstr text(szString); diff --git a/Source/Project64/Multilanguage/Language Class.h b/Source/Project64/Multilanguage/Language Class.h index 84af4f2b1..f8b402002 100644 --- a/Source/Project64/Multilanguage/Language Class.h +++ b/Source/Project64/Multilanguage/Language Class.h @@ -20,7 +20,8 @@ typedef std::map > LANG_STRINGS; typedef LANG_STRINGS::value_type LANG_STR; -typedef struct { +typedef struct +{ stdstr Filename; std::wstring LanguageName; } LanguageFile; diff --git a/Source/Project64/N64 System/C Core/Logging.cpp b/Source/Project64/N64 System/C Core/Logging.cpp index 717e76f02..bc9dacb18 100644 --- a/Source/Project64/N64 System/C Core/Logging.cpp +++ b/Source/Project64/N64 System/C Core/Logging.cpp @@ -20,7 +20,8 @@ LRESULT CALLBACK LogRegProc ( HWND, UINT, WPARAM, LPARAM ); LOG_OPTIONS LogOptions,TempOptions; HANDLE hLogFile = NULL; -void EnterLogOptions(HWND hwndOwner) { +void EnterLogOptions(HWND hwndOwner) +{ PROPSHEETPAGE psp[3]; PROPSHEETHEADER psh; @@ -68,7 +69,8 @@ void EnterLogOptions(HWND hwndOwner) { return; } -void LoadLogOptions (LOG_OPTIONS * LogOptions, BOOL AlwaysFill) { +void LoadLogOptions (LOG_OPTIONS * LogOptions, BOOL AlwaysFill) +{ long lResult; HKEY hKeyResults = 0; char String[200]; @@ -77,9 +79,11 @@ void LoadLogOptions (LOG_OPTIONS * LogOptions, BOOL AlwaysFill) { lResult = RegOpenKeyEx( HKEY_CURRENT_USER,String,0,KEY_ALL_ACCESS, &hKeyResults); - if (lResult == ERROR_SUCCESS) { + if (lResult == ERROR_SUCCESS) + { //LoadLogSetting(hKeyResults,"Generate Log File",&LogOptions->GenerateLog); - if (LogOptions->GenerateLog || AlwaysFill) { + if (LogOptions->GenerateLog || AlwaysFill) + { LoadLogSetting(hKeyResults,"Log RDRAM",&LogOptions->LogRDRamRegisters); LoadLogSetting(hKeyResults,"Log SP",&LogOptions->LogSPRegisters); LoadLogSetting(hKeyResults,"Log DP Command",&LogOptions->LogDPCRegisters); @@ -137,20 +141,26 @@ void LoadLogOptions (LOG_OPTIONS * LogOptions, BOOL AlwaysFill) { LogOptions->LogUnknown = FALSE; } -void LoadLogSetting (HKEY hKey,char * String, BOOL * Value) { +void LoadLogSetting (HKEY hKey,char * String, BOOL * Value) +{ DWORD Type, dwResult, Bytes = 4; long lResult; lResult = RegQueryValueEx(hKey,String,0,&Type,(LPBYTE)(&dwResult),&Bytes); - if (Type == REG_DWORD && lResult == ERROR_SUCCESS) { + if (Type == REG_DWORD && lResult == ERROR_SUCCESS) + { *Value = (BOOL)dwResult; - } else { + } + else + { *Value = FALSE; } } -LRESULT CALLBACK LogGeneralProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lParam) { - switch (uMsg) { +LRESULT CALLBACK LogGeneralProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lParam) +{ + switch (uMsg) + { case WM_INITDIALOG: if (TempOptions.LogCP0changes) { CheckDlgButton(hDlg,IDC_CP0_WRITE,BST_CHECKED); } if (TempOptions.LogCP0reads) { CheckDlgButton(hDlg,IDC_CP0_READ,BST_CHECKED); } @@ -178,8 +188,12 @@ LRESULT CALLBACK LogGeneralProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM return TRUE; } -void Log_LW (DWORD PC, DWORD VAddr) { - if (!LogOptions.GenerateLog) { return; } +void Log_LW (DWORD PC, DWORD VAddr) +{ + if (!LogOptions.GenerateLog) + { + return; + } if ( VAddr < 0xA0000000 || VAddr >= 0xC0000000 ) { @@ -196,12 +210,20 @@ void Log_LW (DWORD PC, DWORD VAddr) { } DWORD Value; - if ( VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) { return; } - if ( VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) { - if (!LogOptions.LogRDRamRegisters) { return; } + if ( VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) + { + return; + } + if ( VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) + { + if (!LogOptions.LogRDRamRegisters) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xA3F00000: LogMessage("%08X: read from RDRAM_CONFIG_REG/RDRAM_DEVICE_TYPE_REG (%08X)",PC, Value); return; case 0xA3F00004: LogMessage("%08X: read from RDRAM_DEVICE_ID_REG (%08X)",PC, Value); return; case 0xA3F00008: LogMessage("%08X: read from RDRAM_DELAY_REG (%08X)",PC, Value); return; @@ -215,12 +237,20 @@ void Log_LW (DWORD PC, DWORD VAddr) { } } - if ( VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC ) { return; } - if ( VAddr >= 0xA4040000 && VAddr <= 0xA404001C ) { - if (!LogOptions.LogSPRegisters) { return; } + if ( VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC ) + { + return; + } + if ( VAddr >= 0xA4040000 && VAddr <= 0xA404001C ) + { + if (!LogOptions.LogSPRegisters) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xA4040000: LogMessage("%08X: read from SP_MEM_ADDR_REG (%08X)",PC, Value); break; case 0xA4040004: LogMessage("%08X: read from SP_DRAM_ADDR_REG (%08X)",PC, Value); break; case 0xA4040008: LogMessage("%08X: read from SP_RD_LEN_REG (%08X)",PC, Value); break; @@ -232,17 +262,26 @@ void Log_LW (DWORD PC, DWORD VAddr) { } return; } - if ( VAddr == 0xA4080000) { - if (!LogOptions.LogSPRegisters) { return; } + if ( VAddr == 0xA4080000) + { + if (!LogOptions.LogSPRegisters) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); LogMessage("%08X: read from SP_PC (%08X)",PC, Value); return; } - if (VAddr >= 0xA4100000 && VAddr <= 0xA410001C) { - if (!LogOptions.LogDPCRegisters) { return; } + if (VAddr >= 0xA4100000 && VAddr <= 0xA410001C) + { + if (!LogOptions.LogDPCRegisters) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xA4100000: LogMessage("%08X: read from DPC_START_REG (%08X)",PC, Value); return; case 0xA4100004: LogMessage("%08X: read from DPC_END_REG (%08X)",PC, Value); return; case 0xA4100008: LogMessage("%08X: read from DPC_CURRENT_REG (%08X)",PC, Value); return; @@ -253,22 +292,32 @@ void Log_LW (DWORD PC, DWORD VAddr) { case 0xA410001C: LogMessage("%08X: read from DPC_TMEM_REG (%08X)",PC, Value); return; } } - if (VAddr >= 0xA4300000 && VAddr <= 0xA430000C) { - if (!LogOptions.LogMIPSInterface) { return; } + if (VAddr >= 0xA4300000 && VAddr <= 0xA430000C) + { + if (!LogOptions.LogMIPSInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xA4300000: LogMessage("%08X: read from MI_INIT_MODE_REG/MI_MODE_REG (%08X)",PC, Value); return; case 0xA4300004: LogMessage("%08X: read from MI_VERSION_REG/MI_NOOP_REG (%08X)",PC, Value); return; case 0xA4300008: LogMessage("%08X: read from MI_INTR_REG (%08X)",PC, Value); return; case 0xA430000C: LogMessage("%08X: read from MI_INTR_MASK_REG (%08X)",PC, Value); return; } } - if (VAddr >= 0xA4400000 && VAddr <= 0xA4400034) { - if (!LogOptions.LogVideoInterface) { return; } + if (VAddr >= 0xA4400000 && VAddr <= 0xA4400034) + { + if (!LogOptions.LogVideoInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xA4400000: LogMessage("%08X: read from VI_STATUS_REG/VI_CONTROL_REG (%08X)",PC, Value); return; case 0xA4400004: LogMessage("%08X: read from VI_ORIGIN_REG/VI_DRAM_ADDR_REG (%08X)",PC, Value); return; case 0xA4400008: LogMessage("%08X: read from VI_WIDTH_REG/VI_H_WIDTH_REG (%08X)",PC, Value); return; @@ -285,11 +334,16 @@ void Log_LW (DWORD PC, DWORD VAddr) { case 0xA4400034: LogMessage("%08X: read from VI_Y_SCALE_REG (%08X)",PC, Value); return; } } - if (VAddr >= 0xA4500000 && VAddr <= 0xA4500014) { - if (!LogOptions.LogAudioInterface) { return; } + if (VAddr >= 0xA4500000 && VAddr <= 0xA4500014) + { + if (!LogOptions.LogAudioInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xA4500000: LogMessage("%08X: read from AI_DRAM_ADDR_REG (%08X)",PC, Value); return; case 0xA4500004: LogMessage("%08X: read from AI_LEN_REG (%08X)",PC, Value); return; case 0xA4500008: LogMessage("%08X: read from AI_CONTROL_REG (%08X)",PC, Value); return; @@ -298,11 +352,16 @@ void Log_LW (DWORD PC, DWORD VAddr) { case 0xA4500014: LogMessage("%08X: read from AI_BITRATE_REG (%08X)",PC, Value); return; } } - if (VAddr >= 0xA4600000 && VAddr <= 0xA4600030) { - if (!LogOptions.LogPerInterface) { return; } + if (VAddr >= 0xA4600000 && VAddr <= 0xA4600030) + { + if (!LogOptions.LogPerInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xA4600000: LogMessage("%08X: read from PI_DRAM_ADDR_REG (%08X)",PC, Value); return; case 0xA4600004: LogMessage("%08X: read from PI_CART_ADDR_REG (%08X)",PC, Value); return; case 0xA4600008: LogMessage("%08X: read from PI_RD_LEN_REG (%08X)",PC, Value); return; @@ -318,11 +377,16 @@ void Log_LW (DWORD PC, DWORD VAddr) { case 0xA4600030: LogMessage("%08X: read from PI_BSD_DOM2_RLS_REG (%08X)",PC, Value); return; } } - if (VAddr >= 0xA4700000 && VAddr <= 0xA470001C) { - if (!LogOptions.LogRDRAMInterface) { return; } + if (VAddr >= 0xA4700000 && VAddr <= 0xA470001C) + { + if (!LogOptions.LogRDRAMInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xA4700000: LogMessage("%08X: read from RI_MODE_REG (%08X)",PC, Value); return; case 0xA4700004: LogMessage("%08X: read from RI_CONFIG_REG (%08X)",PC, Value); return; case 0xA4700008: LogMessage("%08X: read from RI_CURRENT_LOAD_REG (%08X)",PC, Value); return; @@ -333,43 +397,74 @@ void Log_LW (DWORD PC, DWORD VAddr) { case 0xA470001C: LogMessage("%08X: read from RI_WERROR_REG (%08X)",PC, Value); return; } } - if ( VAddr == 0xA4800000) { - if (!LogOptions.LogSerialInterface) { return; } + if ( VAddr == 0xA4800000) + { + if (!LogOptions.LogSerialInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); LogMessage("%08X: read from SI_DRAM_ADDR_REG (%08X)",PC, Value); return; } - if ( VAddr == 0xA4800004) { - if (!LogOptions.LogSerialInterface) { return; } + if ( VAddr == 0xA4800004) + { + if (!LogOptions.LogSerialInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); LogMessage("%08X: read from SI_PIF_ADDR_RD64B_REG (%08X)",PC, Value); return; } - if ( VAddr == 0xA4800010) { - if (!LogOptions.LogSerialInterface) { return; } + if ( VAddr == 0xA4800010) + { + if (!LogOptions.LogSerialInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); LogMessage("%08X: read from SI_PIF_ADDR_WR64B_REG (%08X)",PC, Value); return; } - if ( VAddr == 0xA4800018) { - if (!LogOptions.LogSerialInterface) { return; } + if ( VAddr == 0xA4800018) + { + if (!LogOptions.LogSerialInterface) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); LogMessage("%08X: read from SI_STATUS_REG (%08X)",PC, Value); return; } - if ( VAddr >= 0xBFC00000 && VAddr <= 0xBFC007C0 ) { return; } - if ( VAddr >= 0xBFC007C0 && VAddr <= 0xBFC007FC ) { - if (!LogOptions.LogPRDirectMemLoads) { return; } + if ( VAddr >= 0xBFC00000 && VAddr <= 0xBFC007C0 ) + { + return; + } + if ( VAddr >= 0xBFC007C0 && VAddr <= 0xBFC007FC ) + { + if (!LogOptions.LogPRDirectMemLoads) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); LogMessage("%08X: read word from Pif Ram at 0x%X (%08X)",PC,VAddr - 0xBFC007C0, Value); return; } - if ( VAddr >= 0xB0000040 && ((VAddr - 0xB0000000) < g_Rom->GetRomSize())) { return; } - if ( VAddr >= 0xB0000000 && VAddr < 0xB0000040) { - if (!LogOptions.LogRomHeader) { return; } + if ( VAddr >= 0xB0000040 && ((VAddr - 0xB0000000) < g_Rom->GetRomSize())) + { + return; + } + if ( VAddr >= 0xB0000000 && VAddr < 0xB0000040) + { + if (!LogOptions.LogRomHeader) + { + return; + } g_MMU->LW_VAddr(VAddr,Value); - switch (VAddr) { + switch (VAddr) + { case 0xB0000004: LogMessage("%08X: read from Rom Clock Rate (%08X)",PC, Value); break; case 0xB0000008: LogMessage("%08X: read from Rom Boot address offset (%08X)",PC, Value); break; case 0xB000000C: LogMessage("%08X: read from Rom Release offset (%08X)",PC, Value); break; @@ -379,17 +474,27 @@ void Log_LW (DWORD PC, DWORD VAddr) { } return; } - if (!LogOptions.LogUnknown) { return; } + if (!LogOptions.LogUnknown) + { + return; + } LogMessage("%08X: read from unknown ??? (%08X)",PC,VAddr); } -void __cdecl LogMessage (char * Message, ...) { +void __cdecl LogMessage (char * Message, ...) +{ DWORD dwWritten; char Msg[400]; va_list ap; - if(!g_Settings->LoadBool(Debugger_Enabled)) { return; } - if(hLogFile == NULL) { return; } + if (!g_Settings->LoadBool(Debugger_Enabled)) + { + return; + } + if (hLogFile == NULL) + { + return; + } va_start( ap, Message ); vsprintf( Msg, Message, ap ); @@ -400,8 +505,12 @@ void __cdecl LogMessage (char * Message, ...) { WriteFile( hLogFile,Msg,strlen(Msg),&dwWritten,NULL ); } -void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { - if (!LogOptions.GenerateLog) { return; } +void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) +{ + if (!LogOptions.GenerateLog) + { + return; + } if ( VAddr < 0xA0000000 || VAddr >= 0xC0000000 ) { @@ -417,10 +526,18 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { VAddr = PAddr + 0xA0000000; } - if ( VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) { return; } - if ( VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) { - if (!LogOptions.LogRDRamRegisters) { return; } - switch (VAddr) { + if ( VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_MMU->RdramSize())) + { + return; + } + if ( VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) + { + if (!LogOptions.LogRDRamRegisters) + { + return; + } + switch (VAddr) + { case 0xA3F00000: LogMessage("%08X: Writing 0x%08X to RDRAM_CONFIG_REG/RDRAM_DEVICE_TYPE_REG",PC, Value ); return; case 0xA3F00004: LogMessage("%08X: Writing 0x%08X to RDRAM_DEVICE_ID_REG",PC, Value ); return; case 0xA3F00008: LogMessage("%08X: Writing 0x%08X to RDRAM_DELAY_REG",PC, Value ); return; @@ -433,11 +550,19 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { case 0xA3F00024: LogMessage("%08X: Writing 0x%08X to RDRAM_DEVICE_MANUF_REG",PC, Value ); return; } } - if ( VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC ) { return; } + if ( VAddr >= 0xA4000000 && VAddr <= 0xA4001FFC ) + { + return; + } - if ( VAddr >= 0xA4040000 && VAddr <= 0xA404001C) { - if (!LogOptions.LogSPRegisters) { return; } - switch (VAddr) { + if ( VAddr >= 0xA4040000 && VAddr <= 0xA404001C) + { + if (!LogOptions.LogSPRegisters) + { + return; + } + switch (VAddr) + { case 0xA4040000: LogMessage("%08X: Writing 0x%08X to SP_MEM_ADDR_REG",PC, Value ); return; case 0xA4040004: LogMessage("%08X: Writing 0x%08X to SP_DRAM_ADDR_REG",PC, Value ); return; case 0xA4040008: LogMessage("%08X: Writing 0x%08X to SP_RD_LEN_REG",PC, Value ); return; @@ -448,14 +573,23 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { case 0xA404001C: LogMessage("%08X: Writing 0x%08X to SP_SEMAPHORE_REG",PC, Value ); return; } } - if ( VAddr == 0xA4080000) { - if (!LogOptions.LogSPRegisters) { return; } + if ( VAddr == 0xA4080000) + { + if (!LogOptions.LogSPRegisters) + { + return; + } LogMessage("%08X: Writing 0x%08X to SP_PC",PC, Value ); return; } - if ( VAddr >= 0xA4100000 && VAddr <= 0xA410001C) { - if (!LogOptions.LogDPCRegisters) { return; } - switch (VAddr) { + if ( VAddr >= 0xA4100000 && VAddr <= 0xA410001C) + { + if (!LogOptions.LogDPCRegisters) + { + return; + } + switch (VAddr) + { case 0xA4100000: LogMessage("%08X: Writing 0x%08X to DPC_START_REG",PC, Value ); return; case 0xA4100004: LogMessage("%08X: Writing 0x%08X to DPC_END_REG",PC, Value ); return; case 0xA4100008: LogMessage("%08X: Writing 0x%08X to DPC_CURRENT_REG",PC, Value ); return; @@ -467,9 +601,14 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { } } - if ( VAddr >= 0xA4200000 && VAddr <= 0xA420000C) { - if (!LogOptions.LogDPSRegisters) { return; } - switch (VAddr) { + if ( VAddr >= 0xA4200000 && VAddr <= 0xA420000C) + { + if (!LogOptions.LogDPSRegisters) + { + return; + } + switch (VAddr) + { case 0xA4200000: LogMessage("%08X: Writing 0x%08X to DPS_TBIST_REG",PC, Value ); return; case 0xA4200004: LogMessage("%08X: Writing 0x%08X to DPS_TEST_MODE_REG",PC, Value ); return; case 0xA4200008: LogMessage("%08X: Writing 0x%08X to DPS_BUFTEST_ADDR_REG",PC, Value ); return; @@ -477,18 +616,28 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { } } - if ( VAddr >= 0xA4300000 && VAddr <= 0xA430000C) { - if (!LogOptions.LogMIPSInterface) { return; } - switch (VAddr) { + if ( VAddr >= 0xA4300000 && VAddr <= 0xA430000C) + { + if (!LogOptions.LogMIPSInterface) + { + return; + } + switch (VAddr) + { case 0xA4300000: LogMessage("%08X: Writing 0x%08X to MI_INIT_MODE_REG/MI_MODE_REG",PC, Value ); return; case 0xA4300004: LogMessage("%08X: Writing 0x%08X to MI_VERSION_REG/MI_NOOP_REG",PC, Value ); return; case 0xA4300008: LogMessage("%08X: Writing 0x%08X to MI_INTR_REG",PC, Value ); return; case 0xA430000C: LogMessage("%08X: Writing 0x%08X to MI_INTR_MASK_REG",PC, Value ); return; } } - if ( VAddr >= 0xA4400000 && VAddr <= 0xA4400034) { - if (!LogOptions.LogVideoInterface) { return; } - switch (VAddr) { + if ( VAddr >= 0xA4400000 && VAddr <= 0xA4400034) + { + if (!LogOptions.LogVideoInterface) + { + return; + } + switch (VAddr) + { case 0xA4400000: LogMessage("%08X: Writing 0x%08X to VI_STATUS_REG/VI_CONTROL_REG",PC, Value ); return; case 0xA4400004: LogMessage("%08X: Writing 0x%08X to VI_ORIGIN_REG/VI_DRAM_ADDR_REG",PC, Value ); return; case 0xA4400008: LogMessage("%08X: Writing 0x%08X to VI_WIDTH_REG/VI_H_WIDTH_REG",PC, Value ); return; @@ -506,9 +655,14 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { } } - if ( VAddr >= 0xA4500000 && VAddr <= 0xA4500014) { - if (!LogOptions.LogAudioInterface) { return; } - switch (VAddr) { + if ( VAddr >= 0xA4500000 && VAddr <= 0xA4500014) + { + if (!LogOptions.LogAudioInterface) + { + return; + } + switch (VAddr) + { case 0xA4500000: LogMessage("%08X: Writing 0x%08X to AI_DRAM_ADDR_REG",PC, Value ); return; case 0xA4500004: LogMessage("%08X: Writing 0x%08X to AI_LEN_REG",PC, Value ); return; case 0xA4500008: LogMessage("%08X: Writing 0x%08X to AI_CONTROL_REG",PC, Value ); return; @@ -518,9 +672,14 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { } } - if ( VAddr >= 0xA4600000 && VAddr <= 0xA4600030) { - if (!LogOptions.LogPerInterface) { return; } - switch (VAddr) { + if ( VAddr >= 0xA4600000 && VAddr <= 0xA4600030) + { + if (!LogOptions.LogPerInterface) + { + return; + } + switch (VAddr) + { case 0xA4600000: LogMessage("%08X: Writing 0x%08X to PI_DRAM_ADDR_REG",PC, Value ); return; case 0xA4600004: LogMessage("%08X: Writing 0x%08X to PI_CART_ADDR_REG",PC, Value ); return; case 0xA4600008: LogMessage("%08X: Writing 0x%08X to PI_RD_LEN_REG",PC, Value ); return; @@ -536,9 +695,14 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { case 0xA4600030: LogMessage("%08X: Writing 0x%08X to PI_BSD_DOM2_RLS_REG",PC, Value ); return; } } - if ( VAddr >= 0xA4700000 && VAddr <= 0xA470001C) { - if (!LogOptions.LogRDRAMInterface) { return; } - switch (VAddr) { + if ( VAddr >= 0xA4700000 && VAddr <= 0xA470001C) + { + if (!LogOptions.LogRDRAMInterface) + { + return; + } + switch (VAddr) + { case 0xA4700000: LogMessage("%08X: Writing 0x%08X to RI_MODE_REG",PC, Value ); return; case 0xA4700004: LogMessage("%08X: Writing 0x%08X to RI_CONFIG_REG",PC, Value ); return; case 0xA4700008: LogMessage("%08X: Writing 0x%08X to RI_CURRENT_LOAD_REG",PC, Value ); return; @@ -549,40 +713,67 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { case 0xA470001C: LogMessage("%08X: Writing 0x%08X to RI_WERROR_REG",PC, Value ); return; } } - if ( VAddr == 0xA4800000) { - if (!LogOptions.LogSerialInterface) { return; } + if ( VAddr == 0xA4800000) + { + if (!LogOptions.LogSerialInterface) + { + return; + } LogMessage("%08X: Writing 0x%08X to SI_DRAM_ADDR_REG",PC, Value ); return; } - if ( VAddr == 0xA4800004) { - if (LogOptions.LogPRDMAOperations) { + if ( VAddr == 0xA4800004) + { + if (LogOptions.LogPRDMAOperations) + { LogMessage("%08X: A DMA transfer from the PIF ram has occured",PC ); } - if (!LogOptions.LogSerialInterface) { return; } + if (!LogOptions.LogSerialInterface) + { + return; + } LogMessage("%08X: Writing 0x%08X to SI_PIF_ADDR_RD64B_REG",PC, Value ); return; } - if ( VAddr == 0xA4800010) { - if (LogOptions.LogPRDMAOperations) { + if ( VAddr == 0xA4800010) + { + if (LogOptions.LogPRDMAOperations) + { LogMessage("%08X: A DMA transfer to the PIF ram has occured",PC ); } - if (!LogOptions.LogSerialInterface) { return; } + if (!LogOptions.LogSerialInterface) + { + return; + } LogMessage("%08X: Writing 0x%08X to SI_PIF_ADDR_WR64B_REG",PC, Value ); return; } - if ( VAddr == 0xA4800018) { - if (!LogOptions.LogSerialInterface) { return; } + if ( VAddr == 0xA4800018) + { + if (!LogOptions.LogSerialInterface) + { + return; + } LogMessage("%08X: Writing 0x%08X to SI_STATUS_REG",PC, Value ); return; } - if ( VAddr >= 0xBFC007C0 && VAddr <= 0xBFC007FC ) { - if (!LogOptions.LogPRDirectMemStores) { return; } + if ( VAddr >= 0xBFC007C0 && VAddr <= 0xBFC007FC ) + { + if (!LogOptions.LogPRDirectMemStores) + { + return; + } LogMessage("%08X: Writing 0x%08X to Pif Ram at 0x%X",PC,Value, VAddr - 0xBFC007C0); return; } - if (!LogOptions.LogUnknown) { return; } + if (!LogOptions.LogUnknown) + { + return; + } LogMessage("%08X: Writing 0x%08X to %08X ????",PC, Value, VAddr ); } -LRESULT CALLBACK LogPifProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lParam) { - switch (uMsg) { +LRESULT CALLBACK LogPifProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lParam) +{ + switch (uMsg) + { case WM_INITDIALOG: if (TempOptions.LogPRDMAOperations) { CheckDlgButton(hDlg,IDC_SI_DMA,BST_CHECKED); } if (TempOptions.LogPRDirectMemLoads) { CheckDlgButton(hDlg,IDC_DIRECT_WRITE,BST_CHECKED); } @@ -592,7 +783,10 @@ LRESULT CALLBACK LogPifProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lPa if (TempOptions.LogControllerPak) { CheckDlgButton(hDlg,IDC_CONT_PAK,BST_CHECKED); } break; case WM_NOTIFY: - if (((NMHDR FAR *) lParam)->code != PSN_APPLY) { break; } + if (((NMHDR FAR *) lParam)->code != PSN_APPLY) + { + break; + } TempOptions.LogPRDMAOperations = IsDlgButtonChecked(hDlg,IDC_SI_DMA) == BST_CHECKED?TRUE:FALSE; TempOptions.LogPRDirectMemLoads = IsDlgButtonChecked(hDlg,IDC_DIRECT_WRITE) == BST_CHECKED?TRUE:FALSE; TempOptions.LogPRDMAMemLoads = IsDlgButtonChecked(hDlg,IDC_DMA_WRITE) == BST_CHECKED?TRUE:FALSE; @@ -606,8 +800,10 @@ LRESULT CALLBACK LogPifProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lPa return TRUE; } -LRESULT CALLBACK LogRegProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lParam) { - switch (uMsg) { +LRESULT CALLBACK LogRegProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lParam) +{ + switch (uMsg) + { case WM_INITDIALOG: if (TempOptions.LogRDRamRegisters) { CheckDlgButton(hDlg,IDC_RDRAM,BST_CHECKED); } if (TempOptions.LogSPRegisters) { CheckDlgButton(hDlg,IDC_SP_REG,BST_CHECKED); } @@ -621,7 +817,10 @@ LRESULT CALLBACK LogRegProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lPa if (TempOptions.LogSerialInterface) { CheckDlgButton(hDlg,IDC_SI_REG,BST_CHECKED); } break; case WM_NOTIFY: - if (((NMHDR FAR *) lParam)->code != PSN_APPLY) { break; } + if (((NMHDR FAR *) lParam)->code != PSN_APPLY) + { + break; + } TempOptions.LogRDRamRegisters = IsDlgButtonChecked(hDlg,IDC_RDRAM) == BST_CHECKED?TRUE:FALSE; TempOptions.LogSPRegisters = IsDlgButtonChecked(hDlg,IDC_SP_REG) == BST_CHECKED?TRUE:FALSE; TempOptions.LogDPCRegisters = IsDlgButtonChecked(hDlg,IDC_DPC_REG) == BST_CHECKED?TRUE:FALSE; @@ -639,12 +838,14 @@ LRESULT CALLBACK LogRegProc (HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lPa return TRUE; } -void SaveLogSetting (HKEY hKey,char * String, BOOL Value) { +void SaveLogSetting (HKEY hKey,char * String, BOOL Value) +{ DWORD StoreValue = Value; RegSetValueEx(hKey,String,0,REG_DWORD,(CONST BYTE *)&StoreValue,sizeof(DWORD)); } -void SaveLogOptions (void) { +void SaveLogOptions (void) +{ long lResult; HKEY hKeyResults = 0; DWORD Disposition = 0; @@ -684,11 +885,15 @@ void SaveLogOptions (void) { void StartLog (void) { - if (!LogOptions.GenerateLog) { + if (!LogOptions.GenerateLog) + { StopLog(); return; } - if (hLogFile) { return; } + if (hLogFile) + { + return; + } CPath LogFile(CPath::MODULE_DIRECTORY); LogFile.AppendDirectory(_T("Logs")); @@ -699,8 +904,10 @@ void StartLog (void) SetFilePointer(hLogFile,0,NULL,FILE_BEGIN); } -void StopLog (void) { - if (hLogFile) { +void StopLog (void) +{ + if (hLogFile) + { CloseHandle(hLogFile); } hLogFile = NULL; diff --git a/Source/Project64/N64 System/C Core/Logging.h b/Source/Project64/N64 System/C Core/Logging.h index 7539494c6..844fcdf04 100644 --- a/Source/Project64/N64 System/C Core/Logging.h +++ b/Source/Project64/N64 System/C Core/Logging.h @@ -13,7 +13,8 @@ extern "C" { #endif -typedef struct { +typedef struct +{ BOOL GenerateLog; /* Registers Log */ diff --git a/Source/Project64/N64 System/C Core/r4300i Commands.cpp b/Source/Project64/N64 System/C Core/r4300i Commands.cpp index c23e3defa..9b01fd1f7 100644 --- a/Source/Project64/N64 System/C Core/r4300i Commands.cpp +++ b/Source/Project64/N64 System/C Core/r4300i Commands.cpp @@ -16,32 +16,41 @@ BOOL InR4300iCommandsWindow = FALSE; char CommandName[100]; -void SetR4300iCommandToStepping ( void ) { +void SetR4300iCommandToStepping ( void ) +{ } -void SetR4300iCommandViewto ( UINT /*NewLocation*/ ) { +void SetR4300iCommandViewto ( UINT /*NewLocation*/ ) +{ } -void __cdecl Enter_R4300i_Commands_Window ( void ) { +void __cdecl Enter_R4300i_Commands_Window ( void ) +{ } char strLabelName[100]; -char * LabelName (DWORD Address) { +char * LabelName (DWORD Address) +{ sprintf(strLabelName,"0x%08X",Address); return strLabelName; } -char * R4300iSpecialName ( DWORD OpCode, DWORD /*PC*/ ) { +char * R4300iSpecialName ( DWORD OpCode, DWORD /*PC*/ ) +{ OPCODE command; command.Hex = OpCode; - switch (command.funct) { + switch (command.funct) + { case R4300i_SPECIAL_SLL: - if (command.Hex != 0) { + if (command.Hex != 0) + { sprintf(CommandName,"sll\t%s, %s, 0x%X",CRegName::GPR[command.rd], CRegName::GPR[command.rt], command.sa); - } else { + } + else + { sprintf(CommandName,"nop"); } break; @@ -230,18 +239,22 @@ char * R4300iSpecialName ( DWORD OpCode, DWORD /*PC*/ ) { return CommandName; } -char * R4300iRegImmName ( DWORD OpCode, DWORD PC ) { +char * R4300iRegImmName ( DWORD OpCode, DWORD PC ) +{ OPCODE command; command.Hex = OpCode; - switch (command.rt) { + switch (command.rt) + { case R4300i_REGIMM_BLTZ: sprintf(CommandName,"bltz\t%s, %s",CRegName::GPR[command.rs], LabelName(PC + ((short)command.offset << 2) + 4)); break; case R4300i_REGIMM_BGEZ: - if (command.rs == 0) { + if (command.rs == 0) + { sprintf(CommandName,"b\t%s", LabelName(PC + ((short)command.offset << 2) + 4)); - } else { + } else + { sprintf(CommandName,"bgez\t%s, %s",CRegName::GPR[command.rs], LabelName(PC + ((short)command.offset << 2) + 4)); } break; @@ -273,9 +286,12 @@ char * R4300iRegImmName ( DWORD OpCode, DWORD PC ) { sprintf(CommandName,"bltzal\t%s, %s",CRegName::GPR[command.rs], LabelName(PC + ((short)command.offset << 2) + 4)); break; case R4300i_REGIMM_BGEZAL: - if (command.rs == 0) { + if (command.rs == 0) + { sprintf(CommandName,"bal\t%s",LabelName(PC + ((short)command.offset << 2) + 4)); - } else { + } + else + { sprintf(CommandName,"bgezal\t%s, %s",CRegName::GPR[command.rs], LabelName(PC + ((short)command.offset << 2) + 4)); } break; @@ -292,11 +308,13 @@ char * R4300iRegImmName ( DWORD OpCode, DWORD PC ) { return CommandName; } -char * R4300iCop1Name ( DWORD OpCode, DWORD PC ) { +char * R4300iCop1Name ( DWORD OpCode, DWORD PC ) +{ OPCODE command; command.Hex = OpCode; - switch (command.fmt) { + switch (command.fmt) + { case R4300i_COP1_MF: sprintf(CommandName,"mfc1\t%s, %s",CRegName::GPR[command.rt], CRegName::FPR[command.fs]); break; @@ -316,7 +334,8 @@ char * R4300iCop1Name ( DWORD OpCode, DWORD PC ) { sprintf(CommandName,"ctc1\t%s, %s",CRegName::GPR[command.rt], CRegName::FPR_Ctrl[command.fs]); break; case R4300i_COP1_BC: - switch (command.ft) { + switch (command.ft) + { case R4300i_COP1_BC_BCF: sprintf(CommandName,"BC1F\t%s", LabelName(PC + ((short)command.offset << 2) + 4)); break; @@ -338,7 +357,8 @@ char * R4300iCop1Name ( DWORD OpCode, DWORD PC ) { case R4300i_COP1_D: case R4300i_COP1_W: case R4300i_COP1_L: - switch (command.funct) { + switch (command.funct) + { case R4300i_COP1_FUNCT_ADD: sprintf(CommandName,"ADD.%s\t%s, %s, %s",FPR_Type(command.fmt), CRegName::FPR[command.fd], CRegName::FPR[command.fs], @@ -499,11 +519,13 @@ char * R4300iCop1Name ( DWORD OpCode, DWORD PC ) { return CommandName; } -char * R4300iOpcodeName ( DWORD OpCode, DWORD PC ) { +char * R4300iOpcodeName ( DWORD OpCode, DWORD PC ) +{ OPCODE command; command.Hex = OpCode; - switch (command.op) { + switch (command.op) + { case R4300i_SPECIAL: return R4300iSpecialName ( OpCode, PC ); break; @@ -517,21 +539,29 @@ char * R4300iOpcodeName ( DWORD OpCode, DWORD PC ) { sprintf(CommandName,"jal\t%s",LabelName((PC & 0xF0000000) + (command.target << 2))); break; case R4300i_BEQ: - if (command.rs == 0 && command.rt == 0) { + if (command.rs == 0 && command.rt == 0) + { sprintf(CommandName,"b\t%s", LabelName(PC + ((short)command.offset << 2) + 4)); - } else if (command.rs == 0 || command.rt == 0) { + } + else if (command.rs == 0 || command.rt == 0) + { sprintf(CommandName,"beqz\t%s, %s", CRegName::GPR[command.rs == 0 ? command.rt : command.rs ], LabelName(PC + ((short)command.offset << 2) + 4)); - } else { + } + else + { sprintf(CommandName,"beq\t%s, %s, %s", CRegName::GPR[command.rs], CRegName::GPR[command.rt], LabelName(PC + ((short)command.offset << 2) + 4)); } break; case R4300i_BNE: - if ((command.rs == 0) ^ (command.rt == 0)){ + if ((command.rs == 0) ^ (command.rt == 0)) + { sprintf(CommandName,"bnez\t%s, %s", CRegName::GPR[command.rs == 0 ? command.rt : command.rs ], LabelName(PC + ((short)command.offset << 2) + 4)); - } else { + } + else + { sprintf(CommandName,"bne\t%s, %s, %s", CRegName::GPR[command.rs], CRegName::GPR[command.rt], LabelName(PC + ((short)command.offset << 2) + 4)); } @@ -567,7 +597,8 @@ char * R4300iOpcodeName ( DWORD OpCode, DWORD PC ) { sprintf(CommandName,"lui\t%s, 0x%X",CRegName::GPR[command.rt], command.immediate); break; case R4300i_CP0: - switch (command.rs) { + switch (command.rs) + { case R4300i_COP0_MF: sprintf(CommandName,"mfc0\t%s, %s",CRegName::GPR[command.rt], CRegName::Cop0[command.rd]); break; @@ -575,8 +606,10 @@ char * R4300iOpcodeName ( DWORD OpCode, DWORD PC ) { sprintf(CommandName,"mtc0\t%s, %s",CRegName::GPR[command.rt], CRegName::Cop0[command.rd]); break; default: - if ( (command.rs & 0x10 ) != 0 ) { - switch( command.funct ) { + if ( (command.rs & 0x10 ) != 0 ) + { + switch ( command.funct ) + { case R4300i_COP0_CO_TLBR: sprintf(CommandName,"tlbr"); break; case R4300i_COP0_CO_TLBWI: sprintf(CommandName,"tlbwi"); break; case R4300i_COP0_CO_TLBWR: sprintf(CommandName,"tlbwr"); break; @@ -586,7 +619,9 @@ char * R4300iOpcodeName ( DWORD OpCode, DWORD PC ) { sprintf(CommandName,"Unknown\t%02X %02X %02X %02X", command.Ascii[3],command.Ascii[2],command.Ascii[1],command.Ascii[0]); } - } else { + } + else + { sprintf(CommandName,"Unknown\t%02X %02X %02X %02X", command.Ascii[3],command.Ascii[2],command.Ascii[1],command.Ascii[0]); } @@ -596,21 +631,29 @@ char * R4300iOpcodeName ( DWORD OpCode, DWORD PC ) { case R4300i_CP1: return R4300iCop1Name ( OpCode, PC ); case R4300i_BEQL: - if (command.rs == command.rt) { + if (command.rs == command.rt) + { sprintf(CommandName,"b\t%s", LabelName(PC + ((short)command.offset << 2) + 4)); - } else if ((command.rs == 0) ^ (command.rt == 0)){ + } + else if ((command.rs == 0) ^ (command.rt == 0)) + { sprintf(CommandName,"beqzl\t%s, %s", CRegName::GPR[command.rs == 0 ? command.rt : command.rs ], LabelName(PC + ((short)command.offset << 2) + 4)); - } else { + } + else + { sprintf(CommandName,"beql\t%s, %s, %s", CRegName::GPR[command.rs], CRegName::GPR[command.rt], LabelName(PC + ((short)command.offset << 2) + 4)); } break; case R4300i_BNEL: - if ((command.rs == 0) ^ (command.rt == 0)){ + if ((command.rs == 0) ^ (command.rt == 0)) + { sprintf(CommandName,"bnezl\t%s, %s", CRegName::GPR[command.rs == 0 ? command.rt : command.rs ], LabelName(PC + ((short)command.offset << 2) + 4)); - } else { + } + else + { sprintf(CommandName,"bnel\t%s, %s, %s", CRegName::GPR[command.rs], CRegName::GPR[command.rt], LabelName(PC + ((short)command.offset << 2) + 4)); } diff --git a/Source/Project64/N64 System/Debugger/Debug Dialog.h b/Source/Project64/N64 System/Debugger/Debug Dialog.h index 7abd80bb1..519b02338 100644 --- a/Source/Project64/N64 System/Debugger/Debug Dialog.h +++ b/Source/Project64/N64 System/Debugger/Debug Dialog.h @@ -61,7 +61,9 @@ public: if (m_hWnd) { SetForegroundWindow((HWND)m_hWnd); - } else { + } + else + { DWORD ThreadID; ResetEvent(m_CreatedEvent); m_DialogThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)CreateDebuggerWindow,(LPVOID)this,0, &ThreadID); diff --git a/Source/Project64/N64 System/Debugger/Debugger - Memory Dump.cpp b/Source/Project64/N64 System/Debugger/Debugger - Memory Dump.cpp index 8c10f1d61..5ecb12c52 100644 --- a/Source/Project64/N64 System/Debugger/Debugger - Memory Dump.cpp +++ b/Source/Project64/N64 System/Debugger/Debugger - Memory Dump.cpp @@ -140,13 +140,19 @@ LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, // DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Cheats_DumpMemory), // (HWND)hParent, (DLGPROC)WinProc,(LPARAM)this); //} -//DWORD CDumpMemory::AsciiToHex (const char * HexValue) { +//DWORD CDumpMemory::AsciiToHex (const char * HexValue) +//{ // DWORD Count, Finish, Value = 0; // Finish = strlen(HexValue); -// if (Finish > 8 ) { Finish = 8; } -// for (Count = 0; Count < Finish; Count++){ +// if (Finish > 8 ) +// { +// Finish = 8; +// } +// for (Count = 0; Count < Finish; Count++ +// { // Value = (Value << 4); -// switch( HexValue[Count] ) { +// switch ( HexValue[Count] ) +// { // case '0': break; // case '1': Value += 1; break; // case '2': Value += 2; break; @@ -178,7 +184,8 @@ LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, //} //int CALLBACK CDumpMemory::WinProc (HWND hDlg,DWORD uMsg,DWORD wParam, DWORD lParam) //{ -// switch (uMsg) { +// switch (uMsg) +// { // case WM_INITDIALOG: // { // CDumpMemory * _this = (CDumpMemory *)lParam; @@ -199,23 +206,39 @@ LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, // case IDC_E_START_ADDR: // case IDC_E_END_ADDR: // case IDC_E_ALT_PC: -// if (HIWORD(wParam) == EN_UPDATE) { +// if (HIWORD(wParam) == EN_UPDATE) +// { // CDumpMemory * _this = (CDumpMemory *)GetProp(hDlg,"Class"); // TCHAR szTmp[20], szTmp2[20]; // DWORD Value; // GetDlgItemText(hDlg,LOWORD(wParam),szTmp,sizeof(szTmp)); // Value = szTmp[1] =='x'?AsciiToHex(&szTmp[2]):AsciiToHex(szTmp); -// //if (Value > Stop) { Value = Stop; } -// //if (Value < Start) { Value = Start; } +// //if (Value > Stop) +// //{ +// // Value = Stop; +// //} +// //if (Value < Start) +// //{ +// // Value = Start; +// //} // sprintf(szTmp2,"0x%X",Value); -// if (strcmp(szTmp,szTmp2) != 0) { +// if (strcmp(szTmp,szTmp2) != 0) +// { // SetDlgItemText(hDlg,LOWORD(wParam),szTmp2); -// if (_this->SelStop == 0) { _this->SelStop = strlen(szTmp2); _this->SelStart = _this->SelStop; } +// if (_this->SelStop == 0) +// { +// _this->SelStop = strlen(szTmp2); _this->SelStart = _this->SelStop; +// } // SendDlgItemMessage(hDlg,LOWORD(wParam),EM_SETSEL,(WPARAM)_this->SelStart,(LPARAM)_this->SelStop); -// } else { +// } +// else +// { // WORD NewSelStart, NewSelStop; // SendDlgItemMessage(hDlg,LOWORD(wParam),EM_GETSEL,(WPARAM)&NewSelStart,(LPARAM)&NewSelStop); -// if (NewSelStart != 0) { _this->SelStart = NewSelStart; _this->SelStop = NewSelStop; } +// if (NewSelStart != 0) +// { +// _this->SelStart = NewSelStart; _this->SelStop = NewSelStop; +// } // } // } // break; @@ -348,15 +371,21 @@ bool CDumpMemory::DumpMemory ( LPCSTR FileName,DumpFormat Format, DWORD StartPC, // (HWND)hParent, (DLGPROC)WinProc,(LPARAM)this); //} // -//DWORD CDumpMemory::AsciiToHex (const char * HexValue) { +//DWORD CDumpMemory::AsciiToHex (const char * HexValue) +//{ // DWORD Count, Finish, Value = 0; // // Finish = strlen(HexValue); -// if (Finish > 8 ) { Finish = 8; } +// if (Finish > 8 ) +// { +// Finish = 8; +// } // -// for (Count = 0; Count < Finish; Count++){ +// for (Count = 0; Count < Finish; Count++) +// { // Value = (Value << 4); -// switch( HexValue[Count] ) { +// switch ( HexValue[Count] ) +// { // case '0': break; // case '1': Value += 1; break; // case '2': Value += 2; break; @@ -389,7 +418,8 @@ bool CDumpMemory::DumpMemory ( LPCSTR FileName,DumpFormat Format, DWORD StartPC, // //int CALLBACK CDumpMemory::WinProc (HWND hDlg,DWORD uMsg,DWORD wParam, DWORD lParam) //{ -// switch (uMsg) { +// switch (uMsg) +// { // case WM_INITDIALOG: // { // CDumpMemory * _this = (CDumpMemory *)lParam; @@ -412,7 +442,8 @@ bool CDumpMemory::DumpMemory ( LPCSTR FileName,DumpFormat Format, DWORD StartPC, // case IDC_E_START_ADDR: // case IDC_E_END_ADDR: // case IDC_E_ALT_PC: -// if (HIWORD(wParam) == EN_UPDATE) { +// if (HIWORD(wParam) == EN_UPDATE) +// { // CDumpMemory * _this = (CDumpMemory *)GetProp(hDlg,"Class"); // // TCHAR szTmp[20], szTmp2[20]; @@ -420,17 +451,29 @@ bool CDumpMemory::DumpMemory ( LPCSTR FileName,DumpFormat Format, DWORD StartPC, // // GetDlgItemText(hDlg,LOWORD(wParam),szTmp,sizeof(szTmp)); // Value = szTmp[1] =='x'?AsciiToHex(&szTmp[2]):AsciiToHex(szTmp); -// //if (Value > Stop) { Value = Stop; } -// //if (Value < Start) { Value = Start; } +// //if (Value > Stop) +// //{ +// // Value = Stop; +// //} +// //if (Value < Start) +// //{ +// // Value = Start; +// //} // sprintf(szTmp2,"0x%X",Value); -// if (strcmp(szTmp,szTmp2) != 0) { +// if (strcmp(szTmp,szTmp2) != 0) +// { // SetDlgItemText(hDlg,LOWORD(wParam),szTmp2); // if (_this->SelStop == 0) { _this->SelStop = strlen(szTmp2); _this->SelStart = _this->SelStop; } // SendDlgItemMessage(hDlg,LOWORD(wParam),EM_SETSEL,(WPARAM)_this->SelStart,(LPARAM)_this->SelStop); -// } else { +// } +// else +// { // WORD NewSelStart, NewSelStop; // SendDlgItemMessage(hDlg,LOWORD(wParam),EM_GETSEL,(WPARAM)&NewSelStart,(LPARAM)&NewSelStop); -// if (NewSelStart != 0) { _this->SelStart = NewSelStart; _this->SelStop = NewSelStop; } +// if (NewSelStart != 0) +// { +// _this->SelStart = NewSelStart; _this->SelStop = NewSelStop; +// } // } // } // break; diff --git a/Source/Project64/N64 System/Debugger/Debugger - Memory Search.cpp b/Source/Project64/N64 System/Debugger/Debugger - Memory Search.cpp index 2092e5640..ff94e7a33 100644 --- a/Source/Project64/N64 System/Debugger/Debugger - Memory Search.cpp +++ b/Source/Project64/N64 System/Debugger/Debugger - Memory Search.cpp @@ -226,7 +226,9 @@ void CDebugMemorySearch::EnableUnknownOptions( bool Enable ) { ::SetWindowText(GetDlgItem(IDC_BTN_SEARCH), m_HaveResults ? "Search Results" : "Search"); } - } else { + } + else + { ::EnableWindow(GetDlgItem(IDC_UNKNOWN_ALIGN), false ); if (Enable) { @@ -249,8 +251,14 @@ void CDebugMemorySearch::SearchForValue( void ) m_UnknownSize.SetCurSel(m_ValueSize.GetCurSel()); LPCTSTR DisplayStr = "0x%08X"; - if (Size == _16Bit) { DisplayStr = "0x%04X"; } - else if (Size == _8Bit) { DisplayStr = "0x%04X"; } + if (Size == _16Bit) + { + DisplayStr = "0x%04X"; + } + else if (Size == _8Bit) + { + DisplayStr = "0x%04X"; + } if (!m_HaveResults) { @@ -288,7 +296,9 @@ void CDebugMemorySearch::SearchForValue( void ) ::SetWindowText(GetDlgItem(IDC_BTN_SEARCH),"Search Results"); ::ShowWindow(GetDlgItem(IDC_RESET_BUTTON),SW_SHOW); ::EnableWindow(GetDlgItem(IDC_VALUE_ALIGN),false); - } else { + } + else + { int ItemCount = m_SearchResults.GetItemCount(); for (int i = ItemCount - 1; i >= 0; i--) { @@ -298,7 +308,8 @@ void CDebugMemorySearch::SearchForValue( void ) DWORD NewValue = 0; BOOL valid = false; - switch (Size) { + switch (Size) + { case _8Bit: { BYTE mem = 0; @@ -328,7 +339,9 @@ void CDebugMemorySearch::SearchForValue( void ) sprintf(LocationStr,DisplayStr,Result.Value); m_SearchResults.SetItemText(i,3,LocationStr); Result.Value = NewValue; - } else { + } + else + { m_SearchResults.DeleteItem(i); } } @@ -351,8 +364,14 @@ void CDebugMemorySearch::SearchForUnknown() MemorySize Size = (MemorySize)m_UnknownSize.GetItemData(m_UnknownSize.GetCurSel()); m_ValueSize.SetCurSel(m_UnknownSize.GetCurSel()); LPCTSTR DisplayStr = "0x%08X"; - if (Size == _16Bit) { DisplayStr = "0x%04X"; } - else if (Size == _8Bit) { DisplayStr = "0x%04X"; } + if (Size == _16Bit) + { + DisplayStr = "0x%04X"; + } + else if (Size == _8Bit) + { + DisplayStr = "0x%04X"; + } if (!m_HaveResults) { m_HaveResults = true; @@ -411,7 +430,9 @@ void CDebugMemorySearch::SearchForUnknown() ::ShowWindow(GetDlgItem(IDC_RESET_BUTTON),SW_SHOW); ::EnableWindow(GetDlgItem(IDC_RADIO_TEXT),false); ::EnableWindow(GetDlgItem(IDC_RADIO_JAL),false); - } else { + } + else + { int ItemCount = m_SearchResults.GetItemCount(); for (int i = ItemCount - 1; i >= 0; i--) { @@ -422,7 +443,8 @@ void CDebugMemorySearch::SearchForUnknown() DWORD NewValue = 0; BOOL valid = false; - switch (Size) { + switch (Size) + { case _8Bit: { BYTE mem = 0; @@ -482,7 +504,9 @@ void CDebugMemorySearch::SearchForUnknown() sprintf(LocationStr,DisplayStr,Result.Value); m_SearchResults.SetItemText(i,3,LocationStr); Result.Value = NewValue; - } else { + } + else + { m_SearchResults.DeleteItem(i); } } @@ -652,8 +676,14 @@ bool CDebugMemorySearch::SearchForValue (DWORD Value, MemorySize Size, DWORD &St return false; } - if (Size == _32Bit) { StartAddress = ((StartAddress + 3) & ~3); } - if (Size == _16Bit) { StartAddress = ((StartAddress + 1) & ~1); } + if (Size == _32Bit) + { + StartAddress = ((StartAddress + 3) & ~3); + } + if (Size == _16Bit) + { + StartAddress = ((StartAddress + 1) & ~1); + } //search memory if (StartAddress < g_MMU->RdramSize()) @@ -757,4 +787,3 @@ bool CDebugMemorySearch::SearchForValue (DWORD Value, MemorySize Size, DWORD &St } return false; } - diff --git a/Source/Project64/N64 System/Debugger/Debugger - Memory Search.h b/Source/Project64/N64 System/Debugger/Debugger - Memory Search.h index 1ca9fec22..d3a42245e 100644 --- a/Source/Project64/N64 System/Debugger/Debugger - Memory Search.h +++ b/Source/Project64/N64 System/Debugger/Debugger - Memory Search.h @@ -41,7 +41,8 @@ private: SearchChangeState_Lessthan, }; - typedef struct { + typedef struct + { DWORD PAddr; DWORD Value; } SearchResultItem; diff --git a/Source/Project64/N64 System/Debugger/Debugger - TLB.cpp b/Source/Project64/N64 System/Debugger/Debugger - TLB.cpp index 3e5fb4275..4f4037824 100644 --- a/Source/Project64/N64 System/Debugger/Debugger - TLB.cpp +++ b/Source/Project64/N64 System/Debugger/Debugger - TLB.cpp @@ -115,7 +115,8 @@ void CDebugTlb::RefreshTLBWindow (void) int count; CTLB::TLB_ENTRY * tlb = g_TLB->m_tlb; - for (count = 0; count < 32; count ++) { + for (count = 0; count < 32; count ++) + { sprintf(Output,"0x%02X",count); item.mask = LVIF_TEXT; item.iItem = count; @@ -128,66 +129,87 @@ void CDebugTlb::RefreshTLBWindow (void) OldItem.cchTextMax = sizeof( OldText )-1; OldItem.iSubItem = 0; - if (ListView_GetItemCount(hList) <= count) { + if (ListView_GetItemCount(hList) <= count) + { ListView_InsertItem(hList,&item); - } else { + } + else + { ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } } - if (tlb[count].EntryDefined) { + if (tlb[count].EntryDefined) + { sprintf(Output,"0x%08X",tlb[count].PageMask.Value); - } else { + } + else + { strcpy(Output,"................"); } item.iSubItem = 1; OldItem.iSubItem = 1; ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } - if (tlb[count].EntryDefined) { + if (tlb[count].EntryDefined) + { sprintf(Output,"0x%08X",tlb[count].EntryHi.Value); - } else { + } + else + { strcpy(Output,"................"); } item.iSubItem = 2; OldItem.iSubItem = 2; ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } - if (tlb[count].EntryDefined) { + if (tlb[count].EntryDefined) + { sprintf(Output,"0x%08X",tlb[count].EntryLo0.Value); - } else { + } + else + { strcpy(Output,"................"); } item.iSubItem = 3; OldItem.iSubItem = 3; ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } - if (tlb[count].EntryDefined) { + if (tlb[count].EntryDefined) + { sprintf(Output,"0x%08X",tlb[count].EntryLo1.Value); - } else { + } + else + { strcpy(Output,"................"); } item.iSubItem = 4; OldItem.iSubItem = 4; ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } } CTLB::FASTTLB * FastTlb = g_TLB->m_FastTlb; hList = GetDlgItem(IDC_LIST2); - for (count = 0; count < 64; count ++) { + for (count = 0; count < 64; count ++) + { sprintf(Output,"0x%02X",count); item.mask = LVIF_TEXT; item.iItem = count; @@ -200,49 +222,65 @@ void CDebugTlb::RefreshTLBWindow (void) OldItem.cchTextMax = sizeof( OldText )-1; OldItem.iSubItem = 0; - if (ListView_GetItemCount(hList) <= count) { + if (ListView_GetItemCount(hList) <= count) + { item.iItem = ListView_InsertItem(hList,&item); - } else { + } + else + { ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } } - if (FastTlb[count].ValidEntry) { + if (FastTlb[count].ValidEntry) + { sprintf(Output,"%s",FastTlb[count].VALID?"Yes":"No"); - } else { + } + else + { strcpy(Output,"................"); } item.iSubItem = 1; OldItem.iSubItem = 1; ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } - if (FastTlb[count].ValidEntry && FastTlb[count].VALID) { + if (FastTlb[count].ValidEntry && FastTlb[count].VALID) + { sprintf(Output,"%s",FastTlb[count].DIRTY?"Yes":"No"); - } else { + } + else + { strcpy(Output,"................"); } item.iSubItem = 2; OldItem.iSubItem = 2; ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } - if (FastTlb[count].ValidEntry && FastTlb[count].VALID) { + if (FastTlb[count].ValidEntry && FastTlb[count].VALID) + { sprintf(Output,"%08X:%08X -> %08X:%08X",FastTlb[count].VSTART,FastTlb[count].VEND, FastTlb[count].PHYSSTART,FastTlb[count].PHYSEND); - } else { + } + else + { strcpy(Output,"................"); } item.iSubItem = 3; OldItem.iSubItem = 3; ListView_GetItem(hList,&OldItem); - if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) { + if ( strcmp( item.pszText, OldItem.pszText ) != 0 ) + { ListView_SetItem(hList,&item); } } diff --git a/Source/Project64/N64 System/Debugger/Debugger - View Memory.cpp b/Source/Project64/N64 System/Debugger/Debugger - View Memory.cpp index 93f960841..441a973c9 100644 --- a/Source/Project64/N64 System/Debugger/Debugger - View Memory.cpp +++ b/Source/Project64/N64 System/Debugger/Debugger - View Memory.cpp @@ -34,7 +34,8 @@ LRESULT CDebugMemoryView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM memset(m_CompareValid,0,sizeof(m_CompareValid)); HWND hScrlBar = GetDlgItem(IDC_SCRL_BAR); - if (hScrlBar) { + if (hScrlBar) + { SCROLLINFO si; si.cbSize = sizeof(si); @@ -121,7 +122,7 @@ LRESULT CDebugMemoryView::OnDestroy ( void ) LRESULT CDebugMemoryView::OnClicked (WORD /*wNotifyCode*/, WORD wID, HWND , BOOL& /*bHandled*/) { - switch(wID) + switch (wID) { case IDC_REFRSH_MEM: RefreshMemory(true); @@ -162,7 +163,10 @@ LRESULT CDebugMemoryView::OnMemoryModified ( LPNMHDR lpNMHDR ) LPCSTR strValue = m_MemoryList->GetItemText(pListNotify->m_nItem,pListNotify->m_nSubItem); int Finish = strlen(strValue); - if (Finish > 8) { Finish = 8; } + if (Finish > 8) + { + Finish = 8; + } DWORD Value = 0; for (int i = 0; i < Finish; i++) { @@ -206,7 +210,9 @@ LRESULT CDebugMemoryView::OnMemoryModified ( LPNMHDR lpNMHDR ) { WriteTraceF(TraceError,__FUNCTION__ ": failed to store at %X",m_DataStartLoc + Pos); } - } else { + } + else + { if (!g_MMU->SB_PAddr(m_DataStartLoc + Pos,(BYTE)Value)) { WriteTraceF(TraceError,__FUNCTION__ ": failed to store at %X",m_DataStartLoc + Pos); @@ -249,7 +255,9 @@ void CDebugMemoryView::Insert_MemoryLineDump ( int LineNumber ) m_MemoryList->SetItemText(LineNumber,i,"-"); } } - } else { + } + else + { if ( strcmp( Output, m_MemoryList->GetItemText(LineNumber, 0) ) != 0 ) { m_MemoryList->SetItemText(LineNumber,0,Output); @@ -286,11 +294,15 @@ void CDebugMemoryView::Insert_MemoryLineDump ( int LineNumber ) if (m_CurrentData[Pos] < 30) { strcat(Ascii,"."); - } else { + } + else + { sprintf(AsciiAddOn,"%c",m_CurrentData[Pos]); strcat(Ascii,AsciiAddOn); } - } else { + } + else + { m_MemoryList->SetItemText(LineNumber,col,"**"); m_MemoryList->SetItemFormat( LineNumber,col, ITEM_FORMAT_NONE, ITEM_FLAGS_NONE ); m_MemoryList->SetItemColours( LineNumber, col, GetSysColor( COLOR_WINDOW ), GetSysColor( COLOR_WINDOWTEXT ) ); @@ -393,7 +405,9 @@ void CDebugMemoryView::RefreshMemory ( bool ResetCompare ) { ValidData = false; } - } else { + } + else + { if (!g_MMU->LW_PAddr(m_DataStartLoc & ~3, word.UW)) { ValidData = false; @@ -428,7 +442,9 @@ void CDebugMemoryView::RefreshMemory ( bool ResetCompare ) { ValidData = false; } - } else { + } + else + { if (!g_MMU->LW_PAddr(Pos, word.UW)) { ValidData = false; @@ -449,7 +465,8 @@ void CDebugMemoryView::RefreshMemory ( bool ResetCompare ) } } - for (int count = 0 ; count < 16;count ++ ){ + for (int count = 0 ; count < 16;count ++) + { Insert_MemoryLineDump ( count ); } } diff --git a/Source/Project64/N64 System/Debugger/Debugger UI.h b/Source/Project64/N64 System/Debugger/Debugger UI.h index d4e1d4e18..0884e6cf4 100644 --- a/Source/Project64/N64 System/Debugger/Debugger UI.h +++ b/Source/Project64/N64 System/Debugger/Debugger UI.h @@ -44,5 +44,3 @@ #include "Debugger - View Memory.h" #include "Debugger - Memory Dump.h" #include "Debugger - TLB.h" - - diff --git a/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp b/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp index b98c24d15..1efee0932 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp +++ b/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp @@ -17,18 +17,22 @@ void ExecuteInterpreterOps (DWORD /*Cycles*/) g_Notify->BreakPoint(__FILEW__,__LINE__); } -bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) { +bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) +{ OPCODE Command; - if (!g_MMU->LW_VAddr(PC + 4, Command.Hex)) { + if (!g_MMU->LW_VAddr(PC + 4, Command.Hex)) + { //g_Notify->DisplayError(L"Failed to load word 2"); //ExitThread(0); return TRUE; } - switch (Command.op) { + switch (Command.op) + { case R4300i_SPECIAL: - switch (Command.funct) { + switch (Command.funct) + { case R4300i_SPECIAL_SLL: case R4300i_SPECIAL_SRL: case R4300i_SPECIAL_SRA: @@ -62,9 +66,18 @@ bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) { case R4300i_SPECIAL_DSLL32: case R4300i_SPECIAL_DSRL32: case R4300i_SPECIAL_DSRA32: - if (Command.rd == 0) { return FALSE; } - if (Command.rd == Reg1) { return TRUE; } - if (Command.rd == Reg2) { return TRUE; } + if (Command.rd == 0) + { + return FALSE; + } + if (Command.rd == Reg1) + { + return TRUE; + } + if (Command.rd == Reg2) + { + return TRUE; + } break; case R4300i_SPECIAL_MULT: case R4300i_SPECIAL_MULTU: @@ -84,16 +97,28 @@ bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) { } break; case R4300i_CP0: - switch (Command.rs) { + switch (Command.rs) + { case R4300i_COP0_MT: break; case R4300i_COP0_MF: - if (Command.rt == 0) { return FALSE; } - if (Command.rt == Reg1) { return TRUE; } - if (Command.rt == Reg2) { return TRUE; } + if (Command.rt == 0) + { + return FALSE; + } + if (Command.rt == Reg1) + { + return TRUE; + } + if (Command.rt == Reg2) + { + return TRUE; + } break; default: - if ( (Command.rs & 0x10 ) != 0 ) { - switch( Command.funct ) { + if ( (Command.rs & 0x10 ) != 0 ) + { + switch ( Command.funct ) + { case R4300i_COP0_CO_TLBR: break; case R4300i_COP0_CO_TLBWI: break; case R4300i_COP0_CO_TLBWR: break; @@ -105,7 +130,9 @@ bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) { } return TRUE; } - } else { + } + else + { if (g_Settings->LoadBool(Debugger_Enabled)) { g_Notify->DisplayError(L"Does %s effect Delay slot at %X?\n7",R4300iOpcodeName(Command.Hex,PC+4), PC); @@ -115,11 +142,21 @@ bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) { } break; case R4300i_CP1: - switch (Command.fmt) { + switch (Command.fmt) + { case R4300i_COP1_MF: - if (Command.rt == 0) { return FALSE; } - if (Command.rt == Reg1) { return TRUE; } - if (Command.rt == Reg2) { return TRUE; } + if (Command.rt == 0) + { + return FALSE; + } + if (Command.rt == Reg1) + { + return TRUE; + } + if (Command.rt == Reg2) + { + return TRUE; + } break; case R4300i_COP1_CF: break; case R4300i_COP1_MT: break; @@ -158,9 +195,18 @@ bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) { case R4300i_LD: case R4300i_LWC1: case R4300i_LDC1: - if (Command.rt == 0) { return FALSE; } - if (Command.rt == Reg1) { return TRUE; } - if (Command.rt == Reg2) { return TRUE; } + if (Command.rt == 0) + { + return FALSE; + } + if (Command.rt == Reg1) + { + return TRUE; + } + if (Command.rt == Reg2) + { + return TRUE; + } break; case R4300i_CACHE: break; case R4300i_SB: break; @@ -181,7 +227,7 @@ bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2) { return FALSE; } -void CInterpreterCPU::BuildCPU (void ) +void CInterpreterCPU::BuildCPU (void) { R4300iOp::m_TestTimer = FALSE; R4300iOp::m_NextInstruction = NORMAL; @@ -190,14 +236,20 @@ void CInterpreterCPU::BuildCPU (void ) if (g_Settings->LoadBool(Game_32Bit)) { m_R4300i_Opcode = R4300iOp32::BuildInterpreter(); - } else { + } + else + { m_R4300i_Opcode = R4300iOp::BuildInterpreter(); } } -void CInterpreterCPU::InPermLoop (void) { +void CInterpreterCPU::InPermLoop (void) +{ // *** Changed ***/ - //if (CPU_Type == CPU_SyncCores) { SyncRegisters.CP0[9] +=5; } + //if (CPU_Type == CPU_SyncCores) + //{ + // SyncRegisters.CP0[9] +=5; + //} /* Interrupts enabled */ if (( g_Reg->STATUS_REGISTER & STATUS_IE ) == 0 || @@ -205,21 +257,27 @@ void CInterpreterCPU::InPermLoop (void) { ( g_Reg->STATUS_REGISTER & STATUS_ERL ) != 0 || ( g_Reg->STATUS_REGISTER & 0xFF00) == 0) { - if (g_Plugins->Gfx()->UpdateScreen != NULL) { g_Plugins->Gfx()->UpdateScreen(); } + if (g_Plugins->Gfx()->UpdateScreen != NULL) + { + g_Plugins->Gfx()->UpdateScreen(); + } //CurrentFrame = 0; //CurrentPercent = 0; //DisplayFPS(); g_Notify->DisplayError(GS(MSG_PERM_LOOP)); g_System->CloseCpu(); - } else { - if (*g_NextTimer > 0) { + } + else + { + if (*g_NextTimer > 0) + { *g_NextTimer = 0 - g_System->CountPerOp(); g_SystemTimer->UpdateTimers(); } } } -void CInterpreterCPU::ExecuteCPU (void ) +void CInterpreterCPU::ExecuteCPU (void) { bool & Done = g_System->m_EndEmulation; DWORD & PROGRAM_COUNTER = *_PROGRAM_COUNTER; @@ -232,7 +290,7 @@ void CInterpreterCPU::ExecuteCPU (void ) __try { - while(!Done) + while (!Done) { if (g_MMU->LW_VAddr(PROGRAM_COUNTER, Opcode.Hex)) { @@ -290,12 +348,15 @@ void CInterpreterCPU::ExecuteCPU (void ) default: g_Notify->BreakPoint(__FILEW__,__LINE__); } - } else { + } + else + { g_Reg->DoTLBReadMiss(R4300iOp::m_NextInstruction == JUMP,PROGRAM_COUNTER); R4300iOp::m_NextInstruction = NORMAL; } } - } __except( g_MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) { + } __except( g_MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) + { g_Notify->DisplayError(GS(MSG_UNKNOWN_MEM_ACTION)); ExitThread(0); } @@ -314,7 +375,7 @@ void CInterpreterCPU::ExecuteOps ( int Cycles ) __try { - while(!Done) + while (!Done) { if (Cycles <= 0) { @@ -397,12 +458,15 @@ void CInterpreterCPU::ExecuteOps ( int Cycles ) default: g_Notify->BreakPoint(__FILEW__,__LINE__); } - } else { + } + else + { g_Reg->DoTLBReadMiss(R4300iOp::m_NextInstruction == JUMP,PROGRAM_COUNTER); R4300iOp::m_NextInstruction = NORMAL; } } - } __except( g_MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) { + } __except( g_MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) + { g_Notify->DisplayError(GS(MSG_UNKNOWN_MEM_ACTION)); ExitThread(0); } diff --git a/Source/Project64/N64 System/Interpreter/Interpreter Ops 32.cpp b/Source/Project64/N64 System/Interpreter/Interpreter Ops 32.cpp index a691f7a6c..6c1e1967a 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter Ops 32.cpp +++ b/Source/Project64/N64 System/Interpreter/Interpreter Ops 32.cpp @@ -628,7 +628,8 @@ R4300iOp32::Func * R4300iOp32::BuildInterpreter (void ) /************************* Opcode functions *************************/ -void R4300iOp32::JAL (void) { +void R4300iOp32::JAL (void) +{ m_NextInstruction = DELAY_SLOT; m_JumpToLocation = ((*_PROGRAM_COUNTER) & 0xF0000000) + (m_Opcode.target << 2); _GPR[31].UW[0] = (*_PROGRAM_COUNTER) + 8; @@ -639,9 +640,11 @@ void R4300iOp32::JAL (void) { } } -void R4300iOp32::BEQ (void) { +void R4300iOp32::BEQ (void) +{ m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].W[0] == _GPR[m_Opcode.rt].W[0]) { + if (_GPR[m_Opcode.rs].W[0] == _GPR[m_Opcode.rt].W[0]) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -650,14 +653,18 @@ void R4300iOp32::BEQ (void) { m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::BNE (void) { +void R4300iOp32::BNE (void) +{ m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].W[0] != _GPR[m_Opcode.rt].W[0]) { + if (_GPR[m_Opcode.rs].W[0] != _GPR[m_Opcode.rt].W[0]) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -666,14 +673,17 @@ void R4300iOp32::BNE (void) { m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } void R4300iOp32::BLEZ (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].W[0] <= 0) { + if (_GPR[m_Opcode.rs].W[0] <= 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -682,14 +692,18 @@ void R4300iOp32::BLEZ (void) { m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::BGTZ (void) { +void R4300iOp32::BGTZ (void) +{ m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].W[0] > 0) { + if (_GPR[m_Opcode.rs].W[0] > 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -698,48 +712,61 @@ void R4300iOp32::BGTZ (void) { m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::ADDI (void) { +void R4300iOp32::ADDI (void) +{ #ifdef Interpreter_StackTest - if (m_Opcode.rs == 29 && m_Opcode.rt == 29) { + if (m_Opcode.rs == 29 && m_Opcode.rt == 29) + { StackValue += (short)m_Opcode.immediate; } #endif _GPR[m_Opcode.rt].W[0] = (_GPR[m_Opcode.rs].W[0] + ((short)m_Opcode.immediate)); #ifdef Interpreter_StackTest - if (m_Opcode.rt == 29 && m_Opcode.rs != 29) { + if (m_Opcode.rt == 29 && m_Opcode.rs != 29) + { StackValue = _GPR[m_Opcode.rt].W[0]; } #endif } -void R4300iOp32::ADDIU (void) { +void R4300iOp32::ADDIU (void) +{ #ifdef Interpreter_StackTest - if (m_Opcode.rs == 29 && m_Opcode.rt == 29) { + if (m_Opcode.rs == 29 && m_Opcode.rt == 29) + { StackValue += (short)m_Opcode.immediate; } #endif _GPR[m_Opcode.rt].W[0] = (_GPR[m_Opcode.rs].W[0] + ((short)m_Opcode.immediate)); #ifdef Interpreter_StackTest - if (m_Opcode.rt == 29 && m_Opcode.rs != 29) { + if (m_Opcode.rt == 29 && m_Opcode.rs != 29) + { StackValue = _GPR[m_Opcode.rt].W[0]; } #endif } -void R4300iOp32::SLTI (void) { - if (_GPR[m_Opcode.rs].W[0] < (__int64)((short)m_Opcode.immediate)) { +void R4300iOp32::SLTI (void) +{ + if (_GPR[m_Opcode.rs].W[0] < (__int64)((short)m_Opcode.immediate)) + { _GPR[m_Opcode.rt].W[0] = 1; - } else { + } + else + { _GPR[m_Opcode.rt].W[0] = 0; } } -void R4300iOp32::SLTIU (void) { +void R4300iOp32::SLTIU (void) +{ int imm32 = (short)m_Opcode.immediate; __int64 imm64; @@ -747,29 +774,36 @@ void R4300iOp32::SLTIU (void) { _GPR[m_Opcode.rt].W[0] = _GPR[m_Opcode.rs].UW[0] < (unsigned __int64)imm64?1:0; } -void R4300iOp32::ANDI (void) { +void R4300iOp32::ANDI (void) +{ _GPR[m_Opcode.rt].W[0] = _GPR[m_Opcode.rs].W[0] & m_Opcode.immediate; } -void R4300iOp32::ORI (void) { +void R4300iOp32::ORI (void) +{ _GPR[m_Opcode.rt].W[0] = _GPR[m_Opcode.rs].W[0] | m_Opcode.immediate; } -void R4300iOp32::XORI (void) { +void R4300iOp32::XORI (void) +{ _GPR[m_Opcode.rt].W[0] = _GPR[m_Opcode.rs].W[0] ^ m_Opcode.immediate; } -void R4300iOp32::LUI (void) { +void R4300iOp32::LUI (void) +{ _GPR[m_Opcode.rt].W[0] = (long)((short)m_Opcode.offset << 16); #ifdef Interpreter_StackTest - if (m_Opcode.rt == 29) { + if (m_Opcode.rt == 29) + { StackValue = _GPR[m_Opcode.rt].W[0]; } #endif } -void R4300iOp32::BEQL (void) { - if (_GPR[m_Opcode.rs].W[0] == _GPR[m_Opcode.rt].W[0]) { +void R4300iOp32::BEQL (void) +{ + if (_GPR[m_Opcode.rs].W[0] == _GPR[m_Opcode.rt].W[0]) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -779,14 +813,18 @@ void R4300iOp32::BEQL (void) { m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::BNEL (void) { - if (_GPR[m_Opcode.rs].W[0] != _GPR[m_Opcode.rt].W[0]) { +void R4300iOp32::BNEL (void) +{ + if (_GPR[m_Opcode.rs].W[0] != _GPR[m_Opcode.rt].W[0]) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -796,14 +834,18 @@ void R4300iOp32::BNEL (void) { m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::BLEZL (void) { - if (_GPR[m_Opcode.rs].W[0] <= 0) { +void R4300iOp32::BLEZL (void) +{ + if (_GPR[m_Opcode.rs].W[0] <= 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -813,14 +855,18 @@ void R4300iOp32::BLEZL (void) { m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::BGTZL (void) { - if (_GPR[m_Opcode.rs].W[0] > 0) { +void R4300iOp32::BGTZL (void) +{ + if (_GPR[m_Opcode.rs].W[0] > 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -830,38 +876,54 @@ void R4300iOp32::BGTZL (void) { m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::LB (void) { +void R4300iOp32::LB (void) +{ DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if (!g_MMU->LB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LB TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].W[0] = _GPR[m_Opcode.rt].B[0]; } } -void R4300iOp32::LH (void) { +void R4300iOp32::LH (void) +{ DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 1) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } - if (!g_MMU->LH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) { - if (bShowTLBMisses()) { + if ((Address & 1) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } + if (!g_MMU->LH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LH TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].W[0] = _GPR[m_Opcode.rt].HW[0]; } } -void R4300iOp32::LWL (void) { +void R4300iOp32::LWL (void) +{ DWORD Offset, Address, Value; Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; @@ -869,7 +931,8 @@ void R4300iOp32::LWL (void) { if (!g_MMU->LW_VAddr((Address & ~3),Value)) { - if (bShowTLBMisses()) { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LWL TLB: %X",Address); } TLB_READ_EXCEPTION(Address); @@ -880,51 +943,73 @@ void R4300iOp32::LWL (void) { _GPR[m_Opcode.rt].W[0] += (int)(Value << LWL_SHIFT[Offset]); } -void R4300iOp32::LW (void) { +void R4300iOp32::LW (void) +{ DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } if (LogOptions.GenerateLog) { Log_LW((*_PROGRAM_COUNTER),Address); } - if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LW TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].W[0] = _GPR[m_Opcode.rt].W[0]; } } -void R4300iOp32::LBU (void) { +void R4300iOp32::LBU (void) +{ DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if (!g_MMU->LB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LBU TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].UW[0] = _GPR[m_Opcode.rt].UB[0]; } } -void R4300iOp32::LHU (void) { +void R4300iOp32::LHU (void) +{ DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 1) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } - if (!g_MMU->LH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) { - if (bShowTLBMisses()) { + if ((Address & 1) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } + if (!g_MMU->LH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LHU TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].UW[0] = _GPR[m_Opcode.rt].UHW[0]; } } -void R4300iOp32::LWR (void) { +void R4300iOp32::LWR (void) +{ DWORD Offset, Address, Value; Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; @@ -944,118 +1029,158 @@ void R4300iOp32::LWR (void) { _GPR[m_Opcode.rt].W[0] += (int)(Value >> LWR_SHIFT[Offset]); } -void R4300iOp32::LWU (void) { +void R4300iOp32::LWU (void) +{ DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } - if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LWU TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].UW[0] = _GPR[m_Opcode.rt].UW[0]; } } -void R4300iOp32::LL (void) { +void R4300iOp32::LL (void) +{ DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } - if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LL TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].W[0] = _GPR[m_Opcode.rt].W[0]; (*_LLBit) = 1; } } /********************** R4300i OpCodes: Special **********************/ -void R4300iOp32::SPECIAL_SLL (void) { +void R4300iOp32::SPECIAL_SLL (void) +{ _GPR[m_Opcode.rd].W[0] = (_GPR[m_Opcode.rt].W[0] << m_Opcode.sa); } -void R4300iOp32::SPECIAL_SRL (void) { +void R4300iOp32::SPECIAL_SRL (void) +{ _GPR[m_Opcode.rd].W[0] = (int)(_GPR[m_Opcode.rt].UW[0] >> m_Opcode.sa); } -void R4300iOp32::SPECIAL_SRA (void) { +void R4300iOp32::SPECIAL_SRA (void) +{ _GPR[m_Opcode.rd].W[0] = (_GPR[m_Opcode.rt].W[0] >> m_Opcode.sa); } -void R4300iOp32::SPECIAL_SLLV (void) { +void R4300iOp32::SPECIAL_SLLV (void) +{ _GPR[m_Opcode.rd].W[0] = (_GPR[m_Opcode.rt].W[0] << (_GPR[m_Opcode.rs].UW[0] & 0x1F)); } -void R4300iOp32::SPECIAL_SRLV (void) { +void R4300iOp32::SPECIAL_SRLV (void) +{ _GPR[m_Opcode.rd].W[0] = (int)(_GPR[m_Opcode.rt].UW[0] >> (_GPR[m_Opcode.rs].UW[0] & 0x1F)); } -void R4300iOp32::SPECIAL_SRAV (void) { +void R4300iOp32::SPECIAL_SRAV (void) +{ _GPR[m_Opcode.rd].W[0] = (_GPR[m_Opcode.rt].W[0] >> (_GPR[m_Opcode.rs].UW[0] & 0x1F)); } -void R4300iOp32::SPECIAL_JALR (void) { +void R4300iOp32::SPECIAL_JALR (void) +{ m_NextInstruction = DELAY_SLOT; m_JumpToLocation = _GPR[m_Opcode.rs].UW[0]; _GPR[m_Opcode.rd].W[0] = (long)((*_PROGRAM_COUNTER) + 8); m_TestTimer = TRUE; } -void R4300iOp32::SPECIAL_ADD (void) { +void R4300iOp32::SPECIAL_ADD (void) +{ _GPR[m_Opcode.rd].W[0] = _GPR[m_Opcode.rs].W[0] + _GPR[m_Opcode.rt].W[0]; } -void R4300iOp32::SPECIAL_ADDU (void) { +void R4300iOp32::SPECIAL_ADDU (void) +{ _GPR[m_Opcode.rd].W[0] = _GPR[m_Opcode.rs].W[0] + _GPR[m_Opcode.rt].W[0]; } -void R4300iOp32::SPECIAL_SUB (void) { +void R4300iOp32::SPECIAL_SUB (void) +{ _GPR[m_Opcode.rd].W[0] = _GPR[m_Opcode.rs].W[0] - _GPR[m_Opcode.rt].W[0]; } -void R4300iOp32::SPECIAL_SUBU (void) { +void R4300iOp32::SPECIAL_SUBU (void) +{ _GPR[m_Opcode.rd].W[0] = _GPR[m_Opcode.rs].W[0] - _GPR[m_Opcode.rt].W[0]; } -void R4300iOp32::SPECIAL_AND (void) { +void R4300iOp32::SPECIAL_AND (void) +{ _GPR[m_Opcode.rd].W[0] = _GPR[m_Opcode.rs].W[0] & _GPR[m_Opcode.rt].W[0]; } -void R4300iOp32::SPECIAL_OR (void) { +void R4300iOp32::SPECIAL_OR (void) +{ _GPR[m_Opcode.rd].W[0] = _GPR[m_Opcode.rs].W[0] | _GPR[m_Opcode.rt].W[0]; #ifdef Interpreter_StackTest - if (m_Opcode.rd == 29) { + if (m_Opcode.rd == 29) + { StackValue = _GPR[m_Opcode.rd].W[0]; } #endif } -void R4300iOp32::SPECIAL_NOR (void) { +void R4300iOp32::SPECIAL_NOR (void) +{ _GPR[m_Opcode.rd].W[0] = ~(_GPR[m_Opcode.rs].W[0] | _GPR[m_Opcode.rt].W[0]); } -void R4300iOp32::SPECIAL_SLT (void) { - if (_GPR[m_Opcode.rs].W[0] < _GPR[m_Opcode.rt].W[0]) { +void R4300iOp32::SPECIAL_SLT (void) +{ + if (_GPR[m_Opcode.rs].W[0] < _GPR[m_Opcode.rt].W[0]) + { _GPR[m_Opcode.rd].W[0] = 1; - } else { + } + else + { _GPR[m_Opcode.rd].W[0] = 0; } } -void R4300iOp32::SPECIAL_SLTU (void) { - if (_GPR[m_Opcode.rs].UW[0] < _GPR[m_Opcode.rt].UW[0]) { +void R4300iOp32::SPECIAL_SLTU (void) +{ + if (_GPR[m_Opcode.rs].UW[0] < _GPR[m_Opcode.rt].UW[0]) + { _GPR[m_Opcode.rd].W[0] = 1; - } else { + } + else + { _GPR[m_Opcode.rd].W[0] = 0; } } -void R4300iOp32::SPECIAL_TEQ (void) { +void R4300iOp32::SPECIAL_TEQ (void) +{ if (_GPR[m_Opcode.rs].W[0] == _GPR[m_Opcode.rt].W[0] && g_Settings->LoadBool(Debugger_Enabled)) { g_Notify->DisplayError(L"Should trap this ???"); @@ -1073,9 +1198,11 @@ void R4300iOp32::SPECIAL_DSRA32 (void) } /********************** R4300i OpCodes: RegImm **********************/ -void R4300iOp32::REGIMM_BLTZ (void) { +void R4300iOp32::REGIMM_BLTZ (void) +{ m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].W[0] < 0) { + if (_GPR[m_Opcode.rs].W[0] < 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -1084,14 +1211,18 @@ void R4300iOp32::REGIMM_BLTZ (void) { CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::REGIMM_BGEZ (void) { +void R4300iOp32::REGIMM_BGEZ (void) +{ m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].W[0] >= 0) { + if (_GPR[m_Opcode.rs].W[0] >= 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -1100,13 +1231,17 @@ void R4300iOp32::REGIMM_BGEZ (void) { CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::REGIMM_BLTZL (void) { - if (_GPR[m_Opcode.rs].W[0] < 0) { +void R4300iOp32::REGIMM_BLTZL (void) +{ + if (_GPR[m_Opcode.rs].W[0] < 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -1116,14 +1251,18 @@ void R4300iOp32::REGIMM_BLTZL (void) { CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::REGIMM_BGEZL (void) { - if (_GPR[m_Opcode.rs].W[0] >= 0) { +void R4300iOp32::REGIMM_BGEZL (void) +{ + if (_GPR[m_Opcode.rs].W[0] >= 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -1133,15 +1272,19 @@ void R4300iOp32::REGIMM_BGEZL (void) { CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } -void R4300iOp32::REGIMM_BLTZAL (void) { +void R4300iOp32::REGIMM_BLTZAL (void) +{ m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].W[0] < 0) { + if (_GPR[m_Opcode.rs].W[0] < 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -1150,15 +1293,19 @@ void R4300iOp32::REGIMM_BLTZAL (void) { CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } _GPR[31].W[0]= (long)((*_PROGRAM_COUNTER) + 8); } -void R4300iOp32::REGIMM_BGEZAL (void) { +void R4300iOp32::REGIMM_BGEZAL (void) +{ m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].W[0] >= 0) { + if (_GPR[m_Opcode.rs].W[0] >= 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -1167,7 +1314,9 @@ void R4300iOp32::REGIMM_BGEZAL (void) { CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } _GPR[31].W[0] = (long)((*_PROGRAM_COUNTER) + 8); @@ -1186,16 +1335,19 @@ void R4300iOp32::COP0_MF (void) { _GPR[m_Opcode.rt].W[0] = (int)_CP0[m_Opcode.rd]; } -void R4300iOp32::COP0_MT (void) { +void R4300iOp32::COP0_MT (void) +{ if (LogOptions.LogCP0changes) { LogMessage("%08X: Writing 0x%X to %s register (Originally: 0x%08X)",(*_PROGRAM_COUNTER), _GPR[m_Opcode.rt].UW[0],CRegName::Cop0[m_Opcode.rd], _CP0[m_Opcode.rd]); - if (m_Opcode.rd == 11) { //Compare + if (m_Opcode.rd == 11) //Compare + { LogMessage("%08X: Cause register changed from %08X to %08X",(*_PROGRAM_COUNTER), g_Reg->CAUSE_REGISTER, (g_Reg->CAUSE_REGISTER & ~CAUSE_IP7)); } } - switch (m_Opcode.rd) { + switch (m_Opcode.rd) + { case 0: //Index case 2: //EntryLo0 case 3: //EntryLo1 @@ -1229,10 +1381,13 @@ void R4300iOp32::COP0_MT (void) { g_SystemTimer->UpdateCompareTimer(); break; case 12: //Status - if ((_CP0[m_Opcode.rd] & STATUS_FR) != (_GPR[m_Opcode.rt].UW[0] & STATUS_FR)) { + if ((_CP0[m_Opcode.rd] & STATUS_FR) != (_GPR[m_Opcode.rt].UW[0] & STATUS_FR)) + { _CP0[m_Opcode.rd] = _GPR[m_Opcode.rt].UW[0]; g_Reg->FixFpuLocations(); - } else { + } + else + { _CP0[m_Opcode.rd] = _GPR[m_Opcode.rt].UW[0]; } if ((_CP0[m_Opcode.rd] & 0x18) != 0 && g_Settings->LoadBool(Debugger_Enabled)) @@ -1254,12 +1409,14 @@ void R4300iOp32::COP0_MT (void) { } /************************** COP1 functions **************************/ -void R4300iOp32::COP1_MF (void) { +void R4300iOp32::COP1_MF (void) +{ TEST_COP1_USABLE_EXCEPTION _GPR[m_Opcode.rt].W[0] = *(int *)_FPR_S[m_Opcode.fs]; } -void R4300iOp32::COP1_CF (void) { +void R4300iOp32::COP1_CF (void) +{ TEST_COP1_USABLE_EXCEPTION if (m_Opcode.fs != 31 && m_Opcode.fs != 0) { @@ -1269,8 +1426,8 @@ void R4300iOp32::COP1_CF (void) { _GPR[m_Opcode.rt].W[0] = (int)_FPCR[m_Opcode.fs]; } -void R4300iOp32::COP1_DMT (void) { +void R4300iOp32::COP1_DMT (void) +{ TEST_COP1_USABLE_EXCEPTION *(__int64 *)_FPR_D[m_Opcode.fs] = _GPR[m_Opcode.rt].W[0]; } - diff --git a/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp b/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp index 1d4ead132..617b6e20a 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp +++ b/Source/Project64/N64 System/Interpreter/Interpreter Ops.cpp @@ -37,7 +37,7 @@ const DWORD R4300iOp::LWL_MASK[4] = { 0x00000000, 0x000000FF,0x0000FFFF,0x00FFF const DWORD R4300iOp::LWR_MASK[4] = { 0xFFFFFF00, 0xFFFF0000,0xFF000000,0x0000000 }; const int R4300iOp::SWL_SHIFT[4] = { 0, 8, 16, 24 }; -const int R4300iOp::SWR_SHIFT[4] = { 24, 16 , 8, 0 }; +const int R4300iOp::SWR_SHIFT[4] = { 24, 16 , 8, 0 }; const int R4300iOp::LWL_SHIFT[4] = { 0, 8, 16, 24}; const int R4300iOp::LWR_SHIFT[4] = { 24, 16 ,8, 0 }; @@ -710,8 +710,14 @@ bool DelaySlotEffectsCompare (DWORD PC, DWORD Reg1, DWORD Reg2); void TestInterpreterJump (DWORD PC, DWORD TargetPC, int Reg1, int Reg2) { - if (PC != TargetPC) { return; } - if (DelaySlotEffectsCompare(PC,Reg1,Reg2)) { return; } + if (PC != TargetPC) + { + return; + } + if (DelaySlotEffectsCompare(PC,Reg1,Reg2)) + { + return; + } R4300iOp::m_NextInstruction = PERMLOOP_DO_DELAY; R4300iOp::m_TestTimer = TRUE; } @@ -742,7 +748,8 @@ void R4300iOp::JAL (void) void R4300iOp::BEQ (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].DW == _GPR[m_Opcode.rt].DW) { + if (_GPR[m_Opcode.rs].DW == _GPR[m_Opcode.rt].DW) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -751,7 +758,9 @@ void R4300iOp::BEQ (void) m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } @@ -759,7 +768,8 @@ void R4300iOp::BEQ (void) void R4300iOp::BNE (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].DW != _GPR[m_Opcode.rt].DW) { + if (_GPR[m_Opcode.rs].DW != _GPR[m_Opcode.rt].DW) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -768,7 +778,9 @@ void R4300iOp::BNE (void) m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } @@ -776,7 +788,8 @@ void R4300iOp::BNE (void) void R4300iOp::BLEZ (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].DW <= 0) { + if (_GPR[m_Opcode.rs].DW <= 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -785,7 +798,9 @@ void R4300iOp::BLEZ (void) m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } @@ -793,7 +808,8 @@ void R4300iOp::BLEZ (void) void R4300iOp::BGTZ (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].DW > 0) { + if (_GPR[m_Opcode.rs].DW > 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -802,7 +818,9 @@ void R4300iOp::BGTZ (void) m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } @@ -810,13 +828,15 @@ void R4300iOp::BGTZ (void) void R4300iOp::ADDI (void) { #ifdef Interpreter_StackTest - if (m_Opcode.rs == 29 && m_Opcode.rt == 29) { + if (m_Opcode.rs == 29 && m_Opcode.rt == 29) + { StackValue += (short)m_Opcode.immediate; } #endif _GPR[m_Opcode.rt].DW = (_GPR[m_Opcode.rs].W[0] + ((short)m_Opcode.immediate)); #ifdef Interpreter_StackTest - if (m_Opcode.rt == 29 && m_Opcode.rs != 29) { + if (m_Opcode.rt == 29 && m_Opcode.rs != 29) + { StackValue = _GPR[m_Opcode.rt].W[0]; } #endif @@ -825,13 +845,15 @@ void R4300iOp::ADDI (void) void R4300iOp::ADDIU (void) { #ifdef Interpreter_StackTest - if (m_Opcode.rs == 29 && m_Opcode.rt == 29) { + if (m_Opcode.rs == 29 && m_Opcode.rt == 29) + { StackValue += (short)m_Opcode.immediate; } #endif _GPR[m_Opcode.rt].DW = (_GPR[m_Opcode.rs].W[0] + ((short)m_Opcode.immediate)); #ifdef Interpreter_StackTest - if (m_Opcode.rt == 29 && m_Opcode.rs != 29) { + if (m_Opcode.rt == 29 && m_Opcode.rs != 29) + { StackValue = _GPR[m_Opcode.rt].W[0]; } #endif @@ -839,9 +861,12 @@ void R4300iOp::ADDIU (void) void R4300iOp::SLTI (void) { - if (_GPR[m_Opcode.rs].DW < (__int64)((short)m_Opcode.immediate)) { + if (_GPR[m_Opcode.rs].DW < (__int64)((short)m_Opcode.immediate)) + { _GPR[m_Opcode.rt].DW = 1; - } else { + } + else + { _GPR[m_Opcode.rt].DW = 0; } } @@ -874,7 +899,8 @@ void R4300iOp::LUI (void) { _GPR[m_Opcode.rt].DW = (long)((short)m_Opcode.offset << 16); #ifdef Interpreter_StackTest - if (m_Opcode.rt == 29) { + if (m_Opcode.rt == 29) + { StackValue = _GPR[m_Opcode.rt].W[0]; } #endif @@ -882,7 +908,8 @@ void R4300iOp::LUI (void) void R4300iOp::BEQL (void) { - if (_GPR[m_Opcode.rs].DW == _GPR[m_Opcode.rt].DW) { + if (_GPR[m_Opcode.rs].DW == _GPR[m_Opcode.rt].DW) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -892,7 +919,9 @@ void R4300iOp::BEQL (void) m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } @@ -900,7 +929,8 @@ void R4300iOp::BEQL (void) void R4300iOp::BNEL (void) { - if (_GPR[m_Opcode.rs].DW != _GPR[m_Opcode.rt].DW) { + if (_GPR[m_Opcode.rs].DW != _GPR[m_Opcode.rt].DW) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -910,7 +940,9 @@ void R4300iOp::BNEL (void) m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } @@ -918,7 +950,8 @@ void R4300iOp::BNEL (void) void R4300iOp::BLEZL (void) { - if (_GPR[m_Opcode.rs].DW <= 0) { + if (_GPR[m_Opcode.rs].DW <= 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -928,7 +961,9 @@ void R4300iOp::BLEZL (void) m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } @@ -936,7 +971,8 @@ void R4300iOp::BLEZL (void) void R4300iOp::BGTZL (void) { - if (_GPR[m_Opcode.rs].DW > 0) { + if (_GPR[m_Opcode.rs].DW > 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -946,7 +982,9 @@ void R4300iOp::BGTZL (void) m_NextInstruction = PERMLOOP_DO_DELAY; } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } @@ -1014,12 +1052,16 @@ void R4300iOp::LDR (void) void R4300iOp::LB (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if (!g_MMU->LB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LB TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].DW = _GPR[m_Opcode.rt].B[0]; } } @@ -1027,13 +1069,20 @@ void R4300iOp::LB (void) void R4300iOp::LH (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 1) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } - if (!g_MMU->LH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) { - if (bShowTLBMisses()) { + if ((Address & 1) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } + if (!g_MMU->LH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LH TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].DW = _GPR[m_Opcode.rt].HW[0]; } } @@ -1062,19 +1111,26 @@ void R4300iOp::LWL (void) void R4300iOp::LW (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } if (LogOptions.GenerateLog) { Log_LW((*_PROGRAM_COUNTER),Address); } - if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LW TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].DW = _GPR[m_Opcode.rt].W[0]; } } @@ -1082,12 +1138,16 @@ void R4300iOp::LW (void) void R4300iOp::LBU (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if (!g_MMU->LB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LBU TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].UDW = _GPR[m_Opcode.rt].UB[0]; } } @@ -1095,13 +1155,20 @@ void R4300iOp::LBU (void) void R4300iOp::LHU (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 1) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } - if (!g_MMU->LH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) { - if (bShowTLBMisses()) { + if ((Address & 1) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } + if (!g_MMU->LH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LHU TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].UDW = _GPR[m_Opcode.rt].UHW[0]; } } @@ -1130,14 +1197,21 @@ void R4300iOp::LWR (void) void R4300iOp::LWU (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } - if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) { - if (bShowTLBMisses()) { + if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LWU TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].UDW = _GPR[m_Opcode.rt].UW[0]; } } @@ -1145,7 +1219,8 @@ void R4300iOp::LWU (void) void R4300iOp::SB (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if (!g_MMU->SB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) { + if (!g_MMU->SB_VAddr(Address,_GPR[m_Opcode.rt].UB[0])) + { if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); @@ -1160,7 +1235,10 @@ void R4300iOp::SB (void) void R4300iOp::SH (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 1) != 0) { ADDRESS_ERROR_EXCEPTION(Address,FALSE); } + if ((Address & 1) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,FALSE); + } if (!g_MMU->SH_VAddr(Address,_GPR[m_Opcode.rt].UHW[0])) { if (bHaveDebugger()) @@ -1214,7 +1292,10 @@ void R4300iOp::SWL (void) void R4300iOp::SW (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,FALSE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,FALSE); + } if (LogOptions.GenerateLog) { Log_SW((*_PROGRAM_COUNTER),Address,_GPR[m_Opcode.rt].UW[0]); @@ -1238,8 +1319,8 @@ QWORD SDL_MASK[8] = { 0,0xFF00000000000000, 0xFFFFFFFF00000000, 0xFFFFFFFFFF000000, 0xFFFFFFFFFFFF0000, - 0xFFFFFFFFFFFFFF00 - }; + 0xFFFFFFFFFFFFFF00 }; + int SDL_SHIFT[8] = { 0, 8, 16, 24, 32, 40, 48, 56 }; void R4300iOp::SDL (void) @@ -1286,8 +1367,8 @@ QWORD SDR_MASK[8] = { 0x00FFFFFFFFFFFFFF, 0x0000000000FFFFFF, 0x000000000000FFFF, 0x00000000000000FF, - 0x0000000000000000 - }; + 0x0000000000000000 }; + int SDR_SHIFT[8] = { 56,48,40,32,24,16,8,0 }; void R4300iOp::SDR (void) @@ -1365,7 +1446,10 @@ void R4300iOp::SWR (void) void R4300iOp::CACHE (void) { - if (!LogOptions.LogCache) { return; } + if (!LogOptions.LogCache) + { + return; + } LogMessage("%08X: Cache operation %d, 0x%08X", (*_PROGRAM_COUNTER), m_Opcode.rt, _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset ); } @@ -1373,7 +1457,10 @@ void R4300iOp::CACHE (void) void R4300iOp::LL (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } if (!g_MMU->LW_VAddr(Address,_GPR[m_Opcode.rt].UW[0])) { @@ -1382,7 +1469,9 @@ void R4300iOp::LL (void) g_Notify->DisplayError(L"LL TLB: %X",Address); } TLB_READ_EXCEPTION(Address); - } else { + } + else + { _GPR[m_Opcode.rt].DW = _GPR[m_Opcode.rt].W[0]; (*_LLBit) = 1; } @@ -1392,9 +1481,14 @@ void R4300iOp::LWC1 (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (DWORD)((short)m_Opcode.offset); TEST_COP1_USABLE_EXCEPTION - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } - if (!g_MMU->LW_VAddr(Address,*(DWORD *)_FPR_S[m_Opcode.ft])) { - if (bShowTLBMisses()) { + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } + if (!g_MMU->LW_VAddr(Address,*(DWORD *)_FPR_S[m_Opcode.ft])) + { + if (bShowTLBMisses()) + { g_Notify->DisplayError(L"LWC1 TLB: %X",Address); } TLB_READ_EXCEPTION(Address); @@ -1404,7 +1498,10 @@ void R4300iOp::LWC1 (void) void R4300iOp::SC (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,FALSE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,FALSE); + } Log_SW((*_PROGRAM_COUNTER),Address,_GPR[m_Opcode.rt].UW[0]); if ((*_LLBit) == 1) { @@ -1423,7 +1520,10 @@ void R4300iOp::SC (void) void R4300iOp::LD (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 7) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } + if ((Address & 7) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } if (!g_MMU->LD_VAddr(Address,_GPR[m_Opcode.rt].UDW)) { if (bHaveDebugger()) @@ -1437,7 +1537,8 @@ void R4300iOp::LD (void) return; } #ifdef Interpreter_StackTest - if (m_Opcode.rt == 29) { + if (m_Opcode.rt == 29) + { StackValue = _GPR[m_Opcode.rt].W[0]; } #endif @@ -1449,7 +1550,10 @@ void R4300iOp::LDC1 (void) DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; TEST_COP1_USABLE_EXCEPTION - if ((Address & 7) != 0) { ADDRESS_ERROR_EXCEPTION(Address,TRUE); } + if ((Address & 7) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,TRUE); + } if (!g_MMU->LD_VAddr(Address,*(unsigned __int64 *)_FPR_D[m_Opcode.ft])) { if (bHaveDebugger()) @@ -1467,7 +1571,10 @@ void R4300iOp::SWC1 (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; TEST_COP1_USABLE_EXCEPTION - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,FALSE); } + if ((Address & 3) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,FALSE); + } if (!g_MMU->SW_VAddr(Address,*(DWORD *)_FPR_S[m_Opcode.ft])) { @@ -1487,7 +1594,10 @@ void R4300iOp::SDC1 (void) DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; TEST_COP1_USABLE_EXCEPTION - if ((Address & 7) != 0) { ADDRESS_ERROR_EXCEPTION(Address,FALSE); } + if ((Address & 7) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,FALSE); + } if (!g_MMU->SD_VAddr(Address,*(__int64 *)_FPR_D[m_Opcode.ft])) { if (bHaveDebugger()) @@ -1504,7 +1614,10 @@ void R4300iOp::SDC1 (void) void R4300iOp::SD (void) { DWORD Address = _GPR[m_Opcode.base].UW[0] + (short)m_Opcode.offset; - if ((Address & 7) != 0) { ADDRESS_ERROR_EXCEPTION(Address,FALSE); } + if ((Address & 7) != 0) + { + ADDRESS_ERROR_EXCEPTION(Address,FALSE); + } if (!g_MMU->SD_VAddr(Address,_GPR[m_Opcode.rt].UDW)) { if (bHaveDebugger()) @@ -1579,6 +1692,7 @@ void R4300iOp::SPECIAL_BREAK (void) void R4300iOp::SPECIAL_SYNC (void) { + } void R4300iOp::SPECIAL_MFHI (void) @@ -1632,11 +1746,17 @@ void R4300iOp::SPECIAL_MULTU (void) void R4300iOp::SPECIAL_DIV (void) { - if ( _GPR[m_Opcode.rt].UDW != 0 ) { + if ( _GPR[m_Opcode.rt].UDW != 0 ) + { _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 { - if (bShowDivByZero()) { g_Notify->DisplayError(L"DIV by 0 ???"); } + } + else + { + if (bShowDivByZero()) + { + g_Notify->DisplayError(L"DIV by 0 ???"); + } _RegLO->DW = 0; _RegHI->DW = 0; } @@ -1648,8 +1768,13 @@ 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 { - if (bShowDivByZero()) { g_Notify->DisplayError(L"DIVU by 0 ???"); } + } + else + { + if (bShowDivByZero()) + { + g_Notify->DisplayError(L"DIVU by 0 ???"); + } _RegLO->DW = 0; _RegHI->DW = 0; } @@ -1685,10 +1810,13 @@ void R4300iOp::SPECIAL_DMULTU (void) void R4300iOp::SPECIAL_DDIV (void) { - if ( _GPR[m_Opcode.rt].UDW != 0 ) { + if ( _GPR[m_Opcode.rt].UDW != 0 ) + { _RegLO->DW = _GPR[m_Opcode.rs].DW / _GPR[m_Opcode.rt].DW; _RegHI->DW = _GPR[m_Opcode.rs].DW % _GPR[m_Opcode.rt].DW; - } else { + } + else + { if (bHaveDebugger()) { g_Notify->DisplayError(L"DDIV by 0 ???"); @@ -1698,10 +1826,13 @@ void R4300iOp::SPECIAL_DDIV (void) void R4300iOp::SPECIAL_DDIVU (void) { - if ( _GPR[m_Opcode.rt].UDW != 0 ) { + if ( _GPR[m_Opcode.rt].UDW != 0 ) + { _RegLO->UDW = _GPR[m_Opcode.rs].UDW / _GPR[m_Opcode.rt].UDW; _RegHI->UDW = _GPR[m_Opcode.rs].UDW % _GPR[m_Opcode.rt].UDW; - } else { + } + else + { if (bHaveDebugger()) { g_Notify->DisplayError(L"DDIVU by 0 ???"); @@ -1738,7 +1869,8 @@ void R4300iOp::SPECIAL_OR (void) { _GPR[m_Opcode.rd].DW = _GPR[m_Opcode.rs].DW | _GPR[m_Opcode.rt].DW; #ifdef Interpreter_StackTest - if (m_Opcode.rd == 29) { + if (m_Opcode.rd == 29) + { StackValue = _GPR[m_Opcode.rd].W[0]; } #endif @@ -1756,18 +1888,24 @@ void R4300iOp::SPECIAL_NOR (void) void R4300iOp::SPECIAL_SLT (void) { - if (_GPR[m_Opcode.rs].DW < _GPR[m_Opcode.rt].DW) { + if (_GPR[m_Opcode.rs].DW < _GPR[m_Opcode.rt].DW) + { _GPR[m_Opcode.rd].DW = 1; - } else { + } + else + { _GPR[m_Opcode.rd].DW = 0; } } void R4300iOp::SPECIAL_SLTU (void) { - if (_GPR[m_Opcode.rs].UDW < _GPR[m_Opcode.rt].UDW) { + if (_GPR[m_Opcode.rs].UDW < _GPR[m_Opcode.rt].UDW) + { _GPR[m_Opcode.rd].DW = 1; - } else { + } + else + { _GPR[m_Opcode.rd].DW = 0; } } @@ -1834,7 +1972,8 @@ void R4300iOp::SPECIAL_DSRA32 (void) void R4300iOp::REGIMM_BLTZ (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].DW < 0) { + if (_GPR[m_Opcode.rs].DW < 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -1843,7 +1982,9 @@ void R4300iOp::REGIMM_BLTZ (void) CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } @@ -1851,7 +1992,8 @@ void R4300iOp::REGIMM_BLTZ (void) void R4300iOp::REGIMM_BGEZ (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].DW >= 0) { + if (_GPR[m_Opcode.rs].DW >= 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -1860,14 +2002,17 @@ void R4300iOp::REGIMM_BGEZ (void) CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } void R4300iOp::REGIMM_BLTZL (void) { - if (_GPR[m_Opcode.rs].DW < 0) { + if (_GPR[m_Opcode.rs].DW < 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -1877,7 +2022,9 @@ void R4300iOp::REGIMM_BLTZL (void) CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } @@ -1885,7 +2032,8 @@ void R4300iOp::REGIMM_BLTZL (void) void R4300iOp::REGIMM_BGEZL (void) { - if (_GPR[m_Opcode.rs].DW >= 0) { + if (_GPR[m_Opcode.rs].DW >= 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) @@ -1895,7 +2043,9 @@ void R4300iOp::REGIMM_BGEZL (void) CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } @@ -1904,7 +2054,8 @@ void R4300iOp::REGIMM_BGEZL (void) void R4300iOp::REGIMM_BLTZAL (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].DW < 0) { + if (_GPR[m_Opcode.rs].DW < 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -1913,7 +2064,9 @@ void R4300iOp::REGIMM_BLTZAL (void) CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } _GPR[31].DW= (long)((*_PROGRAM_COUNTER) + 8); @@ -1922,7 +2075,8 @@ void R4300iOp::REGIMM_BLTZAL (void) void R4300iOp::REGIMM_BGEZAL (void) { m_NextInstruction = DELAY_SLOT; - if (_GPR[m_Opcode.rs].DW >= 0) { + if (_GPR[m_Opcode.rs].DW >= 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; if ((*_PROGRAM_COUNTER) == m_JumpToLocation) { @@ -1931,7 +2085,9 @@ void R4300iOp::REGIMM_BGEZAL (void) CInterpreterCPU::InPermLoop(); } } - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } _GPR[31].DW = (long)((*_PROGRAM_COUNTER) + 8); @@ -1962,7 +2118,8 @@ void R4300iOp::COP0_MT (void) } } - switch (m_Opcode.rd) { + switch (m_Opcode.rd) + { case 0: //Index case 2: //EntryLo0 case 3: //EntryLo1 @@ -1996,10 +2153,13 @@ void R4300iOp::COP0_MT (void) g_SystemTimer->UpdateCompareTimer(); break; case 12: //Status - if ((_CP0[m_Opcode.rd] & STATUS_FR) != (_GPR[m_Opcode.rt].UW[0] & STATUS_FR)) { + if ((_CP0[m_Opcode.rd] & STATUS_FR) != (_GPR[m_Opcode.rt].UW[0] & STATUS_FR)) + { _CP0[m_Opcode.rd] = _GPR[m_Opcode.rt].UW[0]; g_Reg->FixFpuLocations(); - } else { + } + else + { _CP0[m_Opcode.rd] = _GPR[m_Opcode.rt].UW[0]; } if ((_CP0[m_Opcode.rd] & 0x18) != 0 && bHaveDebugger()) @@ -2023,35 +2183,50 @@ void R4300iOp::COP0_MT (void) /************************** COP0 CO functions ***********************/ void R4300iOp::COP0_CO_TLBR (void) { - if (!g_System->bUseTlb()) { return; } + if (!g_System->bUseTlb()) + { + return; + } g_TLB->ReadEntry(); } void R4300iOp::COP0_CO_TLBWI (void) { - if (!g_System->bUseTlb()) { return; } + if (!g_System->bUseTlb()) + { + return; + } g_TLB->WriteEntry(g_Reg->INDEX_REGISTER & 0x1F,FALSE); } void R4300iOp::COP0_CO_TLBWR (void) { - if (!g_System->bUseTlb()) { return; } + if (!g_System->bUseTlb()) + { + return; + } g_TLB->WriteEntry(g_Reg->RANDOM_REGISTER & 0x1F,true); } void R4300iOp::COP0_CO_TLBP (void) { - if (!g_System->bUseTlb()) { return; } + if (!g_System->bUseTlb()) + { + return; + } g_TLB->Probe(); } void R4300iOp::COP0_CO_ERET (void) { m_NextInstruction = JUMP; - if ((g_Reg->STATUS_REGISTER & STATUS_ERL) != 0) { + if ((g_Reg->STATUS_REGISTER & STATUS_ERL) != 0) + { m_JumpToLocation = g_Reg->ERROREPC_REGISTER; g_Reg->STATUS_REGISTER &= ~STATUS_ERL; - } else { + } + else + { m_JumpToLocation = g_Reg->EPC_REGISTER; g_Reg->STATUS_REGISTER &= ~STATUS_EXL; } @@ -2078,7 +2253,10 @@ void R4300iOp::COP1_CF (void) TEST_COP1_USABLE_EXCEPTION if (m_Opcode.fs != 31 && m_Opcode.fs != 0) { - if (bHaveDebugger()) { g_Notify->DisplayError(L"CFC1 what register are you writing to ?"); } + if (bHaveDebugger()) + { + g_Notify->DisplayError(L"CFC1 what register are you writing to ?"); + } return; } _GPR[m_Opcode.rt].DW = (int)_FPCR[m_Opcode.fs]; @@ -2101,7 +2279,8 @@ void R4300iOp::COP1_CT (void) TEST_COP1_USABLE_EXCEPTION if (m_Opcode.fs == 31) { _FPCR[m_Opcode.fs] = _GPR[m_Opcode.rt].W[0]; - switch((_FPCR[m_Opcode.fs] & 3)) { + switch ((_FPCR[m_Opcode.fs] & 3)) + { case 0: *_RoundingModel = ROUND_NEAR; break; case 1: *_RoundingModel = ROUND_CHOP; break; case 2: *_RoundingModel = ROUND_UP; break; @@ -2109,7 +2288,10 @@ void R4300iOp::COP1_CT (void) } return; } - if (bHaveDebugger()) { g_Notify->DisplayError(L"CTC1 what register are you writing to ?"); } + if (bHaveDebugger()) + { + g_Notify->DisplayError(L"CTC1 what register are you writing to ?"); + } } /************************* COP1: BC1 functions ***********************/ @@ -2117,9 +2299,12 @@ void R4300iOp::COP1_BCF (void) { TEST_COP1_USABLE_EXCEPTION m_NextInstruction = DELAY_SLOT; - if ((_FPCR[31] & FPCSR_C) == 0) { + if ((_FPCR[31] & FPCSR_C) == 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } @@ -2128,9 +2313,12 @@ void R4300iOp::COP1_BCT (void) { TEST_COP1_USABLE_EXCEPTION m_NextInstruction = DELAY_SLOT; - if ((_FPCR[31] & FPCSR_C) != 0) { + if ((_FPCR[31] & FPCSR_C) != 0) + { m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; - } else { + } + else + { m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } @@ -2138,10 +2326,13 @@ void R4300iOp::COP1_BCT (void) void R4300iOp::COP1_BCFL (void) { TEST_COP1_USABLE_EXCEPTION - if ((_FPCR[31] & FPCSR_C) == 0) { + if ((_FPCR[31] & FPCSR_C) == 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } @@ -2150,17 +2341,22 @@ void R4300iOp::COP1_BCFL (void) void R4300iOp::COP1_BCTL (void) { TEST_COP1_USABLE_EXCEPTION - if ((_FPCR[31] & FPCSR_C) != 0) { + if ((_FPCR[31] & FPCSR_C) != 0) + { m_NextInstruction = DELAY_SLOT; m_JumpToLocation = (*_PROGRAM_COUNTER) + ((short)m_Opcode.offset << 2) + 4; - } else { + } + else + { m_NextInstruction = JUMP; m_JumpToLocation = (*_PROGRAM_COUNTER) + 8; } } /************************** COP1: S functions ************************/ -__inline void Float_RoundToInteger32( int * Dest, float * Source ) { - _asm { +__inline void Float_RoundToInteger32( int * Dest, float * Source ) +{ + _asm + { mov esi, [Source] mov edi, [Dest] fld dword ptr [esi] @@ -2168,8 +2364,10 @@ __inline void Float_RoundToInteger32( int * Dest, float * Source ) { } } -__inline void Float_RoundToInteger64( __int64 * Dest, float * Source ) { - _asm { +__inline void Float_RoundToInteger64( __int64 * Dest, float * Source ) +{ + _asm + { mov esi, [Source] mov edi, [Dest] fld dword ptr [esi] @@ -2212,7 +2410,8 @@ void R4300iOp::COP1_S_SQRT (void) float * Dest = (float *)_FPR_S[m_Opcode.fd]; float * Source = (float *)_FPR_S[m_Opcode.fs]; - _asm { + _asm + { push esi mov esi, dword ptr [Source] fld dword ptr [esi] @@ -2326,15 +2525,23 @@ void R4300iOp::COP1_S_CMP (void) if (_isnan(Temp0) || _isnan(Temp1)) { - if (bHaveDebugger()) { g_Notify->DisplayError(__FUNCTIONW__ L": Nan ?"); } + if (bHaveDebugger()) + { + g_Notify->DisplayError(__FUNCTIONW__ L": Nan ?"); + } less = FALSE; equal = FALSE; unorded = TRUE; if ((m_Opcode.funct & 8) != 0) { - if (bHaveDebugger()) { g_Notify->DisplayError(L"Signal InvalidOperationException\nin r4300i_COP1_S_CMP\n%X %ff\n%X %ff", Temp0,Temp0,Temp1,Temp1); } + if (bHaveDebugger()) + { + g_Notify->DisplayError(L"Signal InvalidOperationException\nin r4300i_COP1_S_CMP\n%X %ff\n%X %ff", Temp0,Temp0,Temp1,Temp1); + } } - } else { + } + else + { less = Temp0 < Temp1; equal = Temp0 == Temp1; unorded = FALSE; @@ -2343,17 +2550,22 @@ void R4300iOp::COP1_S_CMP (void) condition = ((m_Opcode.funct & 4) && less) | ((m_Opcode.funct & 2) && equal) | ((m_Opcode.funct & 1) && unorded); - if (condition) { + if (condition) + { _FPCR[31] |= FPCSR_C; - } else { + } + else + { _FPCR[31] &= ~FPCSR_C; } } /************************** COP1: D functions ************************/ -__inline void Double_RoundToInteger32( DWORD * Dest, double * Source ) { - _asm { +__inline void Double_RoundToInteger32( DWORD * Dest, double * Source ) +{ + _asm + { mov esi, [Source] mov edi, [Dest] fld qword ptr [esi] @@ -2361,8 +2573,10 @@ __inline void Double_RoundToInteger32( DWORD * Dest, double * Source ) { } } -__inline void Double_RoundToInteger64( unsigned __int64 * Dest, double * Source ) { - _asm { +__inline void Double_RoundToInteger64( unsigned __int64 * Dest, double * Source ) +{ + _asm + { mov esi, [Source] mov edi, [Dest] fld qword ptr [esi] @@ -2508,13 +2722,19 @@ void R4300iOp::COP1_D_CMP (void) if (_isnan(Temp0.D) || _isnan(Temp1.D)) { - if (bHaveDebugger()) { g_Notify->DisplayError(__FUNCTIONW__ L": Nan ?"); } + if (bHaveDebugger()) + { + g_Notify->DisplayError(__FUNCTIONW__ L": Nan ?"); + } less = FALSE; equal = FALSE; unorded = TRUE; if ((m_Opcode.funct & 8) != 0) { - if (bHaveDebugger()) { g_Notify->DisplayError(L"Signal InvalidOperationException\nin " __FUNCTIONW__); } + if (bHaveDebugger()) + { + g_Notify->DisplayError(L"Signal InvalidOperationException\nin " __FUNCTIONW__); + } } } else @@ -2527,9 +2747,12 @@ void R4300iOp::COP1_D_CMP (void) condition = ((m_Opcode.funct & 4) && less) | ((m_Opcode.funct & 2) && equal) | ((m_Opcode.funct & 1) && unorded); - if (condition) { + if (condition) + { _FPCR[31] |= FPCSR_C; - } else { + } + else + { _FPCR[31] &= ~FPCSR_C; } } @@ -2573,17 +2796,21 @@ void R4300iOp::UnknownOpcode (void) g_Notify->BreakPoint(__FILEW__,__LINE__); #ifdef tofix - if (HaveDebugger && !inFullScreen) { + if (HaveDebugger && !inFullScreen) + { int response; strcat(Message,"\n\nDo you wish to enter the debugger ?"); response = MessageBox(NULL,Message,GS(MSG_MSGBOX_TITLE), MB_YESNO | MB_ICONERROR ); - if (response == IDYES) { + if (response == IDYES) + { Enter_R4300i_Commands_Window (); } ExitThread(0); - } else { + } + else + { g_Notify->DisplayError(Message); ExitThread(0); } diff --git a/Source/Project64/N64 System/Mips/Audio.cpp b/Source/Project64/N64 System/Mips/Audio.cpp index 984bd3215..f8228dd66 100644 --- a/Source/Project64/N64 System/Mips/Audio.cpp +++ b/Source/Project64/N64 System/Mips/Audio.cpp @@ -17,6 +17,7 @@ CAudio::CAudio (void) CAudio::~CAudio (void) { + } void CAudio::Reset ( void ) @@ -65,12 +66,16 @@ void CAudio::LenChanged ( void ) } WriteTraceF(TraceAudio,__FUNCTION__ ": Set Timer AI_LEN_REG: %d m_CountsPerByte: %d",g_Reg->AI_LEN_REG,m_CountsPerByte); g_SystemTimer->SetTimer(CSystemTimer::AiTimerInterrupt,g_Reg->AI_LEN_REG * m_CountsPerByte,false); - } else { + } + else + { WriteTraceF(TraceAudio,__FUNCTION__ ": Increasing Second Buffer (m_SecondBuff %d Increase: %d)",m_SecondBuff,g_Reg->AI_LEN_REG); m_SecondBuff += g_Reg->AI_LEN_REG; } } - } else { + } + else + { WriteTraceF(TraceAudio,__FUNCTION__ ": *** Reset Timer to 0"); g_SystemTimer->StopTimer(CSystemTimer::AiTimerBusy); g_SystemTimer->StopTimer(CSystemTimer::AiTimerInterrupt); @@ -92,7 +97,9 @@ void CAudio::InterruptTimerDone ( void ) { g_SystemTimer->SetTimer(CSystemTimer::AiTimerInterrupt,m_SecondBuff * m_CountsPerByte,false); m_SecondBuff = 0; - } else { + } + else + { if (g_Reg->m_AudioIntrReg == 0) { g_System->SyncToAudio(); @@ -128,7 +135,8 @@ void CAudio::SetFrequency (DWORD Dacrate, DWORD System) WriteTraceF(TraceAudio,__FUNCTION__ "(Dacrate: %X System: %d): AI_BITRATE_REG = %X",Dacrate,System,g_Reg->AI_BITRATE_REG); DWORD Frequency; - switch (System) { + switch (System) + { case SYSTEM_PAL: Frequency = 49656530 / (Dacrate + 1); break; case SYSTEM_MPAL: Frequency = 48628316 / (Dacrate + 1); break; default: Frequency = 48681812 / (Dacrate + 1); break; @@ -141,4 +149,3 @@ void CAudio::SetFrequency (DWORD Dacrate, DWORD System) m_FramesPerSecond = System == SYSTEM_PAL ? 50 : 60; } - diff --git a/Source/Project64/N64 System/Mips/Audio.h b/Source/Project64/N64 System/Mips/Audio.h index 6caca8141..2a17f3e6a 100644 --- a/Source/Project64/N64 System/Mips/Audio.h +++ b/Source/Project64/N64 System/Mips/Audio.h @@ -12,7 +12,8 @@ class CAudio { - enum { + enum + { ai_full = 0x80000000, ai_busy = 0x40000000, }; diff --git a/Source/Project64/N64 System/Mips/Dma.cpp b/Source/Project64/N64 System/Mips/Dma.cpp index bdbdfa212..8022cca03 100644 --- a/Source/Project64/N64 System/Mips/Dma.cpp +++ b/Source/Project64/N64 System/Mips/Dma.cpp @@ -14,10 +14,13 @@ CDMA::CDMA(CFlashram & FlashRam, CSram & Sram) : m_FlashRam(FlashRam), m_Sram(Sram) { + } -void CDMA::OnFirstDMA (void) { - switch (g_Rom->CicChipID()) { +void CDMA::OnFirstDMA (void) +{ + switch (g_Rom->CicChipID()) + { case CIC_NUS_6101: *(DWORD *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; case CIC_UNKNOWN: case CIC_NUS_6102: *(DWORD *)&((g_MMU->Rdram())[0x318]) = g_MMU->RdramSize(); break; @@ -28,21 +31,30 @@ void CDMA::OnFirstDMA (void) { } } -void CDMA::PI_DMA_READ (void) { +void CDMA::PI_DMA_READ (void) +{ // PI_STATUS_REG |= PI_STATUS_DMA_BUSY; if ( g_Reg->PI_DRAM_ADDR_REG + g_Reg->PI_RD_LEN_REG + 1 > g_MMU->RdramSize()) { - if (bHaveDebugger()) { g_Notify->DisplayError(L"PI_DMA_READ not in Memory"); } + if (bHaveDebugger()) + { + g_Notify->DisplayError(L"PI_DMA_READ not in Memory"); + } g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; g_Reg->MI_INTR_REG |= MI_INTR_PI; g_Reg->CheckInterrupts(); return; } - if ( g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08010000) { - if (g_System->m_SaveUsing == SaveChip_Auto) { g_System->m_SaveUsing = SaveChip_Sram; } - if (g_System->m_SaveUsing == SaveChip_Sram) { + if ( g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08010000) + { + if (g_System->m_SaveUsing == SaveChip_Auto) + { + g_System->m_SaveUsing = SaveChip_Sram; + } + if (g_System->m_SaveUsing == SaveChip_Sram) + { m_Sram.DmaToSram( g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_CART_ADDR_REG - 0x08000000, @@ -53,7 +65,8 @@ void CDMA::PI_DMA_READ (void) { g_Reg->CheckInterrupts(); return; } - if (g_System->m_SaveUsing == SaveChip_FlashRam) { + if (g_System->m_SaveUsing == SaveChip_FlashRam) + { m_FlashRam.DmaToFlashram( g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_CART_ADDR_REG - 0x08000000, @@ -102,9 +115,14 @@ void CDMA::PI_DMA_WRITE (void) return; } - if ( g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08010000) { - if (g_System->m_SaveUsing == SaveChip_Auto) { g_System->m_SaveUsing = SaveChip_Sram; } - if (g_System->m_SaveUsing == SaveChip_Sram) { + if ( g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG <= 0x08010000) + { + if (g_System->m_SaveUsing == SaveChip_Auto) + { + g_System->m_SaveUsing = SaveChip_Sram; + } + if (g_System->m_SaveUsing == SaveChip_Sram) + { m_Sram.DmaFromSram( g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_CART_ADDR_REG - 0x08000000, @@ -115,7 +133,8 @@ void CDMA::PI_DMA_WRITE (void) g_Reg->CheckInterrupts(); return; } - if (g_System->m_SaveUsing == SaveChip_FlashRam) { + if (g_System->m_SaveUsing == SaveChip_FlashRam) + { m_FlashRam.DmaFromFlashram( g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG, g_Reg->PI_CART_ADDR_REG - 0x08000000, @@ -133,7 +152,8 @@ void CDMA::PI_DMA_WRITE (void) DWORD i; #ifdef tofix #ifdef ROM_IN_MAPSPACE - if (WrittenToRom) { + if (WrittenToRom) + { DWORD OldProtect; VirtualProtect(ROM,m_RomFileSize,PAGE_READONLY, &OldProtect); } @@ -142,17 +162,23 @@ void CDMA::PI_DMA_WRITE (void) BYTE * ROM = g_Rom->GetRomAddress(); BYTE * RDRAM = g_MMU->Rdram(); g_Reg->PI_CART_ADDR_REG -= 0x10000000; - if (g_Reg->PI_CART_ADDR_REG + PI_WR_LEN_REG < g_Rom->GetRomSize()) { - for (i = 0; i < PI_WR_LEN_REG; i ++) { + if (g_Reg->PI_CART_ADDR_REG + PI_WR_LEN_REG < g_Rom->GetRomSize()) + { + for (i = 0; i < PI_WR_LEN_REG; i ++) + { *(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((g_Reg->PI_CART_ADDR_REG + i) ^ 3)); } - } else { + } + else + { DWORD Len; Len = g_Rom->GetRomSize() - g_Reg->PI_CART_ADDR_REG; - for (i = 0; i < Len; i ++) { + for (i = 0; i < Len; i ++) + { *(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((g_Reg->PI_CART_ADDR_REG + i) ^ 3)); } - for (i = Len; i < PI_WR_LEN_REG - Len; i ++) { + for (i = Len; i < PI_WR_LEN_REG - Len; i ++) + { *(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = 0; } } @@ -182,7 +208,8 @@ void CDMA::PI_DMA_WRITE (void) } -void CDMA::SP_DMA_READ (void) { +void CDMA::SP_DMA_READ (void) +{ g_Reg->SP_DRAM_ADDR_REG &= 0x1FFFFFFF; if (g_Reg->SP_DRAM_ADDR_REG > g_MMU->RdramSize()) @@ -205,9 +232,18 @@ void CDMA::SP_DMA_READ (void) { return; } - if ((g_Reg->SP_MEM_ADDR_REG & 3) != 0) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - if ((g_Reg->SP_DRAM_ADDR_REG & 3) != 0) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - if (((g_Reg->SP_RD_LEN_REG + 1) & 3) != 0) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if ((g_Reg->SP_MEM_ADDR_REG & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } + if ((g_Reg->SP_DRAM_ADDR_REG & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } + if (((g_Reg->SP_RD_LEN_REG + 1) & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } memcpy( g_MMU->Dmem() + (g_Reg->SP_MEM_ADDR_REG & 0x1FFF), g_MMU->Rdram() + g_Reg->SP_DRAM_ADDR_REG, g_Reg->SP_RD_LEN_REG + 1 ); @@ -236,9 +272,19 @@ void CDMA::SP_DMA_WRITE (void) return; } - if ((g_Reg->SP_MEM_ADDR_REG & 3) != 0) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - if ((g_Reg->SP_DRAM_ADDR_REG & 3) != 0) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - if (((g_Reg->SP_WR_LEN_REG + 1) & 3) != 0) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if ((g_Reg->SP_MEM_ADDR_REG & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } + + if ((g_Reg->SP_DRAM_ADDR_REG & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } + if (((g_Reg->SP_WR_LEN_REG + 1) & 3) != 0) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } memcpy( g_MMU->Rdram() + g_Reg->SP_DRAM_ADDR_REG, g_MMU->Dmem() + (g_Reg->SP_MEM_ADDR_REG & 0x1FFF), g_Reg->SP_WR_LEN_REG + 1); @@ -246,4 +292,3 @@ void CDMA::SP_DMA_WRITE (void) g_Reg->SP_DMA_BUSY_REG = 0; g_Reg->SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; } - diff --git a/Source/Project64/N64 System/Mips/Dma.h b/Source/Project64/N64 System/Mips/Dma.h index 2dc7f1ff9..f1fd29164 100644 --- a/Source/Project64/N64 System/Mips/Dma.h +++ b/Source/Project64/N64 System/Mips/Dma.h @@ -33,5 +33,3 @@ private: void OnFirstDMA ( void ); }; - - diff --git a/Source/Project64/N64 System/Mips/Eeprom.cpp b/Source/Project64/N64 System/Mips/Eeprom.cpp index 3d157a89e..27b3870a5 100644 --- a/Source/Project64/N64 System/Mips/Eeprom.cpp +++ b/Source/Project64/N64 System/Mips/Eeprom.cpp @@ -18,8 +18,10 @@ CEeprom::CEeprom (bool ReadOnly): memset(m_EEPROM,0xFF,sizeof(m_EEPROM)); } -CEeprom::~CEeprom (void) { - if (m_hFile) { +CEeprom::~CEeprom (void) +{ + if (m_hFile) + { CloseHandle(m_hFile); m_hFile = NULL; } @@ -31,15 +33,21 @@ unsigned char byte2bcd(int n) return (unsigned char)(((n / 10) << 4) | (n % 10)); } -void CEeprom::EepromCommand ( BYTE * Command) { +void CEeprom::EepromCommand ( BYTE * Command) +{ time_t curtime_time; struct tm curtime; - if (g_System->m_SaveUsing == SaveChip_Auto) { g_System->m_SaveUsing = SaveChip_Eeprom_4K; } + if (g_System->m_SaveUsing == SaveChip_Auto) + { + g_System->m_SaveUsing = SaveChip_Eeprom_4K; + } - switch (Command[2]) { + switch (Command[2]) + { case 0: // check - if (g_System->m_SaveUsing != SaveChip_Eeprom_4K && g_System->m_SaveUsing != SaveChip_Eeprom_16K) { + if (g_System->m_SaveUsing != SaveChip_Eeprom_4K && g_System->m_SaveUsing != SaveChip_Eeprom_16K) + { Command[1] |= 0x80; break; } @@ -52,20 +60,34 @@ void CEeprom::EepromCommand ( BYTE * Command) { Command[4] = (g_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0; if ((Command[1] & 3) > 2) Command[5] = 0x00; - } else { + } + else + { Command[3] = 0x00; Command[4] = g_System->m_SaveUsing == SaveChip_Eeprom_4K?0x80:0xC0; Command[5] = 0x00; } break; case 4: // Read from Eeprom - if (Command[0] != 2 && bHaveDebugger()) { g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); } - if (Command[1] != 8 && bHaveDebugger()) { g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); } + if (Command[0] != 2 && bHaveDebugger()) + { + g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); + } + if (Command[1] != 8 && bHaveDebugger()) + { + g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); + } ReadFrom(&Command[4],Command[3]); break; case 5: //Write to Eeprom - if (Command[0] != 10 && bHaveDebugger()) { g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); } - if (Command[1] != 1 && bHaveDebugger()) { g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); } + if (Command[0] != 10 && bHaveDebugger()) + { + g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); + } + if (Command[1] != 1 && bHaveDebugger()) + { + g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command"); + } WriteTo(&Command[4],Command[3]); break; case 6: //RTC Status query @@ -74,7 +96,7 @@ void CEeprom::EepromCommand ( BYTE * Command) { Command[5] = 0x00; break; case 7: //Read RTC block - switch(Command[3]) + switch (Command[3]) { case 0: //Block number Command[4] = 0x00; @@ -101,14 +123,21 @@ void CEeprom::EepromCommand ( BYTE * Command) { break; case 8: //Write RTC, unimplemented - if (g_Settings->LoadDword(Debugger_ShowPifErrors)) { g_Notify->DisplayError(L"Write RTC, unimplemented"); } + if (g_Settings->LoadDword(Debugger_ShowPifErrors)) + { + g_Notify->DisplayError(L"Write RTC, unimplemented"); + } break; default: - if (g_Settings->LoadDword(Debugger_ShowPifErrors)) { g_Notify->DisplayError(L"Unknown EepromCommand %d",Command[2]); } + if (g_Settings->LoadDword(Debugger_ShowPifErrors)) + { + g_Notify->DisplayError(L"Unknown EepromCommand %d",Command[2]); + } } } -void CEeprom::LoadEeprom (void) { +void CEeprom::LoadEeprom (void) +{ CPath FileName; DWORD dwRead; @@ -135,7 +164,8 @@ void CEeprom::LoadEeprom (void) { ReadFile(m_hFile,m_EEPROM,sizeof(m_EEPROM),&dwRead,NULL); } -void CEeprom::ReadFrom(BYTE * Buffer, int line) { +void CEeprom::ReadFrom(BYTE * Buffer, int line) +{ int i; if (m_hFile == NULL) @@ -143,13 +173,14 @@ void CEeprom::ReadFrom(BYTE * Buffer, int line) { LoadEeprom(); } - for(i=0; i < 8; i++) + for (i=0; i < 8; i++) { Buffer[i] = m_EEPROM[line*8+i]; } } -void CEeprom::WriteTo(BYTE * Buffer, int line) { +void CEeprom::WriteTo(BYTE * Buffer, int line) +{ DWORD dwWritten; int i; @@ -157,7 +188,10 @@ void CEeprom::WriteTo(BYTE * Buffer, int line) { { LoadEeprom(); } - for(i=0;i<8;i++) { m_EEPROM[line*8+i]=Buffer[i]; } + for (i=0;i<8;i++) + { + m_EEPROM[line*8+i]=Buffer[i]; + } SetFilePointer(m_hFile,line*8,NULL,FILE_BEGIN); WriteFile( m_hFile,Buffer,8,&dwWritten,NULL ); FlushFileBuffers(m_hFile); diff --git a/Source/Project64/N64 System/Mips/FlashRam.cpp b/Source/Project64/N64 System/Mips/FlashRam.cpp index 25d471ba0..c4191f129 100644 --- a/Source/Project64/N64 System/Mips/FlashRam.cpp +++ b/Source/Project64/N64 System/Mips/FlashRam.cpp @@ -18,10 +18,13 @@ CFlashram::CFlashram (bool ReadOnly): m_ReadOnly(ReadOnly), m_hFile(NULL) { + } -CFlashram::~CFlashram (void) { - if (m_hFile) { +CFlashram::~CFlashram (void) +{ + if (m_hFile) + { CloseHandle(m_hFile); m_hFile = NULL; } @@ -32,10 +35,15 @@ void CFlashram::DmaFromFlashram ( BYTE * dest, int StartOffset, int len) BYTE FlipBuffer[0x10000]; DWORD dwRead, count; - switch (m_FlashFlag) { + switch (m_FlashFlag) + { case FLASHRAM_MODE_READ: - if (m_hFile == NULL) { - if (!LoadFlashram()) { return; } + if (m_hFile == NULL) + { + if (!LoadFlashram()) + { + return; + } } if (len > 0x10000) { @@ -57,10 +65,12 @@ void CFlashram::DmaFromFlashram ( BYTE * dest, int StartOffset, int len) StartOffset = StartOffset << 1; SetFilePointer(m_hFile,StartOffset,NULL,FILE_BEGIN); ReadFile(m_hFile,FlipBuffer,len,&dwRead,NULL); - for (count = dwRead; (int)count < len; count ++) { + for (count = dwRead; (int)count < len; count ++) + { FlipBuffer[count] = 0xFF; } - _asm { + _asm + { mov edi, dest lea ecx, [FlipBuffer] mov edx, 0 @@ -94,8 +104,10 @@ void CFlashram::DmaFromFlashram ( BYTE * dest, int StartOffset, int len) } } -void CFlashram::DmaToFlashram(BYTE * Source, int StartOffset, int len) { - switch (m_FlashFlag) { +void CFlashram::DmaToFlashram(BYTE * Source, int StartOffset, int len) +{ + switch (m_FlashFlag) + { case FLASHRAM_MODE_WRITE: m_FlashRamPointer = Source; break; @@ -110,7 +122,8 @@ void CFlashram::DmaToFlashram(BYTE * Source, int StartOffset, int len) { DWORD CFlashram::ReadFromFlashStatus (DWORD PAddr) { - switch (PAddr) { + switch (PAddr) + { case 0x08000000: return (DWORD)(m_FlashStatus >> 32); default: if (bHaveDebugger()) @@ -122,7 +135,8 @@ DWORD CFlashram::ReadFromFlashStatus (DWORD PAddr) return (DWORD)(m_FlashStatus >> 32); } -bool CFlashram::LoadFlashram (void) { +bool CFlashram::LoadFlashram (void) +{ CPath FileName; FileName.SetDriveDirectory( g_Settings->LoadString(Directory_NativeSave).c_str()); @@ -146,27 +160,36 @@ bool CFlashram::LoadFlashram (void) { return true; } -void CFlashram::WriteToFlashCommand(DWORD FlashRAM_Command) { +void CFlashram::WriteToFlashCommand(DWORD FlashRAM_Command) +{ BYTE EmptyBlock[128]; DWORD dwWritten; - switch (FlashRAM_Command & 0xFF000000) { + switch (FlashRAM_Command & 0xFF000000) + { case 0xD2000000: - switch (m_FlashFlag) { + switch (m_FlashFlag) + { case FLASHRAM_MODE_NOPES: break; case FLASHRAM_MODE_READ: break; case FLASHRAM_MODE_STATUS: break; case FLASHRAM_MODE_ERASE: memset(EmptyBlock,0xFF,sizeof(EmptyBlock)); if (m_hFile == NULL) { - if (!LoadFlashram()) { return; } + if (!LoadFlashram()) + { + return; + } } SetFilePointer(m_hFile,m_FlashRAM_Offset,NULL,FILE_BEGIN); WriteFile(m_hFile,EmptyBlock,128,&dwWritten,NULL); break; case FLASHRAM_MODE_WRITE: if (m_hFile == NULL) { - if (!LoadFlashram()) { return; } + if (!LoadFlashram()) + { + return; + } } { BYTE FlipBuffer[128]; @@ -174,7 +197,8 @@ void CFlashram::WriteToFlashCommand(DWORD FlashRAM_Command) { BYTE * FlashRamPointer = m_FlashRamPointer; memset(FlipBuffer,0,sizeof(FlipBuffer)); - _asm { + _asm + { lea edi, [FlipBuffer] mov ecx, FlashRamPointer mov edx, 0 diff --git a/Source/Project64/N64 System/Mips/FlashRam.h b/Source/Project64/N64 System/Mips/FlashRam.h index 59681c670..9bf8b80be 100644 --- a/Source/Project64/N64 System/Mips/FlashRam.h +++ b/Source/Project64/N64 System/Mips/FlashRam.h @@ -13,7 +13,8 @@ class CFlashram : private CDebugSettings { - enum Modes { + enum Modes + { FLASHRAM_MODE_NOPES = 0, FLASHRAM_MODE_ERASE = 1, FLASHRAM_MODE_WRITE = 2, diff --git a/Source/Project64/N64 System/Mips/Memory Labels Class.cpp b/Source/Project64/N64 System/Mips/Memory Labels Class.cpp index f27b85cfb..243e19b31 100644 --- a/Source/Project64/N64 System/Mips/Memory Labels Class.cpp +++ b/Source/Project64/N64 System/Mips/Memory Labels Class.cpp @@ -10,15 +10,21 @@ ****************************************************************************/ #include "stdafx.h" -DWORD CMemoryLabel::AsciiToHex (char * HexValue) { +DWORD CMemoryLabel::AsciiToHex (char * HexValue) +{ DWORD Count, Finish, Value = 0; Finish = strlen(HexValue); - if (Finish > 8 ) { Finish = 8; } + if (Finish > 8 ) + { + Finish = 8; + } - for (Count = 0; Count < Finish; Count++){ + for (Count = 0; Count < Finish; Count++) + { Value = (Value << 4); - switch( HexValue[Count] ) { + switch ( HexValue[Count] ) + { case '0': break; case '1': Value += 1; break; case '2': Value += 2; break; @@ -49,9 +55,11 @@ DWORD CMemoryLabel::AsciiToHex (char * HexValue) { return Value; } -void CMemoryLabel::AddMemoryLabel ( DWORD Address, const char * Message, ... ) { +void CMemoryLabel::AddMemoryLabel ( DWORD Address, const char * Message, ... ) +{ StringMap::iterator Item = m_LabelList.find(Address); - if (Item == m_LabelList.end()) { + if (Item == m_LabelList.end()) + { char Msg[1000]; va_list ap; @@ -65,9 +73,11 @@ void CMemoryLabel::AddMemoryLabel ( DWORD Address, const char * Message, ... ) { } } -stdstr CMemoryLabel::LabelName ( DWORD Address ) const { +stdstr CMemoryLabel::LabelName ( DWORD Address ) const +{ //StringMap::iterator theIterator = m_LabelList.find(Address); - //if (theIterator != m_LabelList.end()) { + //if (theIterator != m_LabelList.end()) + //{ // return (*theIterator).second; //} @@ -76,36 +86,47 @@ stdstr CMemoryLabel::LabelName ( DWORD Address ) const { return stdstr(strLabelName); } -stdstr CMemoryLabel::StoredLabelName ( DWORD Address ) { +stdstr CMemoryLabel::StoredLabelName ( DWORD Address ) +{ StringMap::iterator theIterator = m_LabelList.find(Address); - if (theIterator != m_LabelList.end()) { + if (theIterator != m_LabelList.end()) + { return (*theIterator).second; } return stdstr(""); } -void CMemoryLabel::LoadLabelList ( char * file ) { +void CMemoryLabel::LoadLabelList ( char * file ) +{ m_LabelList.clear(); CurrentLabelFile = file; HANDLE hFile = CreateFile(file,GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); - if (hFile == INVALID_HANDLE_VALUE) { return; } + if (hFile == INVALID_HANDLE_VALUE) + { + return; + } SetFilePointer(hFile,0,NULL,FILE_BEGIN); DWORD FileSize = GetFileSize(hFile,NULL); void * FileContents = VirtualAlloc(NULL,FileSize,MEM_COMMIT,PAGE_READWRITE ); - if (FileContents) { + if (FileContents) + { DWORD dwRead; - if (!ReadFile(hFile,FileContents,FileSize,&dwRead,NULL)) { + if (!ReadFile(hFile,FileContents,FileSize,&dwRead,NULL)) + { VirtualFree(FileContents, 0, MEM_RELEASE); FileContents = NULL; } } - if (FileContents) { ProcessCODFile((BYTE *)FileContents, FileSize); } + if (FileContents) + { + ProcessCODFile((BYTE *)FileContents, FileSize); + } VirtualFree(FileContents, 0, MEM_RELEASE); CloseHandle(hFile); @@ -113,21 +134,27 @@ void CMemoryLabel::LoadLabelList ( char * file ) { m_NewLabels = 0; } -// How many new labels been added since loading/saveing label file -int CMemoryLabel::NewLabels ( void ) { +// How many new labels been added since loading/saving label file +int CMemoryLabel::NewLabels ( void ) +{ return m_NewLabels; } -void CMemoryLabel::SaveLabelList ( void ) { +void CMemoryLabel::SaveLabelList ( void ) +{ m_NewLabels = 0; - if (CurrentLabelFile.length() == 0) { return; } + if (CurrentLabelFile.length() == 0) + { + return; + } HANDLE hFile = CreateFile(CurrentLabelFile.c_str(),GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); SetFilePointer(hFile,0,NULL,FILE_BEGIN); - for (StringMap::iterator Item = m_LabelList.begin(); Item != m_LabelList.end(); Item++) { + for (StringMap::iterator Item = m_LabelList.begin(); Item != m_LabelList.end(); Item++) + { char Text[300]; DWORD dwWritten; @@ -140,33 +167,51 @@ void CMemoryLabel::SaveLabelList ( void ) { } -void CMemoryLabel::ProcessCODFile(BYTE * File, DWORD FileLen) { +void CMemoryLabel::ProcessCODFile(BYTE * File, DWORD FileLen) +{ char * CurrentPos = (char *)File; char Label[40]; DWORD Address; int Length; - while ( CurrentPos < (char *)File + FileLen ) { - if (*CurrentPos != '0') { return; } + while ( CurrentPos < (char *)File + FileLen ) + { + if (*CurrentPos != '0') + { + return; + } CurrentPos += 1; - if (*CurrentPos != 'x') { return; } + if (*CurrentPos != 'x') + { + return; + } CurrentPos += 1; - if (strchr(CurrentPos,',') - CurrentPos != 8) { return; } + if (strchr(CurrentPos,',') - CurrentPos != 8) + { + return; + } Address = AsciiToHex (CurrentPos); CurrentPos += 9; - if (strchr(CurrentPos,'\r') == NULL) { + if (strchr(CurrentPos,'\r') == NULL) + { Length = strchr(CurrentPos,'\n') - CurrentPos; - } else { + } + else + { Length = strchr(CurrentPos,'\r') - CurrentPos; - if (Length > (strchr(CurrentPos,'\n') - CurrentPos)) { + if (Length > (strchr(CurrentPos,'\n') - CurrentPos)) + { Length = strchr(CurrentPos,'\n') - CurrentPos; } } - if (Length > 40) { Length = 40; } + if (Length > 40) + { + Length = 40; + } memcpy(Label,CurrentPos,Length); Label[Length] = '\0'; diff --git a/Source/Project64/N64 System/Mips/Memory Labels Class.h b/Source/Project64/N64 System/Mips/Memory Labels Class.h index ce856553b..563caeef4 100644 --- a/Source/Project64/N64 System/Mips/Memory Labels Class.h +++ b/Source/Project64/N64 System/Mips/Memory Labels Class.h @@ -12,7 +12,8 @@ typedef std::map StringMap; -class CMemoryLabel { +class CMemoryLabel +{ // Variable dealing with Labels StringMap m_LabelList; int m_NewLabels; diff --git a/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp b/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp index 2d182dc87..a451af77b 100644 --- a/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp +++ b/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp @@ -64,7 +64,8 @@ void CMipsMemoryVM::Reset( bool /*EraseMemory*/ ) DWORD Len = g_Settings->LoadDword(Rdb_TLB_VAddrLen); //0x01000000; DWORD PAddr = g_Settings->LoadDword(Rdb_TLB_PAddrStart); //0x10034b30; DWORD End = Start + Len; - for (DWORD address = Start; address < End; address += 0x1000) { + for (DWORD address = Start; address < End; address += 0x1000) + { m_TLB_ReadMap[address >> 12] = ((DWORD)m_RDRAM + (address - Start + PAddr)) - address; m_TLB_WriteMap[address >> 12] = ((DWORD)m_RDRAM + (address - Start + PAddr)) - address; } @@ -102,10 +103,19 @@ BOOL CMipsMemoryVM::Initialize ( void ) return true; } - if (m_Reserve1) { m_RDRAM = m_Reserve1; m_Reserve1 = NULL; } - if (m_RDRAM == NULL && m_Reserve2) { m_RDRAM = m_Reserve2; m_Reserve2 = NULL; } - if (m_RDRAM == NULL) { m_RDRAM = (unsigned char *) VirtualAlloc( NULL, 0x20000000, MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE ); } - if( m_RDRAM == NULL ) + if (m_Reserve1) + { + m_RDRAM = m_Reserve1; m_Reserve1 = NULL; + } + if (m_RDRAM == NULL && m_Reserve2) + { + m_RDRAM = m_Reserve2; m_Reserve2 = NULL; + } + if (m_RDRAM == NULL) + { + m_RDRAM = (unsigned char *) VirtualAlloc( NULL, 0x20000000, MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE ); + } + if ( m_RDRAM == NULL ) { WriteTraceF(TraceError,__FUNCTION__ ": Failed to Reserve RDRAM (Size: 0x%X)",0x20000000); FreeMemory(); @@ -113,14 +123,14 @@ BOOL CMipsMemoryVM::Initialize ( void ) } m_AllocatedRdramSize = g_Settings->LoadDword(Game_RDRamSize); - if(VirtualAlloc(m_RDRAM, m_AllocatedRdramSize, MEM_COMMIT, PAGE_READWRITE)==NULL) + if (VirtualAlloc(m_RDRAM, m_AllocatedRdramSize, MEM_COMMIT, PAGE_READWRITE)==NULL) { WriteTraceF(TraceError,__FUNCTION__ ": Failed to Allocate RDRAM (Size: 0x%X)",m_AllocatedRdramSize); FreeMemory(); return false; } - if(VirtualAlloc(m_RDRAM + 0x04000000, 0x2000, MEM_COMMIT, PAGE_READWRITE)==NULL) + if (VirtualAlloc(m_RDRAM + 0x04000000, 0x2000, MEM_COMMIT, PAGE_READWRITE)==NULL) { WriteTraceF(TraceError,__FUNCTION__ ": Failed to Allocate DMEM/IMEM (Size: 0x%X)",0x2000); FreeMemory(); @@ -135,7 +145,7 @@ BOOL CMipsMemoryVM::Initialize ( void ) m_RomMapped = true; m_Rom = m_RDRAM + 0x10000000; m_RomSize = g_Rom->GetRomSize(); - if(VirtualAlloc(m_Rom, g_Rom->GetRomSize(), MEM_COMMIT, PAGE_READWRITE)==NULL) + if (VirtualAlloc(m_Rom, g_Rom->GetRomSize(), MEM_COMMIT, PAGE_READWRITE)==NULL) { WriteTraceF(TraceError,__FUNCTION__ ": Failed to Allocate Rom (Size: 0x%X)",g_Rom->GetRomSize()); FreeMemory(); @@ -145,7 +155,9 @@ BOOL CMipsMemoryVM::Initialize ( void ) DWORD OldProtect; VirtualProtect(m_Rom,g_Rom->GetRomSize(),PAGE_READONLY, &OldProtect); - } else { + } + else + { m_RomMapped = false; m_Rom = g_Rom->GetRomAddress(); m_RomSize = g_Rom->GetRomSize(); @@ -177,9 +189,18 @@ void CMipsMemoryVM::FreeMemory ( void ) { if (VirtualFree( m_RDRAM, 0x20000000,MEM_DECOMMIT) != 0) { - if (m_Reserve1 == NULL) { m_Reserve1 = m_RDRAM; } - else if (m_Reserve2 == NULL) { m_Reserve2 = m_RDRAM; } - else { VirtualFree( m_RDRAM, 0 , MEM_RELEASE); } + if (m_Reserve1 == NULL) + { + m_Reserve1 = m_RDRAM; + } + else if (m_Reserve2 == NULL) + { + m_Reserve2 = m_RDRAM; + } + else + { + VirtualFree( m_RDRAM, 0 , MEM_RELEASE); + } } else { VirtualFree( m_RDRAM, 0 , MEM_RELEASE); } @@ -227,14 +248,20 @@ BYTE * CMipsMemoryVM::PifRam ( void ) BOOL CMipsMemoryVM::LB_VAddr ( DWORD VAddr, BYTE & Value ) { - if (m_TLB_ReadMap[VAddr >> 12] == 0) { return FALSE; } + if (m_TLB_ReadMap[VAddr >> 12] == 0) + { + return FALSE; + } Value = *(BYTE *)(m_TLB_ReadMap[VAddr >> 12] + (VAddr ^ 3)); return TRUE; } BOOL CMipsMemoryVM::LH_VAddr ( DWORD VAddr, WORD & Value ) { - if (m_TLB_ReadMap[VAddr >> 12] == 0) { return FALSE; } + if (m_TLB_ReadMap[VAddr >> 12] == 0) + { + return FALSE; + } Value = *(WORD *)(m_TLB_ReadMap[VAddr >> 12] + (VAddr ^ 2)); return TRUE; } @@ -251,13 +278,17 @@ BOOL CMipsMemoryVM::LW_VAddr ( DWORD VAddr, DWORD & Value ) } } BYTE * BaseAddress = (BYTE *)m_TLB_ReadMap[VAddr >> 12]; - if (BaseAddress == 0) { return FALSE; } + if (BaseAddress == 0) + { + return FALSE; + } Value = *(DWORD *)(BaseAddress + VAddr); // if (LookUpMode == FuncFind_ChangeMemory) // { // g_Notify->BreakPoint(__FILEW__,__LINE__); -// if ( (Command.Hex >> 16) == 0x7C7C) { +// if ( (Command.Hex >> 16) == 0x7C7C) +// { // Command.Hex = OrigMem[(Command.Hex & 0xFFFF)].OriginalValue; // } // } @@ -266,7 +297,10 @@ BOOL CMipsMemoryVM::LW_VAddr ( DWORD VAddr, DWORD & Value ) BOOL CMipsMemoryVM::LD_VAddr ( DWORD VAddr, QWORD & Value ) { - if (m_TLB_ReadMap[VAddr >> 12] == 0) { return FALSE; } + if (m_TLB_ReadMap[VAddr >> 12] == 0) + { + return FALSE; + } *((DWORD *)(&Value) + 1) = *(DWORD *)(m_TLB_ReadMap[VAddr >> 12] + VAddr); *((DWORD *)(&Value)) = *(DWORD *)(m_TLB_ReadMap[VAddr >> 12] + VAddr + 4); return TRUE; @@ -335,14 +369,20 @@ BOOL CMipsMemoryVM::LD_PAddr ( DWORD PAddr, QWORD & Value ) BOOL CMipsMemoryVM::SB_VAddr ( DWORD VAddr, BYTE Value ) { - if (m_TLB_WriteMap[VAddr >> 12] == 0) { return FALSE; } + if (m_TLB_WriteMap[VAddr >> 12] == 0) + { + return FALSE; + } *(BYTE *)(m_TLB_WriteMap[VAddr >> 12] + (VAddr ^ 3)) = Value; return TRUE; } BOOL CMipsMemoryVM::SH_VAddr ( DWORD VAddr, WORD Value ) { - if (m_TLB_WriteMap[VAddr >> 12] == 0) { return FALSE; } + if (m_TLB_WriteMap[VAddr >> 12] == 0) + { + return FALSE; + } *(WORD *)(m_TLB_WriteMap[VAddr >> 12] + (VAddr ^ 2)) = Value; return TRUE; } @@ -358,7 +398,10 @@ BOOL CMipsMemoryVM::SW_VAddr ( DWORD VAddr, DWORD Value ) return true; } } - if (m_TLB_WriteMap[VAddr >> 12] == 0) { return FALSE; } + if (m_TLB_WriteMap[VAddr >> 12] == 0) + { + return FALSE; + } *(DWORD *)(m_TLB_WriteMap[VAddr >> 12] + VAddr) = Value; return TRUE; } @@ -366,7 +409,10 @@ BOOL CMipsMemoryVM::SW_VAddr ( DWORD VAddr, DWORD Value ) BOOL CMipsMemoryVM::SD_VAddr ( DWORD VAddr, QWORD Value ) { - if (m_TLB_WriteMap[VAddr >> 12] == 0) { return FALSE; } + if (m_TLB_WriteMap[VAddr >> 12] == 0) + { + return FALSE; + } *(DWORD *)(m_TLB_WriteMap[VAddr >> 12] + VAddr) = *((DWORD *)(&Value) + 1); *(DWORD *)(m_TLB_WriteMap[VAddr >> 12] + VAddr + 4) = *((DWORD *)(&Value)); return TRUE; @@ -441,20 +487,27 @@ bool CMipsMemoryVM::ValidVaddr ( DWORD VAddr ) const bool CMipsMemoryVM::VAddrToRealAddr ( DWORD VAddr, void * &RealAddress ) const { - if (m_TLB_ReadMap[VAddr >> 12] == 0) { return false; } + if (m_TLB_ReadMap[VAddr >> 12] == 0) + { + return false; + } RealAddress = (BYTE *)(m_TLB_ReadMap[VAddr >> 12] + VAddr); return true; } bool CMipsMemoryVM::TranslateVaddr ( DWORD VAddr, DWORD &PAddr) const { - //Change the Virtual address to a Phyiscal Address - if (m_TLB_ReadMap[VAddr >> 12] == 0) { return false; } + //Change the Virtual address to a Physical Address + if (m_TLB_ReadMap[VAddr >> 12] == 0) + { + return false; + } PAddr = (DWORD)((BYTE *)(m_TLB_ReadMap[VAddr >> 12] + VAddr) - m_RDRAM); return true; } -void CMipsMemoryVM::Compile_LB ( x86Reg Reg, DWORD VAddr, BOOL SignExtend) { +void CMipsMemoryVM::Compile_LB ( x86Reg Reg, DWORD VAddr, BOOL SignExtend) +{ DWORD PAddr; char VarName[100]; @@ -472,22 +525,30 @@ void CMipsMemoryVM::Compile_LB ( x86Reg Reg, DWORD VAddr, BOOL SignExtend) { MoveConstToX86reg(VAddr,AddrReg); MoveVariableDispToX86Reg(m_TLB_ReadMap,"m_TLB_ReadMap",TlbMappReg,TlbMappReg,4); CompileReadTLBMiss(AddrReg,TlbMappReg); - if (SignExtend) { + if (SignExtend) + { MoveSxByteX86regPointerToX86reg(AddrReg, TlbMappReg,Reg); - } else { + } + else + { MoveZxByteX86regPointerToX86reg(AddrReg, TlbMappReg,Reg); } return; } - if (!TranslateVaddr(VAddr,PAddr)) { + if (!TranslateVaddr(VAddr,PAddr)) + { MoveConstToX86reg(0,Reg); CPU_Message("Compile_LB\nFailed to translate address %X",VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_LB\nFailed to translate address %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_LB\nFailed to translate address %X",VAddr); + } return; } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -498,19 +559,26 @@ void CMipsMemoryVM::Compile_LB ( x86Reg Reg, DWORD VAddr, BOOL SignExtend) { case 0x00700000: case 0x10000000: sprintf(VarName,"m_RDRAM + %X",PAddr); - if (SignExtend) { + if (SignExtend) + { MoveSxVariableToX86regByte(PAddr + m_RDRAM,VarName,Reg); - } else { + } + else + { MoveZxVariableToX86regByte(PAddr + m_RDRAM,VarName,Reg); } break; default: MoveConstToX86reg(0,Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_LB\nFailed to compile address: %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_LB\nFailed to compile address: %X",VAddr); + } } } -void CMipsMemoryVM::Compile_LH ( x86Reg Reg, DWORD VAddr, BOOL SignExtend) { +void CMipsMemoryVM::Compile_LH ( x86Reg Reg, DWORD VAddr, BOOL SignExtend) +{ char VarName[100]; DWORD PAddr; @@ -528,22 +596,30 @@ void CMipsMemoryVM::Compile_LH ( x86Reg Reg, DWORD VAddr, BOOL SignExtend) { MoveConstToX86reg(VAddr,AddrReg); MoveVariableDispToX86Reg(m_TLB_ReadMap,"m_TLB_ReadMap",TlbMappReg,TlbMappReg,4); CompileReadTLBMiss(AddrReg,TlbMappReg); - if (SignExtend) { + if (SignExtend) + { MoveSxHalfX86regPointerToX86reg(AddrReg, TlbMappReg,Reg); - } else { + } + else + { MoveZxHalfX86regPointerToX86reg(AddrReg, TlbMappReg,Reg); } return; } - if (!TranslateVaddr(VAddr, PAddr)) { + if (!TranslateVaddr(VAddr, PAddr)) + { MoveConstToX86reg(0,Reg); CPU_Message("Compile_LH\nFailed to translate address %X",VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_LH\nFailed to translate address %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_LH\nFailed to translate address %X",VAddr); + } return; } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -554,19 +630,26 @@ void CMipsMemoryVM::Compile_LH ( x86Reg Reg, DWORD VAddr, BOOL SignExtend) { case 0x00700000: case 0x10000000: sprintf(VarName,"m_RDRAM + %X",PAddr); - if (SignExtend) { + if (SignExtend) + { MoveSxVariableToX86regHalf(PAddr + m_RDRAM,VarName,Reg); - } else { + } + else + { MoveZxVariableToX86regHalf(PAddr + m_RDRAM,VarName,Reg); } break; default: MoveConstToX86reg(0,Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_LHU\nFailed to compile address: %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_LHU\nFailed to compile address: %X",VAddr); + } } } -void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { +void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) +{ char VarName[100]; DWORD PAddr; @@ -585,13 +668,16 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { CompileReadTLBMiss(VAddr,TlbMappReg); AddConstToX86Reg(TlbMappReg,VAddr); MoveX86PointerToX86reg(Reg,TlbMappReg); - } else { + } + else + { if (!TranslateVaddr(VAddr, PAddr)) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -604,12 +690,14 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { MoveVariableToX86reg(PAddr + m_RDRAM,VarName,Reg); break; case 0x04000000: - if (PAddr < 0x04002000) { + if (PAddr < 0x04002000) + { sprintf(VarName,"m_RDRAM + %X",PAddr); MoveVariableToX86reg(PAddr + m_RDRAM,VarName,Reg); break; } - switch (PAddr) { + switch (PAddr) + { case 0x04040010: MoveVariableToX86reg(&g_Reg->SP_STATUS_REG,"SP_STATUS_REG",Reg); break; case 0x04040014: MoveVariableToX86reg(&g_Reg->SP_DMA_FULL_REG,"SP_DMA_FULL_REG",Reg); break; case 0x04040018: MoveVariableToX86reg(&g_Reg->SP_DMA_BUSY_REG,"SP_DMA_BUSY_REG",Reg); break; @@ -620,7 +708,10 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { case 0x04080000: MoveVariableToX86reg(&g_Reg->SP_PC_REG,"SP_PC_REG",Reg); break; default: MoveConstToX86reg(0,Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); + } } break; case 0x04100000: @@ -636,7 +727,8 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { } break; case 0x04300000: - switch (PAddr) { + switch (PAddr) + { case 0x04300000: MoveVariableToX86reg(&g_Reg->MI_MODE_REG,"MI_MODE_REG",Reg); break; case 0x04300004: MoveVariableToX86reg(&g_Reg->MI_VERSION_REG,"MI_VERSION_REG",Reg); break; case 0x04300008: MoveVariableToX86reg(&g_Reg->MI_INTR_REG,"MI_INTR_REG",Reg); break; @@ -647,7 +739,8 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { } break; case 0x04400000: - switch (PAddr) { + switch (PAddr) + { case 0x04400010: m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); UpdateCounters(m_RegWorkingSet,false, true); @@ -660,11 +753,15 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { break; default: MoveConstToX86reg(0,Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); + } } break; case 0x04500000: /* AI registers */ - switch (PAddr) { + switch (PAddr) + { case 0x04500004: if (g_System->bFixedAudio()) { @@ -677,14 +774,19 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { MoveX86regToVariable(x86_EAX,&m_TempValue,"m_TempValue"); AfterCallDirect(m_RegWorkingSet); MoveVariableToX86reg(&m_TempValue,"m_TempValue",Reg); - } else { - if (g_Plugins->Audio()->AiReadLength != NULL) { + } + else + { + if (g_Plugins->Audio()->AiReadLength != NULL) + { BeforeCallDirect(m_RegWorkingSet); Call_Direct(g_Plugins->Audio()->AiReadLength, "AiReadLength"); MoveX86regToVariable(x86_EAX,&m_TempValue,"m_TempValue"); AfterCallDirect(m_RegWorkingSet); MoveVariableToX86reg(&m_TempValue,"m_TempValue",Reg); - } else { + } + else + { MoveConstToX86reg(0,Reg); } } @@ -698,17 +800,23 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { MoveX86regToVariable(x86_EAX,&m_TempValue,"m_TempValue"); AfterCallDirect(m_RegWorkingSet); MoveVariableToX86reg(&m_TempValue,"m_TempValue",Reg); - } else { + } + else + { MoveVariableToX86reg(&g_Reg->AI_STATUS_REG,"AI_STATUS_REG",Reg); } break; default: MoveConstToX86reg(0,Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); + } } break; case 0x04600000: - switch (PAddr) { + switch (PAddr) + { case 0x04600010: MoveVariableToX86reg(&g_Reg->PI_STATUS_REG,"PI_STATUS_REG",Reg); break; case 0x04600014: MoveVariableToX86reg(&g_Reg->PI_DOMAIN1_REG,"PI_DOMAIN1_REG",Reg); break; case 0x04600018: MoveVariableToX86reg(&g_Reg->PI_BSD_DOM1_PWD_REG,"PI_BSD_DOM1_PWD_REG",Reg); break; @@ -720,24 +828,35 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { case 0x04600030: MoveVariableToX86reg(&g_Reg->PI_BSD_DOM2_RLS_REG,"PI_BSD_DOM2_RLS_REG",Reg); break; default: MoveConstToX86reg(0,Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); + } } break; case 0x04700000: - switch (PAddr) { + switch (PAddr) + { case 0x0470000C: MoveVariableToX86reg(&g_Reg->RI_SELECT_REG,"RI_SELECT_REG",Reg); break; case 0x04700010: MoveVariableToX86reg(&g_Reg->RI_REFRESH_REG,"RI_REFRESH_REG",Reg); break; default: MoveConstToX86reg(0,Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); + } } break; case 0x04800000: - switch (PAddr) { + switch (PAddr) + { case 0x04800018: MoveVariableToX86reg(&g_Reg->SI_STATUS_REG,"SI_STATUS_REG",Reg); break; default: MoveConstToX86reg(0,Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); + } } break; case 0x1FC00000: @@ -750,9 +869,12 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { // read from rom sprintf(VarName,"m_RDRAM + %X",PAddr); MoveVariableToX86reg(PAddr + m_RDRAM,VarName,Reg); - } else { + } + else + { MoveConstToX86reg(((PAddr & 0xFFFF) << 16) | (PAddr & 0xFFFF),Reg); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { CPU_Message(__FUNCTION__ "\nFailed to translate address: %X",VAddr); g_Notify->DisplayError(__FUNCTIONW__ L"\nFailed to translate address: %X",VAddr); } @@ -761,7 +883,8 @@ void CMipsMemoryVM::Compile_LW (x86Reg Reg, DWORD VAddr ) { } } -void CMipsMemoryVM::Compile_SB_Const ( BYTE Value, DWORD VAddr ) { +void CMipsMemoryVM::Compile_SB_Const ( BYTE Value, DWORD VAddr ) +{ char VarName[100]; DWORD PAddr; @@ -778,13 +901,15 @@ void CMipsMemoryVM::Compile_SB_Const ( BYTE Value, DWORD VAddr ) { return; } - if (!TranslateVaddr(VAddr, PAddr)) { + if (!TranslateVaddr(VAddr, PAddr)) + { CPU_Message("Compile_SB\nFailed to translate address %X",VAddr); if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SB\nFailed to translate address %X",VAddr); } return; } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -797,11 +922,15 @@ void CMipsMemoryVM::Compile_SB_Const ( BYTE Value, DWORD VAddr ) { MoveConstByteToVariable(Value,PAddr + m_RDRAM,VarName); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SB_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SB_Const\ntrying to store %X in %X?",Value,VAddr); + } } } -void CMipsMemoryVM::Compile_SB_Register ( x86Reg Reg, DWORD VAddr ) { +void CMipsMemoryVM::Compile_SB_Register ( x86Reg Reg, DWORD VAddr ) +{ char VarName[100]; DWORD PAddr; @@ -820,13 +949,18 @@ void CMipsMemoryVM::Compile_SB_Register ( x86Reg Reg, DWORD VAddr ) { return; } - if (!TranslateVaddr(VAddr, PAddr)) { + if (!TranslateVaddr(VAddr, PAddr)) + { CPU_Message("Compile_SB\nFailed to translate address %X",VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SB\nFailed to translate address %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SB\nFailed to translate address %X",VAddr); + } return; } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -839,11 +973,15 @@ void CMipsMemoryVM::Compile_SB_Register ( x86Reg Reg, DWORD VAddr ) { MoveX86regByteToVariable(Reg,PAddr + m_RDRAM,VarName); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SB_Register\ntrying to store in %X?",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SB_Register\ntrying to store in %X?",VAddr); + } } } -void CMipsMemoryVM::Compile_SH_Const ( WORD Value, DWORD VAddr ) { +void CMipsMemoryVM::Compile_SH_Const ( WORD Value, DWORD VAddr ) +{ char VarName[100]; DWORD PAddr; @@ -862,11 +1000,15 @@ void CMipsMemoryVM::Compile_SH_Const ( WORD Value, DWORD VAddr ) { if (!TranslateVaddr(VAddr, PAddr)) { CPU_Message("Compile_SH\nFailed to translate address %X",VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SH\nFailed to translate address %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SH\nFailed to translate address %X",VAddr); + } return; } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -879,11 +1021,15 @@ void CMipsMemoryVM::Compile_SH_Const ( WORD Value, DWORD VAddr ) { MoveConstHalfToVariable(Value,PAddr + m_RDRAM,VarName); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(__FUNCTIONW__ L"\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\ntrying to store %X in %X?",Value,VAddr); + } } } -void CMipsMemoryVM::Compile_SH_Register ( x86Reg Reg, DWORD VAddr ) { +void CMipsMemoryVM::Compile_SH_Register ( x86Reg Reg, DWORD VAddr ) +{ char VarName[100]; DWORD PAddr; @@ -904,11 +1050,15 @@ void CMipsMemoryVM::Compile_SH_Register ( x86Reg Reg, DWORD VAddr ) { if (!TranslateVaddr(VAddr, PAddr)) { CPU_Message("Compile_SH\nFailed to translate address %X",VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SH\nFailed to translate address %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SH\nFailed to translate address %X",VAddr); + } return; } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -921,11 +1071,15 @@ void CMipsMemoryVM::Compile_SH_Register ( x86Reg Reg, DWORD VAddr ) { MoveX86regHalfToVariable(Reg,PAddr + m_RDRAM,VarName); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(__FUNCTIONW__ L"\ntrying to store in %X?",PAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(__FUNCTIONW__ L"\ntrying to store in %X?",PAddr); + } } } -void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { +void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) +{ char VarName[100]; BYTE * Jump; DWORD PAddr; @@ -943,13 +1097,18 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { return; } - if (!TranslateVaddr(VAddr, PAddr)) { + if (!TranslateVaddr(VAddr, PAddr)) + { CPU_Message("Compile_SW\nFailed to translate address %X",VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW\nFailed to translate address %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW\nFailed to translate address %X",VAddr); + } return; } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -962,7 +1121,8 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { MoveConstToVariable(Value,PAddr + m_RDRAM,VarName); break; case 0x03F00000: - switch (PAddr) { + switch (PAddr) + { case 0x03F00000: MoveConstToVariable(Value,&g_Reg->RDRAM_CONFIG_REG,"RDRAM_CONFIG_REG"); break; case 0x03F00004: MoveConstToVariable(Value,&g_Reg->RDRAM_DEVICE_ID_REG,"RDRAM_DEVICE_ID_REG"); break; case 0x03F00008: MoveConstToVariable(Value,&g_Reg->RDRAM_DELAY_REG,"RDRAM_DELAY_REG"); break; @@ -980,16 +1140,21 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { case 0x03F8000C: break; case 0x03F80014: break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; case 0x04000000: - if (PAddr < 0x04002000) { + if (PAddr < 0x04002000) + { sprintf(VarName,"m_RDRAM + %X",PAddr); MoveConstToVariable(Value,PAddr + m_RDRAM,VarName); break; } - switch (PAddr) { + switch (PAddr) + { case 0x04040000: MoveConstToVariable(Value,&g_Reg->SP_MEM_ADDR_REG,"SP_MEM_ADDR_REG"); break; case 0x04040004: MoveConstToVariable(Value,&g_Reg->SP_DRAM_ADDR_REG,"SP_DRAM_ADDR_REG"); break; case 0x04040008: @@ -1016,7 +1181,10 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { case 0x0404001C: MoveConstToVariable(0,&g_Reg->SP_SEMAPHORE_REG,"SP_SEMAPHORE_REG"); break; case 0x04080000: MoveConstToVariable(Value & 0xFFC,&g_Reg->SP_PC_REG,"SP_PC_REG"); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; case 0x04100000: @@ -1031,30 +1199,54 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { AfterCallDirect(m_RegWorkingSet); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; case 0x04300000: - switch (PAddr) { + switch (PAddr) + { case 0x04300000: { DWORD ModValue; ModValue = 0x7F; - if ( ( Value & MI_CLR_INIT ) != 0 ) { ModValue |= MI_MODE_INIT; } - if ( ( Value & MI_CLR_EBUS ) != 0 ) { ModValue |= MI_MODE_EBUS; } - if ( ( Value & MI_CLR_RDRAM ) != 0 ) { ModValue |= MI_MODE_RDRAM; } - if (ModValue != 0) { + if ( ( Value & MI_CLR_INIT ) != 0 ) + { + ModValue |= MI_MODE_INIT; + } + if ( ( Value & MI_CLR_EBUS ) != 0 ) + { + ModValue |= MI_MODE_EBUS; + } + if ( ( Value & MI_CLR_RDRAM ) != 0 ) + { + ModValue |= MI_MODE_RDRAM; + } + if (ModValue != 0) + { AndConstToVariable(~ModValue,&g_Reg->MI_MODE_REG,"MI_MODE_REG"); } ModValue = (Value & 0x7F); - if ( ( Value & MI_SET_INIT ) != 0 ) { ModValue |= MI_MODE_INIT; } - if ( ( Value & MI_SET_EBUS ) != 0 ) { ModValue |= MI_MODE_EBUS; } - if ( ( Value & MI_SET_RDRAM ) != 0 ) { ModValue |= MI_MODE_RDRAM; } + if ( ( Value & MI_SET_INIT ) != 0 ) + { + ModValue |= MI_MODE_INIT; + } + if ( ( Value & MI_SET_EBUS ) != 0 ) + { + ModValue |= MI_MODE_EBUS; + } + if ( ( Value & MI_SET_RDRAM ) != 0 ) + { + ModValue |= MI_MODE_RDRAM; + } if (ModValue != 0) { OrConstToVariable(ModValue,&g_Reg->MI_MODE_REG,"MI_MODE_REG"); } - if ( ( Value & MI_CLR_DP_INTR ) != 0 ) { + if ( ( Value & MI_CLR_DP_INTR ) != 0 ) + { AndConstToVariable((DWORD)~MI_INTR_DP,&g_Reg->MI_INTR_REG,"MI_INTR_REG"); AndConstToVariable((DWORD)~MI_INTR_DP,&g_Reg->m_GfxIntrReg,"m_GfxIntrReg"); } @@ -1064,36 +1256,79 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { { DWORD ModValue; ModValue = 0; - if ( ( Value & MI_INTR_MASK_CLR_SP ) != 0 ) { ModValue |= MI_INTR_MASK_SP; } - if ( ( Value & MI_INTR_MASK_CLR_SI ) != 0 ) { ModValue |= MI_INTR_MASK_SI; } - if ( ( Value & MI_INTR_MASK_CLR_AI ) != 0 ) { ModValue |= MI_INTR_MASK_AI; } - if ( ( Value & MI_INTR_MASK_CLR_VI ) != 0 ) { ModValue |= MI_INTR_MASK_VI; } - if ( ( Value & MI_INTR_MASK_CLR_PI ) != 0 ) { ModValue |= MI_INTR_MASK_PI; } - if ( ( Value & MI_INTR_MASK_CLR_DP ) != 0 ) { ModValue |= MI_INTR_MASK_DP; } - if (ModValue != 0) { + if ( ( Value & MI_INTR_MASK_CLR_SP ) != 0 ) + { + ModValue |= MI_INTR_MASK_SP; + } + if ( ( Value & MI_INTR_MASK_CLR_SI ) != 0 ) + { + ModValue |= MI_INTR_MASK_SI; + } + if ( ( Value & MI_INTR_MASK_CLR_AI ) != 0 ) + { + ModValue |= MI_INTR_MASK_AI; + } + if ( ( Value & MI_INTR_MASK_CLR_VI ) != 0 ) + { + ModValue |= MI_INTR_MASK_VI; + } + if ( ( Value & MI_INTR_MASK_CLR_PI ) != 0 ) + { + ModValue |= MI_INTR_MASK_PI; + } + if ( ( Value & MI_INTR_MASK_CLR_DP ) != 0 ) + { + ModValue |= MI_INTR_MASK_DP; + } + if (ModValue != 0) + { AndConstToVariable(~ModValue,&g_Reg->MI_INTR_MASK_REG,"MI_INTR_MASK_REG"); } ModValue = 0; - if ( ( Value & MI_INTR_MASK_SET_SP ) != 0 ) { ModValue |= MI_INTR_MASK_SP; } - if ( ( Value & MI_INTR_MASK_SET_SI ) != 0 ) { ModValue |= MI_INTR_MASK_SI; } - if ( ( Value & MI_INTR_MASK_SET_AI ) != 0 ) { ModValue |= MI_INTR_MASK_AI; } - if ( ( Value & MI_INTR_MASK_SET_VI ) != 0 ) { ModValue |= MI_INTR_MASK_VI; } - if ( ( Value & MI_INTR_MASK_SET_PI ) != 0 ) { ModValue |= MI_INTR_MASK_PI; } - if ( ( Value & MI_INTR_MASK_SET_DP ) != 0 ) { ModValue |= MI_INTR_MASK_DP; } - if (ModValue != 0) { + if ( ( Value & MI_INTR_MASK_SET_SP ) != 0 ) + { + ModValue |= MI_INTR_MASK_SP; + } + if ( ( Value & MI_INTR_MASK_SET_SI ) != 0 ) + { + ModValue |= MI_INTR_MASK_SI; + } + if ( ( Value & MI_INTR_MASK_SET_AI ) != 0 ) + { + ModValue |= MI_INTR_MASK_AI; + } + if ( ( Value & MI_INTR_MASK_SET_VI ) != 0 ) + { + ModValue |= MI_INTR_MASK_VI; + } + if ( ( Value & MI_INTR_MASK_SET_PI ) != 0 ) + { + ModValue |= MI_INTR_MASK_PI; + } + if ( ( Value & MI_INTR_MASK_SET_DP ) != 0 ) + { + ModValue |= MI_INTR_MASK_DP; + } + if (ModValue != 0) + { OrConstToVariable(ModValue,&g_Reg->MI_INTR_MASK_REG,"MI_INTR_MASK_REG"); } } break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; case 0x04400000: - switch (PAddr) { + switch (PAddr) + { case 0x04400000: - if (g_Plugins->Gfx()->ViStatusChanged != NULL) { + if (g_Plugins->Gfx()->ViStatusChanged != NULL) + { CompConstToVariable(Value,&g_Reg->VI_STATUS_REG,"VI_STATUS_REG"); JeLabel8("Continue",0); Jump = m_RecompPos - 1; @@ -1108,7 +1343,8 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { break; case 0x04400004: MoveConstToVariable((Value & 0xFFFFFF),&g_Reg->VI_ORIGIN_REG,"VI_ORIGIN_REG"); break; case 0x04400008: - if (g_Plugins->Gfx()->ViWidthChanged != NULL) { + if (g_Plugins->Gfx()->ViWidthChanged != NULL) + { CompConstToVariable(Value,&g_Reg->VI_WIDTH_REG,"VI_WIDTH_REG"); JeLabel8("Continue",0); Jump = m_RecompPos - 1; @@ -1139,11 +1375,15 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { case 0x04400030: MoveConstToVariable(Value,&g_Reg->VI_X_SCALE_REG,"VI_X_SCALE_REG"); break; case 0x04400034: MoveConstToVariable(Value,&g_Reg->VI_Y_SCALE_REG,"VI_Y_SCALE_REG"); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; case 0x04500000: /* AI registers */ - switch (PAddr) { + switch (PAddr) + { case 0x04500000: MoveConstToVariable(Value,&g_Reg->AI_DRAM_ADDR_REG,"AI_DRAM_ADDR_REG"); break; case 0x04500004: MoveConstToVariable(Value,&g_Reg->AI_LEN_REG,"AI_LEN_REG"); @@ -1153,7 +1393,9 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { X86BreakPoint(__FILEW__,__LINE__); MoveConstToX86reg((DWORD)g_Audio,x86_ECX); Call_Direct(AddressOf(&CAudio::LenChanged),"LenChanged"); - } else { + } + else + { Call_Direct(g_Plugins->Audio()->AiLenChanged,"AiLenChanged"); } AfterCallDirect(m_RegWorkingSet); @@ -1176,11 +1418,15 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { default: sprintf(VarName,"m_RDRAM + %X",PAddr); MoveConstToVariable(Value,PAddr + m_RDRAM,VarName); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; case 0x04600000: - switch (PAddr) { + switch (PAddr) + { case 0x04600000: MoveConstToVariable(Value,&g_Reg->PI_DRAM_ADDR_REG,"PI_DRAM_ADDR_REG"); break; case 0x04600004: MoveConstToVariable(Value,&g_Reg->PI_CART_ADDR_REG,"PI_CART_ADDR_REG"); break; case 0x04600008: @@ -1198,7 +1444,8 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { AfterCallDirect(m_RegWorkingSet); break; case 0x04600010: - if ((Value & PI_CLR_INTR) != 0 ) { + if ((Value & PI_CLR_INTR) != 0 ) + { AndConstToVariable((DWORD)~MI_INTR_PI,&g_Reg->MI_INTR_REG,"MI_INTR_REG"); BeforeCallDirect(m_RegWorkingSet); MoveConstToX86reg((DWORD)g_Reg,x86_ECX); @@ -1211,21 +1458,29 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { case 0x0460001C: MoveConstToVariable((Value & 0xFF),&g_Reg->PI_BSD_DOM1_PGS_REG,"PI_BSD_DOM1_PGS_REG"); break; case 0x04600020: MoveConstToVariable((Value & 0xFF),&g_Reg->PI_BSD_DOM1_RLS_REG,"PI_BSD_DOM1_RLS_REG"); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; case 0x04700000: - switch (PAddr) { + switch (PAddr) + { case 0x04700000: MoveConstToVariable(Value,&g_Reg->RI_MODE_REG,"RI_MODE_REG"); break; case 0x04700004: MoveConstToVariable(Value,&g_Reg->RI_CONFIG_REG,"RI_CONFIG_REG"); break; case 0x04700008: MoveConstToVariable(Value,&g_Reg->RI_CURRENT_LOAD_REG,"RI_CURRENT_LOAD_REG"); break; case 0x0470000C: MoveConstToVariable(Value,&g_Reg->RI_SELECT_REG,"RI_SELECT_REG"); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; case 0x04800000: - switch (PAddr) { + switch (PAddr) + { case 0x04800000: MoveConstToVariable(Value,&g_Reg->SI_DRAM_ADDR_REG,"SI_DRAM_ADDR_REG"); break; case 0x04800004: m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); @@ -1256,11 +1511,17 @@ void CMipsMemoryVM::Compile_SW_Const ( DWORD Value, DWORD VAddr ) { AfterCallDirect(m_RegWorkingSet); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Const\ntrying to store %X in %X?",Value,VAddr); + } } } @@ -1285,13 +1546,18 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) BYTE * Jump; DWORD PAddr; - if (!TranslateVaddr(VAddr, PAddr)) { + if (!TranslateVaddr(VAddr, PAddr)) + { CPU_Message("Compile_SW_Register\nFailed to translate address %X",VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Register\nFailed to translate address %X",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Register\nFailed to translate address %X",VAddr); + } return; } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -1304,7 +1570,8 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) MoveX86regToVariable(Reg,PAddr + m_RDRAM,VarName); break; case 0x04000000: - switch (PAddr) { + switch (PAddr) + { case 0x04040000: MoveX86regToVariable(Reg,&g_Reg->SP_MEM_ADDR_REG,"SP_MEM_ADDR_REG"); break; case 0x04040004: MoveX86regToVariable(Reg,&g_Reg->SP_DRAM_ADDR_REG,"SP_DRAM_ADDR_REG"); break; case 0x04040008: @@ -1336,12 +1603,18 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) AndConstToVariable(0xFFC,&g_Reg->SP_PC_REG,"SP_PC_REG"); break; default: - if (PAddr < 0x04002000) { + if (PAddr < 0x04002000) + { sprintf(VarName,"m_RDRAM + %X",PAddr); MoveX86regToVariable(Reg,PAddr + m_RDRAM,VarName); - } else { + } + else + { CPU_Message(" Should be moving %s in to %X ?!?",x86_Name(Reg),VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); + } } } break; @@ -1360,7 +1633,8 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) AfterCallDirect(m_RegWorkingSet); break; case 0x04300000: - switch (PAddr) { + switch (PAddr) + { case 0x04300000: MoveX86regToVariable(Reg,&RegModValue,"RegModValue"); BeforeCallDirect(m_RegWorkingSet); @@ -1375,13 +1649,17 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) break; default: CPU_Message(" Should be moving %s in to %X ?!?",x86_Name(Reg),VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); + } } break; case 0x04400000: switch (PAddr) { case 0x04400000: - if (g_Plugins->Gfx()->ViStatusChanged != NULL) { + if (g_Plugins->Gfx()->ViStatusChanged != NULL) + { CompX86regToVariable(Reg,&g_Reg->VI_STATUS_REG,"VI_STATUS_REG"); JeLabel8("Continue",0); Jump = m_RecompPos - 1; @@ -1399,7 +1677,8 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) AndConstToVariable(0xFFFFFF,&g_Reg->VI_ORIGIN_REG,"VI_ORIGIN_REG"); break; case 0x04400008: - if (g_Plugins->Gfx()->ViWidthChanged != NULL) { + if (g_Plugins->Gfx()->ViWidthChanged != NULL) + { CompX86regToVariable(Reg,&g_Reg->VI_WIDTH_REG,"VI_WIDTH_REG"); JeLabel8("Continue",0); Jump = m_RecompPos - 1; @@ -1431,7 +1710,10 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) case 0x04400034: MoveX86regToVariable(Reg,&g_Reg->VI_Y_SCALE_REG,"VI_Y_SCALE_REG"); break; default: CPU_Message(" Should be moving %s in to %X ?!?",x86_Name(Reg),VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); + } } break; case 0x04500000: /* AI registers */ @@ -1447,7 +1729,9 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) { MoveConstToX86reg((DWORD)g_Audio,x86_ECX); Call_Direct(AddressOf(&CAudio::LenChanged),"LenChanged"); - } else { + } + else + { Call_Direct(g_Plugins->Audio()->AiLenChanged, "g_Plugins->Audio()->LenChanged"); } AfterCallDirect(m_RegWorkingSet); @@ -1475,7 +1759,8 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); } } break; case 0x04600000: - switch (PAddr) { + switch (PAddr) + { case 0x04600000: MoveX86regToVariable(Reg,&g_Reg->PI_DRAM_ADDR_REG,"PI_DRAM_ADDR_REG"); break; case 0x04600004: MoveX86regToVariable(Reg,&g_Reg->PI_CART_ADDR_REG,"PI_CART_ADDR_REG"); break; case 0x04600008: @@ -1518,18 +1803,26 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) break; default: CPU_Message(" Should be moving %s in to %X ?!?",x86_Name(Reg),VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); + } } break; case 0x04700000: - switch (PAddr) { + switch (PAddr) + { case 0x04700010: MoveX86regToVariable(Reg,&g_Reg->RI_REFRESH_REG,"RI_REFRESH_REG"); break; default: - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store at %X?",VAddr); + } } break; case 0x04800000: - switch (PAddr) { + switch (PAddr) + { case 0x04800000: MoveX86regToVariable(Reg,&g_Reg->SI_DRAM_ADDR_REG,"SI_DRAM_ADDR_REG"); break; case 0x04800004: MoveX86regToVariable(Reg,&g_Reg->SI_PIF_ADDR_RD64B_REG,"SI_PIF_ADDR_RD64B_REG"); @@ -1563,7 +1856,10 @@ void CMipsMemoryVM::Compile_SW_Register (x86Reg Reg, DWORD VAddr ) break; default: CPU_Message(" Should be moving %s in to %X ?!?",x86_Name(Reg),VAddr); - if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store in %X?",VAddr); } + if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) + { + g_Notify->DisplayError(L"Compile_SW_Register\ntrying to store in %X?",VAddr); + } } } @@ -1577,12 +1873,19 @@ void CMipsMemoryVM::ResetMemoryStack ( void) if (Reg == x86_Unknown) { Reg = Map_TempReg(x86_Any, MipsReg, FALSE); - } else { - if (IsUnknown(MipsReg)) { + } + else + { + if (IsUnknown(MipsReg)) + { MoveVariableToX86reg(&_GPR[MipsReg].UW[0],CRegName::GPR_Lo[MipsReg],Reg); - } else if (IsMapped(MipsReg)) { + } + else if (IsMapped(MipsReg)) + { MoveX86RegToX86Reg(GetMipsRegMapLo(MipsReg),Reg); - } else { + } + else + { MoveConstToX86reg(GetMipsRegLo(MipsReg),Reg); } } @@ -1594,7 +1897,9 @@ void CMipsMemoryVM::ResetMemoryStack ( void) ShiftRightUnsignImmed(TempReg,12); MoveVariableDispToX86Reg(m_TLB_ReadMap,"m_TLB_ReadMap",TempReg,TempReg,4); AddX86RegToX86Reg(Reg,TempReg); - } else { + } + else + { AndConstToX86Reg(Reg,0x1FFFFFFF); AddConstToX86Reg(Reg,(DWORD)m_RDRAM); } @@ -1605,17 +1910,23 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) { if (dwExptCode != EXCEPTION_ACCESS_VIOLATION) { - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } - //convert the pointer since we are not having win32 stuctures in headers + //convert the pointer since we are not having win32 structures in headers LPEXCEPTION_POINTERS lpEP = (LPEXCEPTION_POINTERS)lpExceptionPointer; DWORD MemAddress = (char *)lpEP->ExceptionRecord->ExceptionInformation[1] - (char *)g_MMU->Rdram(); if ((int)(MemAddress) < 0 || MemAddress > 0x1FFFFFFF) { -// if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } +// if (bHaveDebugger()) +// { +// g_Notify->BreakPoint(__FILEW__,__LINE__); +// } return EXCEPTION_EXECUTE_HANDLER; } @@ -1624,23 +1935,30 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) BYTE * TypePos = (unsigned char *)lpEP->ContextRecord->Eip; EXCEPTION_RECORD exRec = *lpEP->ExceptionRecord; - if (*TypePos == 0xF3 && *(TypePos + 1) == 0xA5) { + if (*TypePos == 0xF3 && *(TypePos + 1) == 0xA5) + { DWORD Start, End; Start = (lpEP->ContextRecord->Edi - (DWORD)m_RDRAM); End = (Start + (lpEP->ContextRecord->Ecx << 2) - 1); if ((int)Start < 0) { - if (bHaveDebugger()) { + if (bHaveDebugger()) + { g_Notify->BreakPoint(__FILEW__,__LINE__); } return EXCEPTION_EXECUTE_HANDLER; } #ifdef CFB_READ DWORD count, OldProtect; - if (Start >= CFBStart && End < CFBEnd) { - for ( count = Start; count < End; count += 0x1000 ) { + if (Start >= CFBStart && End < CFBEnd) + { + for ( count = Start; count < End; count += 0x1000 ) + { VirtualProtect(m_RDRAM+count,4,PAGE_READONLY, &OldProtect); - if (FrameBufferRead) { FrameBufferRead(count & ~0xFFF); } + if (FrameBufferRead) + { + FrameBufferRead(count & ~0xFFF); + } } return EXCEPTION_CONTINUE_EXECUTION; } @@ -1653,30 +1971,46 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) } return EXCEPTION_CONTINUE_EXECUTION; } - if (Start >= 0x04000000 && End < 0x04002000) { + if (Start >= 0x04000000 && End < 0x04002000) + { g_Recompiler->ClearRecompCode_Phys(Start & ~0xFFF,0x1000,CRecompiler::Remove_ProtectedMem); return EXCEPTION_CONTINUE_EXECUTION; } - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } BYTE * ReadPos; - if (*TypePos == 0x0F && *(TypePos + 1) == 0xB6) { + if (*TypePos == 0x0F && *(TypePos + 1) == 0xB6) + { ReadPos = TypePos + 2; - } else if (*TypePos == 0x0F && *(TypePos + 1) == 0xB7) { + } + else if (*TypePos == 0x0F && *(TypePos + 1) == 0xB7) + { ReadPos = TypePos + 2; - } else if (*TypePos == 0x0F && *(TypePos + 1) == 0xBE) { + } + else if (*TypePos == 0x0F && *(TypePos + 1) == 0xBE) + { ReadPos = TypePos + 2; - } else if (*TypePos == 0x0F && *(TypePos + 1) == 0xBF) { + } + else if (*TypePos == 0x0F && *(TypePos + 1) == 0xBF) + { ReadPos = TypePos + 2; - } else if (*TypePos == 0x66) { + } + else if (*TypePos == 0x66) + { ReadPos = TypePos + 2; - } else { + } + else + { ReadPos = TypePos + 1; } - switch ((*ReadPos & 0x38)) { + switch ((*ReadPos & 0x38)) + { case 0x00: Reg = &lpEP->ContextRecord->Eax; break; case 0x08: Reg = &lpEP->ContextRecord->Ecx; break; case 0x10: Reg = &lpEP->ContextRecord->Edx; break; @@ -1687,14 +2021,16 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) case 0x38: Reg = &lpEP->ContextRecord->Edi; break; } - switch ((*ReadPos & 0xC7)) { + switch ((*ReadPos & 0xC7)) + { case 0: ReadPos += 1; break; case 1: ReadPos += 1; break; case 2: ReadPos += 1; break; case 3: ReadPos += 1; break; case 4: ReadPos += 1; - switch ((*ReadPos & 0xC7)) { + switch ((*ReadPos & 0xC7)) + { case 0: ReadPos += 1; break; case 1: ReadPos += 1; break; case 2: ReadPos += 1; break; @@ -1723,22 +2059,32 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) case 0x86: ReadPos += 5; break; case 0x87: ReadPos += 5; break; default: - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } if (Reg == NULL) { - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } - switch(*TypePos) { + switch (*TypePos) + { case 0x0F: - switch(*(TypePos + 1)) { + switch (*(TypePos + 1)) + { case 0xB6: - if (!LB_NonMemory(MemAddress,(DWORD *)Reg,FALSE)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!LB_NonMemory(MemAddress,(DWORD *)Reg,FALSE)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to load byte\n\nMIPS Address: %X\nX86 Address", (char *)exRec.ExceptionInformation[1] - (char *)m_RDRAM, *(unsigned char *)lpEP->ContextRecord->Eip); @@ -1747,8 +2093,10 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)ReadPos; return EXCEPTION_CONTINUE_EXECUTION; case 0xB7: - if (!LH_NonMemory(MemAddress,(DWORD *)Reg,FALSE)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!LH_NonMemory(MemAddress,(DWORD *)Reg,FALSE)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to load half word\n\nMIPS Address: %X\nX86 Address", (char *)exRec.ExceptionInformation[1] - (char *)m_RDRAM, *(unsigned char *)lpEP->ContextRecord->Eip); @@ -1757,8 +2105,10 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)ReadPos; return EXCEPTION_CONTINUE_EXECUTION; case 0xBE: - if (!LB_NonMemory(MemAddress,Reg,TRUE)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!LB_NonMemory(MemAddress,Reg,TRUE)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to load byte\n\nMIPS Address: %X\nX86 Address", (char *)exRec.ExceptionInformation[1] - (char *)m_RDRAM, *(unsigned char *)lpEP->ContextRecord->Eip); @@ -1767,8 +2117,10 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)ReadPos; return EXCEPTION_CONTINUE_EXECUTION; case 0xBF: - if (!LH_NonMemory(MemAddress,Reg,TRUE)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!LH_NonMemory(MemAddress,Reg,TRUE)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to load half word\n\nMIPS Address: %X\nX86 Address", (char *)exRec.ExceptionInformation[1] - (char *)m_RDRAM, *(unsigned char *)lpEP->ContextRecord->Eip); @@ -1777,15 +2129,21 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)ReadPos; return EXCEPTION_CONTINUE_EXECUTION; default: - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } break; case 0x66: - switch(*(TypePos + 1)) { + switch (*(TypePos + 1)) + { case 0x8B: - if (!LH_NonMemory(MemAddress,Reg,FALSE)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!LH_NonMemory(MemAddress,Reg,FALSE)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to half word\n\nMIPS Address: %X\nX86 Address", (char *)exRec.ExceptionInformation[1] - (char *)m_RDRAM, *(unsigned char *)lpEP->ContextRecord->Eip); @@ -1794,8 +2152,10 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)ReadPos; return EXCEPTION_CONTINUE_EXECUTION; case 0x89: - if (!SH_NonMemory(MemAddress,*(WORD *)Reg)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!SH_NonMemory(MemAddress,*(WORD *)Reg)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to store half word\n\nMIPS Address: %X\nX86 Address",MemAddress, *(unsigned char *)lpEP->ContextRecord->Eip); } @@ -1805,11 +2165,15 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) case 0xC7: if (Reg != &lpEP->ContextRecord->Eax) { - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } if (!SH_NonMemory(MemAddress,*(WORD *)ReadPos)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to store half word\n\nMIPS Address: %X\nX86 Address",MemAddress, *(unsigned char *)lpEP->ContextRecord->Eip); } @@ -1817,13 +2181,18 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)(ReadPos + 2); return EXCEPTION_CONTINUE_EXECUTION; default: - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } break; case 0x88: - if (!SB_NonMemory(MemAddress,*(BYTE *)Reg)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!SB_NonMemory(MemAddress,*(BYTE *)Reg)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to store byte\n\nMIPS Address: %X\nX86 Address", (char *)exRec.ExceptionInformation[1] - (char *)m_RDRAM, *(unsigned char *)lpEP->ContextRecord->Eip); @@ -1832,8 +2201,10 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)ReadPos; return EXCEPTION_CONTINUE_EXECUTION; case 0x8A: - if (!LB_NonMemory(MemAddress,Reg,FALSE)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!LB_NonMemory(MemAddress,Reg,FALSE)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to load byte\n\nMIPS Address: %X\nX86 Address", (char *)exRec.ExceptionInformation[1] - (char *)m_RDRAM, *(unsigned char *)lpEP->ContextRecord->Eip); @@ -1842,8 +2213,10 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)ReadPos; return EXCEPTION_CONTINUE_EXECUTION; case 0x8B: - if (!LW_NonMemory(MemAddress,Reg)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!LW_NonMemory(MemAddress,Reg)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to load word\n\nMIPS Address: %X\nX86 Address", (char *)exRec.ExceptionInformation[1] - (char *)m_RDRAM, *(unsigned char *)lpEP->ContextRecord->Eip); @@ -1852,8 +2225,10 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)ReadPos; return EXCEPTION_CONTINUE_EXECUTION; case 0x89: - if (!SW_NonMemory(MemAddress,*(DWORD *)Reg)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!SW_NonMemory(MemAddress,*(DWORD *)Reg)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to store word\n\nMIPS Address: %X\nX86 Address",MemAddress, *(unsigned char *)lpEP->ContextRecord->Eip); } @@ -1863,11 +2238,16 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) case 0xC6: if (Reg != &lpEP->ContextRecord->Eax) { - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } - if (!SB_NonMemory(MemAddress,*(BYTE *)ReadPos)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!SB_NonMemory(MemAddress,*(BYTE *)ReadPos)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to store byte\n\nMIPS Address: %X\nX86 Address",MemAddress, *(unsigned char *)lpEP->ContextRecord->Eip); } @@ -1877,11 +2257,16 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) case 0xC7: if (Reg != &lpEP->ContextRecord->Eax) { - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } - if (!SW_NonMemory(MemAddress,*(DWORD *)ReadPos)) { - if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) { + if (!SW_NonMemory(MemAddress,*(DWORD *)ReadPos)) + { + if (g_Settings->LoadDword(Debugger_ShowUnhandledMemory)) + { g_Notify->DisplayError(L"Failed to store word\n\nMIPS Address: %X\nX86 Address",MemAddress, *(unsigned char *)lpEP->ContextRecord->Eip); } @@ -1889,7 +2274,10 @@ int CMipsMemoryVM::MemoryFilter( DWORD dwExptCode, void * lpExceptionPointer ) lpEP->ContextRecord->Eip = (DWORD)(ReadPos + 4); return EXCEPTION_CONTINUE_EXECUTION; } - if (bHaveDebugger()) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (bHaveDebugger()) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } return EXCEPTION_EXECUTE_HANDLER; } @@ -1904,22 +2292,35 @@ int CMipsMemoryVM::LB_NonMemory ( DWORD PAddr, DWORD * Value, BOOL /*SignExtend* { g_Notify->BreakPoint(__FILEW__,__LINE__); #ifdef tofix - if (WrittenToRom) { return FALSE; } - if ((PAddr & 2) == 0) { PAddr = (PAddr + 4) ^ 2; } - if ((PAddr - 0x10000000) < RomFileSize) { - if (SignExtend) { + if (WrittenToRom) + { + return FALSE; + } + if ((PAddr & 2) == 0) + { + PAddr = (PAddr + 4) ^ 2; + } + if ((PAddr - 0x10000000) < RomFileSize) + { + if (SignExtend) + { *Value = (int)((char)ROM[PAddr - 0x10000000]); - } else { + } + else + { *Value = ROM[PAddr - 0x10000000]; } return TRUE; - } else { + } + else + { *Value = 0; return FALSE; } #endif } -// switch (PAddr & 0xFFF00000) { +// switch (PAddr & 0xFFF00000) +//{ // default: * Value = 0; // return FALSE; @@ -1940,7 +2341,8 @@ int CMipsMemoryVM::LH_NonMemory ( DWORD PAddr, DWORD * Value, int/* SignExtend*/ { g_Notify->BreakPoint(__FILEW__,__LINE__); } -// switch (PAddr & 0xFFF00000) { +// switch (PAddr & 0xFFF00000) +// { // default: * Value = 0; return FALSE; @@ -1949,12 +2351,17 @@ int CMipsMemoryVM::LH_NonMemory ( DWORD PAddr, DWORD * Value, int/* SignExtend*/ // return TRUE; } -int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { +int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) +{ #ifdef CFB_READ - if (PAddr >= CFBStart && PAddr < CFBEnd) { + if (PAddr >= CFBStart && PAddr < CFBEnd) + { DWORD OldProtect; VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READONLY, &OldProtect); - if (FrameBufferRead) { FrameBufferRead(PAddr & ~0xFFF); } + if (FrameBufferRead) + { + FrameBufferRead(PAddr & ~0xFFF); + } *Value = *(DWORD *)(m_RDRAM+PAddr); return TRUE; } @@ -1974,19 +2381,24 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { #endif return TRUE; } - if ((PAddr - 0x10000000) < m_RomSize) { + if ((PAddr - 0x10000000) < m_RomSize) + { *Value = *(DWORD *)&m_Rom[PAddr - 0x10000000]; return TRUE; - } else { + } + else + { *Value = PAddr & 0xFFFF; *Value = (*Value << 16) | *Value; return FALSE; } } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x03F00000: - switch (PAddr) { + switch (PAddr) + { case 0x03F00000: * Value = g_Reg->RDRAM_CONFIG_REG; break; case 0x03F00004: * Value = g_Reg->RDRAM_DEVICE_ID_REG; break; case 0x03F00008: * Value = g_Reg->RDRAM_DELAY_REG; break; @@ -2003,7 +2415,8 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { } break; case 0x04000000: - switch (PAddr) { + switch (PAddr) + { case 0x04040010: *Value = g_Reg->SP_STATUS_REG; break; case 0x04040014: *Value = g_Reg->SP_DMA_FULL_REG; break; case 0x04040018: *Value = g_Reg->SP_DMA_BUSY_REG; break; @@ -2018,7 +2431,8 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { } break; case 0x04100000: - switch (PAddr) { + switch (PAddr) + { case 0x0410000C: *Value = g_Reg->DPC_STATUS_REG; break; case 0x04100010: *Value = g_Reg->DPC_CLOCK_REG; break; case 0x04100014: *Value = g_Reg->DPC_BUFBUSY_REG; break; @@ -2030,7 +2444,8 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { } break; case 0x04300000: - switch (PAddr) { + switch (PAddr) + { case 0x04300000: * Value = g_Reg->MI_MODE_REG; break; case 0x04300004: * Value = g_Reg->MI_VERSION_REG; break; case 0x04300008: * Value = g_Reg->MI_INTR_REG; break; @@ -2041,7 +2456,8 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { } break; case 0x04400000: - switch (PAddr) { + switch (PAddr) + { case 0x04400000: *Value = g_Reg->VI_STATUS_REG; break; case 0x04400004: *Value = g_Reg->VI_ORIGIN_REG; break; case 0x04400008: *Value = g_Reg->VI_WIDTH_REG; break; @@ -2065,15 +2481,21 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { } break; case 0x04500000: - switch (PAddr) { + switch (PAddr) + { case 0x04500004: if (g_System->bFixedAudio()) { *Value = g_Audio->GetLength(); - } else { - if (g_Plugins->Audio()->AiReadLength != NULL) { + } + else + { + if (g_Plugins->Audio()->AiReadLength != NULL) + { *Value = g_Plugins->Audio()->AiReadLength(); - } else { + } + else + { *Value = 0; } } @@ -2082,7 +2504,9 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { if (g_System->bFixedAudio()) { *Value = g_Audio->GetStatus(); - } else { + } + else + { *Value = g_Reg->AI_STATUS_REG; } break; @@ -2092,7 +2516,8 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { } break; case 0x04600000: - switch (PAddr) { + switch (PAddr) + { case 0x04600010: *Value = g_Reg->PI_STATUS_REG; break; case 0x04600014: *Value = g_Reg->PI_DOMAIN1_REG; break; case 0x04600018: *Value = g_Reg->PI_BSD_DOM1_PWD_REG; break; @@ -2108,7 +2533,8 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { } break; case 0x04700000: - switch (PAddr) { + switch (PAddr) + { case 0x04700000: * Value = g_Reg->RI_MODE_REG; break; case 0x04700004: * Value = g_Reg->RI_CONFIG_REG; break; case 0x04700008: * Value = g_Reg->RI_CURRENT_LOAD_REG; break; @@ -2123,7 +2549,8 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { } break; case 0x04800000: - switch (PAddr) { + switch (PAddr) + { case 0x04800018: *Value = g_Reg->SI_STATUS_REG; break; default: *Value = 0; @@ -2135,8 +2562,12 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { *Value = (*Value << 16) | *Value; return FALSE; case 0x08000000: - if (g_System->m_SaveUsing == SaveChip_Auto) { g_System->m_SaveUsing = SaveChip_FlashRam; } - if (g_System->m_SaveUsing != SaveChip_FlashRam) { + if (g_System->m_SaveUsing == SaveChip_Auto) + { + g_System->m_SaveUsing = SaveChip_FlashRam; + } + if (g_System->m_SaveUsing != SaveChip_FlashRam) + { *Value = PAddr & 0xFFFF; *Value = (*Value << 16) | *Value; return FALSE; @@ -2144,9 +2575,11 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { *Value = ReadFromFlashStatus(PAddr); break; case 0x1FC00000: - if (PAddr < 0x1FC007C0) { + if (PAddr < 0x1FC007C0) + { /* DWORD ToSwap = *(DWORD *)(&PifRom[PAddr - 0x1FC00000]); - _asm { + _asm + { mov eax,ToSwap bswap eax mov ToSwap,eax @@ -2159,14 +2592,17 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { { BYTE * PIF_Ram = g_MMU->PifRam(); DWORD ToSwap = *(DWORD *)(&PIF_Ram[PAddr - 0x1FC007C0]); - _asm { + _asm + { mov eax,ToSwap bswap eax mov ToSwap,eax } * Value = ToSwap; return TRUE; - } else { + } + else + { * Value = 0; return FALSE; } @@ -2180,8 +2616,10 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) { return TRUE; } -int CMipsMemoryVM::SB_NonMemory ( DWORD PAddr, BYTE Value ) { - switch (PAddr & 0xFFF00000) { +int CMipsMemoryVM::SB_NonMemory ( DWORD PAddr, BYTE Value ) +{ + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -2191,7 +2629,8 @@ int CMipsMemoryVM::SB_NonMemory ( DWORD PAddr, BYTE Value ) { case 0x00600000: case 0x00700000: #ifdef CFB_READ - if (PAddr >= CFBStart && PAddr < CFBEnd) { + if (PAddr >= CFBStart && PAddr < CFBEnd) + { DWORD OldProtect; VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READWRITE, &OldProtect); *(BYTE *)(m_RDRAM+PAddr) = Value; @@ -2216,8 +2655,10 @@ int CMipsMemoryVM::SB_NonMemory ( DWORD PAddr, BYTE Value ) { return TRUE; } -int CMipsMemoryVM::SH_NonMemory ( DWORD PAddr, WORD Value ) { - switch (PAddr & 0xFFF00000) { +int CMipsMemoryVM::SH_NonMemory ( DWORD PAddr, WORD Value ) +{ + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -2227,7 +2668,8 @@ int CMipsMemoryVM::SH_NonMemory ( DWORD PAddr, WORD Value ) { case 0x00600000: case 0x00700000: #ifdef CFB_READ - if (PAddr >= CFBStart && PAddr < CFBEnd) { + if (PAddr >= CFBStart && PAddr < CFBEnd) + { DWORD OldProtect; VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READWRITE, &OldProtect); *(WORD *)(m_RDRAM+PAddr) = Value; @@ -2238,7 +2680,8 @@ int CMipsMemoryVM::SH_NonMemory ( DWORD PAddr, WORD Value ) { break; } #endif - if (PAddr < RdramSize()) { + if (PAddr < RdramSize()) + { DWORD OldProtect; g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF,0x1000,CRecompiler::Remove_ProtectedMem); VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READWRITE, &OldProtect); @@ -2252,10 +2695,12 @@ int CMipsMemoryVM::SH_NonMemory ( DWORD PAddr, WORD Value ) { return TRUE; } -int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { +int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) +{ if (PAddr >= 0x10000000 && PAddr < 0x16000000) { - if ((PAddr - 0x10000000) < g_Rom->GetRomSize()) { + if ((PAddr - 0x10000000) < g_Rom->GetRomSize()) + { m_RomWrittenTo = TRUE; m_RomWroteValue = Value; #ifdef ROM_IN_MAPSPACE @@ -2265,12 +2710,15 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } #endif //LogMessage("%X: Wrote To Rom %X from %X",PROGRAM_COUNTER,Value,PAddr); - } else { + } + else + { return FALSE; } } - switch (PAddr & 0xFFF00000) { + switch (PAddr & 0xFFF00000) + { case 0x00000000: case 0x00100000: case 0x00200000: @@ -2280,7 +2728,8 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { case 0x00600000: case 0x00700000: #ifdef CFB_READ - if (PAddr >= CFBStart && PAddr < CFBEnd) { + if (PAddr >= CFBStart && PAddr < CFBEnd) + { DWORD OldProtect; VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READWRITE, &OldProtect); *(DWORD *)(m_RDRAM+PAddr) = Value; @@ -2290,7 +2739,8 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { break; } #endif - if (PAddr < RdramSize()) { + if (PAddr < RdramSize()) + { DWORD OldProtect; g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF,0x1000,CRecompiler::Remove_ProtectedMem); VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READWRITE, &OldProtect); @@ -2298,7 +2748,8 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x03F00000: - switch (PAddr) { + switch (PAddr) + { case 0x03F00000: g_Reg->RDRAM_CONFIG_REG = Value; break; case 0x03F00004: g_Reg->RDRAM_DEVICE_ID_REG = Value; break; case 0x03F00008: g_Reg->RDRAM_DELAY_REG = Value; break; @@ -2320,11 +2771,15 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x04000000: - if (PAddr < 0x04002000) { + if (PAddr < 0x04002000) + { g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF,0xFFF,CRecompiler::Remove_ProtectedMem); *(DWORD *)(m_RDRAM+PAddr) = Value; - } else { - switch (PAddr) { + } + else + { + switch (PAddr) + { case 0x04040000: g_Reg->SP_MEM_ADDR_REG = Value; break; case 0x04040004: g_Reg->SP_DRAM_ADDR_REG = Value; break; case 0x04040008: @@ -2336,50 +2791,125 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { SP_DMA_WRITE(); break; case 0x04040010: - if ( ( Value & SP_CLR_HALT ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_HALT; } - if ( ( Value & SP_SET_HALT ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_HALT; } - if ( ( Value & SP_CLR_BROKE ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_BROKE; } - if ( ( Value & SP_CLR_INTR ) != 0) { + if ( ( Value & SP_CLR_HALT ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_HALT; + } + if ( ( Value & SP_SET_HALT ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_HALT; + } + if ( ( Value & SP_CLR_BROKE ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_BROKE; + } + if ( ( Value & SP_CLR_INTR ) != 0) + { g_Reg->MI_INTR_REG &= ~MI_INTR_SP; g_Reg->m_RspIntrReg &= ~MI_INTR_SP; g_Reg->CheckInterrupts(); } - if ( ( Value & SP_SET_INTR ) != 0) { g_Notify->DisplayError(L"SP_SET_INTR"); } - if ( ( Value & SP_CLR_SSTEP ) != 0) { + if ( ( Value & SP_SET_INTR ) != 0) + { + g_Notify->DisplayError(L"SP_SET_INTR"); + } + if ( ( Value & SP_CLR_SSTEP ) != 0) + { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SSTEP; } - if ( ( Value & SP_SET_SSTEP ) != 0) { + if ( ( Value & SP_SET_SSTEP ) != 0) + { g_Reg->SP_STATUS_REG |= SP_STATUS_SSTEP; } - if ( ( Value & SP_CLR_INTR_BREAK ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK; } - if ( ( Value & SP_SET_INTR_BREAK ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_INTR_BREAK; } - if ( ( Value & SP_CLR_SIG0 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG0; } - if ( ( Value & SP_SET_SIG0 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG0; } - if ( ( Value & SP_CLR_SIG1 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG1; } - if ( ( Value & SP_SET_SIG1 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG1; } - if ( ( Value & SP_CLR_SIG2 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG2; } - if ( ( Value & SP_SET_SIG2 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG2; } - if ( ( Value & SP_CLR_SIG3 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG3; } - if ( ( Value & SP_SET_SIG3 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG3; } - if ( ( Value & SP_CLR_SIG4 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG4; } - if ( ( Value & SP_SET_SIG4 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG4; } - if ( ( Value & SP_CLR_SIG5 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG5; } - if ( ( Value & SP_SET_SIG5 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG5; } - if ( ( Value & SP_CLR_SIG6 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG6; } - if ( ( Value & SP_SET_SIG6 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG6; } - if ( ( Value & SP_CLR_SIG7 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG7; } - if ( ( Value & SP_SET_SIG7 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG7; } + if ( ( Value & SP_CLR_INTR_BREAK ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK; + } + if ( ( Value & SP_SET_INTR_BREAK ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_INTR_BREAK; + } + if ( ( Value & SP_CLR_SIG0 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG0; + } + if ( ( Value & SP_SET_SIG0 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG0; + } + if ( ( Value & SP_CLR_SIG1 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG1; + } + if ( ( Value & SP_SET_SIG1 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG1; + } + if ( ( Value & SP_CLR_SIG2 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG2; + } + if ( ( Value & SP_SET_SIG2 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG2; + } + if ( ( Value & SP_CLR_SIG3 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG3; + } + if ( ( Value & SP_SET_SIG3 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG3; + } + if ( ( Value & SP_CLR_SIG4 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG4; + } + if ( ( Value & SP_SET_SIG4 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG4; + } + if ( ( Value & SP_CLR_SIG5 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG5; + } + if ( ( Value & SP_SET_SIG5 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG5; + } + if ( ( Value & SP_CLR_SIG6 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG6; + } + if ( ( Value & SP_SET_SIG6 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG6; + } + if ( ( Value & SP_CLR_SIG7 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG7; + } + if ( ( Value & SP_SET_SIG7 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG7; + } if ( ( Value & SP_SET_SIG0 ) != 0 && g_System->RspAudioSignal()) { g_Reg->MI_INTR_REG |= MI_INTR_SP; g_Reg->CheckInterrupts(); } - //if (*( DWORD *)(DMEM + 0xFC0) == 1) { + //if (*( DWORD *)(DMEM + 0xFC0) == 1) + //{ // ChangeTimer(RspTimer,0x30000); - //} else { - try { + //} + //else + //{ + try + { g_System->RunRSP(); - } catch (...) { + } + catch (...) + { g_Notify->BreakPoint(__FILEW__,__LINE__); } //} @@ -2392,43 +2922,81 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x04100000: - switch (PAddr) { + switch (PAddr) + { case 0x04100000: g_Reg->DPC_START_REG = Value; g_Reg->DPC_CURRENT_REG = Value; break; case 0x04100004: g_Reg->DPC_END_REG = Value; - if (g_Plugins->Gfx()->ProcessRDPList) { g_Plugins->Gfx()->ProcessRDPList(); } + if (g_Plugins->Gfx()->ProcessRDPList) + { + g_Plugins->Gfx()->ProcessRDPList(); + } break; //case 0x04100008: g_Reg->DPC_CURRENT_REG = Value; break; case 0x0410000C: - if ( ( Value & DPC_CLR_XBUS_DMEM_DMA ) != 0) { g_Reg->DPC_STATUS_REG &= ~DPC_STATUS_XBUS_DMEM_DMA; } - if ( ( Value & DPC_SET_XBUS_DMEM_DMA ) != 0) { g_Reg->DPC_STATUS_REG |= DPC_STATUS_XBUS_DMEM_DMA; } - if ( ( Value & DPC_CLR_FREEZE ) != 0) { g_Reg->DPC_STATUS_REG &= ~DPC_STATUS_FREEZE; } - if ( ( Value & DPC_SET_FREEZE ) != 0) { g_Reg->DPC_STATUS_REG |= DPC_STATUS_FREEZE; } - if ( ( Value & DPC_CLR_FLUSH ) != 0) { g_Reg->DPC_STATUS_REG &= ~DPC_STATUS_FLUSH; } - if ( ( Value & DPC_SET_FLUSH ) != 0) { g_Reg->DPC_STATUS_REG |= DPC_STATUS_FLUSH; } + if ( ( Value & DPC_CLR_XBUS_DMEM_DMA ) != 0) + { + g_Reg->DPC_STATUS_REG &= ~DPC_STATUS_XBUS_DMEM_DMA; + } + if ( ( Value & DPC_SET_XBUS_DMEM_DMA ) != 0) + { + g_Reg->DPC_STATUS_REG |= DPC_STATUS_XBUS_DMEM_DMA; + } + if ( ( Value & DPC_CLR_FREEZE ) != 0) + { + g_Reg->DPC_STATUS_REG &= ~DPC_STATUS_FREEZE; + } + if ( ( Value & DPC_SET_FREEZE ) != 0) + { + g_Reg->DPC_STATUS_REG |= DPC_STATUS_FREEZE; + } + if ( ( Value & DPC_CLR_FLUSH ) != 0) + { + g_Reg->DPC_STATUS_REG &= ~DPC_STATUS_FLUSH; + } + if ( ( Value & DPC_SET_FLUSH ) != 0) + { + g_Reg->DPC_STATUS_REG |= DPC_STATUS_FLUSH; + } if ( ( Value & DPC_CLR_FREEZE ) != 0) { if ( ( g_Reg->SP_STATUS_REG & SP_STATUS_HALT ) == 0) { if ( ( g_Reg->SP_STATUS_REG & SP_STATUS_BROKE ) == 0 ) { - try { + try + { g_System->RunRSP(); - } catch (...) { + } + catch (...) + { g_Notify->BreakPoint(__FILEW__,__LINE__); } } } } #ifdef tofix - if (ShowUnhandledMemory) { - //if ( ( Value & DPC_CLR_TMEM_CTR ) != 0) { g_Notify->DisplayError(L"RSP: DPC_STATUS_REG: DPC_CLR_TMEM_CTR"); } - //if ( ( Value & DPC_CLR_PIPE_CTR ) != 0) { g_Notify->DisplayError(L"RSP: DPC_STATUS_REG: DPC_CLR_PIPE_CTR"); } - //if ( ( Value & DPC_CLR_CMD_CTR ) != 0) { g_Notify->DisplayError(L"RSP: DPC_STATUS_REG: DPC_CLR_CMD_CTR"); } - //if ( ( Value & DPC_CLR_CLOCK_CTR ) != 0) { g_Notify->DisplayError(L"RSP: DPC_STATUS_REG: DPC_CLR_CLOCK_CTR"); } + if (ShowUnhandledMemory) + { + //if ( ( Value & DPC_CLR_TMEM_CTR ) != 0) + //{ + // g_Notify->DisplayError(L"RSP: DPC_STATUS_REG: DPC_CLR_TMEM_CTR"); + //} + //if ( ( Value & DPC_CLR_PIPE_CTR ) != 0) + //{ + // g_Notify->DisplayError(L"RSP: DPC_STATUS_REG: DPC_CLR_PIPE_CTR"); + //} + //if ( ( Value & DPC_CLR_CMD_CTR ) != 0) + //{ + // g_Notify->DisplayError(L"RSP: DPC_STATUS_REG: DPC_CLR_CMD_CTR"); + //} + //if ( ( Value & DPC_CLR_CLOCK_CTR ) != 0) + //{ + // g_Notify->DisplayError(L"RSP: DPC_STATUS_REG: DPC_CLR_CLOCK_CTR"); + //} } #endif break; @@ -2437,61 +3005,130 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x04300000: - switch (PAddr) { + switch (PAddr) + { case 0x04300000: g_Reg->MI_MODE_REG &= ~0x7F; g_Reg->MI_MODE_REG |= (Value & 0x7F); - if ( ( Value & MI_CLR_INIT ) != 0 ) { g_Reg->MI_MODE_REG &= ~MI_MODE_INIT; } - if ( ( Value & MI_SET_INIT ) != 0 ) { g_Reg->MI_MODE_REG |= MI_MODE_INIT; } - if ( ( Value & MI_CLR_EBUS ) != 0 ) { g_Reg->MI_MODE_REG &= ~MI_MODE_EBUS; } - if ( ( Value & MI_SET_EBUS ) != 0 ) { g_Reg->MI_MODE_REG |= MI_MODE_EBUS; } - if ( ( Value & MI_CLR_DP_INTR ) != 0 ) { + if ( ( Value & MI_CLR_INIT ) != 0 ) + { + g_Reg->MI_MODE_REG &= ~MI_MODE_INIT; + } + if ( ( Value & MI_SET_INIT ) != 0 ) + { + g_Reg->MI_MODE_REG |= MI_MODE_INIT; + } + if ( ( Value & MI_CLR_EBUS ) != 0 ) + { + g_Reg->MI_MODE_REG &= ~MI_MODE_EBUS; + } + if ( ( Value & MI_SET_EBUS ) != 0 ) + { + g_Reg->MI_MODE_REG |= MI_MODE_EBUS; + } + if ( ( Value & MI_CLR_DP_INTR ) != 0 ) + { g_Reg->MI_INTR_REG &= ~MI_INTR_DP; g_Reg->m_GfxIntrReg &= ~MI_INTR_DP; g_Reg->CheckInterrupts(); } - if ( ( Value & MI_CLR_RDRAM ) != 0 ) { g_Reg->MI_MODE_REG &= ~MI_MODE_RDRAM; } - if ( ( Value & MI_SET_RDRAM ) != 0 ) { g_Reg->MI_MODE_REG |= MI_MODE_RDRAM; } + if ( ( Value & MI_CLR_RDRAM ) != 0 ) + { + g_Reg->MI_MODE_REG &= ~MI_MODE_RDRAM; + } + if ( ( Value & MI_SET_RDRAM ) != 0 ) + { + g_Reg->MI_MODE_REG |= MI_MODE_RDRAM; + } break; case 0x0430000C: - if ( ( Value & MI_INTR_MASK_CLR_SP ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_SP; } - if ( ( Value & MI_INTR_MASK_SET_SP ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_SP; } - if ( ( Value & MI_INTR_MASK_CLR_SI ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_SI; } - if ( ( Value & MI_INTR_MASK_SET_SI ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_SI; } - if ( ( Value & MI_INTR_MASK_CLR_AI ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_AI; } - if ( ( Value & MI_INTR_MASK_SET_AI ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_AI; } - if ( ( Value & MI_INTR_MASK_CLR_VI ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_VI; } - if ( ( Value & MI_INTR_MASK_SET_VI ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_VI; } - if ( ( Value & MI_INTR_MASK_CLR_PI ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_PI; } - if ( ( Value & MI_INTR_MASK_SET_PI ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_PI; } - if ( ( Value & MI_INTR_MASK_CLR_DP ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_DP; } - if ( ( Value & MI_INTR_MASK_SET_DP ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_DP; } + if ( ( Value & MI_INTR_MASK_CLR_SP ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_SP; + } + if ( ( Value & MI_INTR_MASK_SET_SP ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_SP; + } + if ( ( Value & MI_INTR_MASK_CLR_SI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_SI; + } + if ( ( Value & MI_INTR_MASK_SET_SI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_SI; + } + if ( ( Value & MI_INTR_MASK_CLR_AI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_AI; + } + if ( ( Value & MI_INTR_MASK_SET_AI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_AI; + } + if ( ( Value & MI_INTR_MASK_CLR_VI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_VI; + } + if ( ( Value & MI_INTR_MASK_SET_VI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_VI; + } + if ( ( Value & MI_INTR_MASK_CLR_PI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_PI; + } + if ( ( Value & MI_INTR_MASK_SET_PI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_PI; + } + if ( ( Value & MI_INTR_MASK_CLR_DP ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_DP; + } + if ( ( Value & MI_INTR_MASK_SET_DP ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_DP; + } break; default: return FALSE; } break; case 0x04400000: - switch (PAddr) { + switch (PAddr) + { case 0x04400000: - if (g_Reg->VI_STATUS_REG != Value) { + if (g_Reg->VI_STATUS_REG != Value) + { g_Reg->VI_STATUS_REG = Value; - if (g_Plugins->Gfx()->ViStatusChanged != NULL ) { g_Plugins->Gfx()->ViStatusChanged(); } + if (g_Plugins->Gfx()->ViStatusChanged != NULL ) + { + g_Plugins->Gfx()->ViStatusChanged(); + } } break; case 0x04400004: #ifdef CFB_READ - if (g_Reg->VI_ORIGIN_REG > 0x280) { + if (g_Reg->VI_ORIGIN_REG > 0x280) + { SetFrameBuffer(g_Reg->VI_ORIGIN_REG, (DWORD)(VI_WIDTH_REG * (VI_WIDTH_REG *.75))); } #endif g_Reg->VI_ORIGIN_REG = (Value & 0xFFFFFF); - //if (UpdateScreen != NULL ) { UpdateScreen(); } + //if (UpdateScreen != NULL ) + //{ + // UpdateScreen(); + //} break; case 0x04400008: - if (g_Reg->VI_WIDTH_REG != Value) { + if (g_Reg->VI_WIDTH_REG != Value) + { g_Reg->VI_WIDTH_REG = Value; - if (g_Plugins->Gfx()->ViWidthChanged != NULL ) { g_Plugins->Gfx()->ViWidthChanged(); } + if (g_Plugins->Gfx()->ViWidthChanged != NULL ) + { + g_Plugins->Gfx()->ViWidthChanged(); + } } break; case 0x0440000C: g_Reg->VI_INTR_REG = Value; break; @@ -2513,15 +3150,21 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x04500000: - switch (PAddr) { + switch (PAddr) + { case 0x04500000: g_Reg->AI_DRAM_ADDR_REG = Value; break; case 0x04500004: g_Reg->AI_LEN_REG = Value; if (g_System->bFixedAudio()) { g_Audio->LenChanged(); - } else { - if (g_Plugins->Audio()->AiLenChanged != NULL) { g_Plugins->Audio()->AiLenChanged(); } + } + else + { + if (g_Plugins->Audio()->AiLenChanged != NULL) + { + g_Plugins->Audio()->AiLenChanged(); + } } break; case 0x04500008: g_Reg->AI_CONTROL_REG = (Value & 1); break; @@ -2545,7 +3188,8 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x04600000: - switch (PAddr) { + switch (PAddr) + { case 0x04600000: g_Reg->PI_DRAM_ADDR_REG = Value; break; case 0x04600004: g_Reg->PI_CART_ADDR_REG = Value; break; case 0x04600008: @@ -2557,8 +3201,12 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { PI_DMA_WRITE(); break; case 0x04600010: - //if ((Value & PI_SET_RESET) != 0 ) { g_Notify->DisplayError(L"reset Controller"); } - if ((Value & PI_CLR_INTR) != 0 ) { + //if ((Value & PI_SET_RESET) != 0 ) + //{ + // g_Notify->DisplayError(L"reset Controller"); + //} + if ((Value & PI_CLR_INTR) != 0 ) + { g_Reg->MI_INTR_REG &= ~MI_INTR_PI; g_Reg->CheckInterrupts(); } @@ -2576,7 +3224,8 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x04700000: - switch (PAddr) { + switch (PAddr) + { case 0x04700000: g_Reg->RI_MODE_REG = Value; break; case 0x04700004: g_Reg->RI_CONFIG_REG = Value; break; case 0x04700008: g_Reg->RI_CURRENT_LOAD_REG = Value; break; @@ -2590,7 +3239,8 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x04800000: - switch (PAddr) { + switch (PAddr) + { case 0x04800000: g_Reg->SI_DRAM_ADDR_REG = Value; break; case 0x04800004: g_Reg->SI_PIF_ADDR_RD64B_REG = Value; @@ -2610,24 +3260,38 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } break; case 0x08000000: - if (PAddr != 0x08010000) { return FALSE; } - if (g_System->m_SaveUsing == SaveChip_Auto) { g_System->m_SaveUsing = SaveChip_FlashRam; } - if (g_System->m_SaveUsing != SaveChip_FlashRam) { return TRUE; } + if (PAddr != 0x08010000) + { + return FALSE; + } + if (g_System->m_SaveUsing == SaveChip_Auto) + { + g_System->m_SaveUsing = SaveChip_FlashRam; + } + if (g_System->m_SaveUsing != SaveChip_FlashRam) + { + return TRUE; + } WriteToFlashCommand(Value); return TRUE; break; case 0x1FC00000: - if (PAddr < 0x1FC007C0) { + if (PAddr < 0x1FC007C0) + { return FALSE; - } else if (PAddr < 0x1FC00800) { - _asm { + } + else if (PAddr < 0x1FC00800) + { + _asm + { mov eax,Value bswap eax mov Value,eax } *(DWORD *)(&m_PifRam[PAddr - 0x1FC007C0]) = Value; - if (PAddr == 0x1FC007FC) { + if (PAddr == 0x1FC007FC) + { PifRamWrite(); } return TRUE; @@ -2645,7 +3309,8 @@ void CMipsMemoryVM::UpdateHalfLine (void) { DWORD NextViTimer = g_SystemTimer->GetTimer(CSystemTimer::ViTimer); - if (*g_NextTimer < 0) { + if (*g_NextTimer < 0) + { m_HalfLine = 0; return; } @@ -2676,18 +3341,30 @@ void CMipsMemoryVM::UpdateFieldSerration (unsigned int interlaced) void CMipsMemoryVM::ProtectMemory( DWORD StartVaddr, DWORD EndVaddr ) { WriteTraceF(TraceProtectedMem,__FUNCTION__ ": StartVaddr: %X EndVaddr: %X",StartVaddr,EndVaddr); - if (!ValidVaddr(StartVaddr) || !ValidVaddr(EndVaddr)) { return; } + if (!ValidVaddr(StartVaddr) || !ValidVaddr(EndVaddr)) + { + return; + } //Get Physical Addresses passed DWORD StartPAddr, EndPAddr; - if (!TranslateVaddr(StartVaddr,StartPAddr)) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - if (!TranslateVaddr(EndVaddr,EndPAddr)) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (!TranslateVaddr(StartVaddr,StartPAddr)) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } + if (!TranslateVaddr(EndVaddr,EndPAddr)) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } //Get Length of memory being protected int Length = ((EndPAddr + 3) - StartPAddr) & ~3; - if (Length < 0) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (Length < 0) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } - //Proect that memory address space + //Protect that memory address space DWORD OldProtect; BYTE * MemLoc = Rdram() + StartPAddr; WriteTraceF(TraceProtectedMem, __FUNCTION__ ": Paddr: %X Length: %X",StartPAddr,Length); @@ -2702,14 +3379,23 @@ void CMipsMemoryVM::UnProtectMemory( DWORD StartVaddr, DWORD EndVaddr ) //Get Physical Addresses passed DWORD StartPAddr, EndPAddr; - if (!TranslateVaddr(StartVaddr,StartPAddr)) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - if (!TranslateVaddr(EndVaddr,EndPAddr)) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (!TranslateVaddr(StartVaddr,StartPAddr)) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } + if (!TranslateVaddr(EndVaddr,EndPAddr)) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } //Get Length of memory being protected int Length = ((EndPAddr + 3) - StartPAddr) & ~3; - if (Length < 0) { g_Notify->BreakPoint(__FILEW__,__LINE__); } + if (Length < 0) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + } - //Proect that memory address space + //Protect that memory address space DWORD OldProtect; BYTE * MemLoc = Rdram() + StartPAddr; @@ -2723,28 +3409,42 @@ void CMipsMemoryVM::Compile_LB (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.rt == 0) return; + if (Opcode.rt == 0) + { + return; + } - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = (GetMipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 3; Map_GPR_32bit(Opcode.rt,TRUE,-1); Compile_LB(GetMipsRegMapLo(Opcode.rt),Address,TRUE); return; } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -2753,7 +3453,9 @@ void CMipsMemoryVM::Compile_LB (void) XorConstToX86Reg(TempReg1,3); Map_GPR_32bit(Opcode.rt,TRUE,-1); MoveSxByteX86regPointerToX86reg(TempReg1, TempReg2,GetMipsRegMapLo(Opcode.rt)); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); XorConstToX86Reg(TempReg1,3); Map_GPR_32bit(Opcode.rt,TRUE,-1); @@ -2768,28 +3470,42 @@ void CMipsMemoryVM::Compile_LBU (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.rt == 0) return; + if (Opcode.rt == 0) + { + return; + } - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = (GetMipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 3; Map_GPR_32bit(Opcode.rt,FALSE,-1); Compile_LB(GetMipsRegMapLo(Opcode.rt),Address,FALSE); return; } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -2798,7 +3514,9 @@ void CMipsMemoryVM::Compile_LBU (void) XorConstToX86Reg(TempReg1,3); Map_GPR_32bit(Opcode.rt,FALSE,-1); MoveZxByteX86regPointerToX86reg(TempReg1, TempReg2,GetMipsRegMapLo(Opcode.rt)); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); XorConstToX86Reg(TempReg1,3); Map_GPR_32bit(Opcode.rt,FALSE,-1); @@ -2815,26 +3533,37 @@ void CMipsMemoryVM::Compile_LH (void) if (Opcode.rt == 0) return; - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = (GetMipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 2; Map_GPR_32bit(Opcode.rt,TRUE,-1); Compile_LH(GetMipsRegMapLo(Opcode.rt),Address,TRUE); return; } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -2843,7 +3572,9 @@ void CMipsMemoryVM::Compile_LH (void) XorConstToX86Reg(TempReg1,2); Map_GPR_32bit(Opcode.rt,TRUE,-1); MoveSxHalfX86regPointerToX86reg(TempReg1, TempReg2,GetMipsRegMapLo(Opcode.rt)); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); XorConstToX86Reg(TempReg1,2); Map_GPR_32bit(Opcode.rt,TRUE,-1); @@ -2858,28 +3589,42 @@ void CMipsMemoryVM::Compile_LHU (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.rt == 0) return; + if (Opcode.rt == 0) + { + return; + } - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = (GetMipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 2; Map_GPR_32bit(Opcode.rt,FALSE,-1); Compile_LH(GetMipsRegMapLo(Opcode.rt),Address,FALSE); return; } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -2888,7 +3633,9 @@ void CMipsMemoryVM::Compile_LHU (void) XorConstToX86Reg(TempReg1,2); Map_GPR_32bit(Opcode.rt,FALSE,-1); MoveZxHalfX86regPointerToX86reg(TempReg1, TempReg2,GetMipsRegMapLo(Opcode.rt)); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); XorConstToX86Reg(TempReg1,2); Map_GPR_32bit(Opcode.rt,TRUE,-1); @@ -2914,7 +3661,8 @@ void CMipsMemoryVM::Compile_LW (bool ResultSigned, bool bRecordLLBit) if (Opcode.rt == 0) return; x86Reg TempReg1, TempReg2; - if (Opcode.base == 29 && g_System->bFastSP()) { + if (Opcode.base == 29 && g_System->bFastSP()) + { char String[100]; Map_GPR_32bit(Opcode.rt,ResultSigned,-1); @@ -2925,8 +3673,11 @@ void CMipsMemoryVM::Compile_LW (bool ResultSigned, bool bRecordLLBit) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - } else { - if (IsConst(Opcode.base)) { + } + else + { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; Map_GPR_32bit(Opcode.rt,ResultSigned,-1); Compile_LW(GetMipsRegMapLo(Opcode.rt),Address); @@ -2934,22 +3685,36 @@ void CMipsMemoryVM::Compile_LW (bool ResultSigned, bool bRecordLLBit) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - } else { - if (g_System->bUseTlb()) { - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { + } + else + { + if (g_System->bUseTlb()) + { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base) && Opcode.offset == 0) + { ProtectGPR(Opcode.base); TempReg1 = GetMipsRegMapLo(Opcode.base); - } else { - if (IsMapped(Opcode.base)) { + } + else + { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); if (Opcode.offset != 0) { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } @@ -2965,16 +3730,24 @@ void CMipsMemoryVM::Compile_LW (bool ResultSigned, bool bRecordLLBit) { MoveConstToVariable(1,_LLBit,"LLBit"); } - } else { - if (IsMapped(Opcode.base)) { + } + else + { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { Map_GPR_32bit(Opcode.rt,ResultSigned,-1); LeaSourceAndOffset(GetMipsRegMapLo(Opcode.rt),GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { Map_GPR_32bit(Opcode.rt,ResultSigned,Opcode.base); } - } else { + } + else + { Map_GPR_32bit(Opcode.rt,ResultSigned,Opcode.base); AddConstToX86Reg(GetMipsRegMapLo(Opcode.rt),(short)Opcode.immediate); } @@ -3003,17 +3776,23 @@ void CMipsMemoryVM::Compile_LWC1 (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); m_Section->CompileCop1Test(); - if ((Opcode.ft & 1) != 0) { - if (RegInStack(Opcode.ft-1,CRegInfo::FPU_Double) || RegInStack(Opcode.ft-1,CRegInfo::FPU_Qword)) { + if ((Opcode.ft & 1) != 0) + { + if (RegInStack(Opcode.ft-1,CRegInfo::FPU_Double) || RegInStack(Opcode.ft-1,CRegInfo::FPU_Qword)) + { UnMap_FPR(Opcode.ft-1,TRUE); } } - if (RegInStack(Opcode.ft,CRegInfo::FPU_Double) || RegInStack(Opcode.ft,CRegInfo::FPU_Qword)) { + if (RegInStack(Opcode.ft,CRegInfo::FPU_Double) || RegInStack(Opcode.ft,CRegInfo::FPU_Qword)) + { UnMap_FPR(Opcode.ft,TRUE); - } else { + } + else + { UnMap_FPR(Opcode.ft,FALSE); } - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; TempReg1 = Map_TempReg(x86_Any,-1,FALSE); @@ -3025,37 +3804,58 @@ void CMipsMemoryVM::Compile_LWC1 (void) MoveX86regToX86Pointer(TempReg1,TempReg2); return; } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { - if (g_System->bUseTlb()) { + if (IsMapped(Opcode.base) && Opcode.offset == 0) + { + if (g_System->bUseTlb()) + { ProtectGPR(Opcode.base); TempReg1 = GetMipsRegMapLo(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { - if (IsMapped(Opcode.base)) { + } + else + { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { + if (Opcode.immediate == 0) + { + + } + else if (Opcode.immediate == 1) + { IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { + } + else if (Opcode.immediate == 0xFFFF) + { DecX86reg(TempReg1); - } else { + } + else + { AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } } } TempReg2 = Map_TempReg(x86_Any,-1,FALSE); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); MoveVariableDispToX86Reg(m_TLB_ReadMap,"m_TLB_ReadMap",TempReg2,TempReg2,4); @@ -3063,7 +3863,9 @@ void CMipsMemoryVM::Compile_LWC1 (void) TempReg3 = Map_TempReg(x86_Any,-1,FALSE); MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg3); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); TempReg3 = Map_TempReg(x86_Any,-1,FALSE); MoveN64MemToX86reg(TempReg3,TempReg1); @@ -3080,9 +3882,13 @@ void CMipsMemoryVM::Compile_LWL (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.rt == 0) return; + if (Opcode.rt == 0) + { + return; + } - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; DWORD Offset = Address & 3; @@ -3096,21 +3902,31 @@ void CMipsMemoryVM::Compile_LWL (void) } shift = Map_TempReg(x86_ECX,-1,FALSE); - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -3126,9 +3942,12 @@ void CMipsMemoryVM::Compile_LWL (void) Map_GPR_32bit(Opcode.rt,TRUE,Opcode.rt); AndVariableDispToX86Reg((void *)LWL_MASK,"LWL_MASK",GetMipsRegMapLo(Opcode.rt),OffsetReg,Multip_x4); MoveVariableDispToX86Reg((void *)LWL_SHIFT,"LWL_SHIFT",shift,OffsetReg,4); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg1); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); MoveN64MemToX86reg(TempReg1,TempReg1); } @@ -3143,9 +3962,13 @@ void CMipsMemoryVM::Compile_LWR (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.rt == 0) return; + if (Opcode.rt == 0) + { + return; + } - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; DWORD Offset = Address & 3; @@ -3159,22 +3982,32 @@ void CMipsMemoryVM::Compile_LWR (void) } shift = Map_TempReg(x86_ECX,-1,FALSE); - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -3190,9 +4023,12 @@ void CMipsMemoryVM::Compile_LWR (void) Map_GPR_32bit(Opcode.rt,TRUE,Opcode.rt); AndVariableDispToX86Reg((void *)LWR_MASK,"LWR_MASK",GetMipsRegMapLo(Opcode.rt),OffsetReg,Multip_x4); MoveVariableDispToX86Reg((void *)LWR_SHIFT,"LWR_SHIFT",shift,OffsetReg,4); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg1); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); MoveN64MemToX86reg(TempReg1,TempReg1); } @@ -3210,11 +4046,15 @@ void CMipsMemoryVM::Compile_LD (void) OPCODE & Opcode = CRecompilerOps::m_Opcode; CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.rt == 0) return; + if (Opcode.rt == 0) + { + return; + } x86Reg TempReg1, TempReg2; - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; Map_GPR_64bit(Opcode.rt,-1); Compile_LW(GetMipsRegMapHi(Opcode.rt),Address); @@ -3225,29 +4065,45 @@ void CMipsMemoryVM::Compile_LD (void) } return; } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { - if (g_System->bUseTlb()) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base) && Opcode.offset == 0) + { + if (g_System->bUseTlb()) + { ProtectGPR(Opcode.base); TempReg1 = GetMipsRegMapLo(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { - if (IsMapped(Opcode.base)) { + } + else + { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -3256,7 +4112,9 @@ void CMipsMemoryVM::Compile_LD (void) Map_GPR_64bit(Opcode.rt,-1); MoveX86regPointerToX86reg(TempReg1, TempReg2,GetMipsRegMapHi(Opcode.rt)); MoveX86regPointerToX86regDisp8(TempReg1, TempReg2,GetMipsRegMapLo(Opcode.rt),4); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); Map_GPR_64bit(Opcode.rt,-1); MoveN64MemToX86reg(GetMipsRegMapHi(Opcode.rt),TempReg1); @@ -3280,7 +4138,8 @@ void CMipsMemoryVM::Compile_LDC1 (void) m_Section->CompileCop1Test(); UnMap_FPR(Opcode.ft,FALSE); - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; TempReg1 = Map_TempReg(x86_Any,-1,FALSE); Compile_LW(TempReg1,Address); @@ -3297,37 +4156,58 @@ void CMipsMemoryVM::Compile_LDC1 (void) MoveX86regToX86Pointer(TempReg1,TempReg2); return; } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { - if (g_System->bUseTlb()) { + if (IsMapped(Opcode.base) && Opcode.offset == 0) + { + if (g_System->bUseTlb()) + { ProtectGPR(Opcode.base); TempReg1 = GetMipsRegMapLo(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { - if (IsMapped(Opcode.base)) { + } + else + { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { + if (Opcode.immediate == 0) + { + + } + else if (Opcode.immediate == 1) + { IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { + } + else if (Opcode.immediate == 0xFFFF) + { DecX86reg(TempReg1); - } else { + } + else + { AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } } } TempReg2 = Map_TempReg(x86_Any,-1,FALSE); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); MoveVariableDispToX86Reg(m_TLB_ReadMap,"m_TLB_ReadMap",TempReg2,TempReg2,4); @@ -3344,7 +4224,9 @@ void CMipsMemoryVM::Compile_LDC1 (void) sprintf(Name,"_FPR_S[%d]",Opcode.ft); MoveVariableToX86reg(&_FPR_D[Opcode.ft],Name,TempReg2); MoveX86regToX86Pointer(TempReg3,TempReg2); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); TempReg3 = Map_TempReg(x86_Any,-1,FALSE); MoveN64MemToX86reg(TempReg3,TempReg1); @@ -3366,8 +4248,14 @@ void CMipsMemoryVM::Compile_LDL (void) OPCODE & Opcode = CRecompilerOps::m_Opcode; CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.base != 0) { UnMap_GPR(Opcode.base,TRUE); } - if (Opcode.rt != 0) { UnMap_GPR(Opcode.rt,TRUE); } + if (Opcode.base != 0) + { + UnMap_GPR(Opcode.base,TRUE); + } + if (Opcode.rt != 0) + { + UnMap_GPR(Opcode.rt,TRUE); + } BeforeCallDirect(m_RegWorkingSet); MoveConstToVariable(Opcode.Hex, &R4300iOp::m_Opcode.Hex, "R4300iOp::m_Opcode.Hex"); Call_Direct(R4300iOp::LDL, "R4300iOp::LDL"); @@ -3379,8 +4267,14 @@ void CMipsMemoryVM::Compile_LDR (void) OPCODE & Opcode = CRecompilerOps::m_Opcode; CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.base != 0) { UnMap_GPR(Opcode.base,TRUE); } - if (Opcode.rt != 0) { UnMap_GPR(Opcode.rt,TRUE); } + if (Opcode.base != 0) + { + UnMap_GPR(Opcode.base,TRUE); + } + if (Opcode.rt != 0) + { + UnMap_GPR(Opcode.rt,TRUE); + } BeforeCallDirect(m_RegWorkingSet); MoveConstToVariable(Opcode.Hex, &R4300iOp::m_Opcode.Hex, "R4300iOp::m_Opcode.Hex"); Call_Direct(R4300iOp::LDR, "R4300iOp::LDR"); @@ -3394,56 +4288,83 @@ void CMipsMemoryVM::Compile_SB (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = (GetMipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 3; - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { Compile_SB_Const((BYTE)(GetMipsRegLo(Opcode.rt) & 0xFF), Address); - } else if (IsMapped(Opcode.rt) && Is8BitReg(GetMipsRegMapLo(Opcode.rt))) { + } + else if (IsMapped(Opcode.rt) && Is8BitReg(GetMipsRegMapLo(Opcode.rt))) + { Compile_SB_Register(GetMipsRegMapLo(Opcode.rt), Address); - } else { + } + else + { Compile_SB_Register(Map_TempReg(x86_Any8Bit,Opcode.rt,FALSE), Address); } return; } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } Compile_StoreInstructClean(TempReg1,4); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); MoveVariableDispToX86Reg(m_TLB_WriteMap,"m_TLB_WriteMap",TempReg2,TempReg2,4); CompileWriteTLBMiss(TempReg1,TempReg2); XorConstToX86Reg(TempReg1,3); - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstByteToX86regPointer((BYTE)(GetMipsRegLo(Opcode.rt) & 0xFF),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt) && Is8BitReg(GetMipsRegMapLo(Opcode.rt))) { + } + else if (IsMapped(Opcode.rt) && Is8BitReg(GetMipsRegMapLo(Opcode.rt))) + { MoveX86regByteToX86regPointer(GetMipsRegMapLo(Opcode.rt),TempReg1, TempReg2); - } else { + } + else + { UnProtectGPR(Opcode.rt); MoveX86regByteToX86regPointer(Map_TempReg(x86_Any8Bit,Opcode.rt,FALSE),TempReg1, TempReg2); } - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); XorConstToX86Reg(TempReg1,3); - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstByteToN64Mem((BYTE)(GetMipsRegLo(Opcode.rt) & 0xFF),TempReg1); - } else if (IsMapped(Opcode.rt) && Is8BitReg(GetMipsRegMapLo(Opcode.rt))) { + } else if (IsMapped(Opcode.rt) && Is8BitReg(GetMipsRegMapLo(Opcode.rt))) + { MoveX86regByteToN64Mem(GetMipsRegMapLo(Opcode.rt),TempReg1); - } else { + } + else + { UnProtectGPR(Opcode.rt); MoveX86regByteToN64Mem(Map_TempReg(x86_Any8Bit,Opcode.rt,FALSE),TempReg1); } @@ -3457,54 +4378,82 @@ void CMipsMemoryVM::Compile_SH (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = (GetMipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 2; - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { Compile_SH_Const((WORD)(GetMipsRegLo(Opcode.rt) & 0xFFFF), Address); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { Compile_SH_Register(GetMipsRegMapLo(Opcode.rt), Address); - } else { + } + else + { Compile_SH_Register(Map_TempReg(x86_Any,Opcode.rt,FALSE), Address); } return; } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); MoveVariableDispToX86Reg(m_TLB_WriteMap,"m_TLB_WriteMap",TempReg2,TempReg2,4); CompileWriteTLBMiss(TempReg1,TempReg2); XorConstToX86Reg(TempReg1,2); - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstHalfToX86regPointer((WORD)(GetMipsRegLo(Opcode.rt) & 0xFFFF),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { MoveX86regHalfToX86regPointer(GetMipsRegMapLo(Opcode.rt),TempReg1, TempReg2); - } else { + } + else + { MoveX86regHalfToX86regPointer(Map_TempReg(x86_Any,Opcode.rt,FALSE),TempReg1, TempReg2); } - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); XorConstToX86Reg(TempReg1,2); - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstHalfToN64Mem((WORD)(GetMipsRegLo(Opcode.rt) & 0xFFFF),TempReg1); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { MoveX86regHalfToN64Mem(GetMipsRegMapLo(Opcode.rt),TempReg1); - } else { + } + else + { MoveX86regHalfToN64Mem(Map_TempReg(x86_Any,Opcode.rt,FALSE),TempReg1); } } @@ -3526,41 +4475,62 @@ void CMipsMemoryVM::Compile_SW (bool bCheckLLbit) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); x86Reg TempReg1, TempReg2; - if (Opcode.base == 29 && g_System->bFastSP()) { + if (Opcode.base == 29 && g_System->bFastSP()) + { if (bCheckLLbit) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } TempReg1 = Map_MemoryStack(x86_Any,true); - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstToMemoryDisp (GetMipsRegLo(Opcode.rt),TempReg1, (DWORD)((short)Opcode.offset)); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { MoveX86regToMemory(GetMipsRegMapLo(Opcode.rt),TempReg1,(DWORD)((short)Opcode.offset)); - } else { + } + else + { TempReg2 = Map_TempReg(x86_Any,Opcode.rt,FALSE); MoveX86regToMemory(TempReg2,TempReg1,(DWORD)((short)Opcode.offset)); } - } else { - if (IsConst(Opcode.base)) { + } + else + { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; if (bCheckLLbit) { g_Notify->BreakPoint(__FILEW__,__LINE__); } - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { Compile_SW_Const(GetMipsRegLo(Opcode.rt), Address); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { Compile_SW_Register(GetMipsRegMapLo(Opcode.rt), Address); - } else { + } + else + { Compile_SW_Register(Map_TempReg(x86_Any,Opcode.rt,FALSE), Address); } return; } - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); if (g_System->bDelaySI() || g_System->bDelayDP()) { @@ -3568,19 +4538,25 @@ void CMipsMemoryVM::Compile_SW (bool bCheckLLbit) UpdateCounters(m_RegWorkingSet,false, true); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); } - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } Compile_StoreInstructClean(TempReg1,4); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -3593,11 +4569,15 @@ void CMipsMemoryVM::Compile_SW (bool bCheckLLbit) JneLabel8("LLBit_Continue",0); Jump = m_RecompPos - 1; } - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstToX86regPointer(GetMipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt)) { + } else if (IsMapped(Opcode.rt)) + { MoveX86regToX86regPointer(GetMipsRegMapLo(Opcode.rt),TempReg1, TempReg2); - } else { + } + else + { MoveX86regToX86regPointer(Map_TempReg(x86_Any,Opcode.rt,FALSE),TempReg1, TempReg2); } if (bCheckLLbit) @@ -3608,17 +4588,24 @@ void CMipsMemoryVM::Compile_SW (bool bCheckLLbit) Map_GPR_32bit(Opcode.rt,false,-1); MoveVariableToX86reg(_LLBit,"_LLBit",GetMipsRegMapLo(Opcode.rt)); } - } else { + } + else + { if (bCheckLLbit) { g_Notify->BreakPoint(__FILEW__,__LINE__); } AndConstToX86Reg(TempReg1,0x1FFFFFFF); - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstToN64Mem(GetMipsRegLo(Opcode.rt),TempReg1); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { MoveX86regToN64Mem(GetMipsRegMapLo(Opcode.rt),TempReg1); - } else { + } + else + { MoveX86regToN64Mem(Map_TempReg(x86_Any,Opcode.rt,FALSE),TempReg1); } } @@ -3635,7 +4622,8 @@ void CMipsMemoryVM::Compile_SWC1 (void) m_Section->CompileCop1Test(); - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; UnMap_FPR(Opcode.ft,TRUE); @@ -3647,26 +4635,40 @@ void CMipsMemoryVM::Compile_SWC1 (void) Compile_SW_Register(TempReg1, Address); return; } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { + if (Opcode.immediate == 0) + { + + } + else if (Opcode.immediate == 1) + { IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { + } else if (Opcode.immediate == 0xFFFF) + { DecX86reg(TempReg1); - } else { + } + else + { AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -3679,7 +4681,9 @@ void CMipsMemoryVM::Compile_SWC1 (void) MoveVariableToX86reg(&_FPR_S[Opcode.ft],Name,TempReg3); MoveX86PointerToX86reg(TempReg3,TempReg3); MoveX86regToX86regPointer(TempReg3,TempReg1, TempReg2); - } else { + } + else + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); UnMap_FPR(Opcode.ft,TRUE); sprintf(Name,"_FPR_S[%d]",Opcode.ft); @@ -3698,7 +4702,8 @@ void CMipsMemoryVM::Compile_SWL (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address; Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; @@ -3714,20 +4719,27 @@ void CMipsMemoryVM::Compile_SWL (void) return; } shift = Map_TempReg(x86_ECX,-1,FALSE); - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -3741,34 +4753,46 @@ void CMipsMemoryVM::Compile_SWL (void) AndConstToX86Reg(TempReg1,(DWORD)~3); Value = Map_TempReg(x86_Any,-1,FALSE); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { MoveX86regPointerToX86reg(TempReg1, TempReg2,Value); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); MoveN64MemToX86reg(Value,TempReg1); } AndVariableDispToX86Reg((void *)SWL_MASK,"SWL_MASK",Value,OffsetReg,Multip_x4); - if (!IsConst(Opcode.rt) || GetMipsRegLo(Opcode.rt) != 0) { + if (!IsConst(Opcode.rt) || GetMipsRegLo(Opcode.rt) != 0) + { MoveVariableDispToX86Reg((void *)SWL_SHIFT,"SWL_SHIFT",shift,OffsetReg,4); - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstToX86reg(GetMipsRegLo(Opcode.rt),OffsetReg); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { MoveX86RegToX86Reg(GetMipsRegMapLo(Opcode.rt),OffsetReg); - } else { + } + else + { MoveVariableToX86reg(&_GPR[Opcode.rt].UW[0],CRegName::GPR_Lo[Opcode.rt],OffsetReg); } ShiftRightUnsign(OffsetReg); AddX86RegToX86Reg(Value,OffsetReg); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); MoveVariableDispToX86Reg(m_TLB_WriteMap,"m_TLB_WriteMap",TempReg2,TempReg2,4); MoveX86regToX86regPointer(Value,TempReg1, TempReg2); - } else { + } + else + { MoveX86regToN64Mem(Value,TempReg1); } } @@ -3781,7 +4805,8 @@ void CMipsMemoryVM::Compile_SWR (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; DWORD Offset = Address & 3; @@ -3795,20 +4820,27 @@ void CMipsMemoryVM::Compile_SWR (void) return; } shift = Map_TempReg(x86_ECX,-1,FALSE); - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -3822,34 +4854,46 @@ void CMipsMemoryVM::Compile_SWR (void) AndConstToX86Reg(TempReg1,(DWORD)~3); Value = Map_TempReg(x86_Any,-1,FALSE); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { MoveX86regPointerToX86reg(TempReg1, TempReg2,Value); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); MoveN64MemToX86reg(Value,TempReg1); } AndVariableDispToX86Reg((void *)SWR_MASK,"SWR_MASK",Value,OffsetReg,Multip_x4); - if (!IsConst(Opcode.rt) || GetMipsRegLo(Opcode.rt) != 0) { + if (!IsConst(Opcode.rt) || GetMipsRegLo(Opcode.rt) != 0) + { MoveVariableDispToX86Reg((void *)SWR_SHIFT,"SWR_SHIFT",shift,OffsetReg,4); - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { MoveConstToX86reg(GetMipsRegLo(Opcode.rt),OffsetReg); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { MoveX86RegToX86Reg(GetMipsRegMapLo(Opcode.rt),OffsetReg); - } else { + } + else + { MoveVariableToX86reg(&_GPR[Opcode.rt].UW[0],CRegName::GPR_Lo[Opcode.rt],OffsetReg); } ShiftLeftSign(OffsetReg); AddX86RegToX86Reg(Value,OffsetReg); } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); MoveVariableDispToX86Reg(m_TLB_WriteMap,"m_TLB_WriteMap",TempReg2,TempReg2,4); MoveX86regToX86regPointer(Value,TempReg1, TempReg2); - } else { + } + else + { MoveX86regToN64Mem(Value,TempReg1); } } @@ -3913,88 +4957,134 @@ void CMipsMemoryVM::Compile_SD (void) CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; - if (IsConst(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { Compile_SW_Const(Is64Bit(Opcode.rt) ? GetMipsRegHi(Opcode.rt) : (GetMipsRegLo_S(Opcode.rt) >> 31), Address); Compile_SW_Const(GetMipsRegLo(Opcode.rt), Address + 4); - } else if (IsMapped(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { Compile_SW_Register(Is64Bit(Opcode.rt) ? GetMipsRegMapHi(Opcode.rt) : Map_TempReg(x86_Any,Opcode.rt,TRUE), Address); Compile_SW_Register(GetMipsRegMapLo(Opcode.rt), Address + 4); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.rt,TRUE); Compile_SW_Register(TempReg1, Address); Compile_SW_Register(Map_TempReg(TempReg1,Opcode.rt,FALSE), Address + 4); } - } else { - if (IsMapped(Opcode.rt)) { ProtectGPR(Opcode.rt); } - if (IsMapped(Opcode.base)) { + } + else + { + if (IsMapped(Opcode.rt)) + { + ProtectGPR(Opcode.rt); + } + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } UnProtectGPR(Opcode.base); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } Compile_StoreInstructClean(TempReg1,8); - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); MoveVariableDispToX86Reg(m_TLB_WriteMap,"m_TLB_WriteMap",TempReg2,TempReg2,4); CompileWriteTLBMiss(TempReg1,TempReg2); - if (IsConst(Opcode.rt)) { - if (Is64Bit(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { + if (Is64Bit(Opcode.rt)) + { MoveConstToX86regPointer(GetMipsRegHi(Opcode.rt),TempReg1, TempReg2); - } else { + } + else + { MoveConstToX86regPointer((GetMipsRegLo_S(Opcode.rt) >> 31),TempReg1, TempReg2); } AddConstToX86Reg(TempReg1,4); MoveConstToX86regPointer(GetMipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt)) { - if (Is64Bit(Opcode.rt)) { + } + else if (IsMapped(Opcode.rt)) + { + if (Is64Bit(Opcode.rt)) + { MoveX86regToX86regPointer(GetMipsRegMapHi(Opcode.rt),TempReg1, TempReg2); - } else { + } + else + { MoveX86regToX86regPointer(Map_TempReg(x86_Any,Opcode.rt,TRUE),TempReg1, TempReg2); } AddConstToX86Reg(TempReg1,4); MoveX86regToX86regPointer(GetMipsRegMapLo(Opcode.rt),TempReg1, TempReg2); - } else { + } + else + { x86Reg Reg = Map_TempReg(x86_Any,Opcode.rt,TRUE); MoveX86regToX86regPointer(Reg,TempReg1, TempReg2); AddConstToX86Reg(TempReg1,4); MoveX86regToX86regPointer(Map_TempReg(Reg,Opcode.rt,FALSE),TempReg1, TempReg2); } - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); - if (IsConst(Opcode.rt)) { - if (Is64Bit(Opcode.rt)) { + if (IsConst(Opcode.rt)) + { + if (Is64Bit(Opcode.rt)) + { MoveConstToN64Mem(GetMipsRegHi(Opcode.rt),TempReg1); - } else if (IsSigned(Opcode.rt)) { + } + else if (IsSigned(Opcode.rt)) + { MoveConstToN64Mem((GetMipsRegLo_S(Opcode.rt) >> 31),TempReg1); - } else { + } + else + { MoveConstToN64Mem(0,TempReg1); } MoveConstToN64MemDisp(GetMipsRegLo(Opcode.rt),TempReg1,4); - } else if (IsKnown(Opcode.rt) && IsMapped(Opcode.rt)) { - if (Is64Bit(Opcode.rt)) { + } + else if (IsKnown(Opcode.rt) && IsMapped(Opcode.rt)) + { + if (Is64Bit(Opcode.rt)) + { MoveX86regToN64Mem(GetMipsRegMapHi(Opcode.rt),TempReg1); - } else if (IsSigned(Opcode.rt)) { + } + else if (IsSigned(Opcode.rt)) + { MoveX86regToN64Mem(Map_TempReg(x86_Any,Opcode.rt,TRUE), TempReg1); - } else { + } + else + { MoveConstToN64Mem(0,TempReg1); } MoveX86regToN64MemDisp(GetMipsRegMapLo(Opcode.rt),TempReg1, 4); - } else { + } + else + { x86Reg Reg; MoveX86regToN64Mem(Reg = Map_TempReg(x86_Any,Opcode.rt,TRUE), TempReg1); MoveX86regToN64MemDisp(Map_TempReg(Reg,Opcode.rt,FALSE), TempReg1,4); @@ -4013,7 +5103,8 @@ void CMipsMemoryVM::Compile_SDC1 (void) m_Section->CompileCop1Test(); - if (IsConst(Opcode.base)) { + if (IsConst(Opcode.base)) + { DWORD Address = GetMipsRegLo(Opcode.base) + (short)Opcode.offset; TempReg1 = Map_TempReg(x86_Any,-1,FALSE); @@ -4029,26 +5120,41 @@ void CMipsMemoryVM::Compile_SDC1 (void) Compile_SW_Register(TempReg1, Address + 4); return; } - if (IsMapped(Opcode.base)) { + if (IsMapped(Opcode.base)) + { ProtectGPR(Opcode.base); - if (Opcode.offset != 0) { + if (Opcode.offset != 0) + { TempReg1 = Map_TempReg(x86_Any,-1,FALSE); LeaSourceAndOffset(TempReg1,GetMipsRegMapLo(Opcode.base),(short)Opcode.offset); - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); } - } else { + } + else + { TempReg1 = Map_TempReg(x86_Any,Opcode.base,FALSE); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { + if (Opcode.immediate == 0) + { + + } + else if (Opcode.immediate == 1) + { IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { + } + else if (Opcode.immediate == 0xFFFF) + { DecX86reg(TempReg1); - } else { + } + else + { AddConstToX86Reg(TempReg1,(short)Opcode.immediate); } } - if (g_System->bUseTlb()) { + if (g_System->bUseTlb()) + { TempReg2 = Map_TempReg(x86_Any,-1,FALSE); MoveX86RegToX86Reg(TempReg1, TempReg2); ShiftRightUnsignImmed(TempReg2,12); @@ -4067,7 +5173,9 @@ void CMipsMemoryVM::Compile_SDC1 (void) MoveVariableToX86reg((BYTE *)&_FPR_D[Opcode.ft],Name,TempReg3); MoveX86PointerToX86reg(TempReg3,TempReg3); MoveX86regToX86regPointer(TempReg3,TempReg1, TempReg2); - } else { + } + else + { AndConstToX86Reg(TempReg1,0x1FFFFFFF); TempReg3 = Map_TempReg(x86_Any,-1,FALSE); sprintf(Name,"_FPR_D[%d]",Opcode.ft); @@ -4082,24 +5190,38 @@ void CMipsMemoryVM::Compile_SDC1 (void) } } -void CMipsMemoryVM::Compile_SDL (void) { +void CMipsMemoryVM::Compile_SDL (void) +{ OPCODE & Opcode = CRecompilerOps::m_Opcode; CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.base != 0) { UnMap_GPR(Opcode.base,TRUE); } - if (Opcode.rt != 0) { UnMap_GPR(Opcode.rt,TRUE); } + if (Opcode.base != 0) + { + UnMap_GPR(Opcode.base,TRUE); + } + if (Opcode.rt != 0) + { + UnMap_GPR(Opcode.rt,TRUE); + } BeforeCallDirect(m_RegWorkingSet); MoveConstToVariable(Opcode.Hex, &R4300iOp::m_Opcode.Hex, "R4300iOp::m_Opcode.Hex"); Call_Direct(R4300iOp::SDL, "R4300iOp::SDL"); AfterCallDirect(m_RegWorkingSet); } -void CMipsMemoryVM::Compile_SDR (void) { +void CMipsMemoryVM::Compile_SDR (void) +{ OPCODE & Opcode = CRecompilerOps::m_Opcode; CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(Opcode.Hex,m_CompilePC)); - if (Opcode.base != 0) { UnMap_GPR(Opcode.base,TRUE); } - if (Opcode.rt != 0) { UnMap_GPR(Opcode.rt,TRUE); } + if (Opcode.base != 0) + { + UnMap_GPR(Opcode.base,TRUE); + } + if (Opcode.rt != 0) + { + UnMap_GPR(Opcode.rt,TRUE); + } BeforeCallDirect(m_RegWorkingSet); MoveConstToVariable(Opcode.Hex, &R4300iOp::m_Opcode.Hex, "R4300iOp::m_Opcode.Hex"); Call_Direct(R4300iOp::SDR, "R4300iOp::SDR"); @@ -4109,7 +5231,8 @@ void CMipsMemoryVM::Compile_SDR (void) { LPCTSTR CMipsMemoryVM::LabelName ( DWORD Address ) const { //StringMap::iterator theIterator = m_LabelList.find(Address); - //if (theIterator != m_LabelList.end()) { + //if (theIterator != m_LabelList.end()) + //{ // return (*theIterator).second; //} @@ -4119,7 +5242,8 @@ LPCTSTR CMipsMemoryVM::LabelName ( DWORD Address ) const void CMipsMemoryVM::TLB_Mapped( DWORD VAddr, DWORD Len, DWORD PAddr, bool bReadOnly ) { - for (DWORD count = VAddr, VEnd = VAddr + Len; count < VEnd; count += 0x1000) { + for (DWORD count = VAddr, VEnd = VAddr + Len; count < VEnd; count += 0x1000) + { DWORD Index = count >> 12; m_TLB_ReadMap[Index] = ((DWORD)m_RDRAM + (count - VAddr + PAddr)) - count; if (!bReadOnly) @@ -4145,14 +5269,17 @@ void CMipsMemoryVM::RdramChanged ( CMipsMemoryVM * _this ) { return; } - if (_this->m_AllocatedRdramSize == 0x400000) { + if (_this->m_AllocatedRdramSize == 0x400000) + { if (VirtualAlloc(_this->m_RDRAM + 0x400000, 0x400000, MEM_COMMIT, PAGE_READWRITE)==NULL) { WriteTrace(TraceError,__FUNCTION__ ": failed to allocate extended memory"); g_Notify->FatalError(GS(MSG_MEM_ALLOC_ERROR)); } _this->m_AllocatedRdramSize = 0x800000; - } else { + } + else + { VirtualFree(_this->m_RDRAM + 0x400000, 0x400000,MEM_DECOMMIT); _this->m_AllocatedRdramSize = 0x400000; } @@ -4161,15 +5288,28 @@ void CMipsMemoryVM::RdramChanged ( CMipsMemoryVM * _this ) void CMipsMemoryVM::ChangeSpStatus (void) { - if ( ( RegModValue & SP_CLR_HALT ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_HALT; } - if ( ( RegModValue & SP_SET_HALT ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_HALT; } - if ( ( RegModValue & SP_CLR_BROKE ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_BROKE; } - if ( ( RegModValue & SP_CLR_INTR ) != 0) { + if ( ( RegModValue & SP_CLR_HALT ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_HALT; + } + if ( ( RegModValue & SP_SET_HALT ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_HALT; + } + if ( ( RegModValue & SP_CLR_BROKE ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_BROKE; + } + if ( ( RegModValue & SP_CLR_INTR ) != 0) + { g_Reg->MI_INTR_REG &= ~MI_INTR_SP; g_Reg->m_RspIntrReg &= ~MI_INTR_SP; g_Reg->CheckInterrupts(); } - if ( ( RegModValue & SP_SET_INTR ) != 0 && bHaveDebugger()) { g_Notify->DisplayError(L"SP_SET_INTR"); } + if ( ( RegModValue & SP_SET_INTR ) != 0 && bHaveDebugger()) + { + g_Notify->DisplayError(L"SP_SET_INTR"); + } if ( ( RegModValue & SP_CLR_SSTEP ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SSTEP; @@ -4178,52 +5318,149 @@ void CMipsMemoryVM::ChangeSpStatus (void) { g_Reg->SP_STATUS_REG |= SP_STATUS_SSTEP; } - if ( ( RegModValue & SP_CLR_INTR_BREAK ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK; } - if ( ( RegModValue & SP_SET_INTR_BREAK ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_INTR_BREAK; } - if ( ( RegModValue & SP_CLR_SIG0 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG0; } - if ( ( RegModValue & SP_SET_SIG0 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG0; } - if ( ( RegModValue & SP_CLR_SIG1 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG1; } - if ( ( RegModValue & SP_SET_SIG1 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG1; } - if ( ( RegModValue & SP_CLR_SIG2 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG2; } - if ( ( RegModValue & SP_SET_SIG2 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG2; } - if ( ( RegModValue & SP_CLR_SIG3 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG3; } - if ( ( RegModValue & SP_SET_SIG3 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG3; } - if ( ( RegModValue & SP_CLR_SIG4 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG4; } - if ( ( RegModValue & SP_SET_SIG4 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG4; } - if ( ( RegModValue & SP_CLR_SIG5 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG5; } - if ( ( RegModValue & SP_SET_SIG5 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG5; } - if ( ( RegModValue & SP_CLR_SIG6 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG6; } - if ( ( RegModValue & SP_SET_SIG6 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG6; } - if ( ( RegModValue & SP_CLR_SIG7 ) != 0) { g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG7; } - if ( ( RegModValue & SP_SET_SIG7 ) != 0) { g_Reg->SP_STATUS_REG |= SP_STATUS_SIG7; } + if ( ( RegModValue & SP_CLR_INTR_BREAK ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK; + } + if ( ( RegModValue & SP_SET_INTR_BREAK ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_INTR_BREAK; + } + if ( ( RegModValue & SP_CLR_SIG0 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG0; + } + if ( ( RegModValue & SP_SET_SIG0 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG0; + } + if ( ( RegModValue & SP_CLR_SIG1 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG1; + } + if ( ( RegModValue & SP_SET_SIG1 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG1; + } + if ( ( RegModValue & SP_CLR_SIG2 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG2; + } + if ( ( RegModValue & SP_SET_SIG2 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG2; + } + if ( ( RegModValue & SP_CLR_SIG3 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG3; + } + if ( ( RegModValue & SP_SET_SIG3 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG3; + } + if ( ( RegModValue & SP_CLR_SIG4 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG4; + } + if ( ( RegModValue & SP_SET_SIG4 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG4; + } + if ( ( RegModValue & SP_CLR_SIG5 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG5; + } + if ( ( RegModValue & SP_SET_SIG5 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG5; + } + if ( ( RegModValue & SP_CLR_SIG6 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG6; + } + if ( ( RegModValue & SP_SET_SIG6 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG6; + } + if ( ( RegModValue & SP_CLR_SIG7 ) != 0) + { + g_Reg->SP_STATUS_REG &= ~SP_STATUS_SIG7; + } + if ( ( RegModValue & SP_SET_SIG7 ) != 0) + { + g_Reg->SP_STATUS_REG |= SP_STATUS_SIG7; + } if ( ( RegModValue & SP_SET_SIG0 ) != 0 && g_System->RspAudioSignal()) { g_Reg->MI_INTR_REG |= MI_INTR_SP; g_Reg->CheckInterrupts(); } - //if (*( DWORD *)(DMEM + 0xFC0) == 1) { + //if (*( DWORD *)(DMEM + 0xFC0) == 1) + //{ // ChangeTimer(RspTimer,0x40000); - //} else { - try { + //} + //else + //{ + try + { g_System->RunRSP(); - } catch (...) { + } + catch (...) + { g_Notify->BreakPoint(__FILEW__,__LINE__); } //} } -void CMipsMemoryVM::ChangeMiIntrMask (void) { - if ( ( RegModValue & MI_INTR_MASK_CLR_SP ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_SP; } - if ( ( RegModValue & MI_INTR_MASK_SET_SP ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_SP; } - if ( ( RegModValue & MI_INTR_MASK_CLR_SI ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_SI; } - if ( ( RegModValue & MI_INTR_MASK_SET_SI ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_SI; } - if ( ( RegModValue & MI_INTR_MASK_CLR_AI ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_AI; } - if ( ( RegModValue & MI_INTR_MASK_SET_AI ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_AI; } - if ( ( RegModValue & MI_INTR_MASK_CLR_VI ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_VI; } - if ( ( RegModValue & MI_INTR_MASK_SET_VI ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_VI; } - if ( ( RegModValue & MI_INTR_MASK_CLR_PI ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_PI; } - if ( ( RegModValue & MI_INTR_MASK_SET_PI ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_PI; } - if ( ( RegModValue & MI_INTR_MASK_CLR_DP ) != 0 ) { g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_DP; } - if ( ( RegModValue & MI_INTR_MASK_SET_DP ) != 0 ) { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_DP; } +void CMipsMemoryVM::ChangeMiIntrMask (void) +{ + if ( ( RegModValue & MI_INTR_MASK_CLR_SP ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_SP; + } + if ( ( RegModValue & MI_INTR_MASK_SET_SP ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_SP; + } + if ( ( RegModValue & MI_INTR_MASK_CLR_SI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_SI; + } + if ( ( RegModValue & MI_INTR_MASK_SET_SI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_SI; + } + if ( ( RegModValue & MI_INTR_MASK_CLR_AI ) != 0) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_AI; + } + if ( ( RegModValue & MI_INTR_MASK_SET_AI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_AI; + } + if ( ( RegModValue & MI_INTR_MASK_CLR_VI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_VI; + } + if ( ( RegModValue & MI_INTR_MASK_SET_VI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_VI; + } + if ( ( RegModValue & MI_INTR_MASK_CLR_PI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_PI; + } + if ( ( RegModValue & MI_INTR_MASK_SET_PI ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_PI; + } + if ( ( RegModValue & MI_INTR_MASK_CLR_DP ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG &= ~MI_INTR_MASK_DP; + } + if ( ( RegModValue & MI_INTR_MASK_SET_DP ) != 0 ) + { + g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_DP; + } } diff --git a/Source/Project64/N64 System/Mips/Memory Virtual Mem.h b/Source/Project64/N64 System/Mips/Memory Virtual Mem.h index 07aeafe39..d1786d6ad 100644 --- a/Source/Project64/N64 System/Mips/Memory Virtual Mem.h +++ b/Source/Project64/N64 System/Mips/Memory Virtual Mem.h @@ -160,7 +160,7 @@ private: DWORD m_FieldSerration; DWORD m_TempValue; - //Initilizing and reseting information about the memory system + //Initializing and resetting information about the memory system void FreeMemory ( void ); mutable char m_strLabelName[100]; diff --git a/Source/Project64/N64 System/Mips/Mempak.cpp b/Source/Project64/N64 System/Mips/Mempak.cpp index 1e793b988..e7f10ccf2 100644 --- a/Source/Project64/N64 System/Mips/Mempak.cpp +++ b/Source/Project64/N64 System/Mips/Mempak.cpp @@ -12,7 +12,8 @@ static BYTE Mempaks[4][0x8000]; HANDLE hMempakFile[4]; -void Mempak::Close(void) { +void Mempak::Close(void) +{ for (int i = 0; i < 4; i++) { if (hMempakFile[i]) @@ -23,7 +24,8 @@ void Mempak::Close(void) { } } -void LoadMempak (int Control) { +void LoadMempak (int Control) +{ CPath FileName; DWORD dwRead; stdstr MempakName; @@ -92,21 +94,28 @@ void LoadMempak (int Control) { } } -BYTE Mempak::CalculateCrc(BYTE * DataToCrc) { +BYTE Mempak::CalculateCrc(BYTE * DataToCrc) +{ DWORD Count; DWORD XorTap; int Length; BYTE CRC = 0; - for (Count = 0; Count < 0x21; Count++) { - for (Length = 0x80; Length >= 1; Length >>= 1) { + for (Count = 0; Count < 0x21; Count++) + { + for (Length = 0x80; Length >= 1; Length >>= 1) + { XorTap = (CRC & 0x80) ? 0x85 : 0; CRC <<= 1; - if (Count == 0x20) { + if (Count == 0x20) + { CRC &= 0xFF; - } else { - if ((*DataToCrc & Length) != 0) { + } + else + { + if ((*DataToCrc & Length) != 0) + { CRC |= 1; } } @@ -118,13 +127,18 @@ BYTE Mempak::CalculateCrc(BYTE * DataToCrc) { return CRC; } -void Mempak::ReadFrom(int Control, int Address, BYTE * Buffer) { - if (Address < 0x8000) { - if (hMempakFile[Control] == NULL) { +void Mempak::ReadFrom(int Control, int Address, BYTE * Buffer) +{ + if (Address < 0x8000) + { + if (hMempakFile[Control] == NULL) + { LoadMempak(Control); } memcpy(Buffer, &Mempaks[Control][Address], 0x20); - } else { + } + else + { memset(Buffer, 0, 0x20); /* Rumble pack area */ } @@ -132,18 +146,23 @@ void Mempak::ReadFrom(int Control, int Address, BYTE * Buffer) { Buffer[0x20] = CalculateCrc(Buffer); } -void Mempak::WriteTo(int Control, int Address, BYTE * Buffer) { +void Mempak::WriteTo(int Control, int Address, BYTE * Buffer) +{ DWORD dwWritten; - if (Address < 0x8000) { - if (hMempakFile[Control] == NULL) { + if (Address < 0x8000) + { + if (hMempakFile[Control] == NULL) + { LoadMempak(Control); } memcpy(&Mempaks[Control][Address], Buffer, 0x20); SetFilePointer(hMempakFile[Control], 0,NULL,FILE_BEGIN); WriteFile(hMempakFile[Control], &Mempaks[Control][0], 0x8000, &dwWritten, NULL); - } else { + } + else + { /* Rumble pack area */ } Buffer[0x20] = CalculateCrc(Buffer); diff --git a/Source/Project64/N64 System/Mips/OpCode.h b/Source/Project64/N64 System/Mips/OpCode.h index c46b38455..d5f26f06c 100644 --- a/Source/Project64/N64 System/Mips/OpCode.h +++ b/Source/Project64/N64 System/Mips/OpCode.h @@ -10,30 +10,35 @@ ****************************************************************************/ #pragma once -typedef union { +typedef union +{ unsigned long Hex; unsigned char Ascii[4]; - struct { + struct + { unsigned offset : 16; unsigned rt : 5; unsigned rs : 5; unsigned op : 6; }; - struct { + struct + { unsigned immediate : 16; unsigned : 5; unsigned base : 5; unsigned : 6; }; - struct { + struct + { unsigned target : 26; unsigned : 6; }; - struct { + struct + { unsigned funct : 6; unsigned sa : 5; unsigned rd : 5; @@ -42,7 +47,8 @@ typedef union { unsigned : 6; }; - struct { + struct + { unsigned : 6; unsigned fd : 5; unsigned fs : 5; diff --git a/Source/Project64/N64 System/Mips/Pif Ram.cpp b/Source/Project64/N64 System/Mips/Pif Ram.cpp index ea4d95998..58a9f9334 100644 --- a/Source/Project64/N64 System/Mips/Pif Ram.cpp +++ b/Source/Project64/N64 System/Mips/Pif Ram.cpp @@ -45,6 +45,7 @@ CPifRam::CPifRam( bool SavesReadOnly ) : CPifRam::~CPifRam( void ) { + } void CPifRam::Reset ( void ) @@ -66,16 +67,21 @@ void CPifRam::n64_cic_nus_6105(char challenge[], char respone[], int length) char key, *lut; int i, sgn, mag, mod; - for (key = 0xB, lut = lut0, i = 0; i < length; i++) { + for (key = 0xB, lut = lut0, i = 0; i < length; i++) + { respone[i] = (key + 5 * challenge[i]) & 0xF; key = lut[respone[i]]; sgn = (respone[i] >> 3) & 0x1; mag = ((sgn == 1) ? ~respone[i] : respone[i]) & 0x7; mod = (mag % 3 == 1) ? sgn : 1 - sgn; if (lut == lut1 && (respone[i] == 0x1 || respone[i] == 0x9)) + { mod = 1; + } if (lut == lut1 && (respone[i] == 0xB || respone[i] == 0xE)) + { mod = 0; + } lut = (mod == 1) ? lut1 : lut0; } } @@ -93,7 +99,8 @@ void CPifRam::PifRamRead (void) int Channel = 0; for (int CurPos = 0; CurPos < 0x40; CurPos ++) { - switch(m_PifRam[CurPos]) { + switch (m_PifRam[CurPos]) + { case 0x00: Channel += 1; if (Channel > 6) @@ -107,31 +114,49 @@ void CPifRam::PifRamRead (void) default: if ((m_PifRam[CurPos] & 0xC0) == 0) { - if (Channel < 4) { - if (Controllers[Channel].Present && Controllers[Channel].RawData) { - if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Channel,&m_PifRam[CurPos]); } - } else { + if (Channel < 4) + { + if (Controllers[Channel].Present && Controllers[Channel].RawData) + { + if (g_Plugins->Control()->ReadController) + { + g_Plugins->Control()->ReadController(Channel,&m_PifRam[CurPos]); + } + } + else + { ReadControllerCommand(Channel,&m_PifRam[CurPos]); } } CurPos += m_PifRam[CurPos] + (m_PifRam[CurPos + 1] & 0x3F) + 1; Channel += 1; - } else { - if (bShowPifRamErrors()) { g_Notify->DisplayError(L"Unknown Command in PifRamRead(%X)",m_PifRam[CurPos]); } + } + else + { + if (bShowPifRamErrors()) + { + g_Notify->DisplayError(L"Unknown Command in PifRamRead(%X)",m_PifRam[CurPos]); + } CurPos = 0x40; } break; } } - if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(-1,NULL); } + if (g_Plugins->Control()->ReadController) + { + g_Plugins->Control()->ReadController(-1,NULL); + } } -void CPifRam::PifRamWrite (void) { +void CPifRam::PifRamWrite (void) +{ CONTROL * Controllers = g_Plugins->Control()->PluginControllers(); int Channel = 0, CurPos; - if( m_PifRam[0x3F] > 0x1) { - switch (m_PifRam[0x3F]) { + if ( m_PifRam[0x3F] > 0x1) + { + switch (m_PifRam[0x3F]) + { case 0x02: // format the 'challenge' message into 30 nibbles for X-Scale's CIC code { @@ -173,31 +198,51 @@ void CPifRam::PifRamWrite (void) { memset(m_PifRam,0,0x40); break; default: - if (bShowPifRamErrors()) { g_Notify->DisplayError(L"Unkown PifRam control: %d",m_PifRam[0x3F]); } + if (bShowPifRamErrors()) + { + g_Notify->DisplayError(L"Unkown PifRam control: %d",m_PifRam[0x3F]); + } } return; } - for (CurPos = 0; CurPos < 0x40; CurPos++){ - switch(m_PifRam[CurPos]) { + for (CurPos = 0; CurPos < 0x40; CurPos++) + { + switch (m_PifRam[CurPos]) + { case 0x00: Channel += 1; - if (Channel > 6) { CurPos = 0x40; } + if (Channel > 6) + { + CurPos = 0x40; + } break; case 0xFE: CurPos = 0x40; break; case 0xFF: break; case 0xB4: case 0x56: case 0xB8: break; /* ??? */ default: - if ((m_PifRam[CurPos] & 0xC0) == 0) { - if (Channel < 4) { - if (Controllers[Channel].Present && Controllers[Channel].RawData) { - if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Channel,&m_PifRam[CurPos]); } - } else { + if ((m_PifRam[CurPos] & 0xC0) == 0) + { + if (Channel < 4) + { + if (Controllers[Channel].Present && Controllers[Channel].RawData) + { + if (g_Plugins->Control()->ControllerCommand) + { + g_Plugins->Control()->ControllerCommand(Channel,&m_PifRam[CurPos]); + } + } + else + { ProcessControllerCommand(Channel,&m_PifRam[CurPos]); } - } else if (Channel == 4) { + } + else if (Channel == 4) + { EepromCommand(&m_PifRam[CurPos]); - } else { + } + else + { if (bShowPifRamErrors()) { g_Notify->DisplayError(L"Command on channel 5?"); @@ -205,15 +250,23 @@ void CPifRam::PifRamWrite (void) { } CurPos += m_PifRam[CurPos] + (m_PifRam[CurPos + 1] & 0x3F) + 1; Channel += 1; - } else { - if (bShowPifRamErrors()) { g_Notify->DisplayError(L"Unknown Command in PifRamWrite(%X)",m_PifRam[CurPos]); } + } + else + { + if (bShowPifRamErrors()) + { + g_Notify->DisplayError(L"Unknown Command in PifRamWrite(%X)",m_PifRam[CurPos]); + } CurPos = 0x40; } break; } } m_PifRam[0x3F] = 0; - if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(-1,NULL); } + if (g_Plugins->Control()->ControllerCommand) + { + g_Plugins->Control()->ControllerCommand(-1,NULL); + } } void CPifRam::SI_DMA_READ (void) @@ -233,16 +286,24 @@ void CPifRam::SI_DMA_READ (void) PifRamRead(); SI_DRAM_ADDR_REG &= 0xFFFFFFF8; - if ((int)SI_DRAM_ADDR_REG < 0) { + if ((int)SI_DRAM_ADDR_REG < 0) + { int count, RdramPos; RdramPos = (int)SI_DRAM_ADDR_REG; - for (count = 0; count < 0x40; count++, RdramPos++) { - if (RdramPos < 0) { continue; } + for (count = 0; count < 0x40; count++, RdramPos++) + { + if (RdramPos < 0) + { + continue; + } RDRAM[RdramPos ^3] = m_PifRam[count]; } - } else { - _asm { + } + else + { + _asm + { mov edi, dword ptr [SI_DRAM_ADDR_REG] mov edi, dword ptr [edi] add edi, RDRAM @@ -267,13 +328,16 @@ void CPifRam::SI_DMA_READ (void) } } - if (LogOptions.LogPRDMAMemStores) { + if (LogOptions.LogPRDMAMemStores) + { int count; char HexData[100], AsciiData[100], Addon[20]; LogMessage("\tData DMAed to RDRAM:"); LogMessage("\t--------------------"); - for (count = 0; count < 16; count ++ ) { - if ((count % 4) == 0) { + for (count = 0; count < 16; count ++ ) + { + if ((count % 4) == 0) + { sprintf(HexData,"\0"); sprintf(AsciiData,"\0"); } @@ -281,7 +345,8 @@ void CPifRam::SI_DMA_READ (void) m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1], m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3] ); strcat(HexData,Addon); - if (((count + 1) % 4) != 0) { + if (((count + 1) % 4) != 0) + { sprintf(Addon,"-"); strcat(HexData,Addon); } @@ -291,16 +356,20 @@ void CPifRam::SI_DMA_READ (void) m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3] ); strcat(AsciiData,Addon); - if (((count + 1) % 4) == 0) { + if (((count + 1) % 4) == 0) + { LogMessage("\t%s %s",HexData, AsciiData); } } LogMessage(""); } - if (g_System->bDelaySI()) { + if (g_System->bDelaySI()) + { g_SystemTimer->SetTimer(CSystemTimer::SiTimer,0x900,false); - } else { + } + else + { g_Reg->MI_INTR_REG |= MI_INTR_SI; g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT; g_Reg->CheckInterrupts(); @@ -324,16 +393,24 @@ void CPifRam::SI_DMA_WRITE (void) SI_DRAM_ADDR_REG &= 0xFFFFFFF8; BYTE * RDRAM = g_MMU->Rdram(); - if ((int)SI_DRAM_ADDR_REG < 0) { + if ((int)SI_DRAM_ADDR_REG < 0) + { int count, RdramPos; RdramPos = (int)SI_DRAM_ADDR_REG; - for (count = 0; count < 0x40; count++, RdramPos++) { - if (RdramPos < 0) { m_PifRam[count] = 0; continue; } + for (count = 0; count < 0x40; count++, RdramPos++) + { + if (RdramPos < 0) + { + m_PifRam[count] = 0; continue; + } m_PifRam[count] = RDRAM[RdramPos ^3]; } - } else { - _asm { + } + else + { + _asm + { mov ecx, dword ptr [SI_DRAM_ADDR_REG] mov ecx, dword ptr [ecx] add ecx, RDRAM @@ -358,14 +435,17 @@ void CPifRam::SI_DMA_WRITE (void) } } - if (LogOptions.LogPRDMAMemLoads) { + if (LogOptions.LogPRDMAMemLoads) + { int count; char HexData[100], AsciiData[100], Addon[20]; LogMessage(""); LogMessage("\tData DMAed to the Pif Ram:"); LogMessage("\t--------------------------"); - for (count = 0; count < 16; count ++ ) { - if ((count % 4) == 0) { + for (count = 0; count < 16; count ++ ) + { + if ((count % 4) == 0) + { sprintf(HexData,"\0"); sprintf(AsciiData,"\0"); } @@ -373,7 +453,8 @@ void CPifRam::SI_DMA_WRITE (void) m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1], m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3] ); strcat(HexData,Addon); - if (((count + 1) % 4) != 0) { + if (((count + 1) % 4) != 0) + { sprintf(Addon,"-"); strcat(HexData,Addon); } @@ -383,7 +464,8 @@ void CPifRam::SI_DMA_WRITE (void) m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3] ); strcat(AsciiData,Addon); - if (((count + 1) % 4) == 0) { + if (((count + 1) % 4) == 0) + { LogMessage("\t%s %s",HexData, AsciiData); } } @@ -392,9 +474,12 @@ void CPifRam::SI_DMA_WRITE (void) PifRamWrite(); - if (g_System->bDelaySI()) { + if (g_System->bDelaySI()) + { g_SystemTimer->SetTimer(CSystemTimer::SiTimer,0x900,false); - } else { + } + else + { g_Reg->MI_INTR_REG |= MI_INTR_SI; g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT; g_Reg->CheckInterrupts(); @@ -405,48 +490,80 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command) { CONTROL * Controllers = g_Plugins->Control()->PluginControllers(); - switch (Command[2]) { + switch (Command[2]) + { case 0x00: // check case 0xFF: // reset & check ? - if ((Command[1] & 0x80) != 0) { break; } + if ((Command[1] & 0x80) != 0) + { + break; + } if (bShowPifRamErrors()) { - if (Command[0] != 1) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); } - if (Command[1] != 3) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); } + if (Command[0] != 1) + { + g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); + } + if (Command[1] != 3) + { + g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); + } } - if (Controllers[Control].Present == TRUE) { + if (Controllers[Control].Present == TRUE) + { Command[3] = 0x05; Command[4] = 0x00; - switch ( Controllers[Control].Plugin) { + switch ( Controllers[Control].Plugin) + { case PLUGIN_RUMBLE_PAK: Command[5] = 1; break; case PLUGIN_MEMPAK: Command[5] = 1; break; case PLUGIN_RAW: Command[5] = 1; break; default: Command[5] = 0; break; } - } else { + } + else + { Command[1] |= 0x80; } break; case 0x01: // read controller if (bShowPifRamErrors()) { - if (Command[0] != 1) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); } - if (Command[1] != 4) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); } + if (Command[0] != 1) + { + g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); + } + if (Command[1] != 4) + { + g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); + } } - if (Controllers[Control].Present == FALSE) { + if (Controllers[Control].Present == FALSE) + { Command[1] |= 0x80; } break; case 0x02: //read from controller pack - if (LogOptions.LogControllerPak) { LogControllerPakData("Read: Before Gettting Results"); } + if (LogOptions.LogControllerPak) + { + LogControllerPakData("Read: Before Gettting Results"); + } if (bShowPifRamErrors()) { - if (Command[0] != 3) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); } - if (Command[1] != 33) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); } + if (Command[0] != 3) + { + g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); + } + if (Command[1] != 33) + { + g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); + } } - if (Controllers[Control].Present == TRUE) { + if (Controllers[Control].Present == TRUE) + { DWORD address = ((Command[3] << 8) | Command[4] & 0xE0); - switch (Controllers[Control].Plugin) { + switch (Controllers[Control].Plugin) + { case PLUGIN_RUMBLE_PAK: memset(&Command[5], (address >= 0x8000 && address < 0x9000) ? 0x80 : 0x00, 0x20); @@ -458,44 +575,70 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command) memset(&Command[5], 0, 0x20); Command[0x25] = 0; } - } else { + } + else + { Command[1] |= 0x80; } - if (LogOptions.LogControllerPak) { LogControllerPakData("Read: After Gettting Results"); } + if (LogOptions.LogControllerPak) + { + LogControllerPakData("Read: After Gettting Results"); + } break; case 0x03: //write controller pak - if (LogOptions.LogControllerPak) { LogControllerPakData("Write: Before Processing"); } + if (LogOptions.LogControllerPak) + { + LogControllerPakData("Write: Before Processing"); + } if (bShowPifRamErrors()) { - if (Command[0] != 35) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); } - if (Command[1] != 1) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); } + if (Command[0] != 35) + { + g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); + } + if (Command[1] != 1) + { + g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); + } } - if (Controllers[Control].Present == TRUE) { + if (Controllers[Control].Present == TRUE) + { DWORD address = ((Command[3] << 8) | Command[4] & 0xE0 ); - switch (Controllers[Control].Plugin) { + switch (Controllers[Control].Plugin) + { case PLUGIN_MEMPAK: Mempak::WriteTo(Control, address, &Command[5]); break; case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break; case PLUGIN_RUMBLE_PAK: - if ((address & 0xFFE0) == 0xC000 && g_Plugins->Control()->RumbleCommand != NULL) { + if ((address & 0xFFE0) == 0xC000 && g_Plugins->Control()->RumbleCommand != NULL) + { g_Plugins->Control()->RumbleCommand(Control, *(BOOL *)(&Command[5])); } default: Command[0x25] = Mempak::CalculateCrc(&Command[5]); } - } else { + } + else + { Command[1] |= 0x80; } - if (LogOptions.LogControllerPak) { LogControllerPakData("Write: After Processing"); } + if (LogOptions.LogControllerPak) + { + LogControllerPakData("Write: After Processing"); + } break; default: - if (bShowPifRamErrors()) { g_Notify->DisplayError(L"Unknown ControllerCommand %d",Command[2]); } + if (bShowPifRamErrors()) + { + g_Notify->DisplayError(L"Unknown ControllerCommand %d",Command[2]); + } } } void CPifRam::ReadControllerCommand (int Control, BYTE * Command) { CONTROL * Controllers = g_Plugins->Control()->PluginControllers(); - switch (Command[2]) { + switch (Command[2]) + { case 0x01: // read controller if (Controllers[Control].Present == TRUE) { @@ -508,15 +651,19 @@ void CPifRam::ReadControllerCommand (int Control, BYTE * Command) { } break; case 0x02: //read from controller pack - if (Controllers[Control].Present == TRUE) { - switch (Controllers[Control].Plugin) { + if (Controllers[Control].Present == TRUE) + { + switch (Controllers[Control].Plugin) + { case PLUGIN_RAW: if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Control, Command); } break; } } break; case 0x03: //write controller pak - if (Controllers[Control].Present == TRUE) { - switch (Controllers[Control].Plugin) { + if (Controllers[Control].Present == TRUE) + { + switch (Controllers[Control].Plugin) + { case PLUGIN_RAW: if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Control, Command); } break; } } @@ -532,8 +679,10 @@ void CPifRam::LogControllerPakData (char * Description) char HexData[100], AsciiData[100], Addon[20]; LogMessage("\t%s:",Description); LogMessage("\t------------------------------"); - for (count = 0; count < 16; count ++ ) { - if ((count % 4) == 0) { + for (count = 0; count < 16; count ++ ) + { + if ((count % 4) == 0) + { sprintf(HexData,"\0"); sprintf(AsciiData,"\0"); } @@ -541,22 +690,28 @@ void CPifRam::LogControllerPakData (char * Description) PIF_Ram[(count << 2) + 0], PIF_Ram[(count << 2) + 1], PIF_Ram[(count << 2) + 2], PIF_Ram[(count << 2) + 3] ); strcat(HexData,Addon); - if (((count + 1) % 4) != 0) { + if (((count + 1) % 4) != 0) + { sprintf(Addon,"-"); strcat(HexData,Addon); } Addon[0] = 0; - for (count2 = 0; count2 < 4; count2++) { - if (PIF_Ram[(count << 2) + count2] < 30) { + for (count2 = 0; count2 < 4; count2++) + { + if (PIF_Ram[(count << 2) + count2] < 30) + { strcat(Addon,"."); - } else { + } + else + { sprintf(Addon,"%s%c",Addon,PIF_Ram[(count << 2) + count2]); } } strcat(AsciiData,Addon); - if (((count + 1) % 4) == 0) { + if (((count + 1) % 4) == 0) + { LogMessage("\t%s %s",HexData, AsciiData); } } diff --git a/Source/Project64/N64 System/Mips/Pif Ram.h b/Source/Project64/N64 System/Mips/Pif Ram.h index c10dcc218..919db7329 100644 --- a/Source/Project64/N64 System/Mips/Pif Ram.h +++ b/Source/Project64/N64 System/Mips/Pif Ram.h @@ -16,7 +16,10 @@ protected: CPifRamSettings(); virtual ~CPifRamSettings(); - inline bool bShowPifRamErrors ( void ) const { return m_bShowPifRamErrors; } + inline bool bShowPifRamErrors ( void ) const + { + return m_bShowPifRamErrors; + } private: static void RefreshSettings ( void * ); diff --git a/Source/Project64/N64 System/Mips/Register Class.cpp b/Source/Project64/N64 System/Mips/Register Class.cpp index caf77edd9..fcb779d7f 100644 --- a/Source/Project64/N64 System/Mips/Register Class.cpp +++ b/Source/Project64/N64 System/Mips/Register Class.cpp @@ -80,6 +80,7 @@ CP0registers::CP0registers(DWORD * _CP0) : ERROREPC_REGISTER(_CP0[30]), FAKE_CAUSE_REGISTER(_CP0[32]) { + } Rdram_InterfaceReg::Rdram_InterfaceReg(DWORD * _RdramInterface) : @@ -95,6 +96,7 @@ Rdram_InterfaceReg::Rdram_InterfaceReg(DWORD * _RdramInterface) : RDRAM_ADDR_SELECT_REG(_RdramInterface[8]), RDRAM_DEVICE_MANUF_REG(_RdramInterface[9]) { + } Mips_InterfaceReg::Mips_InterfaceReg(DWORD * _MipsInterface) : @@ -105,6 +107,7 @@ Mips_InterfaceReg::Mips_InterfaceReg(DWORD * _MipsInterface) : MI_INTR_REG(_MipsInterface[2]), MI_INTR_MASK_REG(_MipsInterface[3]) { + } Video_InterfaceReg::Video_InterfaceReg(DWORD * _VideoInterface) : @@ -132,6 +135,7 @@ Video_InterfaceReg::Video_InterfaceReg(DWORD * _VideoInterface) : VI_X_SCALE_REG(_VideoInterface[12]), VI_Y_SCALE_REG(_VideoInterface[13]) { + } AudioInterfaceReg::AudioInterfaceReg(DWORD * _AudioInterface) : @@ -142,6 +146,7 @@ AudioInterfaceReg::AudioInterfaceReg(DWORD * _AudioInterface) : AI_DACRATE_REG(_AudioInterface[4]), AI_BITRATE_REG(_AudioInterface[5]) { + } PeripheralInterfaceReg::PeripheralInterfaceReg(DWORD * PeripheralInterface) : @@ -161,6 +166,7 @@ PeripheralInterfaceReg::PeripheralInterfaceReg(DWORD * PeripheralInterface) : PI_BSD_DOM2_PGS_REG(PeripheralInterface[11]), PI_BSD_DOM2_RLS_REG(PeripheralInterface[12]) { + } RDRAMInt_InterfaceReg::RDRAMInt_InterfaceReg(DWORD * RdramInterface) : @@ -174,6 +180,7 @@ RDRAMInt_InterfaceReg::RDRAMInt_InterfaceReg(DWORD * RdramInterface) : RI_RERROR_REG(RdramInterface[6]), RI_WERROR_REG(RdramInterface[7]) { + } DisplayControlReg::DisplayControlReg(DWORD * _DisplayProcessor) : @@ -186,6 +193,7 @@ DisplayControlReg::DisplayControlReg(DWORD * _DisplayProcessor) : DPC_PIPEBUSY_REG(_DisplayProcessor[6]), DPC_TMEM_REG(_DisplayProcessor[7]) { + } SigProcessor_InterfaceReg::SigProcessor_InterfaceReg(DWORD * _SignalProcessorInterface) : @@ -200,6 +208,7 @@ SigProcessor_InterfaceReg::SigProcessor_InterfaceReg(DWORD * _SignalProcessorInt SP_PC_REG(_SignalProcessorInterface[8]), SP_IBIST_REG(_SignalProcessorInterface[9]) { + } Serial_InterfaceReg::Serial_InterfaceReg(DWORD * SerialInterface) : @@ -208,6 +217,7 @@ Serial_InterfaceReg::Serial_InterfaceReg(DWORD * SerialInterface) : SI_PIF_ADDR_WR64B_REG(SerialInterface[2]), SI_STATUS_REG(SerialInterface[3]) { + } CRegisters::CRegisters(CN64System * System, CSystemEvents * SystemEvents) : @@ -276,23 +286,37 @@ void CRegisters::SetAsCurrentSystem ( void ) void CRegisters::CheckInterrupts ( void ) { - if (!m_System->bFixedAudio() && (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_SyncCores) { + if (!m_System->bFixedAudio() && (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_SyncCores) + { MI_INTR_REG &= ~MI_INTR_AI; MI_INTR_REG |= (m_AudioIntrReg & MI_INTR_AI); } MI_INTR_REG |= (m_RspIntrReg & MI_INTR_SP); MI_INTR_REG |= (m_GfxIntrReg & MI_INTR_DP); - if ((MI_INTR_MASK_REG & MI_INTR_REG) != 0) { + if ((MI_INTR_MASK_REG & MI_INTR_REG) != 0) + { FAKE_CAUSE_REGISTER |= CAUSE_IP2; - } else { + } + else + { FAKE_CAUSE_REGISTER &= ~CAUSE_IP2; } - if (( STATUS_REGISTER & STATUS_IE ) == 0 ) { return; } - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { return; } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { return; } + if (( STATUS_REGISTER & STATUS_IE ) == 0 ) + { + return; + } + if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) + { + return; + } + if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) + { + return; + } - if (( STATUS_REGISTER & FAKE_CAUSE_REGISTER & 0xFF00) != 0) { + if (( STATUS_REGISTER & FAKE_CAUSE_REGISTER & 0xFF00) != 0) + { if (m_FirstInterupt) { m_FirstInterupt = false; @@ -310,37 +334,50 @@ void CRegisters::DoAddressError ( BOOL DelaySlot, DWORD BadVaddr, BOOL FromRead) if (bHaveDebugger()) { g_Notify->DisplayError(L"AddressError"); - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { + if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) + { g_Notify->DisplayError(L"EXL set in AddressError Exception"); } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { + if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) + { g_Notify->DisplayError(L"ERL set in AddressError Exception"); } } - if (FromRead) { + if (FromRead) + { CAUSE_REGISTER = EXC_RADE; - } else { + } + else + { CAUSE_REGISTER = EXC_WADE; } BAD_VADDR_REGISTER = BadVaddr; - if (DelaySlot) { + if (DelaySlot) + { CAUSE_REGISTER |= CAUSE_BD; EPC_REGISTER = m_PROGRAM_COUNTER - 4; - } else { + } + else + { EPC_REGISTER = m_PROGRAM_COUNTER; } STATUS_REGISTER |= STATUS_EXL; m_PROGRAM_COUNTER = 0x80000180; } -void CRegisters::FixFpuLocations ( void ) { - if ((STATUS_REGISTER & STATUS_FR) == 0) { - for (int count = 0; count < 32; count ++) { +void CRegisters::FixFpuLocations ( void ) +{ + if ((STATUS_REGISTER & STATUS_FR) == 0) + { + for (int count = 0; count < 32; count ++) + { m_FPR_S[count] = &m_FPR[count >> 1].F[count & 1]; m_FPR_D[count] = &m_FPR[count >> 1].D; } - } else { + } + else + { for (int count = 0; count < 32; count ++) { m_FPR_S[count] = &m_FPR[count].F[1]; m_FPR_D[count] = &m_FPR[count].D; @@ -352,19 +389,24 @@ void CRegisters::DoBreakException ( BOOL DelaySlot) { if (bHaveDebugger()) { - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { + if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) + { g_Notify->DisplayError(L"EXL set in Break Exception"); } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { + if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) + { g_Notify->DisplayError(L"ERL set in Break Exception"); } } CAUSE_REGISTER = EXC_BREAK; - if (DelaySlot) { + if (DelaySlot) + { CAUSE_REGISTER |= CAUSE_BD; EPC_REGISTER = m_PROGRAM_COUNTER - 4; - } else { + } + else + { EPC_REGISTER = m_PROGRAM_COUNTER; } STATUS_REGISTER |= STATUS_EXL; @@ -375,20 +417,28 @@ void CRegisters::DoCopUnusableException ( BOOL DelaySlot, int Coprocessor ) { if (bHaveDebugger()) { - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { + if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) + { g_Notify->DisplayError(L"EXL set in Break Exception"); } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { + if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) + { g_Notify->DisplayError(L"ERL set in Break Exception"); } } CAUSE_REGISTER = EXC_CPU; - if (Coprocessor == 1) { CAUSE_REGISTER |= 0x10000000; } - if (DelaySlot) { + if (Coprocessor == 1) + { + CAUSE_REGISTER |= 0x10000000; + } + if (DelaySlot) + { CAUSE_REGISTER |= CAUSE_BD; EPC_REGISTER = m_PROGRAM_COUNTER - 4; - } else { + } + else + { EPC_REGISTER = m_PROGRAM_COUNTER; } STATUS_REGISTER |= STATUS_EXL; @@ -398,18 +448,31 @@ void CRegisters::DoCopUnusableException ( BOOL DelaySlot, int Coprocessor ) BOOL CRegisters::DoIntrException ( BOOL DelaySlot ) { - if (( STATUS_REGISTER & STATUS_IE ) == 0 ) { return FALSE; } - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { return FALSE; } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { return FALSE; } - if (LogOptions.GenerateLog && LogOptions.LogExceptions && !LogOptions.NoInterrupts) { - LogMessage("%08X: Interupt Generated", m_PROGRAM_COUNTER ); + if (( STATUS_REGISTER & STATUS_IE ) == 0 ) + { + return FALSE; + } + if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) + { + return FALSE; + } + if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) + { + return FALSE; + } + if (LogOptions.GenerateLog && LogOptions.LogExceptions && !LogOptions.NoInterrupts) + { + LogMessage("%08X: Interrupt Generated", m_PROGRAM_COUNTER ); } CAUSE_REGISTER = FAKE_CAUSE_REGISTER; CAUSE_REGISTER |= EXC_INT; - if (DelaySlot) { + if (DelaySlot) + { CAUSE_REGISTER |= CAUSE_BD; EPC_REGISTER = m_PROGRAM_COUNTER - 4; - } else { + } + else + { EPC_REGISTER = m_PROGRAM_COUNTER; } STATUS_REGISTER |= STATUS_EXL; @@ -424,21 +487,29 @@ void CRegisters::DoTLBReadMiss ( BOOL DelaySlot, DWORD BadVaddr ) CONTEXT_REGISTER &= 0xFF80000F; CONTEXT_REGISTER |= (BadVaddr >> 9) & 0x007FFFF0; ENTRYHI_REGISTER = (BadVaddr & 0xFFFFE000); - if ((STATUS_REGISTER & STATUS_EXL) == 0) { - if (DelaySlot) { + if ((STATUS_REGISTER & STATUS_EXL) == 0) + { + if (DelaySlot) + { CAUSE_REGISTER |= CAUSE_BD; EPC_REGISTER = m_PROGRAM_COUNTER - 4; - } else { + } + else + { EPC_REGISTER = m_PROGRAM_COUNTER; } if (g_TLB->AddressDefined(BadVaddr)) { m_PROGRAM_COUNTER = 0x80000180; - } else { + } + else + { m_PROGRAM_COUNTER = 0x80000000; } STATUS_REGISTER |= STATUS_EXL; - } else { + } + else + { if (bHaveDebugger()) { g_Notify->DisplayError(L"TLBMiss - EXL Set\nBadVaddr = %X\nAddress Defined: %s",BadVaddr,g_TLB->AddressDefined(BadVaddr)?"TRUE":"FALSE"); @@ -451,22 +522,26 @@ void CRegisters::DoSysCallException ( BOOL DelaySlot) { if (bHaveDebugger()) { - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { + if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) + { g_Notify->DisplayError(L"EXL set in SysCall Exception"); } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { + if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) + { g_Notify->DisplayError(L"ERL set in SysCall Exception"); } } CAUSE_REGISTER = EXC_SYSCALL; - if (DelaySlot) { + if (DelaySlot) + { CAUSE_REGISTER |= CAUSE_BD; EPC_REGISTER = m_PROGRAM_COUNTER - 4; - } else { + } + else + { EPC_REGISTER = m_PROGRAM_COUNTER; } STATUS_REGISTER |= STATUS_EXL; m_PROGRAM_COUNTER = 0x80000180; } - diff --git a/Source/Project64/N64 System/Mips/Register Class.h b/Source/Project64/N64 System/Mips/Register Class.h index d13fb2231..9380aeae6 100644 --- a/Source/Project64/N64 System/Mips/Register Class.h +++ b/Source/Project64/N64 System/Mips/Register Class.h @@ -41,7 +41,8 @@ public: }; //CPO register flags -enum { +enum +{ //Status Register STATUS_IE = 0x00000001, STATUS_EXL = 0x00000002, STATUS_ERL = 0x00000004, STATUS_IP0 = 0x00000100, STATUS_IP1 = 0x00000200, STATUS_IP2 = 0x00000400, @@ -83,7 +84,8 @@ enum { }; //Float point control status register flags -enum { +enum +{ FPCSR_FS = 0x01000000, /* flush denorm to zero */ FPCSR_C = 0x00800000, /* condition bit */ FPCSR_CE = 0x00020000, /* cause: unimplemented operation */ @@ -149,7 +151,8 @@ public: }; //Mips interface flags -enum { +enum +{ MI_MODE_INIT = 0x0080, /* Bit 7: init mode */ MI_MODE_EBUS = 0x0100, /* Bit 8: ebus test mode */ MI_MODE_RDRAM = 0x0200, /* Bit 9: RDRAM reg mode */ @@ -245,7 +248,8 @@ public: DWORD & DPC_TMEM_REG; }; -enum { +enum +{ DPC_CLR_XBUS_DMEM_DMA = 0x0001, /* Bit 0: clear xbus_dmem_dma */ DPC_SET_XBUS_DMEM_DMA = 0x0002, /* Bit 1: set xbus_dmem_dma */ DPC_CLR_FREEZE = 0x0004, /* Bit 2: clear freeze */ @@ -289,7 +293,8 @@ public: DWORD & AI_BITRATE_REG; }; -enum { +enum +{ AI_STATUS_FIFO_FULL = 0x80000000, /* Bit 31: full */ AI_STATUS_DMA_BUSY = 0x40000000, /* Bit 30: busy */ }; @@ -360,7 +365,8 @@ public: }; //Signal Processor interface flags -enum { +enum +{ SP_CLR_HALT = 0x00001, /* Bit 0: clear halt */ SP_SET_HALT = 0x00002, /* Bit 1: set halt */ SP_CLR_BROKE = 0x00004, /* Bit 2: clear broke */ @@ -405,7 +411,8 @@ enum { }; //Peripheral Interface flags -enum { +enum +{ PI_STATUS_DMA_BUSY = 0x01, PI_STATUS_IO_BUSY = 0x02, PI_STATUS_ERROR = 0x04, @@ -430,7 +437,8 @@ public: }; //Serial Interface flags -enum { +enum +{ SI_STATUS_DMA_BUSY = 0x0001, SI_STATUS_RD_BUSY = 0x0002, SI_STATUS_DMA_ERROR = 0x0008, @@ -438,7 +446,8 @@ enum { }; -enum ROUNDING_MODE { +enum ROUNDING_MODE +{ ROUND_NEAR = _RC_NEAR, ROUND_DOWN = _RC_DOWN, ROUND_UP = _RC_UP, diff --git a/Source/Project64/N64 System/Mips/Sram.cpp b/Source/Project64/N64 System/Mips/Sram.cpp index 130a8d13d..df1b389de 100644 --- a/Source/Project64/N64 System/Mips/Sram.cpp +++ b/Source/Project64/N64 System/Mips/Sram.cpp @@ -14,17 +14,20 @@ CSram::CSram ( bool ReadOnly ) : m_hFile(NULL), m_ReadOnly(ReadOnly) { + } CSram::~CSram (void) { - if (m_hFile) { + if (m_hFile) + { CloseHandle(m_hFile); m_hFile = NULL; } } -BOOL CSram::LoadSram (void) { +BOOL CSram::LoadSram (void) +{ CPath FileName; FileName.SetDriveDirectory( g_Settings->LoadString(Directory_NativeSave).c_str()); @@ -47,11 +50,14 @@ BOOL CSram::LoadSram (void) { return true; } -void CSram::DmaFromSram(BYTE * dest, int StartOffset, int len) { +void CSram::DmaFromSram(BYTE * dest, int StartOffset, int len) +{ DWORD dwRead; - if (m_hFile == NULL) { - if (!LoadSram()) { + if (m_hFile == NULL) + { + if (!LoadSram()) + { return; } } @@ -60,14 +66,17 @@ void CSram::DmaFromSram(BYTE * dest, int StartOffset, int len) { } -void CSram::DmaToSram(BYTE * Source, int StartOffset, int len) { +void CSram::DmaToSram(BYTE * Source, int StartOffset, int len) +{ if (m_ReadOnly) { return; } - if (m_hFile == NULL) { - if (!LoadSram()) { + if (m_hFile == NULL) + { + if (!LoadSram()) + { return; } } diff --git a/Source/Project64/N64 System/Mips/System Events.cpp b/Source/Project64/N64 System/Mips/System Events.cpp index 402e7ed8f..d5cf29520 100644 --- a/Source/Project64/N64 System/Mips/System Events.cpp +++ b/Source/Project64/N64 System/Mips/System Events.cpp @@ -15,10 +15,12 @@ CSystemEvents::CSystemEvents(CN64System * System, CPlugins * Plugins) : m_System(System), m_Plugins(Plugins) { + } CSystemEvents::~CSystemEvents() { + } void CSystemEvents::QueueEvent(SystemEvent action) diff --git a/Source/Project64/N64 System/Mips/System Events.h b/Source/Project64/N64 System/Mips/System Events.h index 07127c908..4c7092c3a 100644 --- a/Source/Project64/N64 System/Mips/System Events.h +++ b/Source/Project64/N64 System/Mips/System Events.h @@ -10,7 +10,8 @@ ****************************************************************************/ #pragma once -enum SystemEvent { +enum SystemEvent +{ SysEvent_ExecuteInterrupt, SysEvent_GSButtonPressed, SysEvent_ResetCPU_Soft, @@ -61,7 +62,10 @@ public: void ExecuteEvents ( void ); void QueueEvent ( SystemEvent action); - inline const BOOL & DoSomething ( void ) const { return m_bDoSomething; } + inline const BOOL & DoSomething ( void ) const + { + return m_bDoSomething; + } private: CSystemEvents(void); // Disable default constructor diff --git a/Source/Project64/N64 System/Mips/System Timing.cpp b/Source/Project64/N64 System/Mips/System Timing.cpp index 2a16c8fd9..b32794c0c 100644 --- a/Source/Project64/N64 System/Mips/System Timing.cpp +++ b/Source/Project64/N64 System/Mips/System Timing.cpp @@ -14,6 +14,7 @@ CSystemTimer::CSystemTimer( int & NextTimer ) : m_NextTimer(NextTimer), m_inFixTimer(false) { + } void CSystemTimer::Reset ( void ) @@ -47,10 +48,14 @@ void CSystemTimer::SetTimer ( TimerType Type, DWORD Cycles, bool bRelative ) if (m_TimerDetatils[Type].Active) { m_TimerDetatils[Type].CyclesToTimer += Cycles; //Add to the timer - } else { + } + else + { m_TimerDetatils[Type].CyclesToTimer = (__int64)Cycles - (__int64)m_NextTimer; //replace the new cycles } - } else { + } + else + { m_TimerDetatils[Type].CyclesToTimer = (__int64)Cycles - (__int64)m_NextTimer; //replace the new cycles } FixTimers(); @@ -168,14 +173,17 @@ void CSystemTimer::TimerDone (void) UpdateTimers(); /* DWORD LastTimer; - if (Profiling) { + if (Profiling) + { LastTimer = StartTimer(Timer_Done); } - if (LogOptions.GenerateLog && LogOptions.LogExceptions && !LogOptions.NoInterrupts) { + if (LogOptions.GenerateLog && LogOptions.LogExceptions && !LogOptions.NoInterrupts) + { LogMessage("%08X: Timer Done (Type: %d CurrentTimer: %d)", *_PROGRAM_COUNTER, m_Current, *_Timer ); } */ - switch (m_Current) { + switch (m_Current) + { case CSystemTimer::CompareTimer: g_Reg->FAKE_CAUSE_REGISTER |= CAUSE_IP7; g_Reg->CheckInterrupts(); @@ -211,9 +219,12 @@ void CSystemTimer::TimerDone (void) break; case CSystemTimer::RspTimer: g_SystemTimer->StopTimer(CSystemTimer::RspTimer); - try { + try + { g_System->RunRSP(); - } catch (...) { + } + catch (...) + { g_Notify->BreakPoint(__FILEW__,__LINE__); } break; @@ -234,7 +245,8 @@ void CSystemTimer::TimerDone (void) g_Notify->BreakPoint(__FILEW__,__LINE__); } //CheckTimer(); - /*if (Profiling) { + /*if (Profiling) + { StartTimer(LastTimer); }*/ } @@ -266,8 +278,14 @@ bool CSystemTimer::SaveAllowed ( void ) } for (int i = 0; i < MaxTimer; i++) { - if (i == CompareTimer) { continue; } - if (i == ViTimer) { continue; } + if (i == CompareTimer) + { + continue; + } + if (i == ViTimer) + { + continue; + } if (m_TimerDetatils[i].Active) { return false; @@ -295,8 +313,16 @@ void CSystemTimer::LoadData ( void * file ) unzReadCurrentFile( file,&TimerDetailsSize,sizeof(TimerDetailsSize)); unzReadCurrentFile( file,&Entries,sizeof(Entries)); - if (TimerDetailsSize != sizeof(TIMER_DETAILS)) { g_Notify->BreakPoint(__FILEW__,__LINE__); return; } - if (Entries != sizeof(m_TimerDetatils)/sizeof(m_TimerDetatils[0])) { g_Notify->BreakPoint(__FILEW__,__LINE__); return; } + if (TimerDetailsSize != sizeof(TIMER_DETAILS)) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + return; + } + if (Entries != sizeof(m_TimerDetatils)/sizeof(m_TimerDetatils[0])) + { + g_Notify->BreakPoint(__FILEW__,__LINE__); + return; + } unzReadCurrentFile(file,(void *)&m_TimerDetatils,sizeof(m_TimerDetatils)); unzReadCurrentFile(file,(void *)&m_LastUpdate,sizeof(m_LastUpdate)); @@ -338,15 +364,33 @@ void CSystemTimer::RecordDifference( CLog &LogFile, const CSystemTimer& rSystemT bool CSystemTimer::operator == (const CSystemTimer& rSystemTimer) const { - if (m_LastUpdate != rSystemTimer.m_LastUpdate) { return false; } - if (m_NextTimer != rSystemTimer.m_NextTimer) { return false; } - if (m_Current != rSystemTimer.m_Current) { return false; } - if (m_inFixTimer != rSystemTimer.m_inFixTimer) { return false; } + if (m_LastUpdate != rSystemTimer.m_LastUpdate) + { + return false; + } + if (m_NextTimer != rSystemTimer.m_NextTimer) + { + return false; + } + if (m_Current != rSystemTimer.m_Current) + { + return false; + } + if (m_inFixTimer != rSystemTimer.m_inFixTimer) + { + return false; + } for (int i = 0; i < MaxTimer; i++) { - if (m_TimerDetatils[i].Active != rSystemTimer.m_TimerDetatils[i].Active) { return false; } - if (m_TimerDetatils[i].CyclesToTimer != rSystemTimer.m_TimerDetatils[i].CyclesToTimer) { return false; } + if (m_TimerDetatils[i].Active != rSystemTimer.m_TimerDetatils[i].Active) + { + return false; + } + if (m_TimerDetatils[i].CyclesToTimer != rSystemTimer.m_TimerDetatils[i].CyclesToTimer) + { + return false; + } } return true; } diff --git a/Source/Project64/N64 System/Mips/System Timing.h b/Source/Project64/N64 System/Mips/System Timing.h index fcc246739..16d7c17e6 100644 --- a/Source/Project64/N64 System/Mips/System Timing.h +++ b/Source/Project64/N64 System/Mips/System Timing.h @@ -15,7 +15,8 @@ class CSystemTimer { public: - enum TimerType { + enum TimerType + { UnknownTimer, CompareTimer, SoftResetTimer, @@ -30,7 +31,8 @@ public: MaxTimer }; - typedef struct { + typedef struct + { bool Active; __int64 CyclesToTimer; } TIMER_DETAILS; diff --git a/Source/Project64/N64 System/Mips/TLB Class.h b/Source/Project64/N64 System/Mips/TLB Class.h index bc3fdf7f1..f89f2538f 100644 --- a/Source/Project64/N64 System/Mips/TLB Class.h +++ b/Source/Project64/N64 System/Mips/TLB Class.h @@ -24,13 +24,16 @@ class CTLB : protected CSystemRegisters { public: - typedef struct { + typedef struct + { bool EntryDefined; - union { + union + { unsigned long Value; unsigned char A[4]; - struct { + struct + { unsigned zero : 13; unsigned Mask : 12; unsigned zero2 : 7; @@ -38,11 +41,13 @@ public: } PageMask; - union { + union + { unsigned long Value; unsigned char A[4]; - struct { + struct + { unsigned ASID : 8; unsigned Zero : 4; unsigned G : 1; @@ -51,11 +56,13 @@ public: } EntryHi; - union { + union + { unsigned long Value; unsigned char A[4]; - struct { + struct + { unsigned GLOBAL: 1; unsigned V : 1; unsigned D : 1; @@ -66,11 +73,13 @@ public: } EntryLo0; - union { + union + { unsigned long Value; unsigned char A[4]; - struct { + struct + { unsigned GLOBAL: 1; unsigned V : 1; unsigned D : 1; @@ -96,7 +105,10 @@ public: //See if a VAddr has an entry to translate to a PAddr bool AddressDefined ( DWORD VAddr ); - const TLB_ENTRY & TlbEntry ( int Entry) const { return m_tlb[Entry]; } + const TLB_ENTRY & TlbEntry ( int Entry) const + { + return m_tlb[Entry]; + } bool PAddrToVAddr ( DWORD PAddr, DWORD & VAddr, DWORD & Index ); @@ -106,7 +118,8 @@ public: bool operator != (const CTLB& rTLB) const; private: - typedef struct { + typedef struct + { DWORD VSTART; DWORD VEND; DWORD PHYSSTART; diff --git a/Source/Project64/N64 System/Mips/TLB class.cpp b/Source/Project64/N64 System/Mips/TLB class.cpp index 2032c4b20..da02fe4c5 100644 --- a/Source/Project64/N64 System/Mips/TLB class.cpp +++ b/Source/Project64/N64 System/Mips/TLB class.cpp @@ -20,12 +20,14 @@ CTLB::CTLB(CTLB_CB * CallBack ): WriteTrace(TraceTLB,__FUNCTION__ ": Done"); } -CTLB::~CTLB (void) { +CTLB::~CTLB (void) +{ WriteTrace(TraceTLB,__FUNCTION__ ": Start"); WriteTrace(TraceTLB,__FUNCTION__ ": Done"); } -void CTLB::Reset (bool InvalidateTLB) { +void CTLB::Reset (bool InvalidateTLB) +{ DWORD count; for (count = 0; count < 64; count++) @@ -39,7 +41,9 @@ void CTLB::Reset (bool InvalidateTLB) { { m_tlb[count].EntryDefined = false; } - } else { + } + else + { for (count = 0; count < 32; count ++) { SetupTLB_Entry(count,false); @@ -47,10 +51,12 @@ void CTLB::Reset (bool InvalidateTLB) { } } -bool CTLB::AddressDefined ( DWORD VAddr) { +bool CTLB::AddressDefined ( DWORD VAddr) +{ DWORD i; - if (VAddr >= 0x80000000 && VAddr <= 0xBFFFFFFF) { + if (VAddr >= 0x80000000 && VAddr <= 0xBFFFFFFF) + { return true; } @@ -66,7 +72,8 @@ bool CTLB::AddressDefined ( DWORD VAddr) { return false; } -void CTLB::Probe (void) { +void CTLB::Probe (void) +{ int Counter; WriteTrace(TraceTLB,__FUNCTION__ ": Start"); @@ -83,7 +90,8 @@ void CTLB::Probe (void) { DWORD TlbValueMasked = TlbEntryHiValue & Mask; DWORD EntryHiMasked = g_Reg->ENTRYHI_REGISTER & Mask; - if (TlbValueMasked == EntryHiMasked) { + if (TlbValueMasked == EntryHiMasked) + { if ((TlbEntryHiValue & 0x100) != 0 || //Global ((TlbEntryHiValue & 0xFF) == (g_Reg->ENTRYHI_REGISTER & 0xFF))) //SameAsid { @@ -107,13 +115,15 @@ void CTLB::ReadEntry (void) { g_Reg->ENTRYLO1_REGISTER = m_tlb[index].EntryLo1.Value; } -void CTLB::WriteEntry (int index, bool Random) { +void CTLB::WriteEntry (int index, bool Random) +{ int FastIndx; WriteTraceF(TraceTLB,__FUNCTION__ ": %02d %d %08X %08X %08X %08X ",index,Random,g_Reg->PAGE_MASK_REGISTER,g_Reg->ENTRYHI_REGISTER,g_Reg->ENTRYLO0_REGISTER,g_Reg->ENTRYLO1_REGISTER); //Check to see if entry is unmapping it self - if (m_tlb[index].EntryDefined) { + if (m_tlb[index].EntryDefined) + { FastIndx = index << 1; if (*_PROGRAM_COUNTER >= m_FastTlb[FastIndx].VSTART && *_PROGRAM_COUNTER < m_FastTlb[FastIndx].VEND && @@ -134,16 +144,25 @@ void CTLB::WriteEntry (int index, bool Random) { //Reset old addresses if (m_tlb[index].EntryDefined) { - for ( FastIndx = index << 1; FastIndx <= (index << 1) + 1; FastIndx++) { - if (!m_FastTlb[FastIndx].ValidEntry) { continue; } - if (!m_FastTlb[FastIndx].VALID) { continue; } + for ( FastIndx = index << 1; FastIndx <= (index << 1) + 1; FastIndx++) + { + if (!m_FastTlb[FastIndx].ValidEntry) + { + continue; + } + if (!m_FastTlb[FastIndx].VALID) + { + continue; + } if (m_tlb[index].PageMask.Value == g_Reg->PAGE_MASK_REGISTER && m_tlb[index].EntryHi.Value == g_Reg->ENTRYHI_REGISTER) { - if (FastIndx == (index << 1) && m_tlb[index].EntryLo0.Value == g_Reg->ENTRYLO0_REGISTER) { + if (FastIndx == (index << 1) && m_tlb[index].EntryLo0.Value == g_Reg->ENTRYLO0_REGISTER) + { continue; } - if (FastIndx != (index << 1) && m_tlb[index].EntryLo1.Value == g_Reg->ENTRYLO1_REGISTER) { + if (FastIndx != (index << 1) && m_tlb[index].EntryLo1.Value == g_Reg->ENTRYLO1_REGISTER) + { continue; } } @@ -161,9 +180,13 @@ void CTLB::WriteEntry (int index, bool Random) { m_CB->TLB_Changed(); } -void CTLB::SetupTLB_Entry (int index, bool Random) { +void CTLB::SetupTLB_Entry (int index, bool Random) +{ //Fix up Fast TLB entries - if (!m_tlb[index].EntryDefined) { return; } + if (!m_tlb[index].EntryDefined) + { + return; + } int FastIndx = index << 1; if (m_FastTlb[FastIndx].VALID) @@ -201,19 +224,24 @@ void CTLB::SetupTLB_Entry (int index, bool Random) { m_FastTlb[FastIndx].Probed = false; //Test both entries to see if they are valid - for ( FastIndx = index << 1; FastIndx <= (index << 1) + 1; FastIndx++) { - if (!m_FastTlb[FastIndx].VALID) { + for ( FastIndx = index << 1; FastIndx <= (index << 1) + 1; FastIndx++) + { + if (!m_FastTlb[FastIndx].VALID) + { m_FastTlb[FastIndx].ValidEntry = true; continue; } - if (m_FastTlb[FastIndx].VEND <= m_FastTlb[FastIndx].VSTART) { + if (m_FastTlb[FastIndx].VEND <= m_FastTlb[FastIndx].VSTART) + { continue; } - if (m_FastTlb[FastIndx].VSTART >= 0x80000000 && m_FastTlb[FastIndx].VEND <= 0xBFFFFFFF) { + if (m_FastTlb[FastIndx].VSTART >= 0x80000000 && m_FastTlb[FastIndx].VEND <= 0xBFFFFFFF) + { continue; } - if (m_FastTlb[FastIndx].PHYSSTART > 0x1FFFFFFF) { + if (m_FastTlb[FastIndx].PHYSSTART > 0x1FFFFFFF) + { continue; } @@ -227,7 +255,10 @@ bool CTLB::PAddrToVAddr(DWORD PAddr, DWORD & VAddr, DWORD & Index ) { for (int i = Index; i < 64; i++) { - if (m_FastTlb[i].ValidEntry == false) { continue; } + if (m_FastTlb[i].ValidEntry == false) + { + continue; + } if (PAddr >= m_FastTlb[i].PHYSSTART && PAddr < m_FastTlb[i].PHYSEND) { VAddr = m_FastTlb[i].VSTART + (PAddr - m_FastTlb[i].PHYSSTART); @@ -248,7 +279,10 @@ void CTLB::RecordDifference( CLog &LogFile, const CTLB& rTLB) LogFile.LogF("TLB[%d] Defined: %s %s\r\n",i,m_tlb[i].EntryDefined ? "Yes" : "No",rTLB.m_tlb[i].EntryDefined ? "Yes" : "No"); continue; } - if (!m_tlb[i].EntryDefined) { continue; } + if (!m_tlb[i].EntryDefined) + { + continue; + } if (m_tlb[i].PageMask.Value != rTLB.m_tlb[i].PageMask.Value) { LogFile.LogF("TLB[%d] PageMask: %X %X\r\n",i,m_tlb[i].PageMask.Value,rTLB.m_tlb[i].PageMask.Value); @@ -272,8 +306,14 @@ bool CTLB::operator == (const CTLB& rTLB) const { for (int i = 0, n = sizeof(m_tlb)/sizeof(m_tlb[0]); i < n; i++) { - if (m_tlb[i].EntryDefined != rTLB.m_tlb[i].EntryDefined) { return false; } - if (!m_tlb[i].EntryDefined) { continue; } + if (m_tlb[i].EntryDefined != rTLB.m_tlb[i].EntryDefined) + { + return false; + } + if (!m_tlb[i].EntryDefined) + { + continue; + } if (m_tlb[i].PageMask.Value != rTLB.m_tlb[i].PageMask.Value || m_tlb[i].EntryHi.Value != rTLB.m_tlb[i].EntryHi.Value || m_tlb[i].EntryLo0.Value != rTLB.m_tlb[i].EntryLo0.Value || diff --git a/Source/Project64/N64 System/Recompiler/Code Block.cpp b/Source/Project64/N64 System/Recompiler/Code Block.cpp index 0f3442fcb..1b9793f78 100644 --- a/Source/Project64/N64 System/Recompiler/Code Block.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Block.cpp @@ -48,7 +48,9 @@ CCodeBlock::CCodeBlock(DWORD VAddrEnter, BYTE * RecompPos) : m_MemLocation[1] = m_MemLocation[0] + 1; m_MemContents[0] = *m_MemLocation[0]; m_MemContents[1] = *m_MemLocation[1]; - } else { + } + else + { memset(m_MemLocation,0,sizeof(m_MemLocation)); memset(m_MemContents,0,sizeof(m_MemContents)); } @@ -189,7 +191,9 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection ) } } } - } else { + } + else + { CurrentSection->m_EndSection = true; break; } @@ -265,12 +269,16 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection ) CPU_Message(__FUNCTION__ ": Jump End Block"); JumpSection->m_EndSection = true; TargetPC = (DWORD)-1; - } else { + } + else + { JumpSection->SetJumpAddress(TestPC, TargetPC,false); } JumpSection->SetDelaySlot(); SetSection(JumpSection->m_JumpSection,JumpSection,TargetPC,true,TestPC); - } else { + } + else + { g_Notify->BreakPoint(__FILEW__,__LINE__); } } @@ -331,7 +339,10 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection ) { continue; } - if (!CreateBlockLinkage(Section)) { return false; } + if (!CreateBlockLinkage(Section)) + { + return false; + } break; } if (CurrentSection->m_EndPC == (DWORD)-1) @@ -363,8 +374,14 @@ void CCodeBlock::LogSectionInfo ( void ) bool CCodeBlock::AnalyseBlock ( void ) { - if (!g_System->bLinkBlocks()) { return true; } - if (!CreateBlockLinkage(m_EnterSection)) { return false; } + if (!g_System->bLinkBlocks()) + { + return true; + } + if (!CreateBlockLinkage(m_EnterSection)) + { + return false; + } DetermineLoops(); LogSectionInfo(); return true; @@ -380,7 +397,8 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin PermLoop = false; OPCODE Command; - if (!g_MMU->LW_VAddr(PC, Command.Hex)) { + if (!g_MMU->LW_VAddr(PC, Command.Hex)) + { g_Notify->BreakPoint(__FILEW__,__LINE__); return false; } @@ -432,7 +450,9 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin if (TargetPC == PC + 8) { TargetPC = (DWORD)-1; - } else { + } + else + { if (TargetPC == PC && !DelaySlotEffectsCompare(PC,Command.rs,0)) { PermLoop = true; @@ -447,14 +467,18 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin if (TargetPC == PC + 8) { TargetPC = (DWORD)-1; - } else { + } + else + { if (TargetPC == PC) { if (Command.rs == 0) { TargetPC = (DWORD)-1; EndBlock = true; - } else { + } + else + { if (!DelaySlotEffectsCompare(PC,Command.rs,Command.rt)) { PermLoop = true; @@ -509,7 +533,9 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin if (TargetPC == PC + 8) { TargetPC = (DWORD)-1; - } else { + } + else + { if (Command.rs != 0 || Command.rt != 0) { ContinuePC = PC + 8; @@ -529,7 +555,9 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin if (TargetPC == PC + 8) { TargetPC = (DWORD)-1; - } else { + } + else + { if (TargetPC == PC) { if (!DelaySlotEffectsCompare(PC,Command.rs,Command.rt)) @@ -549,7 +577,8 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin default: if ( (Command.rs & 0x10 ) != 0 ) { - switch( Command.funct ) { + switch ( Command.funct ) + { case R4300i_COP0_CO_TLBR: case R4300i_COP0_CO_TLBWI: case R4300i_COP0_CO_TLBWR: case R4300i_COP0_CO_TLBP: break; @@ -560,7 +589,9 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin g_Notify->BreakPoint(__FILEW__,__LINE__); return false; } - } else { + } + else + { g_Notify->BreakPoint(__FILEW__,__LINE__); return false; } @@ -568,7 +599,8 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin } break; case R4300i_CP1: - switch (Command.fmt) { + switch (Command.fmt) + { case R4300i_COP1_MF: case R4300i_COP1_DMF: case R4300i_COP1_CF: case R4300i_COP1_MT: case R4300i_COP1_DMT: case R4300i_COP1_CT: case R4300i_COP1_S: case R4300i_COP1_D: case R4300i_COP1_W: case R4300i_COP1_L: @@ -581,7 +613,9 @@ bool CCodeBlock::AnalyzeInstruction ( DWORD PC, DWORD & TargetPC, DWORD & Contin if (TargetPC == PC + 8) { TargetPC = (DWORD)-1; - } else { + } + else + { if (TargetPC == PC) { g_Notify->BreakPoint(__FILEW__,__LINE__); @@ -674,14 +708,21 @@ bool CCodeBlock::Compile() EnterCodeBlock(); - if (g_SyncSystem) { - //if ((DWORD)BlockInfo.CompiledLocation == 0x60A7B73B) { X86BreakPoint(__FILEW__,__LINE__); } + if (g_SyncSystem) + { + //if ((DWORD)BlockInfo.CompiledLocation == 0x60A7B73B) + //{ + // X86BreakPoint(__FILEW__,__LINE__); + //} //MoveConstToVariable((DWORD)BlockInfo.CompiledLocation,&CurrentBlock,"CurrentBlock"); } - if (g_System->bLinkBlocks()) { + if (g_System->bLinkBlocks()) + { while (m_EnterSection->GenerateX86Code(NextTest())); - } else { + } + else + { if (!m_EnterSection->GenerateX86Code(NextTest())) { return false;