diff --git a/Source/Project64/N64 System/C Core/C Core Interface.cpp b/Source/Project64/N64 System/C Core/C Core Interface.cpp index f996f02a8..fe10aa20c 100644 --- a/Source/Project64/N64 System/C Core/C Core Interface.cpp +++ b/Source/Project64/N64 System/C Core/C Core Interface.cpp @@ -5,9 +5,8 @@ #include "CPU Log.h" //settings -BOOL g_ShowUnhandledMemory = false, g_ShowCPUPer = false, g_ShowTLBMisses = false, g_UseTlb = true, +BOOL g_ShowCPUPer = false, g_ShowTLBMisses = false, g_UseTlb = true, g_HaveDebugger = false, g_AudioSignal = false, - g_ShowPifRamErrors = false, g_GenerateLog = false, g_UseLinking = false, g_FixedAudio = false, g_LogX86Code = false; DWORD g_RomFileSize = 0, g_CountPerOp = 2, g_ViRefreshRate = 1500; @@ -20,9 +19,6 @@ char g_RomName [300]; DWORD * _AudioIntrReg = NULL; enum SystemType g_SystemType; -//Memory -DWORD g_RdramSize; - BOOL g_IndvidualBlock, g_Profiling; void CC_Core::SetSettings ( ) @@ -30,24 +26,13 @@ void CC_Core::SetSettings ( ) if (_Settings) { g_HaveDebugger = _Settings->LoadBool(Debugger_Enabled); - if (g_HaveDebugger) - { - g_ShowUnhandledMemory = _Settings->LoadBool(Debugger_ShowUnhandledMemory); - } else { - g_ShowUnhandledMemory = false; - g_ShowUnhandledMemory = false; - - } g_ShowCPUPer = _Settings->LoadBool(UserInterface_ShowCPUPer); g_ShowTLBMisses = false; g_UseTlb = _Settings->LoadBool(Game_UseTlb); g_CPU_Type = (CPU_TYPE)_Settings->LoadDword(Game_CpuType); g_SaveUsing = (SAVE_CHIP_TYPE)_Settings->LoadDword(Game_SaveChip); g_AudioSignal = _Settings->LoadBool(Game_RspAudioSignal); - g_RdramSize = _Settings->LoadDword(Game_RDRamSize); - g_ShowPifRamErrors = _Settings->LoadDword(Debugger_ShowPifErrors); g_CountPerOp = _Settings->LoadDword(Game_CounterFactor); - g_GenerateLog = _Settings->LoadDword(Debugger_GenerateDebugLog); g_FixedAudio = _Settings->LoadBool(Game_FixedAudio); g_LogX86Code = _Settings->LoadBool(Debugger_GenerateLogFiles); g_LookUpMode = (FUNC_LOOKUP_METHOD)_Settings->LoadDword(Game_FuncLookupMode); @@ -154,11 +139,6 @@ BOOL Limit_FPS ( void ) return _Settings->LoadDword(GameRunning_LimitFPS); } -void DacrateChanged ( enum SystemType Type ) -{ - _Plugins->Audio()->DacrateChanged(Type); -} - void RunRsp( void ) { CC_Core::RunRsp(); diff --git a/Source/Project64/N64 System/C Core/C Core Interface.h b/Source/Project64/N64 System/C Core/C Core Interface.h index 025eb4714..7eac47591 100644 --- a/Source/Project64/N64 System/C Core/C Core Interface.h +++ b/Source/Project64/N64 System/C Core/C Core Interface.h @@ -41,7 +41,6 @@ void GetAutoSaveDir ( char * Directory ); void GetInstantSaveDir ( char * Directory ); void SetFpuLocations ( void ); BOOL Limit_FPS ( void ); -void DacrateChanged ( enum SystemType Type ); void ChangePluginFunc ( void ); void ApplyGSButtonCheats ( void ); void ChangeFullScreenFunc ( void ); @@ -64,9 +63,8 @@ DWORD StartTimer ( DWORD Address ); DWORD StopTimer ( void ); //settings -extern BOOL g_ShowUnhandledMemory, g_ShowCPUPer, g_ShowTLBMisses, g_UseTlb, - g_HaveDebugger, g_AudioSignal, g_ShowPifRamErrors, - g_GenerateLog, g_ShowCompMem, +extern BOOL g_ShowCPUPer, g_ShowTLBMisses, g_UseTlb, + g_HaveDebugger, g_AudioSignal, g_UseLinking, g_FixedAudio, g_LogX86Code; extern DWORD g_RomFileSize, g_CountPerOp; extern enum CPU_TYPE g_CPU_Type; @@ -78,8 +76,6 @@ extern char g_RomName [300]; extern DWORD * g_AudioIntrReg; extern enum SystemType g_SystemType; -extern DWORD g_RdramSize; - #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/Source/Project64/N64 System/C Core/Logging.cpp b/Source/Project64/N64 System/C Core/Logging.cpp index 5814d06c3..1d4249276 100644 --- a/Source/Project64/N64 System/C Core/Logging.cpp +++ b/Source/Project64/N64 System/C Core/Logging.cpp @@ -189,7 +189,7 @@ void Log_LW (DWORD PC, DWORD VAddr) { } DWORD Value; - if ( VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_RdramSize)) { return; } + if ( VAddr >= 0xA0000000 && VAddr < (0xA0000000 + _MMU->RdramSize())) { return; } if ( VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) { if (!LogOptions.LogRDRamRegisters) { return; } _MMU->LW_VAddr(VAddr,Value); @@ -410,7 +410,7 @@ void Log_SW (DWORD PC, DWORD VAddr, DWORD Value) { VAddr = PAddr + 0xA0000000; } - if ( VAddr >= 0xA0000000 && VAddr < (0xA0000000 + g_RdramSize)) { return; } + if ( VAddr >= 0xA0000000 && VAddr < (0xA0000000 + _MMU->RdramSize())) { return; } if ( VAddr >= 0xA3F00000 && VAddr <= 0xA3F00024) { if (!LogOptions.LogRDRamRegisters) { return; } switch (VAddr) { diff --git a/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp b/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp index bcbef5c35..5aec3dc4a 100644 --- a/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp +++ b/Source/Project64/N64 System/Interpreter/Interpreter CPU.cpp @@ -324,7 +324,7 @@ void CInterpreterCPU::ExecuteOps ( int Cycles ) *_NextTimer -= m_CountPerOp; m_R4300i_Opcode[ Opcode.op ](); - static DWORD TestAddress = 0x80077B0C, TestValue = 0, CurrentValue = 0; + /*static DWORD TestAddress = 0x80077B0C, TestValue = 0, CurrentValue = 0; if (_MMU->LW_VAddr(TestAddress, TestValue)) { if (TestValue != CurrentValue) @@ -332,7 +332,7 @@ void CInterpreterCPU::ExecuteOps ( int Cycles ) WriteTraceF(TraceError,"%X: %X changed (%s)",PROGRAM_COUNTER,TestAddress,R4300iOpcodeName(m_Opcode.Hex,PROGRAM_COUNTER) ); CurrentValue = TestValue; } - } + }*/ switch (R4300iOp::m_NextInstruction) { diff --git a/Source/Project64/N64 System/Mips/Audio.cpp b/Source/Project64/N64 System/Mips/Audio.cpp index 6e29a3c62..2b6be7441 100644 --- a/Source/Project64/N64 System/Mips/Audio.cpp +++ b/Source/Project64/N64 System/Mips/Audio.cpp @@ -14,7 +14,8 @@ void CAudio::Reset ( void ) m_CurrentLength = 0; m_SecondBuff = 0; m_Status = 0; - m_CountsPerByte = 50; // should be calculated ... see below + m_CountsPerByte = 500; // should be calculated ... see below + m_FramesPerSecond = 60; } DWORD CAudio::GetLength ( void ) @@ -64,7 +65,33 @@ void CAudio::TimerDone ( void ) void CAudio::SetViIntr ( DWORD VI_INTR_TIME ) { + double CountsPerSecond = (DWORD)((double)VI_INTR_TIME * m_FramesPerSecond); + m_CountsPerByte = (double)CountsPerSecond / (double)m_BytesPerSecond; + //m_CountsPerByte = 490; // donkey kong + //m_CountsPerByte = 100; // Paper mario + //m_CountsPerByte = 490; // Paper mario + } +void CAudio::SetFrequency (DWORD Dacrate, DWORD System) +{ + + DWORD Frequency; + + switch (System) { + case SYSTEM_PAL: Frequency = 49656530 / (Dacrate + 1); break; + case SYSTEM_MPAL: Frequency = 48628316 / (Dacrate + 1); break; + default: Frequency = 48681812 / (Dacrate + 1); break; + } + + //nBlockAlign = 16 / 8 * 2; + m_BytesPerSecond = Frequency * 4; + + if (System == SYSTEM_PAL) { + m_FramesPerSecond = 50.0; + } else { + m_FramesPerSecond = 60.0; + } +} diff --git a/Source/Project64/N64 System/Mips/Audio.h b/Source/Project64/N64 System/Mips/Audio.h index 0befffca0..12a3956c2 100644 --- a/Source/Project64/N64 System/Mips/Audio.h +++ b/Source/Project64/N64 System/Mips/Audio.h @@ -10,20 +10,21 @@ public: void TimerDone ( void ); void Reset ( void ); void SetViIntr ( DWORD VI_INTR_TIME ); + void SetFrequency ( DWORD Dacrate, DWORD System ); /* void AiCallBack ( void ); - void AiSetFrequency ( DWORD Dacrate, DWORD System ); void UpdateAudioTimer ( DWORD CountsPerFrame ); */ private: DWORD m_CurrentLength; DWORD m_SecondBuff; DWORD m_Status; + DWORD m_BytesPerSecond; double m_CountsPerByte; + int m_FramesPerSecond; /* float m_VSyncTiming; double m_FramesPerSecond; - DWORD m_BytesPerSecond; DWORD m_Length; DWORD m_CurrentCount; DWORD m_IntScheduled;*/ diff --git a/Source/Project64/N64 System/Mips/Dma.cpp b/Source/Project64/N64 System/Mips/Dma.cpp index e883e8a6e..552b5ddf5 100644 --- a/Source/Project64/N64 System/Mips/Dma.cpp +++ b/Source/Project64/N64 System/Mips/Dma.cpp @@ -8,11 +8,11 @@ CDMA::CDMA(CFlashram & FlashRam, CSram & Sram) : void CDMA::OnFirstDMA (void) { switch (_Rom->CicChipID()) { - case 1: *(DWORD *)&((_MMU->Rdram())[0x318]) = g_RdramSize; break; - case 2: *(DWORD *)&((_MMU->Rdram())[0x318]) = g_RdramSize; break; - case 3: *(DWORD *)&((_MMU->Rdram())[0x318]) = g_RdramSize; break; - case 5: *(DWORD *)&((_MMU->Rdram())[0x3F0]) = g_RdramSize; break; - case 6: *(DWORD *)&((_MMU->Rdram())[0x318]) = g_RdramSize; break; + case 1: *(DWORD *)&((_MMU->Rdram())[0x318]) = _MMU->RdramSize(); break; + case 2: *(DWORD *)&((_MMU->Rdram())[0x318]) = _MMU->RdramSize(); break; + case 3: *(DWORD *)&((_MMU->Rdram())[0x318]) = _MMU->RdramSize(); break; + case 5: *(DWORD *)&((_MMU->Rdram())[0x3F0]) = _MMU->RdramSize(); break; + case 6: *(DWORD *)&((_MMU->Rdram())[0x318]) = _MMU->RdramSize(); break; default: DisplayError("Unhandled CicChip(%d) in first DMA",_Rom->CicChipID()); } } @@ -20,7 +20,7 @@ void CDMA::OnFirstDMA (void) { void CDMA::PI_DMA_READ (void) { // PI_STATUS_REG |= PI_STATUS_DMA_BUSY; - if ( _Reg->PI_DRAM_ADDR_REG + _Reg->PI_RD_LEN_REG + 1 > g_RdramSize) { + if ( _Reg->PI_DRAM_ADDR_REG + _Reg->PI_RD_LEN_REG + 1 > _MMU->RdramSize()) { #ifndef EXTERNAL_RELEASE DisplayError("PI_DMA_READ not in Memory"); #endif @@ -76,9 +76,9 @@ void CDMA::PI_DMA_READ (void) { void CDMA::PI_DMA_WRITE (void) { _Reg->PI_STATUS_REG |= PI_STATUS_DMA_BUSY; - if ( _Reg->PI_DRAM_ADDR_REG + _Reg->PI_WR_LEN_REG + 1 > g_RdramSize) + if ( _Reg->PI_DRAM_ADDR_REG + _Reg->PI_WR_LEN_REG + 1 > _MMU->RdramSize()) { - if (g_ShowUnhandledMemory) { DisplayError("PI_DMA_WRITE not in Memory"); } + if (_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { DisplayError("PI_DMA_WRITE not in Memory"); } _Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; _Reg->MI_INTR_REG |= MI_INTR_PI; _Reg->CheckInterrupts(); @@ -157,7 +157,7 @@ void CDMA::PI_DMA_WRITE (void) { return; } - if (g_ShowUnhandledMemory) { DisplayError("PI_DMA_WRITE not in ROM"); } + if (_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { DisplayError("PI_DMA_WRITE not in ROM"); } _Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; _Reg->MI_INTR_REG |= MI_INTR_PI; _Reg->CheckInterrupts(); @@ -167,7 +167,7 @@ void CDMA::PI_DMA_WRITE (void) { void CDMA::SP_DMA_READ (void) { _Reg->SP_DRAM_ADDR_REG &= 0x1FFFFFFF; - if (_Reg->SP_DRAM_ADDR_REG > g_RdramSize) { + if (_Reg->SP_DRAM_ADDR_REG > _MMU->RdramSize()) { #ifndef EXTERNAL_RELEASE DisplayError("SP DMA\nSP_DRAM_ADDR_REG not in RDRam space"); #endif @@ -195,7 +195,7 @@ void CDMA::SP_DMA_READ (void) { } void CDMA::SP_DMA_WRITE (void) { - if (_Reg->SP_DRAM_ADDR_REG > g_RdramSize) { + if (_Reg->SP_DRAM_ADDR_REG > _MMU->RdramSize()) { #ifndef EXTERNAL_RELEASE DisplayError("SP DMA WRITE\nSP_DRAM_ADDR_REG not in RDRam space"); #endif diff --git a/Source/Project64/N64 System/Mips/Eeprom.cpp b/Source/Project64/N64 System/Mips/Eeprom.cpp index c5ae36273..97ff9a827 100644 --- a/Source/Project64/N64 System/Mips/Eeprom.cpp +++ b/Source/Project64/N64 System/Mips/Eeprom.cpp @@ -54,7 +54,7 @@ void CEeprom::EepromCommand ( BYTE * Command) { WriteTo(&Command[4],Command[3]); break; default: - if (g_ShowPifRamErrors) { DisplayError("Unkown EepromCommand %d",Command[2]); } + if (_Settings->LoadDword(Debugger_ShowPifErrors)) { DisplayError("Unknown EepromCommand %d",Command[2]); } } } diff --git a/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp b/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp index 536839a75..c342a417b 100644 --- a/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp +++ b/Source/Project64/N64 System/Mips/Memory Virtual Mem.cpp @@ -1838,8 +1838,11 @@ int CMipsMemoryVM::SB_NonMemory ( DWORD PAddr, BYTE Value ) { break; } #endif - if (PAddr < RdramSize()) { + if (PAddr < RdramSize()) + { + DWORD OldProtect; _Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF,0x1000,CRecompiler::Remove_ProtectedMem); + VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READWRITE, &OldProtect); *(BYTE *)(m_RDRAM+PAddr) = Value; } break; @@ -1873,7 +1876,9 @@ int CMipsMemoryVM::SH_NonMemory ( DWORD PAddr, WORD Value ) { } #endif if (PAddr < RdramSize()) { + DWORD OldProtect; _Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF,0x1000,CRecompiler::Remove_ProtectedMem); + VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READWRITE, &OldProtect); *(WORD *)(m_RDRAM+PAddr) = Value; } break; @@ -1923,7 +1928,9 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { } #endif if (PAddr < RdramSize()) { + DWORD OldProtect; _Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF,0x1000,CRecompiler::Remove_ProtectedMem); + VirtualProtect(m_RDRAM+(PAddr & ~0xFFF),0xFFC,PAGE_READWRITE, &OldProtect); *(DWORD *)(m_RDRAM+PAddr) = Value; } break; @@ -2154,12 +2161,10 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) { break; case 0x04500010: _Reg->AI_DACRATE_REG = Value; - DacrateChanged(g_SystemType); + _Plugins->Audio()->DacrateChanged(g_SystemType); if (g_FixedAudio) { -#ifdef tofix - g_Audio->AiSetFrequency(Value,g_SystemType); -#endif + _Audio->SetFrequency(Value,g_SystemType); } break; case 0x04500014: _Reg->AI_BITRATE_REG = Value; break; diff --git a/Source/Project64/N64 System/Mips/Sram.cpp b/Source/Project64/N64 System/Mips/Sram.cpp new file mode 100644 index 000000000..7351f2c5e --- /dev/null +++ b/Source/Project64/N64 System/Mips/Sram.cpp @@ -0,0 +1,68 @@ +#include "stdafx.h" + +CSram::CSram ( bool ReadOnly ) : + m_hFile(NULL), + m_ReadOnly(ReadOnly) +{ +} + +CSram::~CSram (void) +{ + if (m_hFile) { + CloseHandle(m_hFile); + m_hFile = NULL; + } +} + +BOOL CSram::LoadSram (void) { + CPath FileName; + + FileName.SetDriveDirectory( _Settings->LoadString(Directory_NativeSave).c_str()); + FileName.SetName(_Settings->LoadString(Game_GameName).c_str()); + FileName.SetExtension("sra"); + + if (!FileName.DirectoryExists()) + { + FileName.CreateDirectory(); + } + + m_hFile = CreateFile(FileName,m_ReadOnly ? GENERIC_READ : GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + if (m_hFile == INVALID_HANDLE_VALUE) + { + WriteTraceF(TraceError,"CEeprom::LoadSram: Failed to open (%s), ReadOnly = %d, LastError = %X",(LPCTSTR)FileName, m_ReadOnly, GetLastError()); + return false; + } + SetFilePointer(m_hFile,0,NULL,FILE_BEGIN); + return true; +} + +void CSram::DmaFromSram(BYTE * dest, int StartOffset, int len) { + DWORD dwRead; + + if (m_hFile == NULL) { + if (!LoadSram()) { + return; + } + } + SetFilePointer(m_hFile,StartOffset,NULL,FILE_BEGIN); + ReadFile(m_hFile,dest,len,&dwRead,NULL); + +} + +void CSram::DmaToSram(BYTE * Source, int StartOffset, int len) { + if (m_ReadOnly) + { + return; + } + + if (m_hFile == NULL) { + if (!LoadSram()) { + return; + } + } + DWORD dwWritten; + SetFilePointer(m_hFile,StartOffset,NULL,FILE_BEGIN); + WriteFile(m_hFile,Source,len,&dwWritten,NULL); + FlushFileBuffers(m_hFile); +} diff --git a/Source/Project64/N64 System/Mips/Sram.h b/Source/Project64/N64 System/Mips/Sram.h new file mode 100644 index 000000000..5fa7b27c0 --- /dev/null +++ b/Source/Project64/N64 System/Mips/Sram.h @@ -0,0 +1,15 @@ +class CSram +{ +public: + CSram ( bool ReadOnly ); + ~CSram ( void ); + + void DmaFromSram ( BYTE * dest, int StartOffset, int len); + void DmaToSram ( BYTE * Source, int StartOffset, int len); + +private: + BOOL LoadSram ( void ); + + bool m_ReadOnly; + HANDLE m_hFile; +}; \ No newline at end of file diff --git a/Source/Project64/N64 System/Mips/System Events.cpp b/Source/Project64/N64 System/Mips/System Events.cpp index 437258b5e..dbaf6a7ba 100644 --- a/Source/Project64/N64 System/Mips/System Events.cpp +++ b/Source/Project64/N64 System/Mips/System Events.cpp @@ -171,4 +171,40 @@ void CSystemEvents::ExecuteEvents ( void ) { PauseExecution(); } -} \ No newline at end of file +} + +void CSystemEvents::ChangePluginFunc ( void ) +{ + _Notify->DisplayMessage(0,MSG_PLUGIN_INIT); + if (_Settings->LoadBool(Plugin_GFX_Changed)) + { + _Plugins->Reset(PLUGIN_TYPE_GFX); + } + if (_Settings->LoadBool(Plugin_AUDIO_Changed)) + { + _Plugins->Reset(PLUGIN_TYPE_AUDIO); + } + if (_Settings->LoadBool(Plugin_CONT_Changed)) + { + _Plugins->Reset(PLUGIN_TYPE_CONTROLLER); + } + if (_Settings->LoadBool(Plugin_RSP_Changed) || + _Settings->LoadBool(Plugin_AUDIO_Changed) || + _Settings->LoadBool(Plugin_GFX_Changed)) + { + _Plugins->Reset(PLUGIN_TYPE_RSP); + } + _Settings->SaveBool(Plugin_RSP_Changed, false); + _Settings->SaveBool(Plugin_AUDIO_Changed,false); + _Settings->SaveBool(Plugin_GFX_Changed, false); + _Settings->SaveBool(Plugin_CONT_Changed, false); + _Notify->RefreshMenu(); + if (!_Plugins->Initiate()) + { + _Notify->DisplayMessage(5,MSG_PLUGIN_NOT_INIT); + _BaseSystem->m_EndEmulation = true; + } else { + //CC_Core::SetCurrentSystem(_N64System); + } + _Recompiler->ResetRecompCode(); +} diff --git a/Source/Project64/N64 System/Mips/System Events.h b/Source/Project64/N64 System/Mips/System Events.h index 7bea36411..afc6ec459 100644 --- a/Source/Project64/N64 System/Mips/System Events.h +++ b/Source/Project64/N64 System/Mips/System Events.h @@ -50,9 +50,8 @@ public: inline const BOOL & DoSomething ( void ) const { return m_bDoSomething; } - private: - + void ChangePluginFunc( void ); EventList m_Events; BOOL m_bDoSomething; diff --git a/Source/Project64/N64 System/Mips/TLB class.cpp b/Source/Project64/N64 System/Mips/TLB class.cpp index 9bc8c6d70..7556a0c5d 100644 --- a/Source/Project64/N64 System/Mips/TLB class.cpp +++ b/Source/Project64/N64 System/Mips/TLB class.cpp @@ -155,6 +155,10 @@ void CTLB::SetupTLB_Entry (int index, bool Random) { if (!m_tlb[index].EntryDefined) { return; } int FastIndx = index << 1; + if (m_FastTlb[FastIndx].VALID) + { + m_CB->TLB_Unmaped(m_FastTlb[FastIndx].VSTART,m_FastTlb[FastIndx].Length); + } m_FastTlb[FastIndx].Length = (m_tlb[index].PageMask.Mask << 12) + 0xFFF; m_FastTlb[FastIndx].VSTART=m_tlb[index].EntryHi.VPN2 << 13; m_FastTlb[FastIndx].VEND = m_FastTlb[FastIndx].VSTART + m_FastTlb[FastIndx].Length; @@ -169,6 +173,10 @@ void CTLB::SetupTLB_Entry (int index, bool Random) { FastIndx = (index << 1) + 1; + if (m_FastTlb[FastIndx].VALID) + { + m_CB->TLB_Unmaped(m_FastTlb[FastIndx].VSTART,m_FastTlb[FastIndx].Length); + } m_FastTlb[FastIndx].Length = (m_tlb[index].PageMask.Mask << 12) + 0xFFF; m_FastTlb[FastIndx].VSTART=(m_tlb[index].EntryHi.VPN2 << 13) + (m_FastTlb[FastIndx].Length + 1); m_FastTlb[FastIndx].VEND = m_FastTlb[FastIndx].VSTART + m_FastTlb[FastIndx].Length; diff --git a/Source/Project64/N64 System/N64 Class.cpp b/Source/Project64/N64 System/N64 Class.cpp index 6a29ef075..dfb1c8329 100644 --- a/Source/Project64/N64 System/N64 Class.cpp +++ b/Source/Project64/N64 System/N64 Class.cpp @@ -20,7 +20,7 @@ void InitializeCPUCore ( void ) break; } #ifndef EXTERNAL_RELEASE - LogOptions.GenerateLog = g_GenerateLog; + LogOptions.GenerateLog = _Settings->LoadDword(Debugger_GenerateDebugLog); LoadLogOptions(&LogOptions, FALSE); StartLog(); #endif @@ -89,7 +89,6 @@ void CN64System::ExternalEvent ( SystemEvent action ) case SysEvent_PauseCPU_LoadGame: case SysEvent_PauseCPU_DumpMemory: case SysEvent_PauseCPU_SearchMemory: - break; if (!_Settings->LoadBool(GameRunning_CPU_Paused)) { QueueEvent(action); @@ -321,24 +320,20 @@ void CN64System::StartEmulation2 ( bool NewThread ) _Notify->HideRomBrowser(); //RefreshSettings(); - WriteTrace(TraceDebug,"CN64System::StartEmulation2: Reseting Plugins"); - _Notify->DisplayMessage(5,MSG_PLUGIN_INIT); - _Plugins->Reset(); - if (!_Plugins->Initiate()) + if (!SetActiveSystem()) { - WriteTrace(TraceError,"CN64System::StartEmulation2: _Plugins->Initiate Failed"); _Settings->SaveBool(GameRunning_LoadingInProgress,false); _Notify->DisplayError(MSG_PLUGIN_NOT_INIT); + //Set handle to NULL so this thread is not terminated - m_CPU_Handle = NULL; + m_CPU_Handle = NULL; m_CPU_ThreadID = 0; - // Reset(); _Notify->RefreshMenu(); _Notify->ShowRomBrowser(); - return; } + _Notify->MakeWindowOnTop(_Settings->LoadBool(UserInterface_AlwaysOnTop)); if (!_Settings->LoadBool(Beta_IsValidExe)) { @@ -515,6 +510,11 @@ void CN64System::Reset (bool bInitReg, bool ClearMenory) m_SystemTimer.Reset(); m_SystemTimer.SetTimer(CSystemTimer::CompareTimer,m_Reg.COMPARE_REGISTER - m_Reg.COUNT_REGISTER,false); + for (int i = 0, n = (sizeof(m_LastSuccessSyncPC)/sizeof(m_LastSuccessSyncPC[0])); i < n; i++) + { + m_LastSuccessSyncPC[i] = 0; + } + if (bInitReg) { bool PostPif = true; @@ -530,6 +530,7 @@ void CN64System::Reset (bool bInitReg, bool ClearMenory) bool CN64System::SetActiveSystem( bool bActive ) { bool bInitPlugin = false; + bool bRes = true; if (bActive) { @@ -580,9 +581,16 @@ bool CN64System::SetActiveSystem( bool bActive ) if (bInitPlugin) { - _Plugins->Initiate(); + WriteTrace(TraceDebug,"CN64System::SetActiveSystem: Reseting Plugins"); + _Notify->DisplayMessage(5,MSG_PLUGIN_INIT); + _Plugins->Reset(); + bRes = _Plugins->Initiate(); + if (!bRes) + { + WriteTrace(TraceError,"CN64System::SetActiveSystem: _Plugins->Initiate Failed"); + } } - return true; + return bRes; } void CN64System::InitRegisters( bool bPostPif, CMipsMemory & MMU ) diff --git a/Source/Project64/N64 System/N64 Rom Class.cpp b/Source/Project64/N64 System/N64 Rom Class.cpp index 9e4a7123f..305d213aa 100644 --- a/Source/Project64/N64 System/N64 Rom Class.cpp +++ b/Source/Project64/N64 System/N64 Rom Class.cpp @@ -322,9 +322,6 @@ bool CN64Rom::LoadN64Image ( const char * FileLoc, bool LoadBootCodeOnly ) { return false; } - //Store info about 7z for rom browser - CRomBrowser::Store7ZipInfo(_Settings,ZipFile,i); - //save information about the rom loaded m_ROMImage = Image; m_RomFileSize = RomFileSize; diff --git a/Source/Project64/N64 System/Recompiler/Code Section.cpp b/Source/Project64/N64 System/Recompiler/Code Section.cpp index c98856439..f03bc8b6d 100644 --- a/Source/Project64/N64 System/Recompiler/Code Section.cpp +++ b/Source/Project64/N64 System/Recompiler/Code Section.cpp @@ -676,12 +676,13 @@ bool CCodeSection::GenerateX86Code ( DWORD Test ) { m_BlockInfo->SetVAddrLast(m_CompilePC); } - /*if (m_CompilePC == 0x8031E02C) + /*if (m_CompilePC == 0xF000044) { X86BreakPoint(__FILE__,__LINE__); //m_RegWorkingSet.UnMap_AllFPRs(); - } - /*if (m_CompilePC >= 0x8031DF84 && m_CompilePC <= 0x8031E034 && m_NextInstruction == NORMAL) + }*/ + + if (m_CompilePC >= 0x0F000000 && m_CompilePC <= 0x0F000048 && m_NextInstruction == NORMAL) { m_RegWorkingSet.WriteBackRegisters(); UpdateCounters(m_RegWorkingSet,false,true); diff --git a/Source/Project64/N64 System/Recompiler/Function Map Class.cpp b/Source/Project64/N64 System/Recompiler/Function Map Class.cpp index 0fb8a18ef..684c5becf 100644 --- a/Source/Project64/N64 System/Recompiler/Function Map Class.cpp +++ b/Source/Project64/N64 System/Recompiler/Function Map Class.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" CFunctionMap::CFunctionMap() : + m_JumpTable(NULL), m_FunctionTable(NULL), m_DelaySlotTable(NULL) { @@ -13,25 +14,46 @@ CFunctionMap::~CFunctionMap() bool CFunctionMap::AllocateMemory() { - if (m_FunctionTable == NULL) + if (_Recompiler->LookUpMode() == FuncFind_VirtualLookup) { - m_FunctionTable = (PCCompiledFunc_TABLE *)VirtualAlloc(NULL,0xFFFFF * sizeof(CCompiledFunc *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); - if (m_FunctionTable == NULL) { - WriteTrace(TraceError,"CFunctionMap::AllocateMemory: failed to allocate function table"); + if (m_FunctionTable == NULL) + { + m_FunctionTable = (PCCompiledFunc_TABLE *)VirtualAlloc(NULL,0xFFFFF * sizeof(CCompiledFunc *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); + if (m_FunctionTable == NULL) { + WriteTrace(TraceError,"CFunctionMap::AllocateMemory: failed to allocate function table"); + _Notify->FatalError(MSG_MEM_ALLOC_ERROR); + return false; + } + memset(m_FunctionTable,0,0xFFFFF * sizeof(CCompiledFunc *)); + } + if (m_DelaySlotTable == NULL) + { + m_DelaySlotTable = (BYTE **)VirtualAlloc(NULL,0xFFFFF * sizeof(BYTE *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); + if (m_DelaySlotTable == NULL) { + WriteTrace(TraceError,"CFunctionMap::AllocateMemory: failed to allocate delay slot table"); + _Notify->FatalError(MSG_MEM_ALLOC_ERROR); + return false; + } + memset(m_DelaySlotTable,0,0xFFFFF * sizeof(BYTE *)); + } + } + if (_Recompiler->LookUpMode() == FuncFind_PhysicalLookup) + { + m_JumpTable = new PCCompiledFunc[_MMU->RdramSize() >> 2]; + if (m_JumpTable == NULL) { + WriteTrace(TraceError,"CFunctionMap::AllocateMemory: failed to allocate jump table"); _Notify->FatalError(MSG_MEM_ALLOC_ERROR); return false; } - memset(m_FunctionTable,0,0xFFFFF * sizeof(CCompiledFunc *)); - } - if (m_DelaySlotTable == NULL) - { - m_DelaySlotTable = (BYTE **)VirtualAlloc(NULL,0xFFFFF * sizeof(BYTE *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); + memset(m_JumpTable,0,(_MMU->RdramSize() >> 2) * sizeof(PCCompiledFunc)); + + m_DelaySlotTable = (BYTE **)VirtualAlloc(NULL,(_MMU->RdramSize() >> 0xC) * sizeof(BYTE *),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); if (m_DelaySlotTable == NULL) { WriteTrace(TraceError,"CFunctionMap::AllocateMemory: failed to allocate delay slot table"); _Notify->FatalError(MSG_MEM_ALLOC_ERROR); return false; } - memset(m_DelaySlotTable,0,0xFFFFF * sizeof(BYTE *)); + memset(m_DelaySlotTable,0,(_MMU->RdramSize() >> 0xC) * sizeof(BYTE *)); } return true; } @@ -55,6 +77,11 @@ void CFunctionMap::CleanBuffers ( void ) VirtualFree( m_DelaySlotTable, 0 , MEM_RELEASE); m_DelaySlotTable = NULL; } + if (m_JumpTable) + { + delete [] m_JumpTable; + m_JumpTable = NULL; + } } void CFunctionMap::Reset ( void ) diff --git a/Source/Project64/N64 System/Recompiler/Function Map Class.h b/Source/Project64/N64 System/Recompiler/Function Map Class.h index 987f47a36..ea0632f1c 100644 --- a/Source/Project64/N64 System/Recompiler/Function Map Class.h +++ b/Source/Project64/N64 System/Recompiler/Function Map Class.h @@ -12,11 +12,13 @@ protected: public: inline PCCompiledFunc_TABLE * FunctionTable ( void ) const { return m_FunctionTable; } + inline PCCompiledFunc * JumpTable ( void ) const { return m_JumpTable; } inline BYTE ** DelaySlotTable ( void ) const { return m_DelaySlotTable; } private: void CleanBuffers ( void ); + PCCompiledFunc * m_JumpTable; PCCompiledFunc_TABLE * m_FunctionTable; BYTE ** m_DelaySlotTable; }; diff --git a/Source/Project64/N64 System/Recompiler/Recompiler Class.cpp b/Source/Project64/N64 System/Recompiler/Recompiler Class.cpp index 88fa997af..9465bbec6 100644 --- a/Source/Project64/N64 System/Recompiler/Recompiler Class.cpp +++ b/Source/Project64/N64 System/Recompiler/Recompiler Class.cpp @@ -25,6 +25,11 @@ void CRecompiler::Run() WriteTrace(TraceError,"CRecompiler::Run: CRecompMemory::AllocateMemory failed"); return; } + if (!CFunctionMap::AllocateMemory()) + { + WriteTrace(TraceError,"CRecompiler::Run: CFunctionMap::AllocateMemory failed"); + return; + } m_EndEmulation = false; WriteTrace(TraceError,"CRecompiler::Run Fix g_MemoryStack"); @@ -34,11 +39,6 @@ void CRecompiler::Run() __try { if (LookUpMode() == FuncFind_VirtualLookup) { - if (!CFunctionMap::AllocateMemory()) - { - WriteTrace(TraceError,"CRecompiler::Run: CFunctionMap::AllocateMemory failed"); - return; - } if (bSMM_ValidFunc()) { RecompilerMain_VirtualTable_validate(); @@ -290,8 +290,94 @@ void CRecompiler::RecompilerMain_VirtualTable_validate ( void ) void CRecompiler::RecompilerMain_Lookup( void ) { - _Notify->BreakPoint(__FILE__,__LINE__); + DWORD PhysicalAddr; + CInterpreterCPU::BuildCPU(); + if (g_UseTlb) + { + while(!m_EndEmulation) + { + if (!_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr)) + { + _Reg->DoTLBMiss(false,PROGRAM_COUNTER); + if (!_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr)) + { + DisplayError("Failed to tranlate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER); + m_EndEmulation = true; + } + continue; + } + if (PhysicalAddr < RdramSize()) + { + CCompiledFunc * info = JumpTable()[PhysicalAddr >> 2]; + if (info == NULL) + { + info = CompilerCode(); + if (info == NULL || m_EndEmulation) + { + break; + } + if (bSMM_Protect()) + { + _MMU->ProtectMemory(PROGRAM_COUNTER & ~0xFFF,PROGRAM_COUNTER | 0xFFF); + } + JumpTable()[PhysicalAddr >> 2] = info; + } + (info->Function())(); + } else { + DWORD opsExecuted = 0; + + while (_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= RdramSize()) + { + CInterpreterCPU::ExecuteOps(CountPerOp()); + opsExecuted += CountPerOp(); + } + + if (_SyncSystem) + { + _System->UpdateSyncCPU(_SyncSystem,opsExecuted); + _System->SyncCPU(_SyncSystem); + } + } + } + } else { + while(!m_EndEmulation) + { + PhysicalAddr = PROGRAM_COUNTER & 0x1FFFFFFF; + if (PhysicalAddr < RdramSize()) + { + CCompiledFunc * info = JumpTable()[PhysicalAddr >> 2]; + if (info == NULL) + { + info = CompilerCode(); + if (info == NULL || m_EndEmulation) + { + break; + } + if (bSMM_Protect()) + { + _MMU->ProtectMemory(PROGRAM_COUNTER & ~0xFFF,PROGRAM_COUNTER | 0xFFF); + } + JumpTable()[PhysicalAddr >> 2] = info; + } + (info->Function())(); + } else { + DWORD opsExecuted = 0; + + while (_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= RdramSize()) + { + CInterpreterCPU::ExecuteOps(CountPerOp()); + opsExecuted += CountPerOp(); + } + + if (_SyncSystem) + { + _System->UpdateSyncCPU(_SyncSystem,opsExecuted); + _System->SyncCPU(_SyncSystem); + } + } + } + } /* DWORD Addr; CCompiledFunc * Info; @@ -465,32 +551,68 @@ void CRecompiler::ResetRecompCode() BYTE * CRecompiler::CompileDelaySlot(DWORD PC) { - int Index = PC >> 0xC; - BYTE * delayFunc = DelaySlotTable()[Index]; - if (delayFunc) + if (LookUpMode() == FuncFind_VirtualLookup) { + int Index = PC >> 0xC; + BYTE * delayFunc = DelaySlotTable()[Index]; + if (delayFunc) + { + return delayFunc; + } + + WriteTraceF(TraceRecompiler,"Compile Delay Slot: %X",PC); + if ((PC & 0xFFC) != 0) { + DisplayError("Why are you compiling the Delay Slot at %X",PC); + return NULL; + } + + CheckRecompMem(); + + CCodeBlock CodeBlock(PC, RecompPos(), true); + if (!CodeBlock.Compile()) + { + return NULL; + } + + CCompiledFunc * Func = new CCompiledFunc(CodeBlock); + delayFunc = (BYTE *)Func->Function(); + DelaySlotTable()[Index] = delayFunc; + delete Func; return delayFunc; - } - - WriteTraceF(TraceRecompiler,"Compile Delay Slot: %X",PC); - if ((PC & 0xFFC) != 0) { - DisplayError("Why are you compiling the Delay Slot at %X",PC); + } else { + DWORD pAddr; + if (_TransVaddr->TranslateVaddr(PC,pAddr)) + { + int Index = pAddr >> 0xC; + BYTE * delayFunc = DelaySlotTable()[Index]; + if (delayFunc) + { + return delayFunc; + } + WriteTraceF(TraceRecompiler,"Compile Delay Slot: %X",pAddr); + if ((pAddr & 0xFFC) != 0) { + DisplayError("Why are you compiling the Delay Slot at %X",pAddr); + return NULL; + } + + CheckRecompMem(); + + CCodeBlock CodeBlock(PC, RecompPos(), true); + if (!CodeBlock.Compile()) + { + return NULL; + } + + CCompiledFunc * Func = new CCompiledFunc(CodeBlock); + delayFunc = (BYTE *)Func->Function(); + DelaySlotTable()[Index] = delayFunc; + delete Func; + return delayFunc; + } else { + _Notify->BreakPoint(__FILE__,__LINE__); + } return NULL; } - - CheckRecompMem(); - - CCodeBlock CodeBlock(PC, RecompPos(), true); - if (!CodeBlock.Compile()) - { - return NULL; - } - - CCompiledFunc * Func = new CCompiledFunc(CodeBlock); - delayFunc = (BYTE *)Func->Function(); - DelaySlotTable()[Index] = delayFunc; - delete Func; - return delayFunc; } bool CRecompiler::AnalyseBlock ( CCodeBlock & BlockInfo) @@ -1831,17 +1953,17 @@ void CRecompiler::ClearRecompCode_Phys(DWORD Address, int length, REMOVE_REASON } } } -#ifdef tofix else if (LookUpMode() == FuncFind_PhysicalLookup) { WriteTraceF(TraceRecompiler,"Reseting Jump Table, Addr: %X len: %d",Address,((length + 3) & ~3)); - memset((BYTE *)JumpTable + Address,0,((length + 3) & ~3)); + memset((BYTE *)JumpTable() + Address,0,((length + 3) & ~3)); } -#endif } void CRecompiler::ClearRecompCode_Virt(DWORD Address, int length,REMOVE_REASON Reason ) { + //WriteTraceF(TraceError,"CRecompiler::ClearRecompCode_Virt Not Implemented (Address: %X, Length: %d Reason: %d)",Address,length,Reason); + switch (LookUpMode()) { case FuncFind_VirtualLookup: @@ -1878,42 +2000,16 @@ void CRecompiler::ClearRecompCode_Virt(DWORD Address, int length,REMOVE_REASON R } } break; + case FuncFind_PhysicalLookup: + { + DWORD pAddr = 0; + if (_TransVaddr->TranslateVaddr(Address,pAddr)) + { + ClearRecompCode_Phys(pAddr,length,Reason); + } + } + break; + default: + _Notify->BreakPoint(__FILE__,__LINE__); } - //WriteTraceF(TraceError,"CRecompiler::ClearRecompCode_Virt Not Implemented (Address: %X, Length: %d Reason: %d)",Address,length,Reason); - -/* CCompiledFunc * info; - do - { - info = m_Functions.FindFunction(Address,length); - if (info) - { - RemoveFunction(info,false,Reason); - } - } while (info != NULL); - do - { - info = m_FunctionsDelaySlot.FindFunction(Address,length); - if (info) - { - RemoveFunction(info,true,Reason); - } - } while (info != NULL); - - if (bSMM_Protect()) - { - DWORD Start = Address & ~0xFFF; - info = m_Functions.FindFunction(Start,0xFFF); - if (info) - { - WriteTraceF(TraceDebug,"Function exists at %X End: %X",info->VStartPC(),info->VEndPC()); - return false; - } - info = m_FunctionsDelaySlot.FindFunction(Start,0xFFF); - if (info) - { - WriteTraceF(TraceDebug,"Delay function exists at %X End: %X",info->VStartPC(),info->VEndPC()); - return false; - } - return true; - }*/ } diff --git a/Source/Project64/N64 System/Recompiler/Recompiler Ops.cpp b/Source/Project64/N64 System/Recompiler/Recompiler Ops.cpp index c85018565..869d116e1 100644 --- a/Source/Project64/N64 System/Recompiler/Recompiler Ops.cpp +++ b/Source/Project64/N64 System/Recompiler/Recompiler Ops.cpp @@ -4651,8 +4651,6 @@ void CRecompilerOps::COP1_L_CVT_S (void) { } void CRecompilerOps::COP1_L_CVT_D (void) { - _Notify->BreakPoint(__FILE__,__LINE__); -#ifdef tofix CPU_Message(" %X %s",m_CompilePC,R4300iOpcodeName(m_Opcode.Hex,m_CompilePC)); m_Section->CompileCop1Test(); @@ -4660,7 +4658,6 @@ void CRecompilerOps::COP1_L_CVT_D (void) { Load_FPR_ToTop(m_Opcode.fd,m_Opcode.fs,CRegInfo::FPU_Qword); } ChangeFPURegFormat(m_Opcode.fd,CRegInfo::FPU_Qword,CRegInfo::FPU_Double,CRegInfo::RoundDefault); -#endif } /************************** Other functions **************************/ diff --git a/Source/Project64/Plugins/Plugin Class.cpp b/Source/Project64/Plugins/Plugin Class.cpp index 402f6c3ad..580321c6b 100644 --- a/Source/Project64/Plugins/Plugin Class.cpp +++ b/Source/Project64/Plugins/Plugin Class.cpp @@ -196,9 +196,9 @@ void CPlugins::Reset ( PLUGIN_TYPE Type ) } { m_RSPFile = _Settings->LoadString(Plugin_RSP_Current); - stdstr_f RspPluginFile("%s%s",m_PluginDir.c_str(),m_RSPFile.c_str()); - WriteTraceF(TraceRSP,"Loading (%s): Starting",RspPluginFile.c_str()); - m_RSP = new CRSP_Plugin(RspPluginFile.c_str()); + CPath RspPluginFile(m_PluginDir.c_str(),m_RSPFile.c_str()); + WriteTraceF(TraceRSP,"Loading (%s): Starting",(LPCTSTR)RspPluginFile); + m_RSP = new CRSP_Plugin(RspPluginFile); WriteTrace(TraceRSP,"Loading Done"); } @@ -226,9 +226,9 @@ void CPlugins::Reset ( PLUGIN_TYPE Type ) } { m_GfxFile = _Settings->LoadString(Game_Plugin_Gfx); - stdstr_f GfxPluginFile("%s%s",m_PluginDir.c_str(),m_GfxFile.c_str()); - WriteTraceF(TraceGfxPlugin,"Loading (%s): Starting",GfxPluginFile.c_str()); - m_Gfx = new CGfxPlugin(GfxPluginFile.c_str()); + CPath GfxPluginFile(m_PluginDir.c_str(),m_GfxFile.c_str()); + WriteTraceF(TraceGfxPlugin,"Loading (%s): Starting",(LPCTSTR)GfxPluginFile); + m_Gfx = new CGfxPlugin(GfxPluginFile); WriteTrace(TraceGfxPlugin,"Loading Done"); } WriteTraceF(TraceGfxPlugin,"Current Ver: %s",m_Gfx->PluginName().c_str()); @@ -246,9 +246,9 @@ void CPlugins::Reset ( PLUGIN_TYPE Type ) } { m_AudioFile = _Settings->LoadString(Game_Plugin_Audio); - stdstr_f PluginFile("%s%s",m_PluginDir.c_str(),m_AudioFile.c_str()); - WriteTraceF(TraceDebug,"Loading (%s): Starting",PluginFile.c_str()); - m_Audio = new CAudioPlugin(PluginFile.c_str()); + CPath PluginFile(m_PluginDir.c_str(),m_AudioFile.c_str()); + WriteTraceF(TraceDebug,"Loading (%s): Starting",(LPCTSTR)PluginFile); + m_Audio = new CAudioPlugin(PluginFile); WriteTrace(TraceDebug,"Loading Done"); _Settings->SaveString(Plugin_AUDIO_CurVer,m_Audio->PluginName().c_str()); } @@ -265,9 +265,9 @@ void CPlugins::Reset ( PLUGIN_TYPE Type ) } { m_ControlFile = _Settings->LoadString(Game_Plugin_Controller); - stdstr_f PluginFile("%s%s",m_PluginDir.c_str(),m_ControlFile.c_str()); - WriteTraceF(TraceDebug,"Loading (%s): Starting",PluginFile.c_str()); - m_Control = new CControl_Plugin(PluginFile.c_str()); + CPath PluginFile(m_PluginDir.c_str(),m_ControlFile.c_str()); + WriteTraceF(TraceDebug,"Loading (%s): Starting",(LPCTSTR)PluginFile); + m_Control = new CControl_Plugin(PluginFile); WriteTrace(TraceDebug,"Loading Done"); _Settings->SaveString(Plugin_CONT_CurVer,m_Control->PluginName().c_str()); } diff --git a/Source/Project64/Project64.dsp b/Source/Project64/Project64.dsp index 458d38fe8..c3347745a 100644 --- a/Source/Project64/Project64.dsp +++ b/Source/Project64/Project64.dsp @@ -1380,9 +1380,5 @@ SOURCE="..\Bin\Release\Sync Errors.txt" # End Source File # End Group # End Group -# Begin Source File - -SOURCE=".\User Interface\about.htm" -# End Source File # End Target # End Project diff --git a/Source/Project64/Settings/SettingType/SettingsType-Application.cpp b/Source/Project64/Settings/SettingType/SettingsType-Application.cpp index aecf87031..824b6d65a 100644 --- a/Source/Project64/Settings/SettingType/SettingsType-Application.cpp +++ b/Source/Project64/Settings/SettingType/SettingsType-Application.cpp @@ -72,6 +72,13 @@ void CSettingTypeApplication::Initilize( const char * AppName ) m_UseRegistry = _Settings->LoadBool(Setting_UseFromRegistry); } +void CSettingTypeApplication::Flush() +{ + if (m_SettingsIniFile) + { + m_SettingsIniFile->FlushChanges(); + } +} void CSettingTypeApplication::CleanUp() { diff --git a/Source/Project64/Settings/SettingType/SettingsType-Application.h b/Source/Project64/Settings/SettingType/SettingsType-Application.h index 72835f95f..14d49cf88 100644 --- a/Source/Project64/Settings/SettingType/SettingsType-Application.h +++ b/Source/Project64/Settings/SettingType/SettingsType-Application.h @@ -51,6 +51,7 @@ public: // Initilize this class to use ini or registry static void Initilize ( const char * AppName ); static void CleanUp ( void ); + static void Flush ( void ); LPCSTR GetKeyName ( void) const { return m_KeyName.c_str(); } }; diff --git a/Source/Project64/User Interface/Gui Class.cpp b/Source/Project64/User Interface/Gui Class.cpp index 025ac3ee0..a8e079135 100644 --- a/Source/Project64/User Interface/Gui Class.cpp +++ b/Source/Project64/User Interface/Gui Class.cpp @@ -375,10 +375,18 @@ void CMainGui::SetPos (int X, int Y) { } void CMainGui::SetWindowMenu (CBaseMenu * Menu) { - CGuard Guard(m_CS); - m_Menu = Menu; - HMENU hMenu = (HMENU)Menu->GetHandle(); - SetMenu((HWND)m_hMainWindow,hMenu); + HMENU hMenu = NULL; + + { + CGuard Guard(m_CS); + m_Menu = Menu; + hMenu = (HMENU)Menu->GetHandle(); + } + + if (hMenu) + { + SetMenu((HWND)m_hMainWindow,hMenu); + } } void CMainGui::RefreshMenu (void) { diff --git a/Source/Project64/User Interface/Main Menu Class.cpp b/Source/Project64/User Interface/Main Menu Class.cpp index 7d104bc35..439701cdf 100644 --- a/Source/Project64/User Interface/Main Menu Class.cpp +++ b/Source/Project64/User Interface/Main Menu Class.cpp @@ -1158,10 +1158,13 @@ void CMainMenu::RebuildAccelerators(void) { } void CMainMenu::ResetMenu(void) { - CGuard Guard(m_CS); WriteTrace(TraceDebug,"CMainMenu::ResetMenu - Start"); - m_ShortCuts.Load(); + { + CGuard Guard(m_CS); + m_ShortCuts.Load(); + } + if (!_Settings->LoadBool(UserInterface_InFullScreen)) { //Create a new window with all the items @@ -1171,11 +1174,15 @@ void CMainMenu::ResetMenu(void) { WriteTrace(TraceDebug,"CMainMenu::ResetMenu - Create Menu Done"); //save old menu to destroy latter - MENU_HANDLE OldMenuHandle = m_MenuHandle; + MENU_HANDLE OldMenuHandle; + { + CGuard Guard(m_CS); + OldMenuHandle = m_MenuHandle; - //save handle and re-attach to a window - WriteTrace(TraceDebug,"CMainMenu::ResetMenu - Attach Menu"); - m_MenuHandle = hMenu; + //save handle and re-attach to a window + WriteTrace(TraceDebug,"CMainMenu::ResetMenu - Attach Menu"); + m_MenuHandle = hMenu; + } _Gui->SetWindowMenu(this); WriteTrace(TraceDebug,"CMainMenu::ResetMenu - Remove plugin menu"); diff --git a/Source/Project64/User Interface/Rom Browser Class.cpp b/Source/Project64/User Interface/Rom Browser Class.cpp index 20cf03acb..028cc9bd7 100644 --- a/Source/Project64/User Interface/Rom Browser Class.cpp +++ b/Source/Project64/User Interface/Rom Browser Class.cpp @@ -708,6 +708,8 @@ void CRomBrowser::FillRomList ( strlist & FileList, CPath & BaseDirectory, stdst } } while (SearchPath.FindNext()); + + m_ZipIniFile->FlushChanges(); } int CRomBrowser::GetCicChipID (BYTE * RomData) { @@ -1436,12 +1438,6 @@ void CRomBrowser::SaveRomList ( strlist & FileList ) { MD5 ListHash = RomListHash(FileList); -/* stdstr FileName = _Settings->LoadString(RomListCache); - - FileList.ToLower(); - WriteTraceF(TraceDebug,"SaveRomList: %s",FileList.c_str()); - MD5 md5((const unsigned char *)FileList.c_str(), FileList.length()); -*/ stdstr FileName = _Settings->LoadString(SupportFile_RomListCache); HANDLE hFile = CreateFile(FileName.c_str(),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); @@ -1786,47 +1782,3 @@ void CRomBrowser::WatchThreadStop( void ) } -void CRomBrowser::Store7ZipInfo (CSettings * Settings, C7zip & ZipFile, int FileNo ) -{ - // if we have information about this file already then leave this function - CIniFile zipInfo(Settings->LoadString(SupportFile_7zipCache).c_str()); - CFileItem * cf = ZipFile.FileItem(FileNo); - - char FileName[260]; - stdstr_f SectionName("%s-%d",ZipFile.FileName(FileName,sizeof(FileName)),ZipFile.FileSize()); - SectionName.ToLower(); - - char Header[0x80]; - if (zipInfo.GetString(SectionName.c_str(),cf->Name,"",Header,sizeof(Header)) > 0) - { - return; - } - - // Gather all information that is in relation to this file - for (int i = 0; i < ZipFile.NumFiles(); i++) - { - CFileItem * f = ZipFile.FileItem(i); - - BYTE RomData[0x1000]; - ZipFile.GetFile(i,RomData,sizeof(RomData)); - - if (!IsValidRomImage(RomData)) { continue; } - ByteSwapRomData(RomData,sizeof(RomData)); - - stdstr RomHeader; - for (int x = 0; x < 0x40; x += 4) - { - RomHeader += stdstr_f("%08X",*((DWORD *)&RomData[x])); - } - int CicChip = GetCicChipID(RomData); - - //save this info - zipInfo.SaveString(SectionName.c_str(),f->Name,RomHeader.c_str()); - zipInfo.SaveNumber(SectionName.c_str(),stdstr_f("%s-Cic",f->Name).c_str(),CicChip); - - } - - //delete cache - stdstr CacheFileName = Settings->LoadString(SupportFile_RomListCache); - DeleteFile(CacheFileName.c_str()); -} diff --git a/Source/Project64/User Interface/Rom Browser.h b/Source/Project64/User Interface/Rom Browser.h index 5896a42c6..8242ca328 100644 --- a/Source/Project64/User Interface/Rom Browser.h +++ b/Source/Project64/User Interface/Rom Browser.h @@ -198,7 +198,7 @@ public: void ShowRomList ( void ); bool ShowingRomBrowser ( void ) { return m_ShowingRomBrowser; } LPCSTR CurrentedSelectedRom ( void ) { return m_SelectedRom.c_str(); } - static void Store7ZipInfo ( CSettings * Settings, C7zip & ZipFile, int FileNo ); + void Store7ZipInfo ( C7zip & ZipFile, int FileNo ); static void GetFieldInfo ( ROMBROWSER_FIELDS_LIST & Fields, bool UseDefault = false ); }; \ No newline at end of file diff --git a/Source/Project64/User Interface/Settings Config.cpp b/Source/Project64/User Interface/Settings Config.cpp index cfee80a4c..ed65e5acc 100644 --- a/Source/Project64/User Interface/Settings Config.cpp +++ b/Source/Project64/User Interface/Settings Config.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "Settings Config.h" #include "Settings/Settings Page.h" +#include "Settings/SettingType/SettingsType-Application.h" CSettingConfig::CSettingConfig(bool bJustGameSetting /* = false */) : m_CurrentPage(NULL), @@ -200,7 +201,8 @@ void CSettingConfig::ApplySettings( bool UpdateScreen ) ::EnableWindow(GetDlgItem(IDAPPLY),false); ::EnableWindow(GetDlgItem(IDC_RESET_PAGE), m_CurrentPage->EnableReset()); } - + + CSettingTypeApplication::Flush(); } LRESULT CSettingConfig::OnPageListItemChanged(NMHDR* phdr)