From 2b2e2f78544b045cecb92c06cd0761b4579e5a6f Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 22 Oct 2020 11:09:11 +1000 Subject: [PATCH] Cheats: Invalidate code pages on memory writes --- src/core/cheats.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 1c84dbbc3..4cc757ede 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -5,6 +5,7 @@ #include "common/log.h" #include "common/string.h" #include "common/string_util.h" +#include "cpu_code_cache.h" #include "cpu_core.h" #include "host_interface.h" #include @@ -77,7 +78,18 @@ static void DoMemoryWrite(PhysicalMemoryAddress address, T value) if (address < Bus::RAM_MIRROR_END) { - std::memcpy(&Bus::g_ram[address & Bus::RAM_MASK], &value, sizeof(value)); + // Only invalidate code when it changes. + T old_value; + std::memcpy(&old_value, &Bus::g_ram[address & Bus::RAM_MASK], sizeof(old_value)); + if (old_value != value) + { + std::memcpy(&Bus::g_ram[address & Bus::RAM_MASK], &value, sizeof(value)); + + const u32 code_page_index = Bus::GetRAMCodePageIndex(address & Bus::RAM_MASK); + if (Bus::IsRAMCodePage(code_page_index)) + CPU::CodeCache::InvalidateBlocksWithPageIndex(code_page_index); + } + return; } }