From 2f1074a28718b55b01aa789045950c216dc4a1b5 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 25 Apr 2022 17:12:07 +0930 Subject: [PATCH] Core: Add handler for cartridge domains --- .../CartridgeDomain1Address1Handler.cpp | 27 +++ .../CartridgeDomain1Address1Handler.h | 22 +++ .../CartridgeDomain1Address3Handler.cpp | 17 ++ .../CartridgeDomain1Address3Handler.h | 16 ++ .../CartridgeDomain2Address1Handler.h | 1 + .../CartridgeDomain2Address2Handler.cpp | 122 +++++++++++++ .../CartridgeDomain2Address2Handler.h | 37 ++++ Source/Project64-core/N64System/Mips/Dma.cpp | 59 +------ Source/Project64-core/N64System/Mips/Dma.h | 11 +- .../N64System/Mips/MemoryVirtualMem.cpp | 162 +++--------------- .../N64System/Mips/MemoryVirtualMem.h | 24 +-- Source/Project64-core/N64System/N64System.cpp | 6 + .../Recompiler/x86/x86RecompilerOps.cpp | 5 +- .../N64System/SaveType/FlashRam.cpp | 24 +-- .../N64System/SaveType/FlashRam.h | 30 ++-- Source/Project64-core/Project64-core.vcxproj | 6 + .../Project64-core.vcxproj.filters | 18 ++ .../UserInterface/Debugger/DebugMMU.cpp | 14 +- 18 files changed, 349 insertions(+), 252 deletions(-) create mode 100644 Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address1Handler.cpp create mode 100644 Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address1Handler.h create mode 100644 Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.cpp create mode 100644 Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.h create mode 100644 Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address2Handler.cpp create mode 100644 Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address2Handler.h diff --git a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address1Handler.cpp b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address1Handler.cpp new file mode 100644 index 000000000..eb4234ed4 --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address1Handler.cpp @@ -0,0 +1,27 @@ +#include "stdafx.h" +#include "CartridgeDomain1Address1Handler.h" +#include + +CartridgeDomain1Address1Handler::CartridgeDomain1Address1Handler(CN64Rom * DDRom) : + m_DDRom(DDRom != nullptr ? DDRom->GetRomAddress() : nullptr), + m_DDRomSize(DDRom != nullptr ? DDRom->GetRomSize() : 0) +{ +} + +bool CartridgeDomain1Address1Handler::Read32(uint32_t Address, uint32_t & Value) +{ + if (m_DDRom != nullptr && (Address & 0xFFFFFF) < m_DDRomSize) + { + Value = *(uint32_t *)&m_DDRom[Address & 0xFFFFFF]; + } + else + { + Value = ((Address & 0xFFFF) << 16) | (Address & 0xFFFF); + } + return true; +} + +bool CartridgeDomain1Address1Handler::Write32(uint32_t /*Address*/, uint32_t /*Value*/, uint32_t /*Mask*/) +{ + return true; +} diff --git a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address1Handler.h b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address1Handler.h new file mode 100644 index 000000000..9d4396886 --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address1Handler.h @@ -0,0 +1,22 @@ +#pragma once +#include "MemoryHandler.h" + +class CN64Rom; + +class CartridgeDomain1Address1Handler : + public MemoryHandler +{ +public: + CartridgeDomain1Address1Handler(CN64Rom * DDRom); + + bool Read32(uint32_t Address, uint32_t & Value); + bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask); + +private: + CartridgeDomain1Address1Handler(); + CartridgeDomain1Address1Handler(const CartridgeDomain1Address1Handler &); + CartridgeDomain1Address1Handler & operator=(const CartridgeDomain1Address1Handler &); + + uint32_t m_DDRomSize; + uint8_t * m_DDRom; +}; diff --git a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.cpp b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.cpp new file mode 100644 index 000000000..dcac83d49 --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.cpp @@ -0,0 +1,17 @@ +#include "stdafx.h" +#include "CartridgeDomain1Address3Handler.h" + +CartridgeDomain1Address3Handler::CartridgeDomain1Address3Handler() +{ +} + +bool CartridgeDomain1Address3Handler::Read32(uint32_t Address, uint32_t & Value) +{ + Value = ((Address & 0xFFFF) << 16) | (Address & 0xFFFF); + return true; +} + +bool CartridgeDomain1Address3Handler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask) +{ + return true; +} diff --git a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.h b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.h new file mode 100644 index 000000000..ca612277d --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain1Address3Handler.h @@ -0,0 +1,16 @@ +#pragma once +#include "MemoryHandler.h" + +class CartridgeDomain1Address3Handler : + public MemoryHandler +{ +public: + CartridgeDomain1Address3Handler(); + + bool Read32(uint32_t Address, uint32_t & Value); + bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask); + +private: + CartridgeDomain1Address3Handler(const CartridgeDomain1Address3Handler &); + CartridgeDomain1Address3Handler & operator=(const CartridgeDomain1Address3Handler &); +}; diff --git a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address1Handler.h b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address1Handler.h index 6d2fa1a80..e7ea6d701 100644 --- a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address1Handler.h +++ b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address1Handler.h @@ -77,6 +77,7 @@ class CartridgeDomain2Address1Handler : { public: CartridgeDomain2Address1Handler(CRegisters & Reg); + bool Read32(uint32_t Address, uint32_t & Value); bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask); diff --git a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address2Handler.cpp b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address2Handler.cpp new file mode 100644 index 000000000..ac68ab3a8 --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address2Handler.cpp @@ -0,0 +1,122 @@ +#include "stdafx.h" +#include "CartridgeDomain2Address2Handler.h" +#include + +CartridgeDomain2Address2Handler::CartridgeDomain2Address2Handler(CN64System & System, CRegisters & Reg, CMipsMemoryVM & MMU, bool SavesReadOnly) : + m_System(System), + m_Reg(Reg), + m_MMU(MMU), + m_Sram(SavesReadOnly), + m_FlashRam(SavesReadOnly) +{ +} + +bool CartridgeDomain2Address2Handler::Read32(uint32_t Address, uint32_t & Value) +{ + uint32_t offset = (Address & 0x1FFFFFFF) - 0x08000000; + if (offset > 0x88000) + { + Value = ((offset & 0xFFFF) << 16) | (offset & 0xFFFF); + return true; + } + if (m_System.m_SaveUsing == SaveChip_Auto) + { + m_System.m_SaveUsing = SaveChip_FlashRam; + } + if (m_System.m_SaveUsing == SaveChip_Sram) + { + // Load SRAM + uint8_t tmp[4] = ""; + m_Sram.DmaFromSram(tmp, offset, 4); + Value = tmp[3] << 24 | tmp[2] << 16 | tmp[1] << 8 | tmp[0]; + } + else if (m_System.m_SaveUsing != SaveChip_FlashRam) + { + if (HaveDebugger()) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + Value = ((Address & 0xFFFF) << 16) | (Address & 0xFFFF); + } + else + { + Value = m_FlashRam.ReadFromFlashStatus(Address & 0x1FFFFFFF); + } + return true; +} + +bool CartridgeDomain2Address2Handler::Write32(uint32_t Address, uint32_t Value, uint32_t /*Mask*/) +{ + uint32_t offset = (Address & 0x1FFFFFFF) - 0x08000000; + if (m_System.m_SaveUsing == SaveChip_Sram && offset < 0x88000) + { + // Store SRAM + uint8_t tmp[4] = ""; + tmp[0] = 0xFF & (Value); + tmp[1] = 0xFF & (Value >> 8); + tmp[2] = 0xFF & (Value >> 16); + tmp[3] = 0xFF & (Value >> 24); + m_Sram.DmaToSram(tmp, (Address & 0x1FFFFFFF) - 0x08000000, 4); + return true; + } + if (offset > 0x10000) + { + return true; + } + if (m_System.m_SaveUsing == SaveChip_Auto) + { + m_System.m_SaveUsing = SaveChip_FlashRam; + } + if (m_System.m_SaveUsing == SaveChip_FlashRam) + { + m_FlashRam.WriteToFlashCommand(Value); + } + return true; +} + +bool CartridgeDomain2Address2Handler::DMARead() +{ + if (m_System.m_SaveUsing == SaveChip_Auto) + { + m_System.m_SaveUsing = SaveChip_Sram; + } + if (m_System.m_SaveUsing == SaveChip_Sram) + { + m_Sram.DmaToSram(m_MMU.Rdram() + m_Reg.PI_DRAM_ADDR_REG,m_Reg.PI_CART_ADDR_REG - 0x08000000, m_Reg.PI_RD_LEN_REG); + m_Reg.PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + m_Reg.MI_INTR_REG |= MI_INTR_PI; + m_Reg.CheckInterrupts(); + return true; + } + else if (m_System.m_SaveUsing == SaveChip_FlashRam) + { + m_FlashRam.DmaToFlashram(m_MMU.Rdram() + m_Reg.PI_DRAM_ADDR_REG, m_Reg.PI_CART_ADDR_REG - 0x08000000, m_Reg.PI_RD_LEN_REG); + m_Reg.PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + m_Reg.MI_INTR_REG |= MI_INTR_PI; + m_Reg.CheckInterrupts(); + return true; + } + return false; +} + +void CartridgeDomain2Address2Handler::DMAWrite() +{ + if (m_System.m_SaveUsing == SaveChip_Auto) + { + m_System.m_SaveUsing = SaveChip_Sram; + } + if (m_System.m_SaveUsing == SaveChip_Sram) + { + m_Sram.DmaFromSram(m_MMU.Rdram() + m_Reg.PI_DRAM_ADDR_REG, m_Reg.PI_CART_ADDR_REG - 0x08000000, m_Reg.PI_WR_LEN_REG); + m_Reg.PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + m_Reg.MI_INTR_REG |= MI_INTR_PI; + m_Reg.CheckInterrupts(); + } + else if (m_System.m_SaveUsing == SaveChip_FlashRam) + { + m_FlashRam.DmaFromFlashram(m_MMU.Rdram() + m_Reg.PI_DRAM_ADDR_REG, m_Reg.PI_CART_ADDR_REG - 0x08000000, m_Reg.PI_WR_LEN_REG); + m_Reg.PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; + m_Reg.MI_INTR_REG |= MI_INTR_PI; + m_Reg.CheckInterrupts(); + } +} \ No newline at end of file diff --git a/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address2Handler.h b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address2Handler.h new file mode 100644 index 000000000..6bc059aa1 --- /dev/null +++ b/Source/Project64-core/N64System/MemoryHandler/CartridgeDomain2Address2Handler.h @@ -0,0 +1,37 @@ +#pragma once +#include +#include +#include +#include "MemoryHandler.h" + +class CN64System; +class CMipsMemoryVM; +class CRegisters; + +class CartridgeDomain2Address2Handler : + public MemoryHandler, + private CDebugSettings +{ +public: + CartridgeDomain2Address2Handler(CN64System & System, CRegisters & Reg, CMipsMemoryVM & MMU, bool SavesReadOnly); + + bool Read32(uint32_t Address, uint32_t & Value); + bool Write32(uint32_t Address, uint32_t Value, uint32_t Mask); + + bool DMARead(); + void DMAWrite(); + + CSram & Sram(void) { return m_Sram; } + CFlashRam & FlashRam (void) { return m_FlashRam; } + +private: + CartridgeDomain2Address2Handler(void); + CartridgeDomain2Address2Handler(const CartridgeDomain2Address2Handler &); + CartridgeDomain2Address2Handler & operator=(const CartridgeDomain2Address2Handler &); + + CN64System & m_System; + CRegisters & m_Reg; + CMipsMemoryVM & m_MMU; + CSram m_Sram; + CFlashRam m_FlashRam; +}; diff --git a/Source/Project64-core/N64System/Mips/Dma.cpp b/Source/Project64-core/N64System/Mips/Dma.cpp index 235ee7b84..0b0ddf780 100644 --- a/Source/Project64-core/N64System/Mips/Dma.cpp +++ b/Source/Project64-core/N64System/Mips/Dma.cpp @@ -11,9 +11,8 @@ #include #include -CDMA::CDMA(CFlashram & FlashRam, CSram & Sram) : - m_FlashRam(FlashRam), - m_Sram(Sram) +CDMA::CDMA(CartridgeDomain2Address2Handler & Domain2Address2Handler) : + m_Domain2Address2Handler(Domain2Address2Handler) { } @@ -148,32 +147,8 @@ void CDMA::PI_DMA_READ() if (g_Reg->PI_CART_ADDR_REG >= 0x08000000 && g_Reg->PI_CART_ADDR_REG < 0x08088000) { - if (g_System->m_SaveUsing == SaveChip_Auto) + if (m_Domain2Address2Handler.DMARead()) { - g_System->m_SaveUsing = SaveChip_Sram; - } - if (g_System->m_SaveUsing == SaveChip_Sram) - { - m_Sram.DmaToSram( - g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, - g_Reg->PI_CART_ADDR_REG - 0x08000000, - PI_RD_LEN_REG - ); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } - if (g_System->m_SaveUsing == SaveChip_FlashRam) - { - m_FlashRam.DmaToFlashram( - g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, - g_Reg->PI_CART_ADDR_REG - 0x08000000, - PI_RD_LEN_REG - ); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); return; } } @@ -318,33 +293,7 @@ void CDMA::PI_DMA_WRITE() if (PI_CART_ADDR_REG >= 0x08000000 && PI_CART_ADDR_REG <= 0x08088000) { - if (g_System->m_SaveUsing == SaveChip_Auto) - { - g_System->m_SaveUsing = SaveChip_Sram; - } - if (g_System->m_SaveUsing == SaveChip_Sram) - { - m_Sram.DmaFromSram( - g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, - PI_CART_ADDR_REG - 0x08000000, - PI_WR_LEN_REG - ); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - return; - } - if (g_System->m_SaveUsing == SaveChip_FlashRam) - { - m_FlashRam.DmaFromFlashram( - g_MMU->Rdram() + g_Reg->PI_DRAM_ADDR_REG, - PI_CART_ADDR_REG - 0x08000000, - PI_WR_LEN_REG - ); - g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - g_Reg->MI_INTR_REG |= MI_INTR_PI; - g_Reg->CheckInterrupts(); - } + m_Domain2Address2Handler.DMAWrite(); return; } diff --git a/Source/Project64-core/N64System/Mips/Dma.h b/Source/Project64-core/N64System/Mips/Dma.h index c5b55e10b..86011c865 100644 --- a/Source/Project64-core/N64System/Mips/Dma.h +++ b/Source/Project64-core/N64System/Mips/Dma.h @@ -1,7 +1,7 @@ #pragma once #include -#include -#include + +class CartridgeDomain2Address2Handler; class CDMA : private CDebugSettings @@ -14,14 +14,13 @@ public: void PI_DMA_WRITE(); protected: - CDMA(CFlashram & FlashRam, CSram & Sram); + CDMA(CartridgeDomain2Address2Handler & Domain2Address2Handler); private: CDMA(const CDMA&); CDMA& operator=(const CDMA&); - CFlashram & m_FlashRam; - CSram & m_Sram; - void OnFirstDMA(); + + CartridgeDomain2Address2Handler & m_Domain2Address2Handler; }; diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp index e2edc91c7..1d67adeb5 100755 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp @@ -13,8 +13,6 @@ uint8_t * CMipsMemoryVM::m_Reserve1 = nullptr; uint8_t * CMipsMemoryVM::m_Reserve2 = nullptr; -uint32_t CMipsMemoryVM::m_MemLookupAddress = 0; -MIPS_DWORD CMipsMemoryVM::m_MemLookupValue; bool CMipsMemoryVM::m_MemLookupValid = true; uint32_t CMipsMemoryVM::RegModValue; @@ -22,12 +20,12 @@ uint32_t CMipsMemoryVM::RegModValue; CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) : CPifRam(SavesReadOnly), - CFlashram(SavesReadOnly), - CSram(SavesReadOnly), - CDMA(*this, *this), + CDMA(m_CartridgeDomain2Address2Handler), m_Reg(System.m_Reg), m_AudioInterfaceHandler(System, System.m_Reg), + m_CartridgeDomain1Address1Handler(g_DDRom), m_CartridgeDomain2Address1Handler(System.m_Reg), + m_CartridgeDomain2Address2Handler(System, System.m_Reg, *this, SavesReadOnly), m_RDRAMRegistersHandler(System.m_Reg), m_DPCommandRegistersHandler(System, System.GetPlugins(), System.m_Reg), m_MIPSInterfaceHandler(System.m_Reg), @@ -44,10 +42,7 @@ CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) : m_TLB_WriteMap(nullptr), m_RDRAM(nullptr), m_DMEM(nullptr), - m_IMEM(nullptr), - m_DDRomMapped(false), - m_DDRom(nullptr), - m_DDRomSize(0) + m_IMEM(nullptr) { g_Settings->RegisterChangeCB(Game_RDRamSize, this, (CSettings::SettingChangedFunc)RdramChanged); } @@ -185,15 +180,6 @@ bool CMipsMemoryVM::Initialize(bool SyncSystem) m_DMEM = (uint8_t *)(m_RDRAM + 0x04000000); m_IMEM = (uint8_t *)(m_RDRAM + 0x04001000); - - // 64DD IPL - if (g_DDRom != nullptr) - { - m_DDRomMapped = false; - m_DDRom = g_DDRom->GetRomAddress(); - m_DDRomSize = g_DDRom->GetRomSize(); - } - CPifRam::Reset(); m_MemoryReadMap = new size_t [0x100000]; @@ -280,16 +266,6 @@ void CMipsMemoryVM::FreeMemory() CPifRam::Reset(); } -CSram* CMipsMemoryVM::GetSram(void) -{ - return dynamic_cast(this); -} - -CFlashram* CMipsMemoryVM::GetFlashram() -{ - return dynamic_cast(this); -} - bool CMipsMemoryVM::LB_VAddr(uint32_t VAddr, uint8_t& Value) { uint8_t * MemoryPtr = (uint8_t*)m_MemoryReadMap[VAddr >> 12]; @@ -529,34 +505,32 @@ 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; 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: m_PifRamHandler.Read32(PAddr, m_MemLookupValue.UW[0]); break; - case 0x1FF00000: Load32CartridgeDomain1Address3(); break; + case 0x03F00000: m_RDRAMRegistersHandler.Read32(PAddr, *Value); break; + case 0x04000000: m_SPRegistersHandler.Read32(PAddr, *Value); break; + case 0x04100000: m_DPCommandRegistersHandler.Read32(PAddr, *Value); break; + case 0x04300000: m_MIPSInterfaceHandler.Read32(PAddr, *Value); break; + case 0x04400000: m_VideoInterfaceHandler.Read32(PAddr, *Value); break; + case 0x04500000: m_AudioInterfaceHandler.Read32(PAddr, *Value); break; + case 0x04600000: m_PeripheralInterfaceHandler.Read32(PAddr, *Value); break; + case 0x04700000: m_RDRAMInterfaceHandler.Read32(PAddr, *Value); break; + case 0x04800000: m_SerialInterfaceHandler.Read32(PAddr, *Value); break; + case 0x05000000: m_CartridgeDomain2Address1Handler.Read32(PAddr, *Value); break; + case 0x06000000: m_CartridgeDomain1Address1Handler.Read32(PAddr, *Value); break; + case 0x08000000: m_CartridgeDomain2Address2Handler.Read32(PAddr, *Value); break; + case 0x1FC00000: m_PifRamHandler.Read32(PAddr, *Value); break; + case 0x1FF00000: m_CartridgeDomain1Address3Handler.Read32(PAddr, *Value); break; default: if (PAddr >= 0x10000000 && PAddr < 0x16000000) { - m_RomMemoryHandler.Read32(PAddr, m_MemLookupValue.UW[0]); + m_RomMemoryHandler.Read32(PAddr, *Value); } else { - m_MemLookupValue.UW[0] = ((PAddr & 0xFFFF) << 16) | PAddr & 0xFFFF; + *Value = ((PAddr & 0xFFFF) << 16) | (PAddr & 0xFFFF); } } - *Value = m_MemLookupValue.UW[0]; return true; } @@ -614,9 +588,6 @@ bool CMipsMemoryVM::SH_NonMemory(uint32_t PAddr, uint16_t Value) bool CMipsMemoryVM::SW_NonMemory(uint32_t PAddr, uint32_t Value) { - m_MemLookupValue.UW[0] = Value; - m_MemLookupAddress = PAddr; - switch (PAddr & 0xFFF00000) { case 0x00000000: @@ -654,8 +625,10 @@ bool CMipsMemoryVM::SW_NonMemory(uint32_t PAddr, uint32_t Value) case 0x04700000: m_RDRAMInterfaceHandler.Write32(PAddr, Value, 0xFFFFFFFF); break; case 0x04800000: m_SerialInterfaceHandler.Write32(PAddr, Value, 0xFFFFFFFF); break; case 0x05000000: m_CartridgeDomain2Address1Handler.Write32(PAddr, Value, 0xFFFFFFFF); break; - case 0x08000000: Write32CartridgeDomain2Address2(); break; + case 0x06000000: m_CartridgeDomain1Address1Handler.Write32(PAddr, Value, 0xFFFFFFFF); break; + case 0x08000000: m_CartridgeDomain2Address2Handler.Write32(PAddr, Value, 0xFFFFFFFF); break; case 0x1FC00000: m_PifRamHandler.Write32(PAddr, Value, 0xFFFFFFFF); break; + case 0x1FF00000: m_CartridgeDomain1Address3Handler.Write32(PAddr, Value, 0xFFFFFFFF); break; default: if (PAddr >= 0x10000000 && PAddr < 0x16000000) { @@ -972,93 +945,4 @@ void CMipsMemoryVM::ChangeMiIntrMask() { g_Reg->MI_INTR_MASK_REG |= MI_INTR_MASK_DP; } -} - -void CMipsMemoryVM::Load32CartridgeDomain1Address1(void) -{ - // 64DD IPL ROM - if (g_DDRom != nullptr && (m_MemLookupAddress & 0xFFFFFF) < g_MMU->m_DDRomSize) - { - m_MemLookupValue.UW[0] = *(uint32_t *)&g_MMU->m_DDRom[(m_MemLookupAddress & 0xFFFFFF)]; - } - else - { - m_MemLookupValue.UW[0] = m_MemLookupAddress & 0xFFFF; - m_MemLookupValue.UW[0] = (m_MemLookupValue.UW[0] << 16) | m_MemLookupValue.UW[0]; - } -} - -void CMipsMemoryVM::Load32CartridgeDomain1Address3(void) -{ - m_MemLookupValue.UW[0] = m_MemLookupAddress & 0xFFFF; - m_MemLookupValue.UW[0] = (m_MemLookupValue.UW[0] << 16) | m_MemLookupValue.UW[0]; -} - -void CMipsMemoryVM::Load32CartridgeDomain2Address2(void) -{ - uint32_t offset = (m_MemLookupAddress & 0x1FFFFFFF) - 0x08000000; - if (offset > 0x88000) - { - m_MemLookupValue.UW[0] = ((offset & 0xFFFF) << 16) | (offset & 0xFFFF); - return; - } - if (g_System->m_SaveUsing == SaveChip_Auto) - { - g_System->m_SaveUsing = SaveChip_FlashRam; - } - if (g_System->m_SaveUsing == SaveChip_Sram) - { - // Load SRAM - uint8_t tmp[4] = ""; - g_MMU->DmaFromSram(tmp, offset, 4); - m_MemLookupValue.UW[0] = tmp[3] << 24 | tmp[2] << 16 | tmp[1] << 8 | tmp[0]; - } - else if (g_System->m_SaveUsing != SaveChip_FlashRam) - { - if (HaveDebugger()) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - m_MemLookupValue.UW[0] = m_MemLookupAddress & 0xFFFF; - m_MemLookupValue.UW[0] = (m_MemLookupValue.UW[0] << 16) | m_MemLookupValue.UW[0]; - } - else - { - m_MemLookupValue.UW[0] = g_MMU->ReadFromFlashStatus(m_MemLookupAddress & 0x1FFFFFFF); - } -} - -void CMipsMemoryVM::Write32CartridgeDomain2Address2(void) -{ - uint32_t offset = (m_MemLookupAddress & 0x1FFFFFFF) - 0x08000000; - if (g_System->m_SaveUsing == SaveChip_Sram && offset < 0x88000) - { - // Store SRAM - uint8_t tmp[4] = ""; - tmp[0] = 0xFF & (m_MemLookupValue.UW[0]); - tmp[1] = 0xFF & (m_MemLookupValue.UW[0] >> 8); - tmp[2] = 0xFF & (m_MemLookupValue.UW[0] >> 16); - tmp[3] = 0xFF & (m_MemLookupValue.UW[0] >> 24); - g_MMU->DmaToSram(tmp, (m_MemLookupAddress & 0x1FFFFFFF) - 0x08000000, 4); - return; - } - /*if ((m_MemLookupAddress & 0x1FFFFFFF) != 0x08010000) - { - if (HaveDebugger()) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - }*/ - if (offset > 0x10000) - { - return; - } - if (g_System->m_SaveUsing == SaveChip_Auto) - { - g_System->m_SaveUsing = SaveChip_FlashRam; - } - if (g_System->m_SaveUsing == SaveChip_FlashRam) - { - g_MMU->WriteToFlashCommand(m_MemLookupValue.UW[0]); - } } \ No newline at end of file diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h index 11c380e29..b96972b9e 100644 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.h @@ -5,10 +5,12 @@ #include #include #include -#include #include #include +#include +#include #include +#include #include #include #include @@ -51,8 +53,6 @@ class CMipsMemoryVM : public CTransVaddr, private R4300iOp, public CPifRam, - private CFlashram, - private CSram, public CDMA, private CGameSettings { @@ -72,8 +72,8 @@ public: uint8_t * Imem() const { return m_IMEM; } uint8_t * PifRam() { return &m_PifRam[0]; } - CSram * GetSram(); - CFlashram * GetFlashram(); + CSram & GetSram() { return m_CartridgeDomain2Address2Handler.Sram(); } + CFlashRam & GetFlashRam() { return m_CartridgeDomain2Address2Handler.FlashRam(); } bool LB_VAddr(uint32_t VAddr, uint8_t & Value); bool LH_VAddr(uint32_t VAddr, uint16_t & Value); @@ -135,12 +135,6 @@ private: bool SH_NonMemory(uint32_t PAddr, uint16_t Value); bool SW_NonMemory(uint32_t PAddr, uint32_t Value); - static void Load32CartridgeDomain1Address1(void); - static void Load32CartridgeDomain1Address3(void); - static void Load32CartridgeDomain2Address2(void); - - static void Write32CartridgeDomain2Address2(void); - #if defined(__i386__) || defined(_M_IX86) typedef struct _X86_CONTEXT @@ -167,7 +161,10 @@ private: static uint8_t * m_Reserve1, *m_Reserve2; CRegisters & m_Reg; AudioInterfaceHandler m_AudioInterfaceHandler; + CartridgeDomain1Address1Handler m_CartridgeDomain1Address1Handler; + CartridgeDomain1Address3Handler m_CartridgeDomain1Address3Handler; CartridgeDomain2Address1Handler m_CartridgeDomain2Address1Handler; + CartridgeDomain2Address2Handler m_CartridgeDomain2Address2Handler; DisplayControlRegHandler m_DPCommandRegistersHandler; MIPSInterfaceHandler m_MIPSInterfaceHandler; PeripheralInterfaceHandler m_PeripheralInterfaceHandler; @@ -180,9 +177,6 @@ private: VideoInterfaceHandler m_VideoInterfaceHandler; uint8_t * m_RDRAM, *m_DMEM, *m_IMEM; uint32_t m_AllocatedRdramSize; - bool m_DDRomMapped; - uint8_t * m_DDRom; - uint32_t m_DDRomSize; mutable char m_strLabelName[100]; size_t * m_TLB_ReadMap; @@ -190,8 +184,6 @@ private: size_t * m_MemoryReadMap; size_t * m_MemoryWriteMap; - static uint32_t m_MemLookupAddress; - static MIPS_DWORD m_MemLookupValue; static bool m_MemLookupValid; static uint32_t RegModValue; }; diff --git a/Source/Project64-core/N64System/N64System.cpp b/Source/Project64-core/N64System/N64System.cpp index 846d817c3..970919fcd 100644 --- a/Source/Project64-core/N64System/N64System.cpp +++ b/Source/Project64-core/N64System/N64System.cpp @@ -387,11 +387,17 @@ bool CN64System::LoadFileImage(const char * FileLoc) } g_DDRom->LoadN64ImageIPL(FileLoc); if (g_DDRom->CicChipID() == CIC_NUS_8303) + { g_Settings->SaveString(File_DiskIPLPath, FileLoc); + } else if (g_DDRom->CicChipID() == CIC_NUS_DDUS) + { g_Settings->SaveString(File_DiskIPLUSAPath, FileLoc); + } else if (g_DDRom->CicChipID() == CIC_NUS_8401) + { g_Settings->SaveString(File_DiskIPLTOOLPath, FileLoc); + } } g_System->RefreshGameSettings(); diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index 1c70b408c..908f9bb8d 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -11299,9 +11299,10 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) switch (PAddr) { case 0x04300000: - MoveX86regToVariable(Reg, &CMipsMemoryVM::m_MemLookupValue.UW[0], "CMipsMemoryVM::m_MemLookupValue.UW[0]"); - MoveConstToVariable(PAddr, &CMipsMemoryVM::m_MemLookupAddress, "m_MemLookupAddress"); m_RegWorkingSet.BeforeCallDirect(); + PushImm32(0xFFFFFFFF); + Push(Reg); + PushImm32(PAddr & 0x1FFFFFFF); #ifdef _MSC_VER MoveConstToX86reg((uint32_t)(MemoryHandler*)&g_MMU->m_MIPSInterfaceHandler, x86_ECX); Call_Direct((void*)((long**)(MemoryHandler*)&g_MMU->m_MIPSInterfaceHandler)[0][1], "MIPSInterfaceHandler::Write32"); diff --git a/Source/Project64-core/N64System/SaveType/FlashRam.cpp b/Source/Project64-core/N64System/SaveType/FlashRam.cpp index f0d9d7bbe..3129db77d 100644 --- a/Source/Project64-core/N64System/SaveType/FlashRam.cpp +++ b/Source/Project64-core/N64System/SaveType/FlashRam.cpp @@ -4,20 +4,20 @@ #include #include -CFlashram::CFlashram(bool ReadOnly) : -m_FlashRamPointer(nullptr), -m_FlashFlag(FLASHRAM_MODE_NOPES), -m_FlashStatus(0), -m_FlashRAM_Offset(0), -m_ReadOnly(ReadOnly) +CFlashRam::CFlashRam(bool ReadOnly) : + m_FlashRamPointer(nullptr), + m_FlashFlag(FLASHRAM_MODE_NOPES), + m_FlashStatus(0), + m_FlashRAM_Offset(0), + m_ReadOnly(ReadOnly) { } -CFlashram::~CFlashram() +CFlashRam::~CFlashRam() { } -void CFlashram::DmaFromFlashram(uint8_t * dest, int32_t StartOffset, int32_t len) +void CFlashRam::DmaFromFlashram(uint8_t * dest, int32_t StartOffset, int32_t len) { uint8_t FlipBuffer[0x10000]; @@ -78,7 +78,7 @@ void CFlashram::DmaFromFlashram(uint8_t * dest, int32_t StartOffset, int32_t len } } -void CFlashram::DmaToFlashram(uint8_t * Source, int32_t StartOffset, int32_t len) +void CFlashRam::DmaToFlashram(uint8_t * Source, int32_t StartOffset, int32_t len) { switch (m_FlashFlag) { @@ -93,7 +93,7 @@ void CFlashram::DmaToFlashram(uint8_t * Source, int32_t StartOffset, int32_t len } } -uint32_t CFlashram::ReadFromFlashStatus(uint32_t PAddr) +uint32_t CFlashRam::ReadFromFlashStatus(uint32_t PAddr) { switch (PAddr) { @@ -108,7 +108,7 @@ uint32_t CFlashram::ReadFromFlashStatus(uint32_t PAddr) return (uint32_t)(m_FlashStatus >> 32); } -bool CFlashram::LoadFlashram() +bool CFlashRam::LoadFlashram() { CPath FileName(g_Settings->LoadStringVal(Directory_NativeSave).c_str(), stdstr_f("%s.fla", g_Settings->LoadStringVal(Game_GameName).c_str()).c_str()); if (g_Settings->LoadBool(Setting_UniqueSaveDir)) @@ -134,7 +134,7 @@ bool CFlashram::LoadFlashram() return true; } -void CFlashram::WriteToFlashCommand(uint32_t FlashRAM_Command) +void CFlashRam::WriteToFlashCommand(uint32_t FlashRAM_Command) { uint8_t EmptyBlock[16 * sizeof(int64_t)]; diff --git a/Source/Project64-core/N64System/SaveType/FlashRam.h b/Source/Project64-core/N64System/SaveType/FlashRam.h index 2c24e4604..763534a4e 100644 --- a/Source/Project64-core/N64System/SaveType/FlashRam.h +++ b/Source/Project64-core/N64System/SaveType/FlashRam.h @@ -1,7 +1,7 @@ #pragma once #include -class CFlashram : +class CFlashRam : private CDebugSettings { enum Modes @@ -14,25 +14,25 @@ class CFlashram : }; public: - CFlashram(bool ReadOnly); - ~CFlashram(); + CFlashRam(bool ReadOnly); + ~CFlashRam(); - void DmaFromFlashram(uint8_t * dest, int32_t StartOffset, int32_t len); - void DmaToFlashram(uint8_t * Source, int32_t StartOffset, int32_t len); + void DmaFromFlashram(uint8_t * dest, int32_t StartOffset, int32_t len); + void DmaToFlashram(uint8_t * Source, int32_t StartOffset, int32_t len); uint32_t ReadFromFlashStatus(uint32_t PAddr); - void WriteToFlashCommand(uint32_t Value); + void WriteToFlashCommand(uint32_t Value); private: - CFlashram(void); - CFlashram(const CFlashram&); - CFlashram& operator=(const CFlashram&); + CFlashRam(void); + CFlashRam(const CFlashRam&); + CFlashRam& operator=(const CFlashRam&); - bool LoadFlashram(); + bool LoadFlashram(); uint8_t * m_FlashRamPointer; - Modes m_FlashFlag; - uint64_t m_FlashStatus; - uint32_t m_FlashRAM_Offset; - bool m_ReadOnly; - CFile m_File; + Modes m_FlashFlag; + uint64_t m_FlashStatus; + uint32_t m_FlashRAM_Offset; + bool m_ReadOnly; + CFile m_File; }; diff --git a/Source/Project64-core/Project64-core.vcxproj b/Source/Project64-core/Project64-core.vcxproj index 3075f04f1..d1cb223ae 100644 --- a/Source/Project64-core/Project64-core.vcxproj +++ b/Source/Project64-core/Project64-core.vcxproj @@ -54,7 +54,10 @@ + + + @@ -160,7 +163,10 @@ + + + diff --git a/Source/Project64-core/Project64-core.vcxproj.filters b/Source/Project64-core/Project64-core.vcxproj.filters index 525685ccb..4e1adb516 100644 --- a/Source/Project64-core/Project64-core.vcxproj.filters +++ b/Source/Project64-core/Project64-core.vcxproj.filters @@ -396,6 +396,15 @@ Source Files\N64 System\SaveType + + Source Files\N64 System\MemoryHandler + + + Source Files\N64 System\MemoryHandler + + + Source Files\N64 System\MemoryHandler + @@ -761,6 +770,15 @@ Header Files\N64 System\SaveType + + Header Files\N64 System\MemoryHandler + + + Header Files\N64 System\MemoryHandler + + + Header Files\N64 System\MemoryHandler + diff --git a/Source/Project64/UserInterface/Debugger/DebugMMU.cpp b/Source/Project64/UserInterface/Debugger/DebugMMU.cpp index cc70ce295..369877365 100644 --- a/Source/Project64/UserInterface/Debugger/DebugMMU.cpp +++ b/Source/Project64/UserInterface/Debugger/DebugMMU.cpp @@ -188,15 +188,15 @@ bool CDebugMMU::GetPhysicalByte(uint32_t paddr, uint8_t* value) uint32_t wordpaddr = paddr & ~3; uint8_t data[4]; - CSram *sram = g_MMU->GetSram(); - sram->DmaFromSram(data, wordpaddr - 0x08000000, 4); + CSram & sram = g_MMU->GetSram(); + sram.DmaFromSram(data, wordpaddr - 0x08000000, 4); *value = data[nByte ^ 3]; return true; } else if (g_System->m_SaveUsing == SaveChip_FlashRam && saveOffset <= 3) // FlashRAM status { - CFlashram* flashRam = g_MMU->GetFlashram(); - uint32_t flashStatus = flashRam->ReadFromFlashStatus(0x08000000); + CFlashRam & FlashRam = g_MMU->GetFlashRam(); + uint32_t flashStatus = FlashRam.ReadFromFlashStatus(0x08000000); *value = (flashStatus >> (24 - nByte * 8)) & 0xFF; return true; } @@ -262,10 +262,10 @@ bool CDebugMMU::SetPhysicalByte(uint32_t paddr, uint8_t value) uint32_t wordpaddr = paddr & ~3; uint8_t data[4]; - CSram *sram = g_MMU->GetSram(); - sram->DmaFromSram(data, wordpaddr - 0x08000000, sizeof(data)); + CSram & sram = g_MMU->GetSram(); + sram.DmaFromSram(data, wordpaddr - 0x08000000, sizeof(data)); data[nByte ^ 3] = value; - sram->DmaToSram(data, wordpaddr - 0x08000000, sizeof(data)); + sram.DmaToSram(data, wordpaddr - 0x08000000, sizeof(data)); return true; } }