Add get_buttons callback

This commit is contained in:
twinaphex 2015-02-15 01:57:29 +01:00
parent 207181135c
commit 738d70d2f8
19 changed files with 130 additions and 47 deletions

View File

@ -27,7 +27,7 @@ struct hidpad_ps3_data
send_control_t send_control;
uint8_t data[512];
uint32_t slot;
uint32_t buttons;
uint64_t buttons;
bool have_led;
uint16_t motors[2];
};
@ -96,7 +96,7 @@ static void hidpad_ps3_deinit(void *data)
free(device);
}
static uint32_t hidpad_ps3_get_buttons(void *data)
static uint64_t hidpad_ps3_get_buttons(void *data)
{
struct hidpad_ps3_data *device = (struct hidpad_ps3_data*)data;
if (!device)

View File

@ -521,7 +521,7 @@ static int16_t hidpad_wii_get_axis(void *data, unsigned axis)
return 0;
}
static uint32_t hidpad_wii_get_buttons(void *data)
static uint64_t hidpad_wii_get_buttons(void *data)
{
struct wiimote_t* device = (struct wiimote_t*)data;
if (!device)

View File

@ -136,7 +136,7 @@ void pad_connection_packet(joypad_connection_t *s, uint32_t pad,
s->iface->packet_handler(s->data, data, length);
}
uint32_t pad_connection_get_buttons(joypad_connection_t *s, unsigned pad)
uint64_t pad_connection_get_buttons(joypad_connection_t *s, unsigned pad)
{
if (!s->iface)
return 0;

View File

@ -30,7 +30,7 @@ typedef struct pad_connection_interface
void (*packet_handler)(void* device, uint8_t *packet, uint16_t size);
void (*set_rumble)(void* device, enum retro_rumble_effect effect,
uint16_t strength);
uint32_t (*get_buttons)(void *data);
uint64_t (*get_buttons)(void *data);
int16_t (*get_axis)(void *data, unsigned axis);
} pad_connection_interface_t;
@ -61,7 +61,7 @@ void pad_connection_pad_deinit(joypad_connection_t *joyconn,
void pad_connection_packet(joypad_connection_t *joyconn,
unsigned idx, uint8_t* data, uint32_t length);
uint32_t pad_connection_get_buttons(joypad_connection_t *joyconn,
uint64_t pad_connection_get_buttons(joypad_connection_t *joyconn,
unsigned idx);
int16_t pad_connection_get_axis(joypad_connection_t *joyconn,

View File

@ -139,6 +139,7 @@ rarch_joypad_driver_t android_joypad = {
android_joypad_query_pad,
android_joypad_destroy,
android_joypad_button,
NULL,
android_joypad_axis,
android_joypad_poll,
NULL,

View File

@ -106,9 +106,9 @@ static void hid_device_input_callback(void* context, IOReturn result,
unsigned id = use - 1;
if (state)
BIT32_SET(apple->buttons[connection->slot], id);
BIT64_SET(apple->buttons[connection->slot], id);
else
BIT32_CLEAR(apple->buttons[connection->slot], id);
BIT64_CLEAR(apple->buttons[connection->slot], id);
}
break;
}
@ -284,7 +284,7 @@ static void apple_joypad_destroy(void)
static bool apple_joypad_button(unsigned port, uint16_t joykey)
{
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
uint32_t buttons = pad_connection_get_buttons(&slots[port], port);
uint64_t buttons = pad_connection_get_buttons(&slots[port], port);
if (!apple || joykey == NO_BTN)
return false;
@ -300,6 +300,11 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey)
return false;
}
static uint64_t apple_joypad_get_buttons(unsigned port)
{
return pad_connection_get_buttons(&slots[port], port);
}
static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis)
{
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
@ -352,6 +357,7 @@ rarch_joypad_driver_t apple_hid_joypad = {
apple_joypad_query_pad,
apple_joypad_destroy,
apple_joypad_button,
apple_joypad_get_buttons,
apple_joypad_axis,
apple_joypad_poll,
apple_joypad_rumble,

View File

@ -49,7 +49,7 @@ static void apple_joypad_destroy(void)
static bool apple_joypad_button(unsigned port, uint16_t joykey)
{
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
uint32_t buttons = pad_connection_get_buttons(&slots[port], port);
uint64_t buttons = pad_connection_get_buttons(&slots[port], port);
if (!apple || joykey == NO_BTN)
return false;
@ -63,6 +63,11 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey)
return false;
}
static uint64_t apple_joypad_get_buttons(unsigned port)
{
return pad_connection_get_buttons(&slots[port], port);
}
static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis)
{
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
@ -111,6 +116,7 @@ rarch_joypad_driver_t apple_ios_joypad = {
apple_joypad_query_pad,
apple_joypad_destroy,
apple_joypad_button,
apple_joypad_get_buttons,
apple_joypad_axis,
apple_joypad_poll,
apple_joypad_rumble,

View File

@ -246,6 +246,11 @@ static bool gx_joypad_button(unsigned port, uint16_t joykey)
return pad_state[port] & (1ULL << joykey);
}
static uint64_t gx_joypad_get_buttons(unsigned port)
{
return pad_state[port];
}
static int16_t gx_joypad_axis(unsigned port, uint32_t joyaxis)
{
int val = 0, axis = -1;
@ -621,6 +626,7 @@ rarch_joypad_driver_t gx_joypad = {
gx_joypad_query_pad,
gx_joypad_destroy,
gx_joypad_button,
gx_joypad_get_buttons,
gx_joypad_axis,
gx_joypad_poll,
NULL,

View File

@ -34,7 +34,7 @@
struct linuxraw_joypad
{
int fd;
uint32_t buttons;
uint64_t buttons;
int16_t axes[NUM_AXES];
char *ident;
@ -59,9 +59,9 @@ static void poll_pad(struct linuxraw_joypad *pad)
if (event.number < NUM_BUTTONS)
{
if (event.value)
BIT32_SET(pad->buttons, event.number);
BIT64_SET(pad->buttons, event.number);
else
BIT32_CLEAR(pad->buttons, event.number);
BIT64_CLEAR(pad->buttons, event.number);
}
break;
@ -291,7 +291,15 @@ static bool linuxraw_joypad_button(unsigned port, uint16_t joykey)
const struct linuxraw_joypad *pad = (const struct linuxraw_joypad*)&linuxraw_pads[port];
if (!pad)
return false;
return joykey < NUM_BUTTONS && BIT32_GET(pad->buttons, joykey);
return joykey < NUM_BUTTONS && BIT64_GET(pad->buttons, joykey);
}
static uint64_t linuxraw_joypad_get_buttons(unsigned port)
{
const struct linuxraw_joypad *pad = (const struct linuxraw_joypad*)&linuxraw_pads[port];
if (!pad)
return 0;
return pad->buttons;
}
static int16_t linuxraw_joypad_axis(unsigned port, uint32_t joyaxis)
@ -339,6 +347,7 @@ rarch_joypad_driver_t linuxraw_joypad = {
linuxraw_joypad_query_pad,
linuxraw_joypad_destroy,
linuxraw_joypad_button,
linuxraw_joypad_get_buttons,
linuxraw_joypad_axis,
linuxraw_joypad_poll,
NULL,

View File

@ -35,6 +35,11 @@ static bool null_joypad_button(unsigned port_num, uint16_t joykey)
return false;
}
static uint64_t null_joypad_get_buttons(unsigned port_num)
{
return 0;
}
static int16_t null_joypad_axis(unsigned port_num, uint32_t joyaxis)
{
return 0;
@ -59,6 +64,7 @@ rarch_joypad_driver_t null_joypad = {
null_joypad_query_pad,
null_joypad_destroy,
null_joypad_button,
null_joypad_get_buttons,
null_joypad_axis,
null_joypad_poll,
NULL,

View File

@ -33,7 +33,7 @@
struct parport_joypad
{
int fd;
uint32_t buttons;
uint64_t buttons;
bool button_enable[PARPORT_NUM_BUTTONS];
char saved_data;
char saved_control;
@ -88,22 +88,22 @@ static void parport_poll_pad(struct parport_joypad *pad)
for (i = 0; i < 8; i++)
{
if (!(data & UINT8_C(1 << i)) && pad->button_enable[i])
BIT32_SET(pad->buttons, i);
BIT64_SET(pad->buttons, i);
else
BIT32_CLEAR(pad->buttons, i);
BIT64_CLEAR(pad->buttons, i);
}
for (i = 3; i < 8; i++)
{
if (!(status & UINT8_C(1 << i)) && pad->button_enable[i + 5])
BIT32_SET(pad->buttons, i + 5);
BIT64_SET(pad->buttons, i + 5);
else
BIT32_CLEAR(pad->buttons, i + 5);
BIT64_CLEAR(pad->buttons, i + 5);
}
if (BIT32_GET(pad->buttons, 12) && pad->button_enable[12])
BIT32_CLEAR(pad->buttons, 12);
if (BIT64_GET(pad->buttons, 12) && pad->button_enable[12])
BIT64_CLEAR(pad->buttons, 12);
else
BIT32_SET(pad->buttons, 12);
BIT64_SET(pad->buttons, 12);
}
static bool parport_joypad_init_pad(const char *path, struct parport_joypad *pad)
@ -258,7 +258,7 @@ static bool parport_joypad_init(void)
for (j = 0; j < PARPORT_NUM_BUTTONS; j++)
{
if (!(BIT32_GET(pad->buttons, j)))
if (!(BIT64_GET(pad->buttons, j)))
{
pad->button_enable[j] = true;
found_enabled_button = true;
@ -323,9 +323,17 @@ static void parport_joypad_destroy(void)
static bool parport_joypad_button(unsigned port, uint16_t joykey)
{
const struct parport_joypad *pad = (const struct parport_joypad*)&parport_pads[port];
if (pad)
return joykey < PARPORT_NUM_BUTTONS && BIT32_GET(pad->buttons, joykey);
return false;
if (!pad)
return false;
return joykey < PARPORT_NUM_BUTTONS && BIT64_GET(pad->buttons, joykey);
}
static uint64_t parport_joypad_get_buttons(unsigned port)
{
const struct parport_joypad *pad = (const struct parport_joypad*)&parport_pads[port];
if (!pad)
return false;
return pad->buttons;
}
static int16_t parport_joypad_axis(unsigned port, uint32_t joyaxis)
@ -352,6 +360,7 @@ rarch_joypad_driver_t parport_joypad = {
parport_joypad_query_pad,
parport_joypad_destroy,
parport_joypad_button,
parport_joypad_get_buttons,
parport_joypad_axis,
parport_joypad_poll,
NULL,

View File

@ -64,6 +64,11 @@ static bool ps3_joypad_button(unsigned port_num, uint16_t joykey)
return pad_state[port_num] & (1ULL << joykey);
}
static uint64_t ps3_joypad_get_buttons(unsigned port_num)
{
return pad_state[port_num];
}
static int16_t ps3_joypad_axis(unsigned port_num, uint32_t joyaxis)
{
int val = 0, axis = -1;
@ -247,6 +252,7 @@ rarch_joypad_driver_t ps3_joypad = {
ps3_joypad_query_pad,
ps3_joypad_destroy,
ps3_joypad_button,
ps3_joypad_get_buttons,
ps3_joypad_axis,
ps3_joypad_poll,
ps3_joypad_rumble,

View File

@ -51,6 +51,11 @@ static bool psp_joypad_button(unsigned port_num, uint16_t joykey)
return (pad_state & (1ULL << joykey));
}
static uint64_t psp_joypad_get_buttons(unsigned port_num)
{
return pad_state;
}
static int16_t psp_joypad_axis(unsigned port_num, uint32_t joyaxis)
{
int val = 0, axis = -1;
@ -167,6 +172,7 @@ rarch_joypad_driver_t psp_joypad = {
psp_joypad_query_pad,
psp_joypad_destroy,
psp_joypad_button,
psp_joypad_get_buttons,
psp_joypad_axis,
psp_joypad_poll,
NULL,

View File

@ -50,6 +50,15 @@ static bool qnx_joypad_button(unsigned port_num, uint16_t joykey)
return qnx->pad_state[port_num] & (1ULL << joykey);
}
static uint64_t qnx_joypad_get_buttons(unsigned port_num)
{
qnx_input_t *qnx = (qnx_input_t*)driver.input_data;
if (!qnx || port_num >= MAX_PADS)
return 0;
return qnx->pad_state[port_num];
}
static int16_t qnx_joypad_axis(unsigned port_num, uint32_t joyaxis)
{
qnx_input_t *qnx = (qnx_input_t*)driver.input_data;
@ -118,6 +127,7 @@ rarch_joypad_driver_t qnx_joypad = {
qnx_joypad_query_pad,
qnx_joypad_destroy,
qnx_joypad_button,
qnx_joypad_get_buttons,
qnx_joypad_axis,
qnx_joypad_poll,
NULL,

View File

@ -430,6 +430,7 @@ rarch_joypad_driver_t sdl_joypad = {
sdl_joypad_query_pad,
sdl_joypad_destroy,
sdl_joypad_button,
NULL,
sdl_joypad_axis,
sdl_joypad_poll,
#ifdef HAVE_SDL2

View File

@ -48,7 +48,7 @@ struct udev_joypad
dev_t device;
/* Input state polled. */
uint32_t buttons;
uint64_t buttons;
int16_t axes[NUM_AXES];
int8_t hats[NUM_HATS][2];
@ -105,9 +105,9 @@ static void udev_poll_pad(struct udev_joypad *pad, unsigned p)
if (code >= BTN_MISC || (code >= KEY_UP && code <= KEY_DOWN))
{
if (events[i].value)
BIT32_SET(pad->buttons, pad->button_bind[code]);
BIT64_SET(pad->buttons, pad->button_bind[code]);
else
BIT32_CLEAR(pad->buttons, pad->button_bind[code]);
BIT64_CLEAR(pad->buttons, pad->button_bind[code]);
}
break;
@ -587,7 +587,15 @@ static bool udev_joypad_button(unsigned port, uint16_t joykey)
if (GET_HAT_DIR(joykey))
return udev_joypad_hat(pad, joykey);
return joykey < UDEV_NUM_BUTTONS && BIT32_GET(pad->buttons, joykey);
return joykey < UDEV_NUM_BUTTONS && BIT64_GET(pad->buttons, joykey);
}
static uint64_t udev_joypad_get_buttons(unsigned port)
{
const struct udev_joypad *pad = (const struct udev_joypad*)&udev_pads[port];
if (!pad)
return 0;
return pad->buttons;
}
static int16_t udev_joypad_axis(unsigned port, uint32_t joyaxis)
@ -633,6 +641,7 @@ rarch_joypad_driver_t udev_joypad = {
udev_joypad_query_pad,
udev_joypad_destroy,
udev_joypad_button,
udev_joypad_get_buttons,
udev_joypad_axis,
udev_joypad_poll,
udev_set_rumble,

View File

@ -299,10 +299,11 @@ static const uint16_t button_index_to_bitmap_code[] = {
XINPUT_GAMEPAD_GUIDE
};
static bool winxinput_joypad_button (unsigned port_num, uint16_t joykey)
static bool winxinput_joypad_button(unsigned port_num, uint16_t joykey)
{
uint16_t btn_word;
int xuser;
unsigned num_buttons = 0;
if (joykey == NO_BTN)
return false;
@ -331,14 +332,13 @@ static bool winxinput_joypad_button (unsigned port_num, uint16_t joykey)
}
return false; /* hat requested and no hat button down. */
}
else
{
/* non-hat button. */
unsigned num_buttons = g_winxinput_guide_button_supported ? 11 : 10;
if (joykey < num_buttons)
return btn_word & button_index_to_bitmap_code[joykey];
}
/* non-hat button. */
num_buttons = g_winxinput_guide_button_supported ? 11 : 10;
if (joykey < num_buttons)
return btn_word & button_index_to_bitmap_code[joykey];
return false;
}
@ -455,6 +455,7 @@ rarch_joypad_driver_t winxinput_joypad = {
winxinput_joypad_query_pad,
winxinput_joypad_destroy,
winxinput_joypad_button,
NULL,
winxinput_joypad_axis,
winxinput_joypad_poll,
winxinput_joypad_rumble,

View File

@ -77,19 +77,24 @@ static bool xdk_joypad_init(void)
return true;
}
static bool xdk_joypad_button(unsigned port, uint16_t joykey)
static bool xdk_joypad_button(unsigned port_num, uint16_t joykey)
{
if (port >= MAX_PADS)
if (port_num >= MAX_PADS)
return false;
return pad_state[port] & (1ULL << joykey);
return pad_state[port_num] & (1ULL << joykey);
}
static int16_t xdk_joypad_axis(unsigned port, uint32_t joyaxis)
static uint64_t xdk_joypad_get_buttons(unsigned port_num)
{
return pad_state[port_num];
}
static int16_t xdk_joypad_axis(unsigned port_num, uint32_t joyaxis)
{
int val = 0, axis = -1;
bool is_neg = false, is_pos = false;
if (joyaxis == AXIS_NONE || port >= MAX_PADS)
if (joyaxis == AXIS_NONE || port_num >= MAX_PADS)
return 0;
if (AXIS_NEG_GET(joyaxis) < 4)
@ -106,16 +111,16 @@ static int16_t xdk_joypad_axis(unsigned port, uint32_t joyaxis)
switch (axis)
{
case 0:
val = analog_state[port][0][0];
val = analog_state[port_num][0][0];
break;
case 1:
val = analog_state[port][0][1];
val = analog_state[port_num][0][1];
break;
case 2:
val = analog_state[port][1][0];
val = analog_state[port_num][1][0];
break;
case 3:
val = analog_state[port][1][1];
val = analog_state[port_num][1][1];
break;
}
@ -262,6 +267,7 @@ rarch_joypad_driver_t xdk_joypad = {
xdk_joypad_query_pad,
xdk_joypad_destroy,
xdk_joypad_button,
xdk_joypad_get_buttons,
xdk_joypad_axis,
xdk_joypad_poll,
NULL,

View File

@ -35,6 +35,7 @@ struct rarch_joypad_driver
bool (*query_pad)(unsigned);
void (*destroy)(void);
bool (*button)(unsigned, uint16_t);
uint64_t (*get_buttons)(unsigned);
int16_t (*axis)(unsigned, uint32_t);
void (*poll)(void);
bool (*set_rumble)(unsigned, enum retro_rumble_effect, uint16_t);