HW/HSP: Make IHSPDevice::GetDeviceType a virtual function to eliminate m_device_type.

This commit is contained in:
Jordan Woyak
2026-03-30 18:04:30 -05:00
parent e20f52ce7c
commit 207fe1f5de
8 changed files with 20 additions and 34 deletions

View File

@@ -12,20 +12,12 @@
namespace HSP
{
IHSPDevice::IHSPDevice(HSPDeviceType device_type) : m_device_type(device_type)
{
}
HSPDeviceType IHSPDevice::GetDeviceType() const
{
return m_device_type;
}
IHSPDevice::~IHSPDevice() = default;
void IHSPDevice::DoState(PointerWrap& p)
{
}
// F A C T O R Y
std::unique_ptr<IHSPDevice> HSPDevice_Create(const HSPDeviceType device)
{
auto& system = Core::System::GetInstance();
@@ -33,12 +25,12 @@ std::unique_ptr<IHSPDevice> HSPDevice_Create(const HSPDeviceType device)
switch (device)
{
case HSPDeviceType::ARAMExpansion:
return std::make_unique<CHSPDevice_ARAMExpansion>(device);
return std::make_unique<CHSPDevice_ARAMExpansion>();
case HSPDeviceType::GBPlayer:
return std::make_unique<CHSPDevice_GBPlayer>(system, device);
return std::make_unique<CHSPDevice_GBPlayer>(system);
case HSPDeviceType::None:
default:
return std::make_unique<CHSPDevice_Null>(device);
return std::make_unique<CHSPDevice_Null>();
}
}
} // namespace HSP

View File

@@ -21,19 +21,15 @@ enum class HSPDeviceType : int
class IHSPDevice
{
public:
explicit IHSPDevice(HSPDeviceType device_type);
virtual ~IHSPDevice() = default;
virtual ~IHSPDevice();
HSPDeviceType GetDeviceType() const;
virtual HSPDeviceType GetDeviceType() const = 0;
virtual void Write(u32 address, u64 value) = 0;
virtual u64 Read(u32 address) = 0;
// Savestate support
virtual void DoState(PointerWrap& p);
protected:
HSPDeviceType m_device_type;
};
std::unique_ptr<IHSPDevice> HSPDevice_Create(HSPDeviceType device);

View File

@@ -14,7 +14,7 @@
namespace HSP
{
CHSPDevice_ARAMExpansion::CHSPDevice_ARAMExpansion(HSPDeviceType device) : IHSPDevice(device)
CHSPDevice_ARAMExpansion::CHSPDevice_ARAMExpansion()
{
m_size = MathUtil::NextPowerOf2(Config::Get(Config::MAIN_ARAM_EXPANSION_SIZE));
m_mask = m_size - 1;

View File

@@ -7,12 +7,14 @@
namespace HSP
{
class CHSPDevice_ARAMExpansion : public IHSPDevice
class CHSPDevice_ARAMExpansion final : public IHSPDevice
{
public:
explicit CHSPDevice_ARAMExpansion(HSPDeviceType device);
explicit CHSPDevice_ARAMExpansion();
~CHSPDevice_ARAMExpansion() override;
HSPDeviceType GetDeviceType() const override { return HSPDeviceType::ARAMExpansion; }
void Write(u32 address, u64 value) override;
u64 Read(u32 address) override;

View File

@@ -53,7 +53,7 @@ constexpr u8 CONTROL_MASK_IRQ = 0x10;
constexpr u32 COMMAND_ADDRESS_MASK = 0x1f;
constexpr u32 AV_ADDRESS_MASK = 0xff8;
class CGBPlayer_Dummy : public HSP::IGBPlayer
class CGBPlayer_Dummy final : public HSP::IGBPlayer
{
public:
using IGBPlayer::IGBPlayer;
@@ -89,7 +89,7 @@ enum class CHSPDevice_GBPlayer::IRQ : int
#if defined(HAS_LIBMGBA)
class CGBPlayer_mGBA : public IGBPlayer
class CGBPlayer_mGBA final : public IGBPlayer
{
public:
CGBPlayer_mGBA(Core::System&, CHSPDevice_GBPlayer*);
@@ -389,8 +389,7 @@ void CGBPlayer_mGBA::UpdateVideo(u32 scanline_index, s64 cycles_late)
#endif
CHSPDevice_GBPlayer::CHSPDevice_GBPlayer(Core::System& system, HSPDeviceType device)
: IHSPDevice(device), m_system{system}
CHSPDevice_GBPlayer::CHSPDevice_GBPlayer(Core::System& system) : m_system{system}
{
#if defined(HAS_LIBMGBA)
m_gbp = std::make_unique<CGBPlayer_mGBA>(m_system, this);

View File

@@ -50,12 +50,14 @@ protected:
CHSPDevice_GBPlayer* const m_player;
};
class CHSPDevice_GBPlayer : public IHSPDevice
class CHSPDevice_GBPlayer final : public IHSPDevice
{
public:
enum class IRQ : int;
CHSPDevice_GBPlayer(Core::System& system, HSPDeviceType device);
explicit CHSPDevice_GBPlayer(Core::System& system);
HSPDeviceType GetDeviceType() const override { return HSPDeviceType::GBPlayer; }
void Write(u32 address, u64 value) override;
u64 Read(u32 address) override;

View File

@@ -3,13 +3,8 @@
#include "Core/HW/HSP/HSP_DeviceNull.h"
#include "Core/HW/HSP/HSP.h"
namespace HSP
{
CHSPDevice_Null::CHSPDevice_Null(HSPDeviceType device) : IHSPDevice(device)
{
}
u64 CHSPDevice_Null::Read(u32 address)
{

View File

@@ -8,10 +8,10 @@
namespace HSP
{
class CHSPDevice_Null : public IHSPDevice
class CHSPDevice_Null final : public IHSPDevice
{
public:
explicit CHSPDevice_Null(HSPDeviceType device);
HSPDeviceType GetDeviceType() const override { return HSPDeviceType::None; }
void Write(u32 address, u64 value) override;
u64 Read(u32 address) override;