HW/SerialInterface: Pass System to ISIDevice.

This commit is contained in:
Admiral H. Curtiss 2023-03-12 14:19:38 +01:00
parent 5d07a45241
commit d371b17f37
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
19 changed files with 72 additions and 67 deletions

View File

@ -367,7 +367,7 @@ void DoState(PointerWrap& p)
if (type != device->GetDeviceType())
{
AddDevice(SIDevice_Create(type, i));
AddDevice(SIDevice_Create(Core::System::GetInstance(), type, i));
}
device->DoState(p);
@ -672,7 +672,7 @@ void AddDevice(std::unique_ptr<ISIDevice> device)
void AddDevice(const SIDevices device, int device_number)
{
AddDevice(SIDevice_Create(device, device_number));
AddDevice(SIDevice_Create(Core::System::GetInstance(), device, device_number));
}
void ChangeDevice(SIDevices device, int channel)

View File

@ -55,8 +55,8 @@ std::istream& operator>>(std::istream& stream, SIDevices& device)
return stream;
}
ISIDevice::ISIDevice(SIDevices device_type, int device_number)
: m_device_number(device_number), m_device_type(device_type)
ISIDevice::ISIDevice(Core::System& system, SIDevices device_type, int device_number)
: m_system(system), m_device_number(device_number), m_device_type(device_type)
{
}
@ -169,43 +169,44 @@ bool SIDevice_IsGCController(SIDevices type)
}
// F A C T O R Y
std::unique_ptr<ISIDevice> SIDevice_Create(const SIDevices device, const int port_number)
std::unique_ptr<ISIDevice> SIDevice_Create(Core::System& system, const SIDevices device,
const int port_number)
{
switch (device)
{
case SIDEVICE_GC_CONTROLLER:
return std::make_unique<CSIDevice_GCController>(device, port_number);
return std::make_unique<CSIDevice_GCController>(system, device, port_number);
case SIDEVICE_WIIU_ADAPTER:
return std::make_unique<CSIDevice_GCAdapter>(device, port_number);
return std::make_unique<CSIDevice_GCAdapter>(system, device, port_number);
case SIDEVICE_DANCEMAT:
return std::make_unique<CSIDevice_DanceMat>(device, port_number);
return std::make_unique<CSIDevice_DanceMat>(system, device, port_number);
case SIDEVICE_GC_STEERING:
return std::make_unique<CSIDevice_GCSteeringWheel>(device, port_number);
return std::make_unique<CSIDevice_GCSteeringWheel>(system, device, port_number);
case SIDEVICE_GC_TARUKONGA:
return std::make_unique<CSIDevice_TaruKonga>(device, port_number);
return std::make_unique<CSIDevice_TaruKonga>(system, device, port_number);
case SIDEVICE_GC_GBA:
return std::make_unique<CSIDevice_GBA>(device, port_number);
return std::make_unique<CSIDevice_GBA>(system, device, port_number);
case SIDEVICE_GC_GBA_EMULATED:
#ifdef HAS_LIBMGBA
return std::make_unique<CSIDevice_GBAEmu>(device, port_number);
return std::make_unique<CSIDevice_GBAEmu>(system, device, port_number);
#else
PanicAlertFmtT("Error: This build does not support emulated GBA controllers");
return std::make_unique<CSIDevice_Null>(device, port_number);
return std::make_unique<CSIDevice_Null>(system, device, port_number);
#endif
case SIDEVICE_GC_KEYBOARD:
return std::make_unique<CSIDevice_Keyboard>(device, port_number);
return std::make_unique<CSIDevice_Keyboard>(system, device, port_number);
case SIDEVICE_AM_BASEBOARD:
case SIDEVICE_NONE:
default:
return std::make_unique<CSIDevice_Null>(device, port_number);
return std::make_unique<CSIDevice_Null>(system, device, port_number);
}
}
} // namespace SerialInterface

View File

@ -8,6 +8,10 @@
#include "Common/CommonTypes.h"
class PointerWrap;
namespace Core
{
class System;
}
namespace SerialInterface
{
@ -105,7 +109,7 @@ std::istream& operator>>(std::istream& stream, SIDevices& device);
class ISIDevice
{
public:
ISIDevice(SIDevices device_type, int device_number);
ISIDevice(Core::System& system, SIDevices device_type, int device_number);
virtual ~ISIDevice();
int GetDeviceNumber() const;
@ -128,6 +132,8 @@ public:
virtual void OnEvent(u64 userdata, s64 cycles_late);
protected:
Core::System& m_system;
int m_device_number;
SIDevices m_device_type;
};
@ -135,5 +141,5 @@ protected:
int SIDevice_GetGBATransferTime(EBufferCommands cmd);
bool SIDevice_IsGCController(SIDevices type);
std::unique_ptr<ISIDevice> SIDevice_Create(SIDevices device, int port_number);
std::unique_ptr<ISIDevice> SIDevice_Create(Core::System& system, SIDevices device, int port_number);
} // namespace SerialInterface

View File

@ -11,8 +11,8 @@
namespace SerialInterface
{
CSIDevice_DanceMat::CSIDevice_DanceMat(SIDevices device, int device_number)
: CSIDevice_GCController(device, device_number)
CSIDevice_DanceMat::CSIDevice_DanceMat(Core::System& system, SIDevices device, int device_number)
: CSIDevice_GCController(system, device, device_number)
{
}

View File

@ -10,10 +10,10 @@ struct GCPadStatus;
namespace SerialInterface
{
class CSIDevice_DanceMat : public CSIDevice_GCController
class CSIDevice_DanceMat final : public CSIDevice_GCController
{
public:
CSIDevice_DanceMat(SIDevices device, int device_number);
CSIDevice_DanceMat(Core::System& system, SIDevices device, int device_number);
int RunBuffer(u8* buffer, int request_length) override;
u32 MapPadStatus(const GCPadStatus& pad_status) override;

View File

@ -140,13 +140,12 @@ void GBASockServer::Disconnect()
m_booted = false;
}
void GBASockServer::ClockSync()
void GBASockServer::ClockSync(Core::System& system)
{
if (!m_clock_sync)
if (!(m_clock_sync = GetNextClock()))
return;
auto& system = Core::System::GetInstance();
auto& core_timing = system.GetCoreTiming();
u32 time_slice = 0;
@ -263,7 +262,8 @@ void GBASockServer::Flush()
}
}
CSIDevice_GBA::CSIDevice_GBA(SIDevices device, int device_number) : ISIDevice(device, device_number)
CSIDevice_GBA::CSIDevice_GBA(Core::System& system, SIDevices device, int device_number)
: ISIDevice(system, device, device_number)
{
}
@ -273,7 +273,7 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length)
{
case NextAction::SendCommand:
{
m_sock_server.ClockSync();
m_sock_server.ClockSync(m_system);
if (m_sock_server.Connect())
{
#ifdef _DEBUG
@ -289,15 +289,14 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length)
}
m_last_cmd = static_cast<EBufferCommands>(buffer[0]);
m_timestamp_sent = Core::System::GetInstance().GetCoreTiming().GetTicks();
m_timestamp_sent = m_system.GetCoreTiming().GetTicks();
m_next_action = NextAction::WaitTransferTime;
return 0;
}
case NextAction::WaitTransferTime:
{
int elapsed_time =
static_cast<int>(Core::System::GetInstance().GetCoreTiming().GetTicks() - m_timestamp_sent);
int elapsed_time = static_cast<int>(m_system.GetCoreTiming().GetTicks() - m_timestamp_sent);
// Tell SI to ask again after TransferInterval() cycles
if (SIDevice_GetGBATransferTime(m_last_cmd) > elapsed_time)
return 0;

View File

@ -25,7 +25,7 @@ public:
bool Connect();
bool IsConnected();
void ClockSync();
void ClockSync(Core::System& system);
void Send(const u8* si_buffer);
int Receive(u8* si_buffer, u8 bytes);
void Flush();
@ -40,10 +40,10 @@ private:
bool m_booted = false;
};
class CSIDevice_GBA : public ISIDevice
class CSIDevice_GBA final : public ISIDevice
{
public:
CSIDevice_GBA(SIDevices device, int device_number);
CSIDevice_GBA(Core::System& system, SIDevices device, int device_number);
int RunBuffer(u8* buffer, int request_length) override;
int TransferInterval() override;

View File

@ -27,11 +27,11 @@ static s64 GetSyncInterval()
return SystemTimers::GetTicksPerSecond() / 1000;
}
CSIDevice_GBAEmu::CSIDevice_GBAEmu(SIDevices device, int device_number)
: ISIDevice(device, device_number)
CSIDevice_GBAEmu::CSIDevice_GBAEmu(Core::System& system, SIDevices device, int device_number)
: ISIDevice(system, device, device_number)
{
m_core = std::make_shared<HW::GBA::Core>(m_device_number);
m_core->Start(Core::System::GetInstance().GetCoreTiming().GetTicks());
m_core->Start(system.GetCoreTiming().GetTicks());
m_gbahost = Host_CreateGBAHost(m_core);
m_core->SetHost(m_gbahost);
ScheduleEvent(m_device_number, GetSyncInterval());
@ -56,7 +56,7 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length)
buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
#endif
m_last_cmd = static_cast<EBufferCommands>(buffer[0]);
m_timestamp_sent = Core::System::GetInstance().GetCoreTiming().GetTicks();
m_timestamp_sent = m_system.GetCoreTiming().GetTicks();
m_core->SendJoybusCommand(m_timestamp_sent, TransferInterval(), buffer, m_keys);
RemoveEvent(m_device_number);
@ -75,8 +75,7 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length)
case NextAction::WaitTransferTime:
{
int elapsed_time =
static_cast<int>(Core::System::GetInstance().GetCoreTiming().GetTicks() - m_timestamp_sent);
int elapsed_time = static_cast<int>(m_system.GetCoreTiming().GetTicks() - m_timestamp_sent);
// Tell SI to ask again after TransferInterval() cycles
if (TransferInterval() > elapsed_time)
return 0;
@ -164,8 +163,7 @@ void CSIDevice_GBAEmu::DoState(PointerWrap& p)
void CSIDevice_GBAEmu::OnEvent(u64 userdata, s64 cycles_late)
{
m_core->SendJoybusCommand(Core::System::GetInstance().GetCoreTiming().GetTicks() + userdata, 0,
nullptr, m_keys);
m_core->SendJoybusCommand(m_system.GetCoreTiming().GetTicks() + userdata, 0, nullptr, m_keys);
ScheduleEvent(m_device_number, userdata + GetSyncInterval());
}
} // namespace SerialInterface

View File

@ -17,10 +17,10 @@ class GBAHostInterface;
namespace SerialInterface
{
class CSIDevice_GBAEmu : public ISIDevice
class CSIDevice_GBAEmu final : public ISIDevice
{
public:
CSIDevice_GBAEmu(SIDevices device, int device_number);
CSIDevice_GBAEmu(Core::System& system, SIDevices device, int device_number);
~CSIDevice_GBAEmu();
int RunBuffer(u8* buffer, int request_length) override;

View File

@ -15,8 +15,8 @@
namespace SerialInterface
{
CSIDevice_GCAdapter::CSIDevice_GCAdapter(SIDevices device, int device_number)
: CSIDevice_GCController(device, device_number)
CSIDevice_GCAdapter::CSIDevice_GCAdapter(Core::System& system, SIDevices device, int device_number)
: CSIDevice_GCController(system, device, device_number)
{
// Make sure PAD_GET_ORIGIN gets set due to a newly connected device.
GCAdapter::ResetDeviceType(m_device_number);

View File

@ -9,10 +9,10 @@
namespace SerialInterface
{
class CSIDevice_GCAdapter : public CSIDevice_GCController
class CSIDevice_GCAdapter final : public CSIDevice_GCController
{
public:
CSIDevice_GCAdapter(SIDevices device, int device_number);
CSIDevice_GCAdapter(Core::System& system, SIDevices device, int device_number);
GCPadStatus GetPadStatus() override;
int RunBuffer(u8* buffer, int request_length) override;

View File

@ -24,8 +24,9 @@
namespace SerialInterface
{
// --- standard GameCube controller ---
CSIDevice_GCController::CSIDevice_GCController(SIDevices device, int device_number)
: ISIDevice(device, device_number)
CSIDevice_GCController::CSIDevice_GCController(Core::System& system, SIDevices device,
int device_number)
: ISIDevice(system, device, device_number)
{
// Here we set origin to perfectly centered values.
// This purposely differs from real hardware which sets origin to current input state.
@ -264,19 +265,18 @@ CSIDevice_GCController::HandleButtonCombos(const GCPadStatus& pad_status)
{
m_last_button_combo = temp_combo;
if (m_last_button_combo != COMBO_NONE)
m_timer_button_combo_start = Core::System::GetInstance().GetCoreTiming().GetTicks();
m_timer_button_combo_start = m_system.GetCoreTiming().GetTicks();
}
if (m_last_button_combo != COMBO_NONE)
{
auto& system = Core::System::GetInstance();
const u64 current_time = system.GetCoreTiming().GetTicks();
const u64 current_time = m_system.GetCoreTiming().GetTicks();
if (u32(current_time - m_timer_button_combo_start) > SystemTimers::GetTicksPerSecond() * 3)
{
if (m_last_button_combo == COMBO_RESET)
{
INFO_LOG_FMT(SERIALINTERFACE, "PAD - COMBO_RESET");
system.GetProcessorInterface().ResetButton_Tap();
m_system.GetProcessorInterface().ResetButton_Tap();
}
else if (m_last_button_combo == COMBO_ORIGIN)
{
@ -355,8 +355,8 @@ void CSIDevice_GCController::RefreshConfig()
}
}
CSIDevice_TaruKonga::CSIDevice_TaruKonga(SIDevices device, int device_number)
: CSIDevice_GCController(device, device_number)
CSIDevice_TaruKonga::CSIDevice_TaruKonga(Core::System& system, SIDevices device, int device_number)
: CSIDevice_GCController(system, device, device_number)
{
}

View File

@ -53,7 +53,7 @@ protected:
public:
// Constructor
CSIDevice_GCController(SIDevices device, int device_number);
CSIDevice_GCController(Core::System& system, SIDevices device, int device_number);
~CSIDevice_GCController() override;
// Run the SI Buffer
@ -92,10 +92,10 @@ private:
};
// "TaruKonga", the DK Bongo controller
class CSIDevice_TaruKonga : public CSIDevice_GCController
class CSIDevice_TaruKonga final : public CSIDevice_GCController
{
public:
CSIDevice_TaruKonga(SIDevices device, int device_number);
CSIDevice_TaruKonga(Core::System& system, SIDevices device, int device_number);
bool GetData(u32& hi, u32& low) override;

View File

@ -14,8 +14,9 @@
namespace SerialInterface
{
CSIDevice_GCSteeringWheel::CSIDevice_GCSteeringWheel(SIDevices device, int device_number)
: CSIDevice_GCController(device, device_number)
CSIDevice_GCSteeringWheel::CSIDevice_GCSteeringWheel(Core::System& system, SIDevices device,
int device_number)
: CSIDevice_GCController(system, device, device_number)
{
}

View File

@ -7,10 +7,10 @@
namespace SerialInterface
{
class CSIDevice_GCSteeringWheel : public CSIDevice_GCController
class CSIDevice_GCSteeringWheel final : public CSIDevice_GCController
{
public:
CSIDevice_GCSteeringWheel(SIDevices device, int device_number);
CSIDevice_GCSteeringWheel(Core::System& system, SIDevices device, int device_number);
int RunBuffer(u8* buffer, int request_length) override;
bool GetData(u32& hi, u32& low) override;

View File

@ -16,8 +16,8 @@
namespace SerialInterface
{
// --- GameCube keyboard ---
CSIDevice_Keyboard::CSIDevice_Keyboard(SIDevices device, int device_number)
: ISIDevice(device, device_number)
CSIDevice_Keyboard::CSIDevice_Keyboard(Core::System& system, SIDevices device, int device_number)
: ISIDevice(system, device, device_number)
{
}

View File

@ -12,11 +12,11 @@ struct KeyboardStatus;
namespace SerialInterface
{
class CSIDevice_Keyboard : public ISIDevice
class CSIDevice_Keyboard final : public ISIDevice
{
public:
// Constructor
CSIDevice_Keyboard(SIDevices device, int device_number);
CSIDevice_Keyboard(Core::System& system, SIDevices device, int device_number);
// Run the SI Buffer
int RunBuffer(u8* buffer, int request_length) override;

View File

@ -5,8 +5,8 @@
namespace SerialInterface
{
CSIDevice_Null::CSIDevice_Null(SIDevices device, int device_number)
: ISIDevice{device, device_number}
CSIDevice_Null::CSIDevice_Null(Core::System& system, SIDevices device, int device_number)
: ISIDevice{system, device, device_number}
{
}

View File

@ -12,7 +12,7 @@ namespace SerialInterface
class CSIDevice_Null final : public ISIDevice
{
public:
CSIDevice_Null(SIDevices device, int device_number);
CSIDevice_Null(Core::System& system, SIDevices device, int device_number);
int RunBuffer(u8* buffer, int request_length) override;
bool GetData(u32& hi, u32& low) override;