diff --git a/Source/Project64/N64 System/N64 Class.cpp b/Source/Project64/N64 System/N64 Class.cpp index 73013aa41..54f149ba1 100644 --- a/Source/Project64/N64 System/N64 Class.cpp +++ b/Source/Project64/N64 System/N64 Class.cpp @@ -49,9 +49,9 @@ m_CheatsSlectionChanged(false) { gameHertz = (SystemType() == SYSTEM_PAL) ? 50 : 60; } - m_hPauseEvent = CreateEvent(NULL,true,false,NULL); + m_hPauseEvent = CreateEvent(NULL, true, false, NULL); m_Limitor.SetHertz(gameHertz); - g_Settings->SaveDword(GameRunning_ScreenHertz,gameHertz); + g_Settings->SaveDword(GameRunning_ScreenHertz, gameHertz); m_Cheats.LoadCheats(!g_Settings->LoadDword(Setting_RememberCheats), Plugins); } @@ -82,16 +82,16 @@ CN64System::~CN64System() } } -void CN64System::ExternalEvent ( SystemEvent action ) +void CN64System::ExternalEvent(SystemEvent action) { - switch (action) + switch (action) { - case SysEvent_Profile_GenerateLogs: - case SysEvent_Profile_StartStop: - case SysEvent_Profile_ResetLogs: - case SysEvent_ExecuteInterrupt: - case SysEvent_SaveMachineState: - case SysEvent_LoadMachineState: + case SysEvent_Profile_GenerateLogs: + case SysEvent_Profile_StartStop: + case SysEvent_Profile_ResetLogs: + case SysEvent_ExecuteInterrupt: + case SysEvent_SaveMachineState: + case SysEvent_LoadMachineState: case SysEvent_ChangingFullScreen: case SysEvent_GSButtonPressed: case SysEvent_ResetCPU_SoftDone: @@ -103,18 +103,18 @@ void CN64System::ExternalEvent ( SystemEvent action ) case SysEvent_Interrupt_DP: case SysEvent_ResetCPU_Hard: case SysEvent_ResetCPU_Soft: - case SysEvent_CloseCPU: + case SysEvent_CloseCPU: case SysEvent_ChangePlugins: QueueEvent(action); break; - case SysEvent_PauseCPU_FromMenu: - case SysEvent_PauseCPU_AppLostFocus: - case SysEvent_PauseCPU_AppLostActive: - case SysEvent_PauseCPU_SaveGame: - case SysEvent_PauseCPU_LoadGame: - case SysEvent_PauseCPU_DumpMemory: - case SysEvent_PauseCPU_SearchMemory: - case SysEvent_PauseCPU_Settings: + case SysEvent_PauseCPU_FromMenu: + case SysEvent_PauseCPU_AppLostFocus: + case SysEvent_PauseCPU_AppLostActive: + case SysEvent_PauseCPU_SaveGame: + case SysEvent_PauseCPU_LoadGame: + case SysEvent_PauseCPU_DumpMemory: + case SysEvent_PauseCPU_SearchMemory: + case SysEvent_PauseCPU_Settings: case SysEvent_PauseCPU_Cheats: if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) { @@ -126,43 +126,43 @@ void CN64System::ExternalEvent ( SystemEvent action ) SetEvent(m_hPauseEvent); break; case SysEvent_ResumeCPU_AppGainedFocus: - if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_AppLostFocus ) + if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_AppLostFocus) { SetEvent(m_hPauseEvent); } break; case SysEvent_ResumeCPU_AppGainedActive: - if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_AppLostActive ) + if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_AppLostActive) { SetEvent(m_hPauseEvent); } break; case SysEvent_ResumeCPU_SaveGame: - if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_SaveGame ) + if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_SaveGame) { SetEvent(m_hPauseEvent); } break; case SysEvent_ResumeCPU_LoadGame: - if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_LoadGame ) + if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_LoadGame) { SetEvent(m_hPauseEvent); } break; case SysEvent_ResumeCPU_DumpMemory: - if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_DumpMemory ) + if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_DumpMemory) { SetEvent(m_hPauseEvent); } break; case SysEvent_ResumeCPU_SearchMemory: - if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_SearchMemory ) + if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_SearchMemory) { SetEvent(m_hPauseEvent); } break; case SysEvent_ResumeCPU_Settings: - if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_Settings ) + if (g_Settings->LoadDword(GameRunning_CPU_PausedType) == PauseType_Settings) { SetEvent(m_hPauseEvent); } @@ -179,38 +179,38 @@ void CN64System::ExternalEvent ( SystemEvent action ) } } -bool CN64System::RunFileImage ( const char * FileLoc ) +bool CN64System::RunFileImage(const char * FileLoc) { CloseSystem(); if (g_Settings->LoadBool(GameRunning_LoadingInProgress)) { return false; } - g_Settings->SaveBool(GameRunning_LoadingInProgress,true); + g_Settings->SaveBool(GameRunning_LoadingInProgress, true); - WriteTrace(TraceDebug,__FUNCTION__ ": Mark Rom as loading"); + WriteTrace(TraceDebug, __FUNCTION__ ": Mark Rom as loading"); //Mark the rom as loading - g_Settings->SaveBool(GameRunning_LoadingInProgress,true); + g_Settings->SaveBool(GameRunning_LoadingInProgress, true); Notify().RefreshMenu(); //Try to load the passed N64 rom if (g_Rom == NULL) { - WriteTrace(TraceDebug,__FUNCTION__ ": Allocating global rom object"); + WriteTrace(TraceDebug, __FUNCTION__ ": Allocating global rom object"); g_Rom = new CN64Rom(); - } - else + } + else { - WriteTrace(TraceDebug,__FUNCTION__ ": Use existing global rom object"); + WriteTrace(TraceDebug, __FUNCTION__ ": Use existing global rom object"); } - WriteTraceF(TraceDebug,__FUNCTION__ ": Loading \"%s\"",FileLoc); - if (g_Rom->LoadN64Image(FileLoc)) + WriteTraceF(TraceDebug, __FUNCTION__ ": Loading \"%s\"", FileLoc); + if (g_Rom->LoadN64Image(FileLoc)) { g_System->RefreshGameSettings(); - WriteTrace(TraceDebug,__FUNCTION__ ": Add Recent Rom"); + WriteTrace(TraceDebug, __FUNCTION__ ": Add Recent Rom"); Notify().AddRecentRom(FileLoc); Notify().SetWindowCaption(g_Settings->LoadStringVal(Game_GoodName).ToUTF16().c_str()); @@ -219,7 +219,7 @@ bool CN64System::RunFileImage ( const char * FileLoc ) if (g_Settings->LoadDword(Setting_AutoStart) != 0) { - g_BaseSystem = new CN64System(g_Plugins,false); + g_BaseSystem = new CN64System(g_Plugins, false); if (g_BaseSystem) { g_BaseSystem->StartEmulation(true); @@ -228,11 +228,11 @@ bool CN64System::RunFileImage ( const char * FileLoc ) } else { - WriteTraceF(TraceError,__FUNCTION__ ": LoadN64Image failed (\"%s\")",FileLoc); + WriteTraceF(TraceError, __FUNCTION__ ": LoadN64Image failed (\"%s\")", FileLoc); g_Notify->DisplayError(g_Rom->GetError()); delete g_Rom; g_Rom = NULL; - g_Settings->SaveBool(GameRunning_LoadingInProgress,false); + g_Settings->SaveBool(GameRunning_LoadingInProgress, false); Notify().RefreshMenu(); return false; } @@ -249,52 +249,52 @@ void CN64System::CloseSystem() } } -bool CN64System::EmulationStarting ( HANDLE hThread, DWORD ThreadId ) +bool CN64System::EmulationStarting(HANDLE hThread, DWORD ThreadId) { bool bRes = true; WriteTrace(TraceDebug, __FUNCTION__ ": Setting N64 system as active"); if (g_BaseSystem->SetActiveSystem(true)) { - g_BaseSystem->m_CPU_Handle = hThread; + g_BaseSystem->m_CPU_Handle = hThread; g_BaseSystem->m_CPU_ThreadID = ThreadId; - WriteTrace(TraceDebug,__FUNCTION__ ": Setting up N64 system done"); - g_Settings->SaveBool(GameRunning_LoadingInProgress,false); + WriteTrace(TraceDebug, __FUNCTION__ ": Setting up N64 system done"); + g_Settings->SaveBool(GameRunning_LoadingInProgress, false); Notify().RefreshMenu(); try { - WriteTrace(TraceDebug,__FUNCTION__ ": Game set to auto start, starting"); - g_BaseSystem->StartEmulation2(false); - WriteTrace(TraceDebug,__FUNCTION__ ": Game Done"); - } + WriteTrace(TraceDebug, __FUNCTION__ ": Game set to auto start, starting"); + g_BaseSystem->StartEmulation2(false); + WriteTrace(TraceDebug, __FUNCTION__ ": Game Done"); + } catch (...) { - WriteTraceF(TraceError,__FUNCTION__ ": Exception caught\nFile: %s\nLine: %d",__FILE__,__LINE__); + WriteTraceF(TraceError, __FUNCTION__ ": Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__); char Message[600]; - sprintf(Message,__FUNCTION__ ": Exception caught\nFile: %s\nLine: %d",__FILE__,__LINE__); - MessageBox(NULL,Message,"Exception",MB_OK); + sprintf(Message, __FUNCTION__ ": Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__); + MessageBox(NULL, Message, "Exception", MB_OK); } } - else + else { - WriteTrace(TraceError,__FUNCTION__ ": SetActiveSystem failed"); + WriteTrace(TraceError, __FUNCTION__ ": SetActiveSystem failed"); g_Notify->DisplayError(__FUNCTIONW__ L": Failed to Initialize N64 System"); - g_Settings->SaveBool(GameRunning_LoadingInProgress,false); + g_Settings->SaveBool(GameRunning_LoadingInProgress, false); Notify().RefreshMenu(); bRes = false; } return bRes; } - -void CN64System::StartEmulation2 ( bool NewThread ) + +void CN64System::StartEmulation2(bool NewThread) { if (NewThread) { - WriteTrace(TraceDebug,__FUNCTION__ ": Starting"); + WriteTrace(TraceDebug, __FUNCTION__ ": Starting"); Notify().HideRomBrowser(); - if (bHaveDebugger()) + if (bHaveDebugger()) { g_LogOptions.GenerateLog = g_Settings->LoadBool(Debugger_GenerateDebugLog); LoadLogOptions(&g_LogOptions, FALSE); @@ -305,7 +305,7 @@ void CN64System::StartEmulation2 ( bool NewThread ) DWORD CpuType = g_Settings->LoadDword(Game_CpuType); - if(CpuType == CPU_SyncCores && !g_Settings->LoadBool(Debugger_Enabled)) + if (CpuType == CPU_SyncCores && !g_Settings->LoadBool(Debugger_Enabled)) { g_Settings->SaveDword(Game_CpuType, CPU_Recompiler); CpuType = CPU_Recompiler; @@ -313,12 +313,12 @@ void CN64System::StartEmulation2 ( bool NewThread ) if (CpuType == CPU_SyncCores) { - g_Notify->DisplayMessage(5,L"Copy Plugins"); + g_Notify->DisplayMessage(5, L"Copy Plugins"); g_Plugins->CopyPlugins(g_Settings->LoadStringVal(Directory_PluginSync)); #if defined(WINDOWS_UI) m_SyncWindow = new CMainGui(false); - m_SyncPlugins = new CPlugins( g_Settings->LoadStringVal(Directory_PluginSync) ); - m_SyncPlugins->SetRenderWindows(m_SyncWindow,m_SyncWindow); + m_SyncPlugins = new CPlugins(g_Settings->LoadStringVal(Directory_PluginSync)); + m_SyncPlugins->SetRenderWindows(m_SyncWindow, m_SyncWindow); m_SyncCPU = new CN64System(m_SyncPlugins, true); #else @@ -328,7 +328,7 @@ void CN64System::StartEmulation2 ( bool NewThread ) if (CpuType == CPU_Recompiler || CpuType == CPU_SyncCores) { - m_Recomp = new CRecompiler(m_Reg,m_Profile,m_EndEmulation); + m_Recomp = new CRecompiler(m_Reg, m_Profile, m_EndEmulation); } bool bSetActive = true; @@ -344,7 +344,7 @@ void CN64System::StartEmulation2 ( bool NewThread ) if (!bSetActive) { - g_Settings->SaveBool(GameRunning_LoadingInProgress,false); + g_Settings->SaveBool(GameRunning_LoadingInProgress, false); g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT); Notify().RefreshMenu(); @@ -360,23 +360,23 @@ void CN64System::StartEmulation2 ( bool NewThread ) //create the needed info into a structure to pass as one parameter //for creating a thread Info->ThreadHandle = hThread; - - *hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartEmulationThread,Info,0, &Info->ThreadID); + + *hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartEmulationThread, Info, 0, &Info->ThreadID); } - else + else { //mark the emulation as starting and fix up menus - g_Notify->DisplayMessage(5,MSG_EMULATION_STARTED); + g_Notify->DisplayMessage(5, MSG_EMULATION_STARTED); - if (g_Settings->LoadBool(Setting_AutoFullscreen)) + if (g_Settings->LoadBool(Setting_AutoFullscreen)) { - WriteTrace(TraceDebug,__FUNCTION__ " 15"); + WriteTrace(TraceDebug, __FUNCTION__ " 15"); CIniFile RomIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); stdstr Status = g_Settings->LoadStringVal(Rdb_Status); char String[100]; - RomIniFile.GetString("Rom Status",stdstr_f("%s.AutoFullScreen", Status.c_str()).c_str(),"true",String,sizeof(String)); - if (_stricmp(String,"true") == 0) + RomIniFile.GetString("Rom Status", stdstr_f("%s.AutoFullScreen", Status.c_str()).c_str(), "true", String, sizeof(String)); + if (_stricmp(String, "true") == 0) { Notify().ChangeFullScreen(); } @@ -385,25 +385,25 @@ void CN64System::StartEmulation2 ( bool NewThread ) } } -void CN64System::StartEmulation ( bool NewThread ) +void CN64System::StartEmulation(bool NewThread) { - __try + __try { StartEmulation2(NewThread); } - __except( g_MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation())) + __except (g_MMU->MemoryFilter(GetExceptionCode(), GetExceptionInformation())) { char Message[600]; - sprintf(Message,"Exception caught\nFile: %s\nLine: %d",__FILE__,__LINE__); - MessageBox(NULL,Message,"Exception",MB_OK); + sprintf(Message, "Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__); + MessageBox(NULL, Message, "Exception", MB_OK); } } -void CN64System::StartEmulationThread ( ThreadInfo * Info ) +void CN64System::StartEmulationThread(ThreadInfo * Info) { CoInitialize(NULL); - - EmulationStarting(*Info->ThreadHandle,Info->ThreadID); + + EmulationStarting(*Info->ThreadHandle, Info->ThreadID); delete Info->ThreadHandle; delete Info; @@ -412,9 +412,9 @@ void CN64System::StartEmulationThread ( ThreadInfo * Info ) void CN64System::CloseCpu() { - if (m_CPU_Handle == NULL) + if (m_CPU_Handle == NULL) { - return; + return; } m_EndEmulation = true; @@ -422,26 +422,26 @@ void CN64System::CloseCpu() { SetEvent(m_hPauseEvent); } - + if (GetCurrentThreadId() == m_CPU_ThreadID) { ExternalEvent(SysEvent_CloseCPU); return; } - + HANDLE hThread = m_CPU_Handle; - for (int count = 0; count < 200; count ++ ) + for (int count = 0; count < 200; count++) { Sleep(100); if (Notify().ProcessGuiMessages()) { return; } - + DWORD ExitCode; - if (GetExitCodeThread(hThread,&ExitCode)) + if (GetExitCodeThread(hThread, &ExitCode)) { - if (ExitCode != STILL_ACTIVE) + if (ExitCode != STILL_ACTIVE) { break; } @@ -449,21 +449,21 @@ void CN64System::CloseCpu() } if (hThread) - { + { DWORD ExitCode; - GetExitCodeThread(hThread,&ExitCode); - if (ExitCode == STILL_ACTIVE) + GetExitCodeThread(hThread, &ExitCode); + if (ExitCode == STILL_ACTIVE) { - TerminateThread(hThread,0); + TerminateThread(hThread, 0); } } CpuStopped(); } -void CN64System::DisplayRomInfo ( HWND hParent ) +void CN64System::DisplayRomInfo(HWND hParent) { if (!g_Rom) { return; } - + RomInformation Info(g_Rom); Info.DisplayInformation(hParent); } @@ -475,36 +475,36 @@ void CN64System::Pause() return; } ResetEvent(m_hPauseEvent); - g_Settings->SaveBool(GameRunning_CPU_Paused,true); + g_Settings->SaveBool(GameRunning_CPU_Paused, true); Notify().RefreshMenu(); - g_Notify->DisplayMessage(5,MSG_CPU_PAUSED); + g_Notify->DisplayMessage(5, MSG_CPU_PAUSED); WaitForSingleObject(m_hPauseEvent, INFINITE); ResetEvent(m_hPauseEvent); - g_Settings->SaveBool(GameRunning_CPU_Paused,(DWORD)false); + g_Settings->SaveBool(GameRunning_CPU_Paused, (DWORD)false); Notify().RefreshMenu(); Notify().DisplayMessage(5, MSG_CPU_RESUMED); } -stdstr CN64System::ChooseFileToOpen ( HWND hParent ) +stdstr CN64System::ChooseFileToOpen(HWND hParent) { OPENFILENAME openfilename; - char FileName[_MAX_PATH],Directory[_MAX_PATH]; + char FileName[_MAX_PATH], Directory[_MAX_PATH]; memset(&FileName, 0, sizeof(FileName)); memset(&openfilename, 0, sizeof(openfilename)); - strcpy(Directory,g_Settings->LoadStringVal(Directory_Game).c_str()); + strcpy(Directory, g_Settings->LoadStringVal(Directory_Game).c_str()); - openfilename.lStructSize = sizeof( openfilename ); - openfilename.hwndOwner = (HWND)hParent; + openfilename.lStructSize = sizeof(openfilename); + openfilename.hwndOwner = (HWND)hParent; openfilename.lpstrFilter = "N64 ROMs (*.zip, *.7z, *.?64, *.rom, *.usa, *.jap, *.pal, *.bin)\0*.?64;*.zip;*.7z;*.bin;*.rom;*.usa;*.jap;*.pal\0All files (*.*)\0*.*\0"; - openfilename.lpstrFile = FileName; - openfilename.lpstrInitialDir = Directory; - openfilename.nMaxFile = MAX_PATH; - openfilename.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + openfilename.lpstrFile = FileName; + openfilename.lpstrInitialDir = Directory; + openfilename.nMaxFile = MAX_PATH; + openfilename.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - if (GetOpenFileName (&openfilename)) - { + if (GetOpenFileName(&openfilename)) + { return stdstr(FileName); } return stdstr(""); @@ -512,7 +512,7 @@ stdstr CN64System::ChooseFileToOpen ( HWND hParent ) void CN64System::GameReset() { - m_SystemTimer.SetTimer(CSystemTimer::SoftResetTimer,0x3000000,false); + m_SystemTimer.SetTimer(CSystemTimer::SoftResetTimer, 0x3000000, false); m_Plugins->Gfx()->ShowCFB(); m_Reg.FAKE_CAUSE_REGISTER |= CAUSE_IP4; m_Plugins->Gfx()->SoftReset(); @@ -526,7 +526,7 @@ void CN64System::PluginReset() { if (!m_Plugins->ResetInUiThread(this)) { - g_Notify->DisplayMessage(5,MSG_PLUGIN_NOT_INIT); + g_Notify->DisplayMessage(5, MSG_PLUGIN_NOT_INIT); if (g_BaseSystem) { g_BaseSystem->m_EndEmulation = true; @@ -536,7 +536,7 @@ void CN64System::PluginReset() { if (!m_SyncCPU->m_Plugins->ResetInUiThread(m_SyncCPU)) { - g_Notify->DisplayMessage(5,MSG_PLUGIN_NOT_INIT); + g_Notify->DisplayMessage(5, MSG_PLUGIN_NOT_INIT); if (g_BaseSystem) { g_BaseSystem->m_EndEmulation = true; @@ -558,23 +558,23 @@ void CN64System::PluginReset() #endif } -void CN64System::Reset (bool bInitReg, bool ClearMenory) +void CN64System::Reset(bool bInitReg, bool ClearMenory) { - g_Settings->SaveBool(GameRunning_InReset,true); + g_Settings->SaveBool(GameRunning_InReset, true); RefreshGameSettings(); m_Audio.Reset(); m_MMU_VM.Reset(ClearMenory); Mempak::Close(); m_CyclesToSkip = 0; - m_AlistCount = 0; - m_DlistCount = 0; + m_AlistCount = 0; + m_DlistCount = 0; m_UnknownCount = 0; - m_DMAUsed = false; - m_RspBroke = true; - m_SyncCount = 0; + m_DMAUsed = false; + m_RspBroke = true; + m_SyncCount = 0; - for (int i = 0, n = (sizeof(m_LastSuccessSyncPC)/sizeof(m_LastSuccessSyncPC[0])); i < n; i++) + for (int i = 0, n = (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])); i < n; i++) { m_LastSuccessSyncPC[i] = 0; } @@ -582,20 +582,20 @@ void CN64System::Reset (bool bInitReg, bool ClearMenory) if (bInitReg) { bool PostPif = true; - - InitRegisters(PostPif,m_MMU_VM); - if (PostPif) + + InitRegisters(PostPif, m_MMU_VM); + if (PostPif) { - memcpy((m_MMU_VM.Dmem()+0x40), (g_Rom->GetRomAddress() + 0x040), 0xFBC); + memcpy((m_MMU_VM.Dmem() + 0x40), (g_Rom->GetRomAddress() + 0x040), 0xFBC); } } - else + else { m_Reg.Reset(); } m_SystemTimer.Reset(); - m_SystemTimer.SetTimer(CSystemTimer::CompareTimer,m_Reg.COMPARE_REGISTER - m_Reg.COUNT_REGISTER,false); + m_SystemTimer.SetTimer(CSystemTimer::CompareTimer, m_Reg.COMPARE_REGISTER - m_Reg.COUNT_REGISTER, false); if (m_Recomp) { @@ -604,12 +604,12 @@ void CN64System::Reset (bool bInitReg, bool ClearMenory) if (m_Plugins) { m_Plugins->GameReset(); } if (m_SyncCPU) { - m_SyncCPU->Reset(bInitReg,ClearMenory); + m_SyncCPU->Reset(bInitReg, ClearMenory); } - g_Settings->SaveBool(GameRunning_InReset,true); + g_Settings->SaveBool(GameRunning_InReset, true); } -bool CN64System::SetActiveSystem( bool bActive ) +bool CN64System::SetActiveSystem(bool bActive) { bool bInitPlugin = false; bool bReset = false; @@ -621,7 +621,7 @@ bool CN64System::SetActiveSystem( bool bActive ) } if (bActive) - { + { m_Reg.SetAsCurrentSystem(); if (g_System) @@ -631,21 +631,21 @@ bool CN64System::SetActiveSystem( bool bActive ) g_System->m_JumpToLocation = R4300iOp::m_JumpToLocation; } - g_System = this; + g_System = this; if (g_BaseSystem == this) { - g_SyncSystem = m_SyncCPU; + g_SyncSystem = m_SyncCPU; } - g_Recompiler = m_Recomp; - g_MMU = &m_MMU_VM; - g_TLB = &m_TLB; - g_Reg = &m_Reg; - g_Audio = &m_Audio; - g_SystemTimer = &m_SystemTimer; - g_TransVaddr = &m_MMU_VM; + g_Recompiler = m_Recomp; + g_MMU = &m_MMU_VM; + g_TLB = &m_TLB; + g_Reg = &m_Reg; + g_Audio = &m_Audio; + g_SystemTimer = &m_SystemTimer; + g_TransVaddr = &m_MMU_VM; g_SystemEvents = this; - g_NextTimer = &m_NextTimer; - g_Plugins = m_Plugins; + g_NextTimer = &m_NextTimer; + g_Plugins = m_Plugins; g_TLBLoadAddress = &m_TLBLoadAddress; g_TLBStoreAddress = &m_TLBStoreAddress; R4300iOp::m_TestTimer = m_TestTimer; @@ -667,27 +667,27 @@ bool CN64System::SetActiveSystem( bool bActive ) { if (this == g_BaseSystem) { - g_System = NULL; - g_SyncSystem = NULL; - g_Recompiler = NULL; - g_MMU = NULL; - g_TLB = NULL; - g_Reg = NULL; - g_Audio = NULL; - g_SystemTimer = NULL; - g_TransVaddr = NULL; - g_SystemEvents = NULL; - g_NextTimer = NULL; - g_Plugins = m_Plugins; - g_TLBLoadAddress = NULL; + g_System = NULL; + g_SyncSystem = NULL; + g_Recompiler = NULL; + g_MMU = NULL; + g_TLB = NULL; + g_Reg = NULL; + g_Audio = NULL; + g_SystemTimer = NULL; + g_TransVaddr = NULL; + g_SystemEvents = NULL; + g_NextTimer = NULL; + g_Plugins = m_Plugins; + g_TLBLoadAddress = NULL; g_TLBStoreAddress = NULL; } } if (bInitPlugin) { - WriteTrace(TraceDebug,__FUNCTION__ ": Reseting Plugins"); - g_Notify->DisplayMessage(5,MSG_PLUGIN_INIT); + WriteTrace(TraceDebug, __FUNCTION__ ": Reseting Plugins"); + g_Notify->DisplayMessage(5, MSG_PLUGIN_INIT); m_Plugins->CreatePlugins(); bRes = m_Plugins->Initiate(this); if (!bRes) @@ -698,53 +698,53 @@ bool CN64System::SetActiveSystem( bool bActive ) if (bReset) { - Reset(true,true); + Reset(true, true); } return bRes; } -void CN64System::InitRegisters( bool bPostPif, CMipsMemory & MMU ) +void CN64System::InitRegisters(bool bPostPif, CMipsMemory & MMU) { m_Reg.Reset(); //COP0 Registers - m_Reg.RANDOM_REGISTER = 0x1F; - m_Reg.COUNT_REGISTER = 0x5000; - m_Reg.MI_VERSION_REG = 0x02020102; - m_Reg.SP_STATUS_REG = 0x00000001; - m_Reg.CAUSE_REGISTER = 0x0000005C; - m_Reg.CONTEXT_REGISTER = 0x007FFFF0; - m_Reg.EPC_REGISTER = 0xFFFFFFFF; - m_Reg.BAD_VADDR_REGISTER = 0xFFFFFFFF; - m_Reg.ERROREPC_REGISTER = 0xFFFFFFFF; - m_Reg.CONFIG_REGISTER = 0x0006E463; - m_Reg.STATUS_REGISTER = 0x34000000; + m_Reg.RANDOM_REGISTER = 0x1F; + m_Reg.COUNT_REGISTER = 0x5000; + m_Reg.MI_VERSION_REG = 0x02020102; + m_Reg.SP_STATUS_REG = 0x00000001; + m_Reg.CAUSE_REGISTER = 0x0000005C; + m_Reg.CONTEXT_REGISTER = 0x007FFFF0; + m_Reg.EPC_REGISTER = 0xFFFFFFFF; + m_Reg.BAD_VADDR_REGISTER = 0xFFFFFFFF; + m_Reg.ERROREPC_REGISTER = 0xFFFFFFFF; + m_Reg.CONFIG_REGISTER = 0x0006E463; + m_Reg.STATUS_REGISTER = 0x34000000; //m_Reg.REVISION_REGISTER = 0x00000511; m_Reg.FixFpuLocations(); - if (bPostPif) + if (bPostPif) { - m_Reg.m_PROGRAM_COUNTER = 0xA4000040; - - m_Reg.m_GPR[0].DW=0x0000000000000000; - m_Reg.m_GPR[6].DW=0xFFFFFFFFA4001F0C; - m_Reg.m_GPR[7].DW=0xFFFFFFFFA4001F08; - m_Reg.m_GPR[8].DW=0x00000000000000C0; - m_Reg.m_GPR[9].DW=0x0000000000000000; - m_Reg.m_GPR[10].DW=0x0000000000000040; - m_Reg.m_GPR[11].DW=0xFFFFFFFFA4000040; - m_Reg.m_GPR[16].DW=0x0000000000000000; - m_Reg.m_GPR[17].DW=0x0000000000000000; - m_Reg.m_GPR[18].DW=0x0000000000000000; - m_Reg.m_GPR[19].DW=0x0000000000000000; - m_Reg.m_GPR[21].DW=0x0000000000000000; - m_Reg.m_GPR[26].DW=0x0000000000000000; - m_Reg.m_GPR[27].DW=0x0000000000000000; - m_Reg.m_GPR[28].DW=0x0000000000000000; - m_Reg.m_GPR[29].DW=0xFFFFFFFFA4001FF0; - m_Reg.m_GPR[30].DW=0x0000000000000000; - + m_Reg.m_PROGRAM_COUNTER = 0xA4000040; + + m_Reg.m_GPR[0].DW = 0x0000000000000000; + m_Reg.m_GPR[6].DW = 0xFFFFFFFFA4001F0C; + m_Reg.m_GPR[7].DW = 0xFFFFFFFFA4001F08; + m_Reg.m_GPR[8].DW = 0x00000000000000C0; + m_Reg.m_GPR[9].DW = 0x0000000000000000; + m_Reg.m_GPR[10].DW = 0x0000000000000040; + m_Reg.m_GPR[11].DW = 0xFFFFFFFFA4000040; + m_Reg.m_GPR[16].DW = 0x0000000000000000; + m_Reg.m_GPR[17].DW = 0x0000000000000000; + m_Reg.m_GPR[18].DW = 0x0000000000000000; + m_Reg.m_GPR[19].DW = 0x0000000000000000; + m_Reg.m_GPR[21].DW = 0x0000000000000000; + m_Reg.m_GPR[26].DW = 0x0000000000000000; + m_Reg.m_GPR[27].DW = 0x0000000000000000; + m_Reg.m_GPR[28].DW = 0x0000000000000000; + m_Reg.m_GPR[29].DW = 0xFFFFFFFFA4001FF0; + m_Reg.m_GPR[30].DW = 0x0000000000000000; + switch (g_Rom->GetCountry()) { case Germany: case french: case Italian: @@ -754,145 +754,145 @@ void CN64System::InitRegisters( bool bPostPif, CMipsMemory & MMU ) { case CIC_UNKNOWN: case CIC_NUS_6102: - m_Reg.m_GPR[5].DW=0xFFFFFFFFC0F1D859; - m_Reg.m_GPR[14].DW=0x000000002DE108EA; - m_Reg.m_GPR[24].DW=0x0000000000000000; + m_Reg.m_GPR[5].DW = 0xFFFFFFFFC0F1D859; + m_Reg.m_GPR[14].DW = 0x000000002DE108EA; + m_Reg.m_GPR[24].DW = 0x0000000000000000; break; case CIC_NUS_6103: - m_Reg.m_GPR[5].DW=0xFFFFFFFFD4646273; - m_Reg.m_GPR[14].DW=0x000000001AF99984; - m_Reg.m_GPR[24].DW=0x0000000000000000; + m_Reg.m_GPR[5].DW = 0xFFFFFFFFD4646273; + m_Reg.m_GPR[14].DW = 0x000000001AF99984; + m_Reg.m_GPR[24].DW = 0x0000000000000000; break; case CIC_NUS_6105: - MMU.SW_VAddr(0xA4001004,0xBDA807FC); - m_Reg.m_GPR[5].DW=0xFFFFFFFFDECAAAD1; - m_Reg.m_GPR[14].DW=0x000000000CF85C13; - m_Reg.m_GPR[24].DW=0x0000000000000002; + MMU.SW_VAddr(0xA4001004, 0xBDA807FC); + m_Reg.m_GPR[5].DW = 0xFFFFFFFFDECAAAD1; + m_Reg.m_GPR[14].DW = 0x000000000CF85C13; + m_Reg.m_GPR[24].DW = 0x0000000000000002; break; case CIC_NUS_6106: - m_Reg.m_GPR[5].DW=0xFFFFFFFFB04DC903; - m_Reg.m_GPR[14].DW=0x000000001AF99984; - m_Reg.m_GPR[24].DW=0x0000000000000002; + m_Reg.m_GPR[5].DW = 0xFFFFFFFFB04DC903; + m_Reg.m_GPR[14].DW = 0x000000001AF99984; + m_Reg.m_GPR[24].DW = 0x0000000000000002; break; } - m_Reg.m_GPR[20].DW=0x0000000000000000; - m_Reg.m_GPR[23].DW=0x0000000000000006; - m_Reg.m_GPR[31].DW=0xFFFFFFFFA4001554; + m_Reg.m_GPR[20].DW = 0x0000000000000000; + m_Reg.m_GPR[23].DW = 0x0000000000000006; + m_Reg.m_GPR[31].DW = 0xFFFFFFFFA4001554; break; case NTSC_BETA: case X_NTSC: case USA: case Japan: default: - switch (g_Rom->CicChipID()) + switch (g_Rom->CicChipID()) { case CIC_UNKNOWN: case CIC_NUS_6102: - m_Reg.m_GPR[5].DW=0xFFFFFFFFC95973D5; - m_Reg.m_GPR[14].DW=0x000000002449A366; + m_Reg.m_GPR[5].DW = 0xFFFFFFFFC95973D5; + m_Reg.m_GPR[14].DW = 0x000000002449A366; break; case CIC_NUS_6103: - m_Reg.m_GPR[5].DW=0xFFFFFFFF95315A28; - m_Reg.m_GPR[14].DW=0x000000005BACA1DF; + m_Reg.m_GPR[5].DW = 0xFFFFFFFF95315A28; + m_Reg.m_GPR[14].DW = 0x000000005BACA1DF; break; case CIC_NUS_6105: - MMU.SW_VAddr(0xA4001004,0x8DA807FC); - m_Reg.m_GPR[5].DW=0x000000005493FB9A; - m_Reg.m_GPR[14].DW=0xFFFFFFFFC2C20384; + MMU.SW_VAddr(0xA4001004, 0x8DA807FC); + m_Reg.m_GPR[5].DW = 0x000000005493FB9A; + m_Reg.m_GPR[14].DW = 0xFFFFFFFFC2C20384; case CIC_NUS_6106: - m_Reg.m_GPR[5].DW=0xFFFFFFFFE067221F; - m_Reg.m_GPR[14].DW=0x000000005CD2B70F; + m_Reg.m_GPR[5].DW = 0xFFFFFFFFE067221F; + m_Reg.m_GPR[14].DW = 0x000000005CD2B70F; break; } - m_Reg.m_GPR[20].DW=0x0000000000000001; - m_Reg.m_GPR[23].DW=0x0000000000000000; - m_Reg.m_GPR[24].DW=0x0000000000000003; - m_Reg.m_GPR[31].DW=0xFFFFFFFFA4001550; + m_Reg.m_GPR[20].DW = 0x0000000000000001; + m_Reg.m_GPR[23].DW = 0x0000000000000000; + m_Reg.m_GPR[24].DW = 0x0000000000000003; + m_Reg.m_GPR[31].DW = 0xFFFFFFFFA4001550; } switch (g_Rom->CicChipID()) { - case CIC_NUS_6101: - m_Reg.m_GPR[22].DW=0x000000000000003F; + case CIC_NUS_6101: + m_Reg.m_GPR[22].DW = 0x000000000000003F; break; case CIC_NUS_8303: //64DD IPL CIC case CIC_NUS_5167: //64DD CONVERSION CIC - m_Reg.m_GPR[22].DW=0x00000000000000DD; + m_Reg.m_GPR[22].DW = 0x00000000000000DD; break; case CIC_UNKNOWN: - case CIC_NUS_6102: - m_Reg.m_GPR[1].DW=0x0000000000000001; - m_Reg.m_GPR[2].DW=0x000000000EBDA536; - m_Reg.m_GPR[3].DW=0x000000000EBDA536; - m_Reg.m_GPR[4].DW=0x000000000000A536; - m_Reg.m_GPR[12].DW=0xFFFFFFFFED10D0B3; - m_Reg.m_GPR[13].DW=0x000000001402A4CC; - m_Reg.m_GPR[15].DW=0x000000003103E121; - m_Reg.m_GPR[22].DW=0x000000000000003F; - m_Reg.m_GPR[25].DW=0xFFFFFFFF9DEBB54F; + case CIC_NUS_6102: + m_Reg.m_GPR[1].DW = 0x0000000000000001; + m_Reg.m_GPR[2].DW = 0x000000000EBDA536; + m_Reg.m_GPR[3].DW = 0x000000000EBDA536; + m_Reg.m_GPR[4].DW = 0x000000000000A536; + m_Reg.m_GPR[12].DW = 0xFFFFFFFFED10D0B3; + m_Reg.m_GPR[13].DW = 0x000000001402A4CC; + m_Reg.m_GPR[15].DW = 0x000000003103E121; + m_Reg.m_GPR[22].DW = 0x000000000000003F; + m_Reg.m_GPR[25].DW = 0xFFFFFFFF9DEBB54F; break; - case CIC_NUS_6103: - m_Reg.m_GPR[1].DW=0x0000000000000001; - m_Reg.m_GPR[2].DW=0x0000000049A5EE96; - m_Reg.m_GPR[3].DW=0x0000000049A5EE96; - m_Reg.m_GPR[4].DW=0x000000000000EE96; - m_Reg.m_GPR[12].DW=0xFFFFFFFFCE9DFBF7; - m_Reg.m_GPR[13].DW=0xFFFFFFFFCE9DFBF7; - m_Reg.m_GPR[15].DW=0x0000000018B63D28; - m_Reg.m_GPR[22].DW=0x0000000000000078; - m_Reg.m_GPR[25].DW=0xFFFFFFFF825B21C9; + case CIC_NUS_6103: + m_Reg.m_GPR[1].DW = 0x0000000000000001; + m_Reg.m_GPR[2].DW = 0x0000000049A5EE96; + m_Reg.m_GPR[3].DW = 0x0000000049A5EE96; + m_Reg.m_GPR[4].DW = 0x000000000000EE96; + m_Reg.m_GPR[12].DW = 0xFFFFFFFFCE9DFBF7; + m_Reg.m_GPR[13].DW = 0xFFFFFFFFCE9DFBF7; + m_Reg.m_GPR[15].DW = 0x0000000018B63D28; + m_Reg.m_GPR[22].DW = 0x0000000000000078; + m_Reg.m_GPR[25].DW = 0xFFFFFFFF825B21C9; break; - case CIC_NUS_6105: - MMU.SW_VAddr(0xA4001000,0x3C0DBFC0); - MMU.SW_VAddr(0xA4001008,0x25AD07C0); - MMU.SW_VAddr(0xA400100C,0x31080080); - MMU.SW_VAddr(0xA4001010,0x5500FFFC); - MMU.SW_VAddr(0xA4001014,0x3C0DBFC0); - MMU.SW_VAddr(0xA4001018,0x8DA80024); - MMU.SW_VAddr(0xA400101C,0x3C0BB000); - m_Reg.m_GPR[1].DW=0x0000000000000000; - m_Reg.m_GPR[2].DW=0xFFFFFFFFF58B0FBF; - m_Reg.m_GPR[3].DW=0xFFFFFFFFF58B0FBF; - m_Reg.m_GPR[4].DW=0x0000000000000FBF; - m_Reg.m_GPR[12].DW=0xFFFFFFFF9651F81E; - m_Reg.m_GPR[13].DW=0x000000002D42AAC5; - m_Reg.m_GPR[15].DW=0x0000000056584D60; - m_Reg.m_GPR[22].DW=0x0000000000000091; - m_Reg.m_GPR[25].DW=0xFFFFFFFFCDCE565F; + case CIC_NUS_6105: + MMU.SW_VAddr(0xA4001000, 0x3C0DBFC0); + MMU.SW_VAddr(0xA4001008, 0x25AD07C0); + MMU.SW_VAddr(0xA400100C, 0x31080080); + MMU.SW_VAddr(0xA4001010, 0x5500FFFC); + MMU.SW_VAddr(0xA4001014, 0x3C0DBFC0); + MMU.SW_VAddr(0xA4001018, 0x8DA80024); + MMU.SW_VAddr(0xA400101C, 0x3C0BB000); + m_Reg.m_GPR[1].DW = 0x0000000000000000; + m_Reg.m_GPR[2].DW = 0xFFFFFFFFF58B0FBF; + m_Reg.m_GPR[3].DW = 0xFFFFFFFFF58B0FBF; + m_Reg.m_GPR[4].DW = 0x0000000000000FBF; + m_Reg.m_GPR[12].DW = 0xFFFFFFFF9651F81E; + m_Reg.m_GPR[13].DW = 0x000000002D42AAC5; + m_Reg.m_GPR[15].DW = 0x0000000056584D60; + m_Reg.m_GPR[22].DW = 0x0000000000000091; + m_Reg.m_GPR[25].DW = 0xFFFFFFFFCDCE565F; break; - case CIC_NUS_6106: - m_Reg.m_GPR[1].DW=0x0000000000000000; - m_Reg.m_GPR[2].DW=0xFFFFFFFFA95930A4; - m_Reg.m_GPR[3].DW=0xFFFFFFFFA95930A4; - m_Reg.m_GPR[4].DW=0x00000000000030A4; - m_Reg.m_GPR[12].DW=0xFFFFFFFFBCB59510; - m_Reg.m_GPR[13].DW=0xFFFFFFFFBCB59510; - m_Reg.m_GPR[15].DW=0x000000007A3C07F4; - m_Reg.m_GPR[22].DW=0x0000000000000085; - m_Reg.m_GPR[25].DW=0x00000000465E3F72; + case CIC_NUS_6106: + m_Reg.m_GPR[1].DW = 0x0000000000000000; + m_Reg.m_GPR[2].DW = 0xFFFFFFFFA95930A4; + m_Reg.m_GPR[3].DW = 0xFFFFFFFFA95930A4; + m_Reg.m_GPR[4].DW = 0x00000000000030A4; + m_Reg.m_GPR[12].DW = 0xFFFFFFFFBCB59510; + m_Reg.m_GPR[13].DW = 0xFFFFFFFFBCB59510; + m_Reg.m_GPR[15].DW = 0x000000007A3C07F4; + m_Reg.m_GPR[22].DW = 0x0000000000000085; + m_Reg.m_GPR[25].DW = 0x00000000465E3F72; break; } } else { - m_Reg.m_PROGRAM_COUNTER = 0xBFC00000; -/* PIF_Ram[36] = 0x00; PIF_Ram[39] = 0x3F; //common pif ram start values + m_Reg.m_PROGRAM_COUNTER = 0xBFC00000; + /* PIF_Ram[36] = 0x00; PIF_Ram[39] = 0x3F; //common pif ram start values - switch (g_Rom->CicChipID()) { - case CIC_NUS_6101: PIF_Ram[37] = 0x06; PIF_Ram[38] = 0x3F; break; - case CIC_UNKNOWN: - case CIC_NUS_6102: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x3F; break; - case CIC_NUS_6103: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x78; break; - case CIC_NUS_6105: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x91; break; - case CIC_NUS_6106: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x85; break; - }*/ + switch (g_Rom->CicChipID()) { + case CIC_NUS_6101: PIF_Ram[37] = 0x06; PIF_Ram[38] = 0x3F; break; + case CIC_UNKNOWN: + case CIC_NUS_6102: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x3F; break; + case CIC_NUS_6103: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x78; break; + case CIC_NUS_6105: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x91; break; + case CIC_NUS_6106: PIF_Ram[37] = 0x02; PIF_Ram[38] = 0x85; break; + }*/ } } void CN64System::ExecuteCPU() { //reset code - g_Settings->SaveBool(GameRunning_CPU_Running,true); - g_Settings->SaveBool(GameRunning_CPU_Paused,false); - g_Notify->DisplayMessage(5,MSG_EMULATION_STARTED); - + g_Settings->SaveBool(GameRunning_CPU_Running, true); + g_Settings->SaveBool(GameRunning_CPU_Paused, false); + g_Notify->DisplayMessage(5, MSG_EMULATION_STARTED); + m_EndEmulation = false; Notify().RefreshMenu(); @@ -907,14 +907,14 @@ void CN64System::ExecuteCPU() switch ((CPU_TYPE)g_Settings->LoadDword(Game_CpuType)) { -// Currently the compiler is 32-bit only. We might have to ignore that RDB setting for now. + // Currently the compiler is 32-bit only. We might have to ignore that RDB setting for now. #ifndef _WIN64 case CPU_Recompiler: ExecuteRecompiler(); break; case CPU_SyncCores: ExecuteSyncCPU(); break; #endif default: ExecuteInterpret(); break; } - g_Settings->SaveBool(GameRunning_CPU_Running,(DWORD)false); + g_Settings->SaveBool(GameRunning_CPU_Running, (DWORD)false); Notify().WindowMode(); m_Plugins->RomClosed(); if (m_SyncCPU) @@ -930,7 +930,7 @@ void CN64System::ExecuteInterpret() } void CN64System::ExecuteRecompiler() -{ +{ m_Recomp->Run(); } @@ -942,7 +942,7 @@ void CN64System::ExecuteSyncCPU() void CN64System::CpuStopped() { - g_Settings->SaveBool(GameRunning_CPU_Running,(DWORD)false); + g_Settings->SaveBool(GameRunning_CPU_Running, (DWORD)false); Notify().WindowMode(); if (!m_InReset) { @@ -954,11 +954,11 @@ void CN64System::CpuStopped() Notify().RefreshMenu(); Notify().MakeWindowOnTop(false); - g_Notify->DisplayMessage(5,MSG_EMULATION_ENDED); + g_Notify->DisplayMessage(5, MSG_EMULATION_ENDED); if (g_Settings->LoadDword(RomBrowser_Enabled)) { Notify().ShowRomBrowser(); - } + } } if (m_SyncCPU) { @@ -966,30 +966,30 @@ void CN64System::CpuStopped() } } -void CN64System::UpdateSyncCPU (CN64System * const SecondCPU, DWORD const Cycles) +void CN64System::UpdateSyncCPU(CN64System * const SecondCPU, DWORD const Cycles) { int CyclesToExecute = Cycles - m_CyclesToSkip; - + //Update the number of cycles to skip m_CyclesToSkip -= Cycles; if (m_CyclesToSkip < 0) { m_CyclesToSkip = 0; } //Run the other CPU For the same amount of cycles if (CyclesToExecute < 0) { return; } - + SecondCPU->SetActiveSystem(true); - + CInterpreterCPU::ExecuteOps(Cycles); SetActiveSystem(true); } -void CN64System::SyncCPUPC (CN64System * const SecondCPU) +void CN64System::SyncCPUPC(CN64System * const SecondCPU) { bool ErrorFound = false; g_SystemTimer->UpdateTimers(); - if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) + if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) { ErrorFound = true; } @@ -1000,33 +1000,33 @@ void CN64System::SyncCPUPC (CN64System * const SecondCPU) if (ErrorFound) { DumpSyncErrors(SecondCPU); } - for (int i = (sizeof(m_LastSuccessSyncPC)/sizeof(m_LastSuccessSyncPC[0])) - 1; i > 0; i--) + for (int i = (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])) - 1; i > 0; i--) { m_LastSuccessSyncPC[i] = m_LastSuccessSyncPC[i - 1]; } m_LastSuccessSyncPC[0] = m_Reg.m_PROGRAM_COUNTER; } -void CN64System::SyncCPU (CN64System * const SecondCPU) +void CN64System::SyncCPU(CN64System * const SecondCPU) { bool ErrorFound = false; m_SyncCount += 1; //WriteTraceF(TraceError,"SyncCPU PC = %08X",m_Reg.m_PROGRAM_COUNTER); g_SystemTimer->UpdateTimers(); - + #ifdef TEST_SP_TRACKING if (m_CurrentSP != GPR[29].UW[0]) { ErrorFound = true; } #endif - if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) + if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) { ErrorFound = true; } if (b32BitCore()) { - for (int count = 0; count < 32; count ++) + for (int count = 0; count < 32; count++) { if (m_Reg.m_GPR[count].W[0] != SecondCPU->m_Reg.m_GPR[count].W[0]) { @@ -1044,13 +1044,13 @@ void CN64System::SyncCPU (CN64System * const SecondCPU) } else { - for (int count = 0; count < 32; count ++) + for (int count = 0; count < 32; count++) { if (m_Reg.m_GPR[count].DW != SecondCPU->m_Reg.m_GPR[count].DW) { ErrorFound = true; } - if (m_Reg.m_FPR[count].DW != SecondCPU->m_Reg.m_FPR[count].DW) + if (m_Reg.m_FPR[count].DW != SecondCPU->m_Reg.m_FPR[count].DW) { ErrorFound = true; } @@ -1060,7 +1060,7 @@ void CN64System::SyncCPU (CN64System * const SecondCPU) } } } - + if (m_TLB != SecondCPU->m_TLB) { ErrorFound = true; } if (m_Reg.m_FPCR[0] != SecondCPU->m_Reg.m_FPCR[0]) { ErrorFound = true; } if (m_Reg.m_FPCR[31] != SecondCPU->m_Reg.m_FPCR[31]) { ErrorFound = true; } @@ -1068,30 +1068,30 @@ void CN64System::SyncCPU (CN64System * const SecondCPU) if (m_Reg.m_LO.DW != SecondCPU->m_Reg.m_LO.DW) { ErrorFound = true; } /*if (m_SyncCount > 4788000) { - if (memcmp(m_MMU_VM.Rdram(),SecondCPU->m_MMU_VM.Rdram(),RdramSize()) != 0) - { - ErrorFound = true; - } - } - if (memcmp(m_MMU_VM.Imem(),SecondCPU->m_MMU_VM.Imem(),0x1000) != 0) + if (memcmp(m_MMU_VM.Rdram(),SecondCPU->m_MMU_VM.Rdram(),RdramSize()) != 0) { - ErrorFound = true; + ErrorFound = true; } - if (memcmp(m_MMU_VM.Dmem(),SecondCPU->m_MMU_VM.Dmem(),0x1000) != 0) + } + if (memcmp(m_MMU_VM.Imem(),SecondCPU->m_MMU_VM.Imem(),0x1000) != 0) { - ErrorFound = true; + ErrorFound = true; + } + if (memcmp(m_MMU_VM.Dmem(),SecondCPU->m_MMU_VM.Dmem(),0x1000) != 0) + { + ErrorFound = true; }*/ /*for (int z = 0; z < 0x100; z++) - { - if (m_MMU_VM.Rdram()[0x00206970 + z] != SecondCPU->m_MMU_VM.Rdram()[0x00206970 + z]) - { - ErrorFound = true; - break; - } + { + if (m_MMU_VM.Rdram()[0x00206970 + z] != SecondCPU->m_MMU_VM.Rdram()[0x00206970 + z]) + { + ErrorFound = true; + break; + } }*/ - - if (bFastSP() && m_Recomp) + + if (bFastSP() && m_Recomp) { if (m_Recomp->MemoryStackPos() != (DWORD)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))) { @@ -1102,8 +1102,8 @@ void CN64System::SyncCPU (CN64System * const SecondCPU) if (m_SystemTimer != SecondCPU->m_SystemTimer) { ErrorFound = true; } if (m_NextTimer != SecondCPU->m_NextTimer) { ErrorFound = true; } if (m_Reg.m_RoundingModel != SecondCPU->m_Reg.m_RoundingModel) { ErrorFound = true; } - - for (int i = 0, n = sizeof(m_Reg.m_Mips_Interface) / sizeof(m_Reg.m_Mips_Interface[0]); i < n; i ++) + + for (int i = 0, n = sizeof(m_Reg.m_Mips_Interface) / sizeof(m_Reg.m_Mips_Interface[0]); i < n; i++) { if (m_Reg.m_Mips_Interface[i] != SecondCPU->m_Reg.m_Mips_Interface[i]) { @@ -1111,7 +1111,7 @@ void CN64System::SyncCPU (CN64System * const SecondCPU) } } - for (int i = 0, n = sizeof(m_Reg.m_SigProcessor_Interface) / sizeof(m_Reg.m_SigProcessor_Interface[0]); i < n; i ++) + for (int i = 0, n = sizeof(m_Reg.m_SigProcessor_Interface) / sizeof(m_Reg.m_SigProcessor_Interface[0]); i < n; i++) { if (m_Reg.m_SigProcessor_Interface[i] != SecondCPU->m_Reg.m_SigProcessor_Interface[i]) { @@ -1119,24 +1119,24 @@ void CN64System::SyncCPU (CN64System * const SecondCPU) } } - for (int i = 0, n = sizeof(m_Reg.m_Display_ControlReg) / sizeof(m_Reg.m_Display_ControlReg[0]); i < n; i ++) + for (int i = 0, n = sizeof(m_Reg.m_Display_ControlReg) / sizeof(m_Reg.m_Display_ControlReg[0]); i < n; i++) { if (m_Reg.m_Display_ControlReg[i] != SecondCPU->m_Reg.m_Display_ControlReg[i]) { ErrorFound = true; } } - + if (ErrorFound) { DumpSyncErrors(SecondCPU); } - for (int i = (sizeof(m_LastSuccessSyncPC)/sizeof(m_LastSuccessSyncPC[0])) - 1; i > 0; i--) + for (int i = (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])) - 1; i > 0; i--) { m_LastSuccessSyncPC[i] = m_LastSuccessSyncPC[i - 1]; } m_LastSuccessSyncPC[0] = m_Reg.m_PROGRAM_COUNTER; -// if (PROGRAM_COUNTER == 0x8009BBD8) { -// g_Notify->BreakPoint(__FILEW__,__LINE__); -// } + // if (PROGRAM_COUNTER == 0x8009BBD8) { + // g_Notify->BreakPoint(__FILEW__,__LINE__); + // } } void CN64System::SyncSystem() @@ -1149,12 +1149,12 @@ void CN64System::SyncSystemPC() SyncCPUPC(g_SyncSystem); } -void CN64System::DumpSyncErrors (CN64System * SecondCPU) +void CN64System::DumpSyncErrors(CN64System * SecondCPU) { int count; - + { - CPath ErrorFile (CPath::MODULE_DIRECTORY); + CPath ErrorFile(CPath::MODULE_DIRECTORY); ErrorFile.AppendDirectory("Logs"); ErrorFile.SetNameExtension("Sync Errors.txt"); @@ -1162,190 +1162,190 @@ void CN64System::DumpSyncErrors (CN64System * SecondCPU) Error.Open(ErrorFile); Error.Log("Errors:\r\n"); Error.Log("Register, Recompiler, Interpter\r\n"); - #ifdef TEST_SP_TRACKING +#ifdef TEST_SP_TRACKING if (m_CurrentSP != GPR[29].UW[0]) { Error.Log("m_CurrentSP,%X,%X\r\n",m_CurrentSP,GPR[29].UW[0]); } - #endif +#endif if (m_Reg.m_PROGRAM_COUNTER != SecondCPU->m_Reg.m_PROGRAM_COUNTER) { - Error.LogF("PROGRAM_COUNTER 0x%X, 0x%X\r\n",m_Reg.m_PROGRAM_COUNTER,SecondCPU->m_Reg.m_PROGRAM_COUNTER); + Error.LogF("PROGRAM_COUNTER 0x%X, 0x%X\r\n", m_Reg.m_PROGRAM_COUNTER, SecondCPU->m_Reg.m_PROGRAM_COUNTER); } if (b32BitCore()) { - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { if (m_Reg.m_GPR[count].UW[0] != SecondCPU->m_Reg.m_GPR[count].UW[0]) { - Error.LogF("GPR[%s] 0x%08X%08X, 0x%08X%08X\r\n",CRegName::GPR[count], - m_Reg.m_GPR[count].W[1],m_Reg.m_GPR[count].W[0], - SecondCPU->m_Reg.m_GPR[count].W[1],SecondCPU->m_Reg.m_GPR[count].W[0]); + Error.LogF("GPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count], + m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0], + SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]); } } } - else + else { - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { if (m_Reg.m_GPR[count].DW != SecondCPU->m_Reg.m_GPR[count].DW) { - Error.LogF("GPR[%s] 0x%08X%08X, 0x%08X%08X\r\n",CRegName::GPR[count], - m_Reg.m_GPR[count].W[1],m_Reg.m_GPR[count].W[0], - SecondCPU->m_Reg.m_GPR[count].W[1],SecondCPU->m_Reg.m_GPR[count].W[0]); + Error.LogF("GPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count], + m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0], + SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]); } } } - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { if (m_Reg.m_FPR[count].DW != SecondCPU->m_Reg.m_FPR[count].DW) { - Error.LogF("FPR[%s] 0x%08X%08X, 0x%08X%08X\r\n",CRegName::FPR[count], - m_Reg.m_FPR[count].W[1],m_Reg.m_FPR[count].W[0], - SecondCPU->m_Reg.m_FPR[count].W[1],SecondCPU->m_Reg.m_FPR[count].W[0]); + Error.LogF("FPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::FPR[count], + m_Reg.m_FPR[count].W[1], m_Reg.m_FPR[count].W[0], + SecondCPU->m_Reg.m_FPR[count].W[1], SecondCPU->m_Reg.m_FPR[count].W[0]); } - } - for (count = 0; count < 32; count ++) + } + for (count = 0; count < 32; count++) { if (m_Reg.m_FPCR[count] != SecondCPU->m_Reg.m_FPCR[count]) { - Error.LogF("FPCR[%s] 0x%08X, 0x%08X\r\n",CRegName::FPR_Ctrl[count], + Error.LogF("FPCR[%s] 0x%08X, 0x%08X\r\n", CRegName::FPR_Ctrl[count], m_Reg.m_FPCR[count], SecondCPU->m_Reg.m_FPCR[count]); } - } - for (count = 0; count < 32; count ++) + } + for (count = 0; count < 32; count++) { if (m_Reg.m_CP0[count] != SecondCPU->m_Reg.m_CP0[count]) { - Error.LogF("CP0[%s] 0x%08X, 0x%08X\r\n",CRegName::Cop0[count], + Error.LogF("CP0[%s] 0x%08X, 0x%08X\r\n", CRegName::Cop0[count], m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]); } - } - if (m_Reg.m_HI.DW != SecondCPU->m_Reg.m_HI.DW) + } + if (m_Reg.m_HI.DW != SecondCPU->m_Reg.m_HI.DW) { - Error.LogF("HI Reg 0x%08X%08X, 0x%08X%08X\r\n",m_Reg.m_HI.UW[1],m_Reg.m_HI.UW[0],SecondCPU->m_Reg.m_HI.UW[1],SecondCPU->m_Reg.m_HI.UW[0]); + Error.LogF("HI Reg 0x%08X%08X, 0x%08X%08X\r\n", m_Reg.m_HI.UW[1], m_Reg.m_HI.UW[0], SecondCPU->m_Reg.m_HI.UW[1], SecondCPU->m_Reg.m_HI.UW[0]); } if (m_Reg.m_LO.DW != SecondCPU->m_Reg.m_LO.DW) { - Error.LogF("LO Reg 0x%08X%08X, 0x%08X%08X\r\n",m_Reg.m_LO.UW[1],m_Reg.m_LO.UW[0], SecondCPU->m_Reg.m_LO.UW[1],SecondCPU->m_Reg.m_LO.UW[0]); + Error.LogF("LO Reg 0x%08X%08X, 0x%08X%08X\r\n", m_Reg.m_LO.UW[1], m_Reg.m_LO.UW[0], SecondCPU->m_Reg.m_LO.UW[1], SecondCPU->m_Reg.m_LO.UW[0]); } - for (int i = 0, n = sizeof(m_Reg.m_Mips_Interface) / sizeof(m_Reg.m_Mips_Interface[0]); i < n; i ++) + for (int i = 0, n = sizeof(m_Reg.m_Mips_Interface) / sizeof(m_Reg.m_Mips_Interface[0]); i < n; i++) { if (m_Reg.m_Mips_Interface[i] != SecondCPU->m_Reg.m_Mips_Interface[i]) { - Error.LogF("Mips_Interface[%d] 0x%08X, 0x%08X\r\n",i, m_Reg.m_Mips_Interface[i], SecondCPU->m_Reg.m_Mips_Interface[i]); + Error.LogF("Mips_Interface[%d] 0x%08X, 0x%08X\r\n", i, m_Reg.m_Mips_Interface[i], SecondCPU->m_Reg.m_Mips_Interface[i]); } } - for (int i = 0, n = sizeof(m_Reg.m_SigProcessor_Interface) / sizeof(m_Reg.m_SigProcessor_Interface[0]); i < n; i ++) + for (int i = 0, n = sizeof(m_Reg.m_SigProcessor_Interface) / sizeof(m_Reg.m_SigProcessor_Interface[0]); i < n; i++) { if (m_Reg.m_SigProcessor_Interface[i] != SecondCPU->m_Reg.m_SigProcessor_Interface[i]) { - Error.LogF("SigProcessor_Interface[%d] 0x%08X, 0x%08X\r\n",i, m_Reg.m_SigProcessor_Interface[i], SecondCPU->m_Reg.m_SigProcessor_Interface[i]); + Error.LogF("SigProcessor_Interface[%d] 0x%08X, 0x%08X\r\n", i, m_Reg.m_SigProcessor_Interface[i], SecondCPU->m_Reg.m_SigProcessor_Interface[i]); } } - for (int i = 0, n = sizeof(m_Reg.m_Display_ControlReg) / sizeof(m_Reg.m_Display_ControlReg[0]); i < n; i ++) + for (int i = 0, n = sizeof(m_Reg.m_Display_ControlReg) / sizeof(m_Reg.m_Display_ControlReg[0]); i < n; i++) { if (m_Reg.m_Display_ControlReg[i] != SecondCPU->m_Reg.m_Display_ControlReg[i]) { - Error.LogF("Display_ControlReg[%d] 0x%08X, 0x%08X\r\n",i, m_Reg.m_Display_ControlReg[i], SecondCPU->m_Reg.m_Display_ControlReg[i]); + Error.LogF("Display_ControlReg[%d] 0x%08X, 0x%08X\r\n", i, m_Reg.m_Display_ControlReg[i], SecondCPU->m_Reg.m_Display_ControlReg[i]); } } - if (m_NextTimer != SecondCPU->m_NextTimer) - { - Error.LogF("Current Time: %X %X\r\n",(DWORD)m_NextTimer,(DWORD)SecondCPU->m_NextTimer); + if (m_NextTimer != SecondCPU->m_NextTimer) + { + Error.LogF("Current Time: %X %X\r\n", (DWORD)m_NextTimer, (DWORD)SecondCPU->m_NextTimer); } - m_TLB.RecordDifference(Error,SecondCPU->m_TLB); - m_SystemTimer.RecordDifference(Error,SecondCPU->m_SystemTimer); - if (m_Reg.m_RoundingModel != SecondCPU->m_Reg.m_RoundingModel) - { - Error.LogF("RoundingModel: %X %X\r\n",m_Reg.m_RoundingModel,SecondCPU->m_Reg.m_RoundingModel); + m_TLB.RecordDifference(Error, SecondCPU->m_TLB); + m_SystemTimer.RecordDifference(Error, SecondCPU->m_SystemTimer); + if (m_Reg.m_RoundingModel != SecondCPU->m_Reg.m_RoundingModel) + { + Error.LogF("RoundingModel: %X %X\r\n", m_Reg.m_RoundingModel, SecondCPU->m_Reg.m_RoundingModel); } - if (bFastSP() && m_Recomp) + if (bFastSP() && m_Recomp) { if (m_Recomp->MemoryStackPos() != (DWORD)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))) { - Error.LogF("MemoryStack = %X should be: %X\r\n",m_Recomp->MemoryStackPos(), (DWORD)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))); + Error.LogF("MemoryStack = %X should be: %X\r\n", m_Recomp->MemoryStackPos(), (DWORD)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))); } } - DWORD * Rdram = (DWORD *)m_MMU_VM.Rdram(), * Rdram2 = (DWORD *)SecondCPU->m_MMU_VM.Rdram(); - for (int z = 0, n = (RdramSize() >> 2); z < n; z ++) - { - if (Rdram[z] != Rdram2[z]) + DWORD * Rdram = (DWORD *)m_MMU_VM.Rdram(), *Rdram2 = (DWORD *)SecondCPU->m_MMU_VM.Rdram(); + for (int z = 0, n = (RdramSize() >> 2); z < n; z++) + { + if (Rdram[z] != Rdram2[z]) { - Error.LogF("Rdram[%X]: %X %X\r\n",z << 2,Rdram[z],Rdram2[z]); + Error.LogF("Rdram[%X]: %X %X\r\n", z << 2, Rdram[z], Rdram2[z]); } } - DWORD * Imem = (DWORD *)m_MMU_VM.Imem(), * Imem2 = (DWORD *)SecondCPU->m_MMU_VM.Imem(); - for (int z = 0; z < (0x1000 >> 2); z ++) - { - if (Imem[z] != Imem2[z]) + DWORD * Imem = (DWORD *)m_MMU_VM.Imem(), *Imem2 = (DWORD *)SecondCPU->m_MMU_VM.Imem(); + for (int z = 0; z < (0x1000 >> 2); z++) + { + if (Imem[z] != Imem2[z]) { - Error.LogF("Imem[%X]: %X %X\r\n",z << 2,Imem[z],Imem2[z]); + Error.LogF("Imem[%X]: %X %X\r\n", z << 2, Imem[z], Imem2[z]); } } - DWORD * Dmem = (DWORD *)m_MMU_VM.Dmem(), * Dmem2 = (DWORD *)SecondCPU->m_MMU_VM.Dmem(); - for (int z = 0; z < (0x1000 >> 2); z ++) - { - if (Dmem[z] != Dmem2[z]) + DWORD * Dmem = (DWORD *)m_MMU_VM.Dmem(), *Dmem2 = (DWORD *)SecondCPU->m_MMU_VM.Dmem(); + for (int z = 0; z < (0x1000 >> 2); z++) + { + if (Dmem[z] != Dmem2[z]) { - Error.LogF("Dmem[%X]: %X %X\r\n",z << 2,Dmem[z],Dmem2[z]); + Error.LogF("Dmem[%X]: %X %X\r\n", z << 2, Dmem[z], Dmem2[z]); } } Error.Log("\r\n"); Error.Log("Information:\r\n"); Error.Log("\r\n"); - Error.LogF("PROGRAM_COUNTER,0x%X\r\n",m_Reg.m_PROGRAM_COUNTER); - Error.LogF("Current Timer,0x%X\r\n",m_NextTimer); - Error.LogF("Timer Type,0x%X\r\n",m_SystemTimer.CurrentType()); + Error.LogF("PROGRAM_COUNTER,0x%X\r\n", m_Reg.m_PROGRAM_COUNTER); + Error.LogF("Current Timer,0x%X\r\n", m_NextTimer); + Error.LogF("Timer Type,0x%X\r\n", m_SystemTimer.CurrentType()); Error.Log("\r\n"); - for (int i = 0; i < (sizeof(m_LastSuccessSyncPC)/sizeof(m_LastSuccessSyncPC[0])); i++) + for (int i = 0; i < (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])); i++) { - Error.LogF("LastSuccessSyncPC[%d],0x%X\r\n",i,m_LastSuccessSyncPC[i]); + Error.LogF("LastSuccessSyncPC[%d],0x%X\r\n", i, m_LastSuccessSyncPC[i]); } Error.Log("\r\n"); - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { - Error.LogF("GPR[%s], 0x%08X%08X, 0x%08X%08X\r\n",CRegName::GPR[count], - m_Reg.m_GPR[count].W[1],m_Reg.m_GPR[count].W[0], - SecondCPU->m_Reg.m_GPR[count].W[1],SecondCPU->m_Reg.m_GPR[count].W[0]); - } + Error.LogF("GPR[%s], 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count], + m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0], + SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]); + } Error.Log("\r\n"); - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { - Error.LogF("FPR[%s],%*s0x%08X%08X, 0x%08X%08X\r\n",CRegName::FPR[count], - count < 10 ? 9 : 8," ",m_Reg.m_FPR[count].W[1],m_Reg.m_FPR[count].W[0], - SecondCPU->m_Reg.m_FPR[count].W[1],SecondCPU->m_Reg.m_FPR[count].W[0]); - } + Error.LogF("FPR[%s],%*s0x%08X%08X, 0x%08X%08X\r\n", CRegName::FPR[count], + count < 10 ? 9 : 8, " ", m_Reg.m_FPR[count].W[1], m_Reg.m_FPR[count].W[0], + SecondCPU->m_Reg.m_FPR[count].W[1], SecondCPU->m_Reg.m_FPR[count].W[0]); + } Error.Log("\r\n"); - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { - Error.LogF("FPR_S[%s],%*s%f, %f\r\n",CRegName::FPR[count], - count < 10 ? 7 : 6," ",*(m_Reg.m_FPR_S[count]),*(SecondCPU->m_Reg.m_FPR_S[count])); - } + Error.LogF("FPR_S[%s],%*s%f, %f\r\n", CRegName::FPR[count], + count < 10 ? 7 : 6, " ", *(m_Reg.m_FPR_S[count]), *(SecondCPU->m_Reg.m_FPR_S[count])); + } Error.Log("\r\n"); - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { - Error.LogF("FPR_D[%s],%*s%f, %f\r\n",CRegName::FPR[count], - count < 10 ? 7 : 6," ",*(m_Reg.m_FPR_D[count]),*(SecondCPU->m_Reg.m_FPR_D[count])); - } + Error.LogF("FPR_D[%s],%*s%f, %f\r\n", CRegName::FPR[count], + count < 10 ? 7 : 6, " ", *(m_Reg.m_FPR_D[count]), *(SecondCPU->m_Reg.m_FPR_D[count])); + } Error.Log("\r\n"); - Error.LogF("Rounding Model, 0x%08X, 0x%08X\r\n",m_Reg.m_RoundingModel,SecondCPU->m_Reg.m_RoundingModel); + Error.LogF("Rounding Model, 0x%08X, 0x%08X\r\n", m_Reg.m_RoundingModel, SecondCPU->m_Reg.m_RoundingModel); Error.Log("\r\n"); - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { - Error.LogF("CP0[%s],%*s0x%08X, 0x%08X\r\n",CRegName::Cop0[count], - 12 - strlen(CRegName::Cop0[count]),"", - m_Reg.m_CP0[count],SecondCPU->m_Reg.m_CP0[count]); - } + Error.LogF("CP0[%s],%*s0x%08X, 0x%08X\r\n", CRegName::Cop0[count], + 12 - strlen(CRegName::Cop0[count]), "", + m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]); + } Error.Log("\r\n"); - Error.LogF("HI 0x%08X%08X, 0x%08X%08X\r\n",m_Reg.m_HI.UW[1],m_Reg.m_HI.UW[0], - SecondCPU->m_Reg.m_HI.UW[1],SecondCPU->m_Reg.m_HI.UW[0]); - Error.LogF("LO 0x%08X%08X, 0x%08X%08X\r\n",m_Reg.m_LO.UW[1],m_Reg.m_LO.UW[0], - SecondCPU->m_Reg.m_LO.UW[1],SecondCPU->m_Reg.m_LO.UW[0]); + Error.LogF("HI 0x%08X%08X, 0x%08X%08X\r\n", m_Reg.m_HI.UW[1], m_Reg.m_HI.UW[0], + SecondCPU->m_Reg.m_HI.UW[1], SecondCPU->m_Reg.m_HI.UW[0]); + Error.LogF("LO 0x%08X%08X, 0x%08X%08X\r\n", m_Reg.m_LO.UW[1], m_Reg.m_LO.UW[0], + SecondCPU->m_Reg.m_LO.UW[1], SecondCPU->m_Reg.m_LO.UW[0]); bool bHasTlb = false; - for (count = 0; count < 32; count ++) + for (count = 0; count < 32; count++) { if (!m_TLB.TlbEntry(count).EntryDefined) { continue; } if (!bHasTlb) @@ -1355,74 +1355,72 @@ void CN64System::DumpSyncErrors (CN64System * SecondCPU) bHasTlb = true; } Error.LogF("TLB[%2d], %08X, %08X, %08X, %08X\r\n", count, - m_TLB.TlbEntry(count).EntryHi.Value,m_TLB.TlbEntry(count).PageMask.Value, - SecondCPU->m_TLB.TlbEntry(count).EntryHi.Value,SecondCPU->m_TLB.TlbEntry(count).PageMask.Value - ); + m_TLB.TlbEntry(count).EntryHi.Value, m_TLB.TlbEntry(count).PageMask.Value, + SecondCPU->m_TLB.TlbEntry(count).EntryHi.Value, SecondCPU->m_TLB.TlbEntry(count).PageMask.Value + ); } Error.Log("\r\n"); Error.Log("Code at PC:\r\n"); for (count = -10; count < 10; count++) { DWORD OpcodeValue, Addr = m_Reg.m_PROGRAM_COUNTER + (count << 2); - if (g_MMU->LW_VAddr(Addr,(uint32_t &)OpcodeValue)) + if (g_MMU->LW_VAddr(Addr, (uint32_t &)OpcodeValue)) { - Error.LogF("%X: %s\r\n",Addr,R4300iOpcodeName(OpcodeValue,Addr)); + Error.LogF("%X: %s\r\n", Addr, R4300iOpcodeName(OpcodeValue, Addr)); } - } Error.Log("\r\n"); Error.Log("Code at Last Sync PC:\r\n"); for (count = 0; count < 50; count++) { DWORD OpcodeValue, Addr = m_LastSuccessSyncPC[0] + (count << 2); - if (g_MMU->LW_VAddr(Addr,(uint32_t &)OpcodeValue)) + if (g_MMU->LW_VAddr(Addr, (uint32_t &)OpcodeValue)) { - Error.LogF("%X: %s\r\n",Addr,R4300iOpcodeName(OpcodeValue,Addr)); + Error.LogF("%X: %s\r\n", Addr, R4300iOpcodeName(OpcodeValue, Addr)); } - } } g_Notify->DisplayError(L"Sync Error"); - g_Notify->BreakPoint(__FILEW__,__LINE__); + g_Notify->BreakPoint(__FILEW__, __LINE__); } bool CN64System::SaveState() { - WriteTrace(TraceDebug,__FUNCTION__ ": Start"); + WriteTrace(TraceDebug, __FUNCTION__ ": Start"); -// if (!m_SystemTimer.SaveAllowed()) { return false; } + // if (!m_SystemTimer.SaveAllowed()) { return false; } if ((m_Reg.STATUS_REGISTER & STATUS_EXL) != 0) { return false; } - + //Get the file Name stdstr FileName, ExtraInfoFileName, CurrentSaveName = g_Settings->LoadStringVal(GameRunning_InstantSaveFile); if (CurrentSaveName.empty()) { int Slot = g_Settings->LoadDword(Game_CurrentSaveState); - if (Slot != 0) - { - CurrentSaveName.Format("%s.pj%d",g_Settings->LoadStringVal(Game_GoodName).c_str(), Slot); - } - else + if (Slot != 0) { - CurrentSaveName.Format("%s.pj",g_Settings->LoadStringVal(Game_GoodName).c_str()); + CurrentSaveName.Format("%s.pj%d", g_Settings->LoadStringVal(Game_GoodName).c_str(), Slot); } - FileName.Format("%s%s",g_Settings->LoadStringVal(Directory_InstantSave).c_str(),CurrentSaveName.c_str()); - stdstr_f ZipFileName("%s.zip",FileName.c_str()); - //Make sure the target dir exists - CreateDirectory(g_Settings->LoadStringVal(Directory_InstantSave).c_str(),NULL); + else + { + CurrentSaveName.Format("%s.pj", g_Settings->LoadStringVal(Game_GoodName).c_str()); + } + FileName.Format("%s%s", g_Settings->LoadStringVal(Directory_InstantSave).c_str(), CurrentSaveName.c_str()); + stdstr_f ZipFileName("%s.zip", FileName.c_str()); + //Make sure the target dir exists + CreateDirectory(g_Settings->LoadStringVal(Directory_InstantSave).c_str(), NULL); //delete any old save DeleteFile(FileName.c_str()); DeleteFile(ZipFileName.c_str()); - ExtraInfoFileName.Format("%s.dat",CurrentSaveName.c_str()); - + ExtraInfoFileName.Format("%s.dat", CurrentSaveName.c_str()); + //If ziping save add .zip on the end if (g_Settings->LoadDword(Setting_AutoZipInstantSave)) { FileName = ZipFileName; } - g_Settings->SaveDword(Game_LastSaveSlot,g_Settings->LoadDword(Game_CurrentSaveState)); - } + g_Settings->SaveDword(Game_LastSaveSlot, g_Settings->LoadDword(Game_CurrentSaveState)); + } else { char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; @@ -1442,63 +1440,63 @@ bool CN64System::SaveState() if (FileName.empty()) { return true; } //Open the file - if (g_Settings->LoadDword(Game_FuncLookupMode) == FuncFind_ChangeMemory) + if (g_Settings->LoadDword(Game_FuncLookupMode) == FuncFind_ChangeMemory) { if (m_Recomp) { - m_Recomp->ResetRecompCode(true); + m_Recomp->ResetRecompCode(true); } } DWORD dwWritten, SaveID_0 = 0x23D8A6C8, SaveID_1 = 0x56D2CD23; - DWORD RdramSize = g_Settings->LoadDword(Game_RDRamSize); - DWORD MiInterReg = g_Reg->MI_INTR_REG; + DWORD RdramSize = g_Settings->LoadDword(Game_RDRamSize); + DWORD MiInterReg = g_Reg->MI_INTR_REG; DWORD NextViTimer = m_SystemTimer.GetTimer(CSystemTimer::ViTimer); if (g_Settings->LoadDword(Setting_AutoZipInstantSave)) { zipFile file; - file = zipOpen(FileName.c_str(),0); - zipOpenNewFileInZip(file,CurrentSaveName.c_str(),NULL,NULL,0,NULL,0,NULL,Z_DEFLATED,Z_DEFAULT_COMPRESSION); - zipWriteInFileInZip(file,&SaveID_0,sizeof(SaveID_0)); - zipWriteInFileInZip(file,&RdramSize,sizeof(DWORD)); - zipWriteInFileInZip(file,g_Rom->GetRomAddress(),0x40); - zipWriteInFileInZip(file,&NextViTimer,sizeof(DWORD)); - zipWriteInFileInZip(file,&m_Reg.m_PROGRAM_COUNTER,sizeof(m_Reg.m_PROGRAM_COUNTER)); - zipWriteInFileInZip(file,m_Reg.m_GPR,sizeof(__int64)*32); - zipWriteInFileInZip(file,m_Reg.m_FPR,sizeof(__int64)*32); - zipWriteInFileInZip(file,m_Reg.m_CP0,sizeof(DWORD)*32); - zipWriteInFileInZip(file,m_Reg.m_FPCR,sizeof(DWORD)*32); - zipWriteInFileInZip(file,&m_Reg.m_HI,sizeof(__int64)); - zipWriteInFileInZip(file,&m_Reg.m_LO,sizeof(__int64)); - zipWriteInFileInZip(file,m_Reg.m_RDRAM_Registers,sizeof(DWORD)*10); - zipWriteInFileInZip(file,m_Reg.m_SigProcessor_Interface,sizeof(DWORD)*10); - zipWriteInFileInZip(file,m_Reg.m_Display_ControlReg,sizeof(DWORD)*10); - zipWriteInFileInZip(file,m_Reg.m_Mips_Interface,sizeof(DWORD)*4); - zipWriteInFileInZip(file,m_Reg.m_Video_Interface,sizeof(DWORD)*14); - zipWriteInFileInZip(file,m_Reg.m_Audio_Interface,sizeof(DWORD)*6); - zipWriteInFileInZip(file,m_Reg.m_Peripheral_Interface,sizeof(DWORD)*13); - zipWriteInFileInZip(file,m_Reg.m_RDRAM_Interface,sizeof(DWORD)*8); - zipWriteInFileInZip(file,m_Reg.m_SerialInterface,sizeof(DWORD)*4); - zipWriteInFileInZip(file,(void *const)&m_TLB.TlbEntry(0),sizeof(CTLB::TLB_ENTRY)*32); - zipWriteInFileInZip(file,m_MMU_VM.PifRam(),0x40); - zipWriteInFileInZip(file,m_MMU_VM.Rdram(),RdramSize); - zipWriteInFileInZip(file,m_MMU_VM.Dmem(),0x1000); - zipWriteInFileInZip(file,m_MMU_VM.Imem(),0x1000); + file = zipOpen(FileName.c_str(), 0); + zipOpenNewFileInZip(file, CurrentSaveName.c_str(), NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION); + zipWriteInFileInZip(file, &SaveID_0, sizeof(SaveID_0)); + zipWriteInFileInZip(file, &RdramSize, sizeof(DWORD)); + zipWriteInFileInZip(file, g_Rom->GetRomAddress(), 0x40); + zipWriteInFileInZip(file, &NextViTimer, sizeof(DWORD)); + zipWriteInFileInZip(file, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER)); + zipWriteInFileInZip(file, m_Reg.m_GPR, sizeof(__int64) * 32); + zipWriteInFileInZip(file, m_Reg.m_FPR, sizeof(__int64) * 32); + zipWriteInFileInZip(file, m_Reg.m_CP0, sizeof(DWORD) * 32); + zipWriteInFileInZip(file, m_Reg.m_FPCR, sizeof(DWORD) * 32); + zipWriteInFileInZip(file, &m_Reg.m_HI, sizeof(__int64)); + zipWriteInFileInZip(file, &m_Reg.m_LO, sizeof(__int64)); + zipWriteInFileInZip(file, m_Reg.m_RDRAM_Registers, sizeof(DWORD) * 10); + zipWriteInFileInZip(file, m_Reg.m_SigProcessor_Interface, sizeof(DWORD) * 10); + zipWriteInFileInZip(file, m_Reg.m_Display_ControlReg, sizeof(DWORD) * 10); + zipWriteInFileInZip(file, m_Reg.m_Mips_Interface, sizeof(DWORD) * 4); + zipWriteInFileInZip(file, m_Reg.m_Video_Interface, sizeof(DWORD) * 14); + zipWriteInFileInZip(file, m_Reg.m_Audio_Interface, sizeof(DWORD) * 6); + zipWriteInFileInZip(file, m_Reg.m_Peripheral_Interface, sizeof(DWORD) * 13); + zipWriteInFileInZip(file, m_Reg.m_RDRAM_Interface, sizeof(DWORD) * 8); + zipWriteInFileInZip(file, m_Reg.m_SerialInterface, sizeof(DWORD) * 4); + zipWriteInFileInZip(file, (void *const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32); + zipWriteInFileInZip(file, m_MMU_VM.PifRam(), 0x40); + zipWriteInFileInZip(file, m_MMU_VM.Rdram(), RdramSize); + zipWriteInFileInZip(file, m_MMU_VM.Dmem(), 0x1000); + zipWriteInFileInZip(file, m_MMU_VM.Imem(), 0x1000); zipCloseFileInZip(file); - - zipOpenNewFileInZip(file,ExtraInfoFileName.c_str(),NULL,NULL,0,NULL,0,NULL,Z_DEFLATED,Z_DEFAULT_COMPRESSION); - zipWriteInFileInZip(file,&SaveID_1,sizeof(SaveID_1)); + + zipOpenNewFileInZip(file, ExtraInfoFileName.c_str(), NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION); + zipWriteInFileInZip(file, &SaveID_1, sizeof(SaveID_1)); m_SystemTimer.SaveData(file); zipCloseFileInZip(file); - zipClose(file,""); - } + zipClose(file, ""); + } else { - HANDLE hSaveFile = CreateFile(FileName.c_str(),GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, - NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); - if (hSaveFile == INVALID_HANDLE_VALUE) + HANDLE hSaveFile = CreateFile(FileName.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + if (hSaveFile == INVALID_HANDLE_VALUE) { g_Notify->DisplayError(GS(MSG_FAIL_OPEN_SAVE)); m_Reg.MI_INTR_REG = MiInterReg; @@ -1506,44 +1504,44 @@ bool CN64System::SaveState() } //Write info to file - SetFilePointer(hSaveFile,0,NULL,FILE_BEGIN); - WriteFile( hSaveFile,&SaveID_0,sizeof(DWORD),&dwWritten,NULL); - WriteFile( hSaveFile,&RdramSize,sizeof(DWORD),&dwWritten,NULL); - WriteFile( hSaveFile,g_Rom->GetRomAddress(),0x40,&dwWritten,NULL); - WriteFile( hSaveFile,&NextViTimer,sizeof(DWORD),&dwWritten,NULL); - WriteFile( hSaveFile,&m_Reg.m_PROGRAM_COUNTER,sizeof(m_Reg.m_PROGRAM_COUNTER),&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_GPR,sizeof(__int64)*32,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_FPR,sizeof(__int64)*32,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_CP0,sizeof(DWORD)*32,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_FPCR,sizeof(DWORD)*32,&dwWritten,NULL); - WriteFile( hSaveFile,&m_Reg.m_HI,sizeof(__int64),&dwWritten,NULL); - WriteFile( hSaveFile,&m_Reg.m_LO,sizeof(__int64),&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_RDRAM_Registers,sizeof(DWORD)*10,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_SigProcessor_Interface,sizeof(DWORD)*10,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_Display_ControlReg,sizeof(DWORD)*10,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_Mips_Interface,sizeof(DWORD)*4,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_Video_Interface,sizeof(DWORD)*14,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_Audio_Interface,sizeof(DWORD)*6,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_Peripheral_Interface,sizeof(DWORD)*13,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_RDRAM_Interface,sizeof(DWORD)*8,&dwWritten,NULL); - WriteFile( hSaveFile,m_Reg.m_SerialInterface,sizeof(DWORD)*4,&dwWritten,NULL); - WriteFile( hSaveFile,&g_TLB->TlbEntry(0),sizeof(CTLB::TLB_ENTRY)*32,&dwWritten,NULL); - WriteFile( hSaveFile,g_MMU->PifRam(),0x40,&dwWritten,NULL); - WriteFile( hSaveFile,g_MMU->Rdram(),RdramSize,&dwWritten,NULL); - WriteFile( hSaveFile,g_MMU->Dmem(),0x1000,&dwWritten,NULL); - WriteFile( hSaveFile,g_MMU->Imem(),0x1000,&dwWritten,NULL); + SetFilePointer(hSaveFile, 0, NULL, FILE_BEGIN); + WriteFile(hSaveFile, &SaveID_0, sizeof(DWORD), &dwWritten, NULL); + WriteFile(hSaveFile, &RdramSize, sizeof(DWORD), &dwWritten, NULL); + WriteFile(hSaveFile, g_Rom->GetRomAddress(), 0x40, &dwWritten, NULL); + WriteFile(hSaveFile, &NextViTimer, sizeof(DWORD), &dwWritten, NULL); + WriteFile(hSaveFile, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER), &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_GPR, sizeof(__int64) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_FPR, sizeof(__int64) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_CP0, sizeof(DWORD) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_FPCR, sizeof(DWORD) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, &m_Reg.m_HI, sizeof(__int64), &dwWritten, NULL); + WriteFile(hSaveFile, &m_Reg.m_LO, sizeof(__int64), &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_RDRAM_Registers, sizeof(DWORD) * 10, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_SigProcessor_Interface, sizeof(DWORD) * 10, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Display_ControlReg, sizeof(DWORD) * 10, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Mips_Interface, sizeof(DWORD) * 4, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Video_Interface, sizeof(DWORD) * 14, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Audio_Interface, sizeof(DWORD) * 6, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_Peripheral_Interface, sizeof(DWORD) * 13, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_RDRAM_Interface, sizeof(DWORD) * 8, &dwWritten, NULL); + WriteFile(hSaveFile, m_Reg.m_SerialInterface, sizeof(DWORD) * 4, &dwWritten, NULL); + WriteFile(hSaveFile, &g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32, &dwWritten, NULL); + WriteFile(hSaveFile, g_MMU->PifRam(), 0x40, &dwWritten, NULL); + WriteFile(hSaveFile, g_MMU->Rdram(), RdramSize, &dwWritten, NULL); + WriteFile(hSaveFile, g_MMU->Dmem(), 0x1000, &dwWritten, NULL); + WriteFile(hSaveFile, g_MMU->Imem(), 0x1000, &dwWritten, NULL); CloseHandle(hSaveFile); } m_Reg.MI_INTR_REG = MiInterReg; - g_Settings->SaveString(GameRunning_InstantSaveFile,""); + g_Settings->SaveString(GameRunning_InstantSaveFile, ""); std::wstring SaveMessage = g_Lang->GetString(MSG_SAVED_STATE); CPath SavedFileName(FileName); - - g_Notify->DisplayMessage(5,stdstr_f("%s %s",SaveMessage.c_str(),SavedFileName.GetNameExtension()).ToUTF16().c_str()); + + g_Notify->DisplayMessage(5, stdstr_f("%s %s", SaveMessage.c_str(), SavedFileName.GetNameExtension()).ToUTF16().c_str()); Notify().RefreshMenu(); - WriteTrace(TraceDebug,__FUNCTION__ ": Done"); + WriteTrace(TraceDebug, __FUNCTION__ ": Done"); return true; } @@ -1553,19 +1551,19 @@ bool CN64System::LoadState() if (!InstantFileName.empty()) { bool Result = LoadState(InstantFileName.c_str()); - g_Settings->SaveString(GameRunning_InstantSaveFile,""); + g_Settings->SaveString(GameRunning_InstantSaveFile, ""); return Result; } CPath FileName; FileName.SetDriveDirectory(g_Settings->LoadStringVal(Directory_InstantSave).c_str()); - if (g_Settings->LoadDword(Game_CurrentSaveState) != 0) + if (g_Settings->LoadDword(Game_CurrentSaveState) != 0) { - FileName.SetNameExtension(stdstr_f("%s.pj%d",g_Settings->LoadStringVal(Game_GoodName).c_str(),g_Settings->LoadDword(Game_CurrentSaveState)).c_str()); - } - else + FileName.SetNameExtension(stdstr_f("%s.pj%d", g_Settings->LoadStringVal(Game_GoodName).c_str(), g_Settings->LoadDword(Game_CurrentSaveState)).c_str()); + } + else { - FileName.SetNameExtension(stdstr_f("%s.pj",g_Settings->LoadStringVal(Game_GoodName).c_str()).c_str()); + FileName.SetNameExtension(stdstr_f("%s.pj", g_Settings->LoadStringVal(Game_GoodName).c_str()).c_str()); } CPath ZipFileName; @@ -1580,119 +1578,119 @@ bool CN64System::LoadState() } //Use old file Name - if (g_Settings->LoadDword(Game_CurrentSaveState) != 0) - { - FileName.SetNameExtension(stdstr_f("%s.pj%d",g_Settings->LoadStringVal(Game_GameName).c_str(),g_Settings->LoadDword(Game_CurrentSaveState)).c_str()); + if (g_Settings->LoadDword(Game_CurrentSaveState) != 0) + { + FileName.SetNameExtension(stdstr_f("%s.pj%d", g_Settings->LoadStringVal(Game_GameName).c_str(), g_Settings->LoadDword(Game_CurrentSaveState)).c_str()); } else { - FileName.SetNameExtension(stdstr_f("%s.pj",g_Settings->LoadStringVal(Game_GameName).c_str()).c_str()); + FileName.SetNameExtension(stdstr_f("%s.pj", g_Settings->LoadStringVal(Game_GameName).c_str()).c_str()); } return LoadState(FileName); } -bool CN64System::LoadState(LPCSTR FileName) +bool CN64System::LoadState(LPCSTR FileName) { - DWORD dwRead, Value,SaveRDRAMSize, NextVITimer = 0, old_status, old_width, old_dacrate; + DWORD dwRead, Value, SaveRDRAMSize, NextVITimer = 0, old_status, old_width, old_dacrate; bool LoadedZipFile = false, AudioResetOnLoad; old_status = g_Reg->VI_STATUS_REG; old_width = g_Reg->VI_WIDTH_REG; old_dacrate = g_Reg->AI_DACRATE_REG; - - WriteTraceF((TraceType)(TraceDebug | TraceRecompiler),__FUNCTION__ "(%s): Start",FileName); - char drive[_MAX_DRIVE] ,dir[_MAX_DIR], fname[_MAX_FNAME],ext[_MAX_EXT]; + WriteTraceF((TraceType)(TraceDebug | TraceRecompiler), __FUNCTION__ "(%s): Start", FileName); + + char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; _splitpath(FileName, drive, dir, fname, ext); stdstr FileNameStr(FileName); - if (g_Settings->LoadDword(Setting_AutoZipInstantSave) || _stricmp(ext,".zip") == 0) + if (g_Settings->LoadDword(Setting_AutoZipInstantSave) || _stricmp(ext, ".zip") == 0) { //If ziping save add .zip on the end - if (_stricmp(ext,".zip") != 0) + if (_stricmp(ext, ".zip") != 0) { FileNameStr += ".zip"; } unzFile file = unzOpen(FileNameStr.c_str()); int port = -1; - if (file != NULL) + if (file != NULL) { port = unzGoToFirstFile(file); } DWORD Value; - while (port == UNZ_OK) + while (port == UNZ_OK) { unz_file_info info; char zname[132]; - unzGetCurrentFileInfo(file, &info, zname, 128, NULL,0, NULL,0); - if (unzLocateFile(file, zname, 1) != UNZ_OK ) + unzGetCurrentFileInfo(file, &info, zname, 128, NULL, 0, NULL, 0); + if (unzLocateFile(file, zname, 1) != UNZ_OK) { unzClose(file); port = -1; continue; } - if( unzOpenCurrentFile(file) != UNZ_OK ) + if (unzOpenCurrentFile(file) != UNZ_OK) { unzClose(file); port = -1; continue; } - unzReadCurrentFile(file,&Value,4); - if (Value != 0x23D8A6C8 && Value != 0x56D2CD23) + unzReadCurrentFile(file, &Value, 4); + if (Value != 0x23D8A6C8 && Value != 0x56D2CD23) { unzCloseCurrentFile(file); port = unzGoToNextFile(file); continue; } - if (!LoadedZipFile && Value == 0x23D8A6C8 && port == UNZ_OK) + if (!LoadedZipFile && Value == 0x23D8A6C8 && port == UNZ_OK) { - unzReadCurrentFile(file,&SaveRDRAMSize,sizeof(SaveRDRAMSize)); + unzReadCurrentFile(file, &SaveRDRAMSize, sizeof(SaveRDRAMSize)); //Check header BYTE LoadHeader[64]; - unzReadCurrentFile(file,LoadHeader,0x40); - if (memcmp(LoadHeader,g_Rom->GetRomAddress(),0x40) != 0) + unzReadCurrentFile(file, LoadHeader, 0x40); + if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0) { //if (inFullScreen) { return false; } - int result = MessageBoxW(NULL,GS(MSG_SAVE_STATE_HEADER),GS(MSG_MSGBOX_TITLE), - MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2); + int result = MessageBoxW(NULL, GS(MSG_SAVE_STATE_HEADER), GS(MSG_MSGBOX_TITLE), + MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2); if (result == IDNO) return false; } - Reset(false,true); + Reset(false, true); - g_MMU->UnProtectMemory(0x80000000,0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4); - g_MMU->UnProtectMemory(0xA4000000,0xA4001FFC); - g_Settings->SaveDword(Game_RDRamSize,SaveRDRAMSize); - unzReadCurrentFile(file,&NextVITimer,sizeof(NextVITimer)); - unzReadCurrentFile(file,&m_Reg.m_PROGRAM_COUNTER,sizeof(m_Reg.m_PROGRAM_COUNTER)); - unzReadCurrentFile(file,m_Reg.m_GPR,sizeof(__int64)*32); - unzReadCurrentFile(file,m_Reg.m_FPR,sizeof(__int64)*32); - unzReadCurrentFile(file,m_Reg.m_CP0,sizeof(DWORD)*32); - unzReadCurrentFile(file,m_Reg.m_FPCR,sizeof(DWORD)*32); - unzReadCurrentFile(file,&m_Reg.m_HI,sizeof(__int64)); - unzReadCurrentFile(file,&m_Reg.m_LO,sizeof(__int64)); - unzReadCurrentFile(file,m_Reg.m_RDRAM_Registers,sizeof(DWORD)*10); - unzReadCurrentFile(file,m_Reg.m_SigProcessor_Interface,sizeof(DWORD)*10); - unzReadCurrentFile(file,m_Reg.m_Display_ControlReg,sizeof(DWORD)*10); - unzReadCurrentFile(file,m_Reg.m_Mips_Interface,sizeof(DWORD)*4); - unzReadCurrentFile(file,m_Reg.m_Video_Interface,sizeof(DWORD)*14); - unzReadCurrentFile(file,m_Reg.m_Audio_Interface,sizeof(DWORD)*6); - unzReadCurrentFile(file,m_Reg.m_Peripheral_Interface,sizeof(DWORD)*13); - unzReadCurrentFile(file,m_Reg.m_RDRAM_Interface,sizeof(DWORD)*8); - unzReadCurrentFile(file,m_Reg.m_SerialInterface,sizeof(DWORD)*4); - unzReadCurrentFile(file,(void *const)&g_TLB->TlbEntry(0),sizeof(CTLB::TLB_ENTRY)*32); - unzReadCurrentFile(file,m_MMU_VM.PifRam(),0x40); - unzReadCurrentFile(file,m_MMU_VM.Rdram(),SaveRDRAMSize); - unzReadCurrentFile(file,m_MMU_VM.Dmem(),0x1000); - unzReadCurrentFile(file,m_MMU_VM.Imem(),0x1000); + g_MMU->UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4); + g_MMU->UnProtectMemory(0xA4000000, 0xA4001FFC); + g_Settings->SaveDword(Game_RDRamSize, SaveRDRAMSize); + unzReadCurrentFile(file, &NextVITimer, sizeof(NextVITimer)); + unzReadCurrentFile(file, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER)); + unzReadCurrentFile(file, m_Reg.m_GPR, sizeof(__int64) * 32); + unzReadCurrentFile(file, m_Reg.m_FPR, sizeof(__int64) * 32); + unzReadCurrentFile(file, m_Reg.m_CP0, sizeof(DWORD) * 32); + unzReadCurrentFile(file, m_Reg.m_FPCR, sizeof(DWORD) * 32); + unzReadCurrentFile(file, &m_Reg.m_HI, sizeof(__int64)); + unzReadCurrentFile(file, &m_Reg.m_LO, sizeof(__int64)); + unzReadCurrentFile(file, m_Reg.m_RDRAM_Registers, sizeof(DWORD) * 10); + unzReadCurrentFile(file, m_Reg.m_SigProcessor_Interface, sizeof(DWORD) * 10); + unzReadCurrentFile(file, m_Reg.m_Display_ControlReg, sizeof(DWORD) * 10); + unzReadCurrentFile(file, m_Reg.m_Mips_Interface, sizeof(DWORD) * 4); + unzReadCurrentFile(file, m_Reg.m_Video_Interface, sizeof(DWORD) * 14); + unzReadCurrentFile(file, m_Reg.m_Audio_Interface, sizeof(DWORD) * 6); + unzReadCurrentFile(file, m_Reg.m_Peripheral_Interface, sizeof(DWORD) * 13); + unzReadCurrentFile(file, m_Reg.m_RDRAM_Interface, sizeof(DWORD) * 8); + unzReadCurrentFile(file, m_Reg.m_SerialInterface, sizeof(DWORD) * 4); + unzReadCurrentFile(file, (void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32); + unzReadCurrentFile(file, m_MMU_VM.PifRam(), 0x40); + unzReadCurrentFile(file, m_MMU_VM.Rdram(), SaveRDRAMSize); + unzReadCurrentFile(file, m_MMU_VM.Dmem(), 0x1000); + unzReadCurrentFile(file, m_MMU_VM.Imem(), 0x1000); unzCloseCurrentFile(file); port = unzGoToFirstFile(file); LoadedZipFile = true; continue; } - if (LoadedZipFile && Value == 0x56D2CD23 && port == UNZ_OK) + if (LoadedZipFile && Value == 0x56D2CD23 && port == UNZ_OK) { m_SystemTimer.LoadData(file); } @@ -1701,64 +1699,64 @@ bool CN64System::LoadState(LPCSTR FileName) } unzClose(file); } - if (!LoadedZipFile) + if (!LoadedZipFile) { - HANDLE hSaveFile = CreateFile(FileNameStr.c_str(),GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ,NULL, - OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); - if (hSaveFile == INVALID_HANDLE_VALUE) + HANDLE hSaveFile = CreateFile(FileNameStr.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + if (hSaveFile == INVALID_HANDLE_VALUE) { - g_Notify->DisplayMessage(5,stdstr_f("%s %s",GS(MSG_UNABLED_LOAD_STATE),FileNameStr).ToUTF16().c_str()); + g_Notify->DisplayMessage(5, stdstr_f("%s %s", GS(MSG_UNABLED_LOAD_STATE), FileNameStr).ToUTF16().c_str()); return false; } - SetFilePointer(hSaveFile,0,NULL,FILE_BEGIN); - ReadFile( hSaveFile,&Value,sizeof(Value),&dwRead,NULL); + SetFilePointer(hSaveFile, 0, NULL, FILE_BEGIN); + ReadFile(hSaveFile, &Value, sizeof(Value), &dwRead, NULL); if (Value != 0x23D8A6C8) return false; - ReadFile( hSaveFile,&SaveRDRAMSize,sizeof(SaveRDRAMSize),&dwRead,NULL); + ReadFile(hSaveFile, &SaveRDRAMSize, sizeof(SaveRDRAMSize), &dwRead, NULL); //Check header BYTE LoadHeader[64]; - ReadFile( hSaveFile,LoadHeader,0x40,&dwRead,NULL); - if (memcmp(LoadHeader,g_Rom->GetRomAddress(),0x40) != 0) + ReadFile(hSaveFile, LoadHeader, 0x40, &dwRead, NULL); + if (memcmp(LoadHeader, g_Rom->GetRomAddress(), 0x40) != 0) { //if (inFullScreen) { return false; } - int result = MessageBoxW(NULL,GS(MSG_SAVE_STATE_HEADER),GS(MSG_MSGBOX_TITLE), - MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2); + int result = MessageBoxW(NULL, GS(MSG_SAVE_STATE_HEADER), GS(MSG_MSGBOX_TITLE), + MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2); if (result == IDNO) return false; } - Reset(false,true); - m_MMU_VM.UnProtectMemory(0x80000000,0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4); - m_MMU_VM.UnProtectMemory(0xA4000000,0xA4001FFC); - g_Settings->SaveDword(Game_RDRamSize,SaveRDRAMSize); + Reset(false, true); + m_MMU_VM.UnProtectMemory(0x80000000, 0x80000000 + g_Settings->LoadDword(Game_RDRamSize) - 4); + m_MMU_VM.UnProtectMemory(0xA4000000, 0xA4001FFC); + g_Settings->SaveDword(Game_RDRamSize, SaveRDRAMSize); - ReadFile( hSaveFile,&NextVITimer,sizeof(NextVITimer),&dwRead,NULL); - ReadFile( hSaveFile,&m_Reg.m_PROGRAM_COUNTER,sizeof(m_Reg.m_PROGRAM_COUNTER),&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_GPR,sizeof(__int64)*32,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_FPR,sizeof(__int64)*32,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_CP0,sizeof(DWORD)*32,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_FPCR,sizeof(DWORD)*32,&dwRead,NULL); - ReadFile( hSaveFile,&m_Reg.m_HI,sizeof(__int64),&dwRead,NULL); - ReadFile( hSaveFile,&m_Reg.m_LO,sizeof(__int64),&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_RDRAM_Registers,sizeof(DWORD)*10,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_SigProcessor_Interface,sizeof(DWORD)*10,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_Display_ControlReg,sizeof(DWORD)*10,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_Mips_Interface,sizeof(DWORD)*4,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_Video_Interface,sizeof(DWORD)*14,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_Audio_Interface,sizeof(DWORD)*6,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_Peripheral_Interface,sizeof(DWORD)*13,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_RDRAM_Interface,sizeof(DWORD)*8,&dwRead,NULL); - ReadFile( hSaveFile,m_Reg.m_SerialInterface,sizeof(DWORD)*4,&dwRead,NULL); - ReadFile( hSaveFile,(void *const)&g_TLB->TlbEntry(0),sizeof(CTLB::TLB_ENTRY)*32,&dwRead,NULL); - ReadFile( hSaveFile,m_MMU_VM.PifRam(),0x40,&dwRead,NULL); - ReadFile( hSaveFile,m_MMU_VM.Rdram(),SaveRDRAMSize,&dwRead,NULL); - ReadFile( hSaveFile,m_MMU_VM.Dmem(),0x1000,&dwRead,NULL); - ReadFile( hSaveFile,m_MMU_VM.Imem(),0x1000,&dwRead,NULL); + ReadFile(hSaveFile, &NextVITimer, sizeof(NextVITimer), &dwRead, NULL); + ReadFile(hSaveFile, &m_Reg.m_PROGRAM_COUNTER, sizeof(m_Reg.m_PROGRAM_COUNTER), &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_GPR, sizeof(__int64) * 32, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_FPR, sizeof(__int64) * 32, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_CP0, sizeof(DWORD) * 32, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_FPCR, sizeof(DWORD) * 32, &dwRead, NULL); + ReadFile(hSaveFile, &m_Reg.m_HI, sizeof(__int64), &dwRead, NULL); + ReadFile(hSaveFile, &m_Reg.m_LO, sizeof(__int64), &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_RDRAM_Registers, sizeof(DWORD) * 10, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_SigProcessor_Interface, sizeof(DWORD) * 10, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Display_ControlReg, sizeof(DWORD) * 10, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Mips_Interface, sizeof(DWORD) * 4, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Video_Interface, sizeof(DWORD) * 14, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Audio_Interface, sizeof(DWORD) * 6, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_Peripheral_Interface, sizeof(DWORD) * 13, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_RDRAM_Interface, sizeof(DWORD) * 8, &dwRead, NULL); + ReadFile(hSaveFile, m_Reg.m_SerialInterface, sizeof(DWORD) * 4, &dwRead, NULL); + ReadFile(hSaveFile, (void *const)&g_TLB->TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32, &dwRead, NULL); + ReadFile(hSaveFile, m_MMU_VM.PifRam(), 0x40, &dwRead, NULL); + ReadFile(hSaveFile, m_MMU_VM.Rdram(), SaveRDRAMSize, &dwRead, NULL); + ReadFile(hSaveFile, m_MMU_VM.Dmem(), 0x1000, &dwRead, NULL); + ReadFile(hSaveFile, m_MMU_VM.Imem(), 0x1000, &dwRead, NULL); CloseHandle(hSaveFile); } - + //Fix losing audio in certain games with certain plugins AudioResetOnLoad = g_Settings->LoadBool(Game_AudioResetOnLoad); if (AudioResetOnLoad) @@ -1767,63 +1765,63 @@ bool CN64System::LoadState(LPCSTR FileName) m_Reg.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; g_Reg->MI_INTR_REG |= MI_INTR_AI; } - + if (bFixedAudio()) { m_Audio.SetFrequency(m_Reg.AI_DACRATE_REG, g_System->SystemType()); } - + if (old_status != g_Reg->VI_STATUS_REG) { g_Plugins->Gfx()->ViStatusChanged(); } - + if (old_width != g_Reg->VI_WIDTH_REG) { g_Plugins->Gfx()->ViWidthChanged(); } - + if (old_dacrate != g_Reg->AI_DACRATE_REG) { g_Plugins->Audio()->DacrateChanged(g_System->SystemType()); } - + //Fix Random Register while ((int)m_Reg.RANDOM_REGISTER < (int)m_Reg.WIRED_REGISTER) { m_Reg.RANDOM_REGISTER += 32 - m_Reg.WIRED_REGISTER; } //Fix up timer - WriteTrace(TraceDebug,__FUNCTION__ ": 2"); - m_SystemTimer.SetTimer(CSystemTimer::CompareTimer,m_Reg.COMPARE_REGISTER - m_Reg.COUNT_REGISTER,false); - m_SystemTimer.SetTimer(CSystemTimer::ViTimer,NextVITimer,false); + WriteTrace(TraceDebug, __FUNCTION__ ": 2"); + m_SystemTimer.SetTimer(CSystemTimer::CompareTimer, m_Reg.COMPARE_REGISTER - m_Reg.COUNT_REGISTER, false); + m_SystemTimer.SetTimer(CSystemTimer::ViTimer, NextVITimer, false); m_Reg.FixFpuLocations(); - WriteTrace(TraceDebug,__FUNCTION__ ": 5"); + WriteTrace(TraceDebug, __FUNCTION__ ": 5"); m_TLB.Reset(false); - WriteTrace(TraceDebug,__FUNCTION__ ": 6"); + WriteTrace(TraceDebug, __FUNCTION__ ": 6"); m_CPU_Usage.ResetCounters(); - WriteTrace(TraceDebug,__FUNCTION__ ": 7"); + WriteTrace(TraceDebug, __FUNCTION__ ": 7"); m_Profile.ResetCounters(); - WriteTrace(TraceDebug,__FUNCTION__ ": 8"); + WriteTrace(TraceDebug, __FUNCTION__ ": 8"); m_FPS.Reset(true); - WriteTrace(TraceDebug,__FUNCTION__ ": 9"); + WriteTrace(TraceDebug, __FUNCTION__ ": 9"); if (bLogX86Code()) { Stop_x86_Log(); Start_x86_Log(); } - WriteTrace(TraceDebug,__FUNCTION__ ": Done"); + WriteTrace(TraceDebug, __FUNCTION__ ": Done"); #ifdef TEST_SP_TRACKING m_CurrentSP = GPR[29].UW[0]; #endif if (bFastSP() && m_Recomp) { m_Recomp->ResetMemoryStackPos(); } - if (g_Settings->LoadDword(Game_CpuType) == CPU_SyncCores) + if (g_Settings->LoadDword(Game_CpuType) == CPU_SyncCores) { if (m_SyncCPU) { - for (int i = 0; i < (sizeof(m_LastSuccessSyncPC)/sizeof(m_LastSuccessSyncPC[0])); i++) + for (int i = 0; i < (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])); i++) { m_LastSuccessSyncPC[i] = 0; } @@ -1833,10 +1831,10 @@ bool CN64System::LoadState(LPCSTR FileName) SyncCPU(m_SyncCPU); } } - WriteTrace(TraceDebug,__FUNCTION__ ": 13"); + WriteTrace(TraceDebug, __FUNCTION__ ": 13"); std::wstring LoadMsg = g_Lang->GetString(MSG_LOADED_STATE); - g_Notify->DisplayMessage(5,stdstr_f("%s %s",LoadMsg.c_str(),CPath(FileNameStr).GetNameExtension()).ToUTF16().c_str()); - WriteTrace(TraceDebug,__FUNCTION__ ": Done"); + g_Notify->DisplayMessage(5, stdstr_f("%s %s", LoadMsg.c_str(), CPath(FileNameStr).GetNameExtension()).ToUTF16().c_str()); + WriteTrace(TraceDebug, __FUNCTION__ ": Done"); return true; } @@ -1847,18 +1845,18 @@ void CN64System::DisplayRSPListCount() void CN64System::RunRSP() { - WriteTraceF(TraceRSP, __FUNCTION__ ": Start (SP Status %X)",m_Reg.SP_STATUS_REG); - if ( ( m_Reg.SP_STATUS_REG & SP_STATUS_HALT ) == 0) - { - if ( ( m_Reg.SP_STATUS_REG & SP_STATUS_BROKE ) == 0 ) - { + WriteTraceF(TraceRSP, __FUNCTION__ ": Start (SP Status %X)", m_Reg.SP_STATUS_REG); + if ((m_Reg.SP_STATUS_REG & SP_STATUS_HALT) == 0) + { + if ((m_Reg.SP_STATUS_REG & SP_STATUS_BROKE) == 0) + { SPECIAL_TIMERS CPU_UsageAddr = Timer_None/*, ProfileAddr = Timer_None*/; - + DWORD Task = 0; if (m_RspBroke) { - g_MMU->LW_VAddr(0xA4000FC0,(uint32_t &)Task); - if (Task == 1 && (m_Reg.DPC_STATUS_REG & DPC_STATUS_FREEZE) != 0) + g_MMU->LW_VAddr(0xA4000FC0, (uint32_t &)Task); + if (Task == 1 && (m_Reg.DPC_STATUS_REG & DPC_STATUS_FREEZE) != 0) { WriteTrace(TraceRSP, __FUNCTION__ ": Dlist that is frozen"); return; @@ -1866,18 +1864,18 @@ void CN64System::RunRSP() switch (Task) { - case 1: + case 1: WriteTrace(TraceRSP, __FUNCTION__ ": *** Display list ***"); - m_DlistCount += 1; + m_DlistCount += 1; m_FPS.UpdateDlCounter(); break; - case 2: + case 2: WriteTrace(TraceRSP, __FUNCTION__ ": *** Audio list ***"); - m_AlistCount += 1; + m_AlistCount += 1; break; - default: + default: WriteTrace(TraceRSP, __FUNCTION__ ": *** Unknown list ***"); - m_UnknownCount += 1; + m_UnknownCount += 1; break; } @@ -1885,9 +1883,9 @@ void CN64System::RunRSP() { DisplayRSPListCount(); } - if (bShowCPUPer()) + if (bShowCPUPer()) { - switch (Task) + switch (Task) { case 1: CPU_UsageAddr = m_CPU_Usage.StartTimer(Timer_RSP_Dlist); break; case 2: CPU_UsageAddr = m_CPU_Usage.StartTimer(Timer_RSP_Alist); break; @@ -1895,15 +1893,14 @@ void CN64System::RunRSP() } } } - - __try + __try { WriteTrace(TraceRSP, __FUNCTION__ ": do cycles - starting"); g_Plugins->RSP()->DoRspCycles(100); WriteTrace(TraceRSP, __FUNCTION__ ": do cycles - Done"); } - __except( g_MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) + __except (g_MMU->MemoryFilter(GetExceptionCode(), GetExceptionInformation())) { WriteTrace(TraceError, __FUNCTION__ ": exception generated"); g_Notify->FatalError(__FUNCTIONW__ L"\nUnknown memory action\n\nEmulation stop"); @@ -1911,17 +1908,17 @@ void CN64System::RunRSP() if (Task == 1 && bDelayDP() && ((m_Reg.m_GfxIntrReg & MI_INTR_DP) != 0)) { - g_SystemTimer->SetTimer(CSystemTimer::RSPTimerDlist,0x1000,false); + g_SystemTimer->SetTimer(CSystemTimer::RSPTimerDlist, 0x1000, false); m_Reg.m_GfxIntrReg &= ~MI_INTR_DP; } if (bShowCPUPer()) { m_CPU_Usage.StartTimer(CPU_UsageAddr); } //if (bProfiling) { m_Profile.StartTimer(ProfileAddr); } - if ( ( m_Reg.SP_STATUS_REG & SP_STATUS_HALT ) == 0 && - ( m_Reg.SP_STATUS_REG & SP_STATUS_BROKE ) == 0 && - m_Reg.m_RspIntrReg == 0) + if ((m_Reg.SP_STATUS_REG & SP_STATUS_HALT) == 0 && + (m_Reg.SP_STATUS_REG & SP_STATUS_BROKE) == 0 && + m_Reg.m_RspIntrReg == 0) { - g_SystemTimer->SetTimer(CSystemTimer::RspTimer,0x200,false); + g_SystemTimer->SetTimer(CSystemTimer::RspTimer, 0x200, false); m_RspBroke = false; } else @@ -1932,7 +1929,7 @@ void CN64System::RunRSP() g_Reg->CheckInterrupts(); } } - WriteTraceF(TraceRSP, __FUNCTION__ ": Done (SP Status %X)",m_Reg.SP_STATUS_REG); + WriteTraceF(TraceRSP, __FUNCTION__ ": Done (SP Status %X)", m_Reg.SP_STATUS_REG); } void CN64System::SyncToAudio() @@ -1944,19 +1941,19 @@ void CN64System::SyncToAudio() SPECIAL_TIMERS CPU_UsageAddr = Timer_None; if (bShowCPUPer()) { CPU_UsageAddr = m_CPU_Usage.StartTimer(Timer_Idel); } - + for (int i = 0; i < 50; i++) { if (g_Reg->m_AudioIntrReg != 0) { - WriteTraceF(TraceAudio, __FUNCTION__ ": Audio Interrupt done (%d)",i); + WriteTraceF(TraceAudio, __FUNCTION__ ": Audio Interrupt done (%d)", i); break; } Sleep(1); } - if (bShowCPUPer()) + if (bShowCPUPer()) { - m_CPU_Usage.StartTimer(CPU_UsageAddr != Timer_None ? CPU_UsageAddr : Timer_R4300 ); + m_CPU_Usage.StartTimer(CPU_UsageAddr != Timer_None ? CPU_UsageAddr : Timer_R4300); } } @@ -1964,53 +1961,53 @@ void CN64System::RefreshScreen() { SPECIAL_TIMERS CPU_UsageAddr = Timer_None/*, ProfilingAddr = Timer_None*/; DWORD VI_INTR_TIME = 500000; - + if (bShowCPUPer()) { CPU_UsageAddr = m_CPU_Usage.StartTimer(Timer_RefreshScreen); } //if (bProfiling) { ProfilingAddr = m_Profile.StartTimer(Timer_RefreshScreen); } //Calculate how many cycles to next refresh - if (m_Reg.VI_V_SYNC_REG == 0) + if (m_Reg.VI_V_SYNC_REG == 0) { VI_INTR_TIME = 500000; } else { VI_INTR_TIME = (m_Reg.VI_V_SYNC_REG + 1) * ViRefreshRate(); - if ((m_Reg.VI_V_SYNC_REG % 1) != 0) + if ((m_Reg.VI_V_SYNC_REG % 1) != 0) { VI_INTR_TIME -= 38; } } - g_SystemTimer->SetTimer(CSystemTimer::ViTimer,VI_INTR_TIME,true); + g_SystemTimer->SetTimer(CSystemTimer::ViTimer, VI_INTR_TIME, true); if (bFixedAudio()) { - g_Audio->SetViIntr (VI_INTR_TIME); + g_Audio->SetViIntr(VI_INTR_TIME); } - if (g_Plugins->Control()->GetKeys) + if (g_Plugins->Control()->GetKeys) { BUTTONS Keys; - memset(&Keys,0,sizeof(Keys)); + memset(&Keys, 0, sizeof(Keys)); for (int Control = 0; Control < 4; Control++) - { - g_Plugins->Control()->GetKeys(Control,&Keys); + { + g_Plugins->Control()->GetKeys(Control, &Keys); m_Buttons[Control] = Keys.Value; } } if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_UpdateScreen); } -// if (bProfiling) { m_Profile.StartTimer(Timer_UpdateScreen); } - + // if (bProfiling) { m_Profile.StartTimer(Timer_UpdateScreen); } + __try { - WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Starting"); + WriteTrace(TraceGfxPlugin, __FUNCTION__ ": Starting"); g_Plugins->Gfx()->UpdateScreen(); - WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Done"); + WriteTrace(TraceGfxPlugin, __FUNCTION__ ": Done"); } - __except (g_MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation())) + __except (g_MMU->MemoryFilter(GetExceptionCode(), GetExceptionInformation())) { - WriteTrace(TraceGfxPlugin,__FUNCTION__ ": Exception caught"); - WriteTrace(TraceError,__FUNCTION__ ": Exception caught"); + WriteTrace(TraceGfxPlugin, __FUNCTION__ ": Exception caught"); + WriteTrace(TraceError, __FUNCTION__ ": Exception caught"); } g_MMU->UpdateFieldSerration((m_Reg.VI_STATUS_REG & 0x40) != 0); @@ -2031,18 +2028,18 @@ void CN64System::RefreshScreen() m_FPS.UpdateViCounter(); m_bCleanFrameBox = true; } - + if (m_bCleanFrameBox && !bDisplayFrameRate()) { - m_FPS.Reset (true); + m_FPS.Reset(true); m_bCleanFrameBox = false; } - if (bShowCPUPer()) + if (bShowCPUPer()) { m_CPU_Usage.StopTimer(); m_CPU_Usage.ShowCPU_Usage(); - m_CPU_Usage.StartTimer(CPU_UsageAddr != Timer_None ? CPU_UsageAddr : Timer_R4300 ); + m_CPU_Usage.StartTimer(CPU_UsageAddr != Timer_None ? CPU_UsageAddr : Timer_R4300); } if ((m_Reg.STATUS_REGISTER & STATUS_IE) != 0) { @@ -2060,12 +2057,12 @@ void CN64System::RefreshScreen() // if (bProfiling) { m_Profile.StartTimer(ProfilingAddr != Timer_None ? ProfilingAddr : Timer_R4300); } } -bool CN64System::WriteToProtectedMemory (uint32_t Address, int length) +bool CN64System::WriteToProtectedMemory(uint32_t Address, int length) { - WriteTraceF(TraceDebug,__FUNCTION__ ": Address: %X Len: %d",Address,length); + WriteTraceF(TraceDebug, __FUNCTION__ ": Address: %X Len: %d", Address, length); if (m_Recomp) { - g_Notify->BreakPoint(__FILEW__,__LINE__); + g_Notify->BreakPoint(__FILEW__, __LINE__); #ifdef tofix return m_Recomp->ClearRecompCode_Phys(Address,length,CRecompiler::Remove_ProtectedMem); #endif @@ -2073,17 +2070,17 @@ bool CN64System::WriteToProtectedMemory (uint32_t Address, int length) return false; } -void CN64System::TLB_Mapped ( uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly ) +void CN64System::TLB_Mapped(uint32_t VAddr, uint32_t Len, uint32_t PAddr, bool bReadOnly) { - m_MMU_VM.TLB_Mapped(VAddr,Len,PAddr,bReadOnly); + m_MMU_VM.TLB_Mapped(VAddr, Len, PAddr, bReadOnly); } -void CN64System::TLB_Unmaped ( uint32_t VAddr, uint32_t Len ) +void CN64System::TLB_Unmaped(uint32_t VAddr, uint32_t Len) { - m_MMU_VM.TLB_Unmaped(VAddr,Len); + m_MMU_VM.TLB_Unmaped(VAddr, Len); if (m_Recomp && bSMM_TLB()) { - m_Recomp->ClearRecompCode_Virt(VAddr,Len,CRecompiler::Remove_TLB); + m_Recomp->ClearRecompCode_Virt(VAddr, Len, CRecompiler::Remove_TLB); } } @@ -2093,4 +2090,4 @@ void CN64System::TLB_Changed() { g_Debugger->TLBChanged(); } -} +} \ No newline at end of file diff --git a/Source/Project64/N64 System/N64 Class.h b/Source/Project64/N64 System/N64 Class.h index 79971522a..27292a815 100644 --- a/Source/Project64/N64 System/N64 Class.h +++ b/Source/Project64/N64 System/N64 Class.h @@ -21,53 +21,53 @@ class CRecompiler; //#define TEST_SP_TRACKING //track the SP to make sure all ops pick it up fine class CN64System : - public CMipsMemory_CallBack, - public CTLB_CB, - private CSystemEvents, - protected CN64SystemSettings, - public CGameSettings, - protected CDebugSettings + public CMipsMemory_CallBack, + public CTLB_CB, + private CSystemEvents, + protected CN64SystemSettings, + public CGameSettings, + protected CDebugSettings { public: - CN64System(CPlugins * Plugins, bool SavesReadOnly); - virtual ~CN64System(void); + CN64System(CPlugins * Plugins, bool SavesReadOnly); + virtual ~CN64System(void); struct ThreadInfo { HANDLE * ThreadHandle; DWORD ThreadID; }; - CProfiling m_Profile; - CCheats m_Cheats; - bool m_EndEmulation; - SAVE_CHIP_TYPE m_SaveUsing; + CProfiling m_Profile; + CCheats m_Cheats; + bool m_EndEmulation; + SAVE_CHIP_TYPE m_SaveUsing; - //Methods - static bool RunFileImage(const char * FileLoc); - static void CloseSystem(void); + //Methods + static bool RunFileImage(const char * FileLoc); + static void CloseSystem(void); - void CloseCpu (); - void ExternalEvent ( SystemEvent action ); //covers gui interacting and timers etc.. - stdstr ChooseFileToOpen ( HWND hParent ); - void DisplayRomInfo ( HWND hParent ); - void StartEmulation ( bool NewThread ); - void SyncToAudio (); - void IncreaseSpeed () { m_Limitor.IncreaseSpeed(); } - void DecreaseSpeed () { m_Limitor.DecreaseSpeed(); } - void Reset ( bool bInitReg, bool ClearMenory ); - void GameReset (); - void PluginReset (); + void CloseCpu(); + void ExternalEvent(SystemEvent action); //covers gui interacting and timers etc.. + stdstr ChooseFileToOpen(HWND hParent); + void DisplayRomInfo(HWND hParent); + void StartEmulation(bool NewThread); + void SyncToAudio(); + void IncreaseSpeed() { m_Limitor.IncreaseSpeed(); } + void DecreaseSpeed() { m_Limitor.DecreaseSpeed(); } + void Reset(bool bInitReg, bool ClearMenory); + void GameReset(); + void PluginReset(); - void Pause (); - void RunRSP (); - bool SaveState (); - bool LoadState ( LPCSTR FileName ); - bool LoadState (); + void Pause(); + void RunRSP(); + bool SaveState(); + bool LoadState(LPCSTR FileName); + bool LoadState(); bool DmaUsed() const { return m_DMAUsed; } void SetDmaUsed(bool DMAUsed) { m_DMAUsed = DMAUsed; } - void SetCheatsSlectionChanged(bool changed) { m_CheatsSlectionChanged = changed; } - bool HasCheatsSlectionChanged(void) const { return m_CheatsSlectionChanged; } + void SetCheatsSlectionChanged(bool changed) { m_CheatsSlectionChanged = changed; } + bool HasCheatsSlectionChanged(void) const { return m_CheatsSlectionChanged; } DWORD GetButtons(int Control) const { return m_Buttons[Control]; } //Variable used to track that the SP is being handled and stays the same as the real SP in sync core @@ -75,31 +75,31 @@ public: DWORD m_CurrentSP; #endif //For Sync CPU - void UpdateSyncCPU ( CN64System * const SecondCPU, DWORD const Cycles ); - void SyncCPU ( CN64System * const SecondCPU ); - void SyncCPUPC ( CN64System * const SecondCPU ); - void SyncSystem (); - void SyncSystemPC (); + void UpdateSyncCPU(CN64System * const SecondCPU, DWORD const Cycles); + void SyncCPU(CN64System * const SecondCPU); + void SyncCPUPC(CN64System * const SecondCPU); + void SyncSystem(); + void SyncSystemPC(); private: //Make sure plugins can directly access this information friend CGfxPlugin; friend CAudioPlugin; friend CRSP_Plugin; friend CControl_Plugin; - + //Recompiler has access to manipulate and call functions friend CSystemTimer; //Used for loading and potentially executing the CPU in its own thread. - static void StartEmulationThread ( ThreadInfo * Info ); - static bool EmulationStarting ( HANDLE hThread, DWORD ThreadId ); + static void StartEmulationThread(ThreadInfo * Info); + static bool EmulationStarting(HANDLE hThread, DWORD ThreadId); - void ExecuteCPU (); - void RefreshScreen (); - void DumpSyncErrors ( CN64System * SecondCPU ); - void StartEmulation2 ( bool NewThread ); - bool SetActiveSystem ( bool bActive = true ); - void InitRegisters ( bool bPostPif, CMipsMemory & MMU ); + void ExecuteCPU(); + void RefreshScreen(); + void DumpSyncErrors(CN64System * SecondCPU); + void StartEmulation2(bool NewThread); + bool SetActiveSystem(bool bActive = true); + void InitRegisters(bool bPostPif, CMipsMemory & MMU); void DisplayRSPListCount(); //CPU Methods @@ -118,11 +118,11 @@ private: void TLB_Unmaped(uint32_t VAddr, uint32_t Len); void TLB_Changed(); - CPlugins * const m_Plugins; //The plugin container + CPlugins * const m_Plugins; //The plugin container CN64System * m_SyncCPU; CPlugins * m_SyncPlugins; CMainGui * m_SyncWindow; - CMipsMemoryVM m_MMU_VM; //Memory of the n64 + CMipsMemoryVM m_MMU_VM; //Memory of the n64 CTLB m_TLB; CRegisters m_Reg; CFramePerSecond m_FPS; @@ -141,10 +141,10 @@ private: bool m_TestTimer; DWORD m_NextInstruction; DWORD m_JumpToLocation; - uint32_t m_TLBLoadAddress; - uint32_t m_TLBStoreAddress; + uint32_t m_TLBLoadAddress; + uint32_t m_TLBStoreAddress; DWORD m_SyncCount; - bool m_CheatsSlectionChanged; + bool m_CheatsSlectionChanged; //When Syncing cores this is the PC where it last Sync'ed correctly DWORD m_LastSuccessSyncPC[10]; @@ -153,7 +153,7 @@ private: //Handle to the cpu thread HANDLE m_CPU_Handle; DWORD m_CPU_ThreadID; - + //Handle to pause mutex void * m_hPauseEvent;