Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11629 from AdmiralCurtiss/globals-hsp
HW/HSP: Refactor to class, move to System.
  • Loading branch information
lioncash committed Mar 7, 2023
2 parents 560a239 + f389da2 commit 0461fae
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/DSP.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 19 additions & 18 deletions Source/Core/Core/HW/HSP/HSP.cpp
Expand Up @@ -11,58 +11,59 @@

namespace HSP
{
static std::unique_ptr<IHSPDevice> 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<IHSPDevice> device)
void HSPManager::AddDevice(std::unique_ptr<IHSPDevice> 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
30 changes: 22 additions & 8 deletions Source/Core/Core/HW/HSP/HSP.h
Expand Up @@ -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();

void Init();
void Shutdown();

u64 Read(u32 address);
void Write(u32 address, u64 value);

u64 Read(u32 address);
void Write(u32 address, u64 value);
void DoState(PointerWrap& p);

void DoState(PointerWrap& p);
void RemoveDevice();
void AddDevice(std::unique_ptr<IHSPDevice> device);
void AddDevice(HSPDeviceType device);

void RemoveDevice();
void AddDevice(std::unique_ptr<IHSPDevice> device);
void AddDevice(HSPDeviceType device);
private:
std::unique_ptr<IHSPDevice> m_device;
};
} // namespace HSP
6 changes: 3 additions & 3 deletions Source/Core/Core/HW/HW.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -77,7 +77,7 @@ void Shutdown()
MemoryInterface::Shutdown();
AddressSpace::Shutdown();
system.GetMemory().Shutdown();
HSP::Shutdown();
system.GetHSP().Shutdown();
ExpansionInterface::Shutdown();
SerialInterface::Shutdown();
AudioInterface::Shutdown();
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/System.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/System.h
Expand Up @@ -47,6 +47,10 @@ namespace GPFifo
{
class GPFifoManager;
}
namespace HSP
{
class HSPManager;
}
namespace IOS::HLE::USB
{
class SkylanderPortal;
Expand Down Expand Up @@ -124,6 +128,7 @@ class System
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;
Expand Down

0 comments on commit 0461fae

Please sign in to comment.