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