Merge pull request #4722 from lioncash/si-device

SI_Device: Minor cleanup
This commit is contained in:
Matthew Parlane 2017-01-23 21:28:58 +13:00 committed by GitHub
commit 836f43038a
6 changed files with 53 additions and 37 deletions

View File

@ -18,18 +18,34 @@
#include "Core/HW/SI/SI_DeviceKeyboard.h" #include "Core/HW/SI/SI_DeviceKeyboard.h"
#include "Core/HW/SI/SI_DeviceNull.h" #include "Core/HW/SI/SI_DeviceNull.h"
int ISIDevice::RunBuffer(u8* _pBuffer, int _iLength) ISIDevice::ISIDevice(SIDevices device_type, int device_number)
: m_device_number(device_number), m_device_type(device_type)
{
}
ISIDevice::~ISIDevice() = default;
int ISIDevice::GetDeviceNumber() const
{
return m_device_number;
}
SIDevices ISIDevice::GetDeviceType() const
{
return m_device_type;
}
int ISIDevice::RunBuffer(u8* buffer, int length)
{ {
#ifdef _DEBUG #ifdef _DEBUG
DEBUG_LOG(SERIALINTERFACE, "Send Data Device(%i) - Length(%i) ", ISIDevice::m_iDeviceNumber, DEBUG_LOG(SERIALINTERFACE, "Send Data Device(%i) - Length(%i) ", m_device_number, length);
_iLength);
std::string temp; std::string temp;
int num = 0; int num = 0;
while (num < _iLength) while (num < length)
{ {
temp += StringFromFormat("0x%02x ", _pBuffer[num ^ 3]); temp += StringFromFormat("0x%02x ", buffer[num ^ 3]);
num++; num++;
if ((num % 8) == 0) if ((num % 8) == 0)
@ -49,6 +65,10 @@ int ISIDevice::TransferInterval()
return 0; return 0;
} }
void ISIDevice::DoState(PointerWrap& p)
{
}
// Check if a device class is inheriting from CSIDevice_GCController // Check if a device class is inheriting from CSIDevice_GCController
// The goal of this function is to avoid special casing a long list of // The goal of this function is to avoid special casing a long list of
// device types when there is no "real" input device, e.g. when playing // device types when there is no "real" input device, e.g. when playing

View File

@ -72,35 +72,31 @@ enum SIDevices : int
class ISIDevice class ISIDevice
{ {
protected:
int m_iDeviceNumber;
SIDevices m_deviceType;
public: public:
// Constructor ISIDevice(SIDevices device_type, int device_number);
ISIDevice(SIDevices deviceType, int _iDeviceNumber) virtual ~ISIDevice();
: m_iDeviceNumber(_iDeviceNumber), m_deviceType(deviceType)
{ int GetDeviceNumber() const;
} SIDevices GetDeviceType() const;
// Destructor
virtual ~ISIDevice() {}
// Run the SI Buffer // Run the SI Buffer
virtual int RunBuffer(u8* _pBuffer, int _iLength); virtual int RunBuffer(u8* buffer, int length);
virtual int TransferInterval(); virtual int TransferInterval();
// Return true on new data // Return true on new data
virtual bool GetData(u32& _Hi, u32& _Low) = 0; virtual bool GetData(u32& hi, u32& low) = 0;
// Send a command directly (no detour per buffer) // Send a command directly (no detour per buffer)
virtual void SendCommand(u32 _Cmd, u8 _Poll) = 0; virtual void SendCommand(u32 command, u8 poll) = 0;
// Savestate support // Savestate support
virtual void DoState(PointerWrap& p) {} virtual void DoState(PointerWrap& p);
int GetDeviceNumber() const { return m_iDeviceNumber; }
SIDevices GetDeviceType() const { return m_deviceType; } protected:
int m_device_number;
SIDevices m_device_type;
}; };
bool SIDevice_IsGCController(SIDevices type); bool SIDevice_IsGCController(SIDevices type);
std::unique_ptr<ISIDevice> SIDevice_Create(const SIDevices device, const int port_number); std::unique_ptr<ISIDevice> SIDevice_Create(SIDevices device, int port_number);

View File

@ -19,7 +19,7 @@ CSIDevice_GCAdapter::CSIDevice_GCAdapter(SIDevices device, int _iDeviceNumber)
: CSIDevice_GCController(device, _iDeviceNumber) : CSIDevice_GCController(device, _iDeviceNumber)
{ {
// get the correct pad number that should rumble locally when using netplay // get the correct pad number that should rumble locally when using netplay
const int numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber); const int numPAD = NetPlay_InGamePadToLocalPad(m_device_number);
if (numPAD < 4) if (numPAD < 4)
m_simulate_konga = SConfig::GetInstance().m_AdapterKonga[numPAD]; m_simulate_konga = SConfig::GetInstance().m_AdapterKonga[numPAD];
} }
@ -32,7 +32,7 @@ GCPadStatus CSIDevice_GCAdapter::GetPadStatus()
// the remote controllers receive their status there as well // the remote controllers receive their status there as well
if (!NetPlay::IsNetPlayRunning()) if (!NetPlay::IsNetPlayRunning())
{ {
pad_status = GCAdapter::Input(m_iDeviceNumber); pad_status = GCAdapter::Input(m_device_number);
} }
HandleMoviePadStatus(&pad_status); HandleMoviePadStatus(&pad_status);
@ -50,7 +50,7 @@ int CSIDevice_GCAdapter::RunBuffer(u8* buffer, int length)
// This returns an error value if there is no controller plugged // This returns an error value if there is no controller plugged
// into this port on the hardware gc adapter, exposing it to the game. // into this port on the hardware gc adapter, exposing it to the game.
if (!GCAdapter::DeviceConnected(ISIDevice::m_iDeviceNumber)) if (!GCAdapter::DeviceConnected(m_device_number))
{ {
TSIDevices device = SI_NONE; TSIDevices device = SI_NONE;
memcpy(buffer, &device, sizeof(device)); memcpy(buffer, &device, sizeof(device));

View File

@ -117,25 +117,25 @@ int CSIDevice_GCController::RunBuffer(u8* _pBuffer, int _iLength)
void CSIDevice_GCController::HandleMoviePadStatus(GCPadStatus* PadStatus) void CSIDevice_GCController::HandleMoviePadStatus(GCPadStatus* PadStatus)
{ {
Movie::CallGCInputManip(PadStatus, ISIDevice::m_iDeviceNumber); Movie::CallGCInputManip(PadStatus, m_device_number);
Movie::SetPolledDevice(); Movie::SetPolledDevice();
if (NetPlay_GetInput(ISIDevice::m_iDeviceNumber, PadStatus)) if (NetPlay_GetInput(m_device_number, PadStatus))
{ {
} }
else if (Movie::IsPlayingInput()) else if (Movie::IsPlayingInput())
{ {
Movie::PlayController(PadStatus, ISIDevice::m_iDeviceNumber); Movie::PlayController(PadStatus, m_device_number);
Movie::InputUpdate(); Movie::InputUpdate();
} }
else if (Movie::IsRecordingInput()) else if (Movie::IsRecordingInput())
{ {
Movie::RecordInput(PadStatus, ISIDevice::m_iDeviceNumber); Movie::RecordInput(PadStatus, m_device_number);
Movie::InputUpdate(); Movie::InputUpdate();
} }
else else
{ {
Movie::CheckPadStatus(PadStatus, ISIDevice::m_iDeviceNumber); Movie::CheckPadStatus(PadStatus, m_device_number);
} }
} }
@ -147,7 +147,7 @@ GCPadStatus CSIDevice_GCController::GetPadStatus()
// the remote controllers receive their status there as well // the remote controllers receive their status there as well
if (!NetPlay::IsNetPlayRunning()) if (!NetPlay::IsNetPlayRunning())
{ {
pad_status = Pad::GetStatus(m_iDeviceNumber); pad_status = Pad::GetStatus(m_device_number);
} }
HandleMoviePadStatus(&pad_status); HandleMoviePadStatus(&pad_status);
@ -290,7 +290,7 @@ void CSIDevice_GCController::SendCommand(u32 _Cmd, u8 _Poll)
unsigned int uStrength = command.Parameter2; unsigned int uStrength = command.Parameter2;
// get the correct pad number that should rumble locally when using netplay // get the correct pad number that should rumble locally when using netplay
const int numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber); const int numPAD = NetPlay_InGamePadToLocalPad(m_device_number);
if (numPAD < 4) if (numPAD < 4)
{ {
@ -303,7 +303,7 @@ void CSIDevice_GCController::SendCommand(u32 _Cmd, u8 _Poll)
if (!_Poll) if (!_Poll)
{ {
m_Mode = command.Parameter2; m_Mode = command.Parameter2;
INFO_LOG(SERIALINTERFACE, "PAD %i set to mode %i", ISIDevice::m_iDeviceNumber, m_Mode); INFO_LOG(SERIALINTERFACE, "PAD %i set to mode %i", m_device_number, m_Mode);
} }
} }
break; break;

View File

@ -83,7 +83,7 @@ void CSIDevice_GCSteeringWheel::SendCommand(u32 _Cmd, u8 _Poll)
unsigned int uType = command.Parameter2; // 06 = motor on, 04 = motor off unsigned int uType = command.Parameter2; // 06 = motor on, 04 = motor off
// get the correct pad number that should rumble locally when using netplay // get the correct pad number that should rumble locally when using netplay
const int numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber); const int numPAD = NetPlay_InGamePadToLocalPad(m_device_number);
if (numPAD < 4) if (numPAD < 4)
{ {
@ -102,7 +102,7 @@ void CSIDevice_GCSteeringWheel::SendCommand(u32 _Cmd, u8 _Poll)
if (!_Poll) if (!_Poll)
{ {
m_Mode = command.Parameter2; m_Mode = command.Parameter2;
INFO_LOG(SERIALINTERFACE, "PAD %i set to mode %i", ISIDevice::m_iDeviceNumber, m_Mode); INFO_LOG(SERIALINTERFACE, "PAD %i set to mode %i", m_device_number, m_Mode);
} }
} }
else else

View File

@ -57,7 +57,7 @@ int CSIDevice_Keyboard::RunBuffer(u8* _pBuffer, int _iLength)
KeyboardStatus CSIDevice_Keyboard::GetKeyboardStatus() const KeyboardStatus CSIDevice_Keyboard::GetKeyboardStatus() const
{ {
return Keyboard::GetStatus(m_iDeviceNumber); return Keyboard::GetStatus(m_device_number);
} }
bool CSIDevice_Keyboard::GetData(u32& _Hi, u32& _Low) bool CSIDevice_Keyboard::GetData(u32& _Hi, u32& _Low)