diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp index 4ec0ffa88..b648ca024 100755 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp @@ -670,9 +670,19 @@ bool CMipsMemoryVM::SH_NonMemory(uint32_t VAddr, uint16_t Value) case 0x00700000: if (PAddr < RdramSize()) { - g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF, 0x1000, CRecompiler::Remove_ProtectedMem); - ::ProtectMemory(m_RDRAM + (PAddr & ~0xFFF), 0xFFC, MEM_READWRITE); - *(uint16_t *)(m_RDRAM + (PAddr ^ 2)) = Value; + if (CGameSettings::bSMM_Protect() || CGameSettings::bSMM_StoreInstruc()) + { + g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF, 0x1000, CRecompiler::Remove_ProtectedMem); + if (CGameSettings::bSMM_Protect()) + { + ::ProtectMemory(m_RDRAM + (PAddr & ~0xFFF), 0xFFC, MEM_READWRITE); + } + if (CGameSettings::bSMM_StoreInstruc()) + { + m_TLB_WriteMap[VAddr >> 12] = PAddr - VAddr; + } + *(uint16_t *)(m_RDRAM + (PAddr ^ 2)) = Value; + } } break; default: @@ -704,9 +714,19 @@ bool CMipsMemoryVM::SW_NonMemory(uint32_t VAddr, uint32_t Value) case 0x00700000: if (PAddr < RdramSize()) { - g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF, 0x1000, CRecompiler::Remove_ProtectedMem); - ::ProtectMemory(m_RDRAM + (PAddr & ~0xFFF), 0xFFC, MEM_READWRITE); - *(uint32_t *)(m_RDRAM + PAddr) = Value; + if (CGameSettings::bSMM_Protect() || CGameSettings::bSMM_StoreInstruc()) + { + g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF, 0x1000, CRecompiler::Remove_ProtectedMem); + if (CGameSettings::bSMM_Protect()) + { + ::ProtectMemory(m_RDRAM + (PAddr & ~0xFFF), 0xFFC, MEM_READWRITE); + } + if (CGameSettings::bSMM_StoreInstruc()) + { + m_TLB_WriteMap[VAddr >> 12] = PAddr - VAddr; + } + *(uint32_t *)(m_RDRAM + PAddr) = Value; + } } break; case 0x03F00000: m_RDRAMRegistersHandler.Write32(PAddr, Value, 0xFFFFFFFF); break; @@ -777,6 +797,20 @@ bool CMipsMemoryVM::SD_NonMemory(uint32_t VAddr, uint64_t Value) return true; } +void CMipsMemoryVM::ClearMemoryWriteMap(uint32_t VAddr, uint32_t Length) +{ + uint32_t BaseAddress = m_TLB_ReadMap[VAddr >> 12]; + if (BaseAddress == -1) + { + return; + } + uint32_t PAddr = m_TLB_ReadMap[VAddr >> 12] + VAddr; + for (uint32_t i = PAddr, n = (PAddr + Length) + 0x1000; i < n; i += 0x1000) + { + m_MemoryWriteMap[(i + 0x80000000) >> 12] = (size_t)-1; + m_MemoryWriteMap[(i + 0xA0000000) >> 12] = (size_t)-1; + } +} void CMipsMemoryVM::ProtectMemory(uint32_t StartVaddr, uint32_t EndVaddr) { diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h index b7b5d7a83..e171e9e0f 100644 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h @@ -100,6 +100,8 @@ public: static void segv_handler(int signal, siginfo_t *siginfo, void *sigcontext); #endif + void ClearMemoryWriteMap(uint32_t VAddr, uint32_t Length); + // Protect the memory from being written to void ProtectMemory(uint32_t StartVaddr, uint32_t EndVaddr); void UnProtectMemory(uint32_t StartVaddr, uint32_t EndVaddr); diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index c8224d74e..4e58da618 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -9846,7 +9846,13 @@ void CX86RecompilerOps::SB_Const(uint8_t Value, uint32_t VAddr) case 0x00500000: case 0x00600000: case 0x00700000: - if (PAddr < g_MMU->RdramSize()) + if (CGameSettings::bSMM_StoreInstruc()) + { + x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); + MoveConstToX86reg(VAddr, AddressReg); + CompileStoreMemoryValue(AddressReg, x86_Unknown, x86_Unknown, Value, 8); + } + else if (PAddr < g_MMU->RdramSize()) { MoveConstByteToVariable(Value, (PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 3)", PAddr).c_str()); } @@ -9891,7 +9897,13 @@ void CX86RecompilerOps::SB_Register(x86Reg Reg, uint32_t VAddr) case 0x00500000: case 0x00600000: case 0x00700000: - if (PAddr < g_MMU->RdramSize()) + if (CGameSettings::bSMM_StoreInstruc()) + { + x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); + MoveConstToX86reg(VAddr, AddressReg); + CompileStoreMemoryValue(AddressReg, Reg, x86_Unknown, 0, 8); + } + else if (PAddr < g_MMU->RdramSize()) { MoveX86regByteToVariable(Reg, (PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 3)", PAddr).c_str()); } @@ -9935,7 +9947,13 @@ void CX86RecompilerOps::SH_Const(uint16_t Value, uint32_t VAddr) case 0x00500000: case 0x00600000: case 0x00700000: - if (PAddr < g_MMU->RdramSize()) + if (CGameSettings::bSMM_StoreInstruc()) + { + x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); + MoveConstToX86reg(VAddr, AddressReg); + CompileStoreMemoryValue(AddressReg, x86_Unknown, x86_Unknown, Value, 16); + } + else if (PAddr < g_MMU->RdramSize()) { MoveConstHalfToVariable(Value, (PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 2)", PAddr).c_str()); } @@ -9973,7 +9991,13 @@ void CX86RecompilerOps::SH_Register(x86Reg Reg, uint32_t VAddr) case 0x00500000: case 0x00600000: case 0x00700000: - if (PAddr < g_MMU->RdramSize()) + if (CGameSettings::bSMM_StoreInstruc()) + { + x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); + MoveConstToX86reg(VAddr, AddressReg); + CompileStoreMemoryValue(AddressReg, Reg, x86_Unknown, 0, 16); + } + else if (PAddr < g_MMU->RdramSize()) { MoveX86regHalfToVariable(Reg, (PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 2)", PAddr).c_str()); } @@ -10029,7 +10053,13 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) case 0x00500000: case 0x00600000: case 0x00700000: - if (PAddr < g_MMU->RdramSize()) + if (CGameSettings::bSMM_StoreInstruc()) + { + x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); + MoveConstToX86reg(VAddr, AddressReg); + CompileStoreMemoryValue(AddressReg, x86_Unknown, x86_Unknown, Value, 32); + } + else if (PAddr < g_MMU->RdramSize()) { MoveConstToVariable(Value, PAddr + g_MMU->Rdram(), stdstr_f("RDRAM + %X", PAddr).c_str()); } @@ -10601,7 +10631,13 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) case 0x00500000: case 0x00600000: case 0x00700000: - if (PAddr < g_MMU->RdramSize()) + if (CGameSettings::bSMM_StoreInstruc()) + { + x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); + MoveConstToX86reg(VAddr, AddressReg); + CompileStoreMemoryValue(AddressReg, Reg, x86_Unknown, 0, 32); + } + else if (PAddr < g_MMU->RdramSize()) { sprintf(VarName, "RDRAM + %X", PAddr); MoveX86regToVariable(Reg, PAddr + g_MMU->Rdram(), VarName); @@ -10643,7 +10679,13 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) AndConstToVariable(0xFFC, &g_Reg->SP_PC_REG, "SP_PC_REG"); break; default: - if (PAddr < 0x04001000) + if (CGameSettings::bSMM_StoreInstruc()) + { + x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); + MoveConstToX86reg(VAddr, AddressReg); + CompileStoreMemoryValue(AddressReg, Reg, x86_Unknown, 0, 32); + } + else if (PAddr < 0x04001000) { MoveX86regToVariable(Reg, g_MMU->Dmem() + (PAddr - 0x04000000), stdstr_f("DMEM + 0x%X", (PAddr - 0x04000000)).c_str()); } diff --git a/Source/Project64-core/Settings/GameSettings.cpp b/Source/Project64-core/Settings/GameSettings.cpp index 201ad0669..616018e9d 100644 --- a/Source/Project64-core/Settings/GameSettings.cpp +++ b/Source/Project64-core/Settings/GameSettings.cpp @@ -58,7 +58,7 @@ void CGameSettings::RefreshGameSettings() { WriteTrace(TraceN64System, TraceDebug, "start"); m_UseHleGfx = g_Settings->LoadBool(Game_UseHleGfx); - m_bSMM_StoreInstruc = false /*g_Settings->LoadBool(Game_SMM_StoreInstruc)*/; + m_bSMM_StoreInstruc = g_Settings->LoadBool(Game_SMM_StoreInstruc); m_bSMM_Protect = g_Settings->LoadBool(Game_SMM_Protect); m_bSMM_ValidFunc = g_Settings->LoadBool(Game_SMM_ValidFunc); m_bSMM_PIDMA = g_Settings->LoadBool(Game_SMM_PIDMA); diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Game-Recompiler.cpp b/Source/Project64/UserInterface/Settings/SettingsPage-Game-Recompiler.cpp index 8788cc801..70e4205ac 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Game-Recompiler.cpp +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Game-Recompiler.cpp @@ -34,8 +34,7 @@ CGameRecompilePage::CGameRecompilePage(HWND hParent, const RECT & rcDispay) AddModCheckBox(GetDlgItem(IDC_SMM_VALIDATE), Game_SMM_ValidFunc); AddModCheckBox(GetDlgItem(IDC_SMM_TLB), Game_SMM_TLB); AddModCheckBox(GetDlgItem(IDC_SMM_PROTECT), Game_SMM_Protect); - ::ShowWindow(GetDlgItem(IDC_SMM_STORE), SW_HIDE); - //AddModCheckBox(GetDlgItem(IDC_SMM_STORE),Game_SMM_StoreInstruc); + AddModCheckBox(GetDlgItem(IDC_SMM_STORE), Game_SMM_StoreInstruc); AddModCheckBox(GetDlgItem(IDC_ROM_FASTSP), Game_FastSP); CModifiedComboBox * ComboBox;