GCPad: Return input state by value
This commit is contained in:
parent
84c936cab8
commit
ee43820282
|
@ -46,13 +46,9 @@ void LoadConfig()
|
|||
s_config.LoadConfig(true);
|
||||
}
|
||||
|
||||
void GetStatus(u8 pad_num, GCPadStatus* pad_status)
|
||||
GCPadStatus GetStatus(u8 pad_num)
|
||||
{
|
||||
memset(pad_status, 0, sizeof(*pad_status));
|
||||
pad_status->err = PAD_ERR_NONE;
|
||||
|
||||
// Get input
|
||||
static_cast<GCPad*>(s_config.GetController(pad_num))->GetInput(pad_status);
|
||||
return static_cast<GCPad*>(s_config.GetController(pad_num))->GetInput();
|
||||
}
|
||||
|
||||
void Rumble(const u8 pad_num, const ControlState strength)
|
||||
|
|
|
@ -18,7 +18,7 @@ void LoadConfig();
|
|||
|
||||
InputConfig* GetConfig();
|
||||
|
||||
void GetStatus(u8 pad_num, GCPadStatus* pad_status);
|
||||
GCPadStatus GetStatus(u8 pad_num);
|
||||
void Rumble(u8 pad_num, ControlState strength);
|
||||
|
||||
bool GetMicButton(u8 pad_num);
|
||||
|
|
|
@ -79,41 +79,44 @@ std::string GCPad::GetName() const
|
|||
return std::string("GCPad") + char('1' + m_index);
|
||||
}
|
||||
|
||||
void GCPad::GetInput(GCPadStatus* const pad)
|
||||
GCPadStatus GCPad::GetInput() const
|
||||
{
|
||||
auto lock = ControllerEmu::GetStateLock();
|
||||
|
||||
ControlState x, y, triggers[2];
|
||||
GCPadStatus pad = {};
|
||||
|
||||
// buttons
|
||||
m_buttons->GetState(&pad->button, button_bitmasks);
|
||||
m_buttons->GetState(&pad.button, button_bitmasks);
|
||||
|
||||
// set analog A/B analog to full or w/e, prolly not needed
|
||||
if (pad->button & PAD_BUTTON_A)
|
||||
pad->analogA = 0xFF;
|
||||
if (pad->button & PAD_BUTTON_B)
|
||||
pad->analogB = 0xFF;
|
||||
if (pad.button & PAD_BUTTON_A)
|
||||
pad.analogA = 0xFF;
|
||||
if (pad.button & PAD_BUTTON_B)
|
||||
pad.analogB = 0xFF;
|
||||
|
||||
// dpad
|
||||
m_dpad->GetState(&pad->button, dpad_bitmasks);
|
||||
m_dpad->GetState(&pad.button, dpad_bitmasks);
|
||||
|
||||
// sticks
|
||||
m_main_stick->GetState(&x, &y);
|
||||
pad->stickX =
|
||||
pad.stickX =
|
||||
static_cast<u8>(GCPadStatus::MAIN_STICK_CENTER_X + (x * GCPadStatus::MAIN_STICK_RADIUS));
|
||||
pad->stickY =
|
||||
pad.stickY =
|
||||
static_cast<u8>(GCPadStatus::MAIN_STICK_CENTER_Y + (y * GCPadStatus::MAIN_STICK_RADIUS));
|
||||
|
||||
m_c_stick->GetState(&x, &y);
|
||||
pad->substickX =
|
||||
pad.substickX =
|
||||
static_cast<u8>(GCPadStatus::C_STICK_CENTER_X + (x * GCPadStatus::C_STICK_RADIUS));
|
||||
pad->substickY =
|
||||
pad.substickY =
|
||||
static_cast<u8>(GCPadStatus::C_STICK_CENTER_Y + (y * GCPadStatus::C_STICK_RADIUS));
|
||||
|
||||
// triggers
|
||||
m_triggers->GetState(&pad->button, trigger_bitmasks, triggers);
|
||||
pad->triggerLeft = static_cast<u8>(triggers[0] * 0xFF);
|
||||
pad->triggerRight = static_cast<u8>(triggers[1] * 0xFF);
|
||||
m_triggers->GetState(&pad.button, trigger_bitmasks, triggers);
|
||||
pad.triggerLeft = static_cast<u8>(triggers[0] * 0xFF);
|
||||
pad.triggerRight = static_cast<u8>(triggers[1] * 0xFF);
|
||||
|
||||
return pad;
|
||||
}
|
||||
|
||||
void GCPad::SetOutput(const ControlState strength)
|
||||
|
|
|
@ -12,7 +12,7 @@ class GCPad : public ControllerEmu
|
|||
{
|
||||
public:
|
||||
GCPad(const unsigned int index);
|
||||
void GetInput(GCPadStatus* const pad);
|
||||
GCPadStatus GetInput() const;
|
||||
void SetOutput(const ControlState strength);
|
||||
|
||||
bool GetMicButton() const;
|
||||
|
|
|
@ -132,16 +132,14 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* _pBuffer, int _iLength)
|
|||
case 0x10:
|
||||
{
|
||||
DEBUG_LOG(AMBASEBOARDDEBUG, "GC-AM: Command 10, %02x (READ STATUS&SWITCHES)", ptr(1));
|
||||
GCPadStatus PadStatus;
|
||||
memset(&PadStatus, 0, sizeof(PadStatus));
|
||||
Pad::GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
|
||||
GCPadStatus pad_status = Pad::GetStatus(m_iDeviceNumber);
|
||||
res[resp++] = 0x10;
|
||||
res[resp++] = 0x2;
|
||||
int d10_0 = 0xdf;
|
||||
|
||||
if (PadStatus.triggerLeft)
|
||||
if (pad_status.triggerLeft)
|
||||
d10_0 &= ~0x80;
|
||||
if (PadStatus.triggerRight)
|
||||
if (pad_status.triggerRight)
|
||||
d10_0 &= ~0x40;
|
||||
|
||||
res[resp++] = d10_0;
|
||||
|
@ -299,32 +297,31 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* _pBuffer, int _iLength)
|
|||
msg.AddData(0); // tilt
|
||||
for (i = 0; i < nr_players; ++i)
|
||||
{
|
||||
GCPadStatus PadStatus;
|
||||
Pad::GetStatus(i, &PadStatus);
|
||||
GCPadStatus pad_status = Pad::GetStatus(i);
|
||||
unsigned char player_data[2] = {0, 0};
|
||||
if (PadStatus.button & PAD_BUTTON_START)
|
||||
if (pad_status.button & PAD_BUTTON_START)
|
||||
player_data[0] |= 0x80;
|
||||
if (PadStatus.button & PAD_BUTTON_UP)
|
||||
if (pad_status.button & PAD_BUTTON_UP)
|
||||
player_data[0] |= 0x20;
|
||||
if (PadStatus.button & PAD_BUTTON_DOWN)
|
||||
if (pad_status.button & PAD_BUTTON_DOWN)
|
||||
player_data[0] |= 0x10;
|
||||
if (PadStatus.button & PAD_BUTTON_LEFT)
|
||||
if (pad_status.button & PAD_BUTTON_LEFT)
|
||||
player_data[0] |= 0x08;
|
||||
if (PadStatus.button & PAD_BUTTON_RIGHT)
|
||||
if (pad_status.button & PAD_BUTTON_RIGHT)
|
||||
player_data[0] |= 0x04;
|
||||
|
||||
if (PadStatus.button & PAD_BUTTON_A)
|
||||
if (pad_status.button & PAD_BUTTON_A)
|
||||
player_data[0] |= 0x02;
|
||||
if (PadStatus.button & PAD_BUTTON_B)
|
||||
if (pad_status.button & PAD_BUTTON_B)
|
||||
player_data[0] |= 0x01;
|
||||
|
||||
if (PadStatus.button & PAD_BUTTON_X)
|
||||
if (pad_status.button & PAD_BUTTON_X)
|
||||
player_data[1] |= 0x80;
|
||||
if (PadStatus.button & PAD_BUTTON_Y)
|
||||
if (pad_status.button & PAD_BUTTON_Y)
|
||||
player_data[1] |= 0x40;
|
||||
if (PadStatus.button & PAD_TRIGGER_L)
|
||||
if (pad_status.button & PAD_TRIGGER_L)
|
||||
player_data[1] |= 0x20;
|
||||
if (PadStatus.button & PAD_TRIGGER_R)
|
||||
if (pad_status.button & PAD_TRIGGER_R)
|
||||
player_data[1] |= 0x10;
|
||||
|
||||
for (j = 0; j < bytes_per_player; ++j)
|
||||
|
@ -336,12 +333,11 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* _pBuffer, int _iLength)
|
|||
{
|
||||
int slots = *jvs_io++;
|
||||
msg.AddData(1);
|
||||
GCPadStatus PadStatus;
|
||||
Pad::GetStatus(0, &PadStatus);
|
||||
GCPadStatus pad_status = Pad::GetStatus(0);
|
||||
while (slots--)
|
||||
{
|
||||
msg.AddData(0);
|
||||
msg.AddData((PadStatus.button & PAD_BUTTON_START) ? 1 : 0);
|
||||
msg.AddData((pad_status.button & PAD_BUTTON_START) ? 1 : 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -140,18 +140,17 @@ void CSIDevice_GCController::HandleMoviePadStatus(GCPadStatus* PadStatus)
|
|||
|
||||
GCPadStatus CSIDevice_GCController::GetPadStatus()
|
||||
{
|
||||
GCPadStatus PadStatus;
|
||||
memset(&PadStatus, 0, sizeof(PadStatus));
|
||||
GCPadStatus pad_status = {};
|
||||
|
||||
// For netplay, the local controllers are polled in GetNetPads(), and
|
||||
// the remote controllers receive their status there as well
|
||||
if (!NetPlay::IsNetPlayRunning())
|
||||
{
|
||||
Pad::GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
|
||||
pad_status = Pad::GetStatus(m_iDeviceNumber);
|
||||
}
|
||||
|
||||
HandleMoviePadStatus(&PadStatus);
|
||||
return PadStatus;
|
||||
HandleMoviePadStatus(&pad_status);
|
||||
return pad_status;
|
||||
}
|
||||
|
||||
// GetData
|
||||
|
|
|
@ -977,7 +977,7 @@ bool NetPlayClient::GetNetPads(const u8 pad_nb, GCPadStatus* pad_status)
|
|||
break;
|
||||
case SIDEVICE_GC_CONTROLLER:
|
||||
default:
|
||||
Pad::GetStatus(local_pad, pad_status);
|
||||
*pad_status = Pad::GetStatus(local_pad);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue