diff --git a/Source/Project64-core/Logging.cpp b/Source/Project64-core/Logging.cpp index fe979f678..720dbd3dd 100644 --- a/Source/Project64-core/Logging.cpp +++ b/Source/Project64-core/Logging.cpp @@ -200,26 +200,6 @@ void CLogging::Log_LW(uint32_t PC, uint32_t VAddr) case 0xA4600030: LogMessage("%08X: read from PI_BSD_DOM2_RLS_REG (%08X)", PC, Value); return; } } - if (VAddr >= 0xA4700000 && VAddr <= 0xA470001C) - { - if (!LogRDRAMInterface()) - { - return; - } - g_MMU->LW_VAddr(VAddr, Value); - - switch (VAddr) - { - case 0xA4700000: LogMessage("%08X: read from RI_MODE_REG (%08X)", PC, Value); return; - case 0xA4700004: LogMessage("%08X: read from RI_CONFIG_REG (%08X)", PC, Value); return; - case 0xA4700008: LogMessage("%08X: read from RI_CURRENT_LOAD_REG (%08X)", PC, Value); return; - case 0xA470000C: LogMessage("%08X: read from RI_SELECT_REG (%08X)", PC, Value); return; - case 0xA4700010: LogMessage("%08X: read from RI_REFRESH_REG/RI_COUNT_REG (%08X)", PC, Value); return; - case 0xA4700014: LogMessage("%08X: read from RI_LATENCY_REG (%08X)", PC, Value); return; - case 0xA4700018: LogMessage("%08X: read from RI_RERROR_REG (%08X)", PC, Value); return; - case 0xA470001C: LogMessage("%08X: read from RI_WERROR_REG (%08X)", PC, Value); return; - } - } if (VAddr == 0xA4800000) { if (!LogSerialInterface()) @@ -494,24 +474,6 @@ void CLogging::Log_SW(uint32_t PC, uint32_t VAddr, uint32_t Value) case 0xA4600030: LogMessage("%08X: Writing 0x%08X to PI_BSD_DOM2_RLS_REG", PC, Value); return; } } - if (VAddr >= 0xA4700000 && VAddr <= 0xA470001C) - { - if (!LogRDRAMInterface()) - { - return; - } - switch (VAddr) - { - case 0xA4700000: LogMessage("%08X: Writing 0x%08X to RI_MODE_REG", PC, Value); return; - case 0xA4700004: LogMessage("%08X: Writing 0x%08X to RI_CONFIG_REG", PC, Value); return; - case 0xA4700008: LogMessage("%08X: Writing 0x%08X to RI_CURRENT_LOAD_REG", PC, Value); return; - case 0xA470000C: LogMessage("%08X: Writing 0x%08X to RI_SELECT_REG", PC, Value); return; - case 0xA4700010: LogMessage("%08X: Writing 0x%08X to RI_REFRESH_REG/RI_COUNT_REG", PC, Value); return; - case 0xA4700014: LogMessage("%08X: Writing 0x%08X to RI_LATENCY_REG", PC, Value); return; - case 0xA4700018: LogMessage("%08X: Writing 0x%08X to RI_RERROR_REG", PC, Value); return; - case 0xA470001C: LogMessage("%08X: Writing 0x%08X to RI_WERROR_REG", PC, Value); return; - } - } if (VAddr == 0xA4800000) { if (!LogSerialInterface()) diff --git a/Source/Project64-core/N64System/MemoryHandler/MemoryHandler.h b/Source/Project64-core/N64System/MemoryHandler/MemoryHandler.h new file mode 100644 index 000000000..2bcbdc9e6 --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/MemoryHandler.h @@ -0,0 +1,8 @@ +#pragma once +#include + +__interface MemoryHandler +{ + bool Read32(uint32_t Address, uint32_t & Value); + bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask); +}; \ No newline at end of file diff --git a/Source/Project64-core/N64System/MemoryHandler/RDRAMInterfaceHandler.cpp b/Source/Project64-core/N64System/MemoryHandler/RDRAMInterfaceHandler.cpp new file mode 100644 index 000000000..601f15323 --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/RDRAMInterfaceHandler.cpp @@ -0,0 +1,106 @@ +#include "stdafx.h" +#include +#include +#include "RDRAMInterfaceHandler.h" + +RDRAMInterfaceReg::RDRAMInterfaceReg(uint32_t * RdramInterface) : + RI_MODE_REG(RdramInterface[0]), + RI_CONFIG_REG(RdramInterface[1]), + RI_CURRENT_LOAD_REG(RdramInterface[2]), + RI_SELECT_REG(RdramInterface[3]), + RI_COUNT_REG(RdramInterface[4]), + RI_REFRESH_REG(RdramInterface[4]), + RI_LATENCY_REG(RdramInterface[5]), + RI_RERROR_REG(RdramInterface[6]), + RI_WERROR_REG(RdramInterface[7]) +{ +} + +RDRAMInterfaceHandler::RDRAMInterfaceHandler(CRegisters & Reg) : + RDRAMInterfaceReg(Reg.m_RDRAM_Interface), + m_PC(Reg.m_PROGRAM_COUNTER) +{ +} + +bool RDRAMInterfaceHandler::Read32(uint32_t Address, uint32_t & Value) +{ + switch (Address & 0x1FFFFFFF) + { + case 0x04700000: Value = RI_MODE_REG; break; + case 0x04700004: Value = RI_CONFIG_REG; break; + case 0x04700008: Value = RI_CURRENT_LOAD_REG; break; + case 0x0470000C: Value = RI_SELECT_REG; break; + case 0x04700010: Value = RI_REFRESH_REG; break; + case 0x04700014: Value = RI_LATENCY_REG; break; + case 0x04700018: Value = RI_RERROR_REG; break; + case 0x0470001C: Value = RI_WERROR_REG; break; + default: + Value = 0; + if (HaveDebugger()) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + } + + if (GenerateLog() && LogRDRAMInterface()) + { + switch (Address & 0x1FFFFFFF) + { + case 0x04700000: LogMessage("%08X: read from RI_MODE_REG (%08X)", m_PC, Value); break; + case 0x04700004: LogMessage("%08X: read from RI_CONFIG_REG (%08X)", m_PC, Value); break; + case 0x04700008: LogMessage("%08X: read from RI_CURRENT_LOAD_REG (%08X)", m_PC, Value); break; + case 0x0470000C: LogMessage("%08X: read from RI_SELECT_REG (%08X)", m_PC, Value); break; + case 0x04700010: LogMessage("%08X: read from RI_REFRESH_REG/RI_COUNT_REG (%08X)", m_PC, Value); break; + case 0x04700014: LogMessage("%08X: read from RI_LATENCY_REG (%08X)", m_PC, Value); break; + case 0x04700018: LogMessage("%08X: read from RI_RERROR_REG (%08X)", m_PC, Value); break; + case 0x0470001C: LogMessage("%08X: read from RI_WERROR_REG (%08X)", m_PC, Value); break; + default: + if (HaveDebugger()) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + } + } + return true; +} + +bool RDRAMInterfaceHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask) +{ + if (GenerateLog() && LogRDRAMInterface()) + { + switch (Address & 0x1FFFFFFF) + { + case 0x04700000: LogMessage("%08X: Writing 0x%08X (Mask: 0x%08X) to RI_MODE_REG", m_PC, Value, Mask); break; + case 0x04700004: LogMessage("%08X: Writing 0x%08X (Mask: 0x%08X) to RI_CONFIG_REG", m_PC, Value, Mask); break; + case 0x04700008: LogMessage("%08X: Writing 0x%08X (Mask: 0x%08X) to RI_CURRENT_LOAD_REG", m_PC, Value, Mask); break; + case 0x0470000C: LogMessage("%08X: Writing 0x%08X (Mask: 0x%08X) to RI_SELECT_REG", m_PC, Value, Mask); break; + case 0x04700010: LogMessage("%08X: Writing 0x%08X (Mask: 0x%08X) to RI_REFRESH_REG/RI_COUNT_REG", m_PC, Value, Mask); break; + case 0x04700014: LogMessage("%08X: Writing 0x%08X (Mask: 0x%08X) to RI_LATENCY_REG", m_PC, Value, Mask); break; + case 0x04700018: LogMessage("%08X: Writing 0x%08X (Mask: 0x%08X) to RI_RERROR_REG", m_PC, Value, Mask); break; + case 0x0470001C: LogMessage("%08X: Writing 0x%08X (Mask: 0x%08X) to RI_WERROR_REG", m_PC, Value, Mask); break; + default: + if (HaveDebugger()) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + } + } + + switch (Address & 0x1FFFFFFF) + { + case 0x04700000: RI_MODE_REG = (RI_MODE_REG & ~Mask) | (Value & Mask); break; + case 0x04700004: RI_CONFIG_REG = (RI_CONFIG_REG & ~Mask) | (Value & Mask); break; + case 0x04700008: RI_CURRENT_LOAD_REG = (RI_CURRENT_LOAD_REG & ~Mask) | (Value & Mask); break; + case 0x0470000C: RI_SELECT_REG = (RI_SELECT_REG & ~Mask) | (Value & Mask); break; + case 0x04700010: RI_REFRESH_REG = (RI_REFRESH_REG & ~Mask) | (Value & Mask); break; + case 0x04700014: RI_LATENCY_REG = (RI_LATENCY_REG & ~Mask) | (Value & Mask); break; + case 0x04700018: RI_RERROR_REG = (RI_RERROR_REG & ~Mask) | (Value & Mask); break; + case 0x0470001C: RI_WERROR_REG = (RI_WERROR_REG & ~Mask) | (Value & Mask); break; + default: + if (HaveDebugger()) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + } + return true; +} diff --git a/Source/Project64-core/N64System/MemoryHandler/RDRAMInterfaceHandler.h b/Source/Project64-core/N64System/MemoryHandler/RDRAMInterfaceHandler.h new file mode 100644 index 000000000..8b6de7d4c --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/RDRAMInterfaceHandler.h @@ -0,0 +1,48 @@ +#pragma once +#include "MemoryHandler.h" +#include +#include +#include + +class RDRAMInterfaceReg +{ +protected: + RDRAMInterfaceReg(uint32_t * RdramInterface); + +public: + uint32_t & RI_MODE_REG; + uint32_t & RI_CONFIG_REG; + uint32_t & RI_CURRENT_LOAD_REG; + uint32_t & RI_SELECT_REG; + uint32_t & RI_COUNT_REG; + uint32_t & RI_REFRESH_REG; + uint32_t & RI_LATENCY_REG; + uint32_t & RI_RERROR_REG; + uint32_t & RI_WERROR_REG; + +private: + RDRAMInterfaceReg(); + RDRAMInterfaceReg(const RDRAMInterfaceReg &); + RDRAMInterfaceReg & operator=(const RDRAMInterfaceReg &); +}; + +class CRegisters; + +class RDRAMInterfaceHandler : + public MemoryHandler, + private RDRAMInterfaceReg, + private CDebugSettings, + private CLogging +{ +public: + RDRAMInterfaceHandler(CRegisters & Reg); + bool Read32(uint32_t Address, uint32_t & Value); + bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask); + +private: + RDRAMInterfaceHandler(); + RDRAMInterfaceHandler(const RDRAMInterfaceHandler &); + RDRAMInterfaceHandler & operator=(const RDRAMInterfaceHandler &); + + uint32_t & m_PC; +}; diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp index 78077e933..357a33f9b 100755 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp @@ -1,13 +1,13 @@ #include "stdafx.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -21,12 +21,14 @@ uint32_t CMipsMemoryVM::RegModValue; #pragma warning(disable:4355) // Disable 'this' : used in base member initializer list -CMipsMemoryVM::CMipsMemoryVM(bool SavesReadOnly) : +CMipsMemoryVM::CMipsMemoryVM(CRegisters & Reg, bool SavesReadOnly) : CPifRam(SavesReadOnly), CFlashram(SavesReadOnly), CSram(SavesReadOnly), CDMA(*this, *this), + m_Reg(Reg), m_RomMapped(false), + m_RDRAMInterfaceHandler(Reg), m_Rom(nullptr), m_RomSize(0), m_RomWrittenTo(false), @@ -697,7 +699,7 @@ bool CMipsMemoryVM::LW_NonMemory(uint32_t PAddr, uint32_t* Value) case 0x04400000: Load32VideoInterface(); break; case 0x04500000: Load32AudioInterface(); break; case 0x04600000: Load32PeripheralInterface(); break; - case 0x04700000: Load32RDRAMInterface(); break; + case 0x04700000: m_RDRAMInterfaceHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; case 0x04800000: Load32SerialInterface(); break; case 0x05000000: Load32CartridgeDomain2Address1(); break; case 0x06000000: Load32CartridgeDomain1Address1(); break; @@ -861,7 +863,7 @@ bool CMipsMemoryVM::SW_NonMemory(uint32_t PAddr, uint32_t Value) case 0x04400000: Write32VideoInterface(); break; case 0x04500000: Write32AudioInterface(); break; case 0x04600000: Write32PeripheralInterface(); break; - case 0x04700000: Write32RDRAMInterface(); break; + case 0x04700000: m_RDRAMInterfaceHandler.Write32(PAddr, Value, 0xFFFFFFFF); break; case 0x04800000: Write32SerialInterface(); break; case 0x05000000: Write32CartridgeDomain2Address1(); break; case 0x08000000: Write32CartridgeDomain2Address2(); break; @@ -1395,27 +1397,6 @@ void CMipsMemoryVM::Load32PeripheralInterface(void) } } -void CMipsMemoryVM::Load32RDRAMInterface(void) -{ - switch (m_MemLookupAddress & 0x1FFFFFFF) - { - case 0x04700000: m_MemLookupValue.UW[0] = g_Reg->RI_MODE_REG; break; - case 0x04700004: m_MemLookupValue.UW[0] = g_Reg->RI_CONFIG_REG; break; - case 0x04700008: m_MemLookupValue.UW[0] = g_Reg->RI_CURRENT_LOAD_REG; break; - case 0x0470000C: m_MemLookupValue.UW[0] = g_Reg->RI_SELECT_REG; break; - case 0x04700010: m_MemLookupValue.UW[0] = g_Reg->RI_REFRESH_REG; break; - case 0x04700014: m_MemLookupValue.UW[0] = g_Reg->RI_LATENCY_REG; break; - case 0x04700018: m_MemLookupValue.UW[0] = g_Reg->RI_RERROR_REG; break; - case 0x0470001C: m_MemLookupValue.UW[0] = g_Reg->RI_WERROR_REG; break; - default: - m_MemLookupValue.UW[0] = 0; - if (HaveDebugger()) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - } -} - void CMipsMemoryVM::Load32SerialInterface(void) { switch (m_MemLookupAddress & 0x1FFFFFFF) @@ -2090,26 +2071,6 @@ void CMipsMemoryVM::Write32PeripheralInterface(void) } } -void CMipsMemoryVM::Write32RDRAMInterface(void) -{ - switch (m_MemLookupAddress & 0xFFFFFFF) - { - case 0x04700000: g_Reg->RI_MODE_REG = m_MemLookupValue.UW[0]; break; - case 0x04700004: g_Reg->RI_CONFIG_REG = m_MemLookupValue.UW[0]; break; - case 0x04700008: g_Reg->RI_CURRENT_LOAD_REG = m_MemLookupValue.UW[0]; break; - case 0x0470000C: g_Reg->RI_SELECT_REG = m_MemLookupValue.UW[0]; break; - case 0x04700010: g_Reg->RI_REFRESH_REG = m_MemLookupValue.UW[0]; break; - case 0x04700014: g_Reg->RI_LATENCY_REG = m_MemLookupValue.UW[0]; break; - case 0x04700018: g_Reg->RI_RERROR_REG = m_MemLookupValue.UW[0]; break; - case 0x0470001C: g_Reg->RI_WERROR_REG = m_MemLookupValue.UW[0]; break; - default: - if (HaveDebugger()) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - } -} - void CMipsMemoryVM::Write32SerialInterface(void) { switch (m_MemLookupAddress & 0xFFFFFFF) diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h index b307af49d..eb522628a 100644 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h @@ -1,12 +1,13 @@ #pragma once -#include +#include #include "TranslateVaddr.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #ifdef __arm__ @@ -45,7 +46,7 @@ class CMipsMemoryVM : private CGameSettings { public: - CMipsMemoryVM(bool SavesReadOnly); + CMipsMemoryVM(CRegisters & Reg, bool SavesReadOnly); ~CMipsMemoryVM(); static void ReserveMemory(); @@ -138,7 +139,6 @@ private: static void Load32VideoInterface(void); static void Load32AudioInterface(void); static void Load32PeripheralInterface(void); - static void Load32RDRAMInterface(void); static void Load32SerialInterface(void); static void Load32CartridgeDomain1Address1(void); static void Load32CartridgeDomain1Address3(void); @@ -154,7 +154,6 @@ private: static void Write32VideoInterface(void); static void Write32AudioInterface(void); static void Write32PeripheralInterface(void); - static void Write32RDRAMInterface(void); static void Write32SerialInterface(void); static void Write32CartridgeDomain2Address1(void); static void Write32CartridgeDomain2Address2(void); @@ -185,6 +184,8 @@ private: void FreeMemory(); static uint8_t * m_Reserve1, *m_Reserve2; + CRegisters & m_Reg; + RDRAMInterfaceHandler m_RDRAMInterfaceHandler; uint8_t * m_RDRAM, *m_DMEM, *m_IMEM; uint32_t m_AllocatedRdramSize; bool m_RomMapped; diff --git a/Source/Project64-core/N64System/Mips/Register.cpp b/Source/Project64-core/N64System/Mips/Register.cpp index 06830331c..8d15cfa36 100644 --- a/Source/Project64-core/N64System/Mips/Register.cpp +++ b/Source/Project64-core/N64System/Mips/Register.cpp @@ -156,19 +156,6 @@ PeripheralInterfaceReg::PeripheralInterfaceReg(uint32_t * PeripheralInterface) : { } -RDRAMInt_InterfaceReg::RDRAMInt_InterfaceReg(uint32_t * RdramInterface) : - RI_MODE_REG(RdramInterface[0]), - RI_CONFIG_REG(RdramInterface[1]), - RI_CURRENT_LOAD_REG(RdramInterface[2]), - RI_SELECT_REG(RdramInterface[3]), - RI_COUNT_REG(RdramInterface[4]), - RI_REFRESH_REG(RdramInterface[4]), - RI_LATENCY_REG(RdramInterface[5]), - RI_RERROR_REG(RdramInterface[6]), - RI_WERROR_REG(RdramInterface[7]) -{ -} - DisplayControlReg::DisplayControlReg(uint32_t * _DisplayProcessor) : DPC_START_REG(_DisplayProcessor[0]), DPC_END_REG(_DisplayProcessor[1]), @@ -236,7 +223,7 @@ CRegisters::CRegisters(CN64System * System, CSystemEvents * SystemEvents) : Video_InterfaceReg(m_Video_Interface), AudioInterfaceReg(m_Audio_Interface), PeripheralInterfaceReg(m_Peripheral_Interface), - RDRAMInt_InterfaceReg(m_RDRAM_Interface), + RDRAMInterfaceReg(m_RDRAM_Interface), SigProcessor_InterfaceReg(m_SigProcessor_Interface), DisplayControlReg(m_Display_ControlReg), Serial_InterfaceReg(m_SerialInterface), diff --git a/Source/Project64-core/N64System/Mips/Register.h b/Source/Project64-core/N64System/Mips/Register.h index c566e7bdd..eb972c8c6 100644 --- a/Source/Project64-core/N64System/Mips/Register.h +++ b/Source/Project64-core/N64System/Mips/Register.h @@ -1,10 +1,11 @@ #pragma once #include -#include -#include -#include -#include +#include +#include +#include +#include +#include // CPO registers by name class CP0registers @@ -341,28 +342,6 @@ private: PeripheralInterfaceReg& operator=(const PeripheralInterfaceReg&); }; -class RDRAMInt_InterfaceReg -{ -protected: - RDRAMInt_InterfaceReg (uint32_t * RdramInterface); - -public: - uint32_t & RI_MODE_REG; - uint32_t & RI_CONFIG_REG; - uint32_t & RI_CURRENT_LOAD_REG; - uint32_t & RI_SELECT_REG; - uint32_t & RI_COUNT_REG; - uint32_t & RI_REFRESH_REG; - uint32_t & RI_LATENCY_REG; - uint32_t & RI_RERROR_REG; - uint32_t & RI_WERROR_REG; - -private: - RDRAMInt_InterfaceReg(); - RDRAMInt_InterfaceReg(const RDRAMInt_InterfaceReg&); - RDRAMInt_InterfaceReg& operator=(const RDRAMInt_InterfaceReg&); -}; - // Signal processor interface class SigProcessor_InterfaceReg { @@ -577,7 +556,7 @@ class CRegisters : public Video_InterfaceReg, public AudioInterfaceReg, public PeripheralInterfaceReg, - public RDRAMInt_InterfaceReg, + public RDRAMInterfaceReg, public SigProcessor_InterfaceReg, public DisplayControlReg, public Serial_InterfaceReg, diff --git a/Source/Project64-core/N64System/N64System.cpp b/Source/Project64-core/N64System/N64System.cpp index ec076ca64..4e736e143 100644 --- a/Source/Project64-core/N64System/N64System.cpp +++ b/Source/Project64-core/N64System/N64System.cpp @@ -30,7 +30,7 @@ CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesR m_Plugins(Plugins), m_SyncCPU(nullptr), m_SyncPlugins(nullptr), - m_MMU_VM(SavesReadOnly), + m_MMU_VM(m_Reg, SavesReadOnly), //m_Cheats(m_MMU_VM), m_TLB(this), m_Reg(this, this), diff --git a/Source/Project64-core/Project64-core.vcxproj b/Source/Project64-core/Project64-core.vcxproj index 14e66a173..8bd5d0539 100644 --- a/Source/Project64-core/Project64-core.vcxproj +++ b/Source/Project64-core/Project64-core.vcxproj @@ -53,6 +53,7 @@ + @@ -148,6 +149,8 @@ + + diff --git a/Source/Project64-core/Project64-core.vcxproj.filters b/Source/Project64-core/Project64-core.vcxproj.filters index 117e46d82..562a65dbb 100644 --- a/Source/Project64-core/Project64-core.vcxproj.filters +++ b/Source/Project64-core/Project64-core.vcxproj.filters @@ -94,6 +94,12 @@ {ec73ae9e-54e8-4cbe-93fb-1d98d6755619} + + {3e6f4352-4933-4138-bbed-1094b988638e} + + + {f32cf723-4acb-4d3d-9bd9-05823579f8dd} + @@ -351,6 +357,9 @@ Source Files + + Source Files\N64 System\MemoryHandler + @@ -668,6 +677,12 @@ Header Files\N64 System\Enhancement + + Header Files\N64 System\MemoryHandler + + + Header Files\N64 System\MemoryHandler +