Start preparing for being able to grab multiple buttons at the same time

This commit is contained in:
twinaphex 2020-07-18 19:51:14 +02:00
parent 8b078662cd
commit 08ad00f5d3
37 changed files with 743 additions and 392 deletions

View File

@ -53,48 +53,6 @@
#define DEFAULT_ASPECT_RATIO -1.0f #define DEFAULT_ASPECT_RATIO -1.0f
#endif #endif
#if defined(ANDROID)
#define DEFAULT_MAX_PADS 8
#define ANDROID_KEYBOARD_PORT DEFAULT_MAX_PADS
#elif defined(_3DS)
#define DEFAULT_MAX_PADS 1
#elif defined(SWITCH) || defined(HAVE_LIBNX)
#define DEFAULT_MAX_PADS 8
#elif defined(WIIU)
#ifdef WIIU_HID
#define DEFAULT_MAX_PADS 16
#else
#define DEFAULT_MAX_PADS 5
#endif
#elif defined(DJGPP)
#define DEFAULT_MAX_PADS 1
#define DOS_KEYBOARD_PORT DEFAULT_MAX_PADS
#elif defined(XENON)
#define DEFAULT_MAX_PADS 4
#elif defined(VITA) || defined(SN_TARGET_PSP2)
#define DEFAULT_MAX_PADS 4
#elif defined(PSP)
#define DEFAULT_MAX_PADS 1
#elif defined(PS2)
#define DEFAULT_MAX_PADS 2
#elif defined(GEKKO) || defined(HW_RVL)
#define DEFAULT_MAX_PADS 4
#elif defined(__linux__) || (defined(BSD) && !defined(__MACH__))
#define DEFAULT_MAX_PADS 8
#elif defined(__QNX__)
#define DEFAULT_MAX_PADS 8
#elif defined(__CELLOS_LV2__)
#define DEFAULT_MAX_PADS 7
#elif defined(_XBOX)
#define DEFAULT_MAX_PADS 4
#elif defined(HAVE_XINPUT) && !defined(HAVE_DINPUT)
#define DEFAULT_MAX_PADS 4
#elif defined(DINGUX)
#define DEFAULT_MAX_PADS 2
#else
#define DEFAULT_MAX_PADS 16
#endif
#if defined(GEKKO) #if defined(GEKKO)
#define DEFAULT_MOUSE_SCALE 1 #define DEFAULT_MOUSE_SCALE 1
#endif #endif

View File

@ -333,13 +333,22 @@ static const char *ds3_get_name(void *data)
return "Sony DualShock 3"; return "Sony DualShock 3";
} }
static bool ds3_button(void *data, uint16_t joykey) static int16_t ds3_button(void *data, uint16_t joykey)
{ {
ds3_instance_t *pad = (ds3_instance_t *)data; int16_t ret = 0;
if(!pad || joykey > 31) uint16_t i = joykey;
return false; uint16_t end = joykey + 1;
ds3_instance_t *pad = (ds3_instance_t *)data;
return pad->buttons & (1 << joykey); if(!pad)
return false;
for (; i < end; i++)
{
if (i < 31)
if (pad->buttons & (1 << i))
ret |= (1 << i);
}
return ret;
} }
pad_connection_interface_t ds3_pad_connection = { pad_connection_interface_t ds3_pad_connection = {

View File

@ -137,9 +137,9 @@ static const char *ds4_get_name(void *data)
return "Sony DualShock 4"; return "Sony DualShock 4";
} }
static bool ds4_button(void *data, uint16_t joykey) static int16_t ds4_button(void *data, uint16_t joykey)
{ {
return false; return 0;
} }
pad_connection_interface_t ds4_pad_connection = { pad_connection_interface_t ds4_pad_connection = {

View File

@ -200,9 +200,9 @@ static const char *hid_null_get_name(void *data)
/** /**
* Read the state of a single button. * Read the state of a single button.
*/ */
static bool hid_null_button(void *data, uint16_t joykey) static int16_t hid_null_button(void *data, uint16_t joykey)
{ {
return false; return 0;
} }
/** /**

View File

@ -341,14 +341,22 @@ static const char *wiiu_gca_get_name(void *data)
* 0x0008 - Y 0x0080 - up 0x0800 - L * 0x0008 - Y 0x0080 - up 0x0800 - L
*/ */
static bool wiiu_gca_button(void *data, uint16_t joykey) static int16_t wiiu_gca_button(void *data, uint16_t joykey)
{ {
gca_pad_t *pad = (gca_pad_t *)data; int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
gca_pad_t *pad = (gca_pad_t *)data;
if(!pad || joykey > 31) if (!pad)
return false; return 0;
for (; i < end; i++)
return pad->buttons & (1 << joykey); {
if (i < 31)
if (pad->buttons & (1 << i))
ret |= (1 << i);
}
return ret;
} }
pad_connection_interface_t wiiu_gca_pad_connection = { pad_connection_interface_t wiiu_gca_pad_connection = {

View File

@ -1366,16 +1366,23 @@ static void btstack_hid_joypad_get_buttons(void *data, unsigned port,
static int16_t btstack_hid_joypad_button(void *data, static int16_t btstack_hid_joypad_button(void *data,
unsigned port, uint16_t joykey) unsigned port, uint16_t joykey)
{ {
input_bits_t buttons; input_bits_t buttons;
btstack_hid_joypad_get_buttons(data, port, &buttons); int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
btstack_hid_joypad_get_buttons(data, port, &buttons);
/* Check hat. */ for (; i < end; i++)
if (GET_HAT_DIR(joykey)) {
return 0; /* Check hat. */
else if ((port < MAX_USERS) && (joykey < 32)) if (GET_HAT_DIR(i))
return (BIT256_GET(buttons, joykey) != 0); continue;
else if ((port < MAX_USERS) && (i < 32))
if (BIT256_GET(buttons, i) != 0)
ret |= (1 << i);
}
return 0; return ret;
} }
static bool btstack_hid_joypad_rumble(void *data, unsigned pad, static bool btstack_hid_joypad_rumble(void *data, unsigned pad,

View File

@ -149,39 +149,58 @@ static void iohidmanager_hid_joypad_get_buttons(void *data,
static int16_t iohidmanager_hid_joypad_button(void *data, static int16_t iohidmanager_hid_joypad_button(void *data,
unsigned port, uint16_t joykey) unsigned port, uint16_t joykey)
{ {
input_bits_t buttons; input_bits_t buttons;
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data; int16_t ret = 0;
unsigned hat_dir = GET_HAT_DIR(joykey); uint16_t i = joykey;
uint16_t end = joykey + 1;
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data;
iohidmanager_hid_joypad_get_buttons(data, port, &buttons); if (port >= DEFAULT_MAX_PADS)
return 0;
/* Check hat. */ iohidmanager_hid_joypad_get_buttons(data, port, &buttons);
if (hat_dir)
for (; i < end; i++)
{ {
unsigned h = GET_HAT(joykey); unsigned hat_dir = GET_HAT_DIR(i);
if (h >= 1)
return 0;
switch(hat_dir) /* Check hat. */
if (hat_dir)
{ {
case HAT_LEFT_MASK: unsigned h = GET_HAT(i);
return hid->hats[port][0] < 0; if (h >= 1)
case HAT_RIGHT_MASK: continue;
return hid->hats[port][0] > 0;
case HAT_UP_MASK:
return hid->hats[port][1] < 0;
case HAT_DOWN_MASK:
return hid->hats[port][1] > 0;
default:
break;
}
/* hat requested and no hat button down */
}
else if ((port < MAX_USERS) && (joykey < 32))
return (BIT256_GET(buttons, joykey) != 0)
|| ((hid->buttons[port] & (1 << joykey)) != 0);
return 0; switch (hat_dir)
{
case HAT_LEFT_MASK:
if (hid->hats[port][0] < 0)
ret |= (1 << i);
break;
case HAT_RIGHT_MASK:
if (hid->hats[port][0] > 0)
ret |= (1 << i);
break;
case HAT_UP_MASK:
if (hid->hats[port][1] < 0)
ret |= (1 << i);
break;
case HAT_DOWN_MASK:
if (hid->hats[port][1] > 0)
ret |= (1 << i);
break;
default:
break;
}
/* hat requested and no hat button down */
}
else if (i < 32)
if ((BIT256_GET(buttons, i) != 0)
|| ((hid->buttons[port] & (1 << i)) != 0))
ret |= (1 << i);
}
return ret;
} }
static bool iohidmanager_hid_joypad_rumble(void *data, unsigned pad, static bool iohidmanager_hid_joypad_rumble(void *data, unsigned pad,

View File

@ -458,14 +458,24 @@ static int16_t libusb_hid_joypad_button(void *data,
unsigned port, uint16_t joykey) unsigned port, uint16_t joykey)
{ {
input_bits_t buttons; input_bits_t buttons;
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port >= DEFAULT_MAX_PADS)
return 0;
libusb_hid_joypad_get_buttons(data, port, &buttons); libusb_hid_joypad_get_buttons(data, port, &buttons);
/* Check hat. */ for (; i < end; i++)
if (GET_HAT_DIR(joykey)) {
return 0; /* Check hat. */
else if ((port < MAX_USERS) && (joykey < 32)) if (GET_HAT_DIR(i))
return (BIT256_GET(buttons, joykey) != 0); continue;
return 0; else if (i < 32)
if (BIT256_GET(buttons, i) != 0)
ret |= (1 << i);
}
return ret;
} }
static bool libusb_hid_joypad_rumble(void *data, unsigned pad, static bool libusb_hid_joypad_rumble(void *data, unsigned pad,

View File

@ -61,13 +61,22 @@ static void wiiu_hid_joypad_get_buttons(void *data, unsigned slot, input_bits_t
pad->iface->get_buttons(pad->data, state); pad->iface->get_buttons(pad->data, state);
} }
static int16_t wiiu_hid_joypad_button(void *data, unsigned slot, uint16_t joykey) static int16_t wiiu_hid_joypad_button(void *data,
unsigned slot, uint16_t joykey)
{ {
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot); int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
joypad_connection_t *pad = get_pad((wiiu_hid_t *)data, slot);
if (!pad) if (!pad)
return 0; return 0;
return pad->iface->button(pad->data, joykey); for (; i < end; i++)
{
if (pad->iface->button(pad->data, i))
ret |= (1 << i);
}
return ret;
} }
static bool wiiu_hid_joypad_rumble(void *data, unsigned slot, static bool wiiu_hid_joypad_rumble(void *data, unsigned slot,

View File

@ -542,16 +542,26 @@ static void wiiusb_hid_joypad_get_buttons(void *data,
static int16_t wiiusb_hid_joypad_button(void *data, static int16_t wiiusb_hid_joypad_button(void *data,
unsigned port, uint16_t joykey) unsigned port, uint16_t joykey)
{ {
input_bits_t buttons; input_bits_t buttons;
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
wiiusb_hid_joypad_get_buttons(data, port, &buttons); if (port >= DEFAULT_MAX_PADS)
return 0;
wiiusb_hid_joypad_get_buttons(data, port, &buttons);
/* Check hat. */ for (; i < end; i++)
if (GET_HAT_DIR(joykey)) {
return 0; /* Check hat. */
else if ((port < MAX_USERS) && (joykey < 32)) if (GET_HAT_DIR(i))
return (BIT256_GET(buttons, joykey) != 0); continue;
return 0; else if (i < 32)
if (BIT256_GET(buttons, i) != 0)
ret |= (1 << i);
}
return ret;
} }
static bool wiiusb_hid_joypad_rumble(void *data, unsigned pad, static bool wiiusb_hid_joypad_rumble(void *data, unsigned pad,

View File

@ -32,38 +32,53 @@ static bool android_joypad_init(void *data)
static int16_t android_joypad_button(unsigned port, uint16_t joykey) static int16_t android_joypad_button(unsigned port, uint16_t joykey)
{ {
int16_t ret = 0;
uint8_t *buf = android_keyboard_state_get(port); uint8_t *buf = android_keyboard_state_get(port);
struct android_app *android_app = (struct android_app*)g_android; struct android_app *android_app = (struct android_app*)g_android;
unsigned hat_dir = GET_HAT_DIR(joykey); unsigned hat_dir = GET_HAT_DIR(joykey);
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port >= DEFAULT_MAX_PADS) if (port >= DEFAULT_MAX_PADS)
return 0; return 0;
if (hat_dir) for (; i < end; i++)
{ {
unsigned h = GET_HAT(joykey); if (hat_dir)
if (h > 0)
return 0;
switch (hat_dir)
{ {
case HAT_LEFT_MASK: unsigned h = GET_HAT(i);
return android_app->hat_state[port][0] == -1; if (h > 0)
case HAT_RIGHT_MASK: continue;
return android_app->hat_state[port][0] == 1;
case HAT_UP_MASK:
return android_app->hat_state[port][1] == -1;
case HAT_DOWN_MASK:
return android_app->hat_state[port][1] == 1;
default:
break;
}
/* hat requested and no hat button down */
}
else if (joykey < LAST_KEYCODE)
return BIT_GET(buf, joykey);
return 0; switch (hat_dir)
{
case HAT_LEFT_MASK:
if (android_app->hat_state[port][0] == -1)
ret |= (1 << i);
break;
case HAT_RIGHT_MASK:
if (android_app->hat_state[port][0] == 1)
ret |= (1 << i);
break;
case HAT_UP_MASK:
if (android_app->hat_state[port][1] == -1)
ret |= (1 << i);
break;
case HAT_DOWN_MASK:
if (android_app->hat_state[port][1] == 1)
ret |= (1 << i);
break;
default:
break;
}
/* hat requested and no hat button down */
}
else if (i < LAST_KEYCODE)
if (BIT_GET(buf, i))
ret |= (1 << i):
}
return ret;
} }
static int16_t android_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t android_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -55,11 +55,20 @@ static bool ctr_joypad_init(void *data)
return true; return true;
} }
static int16_t ctr_joypad_button(unsigned port_num, uint16_t key) static int16_t ctr_joypad_button(unsigned port_num, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port_num >= DEFAULT_MAX_PADS) if (port_num >= DEFAULT_MAX_PADS)
return 0; return 0;
return (pad_state & (1 << key));
for (; i < end; i++)
{
if (pad_state & (1 << i))
ret |= (1 << i);
}
return ret;
} }
static void ctr_joypad_get_buttons(unsigned port_num, input_bits_t *state) static void ctr_joypad_get_buttons(unsigned port_num, input_bits_t *state)

View File

@ -445,66 +445,88 @@ static bool dinput_joypad_init(void *data)
static int16_t dinput_joypad_button(unsigned port_num, uint16_t joykey) static int16_t dinput_joypad_button(unsigned port_num, uint16_t joykey)
{ {
const struct dinput_joypad_data *pad = &g_pads[port_num]; const struct dinput_joypad_data *pad = &g_pads[port_num];
int16_t ret = 0;
unsigned hat_dir = 0; unsigned hat_dir = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (!pad || !pad->joypad) if (!pad || !pad->joypad)
return 0; return 0;
hat_dir = GET_HAT_DIR(joykey);
if (hat_dir) for (; i < end; i++)
{ {
unsigned h = GET_HAT(joykey); hat_dir = GET_HAT_DIR(i);
if (h < NUM_HATS)
if (hat_dir)
{ {
unsigned pov = pad->joy_state.rgdwPOV[h]; unsigned h = GET_HAT(i);
switch (hat_dir) if (h < NUM_HATS)
{ {
case HAT_UP_MASK: unsigned pov = pad->joy_state.rgdwPOV[h];
{ switch (hat_dir)
static const unsigned check1 = (JOY_POVRIGHT/2); {
static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2); case HAT_UP_MASK:
return {
(pov == JOY_POVFORWARD) || static const unsigned check1 = (JOY_POVRIGHT/2);
(pov == check1) || static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2);
(pov == check2); if (
} (pov == JOY_POVFORWARD) ||
case HAT_RIGHT_MASK: (pov == check1) ||
{ (pov == check2)
static const unsigned check1 = (JOY_POVRIGHT/2); )
static const unsigned check2 = (JOY_POVRIGHT+JOY_POVRIGHT/2); ret |= (1 << i);
return }
(pov == JOY_POVRIGHT) || break;
(pov == check1) || case HAT_RIGHT_MASK:
(pov == check2); {
} static const unsigned check1 = (JOY_POVRIGHT/2);
case HAT_DOWN_MASK: static const unsigned check2 = (JOY_POVRIGHT+JOY_POVRIGHT/2);
{ if (
static const unsigned check1 = (JOY_POVRIGHT+JOY_POVRIGHT/2); (pov == JOY_POVRIGHT) ||
static const unsigned check2 = (JOY_POVBACKWARD+JOY_POVRIGHT/2); (pov == check1) ||
return (pov == check2)
(pov == JOY_POVBACKWARD) || )
(pov == check1) || ret |= (1 << i);
(pov == check2); }
} break;
case HAT_LEFT_MASK: case HAT_DOWN_MASK:
{ {
static const unsigned check1 = (JOY_POVBACKWARD+JOY_POVRIGHT/2); static const unsigned check1 = (JOY_POVRIGHT+JOY_POVRIGHT/2);
static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2); static const unsigned check2 = (JOY_POVBACKWARD+JOY_POVRIGHT/2);
return if
(pov == JOY_POVLEFT) || (
(pov == check1) || (pov == JOY_POVBACKWARD) ||
(pov == check2); (pov == check1) ||
} (pov == check2)
default: )
break; ret |= (1 << i);
}
break;
case HAT_LEFT_MASK:
{
static const unsigned check1 = (JOY_POVBACKWARD+JOY_POVRIGHT/2);
static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2);
if
(
(pov == JOY_POVLEFT) ||
(pov == check1) ||
(pov == check2)
)
ret |= (1 << i);
}
break;
default:
break;
}
} }
/* hat requested and no hat button down */
} }
/* hat requested and no hat button down */ else if (i < ARRAY_SIZE_RGB_BUTTONS)
if (pad->joy_state.rgbButtons[i])
ret |= (1 << i);
} }
else if (joykey < ARRAY_SIZE_RGB_BUTTONS)
return pad->joy_state.rgbButtons[joykey]; return ret;
return 0;
} }
static int16_t dinput_joypad_axis(unsigned port_num, uint32_t joyaxis) static int16_t dinput_joypad_axis(unsigned port_num, uint32_t joyaxis)

View File

@ -164,38 +164,64 @@ static bool dos_joypad_init(void *data)
return true; return true;
} }
static int16_t dos_joypad_button(unsigned port_num, uint16_t key) static int16_t dos_joypad_button(unsigned port_num, uint16_t joykey)
{ {
uint16_t *buf = dos_keyboard_state_get(port_num); int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
uint16_t *buf = dos_keyboard_state_get(port_num);
if (port_num >= DEFAULT_MAX_PADS) if (port_num >= DEFAULT_MAX_PADS)
return 0; return 0;
switch (key) for (; i < end; i++)
{ {
case RETRO_DEVICE_ID_JOYPAD_A: switch (key)
return buf[DOSKEY_x]; {
case RETRO_DEVICE_ID_JOYPAD_B: case RETRO_DEVICE_ID_JOYPAD_A:
return buf[DOSKEY_z]; if (buf[DOSKEY_x])
case RETRO_DEVICE_ID_JOYPAD_X: ret |= (1 << i);
return buf[DOSKEY_s]; break;
case RETRO_DEVICE_ID_JOYPAD_Y: case RETRO_DEVICE_ID_JOYPAD_B:
return buf[DOSKEY_a]; if (buf[DOSKEY_z])
case RETRO_DEVICE_ID_JOYPAD_SELECT: ret |= (1 << i);
return buf[DOSKEY_RSHIFT]; break;
case RETRO_DEVICE_ID_JOYPAD_START: case RETRO_DEVICE_ID_JOYPAD_X:
return buf[DOSKEY_RETURN]; if (buf[DOSKEY_s])
case RETRO_DEVICE_ID_JOYPAD_UP: ret |= (1 << i):
return buf[DOSKEY_UP]; break;
case RETRO_DEVICE_ID_JOYPAD_DOWN: case RETRO_DEVICE_ID_JOYPAD_Y:
return buf[DOSKEY_DOWN]; if (buf[DOSKEY_a])
case RETRO_DEVICE_ID_JOYPAD_LEFT: ret |= (1 << i);
return buf[DOSKEY_LEFT]; break;
case RETRO_DEVICE_ID_JOYPAD_RIGHT: case RETRO_DEVICE_ID_JOYPAD_SELECT:
return buf[DOSKEY_RIGHT]; if (buf[DOSKEY_RSHIFT])
ret |= (1 << i);
break;
case RETRO_DEVICE_ID_JOYPAD_START:
if (buf[DOSKEY_RETURN])
ret |= (1 << i);
break;
case RETRO_DEVICE_ID_JOYPAD_UP:
if (buf[DOSKEY_UP])
ret |= (1 << i):
break;
case RETRO_DEVICE_ID_JOYPAD_DOWN:
if (buf[DOSKEY_DOWN])
ret |= (1 << i);
break;
case RETRO_DEVICE_ID_JOYPAD_LEFT:
if (buf[DOSKEY_LEFT])
ret |= (1 << i);
break;
case RETRO_DEVICE_ID_JOYPAD_RIGHT:
if (buf[DOSKEY_RIGHT])
ret |= (1 << i);
break;
}
} }
return 0; return ret;
} }
static void dos_joypad_poll(void) static void dos_joypad_poll(void)

View File

@ -243,11 +243,19 @@ static void check_port0_active(uint8_t pad_count)
} }
} }
static int16_t gx_joypad_button(unsigned port, uint16_t key) static int16_t gx_joypad_button(unsigned port, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port >= DEFAULT_MAX_PADS) if (port >= DEFAULT_MAX_PADS)
return 0; return 0;
return (pad_state[port] & (UINT64_C(1) << key)); for (; i < end; i++)
{
if (pad_state[port] & (UINT64_C(1) << i))
ret |= (1 << i);
}
return ret;
} }
static void gx_joypad_get_buttons(unsigned port, input_bits_t *state) static void gx_joypad_get_buttons(unsigned port, input_bits_t *state)

View File

@ -303,12 +303,20 @@ static void linuxraw_joypad_destroy(void)
static int16_t linuxraw_joypad_button(unsigned port, uint16_t joykey) static int16_t linuxraw_joypad_button(unsigned port, uint16_t joykey)
{ {
const struct linuxraw_joypad *pad = (const struct linuxraw_joypad*) int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
const struct linuxraw_joypad *pad = (const struct linuxraw_joypad*)
&linuxraw_pads[port]; &linuxraw_pads[port];
if (port >= DEFAULT_MAX_PADS)
if (joykey < NUM_BUTTONS) return 0;
return BIT32_GET(pad->buttons, joykey); for (; i < end; i++)
return 0; {
if (i < NUM_BUTTONS)
if (BIT32_GET(pad->buttons, i))
ret |= (1 << i);
}
return ret;
} }
static void linuxraw_joypad_get_buttons(unsigned port, input_bits_t *state) static void linuxraw_joypad_get_buttons(unsigned port, input_bits_t *state)

View File

@ -335,15 +335,24 @@ static void apple_gamecontroller_joypad_destroy(void)
{ {
} }
static int16_t apple_gamecontroller_joypad_button(unsigned port, uint16_t joykey) static int16_t apple_gamecontroller_joypad_button(
unsigned port, uint16_t joykey)
{ {
/* Check hat. */ int16_t ret = 0;
if (GET_HAT_DIR(joykey)) uint16_t i = joykey;
return 0; uint16_t end = joykey + 1;
/* Check the button. */ if (port >= DEFAULT_MAX_PADS)
if ((port < MAX_USERS) && (joykey < 32)) return 0;
return ((mfi_buttons[port] & (1 << joykey)) != 0); for (; i < end; i++)
return 0; {
/* Check hat. */
if (GET_HAT_DIR(i))
continue;
else if (i < 32)
if ((mfi_buttons[port] & (1 << i)) != 0)
ret |= (1 << i);
}
return ret;
} }
static void apple_gamecontroller_joypad_get_buttons(unsigned port, static void apple_gamecontroller_joypad_get_buttons(unsigned port,

View File

@ -331,10 +331,20 @@ static void parport_joypad_destroy(void)
static int16_t parport_joypad_button(unsigned port, uint16_t joykey) static int16_t parport_joypad_button(unsigned port, uint16_t joykey)
{ {
const struct parport_joypad *pad = (const struct parport_joypad*)&parport_pads[port]; int16_t ret = 0;
if (joykey < PARPORT_NUM_BUTTONS) uint16_t i = joykey;
return BIT32_GET(pad->buttons, joykey); uint16_t end = joykey + 1;
return 0; const struct parport_joypad *pad = (const struct parport_joypad*)
&parport_pads[port];
if (port >= DEFAULT_MAX_PADS)
return 0;
for (; i < end; i++)
{
if (i < PARPORT_NUM_BUTTONS)
if (BIT32_GET(pad->buttons, i))
ret |= (1 << i);
}
return ret;
} }
static void parport_joypad_get_buttons(unsigned port, input_bits_t *state) static void parport_joypad_get_buttons(unsigned port, input_bits_t *state)

View File

@ -86,9 +86,17 @@ static bool ps2_joypad_init(void *data)
static int16_t ps2_joypad_button(unsigned port_num, uint16_t joykey) static int16_t ps2_joypad_button(unsigned port_num, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port_num >= DEFAULT_MAX_PADS) if (port_num >= DEFAULT_MAX_PADS)
return 0; return 0;
return (pad_state[port_num] & (UINT64_C(1) << joykey)); for (; i < end; i++)
{
if (pad_state[port_num] & (UINT64_C(1) << i))
ret |= (1 << i);
}
return ret;
} }
static void ps2_joypad_get_buttons(unsigned port_num, input_bits_t *state) static void ps2_joypad_get_buttons(unsigned port_num, input_bits_t *state)

View File

@ -63,9 +63,17 @@ static bool ps3_joypad_init(void *data)
static int16_t ps3_joypad_button(unsigned port_num, uint16_t joykey) static int16_t ps3_joypad_button(unsigned port_num, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port_num >= DEFAULT_MAX_PADS) if (port_num >= DEFAULT_MAX_PADS)
return 0; return 0;
return pad_state[port_num] & (UINT64_C(1) << joykey); for (; i < end; i++)
{
if (pad_state[port_num] & (UINT64_C(1) << i))
ret |= (1 << i);
}
return ret;
} }
static void ps3_joypad_get_buttons(unsigned port_num, input_bits_t *state) static void ps3_joypad_get_buttons(unsigned port_num, input_bits_t *state)

View File

@ -132,9 +132,17 @@ static bool ps4_joypad_init(void *data)
static int16_t ps4_joypad_button(unsigned port_num, uint16_t joykey) static int16_t ps4_joypad_button(unsigned port_num, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port_num >= PS4_MAX_ORBISPADS) if (port_num >= PS4_MAX_ORBISPADS)
return 0; return 0;
return (pad_state[port_num] & (UINT64_C(1) << joykey)); for (; i < end; i++)
{
if (pad_state[port_num] & (UINT64_C(1) << i))
ret |= (1 << i);
}
return ret;
} }
static void ps4_joypad_get_buttons(unsigned port_num, input_bits_t *state) static void ps4_joypad_get_buttons(unsigned port_num, input_bits_t *state)

View File

@ -119,11 +119,19 @@ static bool psp_joypad_init(void *data)
return true; return true;
} }
static int16_t psp_joypad_button(unsigned port_num, uint16_t key) static int16_t psp_joypad_button(unsigned port_num, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port_num >= DEFAULT_MAX_PADS) if (port_num >= DEFAULT_MAX_PADS)
return 0; return 0;
return (pad_state[port_num] & (UINT64_C(1) << key)); for (; i < end; i++)
{
if (pad_state[port_num] & (UINT64_C(1) << i))
ret |= (1 << i);
}
return ret;
} }
static void psp_joypad_get_buttons(unsigned port_num, input_bits_t *state) static void psp_joypad_get_buttons(unsigned port_num, input_bits_t *state)

View File

@ -46,17 +46,24 @@ static bool qnx_joypad_init(void *data)
static int16_t qnx_joypad_button(unsigned port_num, uint16_t joykey) static int16_t qnx_joypad_button(unsigned port_num, uint16_t joykey)
{ {
qnx_input_device_t* controller = NULL; qnx_input_device_t* controller = NULL;
qnx_input_t *qnx = (qnx_input_t*)input_driver_get_data(); qnx_input_t *qnx = (qnx_input_t*)input_driver_get_data();
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (!qnx || port_num >= DEFAULT_MAX_PADS) if (!qnx || port_num >= DEFAULT_MAX_PADS)
return 0; return 0;
controller = (qnx_input_device_t*)&qnx->devices[port_num]; controller = (qnx_input_device_t*)&qnx->devices[port_num];
if(port_num < MAX_USERS && joykey <= 19) for (; i < end; i++)
return (controller->buttons & (1 << joykey)) != 0; {
return 0; if (i <= 19)
if ((controller->buttons & (1 << i)) != 0)
ret |= (1 << i);
}
return ret;
} }
static int16_t qnx_joypad_axis(unsigned port_num, uint32_t joyaxis) static int16_t qnx_joypad_axis(unsigned port_num, uint32_t joyaxis)

View File

@ -102,14 +102,23 @@ static const char *rwebpad_joypad_name(unsigned pad)
static int16_t rwebpad_joypad_button(unsigned port_num, uint16_t joykey) static int16_t rwebpad_joypad_button(unsigned port_num, uint16_t joykey)
{ {
EmscriptenGamepadEvent gamepad_state; EmscriptenGamepadEvent gamepad_state;
EMSCRIPTEN_RESULT r = emscripten_get_gamepad_status( int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
EMSCRIPTEN_RESULT r = emscripten_get_gamepad_status(
port_num, &gamepad_state); port_num, &gamepad_state);
if (r == EMSCRIPTEN_RESULT_SUCCESS) if (port >= DEFAULT_MAX_PADS)
if (joykey < gamepad_state.numButtons) return 0;
return gamepad_state.digitalButton[joykey]; if (r != EMSCRIPTEN_RESULT_SUCCESS)
return 0;
return 0; for (; i < end; i++)
{
if (i < gamepad_state.numButtons)
if (gamepad_state.digitalButton[i])
ret |= (1 << i);
}
return ret;
} }
static void rwebpad_joypad_get_buttons(unsigned port_num, input_bits_t *state) static void rwebpad_joypad_get_buttons(unsigned port_num, input_bits_t *state)

View File

@ -297,42 +297,58 @@ error:
static int16_t sdl_joypad_button(unsigned port, uint16_t joykey) static int16_t sdl_joypad_button(unsigned port, uint16_t joykey)
{ {
unsigned hat_dir = 0; int16_t ret = 0;
sdl_joypad_t *pad = (sdl_joypad_t*)&sdl_pads[port]; uint16_t i = joykey;
uint16_t end = joykey + 1;
sdl_joypad_t *pad = (sdl_joypad_t*)&sdl_pads[port];
if (!pad || !pad->joypad) if (!pad || !pad->joypad)
return 0; return 0;
if (port >= DEFAULT_MAX_PADS)
return 0;
hat_dir = GET_HAT_DIR(joykey); for (; i < end; i++)
/* Check hat. */
if (hat_dir)
{ {
uint8_t dir; unsigned hat_dir = GET_HAT_DIR(i);
uint16_t hat = GET_HAT(joykey); /* Check hat. */
if (hat_dir)
if (hat >= pad->num_hats)
return false;
dir = sdl_pad_get_hat(pad, hat);
switch (hat_dir)
{ {
case HAT_UP_MASK: uint8_t dir;
return dir & SDL_HAT_UP; uint16_t hat = GET_HAT(i);
case HAT_DOWN_MASK:
return dir & SDL_HAT_DOWN;
case HAT_LEFT_MASK:
return dir & SDL_HAT_LEFT;
case HAT_RIGHT_MASK:
return dir & SDL_HAT_RIGHT;
default:
break;
}
/* hat requested and no hat button down */
}
else if (joykey < pad->num_buttons)
return sdl_pad_get_button(pad, joykey);
return 0; if (hat >= pad->num_hats)
continue;
dir = sdl_pad_get_hat(pad, hat);
switch (hat_dir)
{
case HAT_UP_MASK:
if (dir & SDL_HAT_UP)
ret |= (1 << i);
break;
case HAT_DOWN_MASK:
if (dir & SDL_HAT_DOWN)
ret |= (1 << i);
break;
case HAT_LEFT_MASK:
if (dir & SDL_HAT_LEFT)
ret |= (1 << i);
break;
case HAT_RIGHT_MASK:
if (dir & SDL_HAT_RIGHT)
ret |= (1 << i);
break;
default:
break;
}
/* hat requested and no hat button down */
}
else if (i < pad->num_buttons)
if (sdl_pad_get_button(pad, i))
ret |= (1 << i);
}
return ret;
} }
static int16_t sdl_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t sdl_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -83,11 +83,19 @@ static bool switch_joypad_init(void *data)
return true; return true;
} }
static int16_t switch_joypad_button(unsigned port_num, uint16_t key) static int16_t switch_joypad_button(unsigned port_num, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port_num >= DEFAULT_MAX_PADS) if (port_num >= DEFAULT_MAX_PADS)
return 0; return 0;
return (pad_state[port_num] & (1 << key)); for (; i < end; i++)
{
if (pad_state[port_num] & (1 << i))
ret |= (1 << i);
}
return ret;
} }
static void switch_joypad_get_buttons(unsigned port_num, input_bits_t *state) static void switch_joypad_get_buttons(unsigned port_num, input_bits_t *state)

View File

@ -592,33 +592,51 @@ error:
static int16_t udev_joypad_button(unsigned port, uint16_t joykey) static int16_t udev_joypad_button(unsigned port, uint16_t joykey)
{ {
const struct udev_joypad *pad = (const struct udev_joypad*)&udev_pads[port]; int16_t ret = 0;
unsigned hat_dir = GET_HAT_DIR(joykey); uint16_t i = joykey;
uint16_t end = joykey + 1;
if (hat_dir) const struct udev_joypad *pad = (const struct udev_joypad*)
&udev_pads[port];
if (port >= DEFAULT_MAX_PADS)
return 0;
for (; i < end; i++)
{ {
unsigned h = GET_HAT(joykey); unsigned hat_dir = GET_HAT_DIR(i);
if (h < NUM_HATS)
if (hat_dir)
{ {
switch (hat_dir) unsigned h = GET_HAT(i);
if (h < NUM_HATS)
{ {
case HAT_LEFT_MASK: switch (hat_dir)
return pad->hats[h][0] < 0; {
case HAT_RIGHT_MASK: case HAT_LEFT_MASK:
return pad->hats[h][0] > 0; if (pad->hats[h][0] < 0)
case HAT_UP_MASK: ret |= (1 << i);
return pad->hats[h][1] < 0; break;
case HAT_DOWN_MASK: case HAT_RIGHT_MASK:
return pad->hats[h][1] > 0; if (pad->hats[h][0] > 0)
default: ret |= (1 << i):
break; break;
case HAT_UP_MASK:
if (pad->hats[h][1] < 0)
ret |= (1 << i);
break;
case HAT_DOWN_MASK:
if (pad->hats[h][1] > 0)
ret |= (1 << i);
break;
default:
break;
}
} }
/* hat requested and no hat button down */
} }
/* hat requested and no hat button down */ else if (i < UDEV_NUM_BUTTONS)
if (BIT64_GET(pad->buttons, i))
ret |= (1 << i);
} }
else if (joykey < UDEV_NUM_BUTTONS) return ret;
return BIT64_GET(pad->buttons, joykey);
return 0;
} }
static void udev_joypad_get_buttons(unsigned port, input_bits_t *state) static void udev_joypad_get_buttons(unsigned port, input_bits_t *state)

View File

@ -58,11 +58,19 @@ static void hidpad_destroy(void)
hid_deinit(&hid_instance); hid_deinit(&hid_instance);
} }
static int16_t hidpad_button(unsigned pad, uint16_t button) static int16_t hidpad_button(unsigned pad, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (!hidpad_query_pad(pad)) if (!hidpad_query_pad(pad))
return 0; return 0;
return HID_BUTTON(pad, button); for (; i < end; i++)
{
if (HID_BUTTON(pad, i))
ret |= (1 << i);
}
return ret;
} }
static void hidpad_get_buttons(unsigned pad, input_bits_t *state) static void hidpad_get_buttons(unsigned pad, input_bits_t *state)

View File

@ -22,14 +22,8 @@
#include "../../include/wiiu/input.h" #include "../../include/wiiu/input.h"
static bool kpad_init(void *data); /* Forward declarations */
static bool kpad_query_pad(unsigned pad);
static void kpad_destroy(void);
static bool kpad_button(unsigned pad, uint16_t button);
static void kpad_get_buttons(unsigned pad, input_bits_t *state);
static int16_t kpad_axis(unsigned pad, uint32_t axis);
static void kpad_poll(void); static void kpad_poll(void);
static const char *kpad_name(unsigned pad);
static void kpad_deregister(unsigned channel); static void kpad_deregister(unsigned channel);
typedef struct _wiimote_state wiimote_state; typedef struct _wiimote_state wiimote_state;
@ -98,18 +92,25 @@ static void kpad_destroy(void)
kpad_ready = false; kpad_ready = false;
} }
static int16_t kpad_button(unsigned pad, uint16_t button_bit) static int16_t kpad_button(unsigned pad, uint16_t joykey)
{ {
int channel; int channel;
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (!kpad_query_pad(pad)) if (!kpad_query_pad(pad))
return 0; return 0;
channel = to_wiimote_channel(pad); channel = to_wiimote_channel(pad);
if(channel < 0) if(channel < 0)
return 0; return 0;
for (; i < end; i++)
return wiimotes[channel].button_state {
& (UINT64_C(1) << button_bit); if (wiimotes[channel].button_state
& (UINT64_C(1) << i))
ret |= (1 << i);
}
return ret;
} }
static void kpad_get_buttons(unsigned pad, input_bits_t *state) static void kpad_get_buttons(unsigned pad, input_bits_t *state)

View File

@ -278,9 +278,12 @@ static void wpad_destroy(void)
} }
static int16_t wpad_button(unsigned pad, uint16_t button_bit) static int16_t wpad_button(unsigned pad, uint16_t joykey)
{ {
VPADChan channel; VPADChan channel;
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (!wpad_query_pad(pad)) if (!wpad_query_pad(pad))
return 0; return 0;
@ -289,7 +292,12 @@ static int16_t wpad_button(unsigned pad, uint16_t button_bit)
if (channel < 0) if (channel < 0)
return 0; return 0;
return gamepads[channel].button_state & (UINT64_C(1) << button_bit); for (; i < end; i++)
{
if (gamepads[channel].button_state & (UINT64_C(1) << i))
ret |= (1 << i);
}
return ret;
} }
static void wpad_get_buttons(unsigned pad, input_bits_t *state) static void wpad_get_buttons(unsigned pad, input_bits_t *state)

View File

@ -60,11 +60,21 @@ static void wiiu_joypad_destroy(void)
#endif #endif
} }
static int16_t wiiu_joypad_button(unsigned pad, uint16_t key) static int16_t wiiu_joypad_button(unsigned pad, uint16_t joykey)
{ {
int16_t ret = 0;
uint16_t i = joykey;
uint16_t end = joykey + 1;
if (!wiiu_joypad_query_pad(pad)) if (!wiiu_joypad_query_pad(pad))
return 0; return 0;
return pad_drivers[pad]->button(pad, key); if (port >= DEFAULT_MAX_PADS)
return 0;
for (; i < end; i++)
{
if (pad_drivers[pad]->button(pad, i))
ret |= (1 << i);
}
return ret;
} }
static void wiiu_joypad_get_buttons(unsigned pad, input_bits_t *state) static void wiiu_joypad_get_buttons(unsigned pad, input_bits_t *state)

View File

@ -92,69 +92,107 @@ static const uint16_t button_index_to_bitmap_code[] = {
static int16_t xdk_joypad_button(unsigned port_num, uint16_t joykey) static int16_t xdk_joypad_button(unsigned port_num, uint16_t joykey)
{ {
uint16_t btn_word = 0; int16_t ret = 0;
unsigned hat_dir = 0; uint16_t i = joykey;
uint16_t end = joykey + 1;
if (port_num >= DEFAULT_MAX_PADS) if (port_num >= DEFAULT_MAX_PADS)
return 0; return 0;
btn_word = g_xinput_states[port_num].xstate.Gamepad.wButtons; for (; i < end; i++)
hat_dir = GET_HAT_DIR(joykey); {
uint16_t btn_word = g_xinput_states[port_num].xstate.Gamepad.wButtons;
unsigned hat_dir = GET_HAT_DIR(i);
if (hat_dir) if (hat_dir)
{
switch (hat_dir)
{ {
case HAT_UP_MASK: switch (hat_dir)
return btn_word & XINPUT_GAMEPAD_DPAD_UP; {
case HAT_DOWN_MASK: case HAT_UP_MASK:
return btn_word & XINPUT_GAMEPAD_DPAD_DOWN; if (btn_word & XINPUT_GAMEPAD_DPAD_UP)
case HAT_LEFT_MASK: ret |= (1 << i);
return btn_word & XINPUT_GAMEPAD_DPAD_LEFT; break;
case HAT_RIGHT_MASK: case HAT_DOWN_MASK:
return btn_word & XINPUT_GAMEPAD_DPAD_RIGHT; if (btn_word & XINPUT_GAMEPAD_DPAD_DOWN)
ret |= (1 << i);
break;
case HAT_LEFT_MASK:
if (btn_word & XINPUT_GAMEPAD_DPAD_LEFT)
ret |= (1 << i);
break;
case HAT_RIGHT_MASK:
if (btn_word & XINPUT_GAMEPAD_DPAD_RIGHT)
ret |= (1 << i);
break;
default:
break;
}
/* hat requested and no hat button down */
} }
/* hat requested and no hat button down */ else
} {
else
{
#ifdef _XBOX1 #ifdef _XBOX1
switch (joykey) switch (i)
{ {
case RETRO_DEVICE_ID_JOYPAD_A: case RETRO_DEVICE_ID_JOYPAD_A:
return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_B] > XINPUT_GAMEPAD_MAX_CROSSTALK); if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_B] > XINPUT_GAMEPAD_MAX_CROSSTALK)
case RETRO_DEVICE_ID_JOYPAD_B: ret |= (1 << i);
return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_A] > XINPUT_GAMEPAD_MAX_CROSSTALK); break;
case RETRO_DEVICE_ID_JOYPAD_Y: case RETRO_DEVICE_ID_JOYPAD_B:
return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_X] > XINPUT_GAMEPAD_MAX_CROSSTALK); if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_A] > XINPUT_GAMEPAD_MAX_CROSSTALK)
case RETRO_DEVICE_ID_JOYPAD_X: ret |= (1 << i);
return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_Y] > XINPUT_GAMEPAD_MAX_CROSSTALK); break;
case RETRO_DEVICE_ID_JOYPAD_START: case RETRO_DEVICE_ID_JOYPAD_Y:
return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_START); if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_X] > XINPUT_GAMEPAD_MAX_CROSSTALK)
case RETRO_DEVICE_ID_JOYPAD_SELECT: ret |= (1 << i);
return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_BACK); break;
case RETRO_DEVICE_ID_JOYPAD_L3: case RETRO_DEVICE_ID_JOYPAD_X:
return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB); if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_Y] > XINPUT_GAMEPAD_MAX_CROSSTALK)
case RETRO_DEVICE_ID_JOYPAD_R3: ret |= (1 << i);
return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB); break;
case RETRO_DEVICE_ID_JOYPAD_L2: case RETRO_DEVICE_ID_JOYPAD_START:
return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_WHITE] > XINPUT_GAMEPAD_MAX_CROSSTALK); return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_START);
case RETRO_DEVICE_ID_JOYPAD_R2: break;
return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_BLACK] > XINPUT_GAMEPAD_MAX_CROSSTALK); case RETRO_DEVICE_ID_JOYPAD_SELECT:
case RETRO_DEVICE_ID_JOYPAD_L: if (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_BACK)
return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER] > XINPUT_GAMEPAD_MAX_CROSSTALK); ret |= (1 << i);
case RETRO_DEVICE_ID_JOYPAD_R: break;
return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER] > XINPUT_GAMEPAD_MAX_CROSSTALK); case RETRO_DEVICE_ID_JOYPAD_L3:
default: if (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB)
break; ret |= (1 << i);
} break;
case RETRO_DEVICE_ID_JOYPAD_R3:
if (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB)
ret |= (1 << i);
break;
case RETRO_DEVICE_ID_JOYPAD_L2:
if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_WHITE] > XINPUT_GAMEPAD_MAX_CROSSTALK)
ret |= (1 << i);
break;
case RETRO_DEVICE_ID_JOYPAD_R2:
if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_BLACK] > XINPUT_GAMEPAD_MAX_CROSSTALK)
ret |= (1 << i);
break;
case RETRO_DEVICE_ID_JOYPAD_L:
if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER] > XINPUT_GAMEPAD_MAX_CROSSTALK)
ret |= (1 << i);
break;
case RETRO_DEVICE_ID_JOYPAD_R:
if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER] > XINPUT_GAMEPAD_MAX_CROSSTALK)
ret |= (1 << i);
break;
default:
break;
}
#else #else
if (joykey < 10) if (i < 10)
return btn_word & button_index_to_bitmap_code[joykey]; if (btn_word & button_index_to_bitmap_code[i])
ret |= (1 << i);
#endif #endif
}
} }
return 0; return ret;
} }
static int16_t xdk_joypad_axis(unsigned port_num, uint32_t joyaxis) static int16_t xdk_joypad_axis(unsigned port_num, uint32_t joyaxis)

View File

@ -424,9 +424,12 @@ static const uint16_t button_index_to_bitmap_code[] = {
static int16_t xinput_joypad_button(unsigned port_num, uint16_t joykey) static int16_t xinput_joypad_button(unsigned port_num, uint16_t joykey)
{ {
uint16_t btn_word = 0; int16_t ret = 0;
unsigned hat_dir = 0; uint16_t btn_word = 0;
int xuser = pad_index_to_xuser_index(port_num); unsigned hat_dir = 0;
int xuser = pad_index_to_xuser_index(port_num);
uint16_t i = joykey;
uint16_t end = joykey + 1;
#ifdef HAVE_DINPUT #ifdef HAVE_DINPUT
if (xuser == -1) if (xuser == -1)
@ -436,30 +439,42 @@ static int16_t xinput_joypad_button(unsigned port_num, uint16_t joykey)
if (!(g_xinput_states[xuser].connected)) if (!(g_xinput_states[xuser].connected))
return 0; return 0;
btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons; for (; i < end; i++)
hat_dir = GET_HAT_DIR(joykey);
if (hat_dir)
{ {
switch (hat_dir) btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons;
{ hat_dir = GET_HAT_DIR(i);
case HAT_UP_MASK:
return btn_word & XINPUT_GAMEPAD_DPAD_UP;
case HAT_DOWN_MASK:
return btn_word & XINPUT_GAMEPAD_DPAD_DOWN;
case HAT_LEFT_MASK:
return btn_word & XINPUT_GAMEPAD_DPAD_LEFT;
case HAT_RIGHT_MASK:
return btn_word & XINPUT_GAMEPAD_DPAD_RIGHT;
default:
break;
}
/* hat requested and no hat button down */
}
else if (joykey < g_xinput_num_buttons)
return btn_word & button_index_to_bitmap_code[joykey];
return 0; if (hat_dir)
{
switch (hat_dir)
{
case HAT_UP_MASK:
if (btn_word & XINPUT_GAMEPAD_DPAD_UP)
ret |= (1 << i);
break;
case HAT_DOWN_MASK:
if (btn_word & XINPUT_GAMEPAD_DPAD_DOWN)
ret |= (1 << i);
break;
case HAT_LEFT_MASK:
if (btn_word & XINPUT_GAMEPAD_DPAD_LEFT)
ret |= (1 << i);
break;
case HAT_RIGHT_MASK:
if (btn_word & XINPUT_GAMEPAD_DPAD_RIGHT)
ret |= (1 << i);
break;
default:
break;
}
/* hat requested and no hat button down */
}
else if (i < g_xinput_num_buttons)
if (btn_word & button_index_to_bitmap_code[i])
ret |= (1 << i);
}
return ret;
} }
static int16_t xinput_joypad_axis (unsigned port_num, uint32_t joyaxis) static int16_t xinput_joypad_axis (unsigned port_num, uint32_t joyaxis)

View File

@ -20,11 +20,13 @@
#include "../input_driver.h" #include "../input_driver.h"
struct pad_connection_listener_interface { struct pad_connection_listener_interface
{
void (*connected)(unsigned port, input_device_driver_t *driver); void (*connected)(unsigned port, input_device_driver_t *driver);
}; };
typedef struct _axis_data { typedef struct _axis_data
{
int32_t axis; int32_t axis;
bool is_negative; bool is_negative;
} axis_data; } axis_data;

View File

@ -38,7 +38,7 @@ struct hid_driver
void *(*init)(void); void *(*init)(void);
bool (*query_pad)(void *handle, unsigned pad); bool (*query_pad)(void *handle, unsigned pad);
void (*free)(const void *handle); void (*free)(const void *handle);
bool (*button)(void *handle, unsigned pad, uint16_t button); int16_t (*button)(void *handle, unsigned pad, uint16_t button);
void (*get_buttons)(void *handle, unsigned pad, input_bits_t *state); void (*get_buttons)(void *handle, unsigned pad, input_bits_t *state);
int16_t (*axis)(void *handle, unsigned pad, uint32_t axis); int16_t (*axis)(void *handle, unsigned pad, uint32_t axis);
void (*poll)(void *handle); void (*poll)(void *handle);

View File

@ -215,6 +215,48 @@ struct rarch_joypad_driver
const char *ident; const char *ident;
}; };
#if defined(ANDROID)
#define DEFAULT_MAX_PADS 8
#define ANDROID_KEYBOARD_PORT DEFAULT_MAX_PADS
#elif defined(_3DS)
#define DEFAULT_MAX_PADS 1
#elif defined(SWITCH) || defined(HAVE_LIBNX)
#define DEFAULT_MAX_PADS 8
#elif defined(WIIU)
#ifdef WIIU_HID
#define DEFAULT_MAX_PADS 16
#else
#define DEFAULT_MAX_PADS 5
#endif
#elif defined(DJGPP)
#define DEFAULT_MAX_PADS 1
#define DOS_KEYBOARD_PORT DEFAULT_MAX_PADS
#elif defined(XENON)
#define DEFAULT_MAX_PADS 4
#elif defined(VITA) || defined(SN_TARGET_PSP2)
#define DEFAULT_MAX_PADS 4
#elif defined(PSP)
#define DEFAULT_MAX_PADS 1
#elif defined(PS2)
#define DEFAULT_MAX_PADS 2
#elif defined(GEKKO) || defined(HW_RVL)
#define DEFAULT_MAX_PADS 4
#elif defined(__linux__) || (defined(BSD) && !defined(__MACH__))
#define DEFAULT_MAX_PADS 8
#elif defined(__QNX__)
#define DEFAULT_MAX_PADS 8
#elif defined(__CELLOS_LV2__)
#define DEFAULT_MAX_PADS 7
#elif defined(_XBOX)
#define DEFAULT_MAX_PADS 4
#elif defined(HAVE_XINPUT) && !defined(HAVE_DINPUT)
#define DEFAULT_MAX_PADS 4
#elif defined(DINGUX)
#define DEFAULT_MAX_PADS 2
#else
#define DEFAULT_MAX_PADS 16
#endif
/** /**
* config_get_input_driver_options: * config_get_input_driver_options:
* *

View File

@ -871,8 +871,8 @@ static const char *null_hid_joypad_name(
void *data, unsigned pad) { return NULL; } void *data, unsigned pad) { return NULL; }
static void null_hid_joypad_get_buttons(void *data, static void null_hid_joypad_get_buttons(void *data,
unsigned port, input_bits_t *state) { BIT256_CLEAR_ALL_PTR(state); } unsigned port, input_bits_t *state) { BIT256_CLEAR_ALL_PTR(state); }
static bool null_hid_joypad_button( static int16_t null_hid_joypad_button(
void *data, unsigned port, uint16_t joykey) { return false; } void *data, unsigned port, uint16_t joykey) { return 0; }
static bool null_hid_joypad_rumble(void *data, unsigned pad, static bool null_hid_joypad_rumble(void *data, unsigned pad,
enum retro_rumble_effect effect, uint16_t strength) { return false; } enum retro_rumble_effect effect, uint16_t strength) { return false; }
static int16_t null_hid_joypad_axis( static int16_t null_hid_joypad_axis(