Fix GameCube button detection

This should fix the issue where R/L buttons didn't register when doing
input detection.

This also brings the GC pad in line with the rest of the gamepads in
input_autodetect_builtin.c.

Also fixed a really stupid bug that was part of why analog inputs aren't
being read. Analog still isn't working, mind, but it's a lot closer to
working now that it's actually getting down into the pad driver level!
This commit is contained in:
gblues 2018-04-20 00:00:33 -07:00
parent 53738e4a0d
commit 0c92fab0b9
3 changed files with 63 additions and 18 deletions

View file

@ -212,6 +212,38 @@ static void wiiu_gca_get_buttons(void *data, input_bits_t *state)
}
}
static void update_buttons(gca_pad_t *pad)
{
uint32_t i, pressed_keys;
static const uint32_t button_mapping[12] =
{
RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_X,
RETRO_DEVICE_ID_JOYPAD_Y,
RETRO_DEVICE_ID_JOYPAD_LEFT,
RETRO_DEVICE_ID_JOYPAD_RIGHT,
RETRO_DEVICE_ID_JOYPAD_DOWN,
RETRO_DEVICE_ID_JOYPAD_UP,
RETRO_DEVICE_ID_JOYPAD_START,
RETRO_DEVICE_ID_JOYPAD_SELECT,
RETRO_DEVICE_ID_JOYPAD_R,
RETRO_DEVICE_ID_JOYPAD_L,
};
if(!pad)
return;
pressed_keys = pad->data[1] | (pad->data[2] << 8);
pad->buttons = 0;
for(i = 0; i < 12; i++)
pad->buttons |= (pressed_keys & (1 << i)) ?
(1 << button_mapping[i]) : 0;
}
/**
* The USB packet provides a 9-byte data packet for each pad.
*
@ -230,9 +262,11 @@ static void wiiu_gca_packet_handler(void *data, uint8_t *packet, uint16_t size)
return;
memcpy(pad->data, packet, size);
pad->buttons = pad->data[1] | (pad->data[2] << 8);
update_buttons(pad);
}
static void wiiu_gca_set_rumble(void *data, enum retro_rumble_effect effect, uint16_t strength)
{
(void)data;
@ -240,8 +274,19 @@ static void wiiu_gca_set_rumble(void *data, enum retro_rumble_effect effect, uin
(void)strength;
}
static unsigned decode_axis(unsigned axis)
{
unsigned positive = AXIS_POS_GET(axis);
unsigned negative = AXIS_NEG_GET(axis);
RARCH_LOG("[gca]: positive: %ud negative: %ud\n", positive, negative);
return positive >= 4 ? negative : positive;
}
static int16_t wiiu_gca_get_axis(void *data, unsigned axis)
{
axis = decode_axis(axis);
RARCH_LOG("[gca]: decoded axis: %d\n", axis);
int16_t val;
gca_pad_t *pad = (gca_pad_t *)data;
@ -265,7 +310,7 @@ static int16_t wiiu_gca_get_axis(void *data, unsigned axis)
if(val > 0x1000 || val < -0x1000)
return 0;
// RARCH_LOG("[gca]: reading axis %d: %04x\n", axis, val);
RARCH_LOG("[gca]: reading axis %d: %04x\n", axis, val);
return val;
}
@ -288,10 +333,10 @@ static bool wiiu_gca_button(void *data, uint16_t joykey)
{
gca_pad_t *pad = (gca_pad_t *)data;
if(!pad)
if(!pad || joykey > 31)
return false;
return (pad->buttons & joykey);
return pad->buttons & (1 << joykey);
}
pad_connection_interface_t wiiu_gca_pad_connection = {

View file

@ -229,18 +229,18 @@ DECL_AXIS(r_y_minus, +3)
#ifdef WIIU
#define WIIUINPUT_GAMECUBE_DEFAULT_BINDS \
DECL_BTN_EX(a, 0x0001, "A") \
DECL_BTN_EX(b, 0x0002, "B") \
DECL_BTN_EX(x, 0x0004, "X") \
DECL_BTN_EX(y, 0x0008, "Y") \
DECL_BTN_EX(select, 0x0200, "Z") \
DECL_BTN_EX(start, 0x0100, "Start/Pause") \
DECL_BTN_EX(l, 0x0800, "L Trigger") \
DECL_BTN_EX(r, 0x0400, "R Trigger") \
DECL_BTN_EX(left, 0x0010, "D-Pad Left") \
DECL_BTN_EX(right, 0x0020, "D-Pad Right") \
DECL_BTN_EX(down, 0x0040, "D-Pad Down") \
DECL_BTN_EX(up, 0x0080, "D-Pad Up") \
DECL_BTN_EX(a, 8, "A") \
DECL_BTN_EX(b, 0, "B") \
DECL_BTN_EX(x, 9, "X") \
DECL_BTN_EX(y, 1, "Y") \
DECL_BTN_EX(left, 6, "D-Pad Left") \
DECL_BTN_EX(right, 7, "D-Pad Right") \
DECL_BTN_EX(down, 5, "D-Pad Down") \
DECL_BTN_EX(up, 4, "D-Pad Up") \
DECL_BTN_EX(start, 3, "Start/Pause") \
DECL_BTN_EX(select, 2, "Z") \
DECL_BTN_EX(r, 10, "R Trigger") \
DECL_BTN_EX(l, 11, "L Trigger") \
DECL_AXIS_EX(l_x_plus, +1, "Analog right") \
DECL_AXIS_EX(l_x_minus, -1, "Analog left") \
DECL_AXIS_EX(l_y_plus, +0, "Analog up") \

View file

@ -80,8 +80,8 @@ static void hidpad_get_buttons(unsigned pad, input_bits_t *state)
static int16_t hidpad_axis(unsigned pad, uint32_t axis)
{
if (!hidpad_query_pad(pad));
return 0;
if (!hidpad_query_pad(pad))
return 0;
return HID_AXIS(pad, axis);
}