diff --git a/Config/Project64.rdb b/Config/Project64.rdb index e8b6e31af..c8aa698bd 100644 --- a/Config/Project64.rdb +++ b/Config/Project64.rdb @@ -2493,7 +2493,6 @@ Clear Frame=2 Culling=1 FuncFind=2 RDRAM Size=4 -Rom In Memory=1 SMM-Cache=0 SMM-FUNC=0 SMM-PI DMA=0 diff --git a/Source/Android/Bridge/jniBridgeSettings.cpp b/Source/Android/Bridge/jniBridgeSettings.cpp index 9d15dc1da..2fadbf53c 100644 --- a/Source/Android/Bridge/jniBridgeSettings.cpp +++ b/Source/Android/Bridge/jniBridgeSettings.cpp @@ -103,7 +103,6 @@ CJniBridegSettings::CJniBridegSettings() ADD_SETTING(Rdb_TLB_PAddrStart); ADD_SETTING(Rdb_UseHleGfx); ADD_SETTING(Rdb_UseHleAudio); - ADD_SETTING(Rdb_LoadRomToMemory); ADD_SETTING(Rdb_ScreenHertz); ADD_SETTING(Rdb_FuncLookupMode); ADD_SETTING(Rdb_RegCache); @@ -166,7 +165,6 @@ CJniBridegSettings::CJniBridegSettings() ADD_SETTING(Game_RspAudioSignal); ADD_SETTING(Game_UseHleGfx); ADD_SETTING(Game_UseHleAudio); - ADD_SETTING(Game_LoadRomToMemory); ADD_SETTING(Game_ViRefreshRate); ADD_SETTING(Game_AiCountPerBytes); ADD_SETTING(Game_AudioResetOnLoad); diff --git a/Source/Project64-core/Logging.cpp b/Source/Project64-core/Logging.cpp index 206ed56c5..25aec82df 100644 --- a/Source/Project64-core/Logging.cpp +++ b/Source/Project64-core/Logging.cpp @@ -42,7 +42,8 @@ void CLogging::Log_LW(uint32_t PC, uint32_t VAddr) (VAddr >= 0xA4400000 && VAddr <= 0xA4400034) || (VAddr >= 0xA4500000 && VAddr <= 0xA4500014) || (VAddr == 0xA4800000 && VAddr <= 0xA4800018) || - (VAddr >= 0xBFC00000 && VAddr <= 0xBFC007C0)) + (VAddr >= 0xBFC00000 && VAddr <= 0xBFC007C0) || + (VAddr >= 0xB0000000 && ((VAddr - 0xB0000000) < g_Rom->GetRomSize()))) { return; } @@ -56,29 +57,6 @@ void CLogging::Log_LW(uint32_t PC, uint32_t VAddr) LogMessage("%08X: read word from PIF RAM at 0x%X (%08X)", PC, VAddr - 0xBFC007C0, Value); return; } - if (VAddr >= 0xB0000040 && ((VAddr - 0xB0000000) < g_Rom->GetRomSize())) - { - return; - } - if (VAddr >= 0xB0000000 && VAddr < 0xB0000040) - { - if (!LogRomHeader()) - { - return; - } - - g_MMU->LW_VAddr(VAddr, Value); - switch (VAddr) - { - case 0xB0000004: LogMessage("%08X: read from ROM clock rate (%08X)", PC, Value); break; - case 0xB0000008: LogMessage("%08X: read from ROM boot address offset (%08X)", PC, Value); break; - case 0xB000000C: LogMessage("%08X: read from ROM release offset (%08X)", PC, Value); break; - case 0xB0000010: LogMessage("%08X: read from ROM CRC1 (%08X)", PC, Value); break; - case 0xB0000014: LogMessage("%08X: read from ROM CRC2 (%08X)", PC, Value); break; - default: LogMessage("%08X: read from ROM header 0x%X (%08X)", PC, VAddr & 0xFF, Value); break; - } - return; - } if (!LogUnknown()) { return; diff --git a/Source/Project64-core/N64System/MemoryHandler/RomMemoryHandler.cpp b/Source/Project64-core/N64System/MemoryHandler/RomMemoryHandler.cpp new file mode 100644 index 000000000..0b09d5bdc --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/RomMemoryHandler.cpp @@ -0,0 +1,69 @@ +#include "stdafx.h" +#include "RomMemoryHandler.h" +#include +#include +#include + +RomMemoryHandler::RomMemoryHandler(CN64System & System, CRegisters & Reg, CN64Rom & Rom) : + m_PC(Reg.m_PROGRAM_COUNTER), + m_Rom(Rom), + m_RomWrittenTo(false), + m_RomWroteValue(0) +{ + System.RegisterCallBack(CN64SystemCB_Reset, this, (CN64System::CallBackFunction)stSystemReset); + System.RegisterCallBack(CN64SystemCB_LoadedGameState, this, (CN64System::CallBackFunction)stLoadedGameState); +} + +bool RomMemoryHandler::Read32(uint32_t Address, uint32_t & Value) +{ + if (m_RomWrittenTo) + { + Value = m_RomWroteValue; + //LogMessage("%X: Read crap from ROM %08X from %08X",PROGRAM_COUNTER,*Value,PAddr); + m_RomWrittenTo = false; + } + else if ((Address & 0xFFFFFFF) < m_Rom.GetRomSize()) + { + Value = *(uint32_t *)&m_Rom.GetRomAddress()[(Address & 0xFFFFFFF)]; + } + else + { + Value = (Address << 16) | (Address & 0xFFFF); + } + + if (LogRomHeader() && (Address & 0x1FFFFFFF) >= 0x10000000 && (Address & 0x1FFFFFFF) < 0x10000040) + { + switch (Address & 0x1FFFFFFF) + { + case 0x10000004: LogMessage("%08X: read from ROM clock rate (%08X)", m_PC, Value); break; + case 0x10000008: LogMessage("%08X: read from ROM boot address offset (%08X)", m_PC, Value); break; + case 0x1000000C: LogMessage("%08X: read from ROM release offset (%08X)", m_PC, Value); break; + case 0x10000010: LogMessage("%08X: read from ROM CRC1 (%08X)", m_PC, Value); break; + case 0x10000014: LogMessage("%08X: read from ROM CRC2 (%08X)", m_PC, Value); break; + default: LogMessage("%08X: read from ROM header 0x%X (%08X)", m_PC, Address & 0xFF, Value); break; + } + } + return true; +} + +bool RomMemoryHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask) +{ + if (((Address & 0x1FFFFFFF) - 0x10000000) < m_Rom.GetRomSize()) + { + m_RomWrittenTo = true; + m_RomWroteValue = (Value & Mask); + } + return true; +} + +void RomMemoryHandler::SystemReset(void) +{ + m_RomWrittenTo = false; + m_RomWroteValue = 0; +} + +void RomMemoryHandler::LoadedGameState(void) +{ + m_RomWrittenTo = false; + m_RomWroteValue = 0; +} diff --git a/Source/Project64-core/N64System/MemoryHandler/RomMemoryHandler.h b/Source/Project64-core/N64System/MemoryHandler/RomMemoryHandler.h new file mode 100644 index 000000000..737f55aaf --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/RomMemoryHandler.h @@ -0,0 +1,37 @@ +#pragma once +#include "MemoryHandler.h" +#include +#include +#include + +class CRegisters; +class CN64Rom; +class CN64System; + +class RomMemoryHandler : + public MemoryHandler, + private CDebugSettings, + private CLogging +{ +public: + RomMemoryHandler(CN64System & System, CRegisters & Reg, CN64Rom & Rom); + + bool Read32(uint32_t Address, uint32_t & Value); + bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask); + +private: + RomMemoryHandler(); + RomMemoryHandler(const RomMemoryHandler&); + RomMemoryHandler& operator=(const RomMemoryHandler&); + + void SystemReset(void); + void LoadedGameState(void); + + static void stSystemReset(RomMemoryHandler * _this) { _this->SystemReset(); } + static void stLoadedGameState(RomMemoryHandler * _this) { _this->LoadedGameState(); } + + uint32_t & m_PC; + CN64Rom & m_Rom; + bool m_RomWrittenTo; + uint32_t m_RomWroteValue; +}; diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp index 31e4aa155..481c974ff 100755 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp @@ -30,20 +30,16 @@ CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) : m_AudioInterfaceHandler(System, System.m_Reg), m_CartridgeDomain2Address1Handler(System.m_Reg), m_RDRAMRegistersHandler(System.m_Reg), - m_RomMapped(false), m_DPCommandRegistersHandler(System, System.GetPlugins(), System.m_Reg), m_MIPSInterfaceHandler(System.m_Reg), m_PeripheralInterfaceHandler(*this, System.m_Reg), m_RDRAMInterfaceHandler(System.m_Reg), + m_RomMemoryHandler(System, System.m_Reg, *g_Rom), m_SerialInterfaceHandler(*this, System.m_Reg), m_SPRegistersHandler(System, *this, System.m_Reg), m_VideoInterfaceHandler(System, *this, System.m_Reg), - m_Rom(nullptr), - m_RomSize(0), m_MemoryReadMap(nullptr), m_MemoryWriteMap(nullptr), - m_RomWrittenTo(false), - m_RomWroteValue(0), m_TLB_ReadMap(nullptr), m_TLB_WriteMap(nullptr), m_RDRAM(nullptr), @@ -129,9 +125,9 @@ void CMipsMemoryVM::Reset(bool /*EraseMemory*/) m_MemoryReadMap[Address >> 12] = ((size_t)m_RDRAM + TargetAddress) - Address; m_MemoryWriteMap[Address >> 12] = ((size_t)m_RDRAM + TargetAddress) - Address; } - if (TargetAddress >= 0x10000000 && TargetAddress < (0x10000000 + m_RomSize)) + if (TargetAddress >= 0x10000000 && TargetAddress < (0x10000000 + g_Rom->GetRomSize())) { - m_MemoryReadMap[Address >> 12] = ((size_t)m_Rom + (TargetAddress - 0x10000000)) - Address; + m_MemoryReadMap[Address >> 12] = ((size_t)g_Rom->GetRomAddress() + (TargetAddress - 0x10000000)) - Address; } m_TLB_ReadMap[Address >> 12] = ((size_t)m_RDRAM + TargetAddress) - Address; m_TLB_WriteMap[Address >> 12] = ((size_t)m_RDRAM + TargetAddress) - Address; @@ -207,52 +203,12 @@ bool CMipsMemoryVM::Initialize(bool SyncSystem) m_DMEM = (uint8_t *)(m_RDRAM + 0x04000000); m_IMEM = (uint8_t *)(m_RDRAM + 0x04001000); - if (g_Settings->LoadBool(Game_LoadRomToMemory)) - { - m_RomMapped = true; - m_Rom = m_RDRAM + 0x10000000; - m_RomSize = g_Rom->GetRomSize(); - if (CommitMemory(m_Rom, g_Rom->GetRomSize(), MEM_READWRITE) == nullptr) - { - WriteTrace(TraceN64System, TraceError, "Failed to allocate ROM (Size: 0x%X)", g_Rom->GetRomSize()); - FreeMemory(); - return false; - } - memcpy(m_Rom, g_Rom->GetRomAddress(), g_Rom->GetRomSize()); - - ::ProtectMemory(m_Rom, g_Rom->GetRomSize(), MEM_READONLY); - } - else - { - m_RomMapped = false; - m_Rom = g_Rom->GetRomAddress(); - m_RomSize = g_Rom->GetRomSize(); - } - // 64DD IPL if (g_DDRom != nullptr) { - if (g_Settings->LoadBool(Game_LoadRomToMemory)) - { - m_DDRomMapped = true; - m_DDRom = m_RDRAM + 0x06000000; - m_DDRomSize = g_DDRom->GetRomSize(); - if (CommitMemory(m_DDRom, g_DDRom->GetRomSize(), MEM_READWRITE) == nullptr) - { - WriteTrace(TraceN64System, TraceError, "Failed to allocate ROM (Size: 0x%X)", g_DDRom->GetRomSize()); - FreeMemory(); - return false; - } - memcpy(m_DDRom, g_DDRom->GetRomAddress(), g_DDRom->GetRomSize()); - - ::ProtectMemory(m_DDRom, g_DDRom->GetRomSize(), MEM_READONLY); - } - else - { - m_DDRomMapped = false; - m_DDRom = g_DDRom->GetRomAddress(); - m_DDRomSize = g_DDRom->GetRomSize(); - } + m_DDRomMapped = false; + m_DDRom = g_DDRom->GetRomAddress(); + m_DDRomSize = g_DDRom->GetRomSize(); } CPifRam::Reset(); @@ -557,9 +513,18 @@ bool CMipsMemoryVM::LB_NonMemory(uint32_t PAddr, uint32_t* Value, bool /*SignExt if (PAddr >= 0x10000000 && PAddr < 0x16000000) { - g_Notify->BreakPoint(__FILE__, __LINE__); + uint32_t Value32; + if (!m_RomMemoryHandler.Read32(PAddr & ~0x3, Value32)) + { + return false; + } + *Value = ((Value32 >> (((PAddr & 3) ^ 3) << 3)) & 0xff); + } + else + { + g_Notify->BreakPoint(__FILE__, __LINE__); + *Value = 0; } - *Value = 0; return true; } @@ -582,31 +547,30 @@ bool CMipsMemoryVM::LH_NonMemory(uint32_t PAddr, uint32_t* Value, bool/* SignExt bool CMipsMemoryVM::LW_NonMemory(uint32_t PAddr, uint32_t* Value) { m_MemLookupAddress = PAddr; - if (PAddr >= 0x10000000 && PAddr < 0x16000000) + switch (PAddr & 0xFFF00000) { - Load32Rom(); - } - else - { - switch (PAddr & 0xFFF00000) + case 0x03F00000: m_RDRAMRegistersHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x04000000: m_SPRegistersHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x04100000: m_DPCommandRegistersHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x04300000: m_MIPSInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x04400000: m_VideoInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x04500000: m_AudioInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x04600000: m_PeripheralInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x04700000: m_RDRAMInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x04800000: m_SerialInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x05000000: m_CartridgeDomain2Address1Handler.Read32(PAddr, m_MemLookupValue.UW[0]); break; + case 0x06000000: Load32CartridgeDomain1Address1(); break; + case 0x08000000: Load32CartridgeDomain2Address2(); break; + case 0x1FC00000: Load32PifRam(); break; + case 0x1FF00000: Load32CartridgeDomain1Address3(); break; + default: + if (PAddr >= 0x10000000 && PAddr < 0x16000000) { - case 0x03F00000: m_RDRAMRegistersHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x04000000: m_SPRegistersHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x04100000: m_DPCommandRegistersHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x04300000: m_MIPSInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x04400000: m_VideoInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x04500000: m_AudioInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x04600000: m_PeripheralInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x04700000: m_RDRAMInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x04800000: m_SerialInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x05000000: m_CartridgeDomain2Address1Handler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x06000000: Load32CartridgeDomain1Address1(); break; - case 0x08000000: Load32CartridgeDomain2Address2(); break; - case 0x1FC00000: Load32PifRam(); break; - case 0x1FF00000: Load32CartridgeDomain1Address3(); break; - default: - m_MemLookupValue.UW[0] = PAddr & 0xFFFF; - m_MemLookupValue.UW[0] = (m_MemLookupValue.UW[0] << 16) | m_MemLookupValue.UW[0]; + m_RomMemoryHandler.Read32(PAddr, m_MemLookupValue.UW[0]); + } + else + { + m_MemLookupValue.UW[0] = ((PAddr & 0xFFFF) << 16) | PAddr & 0xFFFF; } } *Value = m_MemLookupValue.UW[0]; @@ -670,19 +634,6 @@ bool CMipsMemoryVM::SW_NonMemory(uint32_t PAddr, uint32_t Value) m_MemLookupValue.UW[0] = Value; m_MemLookupAddress = PAddr; - if (PAddr >= 0x10000000 && PAddr < 0x16000000) - { - if ((PAddr - 0x10000000) < g_Rom->GetRomSize()) - { - m_RomWrittenTo = true; - m_RomWroteValue = Value; - } - else - { - return false; - } - } - switch (PAddr & 0xFFF00000) { case 0x00000000: @@ -723,6 +674,11 @@ bool CMipsMemoryVM::SW_NonMemory(uint32_t PAddr, uint32_t Value) case 0x08000000: Write32CartridgeDomain2Address2(); break; case 0x1FC00000: Write32PifRam(); break; default: + if (PAddr >= 0x10000000 && PAddr < 0x16000000) + { + m_RomMemoryHandler.Write32(PAddr, Value, 0xFFFFFFFF); + return true; + } return false; break; } @@ -1116,25 +1072,6 @@ void CMipsMemoryVM::Load32PifRam(void) } } -void CMipsMemoryVM::Load32Rom(void) -{ - if (g_MMU->m_RomWrittenTo) - { - m_MemLookupValue.UW[0] = g_MMU->m_RomWroteValue; - //LogMessage("%X: Read crap from ROM %08X from %08X",PROGRAM_COUNTER,*Value,PAddr); - g_MMU->m_RomWrittenTo = false; - } - else if ((m_MemLookupAddress & 0xFFFFFFF) < g_MMU->m_RomSize) - { - m_MemLookupValue.UW[0] = *(uint32_t *)&g_MMU->m_Rom[(m_MemLookupAddress & 0xFFFFFFF)]; - } - else - { - m_MemLookupValue.UW[0] = m_MemLookupAddress & 0xFFFF; - m_MemLookupValue.UW[0] = (m_MemLookupValue.UW[0] << 16) | m_MemLookupValue.UW[0]; - } -} - void CMipsMemoryVM::Write32CartridgeDomain2Address2(void) { uint32_t offset = (m_MemLookupAddress & 0x1FFFFFFF) - 0x08000000; diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h index afa5546e9..eb88eddfe 100644 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h @@ -7,12 +7,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -66,7 +68,6 @@ public: uint32_t RdramSize() const { return m_AllocatedRdramSize; } uint8_t * Dmem() const { return m_DMEM; } uint8_t * Imem() const { return m_IMEM; } - uint8_t * Rom() const { return m_Rom; } uint8_t * PifRam() { return &m_PifRam[0]; } CSram * GetSram(); @@ -136,7 +137,6 @@ private: static void Load32CartridgeDomain1Address3(void); static void Load32CartridgeDomain2Address2(void); static void Load32PifRam(void); - static void Load32Rom(void); static void Write32CartridgeDomain2Address2(void); static void Write32PifRam(void); @@ -171,6 +171,7 @@ private: DisplayControlRegHandler m_DPCommandRegistersHandler; MIPSInterfaceHandler m_MIPSInterfaceHandler; PeripheralInterfaceHandler m_PeripheralInterfaceHandler; + RomMemoryHandler m_RomMemoryHandler; RDRAMInterfaceHandler m_RDRAMInterfaceHandler; RDRAMRegistersHandler m_RDRAMRegistersHandler; SerialInterfaceHandler m_SerialInterfaceHandler; @@ -178,11 +179,6 @@ private: VideoInterfaceHandler m_VideoInterfaceHandler; uint8_t * m_RDRAM, *m_DMEM, *m_IMEM; uint32_t m_AllocatedRdramSize; - bool m_RomMapped; - uint8_t * m_Rom; - uint32_t m_RomSize; - bool m_RomWrittenTo; - uint32_t m_RomWroteValue; bool m_DDRomMapped; uint8_t * m_DDRom; uint32_t m_DDRomSize; diff --git a/Source/Project64-core/N64System/N64Rom.h b/Source/Project64-core/N64System/N64Rom.h index c7f5761e9..4d5e4dbef 100644 --- a/Source/Project64-core/N64System/N64Rom.h +++ b/Source/Project64-core/N64System/N64Rom.h @@ -18,7 +18,7 @@ public: void SaveRomSettingID(bool temp); void ClearRomSettingID(); CICChip CicChipID(); - uint8_t * GetRomAddress() { return m_ROMImage; } + uint8_t * GetRomAddress() const { return m_ROMImage; } uint32_t GetRomSize() const { return m_RomFileSize; } const std::string & GetRomMD5() const { return m_MD5; } const std::string & GetRomName() const { return m_RomName; } diff --git a/Source/Project64-core/N64System/N64System.cpp b/Source/Project64-core/N64System/N64System.cpp index eb4c2ffa4..846d817c3 100644 --- a/Source/Project64-core/N64System/N64System.cpp +++ b/Source/Project64-core/N64System/N64System.cpp @@ -1325,9 +1325,7 @@ void CN64System::UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycl if (CyclesToExecute < 0) { return; } SecondCPU->SetActiveSystem(true); - CInterpreterCPU::ExecuteOps(Cycles); - SetActiveSystem(true); } diff --git a/Source/Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.cpp index f86732311..53676a5dc 100644 --- a/Source/Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.cpp @@ -5899,7 +5899,7 @@ void CArmRecompilerOps::UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles) RegSet.AfterCallDirect(); } -void CArmRecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues) +void CArmRecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues, bool /*UpdateTimer*/) { if (RegSet.GetBlockCycleCount() != 0) { diff --git a/Source/Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h b/Source/Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h index 282bc9540..ff814a5d2 100644 --- a/Source/Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h +++ b/Source/Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h @@ -215,7 +215,7 @@ private: void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason); void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, CArmOps::ArmCompareType CompareType); static void UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles); - void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false); + void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false, bool UpdateTimer = true); void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet); void CompileReadTLBMiss(ArmReg AddressReg, ArmReg LookUpReg); void CompileWriteTLBMiss(ArmReg AddressReg, ArmReg LookUpReg); diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerOps.h b/Source/Project64-core/N64System/Recompiler/RecompilerOps.h index a00cfac64..96b17eeef 100644 --- a/Source/Project64-core/N64System/Recompiler/RecompilerOps.h +++ b/Source/Project64-core/N64System/Recompiler/RecompilerOps.h @@ -229,7 +229,7 @@ public: virtual const OPCODE & GetOpcode(void) const = 0; virtual void PreCompileOpcode(void) = 0; virtual void PostCompileOpcode(void) = 0; - virtual void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false) = 0; + virtual void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false, bool UpdateTimer = true) = 0; virtual void CompileExecuteBP(void) = 0; virtual void CompileExecuteDelaySlotBP(void) = 0; }; diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index 2e75454fc..1c70b408c 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -3421,7 +3421,7 @@ void CX86RecompilerOps::LW_KnownAddress(x86Reg Reg, uint32_t VAddr) { // Read from ROM sprintf(VarName, "Rom + %X", (PAddr - 0x10000000)); - MoveVariableToX86reg((PAddr - 0x10000000) + g_MMU->Rom(), VarName, Reg); + MoveVariableToX86reg((PAddr - 0x10000000) + g_Rom->GetRomAddress(), VarName, Reg); } else if (g_DDRom != nullptr && ((PAddr & 0xFF000000) == 0x06000000 && (PAddr - 0x06000000) < g_DDRom->GetRomSize())) { @@ -9089,7 +9089,7 @@ void CX86RecompilerOps::CompileInPermLoop(CRegInfo & RegSet, uint32_t ProgramCou { MoveConstToVariable(ProgramCounter, _PROGRAM_COUNTER, "PROGRAM_COUNTER"); RegSet.WriteBackRegisters(); - UpdateCounters(RegSet, false, true); + UpdateCounters(RegSet, false, true, false); Call_Direct(AddressOf(CInterpreterCPU::InPermLoop), "CInterpreterCPU::InPermLoop"); #ifdef _MSC_VER MoveConstToX86reg((uint32_t)g_SystemTimer, x86_ECX); @@ -9871,7 +9871,7 @@ void CX86RecompilerOps::UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles) RegSet.AfterCallDirect(); } -void CX86RecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues) +void CX86RecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues, bool UpdateTimer) { if (RegSet.GetBlockCycleCount() != 0) { @@ -9907,6 +9907,20 @@ void CX86RecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool CPU_Message(" $Continue_From_Timer_Test:"); SetJump8(Jump, *g_RecompPos); } + + if (UpdateTimer && g_SyncSystem) + { + m_RegWorkingSet.BeforeCallDirect(); +#ifdef _MSC_VER + MoveConstToX86reg((uint32_t)g_SystemTimer, x86_ECX); + Call_Direct(AddressOf(&CSystemTimer::UpdateTimers), "CSystemTimer::UpdateTimers"); +#else + PushImm32((uint32_t)g_SystemTimer); + Call_Direct(AddressOf(&CSystemTimer::UpdateTimers), "CSystemTimer::UpdateTimers"); + AddConstToX86Reg(x86_ESP, 4); +#endif + m_RegWorkingSet.AfterCallDirect(); + } } void CX86RecompilerOps::CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet) diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h index c616ed8f9..a0a8230e1 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h @@ -234,7 +234,7 @@ public: void CompileReadTLBMiss(x86Reg AddressReg, x86Reg LookUpReg); void CompileWriteTLBMiss(x86Reg AddressReg, x86Reg LookUpReg); static void UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles); - void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false); + void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false, bool UpdateTimer = true); void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet); void CompileExecuteBP(void); void CompileExecuteDelaySlotBP(void); diff --git a/Source/Project64-core/Project64-core.vcxproj b/Source/Project64-core/Project64-core.vcxproj index d92508eaa..aacbbd567 100644 --- a/Source/Project64-core/Project64-core.vcxproj +++ b/Source/Project64-core/Project64-core.vcxproj @@ -60,6 +60,7 @@ + @@ -165,6 +166,7 @@ + diff --git a/Source/Project64-core/Project64-core.vcxproj.filters b/Source/Project64-core/Project64-core.vcxproj.filters index ee3919ee1..693bb2d48 100644 --- a/Source/Project64-core/Project64-core.vcxproj.filters +++ b/Source/Project64-core/Project64-core.vcxproj.filters @@ -40,9 +40,6 @@ {e3f8ea19-e06b-47a7-8d69-14a0c1cfa8f1} - - {ac92e812-22e1-4a1a-8dd5-5055073c882c} - {febaabe1-9838-4211-970d-2af9a003ef8f} @@ -100,6 +97,9 @@ {f32cf723-4acb-4d3d-9bd9-05823579f8dd} + + {ac92e812-22e1-4a1a-8dd5-5055073c882c} + @@ -184,22 +184,22 @@ Source Files\Settings - Source Files\Plugins + Source Files\N64 System\Plugins - Source Files\Plugins + Source Files\N64 System\Plugins - Source Files\Plugins + Source Files\N64 System\Plugins - Source Files\Plugins + Source Files\N64 System\Plugins - Source Files\Plugins + Source Files\N64 System\Plugins - Source Files\Plugins + Source Files\N64 System\Plugins Source Files\N64 System @@ -384,6 +384,9 @@ Source Files\N64 System\MemoryHandler + + Source Files\N64 System\MemoryHandler + @@ -734,6 +737,9 @@ Header Files\N64 System\MemoryHandler + + Header Files\N64 System\MemoryHandler + diff --git a/Source/Project64-core/Settings.cpp b/Source/Project64-core/Settings.cpp index a8419e1ff..1b4dd6f77 100644 --- a/Source/Project64-core/Settings.cpp +++ b/Source/Project64-core/Settings.cpp @@ -158,7 +158,6 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(Rdb_TLB_PAddrStart, new CSettingTypeRomDatabase("TLB: PAddr Start", (uint32_t)0)); AddHandler(Rdb_UseHleGfx, new CSettingTypeRomDatabase("HLE GFX RDB", Plugin_UseHleGfx)); AddHandler(Rdb_UseHleAudio, new CSettingTypeRomDatabase("HLE Audio RDB", Plugin_UseHleAudio)); - AddHandler(Rdb_LoadRomToMemory, new CSettingTypeRomDatabase("Rom In Memory", false)); AddHandler(Rdb_ScreenHertz, new CSettingTypeRomDatabase("ScreenHertz", (uint32_t)0)); AddHandler(Rdb_FuncLookupMode, new CSettingTypeRomDatabase("FuncFind", (uint32_t)FuncFind_PhysicalLookup)); AddHandler(Rdb_RegCache, new CSettingTypeRDBYesNo("Reg Cache", true)); @@ -217,7 +216,6 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(Game_SyncViaAudio, new CSettingTypeGame("Sync Audio", Rdb_SyncViaAudio)); AddHandler(Game_UseHleGfx, new CSettingTypeGame("HLE GFX", Rdb_UseHleGfx)); AddHandler(Game_UseHleAudio, new CSettingTypeGame("HLE Audio", Rdb_UseHleAudio)); - AddHandler(Game_LoadRomToMemory, new CSettingTypeGame("Rom In Memory", Rdb_LoadRomToMemory)); AddHandler(Game_ScreenHertz, new CSettingTypeGame("ScreenHertz", Rdb_ScreenHertz)); AddHandler(Game_FuncLookupMode, new CSettingTypeGame("FuncFind", Rdb_FuncLookupMode)); AddHandler(Game_RegCache, new CSettingTypeGame("Reg Cache", Rdb_RegCache)); diff --git a/Source/Project64-core/Settings/GameSettings.cpp b/Source/Project64-core/Settings/GameSettings.cpp index 11a83b3a6..201ad0669 100644 --- a/Source/Project64-core/Settings/GameSettings.cpp +++ b/Source/Project64-core/Settings/GameSettings.cpp @@ -22,7 +22,6 @@ bool CGameSettings::m_FullSpeed = true; bool CGameSettings::m_bFastSP = true; bool CGameSettings::m_b32Bit = true; bool CGameSettings::m_RspAudioSignal; -bool CGameSettings::m_bRomInMemory; bool CGameSettings::m_RegCaching; bool CGameSettings::m_bLinkBlocks; uint32_t CGameSettings::m_LookUpMode; //FUNC_LOOKUP_METHOD @@ -80,7 +79,6 @@ void CGameSettings::RefreshGameSettings() m_bFastSP = g_Settings->LoadBool(Game_FastSP); #endif m_RspAudioSignal = g_Settings->LoadBool(Game_RspAudioSignal); - m_bRomInMemory = g_Settings->LoadBool(Game_LoadRomToMemory); m_RegCaching = g_Settings->LoadBool(Game_RegCache); m_bLinkBlocks = g_Settings->LoadBool(Game_BlockLinking); m_LookUpMode = g_Settings->LoadDword(Game_FuncLookupMode); diff --git a/Source/Project64-core/Settings/GameSettings.h b/Source/Project64-core/Settings/GameSettings.h index 7b9faab64..18ca71f54 100644 --- a/Source/Project64-core/Settings/GameSettings.h +++ b/Source/Project64-core/Settings/GameSettings.h @@ -12,7 +12,6 @@ public: void RefreshGameSettings(void); inline static bool UseHleGfx(void) { return m_UseHleGfx; } - inline static bool bRomInMemory(void) { return m_bRomInMemory; } inline static bool bRegCaching(void) { return m_RegCaching; } inline static bool bLinkBlocks(void) { return m_bLinkBlocks && !CDebugSettings::HaveWriteBP() && !CDebugSettings::HaveReadBP(); } inline static FUNC_LOOKUP_METHOD LookUpMode(void) { return (FUNC_LOOKUP_METHOD)m_LookUpMode; } @@ -55,7 +54,6 @@ private: // Settings that can be changed on the fly static bool m_UseHleGfx; - static bool m_bRomInMemory; static bool m_RegCaching; static bool m_bLinkBlocks; static uint32_t m_LookUpMode; //FUNC_LOOKUP_METHOD diff --git a/Source/Project64-core/Settings/SettingsID.h b/Source/Project64-core/Settings/SettingsID.h index 89235ecb3..c52ae3870 100644 --- a/Source/Project64-core/Settings/SettingsID.h +++ b/Source/Project64-core/Settings/SettingsID.h @@ -94,7 +94,6 @@ enum SettingID Rdb_TLB_PAddrStart, Rdb_UseHleGfx, Rdb_UseHleAudio, - Rdb_LoadRomToMemory, Rdb_ScreenHertz, Rdb_FuncLookupMode, Rdb_RegCache, @@ -157,7 +156,6 @@ enum SettingID Game_RspAudioSignal, Game_UseHleGfx, Game_UseHleAudio, - Game_LoadRomToMemory, Game_ViRefreshRate, Game_AiCountPerBytes, Game_AudioResetOnLoad,