From 95358b1ac1b785e6de0c74e33a671c04596fba4d Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 21 Jan 2018 12:51:36 +1100 Subject: [PATCH] [Debugger] Have memory viewer to be able to write to rom --- .../Debugger/Debugger-ViewMemory.cpp | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp b/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp index d89a28916..1dca3f4c8 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-ViewMemory.cpp @@ -9,6 +9,8 @@ * * ****************************************************************************/ #include "stdafx.h" +#include +#include #include "DebuggerUI.h" #include "Symbols.h" @@ -342,19 +344,37 @@ LRESULT CDebugMemoryView::OnMemoryModified(LPNMHDR lpNMHDR) m_CurrentData[Pos] = (BYTE)Value; //sb - if (m_DataVAddrr) + __except_try() { - if (!g_MMU->SB_VAddr(m_DataStartLoc + Pos, (BYTE)Value)) + if (m_DataVAddrr) { - WriteTrace(TraceUserInterface, TraceError, "failed to store at %X", m_DataStartLoc + Pos); + if (!g_MMU->SB_VAddr(m_DataStartLoc + Pos, (BYTE)Value)) + { + WriteTrace(TraceUserInterface, TraceError, "failed to store at %X", m_DataStartLoc + Pos); + } + } + else + { + if (!g_MMU->SB_PAddr(m_DataStartLoc + Pos, (BYTE)Value)) + { + WriteTrace(TraceUserInterface, TraceError, "failed to store at %X", m_DataStartLoc + Pos); + } + } + uint32_t PhysicalAddress = m_DataStartLoc + Pos; + if (!m_DataVAddrr || g_MMU->TranslateVaddr(PhysicalAddress, PhysicalAddress)) + { + if (PhysicalAddress > 0x10000000 && (PhysicalAddress - 0x10000000) < g_Rom->GetRomSize()) + { + uint8_t * ROM = g_Settings->LoadBool(Game_LoadRomToMemory) ? g_MMU->Rdram() + 0x10000000: g_Rom->GetRomAddress(); + ProtectMemory(ROM, g_Rom->GetRomSize(), MEM_READWRITE); + ROM[(PhysicalAddress - 0x10000000) ^ 3] = (uint8_t)Value; + ProtectMemory(ROM, g_Rom->GetRomSize(), MEM_READONLY); + } } } - else + __except_catch() { - if (!g_MMU->SB_PAddr(m_DataStartLoc + Pos, (BYTE)Value)) - { - WriteTrace(TraceUserInterface, TraceError, "failed to store at %X", m_DataStartLoc + Pos); - } + g_Notify->FatalError(GS(MSG_UNKNOWN_MEM_ACTION)); } Insert_MemoryLineDump(LineNumber);