(WiiU) Cleanups

This commit is contained in:
twinaphex 2020-06-11 22:05:30 +02:00
parent 255794d903
commit e40d381f6b

View File

@ -35,8 +35,8 @@
#include "wiiu_dbg.h"
static uint8_t keyboardChannel = 0x00;
static bool keyboardState[RETROK_LAST] = { 0 };
static uint8_t keyboard_channel = 0x00;
static bool keyboard_state[RETROK_LAST] = { 0 };
typedef struct wiiu_input
{
@ -45,12 +45,12 @@ typedef struct wiiu_input
static void kb_connection_callback(KBDKeyEvent *key)
{
keyboardChannel = keyboardChannel + (key->channel + 0x01);
keyboard_channel += (key->channel + 0x01);
}
static void kb_disconnection_callback(KBDKeyEvent *key)
{
keyboardChannel = keyboardChannel - (key->channel + 0x01);
keyboard_channel -= (key->channel + 0x01);
}
static void kb_key_callback(KBDKeyEvent *key)
@ -62,9 +62,10 @@ static void kb_key_callback(KBDKeyEvent *key)
if (key->state > 0)
pressed = true;
code = input_keymaps_translate_keysym_to_rk(key->scancode);
code = input_keymaps_translate_keysym_to_rk(
key->scancode);
if (code < RETROK_LAST)
keyboardState[code] = pressed;
keyboard_state[code] = pressed;
if (key->modifier & KBD_WIIU_SHIFT)
mod |= RETROKMOD_SHIFT;
@ -120,6 +121,30 @@ static void wiiu_input_poll(void *data)
wiiu->joypad->poll();
}
static int16_t wiiu_is_pressed(
const input_device_driver_t *joypad,
rarch_joypad_info_t *joypad_info,
const struct retro_keybind *binds,
unsigned port, unsigned id)
{
const struct retro_keybind *bind = &binds[id];
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[id].joykey != NO_BTN)
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
if (mouse && winraw_mouse_button_pressed(wr,
mouse, port, bind->mbutton))
return 1;
if ((uint16_t)joykey != NO_BTN &&
joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
return 1;
if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis))
/ 0x8000) > joypad_info->axis_threshold)
return 1;
return 0;
}
static int16_t wiiu_input_state(void *data,
rarch_joypad_info_t *joypad_info,
const struct retro_keybind **binds,
@ -141,42 +166,25 @@ static int16_t wiiu_input_state(void *data,
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[port][i].joykey != NO_BTN)
? binds[port][i].joykey : joypad_info->auto_binds[i].joykey;
const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE)
? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis;
if ((uint16_t)joykey != NO_BTN && wiiu->joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
{
ret |= (1 << i);
continue;
}
if (((float)abs(wiiu->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
{
ret |= (1 << i);
continue;
}
if (binds[port][i].valid)
if (wiiu_is_pressed(
wiiu->joypad,
joypad_info, binds[port], port, i))
ret |= (1 << i);
}
return ret;
}
else
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[port][id].joykey != NO_BTN)
? binds[port][id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE)
? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis;
if ((uint16_t)joykey != NO_BTN && wiiu->joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
return 1;
if (((float)abs(wiiu->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
return 1;
if (binds[port][i].valid)
return wiiu_is_pressed(
wiiu->joypad,
joypad_info, binds[port], port, id);
}
break;
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST && keyboardState[id] && (keyboardChannel > 0))
if (id < RETROK_LAST && keyboard_state[id] && (keyboard_channel > 0))
return 1;
break;
case RETRO_DEVICE_ANALOG: