diff --git a/Source/Core/Core/HW/DSP.cpp b/Source/Core/Core/HW/DSP.cpp index d849cc34f0..2c2b714623 100644 --- a/Source/Core/Core/HW/DSP.cpp +++ b/Source/Core/Core/HW/DSP.cpp @@ -610,7 +610,7 @@ static void Do_ARAM_DMA() { while (state.aram_dma.Cnt.count) { - memory.Write_U64(HSP::Read(state.aram_dma.ARAddr), state.aram_dma.MMAddr); + memory.Write_U64(system.GetHSP().Read(state.aram_dma.ARAddr), state.aram_dma.MMAddr); state.aram_dma.MMAddr += 8; state.aram_dma.ARAddr += 8; state.aram_dma.Cnt.count -= 8; @@ -662,7 +662,7 @@ static void Do_ARAM_DMA() { while (state.aram_dma.Cnt.count) { - HSP::Write(state.aram_dma.ARAddr, memory.Read_U64(state.aram_dma.MMAddr)); + system.GetHSP().Write(state.aram_dma.ARAddr, memory.Read_U64(state.aram_dma.MMAddr)); state.aram_dma.MMAddr += 8; state.aram_dma.ARAddr += 8; diff --git a/Source/Core/Core/HW/HSP/HSP.cpp b/Source/Core/Core/HW/HSP/HSP.cpp index 562ff662a3..87fccd34f9 100644 --- a/Source/Core/Core/HW/HSP/HSP.cpp +++ b/Source/Core/Core/HW/HSP/HSP.cpp @@ -11,58 +11,59 @@ namespace HSP { -static std::unique_ptr s_device; +HSPManager::HSPManager() = default; +HSPManager::~HSPManager() = default; -void Init() +void HSPManager::Init() { AddDevice(Config::Get(Config::MAIN_HSP_DEVICE)); } -void Shutdown() +void HSPManager::Shutdown() { RemoveDevice(); } -u64 Read(u32 address) +u64 HSPManager::Read(u32 address) { DEBUG_LOG_FMT(HSP, "HSP read from 0x{:08x}", address); - if (s_device) - return s_device->Read(address); + if (m_device) + return m_device->Read(address); return 0; } -void Write(u32 address, u64 value) +void HSPManager::Write(u32 address, u64 value) { DEBUG_LOG_FMT(HSP, "HSP write to 0x{:08x}: 0x{:016x}", address, value); - if (s_device) - s_device->Write(address, value); + if (m_device) + m_device->Write(address, value); } -void DoState(PointerWrap& p) +void HSPManager::DoState(PointerWrap& p) { - HSPDeviceType type = s_device->GetDeviceType(); + HSPDeviceType type = m_device->GetDeviceType(); p.Do(type); // If the type doesn't match, switch to the right device type - if (type != s_device->GetDeviceType()) + if (type != m_device->GetDeviceType()) AddDevice(type); - s_device->DoState(p); + m_device->DoState(p); } -void AddDevice(std::unique_ptr device) +void HSPManager::AddDevice(std::unique_ptr device) { // Set the new one - s_device = std::move(device); + m_device = std::move(device); } -void AddDevice(const HSPDeviceType device) +void HSPManager::AddDevice(const HSPDeviceType device) { AddDevice(HSPDevice_Create(device)); } -void RemoveDevice() +void HSPManager::RemoveDevice() { - s_device.reset(); + m_device.reset(); } } // namespace HSP diff --git a/Source/Core/Core/HW/HSP/HSP.h b/Source/Core/Core/HW/HSP/HSP.h index 1e8f4f772d..5882e4b912 100644 --- a/Source/Core/Core/HW/HSP/HSP.h +++ b/Source/Core/Core/HW/HSP/HSP.h @@ -14,15 +14,29 @@ namespace HSP class IHSPDevice; enum class HSPDeviceType : int; -void Init(); -void Shutdown(); +class HSPManager +{ +public: + HSPManager(); + HSPManager(const HSPManager& other) = delete; + HSPManager(HSPManager&& other) = delete; + HSPManager& operator=(const HSPManager& other) = delete; + HSPManager& operator=(HSPManager&& other) = delete; + ~HSPManager(); -u64 Read(u32 address); -void Write(u32 address, u64 value); + void Init(); + void Shutdown(); -void DoState(PointerWrap& p); + u64 Read(u32 address); + void Write(u32 address, u64 value); -void RemoveDevice(); -void AddDevice(std::unique_ptr device); -void AddDevice(HSPDeviceType device); + void DoState(PointerWrap& p); + + void RemoveDevice(); + void AddDevice(std::unique_ptr device); + void AddDevice(HSPDeviceType device); + +private: + std::unique_ptr m_device; +}; } // namespace HSP diff --git a/Source/Core/Core/HW/HW.cpp b/Source/Core/Core/HW/HW.cpp index f6fe73bd1b..64de70b7a5 100644 --- a/Source/Core/Core/HW/HW.cpp +++ b/Source/Core/Core/HW/HW.cpp @@ -45,7 +45,7 @@ void Init(const Sram* override_sram) SerialInterface::Init(); system.GetProcessorInterface().Init(); ExpansionInterface::Init(override_sram); // Needs to be initialized before Memory - HSP::Init(); + system.GetHSP().Init(); system.GetMemory().Init(); // Needs to be initialized before AddressSpace AddressSpace::Init(); MemoryInterface::Init(); @@ -77,7 +77,7 @@ void Shutdown() MemoryInterface::Shutdown(); AddressSpace::Shutdown(); system.GetMemory().Shutdown(); - HSP::Shutdown(); + system.GetHSP().Shutdown(); ExpansionInterface::Shutdown(); SerialInterface::Shutdown(); AudioInterface::Shutdown(); @@ -109,7 +109,7 @@ void DoState(PointerWrap& p) p.DoMarker("ExpansionInterface"); AudioInterface::DoState(p); p.DoMarker("AudioInterface"); - HSP::DoState(p); + system.GetHSP().DoState(p); p.DoMarker("HSP"); if (SConfig::GetInstance().bWii) diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index e007ab0ffd..58dd46c53f 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -14,6 +14,7 @@ #include "Core/HW/DVD/DVDThread.h" #include "Core/HW/EXI/EXI.h" #include "Core/HW/GPFifo.h" +#include "Core/HW/HSP/HSP.h" #include "Core/HW/Memmap.h" #include "Core/HW/MemoryInterface.h" #include "Core/HW/ProcessorInterface.h" @@ -52,6 +53,7 @@ struct System::Impl Fifo::FifoManager m_fifo; GeometryShaderManager m_geometry_shader_manager; GPFifo::GPFifoManager m_gp_fifo; + HSP::HSPManager m_hsp; IOS::HLE::USB::SkylanderPortal m_skylander_portal; Memory::MemoryManager m_memory; MemoryInterface::MemoryInterfaceState m_memory_interface_state; @@ -158,6 +160,11 @@ GPFifo::GPFifoManager& System::GetGPFifo() const return m_impl->m_gp_fifo; } +HSP::HSPManager& System::GetHSP() const +{ + return m_impl->m_hsp; +} + IOS::HLE::USB::SkylanderPortal& System::GetSkylanderPortal() const { return m_impl->m_skylander_portal; diff --git a/Source/Core/Core/System.h b/Source/Core/Core/System.h index 64ac9fc7e1..286ceabcaf 100644 --- a/Source/Core/Core/System.h +++ b/Source/Core/Core/System.h @@ -47,6 +47,10 @@ namespace GPFifo { class GPFifoManager; } +namespace HSP +{ +class HSPManager; +} namespace IOS::HLE::USB { class SkylanderPortal; @@ -124,6 +128,7 @@ public: Fifo::FifoManager& GetFifo() const; GeometryShaderManager& GetGeometryShaderManager() const; GPFifo::GPFifoManager& GetGPFifo() const; + HSP::HSPManager& GetHSP() const; IOS::HLE::USB::SkylanderPortal& GetSkylanderPortal() const; Memory::MemoryManager& GetMemory() const; MemoryInterface::MemoryInterfaceState& GetMemoryInterfaceState() const;