diff --git a/config.def.h b/config.def.h index 293ac4b774..60658fc8d9 100644 --- a/config.def.h +++ b/config.def.h @@ -53,48 +53,6 @@ #define DEFAULT_ASPECT_RATIO -1.0f #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) #define DEFAULT_MOUSE_SCALE 1 #endif diff --git a/input/common/hid/device_ds3.c b/input/common/hid/device_ds3.c index cb3b01b736..a66cfb8ae9 100644 --- a/input/common/hid/device_ds3.c +++ b/input/common/hid/device_ds3.c @@ -333,13 +333,22 @@ static const char *ds3_get_name(void *data) 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; - if(!pad || joykey > 31) - return false; + int16_t ret = 0; + uint16_t i = joykey; + 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 = { diff --git a/input/common/hid/device_ds4.c b/input/common/hid/device_ds4.c index af923cee13..42ce345083 100644 --- a/input/common/hid/device_ds4.c +++ b/input/common/hid/device_ds4.c @@ -137,9 +137,9 @@ static const char *ds4_get_name(void *data) 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 = { diff --git a/input/common/hid/device_null.c b/input/common/hid/device_null.c index 13ba395ada..947f2720c2 100644 --- a/input/common/hid/device_null.c +++ b/input/common/hid/device_null.c @@ -200,9 +200,9 @@ static const char *hid_null_get_name(void *data) /** * 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; } /** diff --git a/input/common/hid/device_wiiu_gca.c b/input/common/hid/device_wiiu_gca.c index 8d6e713434..153af77fbf 100644 --- a/input/common/hid/device_wiiu_gca.c +++ b/input/common/hid/device_wiiu_gca.c @@ -341,14 +341,22 @@ static const char *wiiu_gca_get_name(void *data) * 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) - return false; - - return pad->buttons & (1 << joykey); + if (!pad) + return 0; + for (; i < end; i++) + { + if (i < 31) + if (pad->buttons & (1 << i)) + ret |= (1 << i); + } + return ret; } pad_connection_interface_t wiiu_gca_pad_connection = { diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index 3e1d6fd3c1..b750348b42 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -1366,16 +1366,23 @@ static void btstack_hid_joypad_get_buttons(void *data, unsigned port, static int16_t btstack_hid_joypad_button(void *data, unsigned port, uint16_t joykey) { - input_bits_t buttons; - btstack_hid_joypad_get_buttons(data, port, &buttons); + input_bits_t buttons; + int16_t ret = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; + btstack_hid_joypad_get_buttons(data, port, &buttons); - /* Check hat. */ - if (GET_HAT_DIR(joykey)) - return 0; - else if ((port < MAX_USERS) && (joykey < 32)) - return (BIT256_GET(buttons, joykey) != 0); + for (; i < end; i++) + { + /* Check hat. */ + if (GET_HAT_DIR(i)) + 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, diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index 21523414b6..854a29a983 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -149,39 +149,58 @@ static void iohidmanager_hid_joypad_get_buttons(void *data, static int16_t iohidmanager_hid_joypad_button(void *data, unsigned port, uint16_t joykey) { - input_bits_t buttons; - iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data; - unsigned hat_dir = GET_HAT_DIR(joykey); + input_bits_t buttons; + int16_t ret = 0; + 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. */ - if (hat_dir) + iohidmanager_hid_joypad_get_buttons(data, port, &buttons); + + for (; i < end; i++) { - unsigned h = GET_HAT(joykey); - if (h >= 1) - return 0; + unsigned hat_dir = GET_HAT_DIR(i); - switch(hat_dir) + /* Check hat. */ + if (hat_dir) { - case HAT_LEFT_MASK: - return hid->hats[port][0] < 0; - case HAT_RIGHT_MASK: - 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); + unsigned h = GET_HAT(i); + if (h >= 1) + continue; - 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, diff --git a/input/drivers_hid/libusb_hid.c b/input/drivers_hid/libusb_hid.c index f1b04b8cd9..24d57fa98a 100644 --- a/input/drivers_hid/libusb_hid.c +++ b/input/drivers_hid/libusb_hid.c @@ -458,14 +458,24 @@ static int16_t libusb_hid_joypad_button(void *data, unsigned port, uint16_t joykey) { 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); - /* Check hat. */ - if (GET_HAT_DIR(joykey)) - return 0; - else if ((port < MAX_USERS) && (joykey < 32)) - return (BIT256_GET(buttons, joykey) != 0); - return 0; + for (; i < end; i++) + { + /* Check hat. */ + if (GET_HAT_DIR(i)) + continue; + 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, diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 831386adf1..85f0fe6402 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -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); } -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) 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, diff --git a/input/drivers_hid/wiiusb_hid.c b/input/drivers_hid/wiiusb_hid.c index 403af4d12b..99b4b562d9 100644 --- a/input/drivers_hid/wiiusb_hid.c +++ b/input/drivers_hid/wiiusb_hid.c @@ -542,16 +542,26 @@ static void wiiusb_hid_joypad_get_buttons(void *data, static int16_t wiiusb_hid_joypad_button(void *data, 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. */ - if (GET_HAT_DIR(joykey)) - return 0; - else if ((port < MAX_USERS) && (joykey < 32)) - return (BIT256_GET(buttons, joykey) != 0); - return 0; + for (; i < end; i++) + { + /* Check hat. */ + if (GET_HAT_DIR(i)) + continue; + 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, diff --git a/input/drivers_joypad/android_joypad.c b/input/drivers_joypad/android_joypad.c index 033538a359..42e2fd48fe 100644 --- a/input/drivers_joypad/android_joypad.c +++ b/input/drivers_joypad/android_joypad.c @@ -32,38 +32,53 @@ static bool android_joypad_init(void *data) static int16_t android_joypad_button(unsigned port, uint16_t joykey) { + int16_t ret = 0; uint8_t *buf = android_keyboard_state_get(port); struct android_app *android_app = (struct android_app*)g_android; unsigned hat_dir = GET_HAT_DIR(joykey); + uint16_t i = joykey; + uint16_t end = joykey + 1; if (port >= DEFAULT_MAX_PADS) return 0; - if (hat_dir) + for (; i < end; i++) { - unsigned h = GET_HAT(joykey); - if (h > 0) - return 0; - - switch (hat_dir) + if (hat_dir) { - case HAT_LEFT_MASK: - return android_app->hat_state[port][0] == -1; - case HAT_RIGHT_MASK: - 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); + unsigned h = GET_HAT(i); + if (h > 0) + continue; - 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) diff --git a/input/drivers_joypad/ctr_joypad.c b/input/drivers_joypad/ctr_joypad.c index f1a8450336..6e13fbcc4e 100644 --- a/input/drivers_joypad/ctr_joypad.c +++ b/input/drivers_joypad/ctr_joypad.c @@ -55,11 +55,20 @@ static bool ctr_joypad_init(void *data) 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) 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) diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 878bebc634..b32f02643f 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -445,66 +445,88 @@ static bool dinput_joypad_init(void *data) static int16_t dinput_joypad_button(unsigned port_num, uint16_t joykey) { const struct dinput_joypad_data *pad = &g_pads[port_num]; + int16_t ret = 0; unsigned hat_dir = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; if (!pad || !pad->joypad) return 0; - - hat_dir = GET_HAT_DIR(joykey); - if (hat_dir) + for (; i < end; i++) { - unsigned h = GET_HAT(joykey); - if (h < NUM_HATS) + hat_dir = GET_HAT_DIR(i); + + if (hat_dir) { - unsigned pov = pad->joy_state.rgdwPOV[h]; - switch (hat_dir) + unsigned h = GET_HAT(i); + if (h < NUM_HATS) { - case HAT_UP_MASK: - { - static const unsigned check1 = (JOY_POVRIGHT/2); - static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2); - return - (pov == JOY_POVFORWARD) || - (pov == check1) || - (pov == check2); - } - case HAT_RIGHT_MASK: - { - static const unsigned check1 = (JOY_POVRIGHT/2); - static const unsigned check2 = (JOY_POVRIGHT+JOY_POVRIGHT/2); - return - (pov == JOY_POVRIGHT) || - (pov == check1) || - (pov == check2); - } - case HAT_DOWN_MASK: - { - static const unsigned check1 = (JOY_POVRIGHT+JOY_POVRIGHT/2); - static const unsigned check2 = (JOY_POVBACKWARD+JOY_POVRIGHT/2); - return - (pov == JOY_POVBACKWARD) || - (pov == check1) || - (pov == check2); - } - case HAT_LEFT_MASK: - { - static const unsigned check1 = (JOY_POVBACKWARD+JOY_POVRIGHT/2); - static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2); - return - (pov == JOY_POVLEFT) || - (pov == check1) || - (pov == check2); - } - default: - break; + unsigned pov = pad->joy_state.rgdwPOV[h]; + switch (hat_dir) + { + case HAT_UP_MASK: + { + static const unsigned check1 = (JOY_POVRIGHT/2); + static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2); + if ( + (pov == JOY_POVFORWARD) || + (pov == check1) || + (pov == check2) + ) + ret |= (1 << i); + } + break; + case HAT_RIGHT_MASK: + { + static const unsigned check1 = (JOY_POVRIGHT/2); + static const unsigned check2 = (JOY_POVRIGHT+JOY_POVRIGHT/2); + if ( + (pov == JOY_POVRIGHT) || + (pov == check1) || + (pov == check2) + ) + ret |= (1 << i); + } + break; + case HAT_DOWN_MASK: + { + static const unsigned check1 = (JOY_POVRIGHT+JOY_POVRIGHT/2); + static const unsigned check2 = (JOY_POVBACKWARD+JOY_POVRIGHT/2); + if + ( + (pov == JOY_POVBACKWARD) || + (pov == check1) || + (pov == check2) + ) + 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 0; + + return ret; } static int16_t dinput_joypad_axis(unsigned port_num, uint32_t joyaxis) diff --git a/input/drivers_joypad/dos_joypad.c b/input/drivers_joypad/dos_joypad.c index ccb82e1e28..aa8dcc646c 100644 --- a/input/drivers_joypad/dos_joypad.c +++ b/input/drivers_joypad/dos_joypad.c @@ -164,38 +164,64 @@ static bool dos_joypad_init(void *data) 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) return 0; - switch (key) + for (; i < end; i++) { - case RETRO_DEVICE_ID_JOYPAD_A: - return buf[DOSKEY_x]; - case RETRO_DEVICE_ID_JOYPAD_B: - return buf[DOSKEY_z]; - case RETRO_DEVICE_ID_JOYPAD_X: - return buf[DOSKEY_s]; - case RETRO_DEVICE_ID_JOYPAD_Y: - return buf[DOSKEY_a]; - case RETRO_DEVICE_ID_JOYPAD_SELECT: - return buf[DOSKEY_RSHIFT]; - case RETRO_DEVICE_ID_JOYPAD_START: - return buf[DOSKEY_RETURN]; - case RETRO_DEVICE_ID_JOYPAD_UP: - return buf[DOSKEY_UP]; - case RETRO_DEVICE_ID_JOYPAD_DOWN: - return buf[DOSKEY_DOWN]; - case RETRO_DEVICE_ID_JOYPAD_LEFT: - return buf[DOSKEY_LEFT]; - case RETRO_DEVICE_ID_JOYPAD_RIGHT: - return buf[DOSKEY_RIGHT]; + switch (key) + { + case RETRO_DEVICE_ID_JOYPAD_A: + if (buf[DOSKEY_x]) + ret |= (1 << i); + break; + case RETRO_DEVICE_ID_JOYPAD_B: + if (buf[DOSKEY_z]) + ret |= (1 << i); + break; + case RETRO_DEVICE_ID_JOYPAD_X: + if (buf[DOSKEY_s]) + ret |= (1 << i): + break; + case RETRO_DEVICE_ID_JOYPAD_Y: + if (buf[DOSKEY_a]) + ret |= (1 << i); + break; + case RETRO_DEVICE_ID_JOYPAD_SELECT: + 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) diff --git a/input/drivers_joypad/gx_joypad.c b/input/drivers_joypad/gx_joypad.c index 76e3f1a638..39e780e860 100644 --- a/input/drivers_joypad/gx_joypad.c +++ b/input/drivers_joypad/gx_joypad.c @@ -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) 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) diff --git a/input/drivers_joypad/linuxraw_joypad.c b/input/drivers_joypad/linuxraw_joypad.c index cc9255a830..fc616cd3fd 100644 --- a/input/drivers_joypad/linuxraw_joypad.c +++ b/input/drivers_joypad/linuxraw_joypad.c @@ -303,12 +303,20 @@ static void linuxraw_joypad_destroy(void) 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]; - - if (joykey < NUM_BUTTONS) - return BIT32_GET(pad->buttons, joykey); - return 0; + if (port >= DEFAULT_MAX_PADS) + return 0; + for (; i < end; i++) + { + 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) diff --git a/input/drivers_joypad/mfi_joypad.m b/input/drivers_joypad/mfi_joypad.m index 25d649dd6a..78e59a50b4 100644 --- a/input/drivers_joypad/mfi_joypad.m +++ b/input/drivers_joypad/mfi_joypad.m @@ -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. */ - if (GET_HAT_DIR(joykey)) - return 0; - /* Check the button. */ - if ((port < MAX_USERS) && (joykey < 32)) - return ((mfi_buttons[port] & (1 << joykey)) != 0); - return 0; + int16_t ret = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; + if (port >= DEFAULT_MAX_PADS) + return 0; + for (; i < end; i++) + { + /* 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, diff --git a/input/drivers_joypad/parport_joypad.c b/input/drivers_joypad/parport_joypad.c index 7e0d8d7dd6..533b5e0f76 100644 --- a/input/drivers_joypad/parport_joypad.c +++ b/input/drivers_joypad/parport_joypad.c @@ -331,10 +331,20 @@ static void parport_joypad_destroy(void) static int16_t parport_joypad_button(unsigned port, uint16_t joykey) { - const struct parport_joypad *pad = (const struct parport_joypad*)&parport_pads[port]; - if (joykey < PARPORT_NUM_BUTTONS) - return BIT32_GET(pad->buttons, joykey); - return 0; + int16_t ret = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; + 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) diff --git a/input/drivers_joypad/ps2_joypad.c b/input/drivers_joypad/ps2_joypad.c index ab57d0f8d1..2bdb487e6e 100644 --- a/input/drivers_joypad/ps2_joypad.c +++ b/input/drivers_joypad/ps2_joypad.c @@ -86,9 +86,17 @@ static bool ps2_joypad_init(void *data) 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) 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) diff --git a/input/drivers_joypad/ps3_joypad.c b/input/drivers_joypad/ps3_joypad.c index df5e076c58..3172db1e44 100644 --- a/input/drivers_joypad/ps3_joypad.c +++ b/input/drivers_joypad/ps3_joypad.c @@ -63,9 +63,17 @@ static bool ps3_joypad_init(void *data) 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) 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) diff --git a/input/drivers_joypad/ps4_joypad.c b/input/drivers_joypad/ps4_joypad.c index 0a155efb16..fe9e3bfbcf 100644 --- a/input/drivers_joypad/ps4_joypad.c +++ b/input/drivers_joypad/ps4_joypad.c @@ -132,9 +132,17 @@ static bool ps4_joypad_init(void *data) 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) 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) diff --git a/input/drivers_joypad/psp_joypad.c b/input/drivers_joypad/psp_joypad.c index 32ccfc5c28..d40721f233 100644 --- a/input/drivers_joypad/psp_joypad.c +++ b/input/drivers_joypad/psp_joypad.c @@ -119,11 +119,19 @@ static bool psp_joypad_init(void *data) 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) 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) diff --git a/input/drivers_joypad/qnx_joypad.c b/input/drivers_joypad/qnx_joypad.c index a938b8b1c9..528496fbb0 100644 --- a/input/drivers_joypad/qnx_joypad.c +++ b/input/drivers_joypad/qnx_joypad.c @@ -46,17 +46,24 @@ static bool qnx_joypad_init(void *data) static int16_t qnx_joypad_button(unsigned port_num, uint16_t joykey) { - qnx_input_device_t* controller = NULL; - qnx_input_t *qnx = (qnx_input_t*)input_driver_get_data(); + qnx_input_device_t* controller = NULL; + 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) return 0; controller = (qnx_input_device_t*)&qnx->devices[port_num]; - if(port_num < MAX_USERS && joykey <= 19) - return (controller->buttons & (1 << joykey)) != 0; - return 0; + for (; i < end; i++) + { + 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) diff --git a/input/drivers_joypad/rwebpad_joypad.c b/input/drivers_joypad/rwebpad_joypad.c index bb512ff4ee..0adfa9eb18 100644 --- a/input/drivers_joypad/rwebpad_joypad.c +++ b/input/drivers_joypad/rwebpad_joypad.c @@ -102,14 +102,23 @@ static const char *rwebpad_joypad_name(unsigned pad) static int16_t rwebpad_joypad_button(unsigned port_num, uint16_t joykey) { 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); - if (r == EMSCRIPTEN_RESULT_SUCCESS) - if (joykey < gamepad_state.numButtons) - return gamepad_state.digitalButton[joykey]; - - return 0; + if (port >= DEFAULT_MAX_PADS) + return 0; + if (r != EMSCRIPTEN_RESULT_SUCCESS) + 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) diff --git a/input/drivers_joypad/sdl_joypad.c b/input/drivers_joypad/sdl_joypad.c index 28f764fe39..0290dd9797 100644 --- a/input/drivers_joypad/sdl_joypad.c +++ b/input/drivers_joypad/sdl_joypad.c @@ -297,42 +297,58 @@ error: static int16_t sdl_joypad_button(unsigned port, uint16_t joykey) { - unsigned hat_dir = 0; - sdl_joypad_t *pad = (sdl_joypad_t*)&sdl_pads[port]; + int16_t ret = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; + sdl_joypad_t *pad = (sdl_joypad_t*)&sdl_pads[port]; if (!pad || !pad->joypad) return 0; + if (port >= DEFAULT_MAX_PADS) + return 0; - hat_dir = GET_HAT_DIR(joykey); - /* Check hat. */ - if (hat_dir) + for (; i < end; i++) { - uint8_t dir; - uint16_t hat = GET_HAT(joykey); - - if (hat >= pad->num_hats) - return false; - - dir = sdl_pad_get_hat(pad, hat); - - switch (hat_dir) + unsigned hat_dir = GET_HAT_DIR(i); + /* Check hat. */ + if (hat_dir) { - case HAT_UP_MASK: - return dir & SDL_HAT_UP; - 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); + uint8_t dir; + uint16_t hat = GET_HAT(i); - 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) diff --git a/input/drivers_joypad/switch_joypad.c b/input/drivers_joypad/switch_joypad.c index 50438eefbb..43216db69b 100644 --- a/input/drivers_joypad/switch_joypad.c +++ b/input/drivers_joypad/switch_joypad.c @@ -83,11 +83,19 @@ static bool switch_joypad_init(void *data) 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) 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) diff --git a/input/drivers_joypad/udev_joypad.c b/input/drivers_joypad/udev_joypad.c index 7e894c5dfe..642499325b 100644 --- a/input/drivers_joypad/udev_joypad.c +++ b/input/drivers_joypad/udev_joypad.c @@ -592,33 +592,51 @@ error: static int16_t udev_joypad_button(unsigned port, uint16_t joykey) { - const struct udev_joypad *pad = (const struct udev_joypad*)&udev_pads[port]; - unsigned hat_dir = GET_HAT_DIR(joykey); - - if (hat_dir) + int16_t ret = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; + 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); - if (h < NUM_HATS) + unsigned hat_dir = GET_HAT_DIR(i); + + if (hat_dir) { - switch (hat_dir) + unsigned h = GET_HAT(i); + if (h < NUM_HATS) { - case HAT_LEFT_MASK: - return pad->hats[h][0] < 0; - case HAT_RIGHT_MASK: - return pad->hats[h][0] > 0; - case HAT_UP_MASK: - return pad->hats[h][1] < 0; - case HAT_DOWN_MASK: - return pad->hats[h][1] > 0; - default: - break; + switch (hat_dir) + { + case HAT_LEFT_MASK: + if (pad->hats[h][0] < 0) + ret |= (1 << i); + break; + case HAT_RIGHT_MASK: + if (pad->hats[h][0] > 0) + ret |= (1 << i): + 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 BIT64_GET(pad->buttons, joykey); - return 0; + return ret; } static void udev_joypad_get_buttons(unsigned port, input_bits_t *state) diff --git a/input/drivers_joypad/wiiu/hidpad_driver.c b/input/drivers_joypad/wiiu/hidpad_driver.c index 65cb79e965..e48611ebbb 100644 --- a/input/drivers_joypad/wiiu/hidpad_driver.c +++ b/input/drivers_joypad/wiiu/hidpad_driver.c @@ -58,11 +58,19 @@ static void hidpad_destroy(void) 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)) 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) diff --git a/input/drivers_joypad/wiiu/kpad_driver.c b/input/drivers_joypad/wiiu/kpad_driver.c index 25acbbdbb6..f2c7b00b83 100644 --- a/input/drivers_joypad/wiiu/kpad_driver.c +++ b/input/drivers_joypad/wiiu/kpad_driver.c @@ -22,14 +22,8 @@ #include "../../include/wiiu/input.h" -static bool kpad_init(void *data); -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); +/* Forward declarations */ static void kpad_poll(void); -static const char *kpad_name(unsigned pad); static void kpad_deregister(unsigned channel); typedef struct _wiimote_state wiimote_state; @@ -98,18 +92,25 @@ static void kpad_destroy(void) 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; + int16_t ret = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; if (!kpad_query_pad(pad)) return 0; channel = to_wiimote_channel(pad); if(channel < 0) return 0; - - return wiimotes[channel].button_state - & (UINT64_C(1) << button_bit); + for (; i < end; i++) + { + 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) diff --git a/input/drivers_joypad/wiiu/wpad_driver.c b/input/drivers_joypad/wiiu/wpad_driver.c index e905ee277a..2177acb9d7 100644 --- a/input/drivers_joypad/wiiu/wpad_driver.c +++ b/input/drivers_joypad/wiiu/wpad_driver.c @@ -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; + int16_t ret = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; if (!wpad_query_pad(pad)) return 0; @@ -289,7 +292,12 @@ static int16_t wpad_button(unsigned pad, uint16_t button_bit) if (channel < 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) diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c index 79726a8b0d..243d7edb31 100644 --- a/input/drivers_joypad/wiiu_joypad.c +++ b/input/drivers_joypad/wiiu_joypad.c @@ -60,11 +60,21 @@ static void wiiu_joypad_destroy(void) #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)) 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) diff --git a/input/drivers_joypad/xdk_joypad.c b/input/drivers_joypad/xdk_joypad.c index 00d90607c6..42fb398c9b 100644 --- a/input/drivers_joypad/xdk_joypad.c +++ b/input/drivers_joypad/xdk_joypad.c @@ -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) { - uint16_t btn_word = 0; - unsigned hat_dir = 0; + int16_t ret = 0; + uint16_t i = joykey; + uint16_t end = joykey + 1; if (port_num >= DEFAULT_MAX_PADS) return 0; - btn_word = g_xinput_states[port_num].xstate.Gamepad.wButtons; - hat_dir = GET_HAT_DIR(joykey); + for (; i < end; i++) + { + uint16_t btn_word = g_xinput_states[port_num].xstate.Gamepad.wButtons; + unsigned hat_dir = GET_HAT_DIR(i); - if (hat_dir) - { - switch (hat_dir) + if (hat_dir) { - 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; + 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 */ } - /* hat requested and no hat button down */ - } - else - { + else + { #ifdef _XBOX1 - switch (joykey) - { - case RETRO_DEVICE_ID_JOYPAD_A: - return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_B] > XINPUT_GAMEPAD_MAX_CROSSTALK); - case RETRO_DEVICE_ID_JOYPAD_B: - return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_A] > XINPUT_GAMEPAD_MAX_CROSSTALK); - case RETRO_DEVICE_ID_JOYPAD_Y: - return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_X] > XINPUT_GAMEPAD_MAX_CROSSTALK); - case RETRO_DEVICE_ID_JOYPAD_X: - return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_Y] > XINPUT_GAMEPAD_MAX_CROSSTALK); - case RETRO_DEVICE_ID_JOYPAD_START: - return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_START); - case RETRO_DEVICE_ID_JOYPAD_SELECT: - return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_BACK); - case RETRO_DEVICE_ID_JOYPAD_L3: - return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB); - case RETRO_DEVICE_ID_JOYPAD_R3: - return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB); - case RETRO_DEVICE_ID_JOYPAD_L2: - return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_WHITE] > XINPUT_GAMEPAD_MAX_CROSSTALK); - case RETRO_DEVICE_ID_JOYPAD_R2: - return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_BLACK] > XINPUT_GAMEPAD_MAX_CROSSTALK); - case RETRO_DEVICE_ID_JOYPAD_L: - return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER] > XINPUT_GAMEPAD_MAX_CROSSTALK); - case RETRO_DEVICE_ID_JOYPAD_R: - return (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER] > XINPUT_GAMEPAD_MAX_CROSSTALK); - default: - break; - } + switch (i) + { + case RETRO_DEVICE_ID_JOYPAD_A: + if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_B] > XINPUT_GAMEPAD_MAX_CROSSTALK) + ret |= (1 << i); + break; + case RETRO_DEVICE_ID_JOYPAD_B: + if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_A] > XINPUT_GAMEPAD_MAX_CROSSTALK) + ret |= (1 << i); + break; + case RETRO_DEVICE_ID_JOYPAD_Y: + if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_X] > XINPUT_GAMEPAD_MAX_CROSSTALK) + ret |= (1 << i); + break; + case RETRO_DEVICE_ID_JOYPAD_X: + if (g_xinput_states[port_num].xstate.Gamepad.bAnalogButtons[XINPUT_GAMEPAD_Y] > XINPUT_GAMEPAD_MAX_CROSSTALK) + ret |= (1 << i); + break; + case RETRO_DEVICE_ID_JOYPAD_START: + return (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_START); + break; + case RETRO_DEVICE_ID_JOYPAD_SELECT: + if (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) + ret |= (1 << i); + break; + case RETRO_DEVICE_ID_JOYPAD_L3: + if (g_xinput_states[port_num].xstate.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) + 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 - if (joykey < 10) - return btn_word & button_index_to_bitmap_code[joykey]; + if (i < 10) + if (btn_word & button_index_to_bitmap_code[i]) + ret |= (1 << i); #endif + } } - return 0; + return ret; } static int16_t xdk_joypad_axis(unsigned port_num, uint32_t joyaxis) diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index eb55d98473..8683c4a11b 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -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) { - uint16_t btn_word = 0; - unsigned hat_dir = 0; - int xuser = pad_index_to_xuser_index(port_num); + int16_t ret = 0; + uint16_t btn_word = 0; + 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 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)) return 0; - btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons; - hat_dir = GET_HAT_DIR(joykey); - - if (hat_dir) + for (; i < end; i++) { - switch (hat_dir) - { - 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]; + btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons; + hat_dir = GET_HAT_DIR(i); - 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) diff --git a/input/include/gamepad.h b/input/include/gamepad.h index d895b55f25..a3fd5dff1e 100644 --- a/input/include/gamepad.h +++ b/input/include/gamepad.h @@ -20,11 +20,13 @@ #include "../input_driver.h" -struct pad_connection_listener_interface { +struct pad_connection_listener_interface +{ void (*connected)(unsigned port, input_device_driver_t *driver); }; -typedef struct _axis_data { +typedef struct _axis_data +{ int32_t axis; bool is_negative; } axis_data; diff --git a/input/include/hid_driver.h b/input/include/hid_driver.h index 81c9f7cd94..9c1040754a 100644 --- a/input/include/hid_driver.h +++ b/input/include/hid_driver.h @@ -38,7 +38,7 @@ struct hid_driver void *(*init)(void); bool (*query_pad)(void *handle, unsigned pad); 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); int16_t (*axis)(void *handle, unsigned pad, uint32_t axis); void (*poll)(void *handle); diff --git a/input/input_driver.h b/input/input_driver.h index c9b1439fcf..ee02e02d0f 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -215,6 +215,48 @@ struct rarch_joypad_driver 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: * diff --git a/retroarch.c b/retroarch.c index 09f4b2a110..a172b4e5fe 100644 --- a/retroarch.c +++ b/retroarch.c @@ -871,8 +871,8 @@ static const char *null_hid_joypad_name( void *data, unsigned pad) { return NULL; } static void null_hid_joypad_get_buttons(void *data, unsigned port, input_bits_t *state) { BIT256_CLEAR_ALL_PTR(state); } -static bool null_hid_joypad_button( - void *data, unsigned port, uint16_t joykey) { return false; } +static int16_t null_hid_joypad_button( + void *data, unsigned port, uint16_t joykey) { return 0; } static bool null_hid_joypad_rumble(void *data, unsigned pad, enum retro_rumble_effect effect, uint16_t strength) { return false; } static int16_t null_hid_joypad_axis(