From ba852a78125190a80ec2ddf243b93da18d7f8b9e Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 12 Mar 2023 17:57:16 +0100 Subject: [PATCH] HW/Memmap: Store reference to System in MemoryManager. --- Source/Core/Core/HW/Memmap.cpp | 38 ++++++++++++++++++---------------- Source/Core/Core/HW/Memmap.h | 8 ++++++- Source/Core/Core/System.cpp | 2 +- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Source/Core/Core/HW/Memmap.cpp b/Source/Core/Core/HW/Memmap.cpp index 25c102d6a4..5a63405d17 100644 --- a/Source/Core/Core/HW/Memmap.cpp +++ b/Source/Core/Core/HW/Memmap.cpp @@ -41,31 +41,33 @@ namespace Memory { -MemoryManager::MemoryManager() = default; +MemoryManager::MemoryManager(Core::System& system) : m_system(system) +{ +} + MemoryManager::~MemoryManager() = default; void MemoryManager::InitMMIO(bool is_wii) { m_mmio_mapping = std::make_unique(); - auto& system = Core::System::GetInstance(); - system.GetCommandProcessor().RegisterMMIO(system, m_mmio_mapping.get(), 0x0C000000); - system.GetPixelEngine().RegisterMMIO(m_mmio_mapping.get(), 0x0C001000); - system.GetVideoInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C002000); - system.GetProcessorInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C003000); - system.GetMemoryInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C004000); - system.GetDSP().RegisterMMIO(m_mmio_mapping.get(), 0x0C005000); - system.GetDVDInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C006000, false); - system.GetSerialInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C006400); - system.GetExpansionInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C006800); - system.GetAudioInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C006C00); + m_system.GetCommandProcessor().RegisterMMIO(m_system, m_mmio_mapping.get(), 0x0C000000); + m_system.GetPixelEngine().RegisterMMIO(m_mmio_mapping.get(), 0x0C001000); + m_system.GetVideoInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C002000); + m_system.GetProcessorInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C003000); + m_system.GetMemoryInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C004000); + m_system.GetDSP().RegisterMMIO(m_mmio_mapping.get(), 0x0C005000); + m_system.GetDVDInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C006000, false); + m_system.GetSerialInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C006400); + m_system.GetExpansionInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C006800); + m_system.GetAudioInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0C006C00); if (is_wii) { IOS::RegisterMMIO(m_mmio_mapping.get(), 0x0D000000); - system.GetDVDInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0D006000, true); - system.GetSerialInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0D006400); - system.GetExpansionInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0D006800); - system.GetAudioInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0D006C00); + m_system.GetDVDInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0D006000, true); + m_system.GetSerialInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0D006400); + m_system.GetExpansionInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0D006800); + m_system.GetAudioInterface().RegisterMMIO(m_mmio_mapping.get(), 0x0D006C00); } } @@ -102,7 +104,7 @@ void MemoryManager::Init() &m_exram, 0x10000000, GetExRamSize(), PhysicalMemoryRegion::WII_ONLY, 0, false}; const bool wii = SConfig::GetInstance().bWii; - const bool mmu = Core::System::GetInstance().IsMMUMode(); + const bool mmu = m_system.IsMMUMode(); // If MMU is turned off in GameCube mode, turn on fake VMEM hack. const bool fake_vmem = !wii && !mmu; @@ -490,7 +492,7 @@ u8* MemoryManager::GetPointer(u32 address) const return m_exram + (address & GetExRamMask()); } - auto& ppc_state = Core::System::GetInstance().GetPPCState(); + auto& ppc_state = m_system.GetPPCState(); PanicAlertFmt("Unknown Pointer {:#010x} PC {:#010x} LR {:#010x}", address, ppc_state.pc, LR(ppc_state)); return nullptr; diff --git a/Source/Core/Core/HW/Memmap.h b/Source/Core/Core/HW/Memmap.h index 1873095d25..39c8c438bb 100644 --- a/Source/Core/Core/HW/Memmap.h +++ b/Source/Core/Core/HW/Memmap.h @@ -16,6 +16,10 @@ // Global declarations class PointerWrap; +namespace Core +{ +class System; +} namespace MMIO { class Mapping; @@ -54,7 +58,7 @@ struct LogicalMemoryView class MemoryManager { public: - MemoryManager(); + explicit MemoryManager(Core::System& system); MemoryManager(const MemoryManager& other) = delete; MemoryManager(MemoryManager&& other) = delete; MemoryManager& operator=(const MemoryManager& other) = delete; @@ -239,6 +243,8 @@ private: std::array m_physical_page_mappings{}; std::array m_logical_page_mappings{}; + Core::System& m_system; + void InitMMIO(bool is_wii); }; } // namespace Memory diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index 047c73793d..b282687cfa 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -37,7 +37,7 @@ struct System::Impl { explicit Impl(System& system) : m_audio_interface(system), m_core_timing(system), m_dsp(system), m_dvd_interface(system), - m_dvd_thread(system), m_expansion_interface(system), m_gp_fifo(system), + m_dvd_thread(system), m_expansion_interface(system), m_gp_fifo(system), m_memory(system), m_ppc_state(PowerPC::ppcState), m_serial_interface(system), m_video_interface(system) { }