replace uint64_t with retro_bits_t* for pad buttons state

This commit is contained in:
David Walters 2017-11-28 10:04:34 +00:00
parent 6ed5a911d7
commit c5bdc02d6f
30 changed files with 520 additions and 401 deletions

View File

@ -27,7 +27,7 @@ struct hidpad_nesusb_data
struct pad_connection* connection; struct pad_connection* connection;
uint8_t data[64]; uint8_t data[64];
uint32_t slot; uint32_t slot;
uint64_t buttons; uint32_t buttons;
}; };
static void* hidpad_nesusb_init(void *data, uint32_t slot, send_control_t ptr) static void* hidpad_nesusb_init(void *data, uint32_t slot, send_control_t ptr)
@ -59,12 +59,14 @@ static void hidpad_nesusb_deinit(void *data)
free(device); free(device);
} }
static uint64_t hidpad_nesusb_get_buttons(void *data) static void hidpad_nesusb_get_buttons(void *data, retro_bits_t* state)
{ {
struct hidpad_nesusb_data *device = (struct hidpad_nesusb_data*)data; struct hidpad_nesusb_data *device = (struct hidpad_nesusb_data*)data;
if (!device) if (device) {
return 0; RARCH_INPUT_STATE_COPY16_PTR(state, device->buttons);
return device->buttons; } else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t hidpad_nesusb_get_axis(void *data, unsigned axis) static int16_t hidpad_nesusb_get_axis(void *data, unsigned axis)
@ -102,7 +104,6 @@ static void hidpad_nesusb_packet_handler(void *data, uint8_t *packet, uint16_t s
RETRO_DEVICE_ID_JOYPAD_A, RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_Y, RETRO_DEVICE_ID_JOYPAD_Y,
RETRO_DEVICE_ID_JOYPAD_X, RETRO_DEVICE_ID_JOYPAD_X,
16, /* HOME BUTTON when pressing SELECT+START */
}; };
struct hidpad_nesusb_data *device = (struct hidpad_nesusb_data*)data; struct hidpad_nesusb_data *device = (struct hidpad_nesusb_data*)data;
@ -113,12 +114,11 @@ static void hidpad_nesusb_packet_handler(void *data, uint8_t *packet, uint16_t s
device->buttons = 0; device->buttons = 0;
pressed_keys = device->data[7] | (device->data[6] << 8) | pressed_keys = device->data[7] | (device->data[6] << 8);
(((device->data[7] & 0x30) == 0x30) ? (1 << 16) : 0); /* SELECT+START=HOME */
for (i = 0; i < 17; i ++) for (i = 0; i < 16; i ++)
if (button_mapping[i] != NO_BTN) if (button_mapping[i] != NO_BTN)
device->buttons |= (pressed_keys & (1 << i)) ? (UINT64_C(1) << button_mapping[i]) : 0; device->buttons |= (pressed_keys & (1 << i)) ? (1 << button_mapping[i]) : 0;
} }
static void hidpad_nesusb_set_rumble(void *data, static void hidpad_nesusb_set_rumble(void *data,

View File

@ -27,7 +27,7 @@ struct hidpad_ps2adapter_data
struct pad_connection* connection; struct pad_connection* connection;
uint8_t data[64]; uint8_t data[64];
uint32_t slot; uint32_t slot;
uint64_t buttons; uint32_t buttons;
}; };
static void* hidpad_ps2adapter_init(void *data, uint32_t slot, send_control_t ptr) static void* hidpad_ps2adapter_init(void *data, uint32_t slot, send_control_t ptr)
@ -59,12 +59,14 @@ static void hidpad_ps2adapter_deinit(void *data)
free(device); free(device);
} }
static uint64_t hidpad_ps2adapter_get_buttons(void *data) static void hidpad_ps2adapter_get_buttons(void *data, retro_bits_t *state)
{ {
struct hidpad_ps2adapter_data *device = (struct hidpad_ps2adapter_data*)data; struct hidpad_ps2adapter_data *device = (struct hidpad_ps2adapter_data*)data;
if (!device) if ( device ) {
return 0; RARCH_INPUT_STATE_COPY16_PTR(state, device->buttons);
return device->buttons; } else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t hidpad_ps2adapter_get_axis(void *data, unsigned axis) static int16_t hidpad_ps2adapter_get_axis(void *data, unsigned axis)

View File

@ -20,6 +20,7 @@
#include <boolean.h> #include <boolean.h>
#include "joypad_connection.h" #include "joypad_connection.h"
#include "../input_defines.h"
struct hidpad_ps3_data struct hidpad_ps3_data
{ {
@ -27,7 +28,7 @@ struct hidpad_ps3_data
send_control_t send_control; send_control_t send_control;
uint8_t data[512]; uint8_t data[512];
uint32_t slot; uint32_t slot;
uint64_t buttons; uint32_t buttons;
bool have_led; bool have_led;
uint16_t motors[2]; uint16_t motors[2];
}; };
@ -104,12 +105,23 @@ static void hidpad_ps3_deinit(void *data)
free(device); free(device);
} }
static uint64_t hidpad_ps3_get_buttons(void *data) static void hidpad_ps3_get_buttons(void *data, retro_bits_t *state)
{ {
struct hidpad_ps3_data *device = (struct hidpad_ps3_data*)data; struct hidpad_ps3_data *device = (struct hidpad_ps3_data*)data;
if (!device) if ( device )
return 0; {
return device->buttons; /*copy first 16 bits - standard RetroPad controls*/
RARCH_INPUT_STATE_COPY16_PTR(state, device->buttons);
/*PS button?*/
if ( device->buttons & 0x10000 ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RARCH_MENU_TOGGLE );
}
}
else
{
RARCH_INPUT_STATE_CLEAR_PTR( state );
}
} }
static int16_t hidpad_ps3_get_axis(void *data, unsigned axis) static int16_t hidpad_ps3_get_axis(void *data, unsigned axis)

View File

@ -184,35 +184,66 @@ static bool hidpad_ps4_check_dpad(struct ps4 *rpt, unsigned id)
return false; return false;
} }
static uint64_t hidpad_ps4_get_buttons(void *data) static void hidpad_ps4_get_buttons(void *data, retro_bits_t* state)
{ {
uint64_t buttonstate = 0; uint64_t buttonstate = 0;
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data; struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
struct ps4 *rpt = device ? (struct ps4*)&device->data : NULL; struct ps4 *rpt = device ? (struct ps4*)&device->data : NULL;
if (!device || !rpt) if (!device || !rpt)
return 0; return;
buttonstate |= (rpt->btn.r3 ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R3) : 0); if ( rpt->btn.r3 ) {
buttonstate |= (rpt->btn.l3 ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L3) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_R3 );
buttonstate |= (rpt->btn.options ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0); }
buttonstate |= (rpt->btn.share ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0); if ( rpt->btn.l3 ) {
buttonstate |= (rpt->btn.r2 ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_L3 );
buttonstate |= (rpt->btn.l2 ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0); }
buttonstate |= (rpt->btn.r1 ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0); if ( rpt->btn.options ) {
buttonstate |= (rpt->btn.l1 ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_START );
}
buttonstate |= (rpt->btn.triangle ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0); if ( rpt->btn.share ) {
buttonstate |= (rpt->btn.circle ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_SELECT );
buttonstate |= (rpt->btn.cross ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0); }
buttonstate |= (rpt->btn.square ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0); if ( rpt->btn.r2 ) {
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_LEFT)) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_R2 );
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_DOWN)) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0); }
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_RIGHT)) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0); if ( rpt->btn.l2 ) {
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_UP)) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_L2 );
buttonstate |= (rpt->btn.ps ? (UINT64_C(1) << RARCH_MENU_TOGGLE) : 0); }
if ( rpt->btn.r1 ) {
return buttonstate; RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_R );
}
if ( rpt->btn.l1 ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_L );
}
if ( rpt->btn.triangle ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_X );
}
if ( rpt->btn.circle ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_A );
}
if ( rpt->btn.cross ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_B );
}
if ( rpt->btn.square ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_Y );
}
if ( (hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_LEFT)) ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_LEFT );
}
if ( (hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_DOWN)) ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_DOWN );
}
if ( (hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_RIGHT)) ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_RIGHT );
}
if ( (hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_UP)) ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_UP );
}
if ( rpt->btn.ps ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RARCH_MENU_TOGGLE );
}
} }
static int16_t hidpad_ps4_get_axis(void *data, unsigned axis) static int16_t hidpad_ps4_get_axis(void *data, unsigned axis)

View File

@ -27,7 +27,7 @@ struct hidpad_psxadapter_data
struct pad_connection* connection; struct pad_connection* connection;
uint8_t data[64]; uint8_t data[64];
uint32_t slot; uint32_t slot;
uint64_t buttons; uint32_t buttons;
}; };
static void* hidpad_psxadapter_init(void *data, uint32_t slot, send_control_t ptr) static void* hidpad_psxadapter_init(void *data, uint32_t slot, send_control_t ptr)
@ -59,12 +59,14 @@ static void hidpad_psxadapter_deinit(void *data)
free(device); free(device);
} }
static uint64_t hidpad_psxadapter_get_buttons(void *data) static void hidpad_psxadapter_get_buttons(void *data, retro_bits_t *state)
{ {
struct hidpad_psxadapter_data *device = (struct hidpad_psxadapter_data*)data; struct hidpad_psxadapter_data *device = (struct hidpad_psxadapter_data*)data;
if (!device) if ( device ) {
return 0; RARCH_INPUT_STATE_COPY16_PTR(state, device->buttons);
return device->buttons; } else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t hidpad_psxadapter_get_axis(void *data, unsigned axis) static int16_t hidpad_psxadapter_get_axis(void *data, unsigned axis)
@ -107,7 +109,7 @@ static void hidpad_psxadapter_packet_handler(void *data, uint8_t *packet, uint16
{ {
uint32_t i, pressed_keys; uint32_t i, pressed_keys;
int16_t hat_value; int16_t hat_value;
static const uint32_t button_mapping[17] = static const uint32_t button_mapping[16] =
{ {
RETRO_DEVICE_ID_JOYPAD_L2, RETRO_DEVICE_ID_JOYPAD_L2,
RETRO_DEVICE_ID_JOYPAD_R2, RETRO_DEVICE_ID_JOYPAD_R2,
@ -125,7 +127,6 @@ static void hidpad_psxadapter_packet_handler(void *data, uint8_t *packet, uint16
RETRO_DEVICE_ID_JOYPAD_A, RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B, RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_Y, RETRO_DEVICE_ID_JOYPAD_Y,
16/* HOME BUTTON when pressing SELECT+START */
}; };
struct hidpad_psxadapter_data *device = (struct hidpad_psxadapter_data*)data; struct hidpad_psxadapter_data *device = (struct hidpad_psxadapter_data*)data;
@ -136,29 +137,28 @@ static void hidpad_psxadapter_packet_handler(void *data, uint8_t *packet, uint16
device->buttons = 0; device->buttons = 0;
pressed_keys = device->data[7] | (device->data[6] << 8) | pressed_keys = device->data[7] | (device->data[6] << 8);
(((device->data[7] & 0x30) == 0x30) ? (1 << 16) : 0); /* SELECT+START = MENU TOGGLE */
for (i = 0; i < 17; i ++) for (i = 0; i < 16; i ++)
if (button_mapping[i] != NO_BTN) if (button_mapping[i] != NO_BTN)
device->buttons |= (pressed_keys & (1 << i)) ? (UINT64_C(1) << button_mapping[i]) : 0; device->buttons |= (pressed_keys & (1 << i)) ? (1 << button_mapping[i]) : 0;
if (device->data[2]==0x7F) /* digital mode detection */ if (device->data[2]==0x7F) /* digital mode detection */
{ {
/* We're in digital mode, process the dpad values */ /* We're in digital mode, process the dpad values */
device->buttons |= (device->data[4]==0x00) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; device->buttons |= (device->data[4]==0x00) ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
device->buttons |= (device->data[4]==0xFF) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; device->buttons |= (device->data[4]==0xFF) ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
device->buttons |= (device->data[5]==0x00) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0; device->buttons |= (device->data[5]==0x00) ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
device->buttons |= (device->data[5]==0xFF) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; device->buttons |= (device->data[5]==0xFF) ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
} }
else else
{ {
/* We're in analog mode, process the hat values as if they were pad buttons */ /* We're in analog mode, process the hat values as if they were pad buttons */
hat_value = PSX_H_GET(device->data[6]); hat_value = PSX_H_GET(device->data[6]);
device->buttons |= PSX_H_LEFT(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; device->buttons |= PSX_H_LEFT(hat_value) ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
device->buttons |= PSX_H_RIGHT(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; device->buttons |= PSX_H_RIGHT(hat_value) ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
device->buttons |= PSX_H_UP(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0; device->buttons |= PSX_H_UP(hat_value) ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
device->buttons |= PSX_H_DOWN(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; device->buttons |= PSX_H_DOWN(hat_value) ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
} }
} }

View File

@ -28,7 +28,7 @@ struct hidpad_snesusb_data
struct pad_connection* connection; struct pad_connection* connection;
uint8_t data[64]; uint8_t data[64];
uint32_t slot; uint32_t slot;
uint64_t buttons; uint32_t buttons;
}; };
static void* hidpad_snesusb_init(void *data, uint32_t slot, send_control_t ptr) static void* hidpad_snesusb_init(void *data, uint32_t slot, send_control_t ptr)
@ -60,12 +60,14 @@ static void hidpad_snesusb_deinit(void *data)
free(device); free(device);
} }
static uint64_t hidpad_snesusb_get_buttons(void *data) static void hidpad_snesusb_get_buttons(void *data, retro_bits_t *state)
{ {
struct hidpad_snesusb_data *device = (struct hidpad_snesusb_data*)data; struct hidpad_snesusb_data *device = (struct hidpad_snesusb_data*)data;
if (!device) if ( device ) {
return 0; RARCH_INPUT_STATE_COPY16_PTR(state, device->buttons);
return device->buttons; } else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t hidpad_snesusb_get_axis(void *data, unsigned axis) static int16_t hidpad_snesusb_get_axis(void *data, unsigned axis)
@ -85,7 +87,7 @@ static int16_t hidpad_snesusb_get_axis(void *data, unsigned axis)
static void hidpad_snesusb_packet_handler(void *data, uint8_t *packet, uint16_t size) static void hidpad_snesusb_packet_handler(void *data, uint8_t *packet, uint16_t size)
{ {
uint32_t i, pressed_keys; uint32_t i, pressed_keys;
static const uint32_t button_mapping[17] = static const uint32_t button_mapping[16] =
{ {
RETRO_DEVICE_ID_JOYPAD_L, RETRO_DEVICE_ID_JOYPAD_L,
RETRO_DEVICE_ID_JOYPAD_R, RETRO_DEVICE_ID_JOYPAD_R,
@ -102,8 +104,7 @@ static void hidpad_snesusb_packet_handler(void *data, uint8_t *packet, uint16_t
RETRO_DEVICE_ID_JOYPAD_X, RETRO_DEVICE_ID_JOYPAD_X,
RETRO_DEVICE_ID_JOYPAD_A, RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B, RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_Y, RETRO_DEVICE_ID_JOYPAD_Y
16, /* HOME BUTTON when pressing SELECT+START */
}; };
struct hidpad_snesusb_data *device = (struct hidpad_snesusb_data*)data; struct hidpad_snesusb_data *device = (struct hidpad_snesusb_data*)data;
@ -114,12 +115,11 @@ static void hidpad_snesusb_packet_handler(void *data, uint8_t *packet, uint16_t
device->buttons = 0; device->buttons = 0;
pressed_keys = device->data[7] | (device->data[6] << 8) | pressed_keys = device->data[7] | (device->data[6] << 8);
(((device->data[7] & 0x30) == 0x30) ? (1 << 16) : 0); /* SELECT+START = MENU TOGGLE */
for (i = 0; i < 17; i ++) for (i = 0; i < 16; i ++)
if (button_mapping[i] != NO_BTN) if (button_mapping[i] != NO_BTN)
device->buttons |= (pressed_keys & (1 << i)) ? (UINT64_C(1) << button_mapping[i]) : 0; device->buttons |= (pressed_keys & (1 << i)) ? (1 << button_mapping[i]) : 0;
} }
static void hidpad_snesusb_set_rumble(void *data, static void hidpad_snesusb_set_rumble(void *data,

View File

@ -25,6 +25,7 @@
#include <retro_timers.h> #include <retro_timers.h>
#include "joypad_connection.h" #include "joypad_connection.h"
#include "../input_defines.h"
/* wiimote state flags*/ /* wiimote state flags*/
#define WIIMOTE_STATE_DEV_FOUND 0x0001 #define WIIMOTE_STATE_DEV_FOUND 0x0001
@ -671,12 +672,15 @@ static int16_t hidpad_wii_get_axis(void *data, unsigned axis)
return 0; return 0;
} }
static uint64_t hidpad_wii_get_buttons(void *data) static void hidpad_wii_get_buttons(void *data, retro_bits_t *state)
{ {
struct connect_wii_wiimote_t* device = (struct connect_wii_wiimote_t*)data; struct connect_wii_wiimote_t* device = (struct connect_wii_wiimote_t*)data;
if (!device) if ( device )
return 0; {
return device->btns | (device->exp.cc.classic.btns << 16); uint32_t b;
b = device->btns | (device->exp.cc.classic.btns << 16); /*broken? this doesn't match retropad!!*/
RARCH_INPUT_STATE_COPY32_PTR(state, b);
}
} }
static void hidpad_wii_packet_handler(void *data, static void hidpad_wii_packet_handler(void *data,

View File

@ -20,6 +20,7 @@
#include <boolean.h> #include <boolean.h>
#include "joypad_connection.h" #include "joypad_connection.h"
#include "../input_defines.h"
struct hidpad_wiiugca_data struct hidpad_wiiugca_data
{ {
@ -27,7 +28,7 @@ struct hidpad_wiiugca_data
send_control_t send_control; send_control_t send_control;
uint8_t data[64]; uint8_t data[64];
uint32_t slot; uint32_t slot;
uint64_t buttons; uint32_t buttons;
}; };
static void* hidpad_wiiugca_init(void *data, uint32_t slot, send_control_t ptr) static void* hidpad_wiiugca_init(void *data, uint32_t slot, send_control_t ptr)
@ -62,12 +63,14 @@ static void hidpad_wiiugca_deinit(void *data)
free(device); free(device);
} }
static uint64_t hidpad_wiiugca_get_buttons(void *data) static void hidpad_wiiugca_get_buttons(void *data, retro_bits_t *state)
{ {
struct hidpad_wiiugca_data *device = (struct hidpad_wiiugca_data*)data; struct hidpad_wiiugca_data *device = (struct hidpad_wiiugca_data*)data;
if (!device) if ( device ) {
return 0; RARCH_INPUT_STATE_COPY16_PTR(state, device->buttons);
return device->buttons; } else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t hidpad_wiiugca_get_axis(void *data, unsigned axis) static int16_t hidpad_wiiugca_get_axis(void *data, unsigned axis)

View File

@ -118,35 +118,65 @@ static void hidpad_wiiupro_deinit(void *data)
free(device); free(device);
} }
static uint64_t hidpad_wiiupro_get_buttons(void *data) static void hidpad_wiiupro_get_buttons(void *data, retro_bits_t *state)
{ {
uint64_t buttonstate = 0;
struct hidpad_wiiupro_data *device = (struct hidpad_wiiupro_data*)data; struct hidpad_wiiupro_data *device = (struct hidpad_wiiupro_data*)data;
struct wiiupro *rpt = device ? (struct wiiupro*)&device->data : NULL; struct wiiupro *rpt = device ? (struct wiiupro*)&device->data : NULL;
if (!device || !rpt) if (!device || !rpt)
return 0; return;
buttonstate |= (rpt->btn.r3 ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R3) : 0); if ( rpt->btn.r3 ) {
buttonstate |= (rpt->btn.l3 ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L3) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_R3 );
buttonstate |= (rpt->btn.plus ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0); }
buttonstate |= (rpt->btn.minus ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0); if ( rpt->btn.l3 ) {
buttonstate |= (rpt->btn.zr ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_L3 );
buttonstate |= (rpt->btn.zl ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0); }
buttonstate |= (rpt->btn.r ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0); if ( rpt->btn.plus ) {
buttonstate |= (rpt->btn.l ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_START );
}
buttonstate |= (rpt->btn.x ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0); if ( rpt->btn.minus ) {
buttonstate |= (rpt->btn.a ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_SELECT );
buttonstate |= (rpt->btn.b ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0); }
buttonstate |= (rpt->btn.y ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0); if ( rpt->btn.zr ) {
buttonstate |= (rpt->btn.left ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_R2 );
buttonstate |= (rpt->btn.right ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0); }
buttonstate |= (rpt->btn.up ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0); if ( rpt->btn.zl ) {
buttonstate |= (rpt->btn.down ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0); RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_L2 );
buttonstate |= (rpt->btn.home ? (UINT64_C(1) << RARCH_MENU_TOGGLE) : 0); }
if ( rpt->btn.r ) {
return buttonstate; RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_R );
}
if ( rpt->btn.l ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_L );
}
if ( rpt->btn.x ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_X );
}
if ( rpt->btn.a ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_A );
}
if ( rpt->btn.b ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_B );
}
if ( rpt->btn.y ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_Y );
}
if ( rpt->btn.left ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_LEFT );
}
if ( rpt->btn.down ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_DOWN );
}
if ( rpt->btn.right ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_RIGHT );
}
if ( rpt->btn.up ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RETRO_DEVICE_ID_JOYPAD_UP );
}
if ( rpt->btn.home ) {
RARCH_INPUT_STATE_BIT_SET_PTR( state, RARCH_MENU_TOGGLE );
}
} }
static int16_t hidpad_wiiupro_get_axis(void *data, unsigned axis) static int16_t hidpad_wiiupro_get_axis(void *data, unsigned axis)

View File

@ -173,11 +173,13 @@ void pad_connection_packet(joypad_connection_t *joyconn, uint32_t pad,
joyconn->iface->packet_handler(joyconn->data, data, length); joyconn->iface->packet_handler(joyconn->data, data, length);
} }
uint64_t pad_connection_get_buttons(joypad_connection_t *joyconn, unsigned pad) void pad_connection_get_buttons(joypad_connection_t *joyconn, unsigned pad, retro_bits_t* state)
{ {
if (!joyconn->iface) if (joyconn->iface) {
return 0; joyconn->iface->get_buttons(joyconn->data, state);
return joyconn->iface->get_buttons(joyconn->data); } else {
RARCH_INPUT_STATE_CLEAR_PTR( state );
}
} }
int16_t pad_connection_get_axis(joypad_connection_t *joyconn, int16_t pad_connection_get_axis(joypad_connection_t *joyconn,

View File

@ -21,6 +21,7 @@
#include <stddef.h> #include <stddef.h>
#include <libretro.h> #include <libretro.h>
#include <retro_miscellaneous.h>
typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size); typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size);
@ -38,7 +39,7 @@ typedef struct pad_connection_interface
void (*packet_handler)(void* device, uint8_t *packet, uint16_t size); void (*packet_handler)(void* device, uint8_t *packet, uint16_t size);
void (*set_rumble)(void* device, enum retro_rumble_effect effect, void (*set_rumble)(void* device, enum retro_rumble_effect effect,
uint16_t strength); uint16_t strength);
uint64_t (*get_buttons)(void *data); void (*get_buttons)(void *data, retro_bits_t *state);
int16_t (*get_axis)(void *data, unsigned axis); int16_t (*get_axis)(void *data, unsigned axis);
const char* (*get_name)(void *data); const char* (*get_name)(void *data);
} pad_connection_interface_t; } pad_connection_interface_t;
@ -69,8 +70,8 @@ void pad_connection_pad_deinit(joypad_connection_t *joyconn,
void pad_connection_packet(joypad_connection_t *joyconn, void pad_connection_packet(joypad_connection_t *joyconn,
uint32_t idx, uint8_t* data, uint32_t length); uint32_t idx, uint8_t* data, uint32_t length);
uint64_t pad_connection_get_buttons(joypad_connection_t *joyconn, void pad_connection_get_buttons(joypad_connection_t *joyconn,
unsigned idx); unsigned idx, retro_bits_t* state);
int16_t pad_connection_get_axis(joypad_connection_t *joyconn, int16_t pad_connection_get_axis(joypad_connection_t *joyconn,
unsigned idx, unsigned i); unsigned idx, unsigned i);

View File

@ -1363,26 +1363,30 @@ static const char *btstack_hid_joypad_name(void *data, unsigned pad)
return NULL; return NULL;
} }
static uint64_t btstack_hid_joypad_get_buttons(void *data, unsigned port) static void btstack_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state)
{ {
btstack_hid_t *hid = (btstack_hid_t*)data; btstack_hid_t *hid = (btstack_hid_t*)data;
if (hid) if ( hid ) {
return pad_connection_get_buttons(&hid->slots[port], port); pad_connection_get_buttons(&hid->slots[port], port, state);
return 0; } else {
RARCH_INPUT_STATE_CLEAR_PTR( state );
}
} }
static bool btstack_hid_joypad_button(void *data, unsigned port, uint16_t joykey) static bool btstack_hid_joypad_button(void *data, unsigned port, uint16_t joykey)
{ {
uint64_t buttons = btstack_hid_joypad_get_buttons(data, port); retro_bits_t buttons;
btstack_hid_joypad_get_buttons(data, port, &buttons);
/* Check hat. */ /* Check hat. */
if (GET_HAT_DIR(joykey)) if (GET_HAT_DIR(joykey))
return false; return false;
/* Check the button. */ /* Check the button. */
if ((port < MAX_USERS) && (joykey < 32)) if ((port < MAX_USERS) && (joykey < 32))
return ((buttons & (1 << joykey)) != 0); return ( RARCH_INPUT_STATE_BIT_GET( buttons, joykey ) != 0 );
return false;
return false;
} }
static bool btstack_hid_joypad_rumble(void *data, unsigned pad, static bool btstack_hid_joypad_rumble(void *data, unsigned pad,

View File

@ -108,21 +108,24 @@ static const char *iohidmanager_hid_joypad_name(void *data, unsigned pad)
return NULL; return NULL;
} }
static uint64_t iohidmanager_hid_joypad_get_buttons(void *data, unsigned port) static void iohidmanager_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state)
{ {
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data; iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data;
if (hid) if (hid) {
return pad_connection_get_buttons(&hid->slots[port], port); return pad_connection_get_buttons(&hid->slots[port], port, state);
return 0; } else {
RARCH_INPUT_STATE_CLEAR_PTR( state );
}
} }
static bool iohidmanager_hid_joypad_button(void *data, static bool iohidmanager_hid_joypad_button(void *data,
unsigned port, uint16_t joykey) unsigned port, uint16_t joykey)
{ {
uint64_t buttons = retro_bits_t buttons;
iohidmanager_hid_joypad_get_buttons(data, port); iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data;
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)data; unsigned hat_dir = GET_HAT_DIR(joykey);
unsigned hat_dir = GET_HAT_DIR(joykey);
iohidmanager_hid_joypad_get_buttons(data, port, &buttons);
/* Check hat. */ /* Check hat. */
if (hat_dir) if (hat_dir)
@ -148,8 +151,9 @@ static bool iohidmanager_hid_joypad_button(void *data,
/* Check the button. */ /* Check the button. */
if ((port < MAX_USERS) && (joykey < 32)) if ((port < MAX_USERS) && (joykey < 32))
return ((buttons & (1 << joykey)) != 0) return (RARCH_INPUT_STATE_BIT_GET( buttons, joykey )) != 0)
|| ((hid->buttons[port] & (1 << joykey)) != 0); || ((hid->buttons[port] & (1 << joykey)) != 0);
return false; return false;
} }

View File

@ -16,11 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef __FreeBSD__
#include <libusb.h>
#else
#include <libusb-1.0/libusb.h> #include <libusb-1.0/libusb.h>
#endif
#include <rthreads/rthreads.h> #include <rthreads/rthreads.h>
#include <compat/strl.h> #include <compat/strl.h>
@ -42,11 +38,7 @@ typedef struct libusb_hid
libusb_context *ctx; libusb_context *ctx;
joypad_connection_t *slots; joypad_connection_t *slots;
sthread_t *poll_thread; sthread_t *poll_thread;
#if defined(__FreeBSD__) && LIBUSB_API_VERSION <= 0x01000102
libusb_hotplug_callback_handle hp;
#else
int hp; /* libusb_hotplug_callback_handle is just int */ int hp; /* libusb_hotplug_callback_handle is just int */
#endif
int quit; int quit;
} libusb_hid_t; } libusb_hid_t;
@ -165,13 +157,7 @@ static void libusb_get_description(struct libusb_device *device,
unsigned i, k; unsigned i, k;
struct libusb_config_descriptor *config; struct libusb_config_descriptor *config;
int desc_ret = libusb_get_config_descriptor(device, 0, &config); libusb_get_config_descriptor(device, 0, &config);
if (desc_ret != 0)
{
RARCH_ERR("Error %d getting libusb config descriptor\n", desc_ret);
return;
}
for (i = 0; i < (int)config->bNumInterfaces; i++) for (i = 0; i < (int)config->bNumInterfaces; i++)
{ {
@ -214,12 +200,11 @@ static void libusb_get_description(struct libusb_device *device,
} }
} }
} }
goto ret; goto ret;
} }
} }
ret: ret:
libusb_free_config_descriptor(config); libusb_free_config_descriptor(config);
} }
@ -441,27 +426,30 @@ static const char *libusb_hid_joypad_name(void *data, unsigned pad)
return NULL; return NULL;
} }
static uint64_t libusb_hid_joypad_get_buttons(void *data, unsigned port) static void libusb_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state)
{ {
libusb_hid_t *hid = (libusb_hid_t*)data; libusb_hid_t *hid = (libusb_hid_t*)data;
if (hid) if (hid) {
return pad_connection_get_buttons(&hid->slots[port], port); return pad_connection_get_buttons(&hid->slots[port], port, state);
return 0; } else {
RARCH_INPUT_STATE_CLEAR_PTR( state );
}
} }
static bool libusb_hid_joypad_button(void *data, static bool libusb_hid_joypad_button(void *data,
unsigned port, uint16_t joykey) unsigned port, uint16_t joykey)
{ {
uint64_t buttons = libusb_hid_joypad_get_buttons(data, port); retro_bits_t buttons;
libusb_hid_joypad_get_buttons(data, port, &buttons);
/* Check hat. */ /* Check hat. */
if (GET_HAT_DIR(joykey)) if (GET_HAT_DIR(joykey))
return false; return false;
/* Check the button. */ /* Check the button. */
if ((port < MAX_USERS) && (joykey < 32)) if ((port < MAX_USERS) && (joykey < 32))
return ((buttons & (1 << joykey)) != 0); return (RARCH_INPUT_STATE_BIT_GET(buttons, joykey) != 0);
return false; return false;
} }
static bool libusb_hid_joypad_rumble(void *data, unsigned pad, static bool libusb_hid_joypad_rumble(void *data, unsigned pad,
@ -517,8 +505,7 @@ static void libusb_hid_free(void *data)
sthread_join(hid->poll_thread); sthread_join(hid->poll_thread);
} }
if (hid->slots) pad_connection_destroy(hid->slots);
pad_connection_destroy(hid->slots);
libusb_hotplug_deregister_callback(hid->ctx, hid->hp); libusb_hotplug_deregister_callback(hid->ctx, hid->hp);
@ -553,14 +540,8 @@ static void *libusb_hid_init(void)
if (ret < 0) if (ret < 0)
goto error; goto error;
#if 0
/* Don't use this for now since it requires a newer API
* version than FreeBSD has, and always returns false on Windows anyway.
* https://github.com/libusb/libusb/issues/86
*/
if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG))
goto error; goto error;
#endif
hid->slots = pad_connection_init(MAX_USERS); hid->slots = pad_connection_init(MAX_USERS);

View File

@ -38,12 +38,12 @@ static const char *null_hid_joypad_name(void *data, unsigned pad)
return NULL; return NULL;
} }
static uint64_t null_hid_joypad_get_buttons(void *data, unsigned port) static void null_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state)
{ {
(void)data; (void)data;
(void)port; (void)port;
return 0; RARCH_INPUT_STATE_CLEAR_PTR(state);
} }
static bool null_hid_joypad_button(void *data, unsigned port, uint16_t joykey) static bool null_hid_joypad_button(void *data, unsigned port, uint16_t joykey)

View File

@ -478,27 +478,31 @@ static bool wiiusb_hid_joypad_query(void *data, unsigned pad)
return pad < MAX_USERS; return pad < MAX_USERS;
} }
static uint64_t wiiusb_hid_joypad_get_buttons(void *data, unsigned port) static void wiiusb_hid_joypad_get_buttons(void *data, unsigned port, retro_bits_t *state)
{ {
wiiusb_hid_t *hid = (wiiusb_hid_t*)data; wiiusb_hid_t *hid = (wiiusb_hid_t*)data;
if (hid) if (hid) {
return pad_connection_get_buttons(&hid->connections[port], port); return pad_connection_get_buttons(&hid->connections[port], port, state);
return 0; } else {
RARCH_INPUT_STATE_CLEAR_PTR( state );
}
} }
static bool wiiusb_hid_joypad_button(void *data, unsigned port, uint16_t joykey) static bool wiiusb_hid_joypad_button(void *data, unsigned port, uint16_t joykey)
{ {
uint64_t buttons = wiiusb_hid_joypad_get_buttons(data, port); retro_bits_t buttons;
/* Check hat. */ wiiusb_hid_joypad_get_buttons(data, port, &buttons);
if (GET_HAT_DIR(joykey))
return false;
/* Check the button. */ /* Check hat. */
if ((port < MAX_USERS) && (joykey < 32)) if (GET_HAT_DIR(joykey))
return ((buttons & (1 << joykey)) != 0); return false;
return false; /* Check the button. */
if ((port < MAX_USERS) && (joykey < 32))
return (RARCH_INPUT_STATE_BIT_GET(buttons, joykey)) != 0);
return false;
} }
static bool wiiusb_hid_joypad_rumble(void *data, unsigned pad, static bool wiiusb_hid_joypad_rumble(void *data, unsigned pad,

View File

@ -31,7 +31,7 @@
#define MAX_PADS 1 #define MAX_PADS 1
#endif #endif
static uint64_t pad_state; static uint32_t pad_state;
static int16_t analog_state[1][2][2]; static int16_t analog_state[1][2][2];
extern uint64_t lifecycle_state; extern uint64_t lifecycle_state;
@ -67,12 +67,16 @@ static bool ctr_joypad_button(unsigned port_num, uint16_t key)
if (port_num >= MAX_PADS) if (port_num >= MAX_PADS)
return false; return false;
return (pad_state & (UINT64_C(1) << key)); return (pad_state & (1 << key));
} }
static uint64_t ctr_joypad_get_buttons(unsigned port_num) static void ctr_joypad_get_buttons(unsigned port_num, retro_bits_t *state)
{ {
return pad_state; if ( port_num < MAX_PADS ) {
RARCH_INPUT_STATE_COPY16_PTR( state, pad_state );
} else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t ctr_joypad_axis(unsigned port_num, uint32_t joyaxis) static int16_t ctr_joypad_axis(unsigned port_num, uint32_t joyaxis)
@ -140,20 +144,20 @@ static void ctr_joypad_poll(void)
hidTouchRead(&state_tmp_touch); hidTouchRead(&state_tmp_touch);
pad_state = 0; pad_state = 0;
pad_state |= (state_tmp & KEY_DLEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; pad_state |= (state_tmp & KEY_DLEFT) ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
pad_state |= (state_tmp & KEY_DDOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; pad_state |= (state_tmp & KEY_DDOWN) ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
pad_state |= (state_tmp & KEY_DRIGHT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; pad_state |= (state_tmp & KEY_DRIGHT) ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
pad_state |= (state_tmp & KEY_DUP) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0; pad_state |= (state_tmp & KEY_DUP) ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
pad_state |= (state_tmp & KEY_START) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0; pad_state |= (state_tmp & KEY_START) ? (1 << RETRO_DEVICE_ID_JOYPAD_START) : 0;
pad_state |= (state_tmp & KEY_SELECT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0; pad_state |= (state_tmp & KEY_SELECT) ? (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
pad_state |= (state_tmp & KEY_X) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0; pad_state |= (state_tmp & KEY_X) ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0;
pad_state |= (state_tmp & KEY_Y) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0; pad_state |= (state_tmp & KEY_Y) ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
pad_state |= (state_tmp & KEY_B) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0; pad_state |= (state_tmp & KEY_B) ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0;
pad_state |= (state_tmp & KEY_A) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0; pad_state |= (state_tmp & KEY_A) ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0;
pad_state |= (state_tmp & KEY_R) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0; pad_state |= (state_tmp & KEY_R) ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0;
pad_state |= (state_tmp & KEY_L) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0; pad_state |= (state_tmp & KEY_L) ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0;
pad_state |= (state_tmp & KEY_ZR) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0; pad_state |= (state_tmp & KEY_ZR) ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
pad_state |= (state_tmp & KEY_ZL) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0; pad_state |= (state_tmp & KEY_ZL) ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = ctr_joypad_fix_range(state_tmp_left_analog.dx); analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = ctr_joypad_fix_range(state_tmp_left_analog.dx);
analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = -ctr_joypad_fix_range(state_tmp_left_analog.dy); analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = -ctr_joypad_fix_range(state_tmp_left_analog.dy);

View File

@ -162,9 +162,13 @@ static bool gx_joypad_button(unsigned port, uint16_t key)
return (pad_state[port] & (UINT64_C(1) << key)); return (pad_state[port] & (UINT64_C(1) << key));
} }
static uint64_t gx_joypad_get_buttons(unsigned port) static void gx_joypad_get_buttons(unsigned port, retro_bits_t *state)
{ {
return pad_state[port]; if ( port < MAX_PADS ) {
RARCH_INPUT_STATE_COPY16_PTR( state, pad_state[port] );
} else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t gx_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t gx_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -55,11 +55,13 @@ static bool hid_joypad_button(unsigned port, uint16_t joykey)
return false; return false;
} }
static uint64_t hid_joypad_get_buttons(unsigned port) static void hid_joypad_get_buttons(unsigned port, retro_bits_t *state)
{ {
if (generic_hid && generic_hid->get_buttons) if (generic_hid && generic_hid->get_buttons) {
return generic_hid->get_buttons((void*)hid_driver_get_data(), port); generic_hid->get_buttons((void*)hid_driver_get_data(), port, state);
return 0; } else {
RARCH_INPUT_STATE_CLEAR_PTR( state );
}
} }
static int16_t hid_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t hid_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -41,7 +41,7 @@
struct linuxraw_joypad struct linuxraw_joypad
{ {
int fd; int fd;
uint64_t buttons; uint32_t buttons;
int16_t axes[NUM_AXES]; int16_t axes[NUM_AXES];
char *ident; char *ident;
@ -66,9 +66,9 @@ static void linuxraw_poll_pad(struct linuxraw_joypad *pad)
if (event.number < NUM_BUTTONS) if (event.number < NUM_BUTTONS)
{ {
if (event.value) if (event.value)
BIT64_SET(pad->buttons, event.number); BIT32_SET(pad->buttons, event.number);
else else
BIT64_CLEAR(pad->buttons, event.number); BIT32_CLEAR(pad->buttons, event.number);
} }
break; break;
@ -323,15 +323,17 @@ static bool linuxraw_joypad_button(unsigned port, uint16_t joykey)
const struct linuxraw_joypad *pad = (const struct linuxraw_joypad*) const struct linuxraw_joypad *pad = (const struct linuxraw_joypad*)
&linuxraw_pads[port]; &linuxraw_pads[port];
return joykey < NUM_BUTTONS && BIT64_GET(pad->buttons, joykey); return joykey < NUM_BUTTONS && BIT32_GET(pad->buttons, joykey);
} }
static uint64_t linuxraw_joypad_get_buttons(unsigned port) static void linuxraw_joypad_get_buttons(unsigned port, retro_bits_t *state)
{ {
const struct linuxraw_joypad *pad = (const struct linuxraw_joypad*) const struct linuxraw_joypad *pad = (const struct linuxraw_joypad*)&linuxraw_pads[port];
&linuxraw_pads[port]; if ( pad ) {
RARCH_INPUT_STATE_COPY16_PTR(state, pad->buttons);
return pad->buttons; } else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t linuxraw_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t linuxraw_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -221,9 +221,9 @@ static bool apple_gamecontroller_joypad_button(unsigned port, uint16_t joykey)
return false; return false;
} }
static uint64_t apple_gamecontroller_joypad_get_buttons(unsigned port) static void apple_gamecontroller_joypad_get_buttons(unsigned port, retro_bits_t *state)
{ {
return mfi_buttons[port]; RARCH_INPUT_STATE_COPY16_PTR(state, mfi_buttons[port]);
} }
static int16_t apple_gamecontroller_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t apple_gamecontroller_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -37,9 +37,9 @@ static bool null_joypad_button(unsigned port_num, uint16_t joykey)
return false; return false;
} }
static uint64_t null_joypad_get_buttons(unsigned port_num) static void null_joypad_get_buttons(unsigned port_num, retro_bits_t *state)
{ {
return 0; RARCH_INPUT_STATE_CLEAR_PTR( state );
} }
static int16_t null_joypad_axis(unsigned port_num, uint32_t joyaxis) static int16_t null_joypad_axis(unsigned port_num, uint32_t joyaxis)

View File

@ -40,7 +40,7 @@
struct parport_joypad struct parport_joypad
{ {
int fd; int fd;
uint64_t buttons; uint32_t buttons;
bool button_enable[PARPORT_NUM_BUTTONS]; bool button_enable[PARPORT_NUM_BUTTONS];
char saved_data; char saved_data;
char saved_control; char saved_control;
@ -97,22 +97,22 @@ static void parport_poll_pad(struct parport_joypad *pad)
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
if (!(data & UINT8_C(1 << i)) && pad->button_enable[i]) if (!(data & UINT8_C(1 << i)) && pad->button_enable[i])
BIT64_SET(pad->buttons, i); BIT32_SET(pad->buttons, i);
else else
BIT64_CLEAR(pad->buttons, i); BIT32_CLEAR(pad->buttons, i);
} }
for (i = 3; i < 8; i++) for (i = 3; i < 8; i++)
{ {
if (!(status & UINT8_C(1 << i)) && pad->button_enable[i + 5]) if (!(status & UINT8_C(1 << i)) && pad->button_enable[i + 5])
BIT64_SET(pad->buttons, i + 5); BIT32_SET(pad->buttons, i + 5);
else else
BIT64_CLEAR(pad->buttons, i + 5); BIT32_CLEAR(pad->buttons, i + 5);
} }
if (BIT64_GET(pad->buttons, 12) && pad->button_enable[12]) if (BIT32_GET(pad->buttons, 12) && pad->button_enable[12])
BIT64_CLEAR(pad->buttons, 12); BIT32_CLEAR(pad->buttons, 12);
else else
BIT64_SET(pad->buttons, 12); BIT32_SET(pad->buttons, 12);
} }
static bool parport_joypad_init_pad(const char *path, struct parport_joypad *pad) static bool parport_joypad_init_pad(const char *path, struct parport_joypad *pad)
@ -268,7 +268,7 @@ static bool parport_joypad_init(void *data)
for (j = 0; j < PARPORT_NUM_BUTTONS; j++) for (j = 0; j < PARPORT_NUM_BUTTONS; j++)
{ {
if (!(BIT64_GET(pad->buttons, j))) if (!(BIT32_GET(pad->buttons, j)))
{ {
pad->button_enable[j] = true; pad->button_enable[j] = true;
found_enabled_button = true; found_enabled_button = true;
@ -337,13 +337,17 @@ static void parport_joypad_destroy(void)
static bool parport_joypad_button(unsigned port, uint16_t joykey) static bool parport_joypad_button(unsigned port, uint16_t joykey)
{ {
const struct parport_joypad *pad = (const struct parport_joypad*)&parport_pads[port]; const struct parport_joypad *pad = (const struct parport_joypad*)&parport_pads[port];
return joykey < PARPORT_NUM_BUTTONS && BIT64_GET(pad->buttons, joykey); return joykey < PARPORT_NUM_BUTTONS && BIT32_GET(pad->buttons, joykey);
} }
static uint64_t parport_joypad_get_buttons(unsigned port) static void parport_joypad_get_buttons(unsigned port, retro_bits_t *state)
{ {
const struct parport_joypad *pad = (const struct parport_joypad*)&parport_pads[port]; const struct parport_joypad *pad = (const struct parport_joypad*)&parport_pads[port];
return pad->buttons; if ( pad ) {
RARCH_INPUT_STATE_COPY16_PTR(state, pad->buttons);
} else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t parport_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t parport_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -68,9 +68,13 @@ static bool ps3_joypad_button(unsigned port_num, uint16_t joykey)
return pad_state[port_num] & (UINT64_C(1) << joykey); return pad_state[port_num] & (UINT64_C(1) << joykey);
} }
static uint64_t ps3_joypad_get_buttons(unsigned port_num) static void ps3_joypad_get_buttons(unsigned port_num, retro_bits_t *state)
{ {
return pad_state[port_num]; if ( port_num < MAX_PADS ) {
RARCH_INPUT_STATE_COPY16_PTR( state, pad_state[port_num] );
} else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t ps3_joypad_axis(unsigned port_num, uint32_t joyaxis) static int16_t ps3_joypad_axis(unsigned port_num, uint32_t joyaxis)

View File

@ -124,9 +124,13 @@ static bool psp_joypad_button(unsigned port_num, uint16_t key)
return (pad_state[port_num] & (UINT64_C(1) << key)); return (pad_state[port_num] & (UINT64_C(1) << key));
} }
static uint64_t psp_joypad_get_buttons(unsigned port_num) static void psp_joypad_get_buttons(unsigned port_num, retro_bits_t *state)
{ {
return pad_state[port_num]; if ( port_num < PSP_MAX_PADS ) {
RARCH_INPUT_STATE_COPY16_PTR( state, pad_state[port_num] );
} else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t psp_joypad_axis(unsigned port_num, uint32_t joyaxis) static int16_t psp_joypad_axis(unsigned port_num, uint32_t joyaxis)

View File

@ -604,10 +604,14 @@ static bool udev_joypad_button(unsigned port, uint16_t joykey)
return joykey < UDEV_NUM_BUTTONS && BIT64_GET(pad->buttons, joykey); return joykey < UDEV_NUM_BUTTONS && BIT64_GET(pad->buttons, joykey);
} }
static uint64_t udev_joypad_get_buttons(unsigned port) static void udev_joypad_get_buttons(unsigned port, retro_bits_t *state)
{ {
const struct udev_joypad *pad = (const struct udev_joypad*)&udev_pads[port]; const struct udev_joypad *pad = (const struct udev_joypad*)&udev_pads[port];
return pad->buttons; if ( pad ) {
RARCH_INPUT_STATE_COPY16_PTR( state, pad->buttons );
} else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t udev_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t udev_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -122,9 +122,13 @@ static bool wiiu_joypad_button(unsigned port_num, uint16_t key)
return (pad_state[port_num] & (UINT64_C(1) << key)); return (pad_state[port_num] & (UINT64_C(1) << key));
} }
static uint64_t wiiu_joypad_get_buttons(unsigned port_num) static void wiiu_joypad_get_buttons(unsigned port_num, retro_bits_t *state)
{ {
return pad_state[port_num]; if ( port_num < MAX_PADS ) {
RARCH_INPUT_STATE_COPY16_PTR( state, pad_state[port_num] );
} else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
static int16_t wiiu_joypad_axis(unsigned port_num, uint32_t joyaxis) static int16_t wiiu_joypad_axis(unsigned port_num, uint32_t joyaxis)

View File

@ -19,7 +19,7 @@
#include "../input_driver.h" #include "../input_driver.h"
#include "../../tasks/tasks_internal.h" #include "../../tasks/tasks_internal.h"
static uint64_t pad_state[MAX_PADS]; static uint32_t pad_state[MAX_PADS];
static int16_t analog_state[MAX_PADS][2][2]; static int16_t analog_state[MAX_PADS][2][2];
#ifdef _XBOX1 #ifdef _XBOX1
static HANDLE gamepads[MAX_PADS]; static HANDLE gamepads[MAX_PADS];
@ -73,12 +73,16 @@ static bool xdk_joypad_button(unsigned port_num, uint16_t joykey)
if (port_num >= MAX_PADS) if (port_num >= MAX_PADS)
return false; return false;
return pad_state[port_num] & (UINT64_C(1) << joykey); return pad_state[port_num] & (1 << joykey);
} }
static uint64_t xdk_joypad_get_buttons(unsigned port_num) static void xdk_joypad_get_buttons(unsigned port_num, retro_bits_t *state)
{ {
return pad_state[port_num]; if ( port_num < MAX_PADS ) {
RARCH_INPUT_STATE_COPY16_PTR( state, pad_state[port_num] );
} else {
RARCH_INPUT_STATE_CLEAR_PTR(state);
}
} }
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

@ -18,6 +18,7 @@
#define __INPUT_DEFINES__H #define __INPUT_DEFINES__H
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <retro_common_api.h> #include <retro_common_api.h>
@ -157,6 +158,30 @@ enum analog_dpad_mode
#define GET_HAT_DIR(x) (x & HAT_MASK) #define GET_HAT_DIR(x) (x & HAT_MASK)
#define GET_HAT(x) (x & (~HAT_MASK)) #define GET_HAT(x) (x & (~HAT_MASK))
#define RARCH_INPUT_STATE_BIT_SET(a,bit) ((a).data [((bit) >> 5)] |= (1 << ((bit) & 31)))
#define RARCH_INPUT_STATE_BIT_SET_PTR(a,bit) ((a)->data[((bit) >> 5)] |= (1 << ((bit) & 31)))
#define RARCH_INPUT_STATE_BIT_GET(a,bit) ((a).data [((bit) >> 5)] & (1 << ((bit) & 31)))
#define RARCH_INPUT_STATE_BIT_GET_PTR(a,bit) ((a)->data[((bit) >> 5)] & (1 << ((bit) & 31)))
#define RARCH_INPUT_STATE_CLEAR(a) memset(&a, 0, sizeof(a));
#define RARCH_INPUT_STATE_CLEAR_PTR(a) memset(a, 0, sizeof(retro_bits_t));
#define RARCH_INPUT_STATE_ANY_SET(a) ( ((a).data[0])||((a).data[1])||((a).data[2])||((a).data[3])|| \
((a).data[4])||((a).data[5])||((a).data[6])||((a).data[7]) )
#define RARCH_INPUT_STATE_ANY_SET_PTR(a) ( ((a)->data[0])||((a)->data[1])||((a)->data[2])||((a)->data[3])|| \
((a)->data[4])||((a)->data[5])||((a)->data[6])||((a)->data[7]) )
#define RARCH_INPUT_STATE_CLEAR_BITS(a,b) \
((a).data[0])&=(~((b).data[0])); \
((a).data[1])&=(~((b).data[1])); \
((a).data[2])&=(~((b).data[2])); \
((a).data[3])&=(~((b).data[3])); \
((a).data[4])&=(~((b).data[4])); \
((a).data[5])&=(~((b).data[5])); \
((a).data[6])&=(~((b).data[6])); \
((a).data[7])&=(~((b).data[7]));
#define RARCH_INPUT_STATE_COPY16_PTR(a,bits) {memset(a, 0, sizeof(retro_bits_t));((a)->data[0] = (bits)&0xffff);}
#define RARCH_INPUT_STATE_COPY32_PTR(a,bits) {memset(a, 0, sizeof(retro_bits_t));((a)->data[0] = (bits));}
RETRO_END_DECLS RETRO_END_DECLS
#endif #endif

View File

@ -174,7 +174,7 @@ struct rarch_joypad_driver
bool (*query_pad)(unsigned); bool (*query_pad)(unsigned);
void (*destroy)(void); void (*destroy)(void);
bool (*button)(unsigned, uint16_t); bool (*button)(unsigned, uint16_t);
uint64_t (*get_buttons)(unsigned); void (*get_buttons)(unsigned, retro_bits_t *);
int16_t (*axis)(unsigned, uint32_t); int16_t (*axis)(unsigned, uint32_t);
void (*poll)(void); void (*poll)(void);
bool (*set_rumble)(unsigned, enum retro_rumble_effect, uint16_t); bool (*set_rumble)(unsigned, enum retro_rumble_effect, uint16_t);
@ -189,7 +189,7 @@ struct hid_driver
bool (*query_pad)(void *, unsigned); bool (*query_pad)(void *, unsigned);
void (*free)(void *); void (*free)(void *);
bool (*button)(void *, unsigned, uint16_t); bool (*button)(void *, unsigned, uint16_t);
uint64_t (*get_buttons)(void *, unsigned); void (*get_buttons)(void *, unsigned, retro_bits_t *);
int16_t (*axis)(void *, unsigned, uint32_t); int16_t (*axis)(void *, unsigned, uint32_t);
void (*poll)(void *); void (*poll)(void *);
bool (*set_rumble)(void *, unsigned, enum retro_rumble_effect, uint16_t); bool (*set_rumble)(void *, unsigned, enum retro_rumble_effect, uint16_t);
@ -336,26 +336,6 @@ void input_poll(void);
int16_t input_state(unsigned port, unsigned device, int16_t input_state(unsigned port, unsigned device,
unsigned idx, unsigned id); unsigned idx, unsigned id);
#define RARCH_INPUT_STATE_BIT_SET(a,bit) ((a).data [((bit) >> 5)] |= (1 << ((bit) & 31)))
#define RARCH_INPUT_STATE_BIT_SET_PTR(a,bit) ((a)->data[((bit) >> 5)] |= (1 << ((bit) & 31)))
#define RARCH_INPUT_STATE_BIT_GET(a,bit) ((a).data [((bit) >> 5)] & (1 << ((bit) & 31)))
#define RARCH_INPUT_STATE_BIT_GET_PTR(a,bit) ((a)->data[((bit) >> 5)] & (1 << ((bit) & 31)))
#define RARCH_INPUT_STATE_CLEAR(a) memset(&a, 0, sizeof(a));
#define RARCH_INPUT_STATE_CLEAR_PTR(a) memset(a, 0, sizeof(retro_bits_t));
#define RARCH_INPUT_STATE_ANY_SET(a) ( ((a).data[0])||((a).data[1])||((a).data[2])||((a).data[3])|| \
((a).data[4])||((a).data[5])||((a).data[6])||((a).data[7]) )
#define RARCH_INPUT_STATE_ANY_SET_PTR(a) ( ((a)->data[0])||((a)->data[1])||((a)->data[2])||((a)->data[3])|| \
((a)->data[4])||((a)->data[5])||((a)->data[6])||((a)->data[7]) )
#define RARCH_INPUT_STATE_CLEAR_BITS(a,b) \
((a).data[0])&=(~((b).data[0])); \
((a).data[1])&=(~((b).data[1])); \
((a).data[2])&=(~((b).data[2])); \
((a).data[3])&=(~((b).data[3])); \
((a).data[4])&=(~((b).data[4])); \
((a).data[5])&=(~((b).data[5])); \
((a).data[6])&=(~((b).data[6])); \
((a).data[7])&=(~((b).data[7]));
void input_keys_pressed(void *data, retro_bits_t* new_state); void input_keys_pressed(void *data, retro_bits_t* new_state);
#ifdef HAVE_MENU #ifdef HAVE_MENU