1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-05 17:58:41 +00:00

WiiU Initial Keyboard Support

WiiU Initial Keyboard Support
This commit is contained in:
xhp-creations 2017-02-09 12:34:12 -05:00
parent a2141e61f7
commit 4915f452f5
5 changed files with 231 additions and 3 deletions

View File

@ -28,11 +28,63 @@
#include "../input_config.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "../input_keyboard.h"
#include "../input_keymaps.h"
#include <wiiu/nsyskbd.h>
#include "wiiu_dbg.h"
#define MAX_PADS 5
static unsigned char keyboardChannel = 0x00;
static KBDModifier keyboardModifier = 0x00;
static unsigned char keyboardCode = 0x00;
static KEYState keyboardState = KBD_WIIU_NULL;
void kb_connection_callback(KBDKeyEvent *key) {
keyboardChannel = keyboardChannel + (key->channel + 0x01);
}
void kb_disconnection_callback(KBDKeyEvent *key) {
keyboardChannel = keyboardChannel - (key->channel + 0x01);
}
void kb_key_callback(KBDKeyEvent *key) {
keyboardModifier = key->modifier;
keyboardCode = key->scancode;
keyboardState = key->state;
bool pressed = false;
if (key->state > 0)
{
pressed = true;
}
uint16_t mod = 0;
unsigned code = input_keymaps_translate_keysym_to_rk(key->scancode);
if (key->modifier & KBD_WIIU_SHIFT)
mod |= RETROKMOD_SHIFT;
if (key->modifier & KBD_WIIU_CTRL)
mod |= RETROKMOD_CTRL;
if (key->modifier & KBD_WIIU_ALT)
mod |= RETROKMOD_ALT;
if (key->modifier & KBD_WIIU_NUM_LOCK)
mod |= RETROKMOD_NUMLOCK;
if (key->modifier & KBD_WIIU_CAPS_LOCK)
mod |= RETROKMOD_CAPSLOCK;
if (key->modifier & KBD_WIIU_SCROLL_LOCK)
mod |= RETROKMOD_SCROLLOCK;
input_keyboard_event(pressed, code, (char)key->UTF16, mod,
RETRO_DEVICE_KEYBOARD);
}
typedef struct wiiu_input
{
bool blocked;
@ -46,7 +98,21 @@ static void wiiu_input_poll(void *data)
wiiu_input_t *wiiu = (wiiu_input_t*)data;
if (wiiu->joypad)
wiiu->joypad->poll();
wiiu->joypad->poll();
}
static bool wiiu_key_pressed(int key)
{
unsigned sym;
bool ret = false;
if (key >= RETROK_LAST)
return false;
if ((keyboardState > 0) && (keyboardChannel > 0))
ret = keyboardCode;
return ret;
}
static int16_t wiiu_input_state(void *data,
@ -59,11 +125,13 @@ static int16_t wiiu_input_state(void *data,
if(!wiiu || !(port < MAX_PADS) || !binds || !binds[port])
return 0;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
return input_joypad_pressed(wiiu->joypad, joypad_info, port, binds[port], id);
case RETRO_DEVICE_KEYBOARD:
return wiiu_key_pressed(id);
case RETRO_DEVICE_ANALOG:
if (binds[port])
return input_joypad_analog(wiiu->joypad, joypad_info, port, idx, id, binds[port]);
@ -79,6 +147,8 @@ static void wiiu_input_free_input(void *data)
if (wiiu && wiiu->joypad)
wiiu->joypad->destroy();
KBDTeardown();
free(data);
}
@ -91,6 +161,10 @@ static void* wiiu_input_init(const char *joypad_driver)
DEBUG_STR(joypad_driver);
wiiu->joypad = input_joypad_init_driver(joypad_driver, wiiu);
KBDSetup(&kb_connection_callback,&kb_disconnection_callback,&kb_key_callback);
input_keymaps_init_keyboard_lut(rarch_key_map_wiiu);
return wiiu;
}
@ -107,7 +181,7 @@ static uint64_t wiiu_input_get_capabilities(void *data)
{
(void)data;
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG) | (1 << RETRO_DEVICE_KEYBOARD);
}
static const input_device_driver_t *wiiu_input_get_joypad_driver(void *data)

View File

@ -684,6 +684,112 @@ const struct rarch_key_map rarch_key_map_rwebinput[] = {
};
#endif
#ifdef WIIU
const struct rarch_key_map rarch_key_map_wiiu[] = {
{ 4, RETROK_a },
{ 5, RETROK_b },
{ 6, RETROK_c },
{ 7, RETROK_d },
{ 8, RETROK_e },
{ 9, RETROK_f },
{ 10, RETROK_g },
{ 11, RETROK_h },
{ 12, RETROK_i },
{ 13, RETROK_j },
{ 14, RETROK_k },
{ 15, RETROK_l },
{ 16, RETROK_m },
{ 17, RETROK_n },
{ 18, RETROK_o },
{ 19, RETROK_p },
{ 20, RETROK_q },
{ 21, RETROK_r },
{ 22, RETROK_s },
{ 23, RETROK_t },
{ 24, RETROK_u },
{ 25, RETROK_v },
{ 26, RETROK_w },
{ 27, RETROK_x },
{ 28, RETROK_y },
{ 29, RETROK_z },
{ 30, RETROK_1 },
{ 31, RETROK_2 },
{ 32, RETROK_3 },
{ 33, RETROK_4 },
{ 34, RETROK_5 },
{ 35, RETROK_6 },
{ 36, RETROK_7 },
{ 37, RETROK_8 },
{ 38, RETROK_9 },
{ 39, RETROK_0 },
{ 40, RETROK_RETURN },
{ 41, RETROK_ESCAPE },
{ 42, RETROK_BACKSPACE },
{ 43, RETROK_TAB },
{ 44, RETROK_SPACE },
{ 45, RETROK_MINUS },
{ 46, RETROK_EQUALS },
{ 47, RETROK_LEFTBRACKET },
{ 48, RETROK_RIGHTBRACKET },
{ 49, RETROK_BACKSLASH },
{ 51, RETROK_SEMICOLON },
{ 52, RETROK_QUOTE },
{ 53, RETROK_BACKQUOTE },
{ 54, RETROK_COMMA },
{ 55, RETROK_PERIOD },
{ 56, RETROK_SLASH },
{ 57, RETROK_CAPSLOCK },
{ 58, RETROK_F1 },
{ 59, RETROK_F2 },
{ 60, RETROK_F3 },
{ 61, RETROK_F4 },
{ 62, RETROK_F5 },
{ 63, RETROK_F6 },
{ 64, RETROK_F7 },
{ 65, RETROK_F8 },
{ 66, RETROK_F9 },
{ 67, RETROK_F10 },
{ 68, RETROK_F11 },
{ 69, RETROK_F12 },
{ 71, RETROK_SCROLLOCK },
{ 72, RETROK_PAUSE },
{ 73, RETROK_INSERT },
{ 74, RETROK_HOME },
{ 75, RETROK_PAGEUP },
{ 76, RETROK_DELETE },
{ 77, RETROK_END },
{ 78, RETROK_PAGEDOWN },
{ 79, RETROK_RIGHT },
{ 80, RETROK_LEFT },
{ 81, RETROK_DOWN },
{ 82, RETROK_UP },
{ 83, RETROK_NUMLOCK },
{ 84, RETROK_KP_DIVIDE },
{ 85, RETROK_KP_MULTIPLY },
{ 86, RETROK_KP_MINUS },
{ 87, RETROK_KP_PLUS },
{ 88, RETROK_KP_ENTER },
{ 89, RETROK_KP1 },
{ 90, RETROK_KP2 },
{ 91, RETROK_KP3 },
{ 92, RETROK_KP4 },
{ 93, RETROK_KP5 },
{ 94, RETROK_KP6 },
{ 95, RETROK_KP7 },
{ 96, RETROK_KP8 },
{ 97, RETROK_KP9 },
{ 98, RETROK_KP0 },
{ 99, RETROK_KP_PERIOD },
{ 224, RETROK_LCTRL },
{ 225, RETROK_LSHIFT },
{ 226, RETROK_LALT },
{ 228, RETROK_RCTRL },
{ 229, RETROK_RSHIFT },
{ 230, RETROK_RALT },
{ 0, RETROK_UNKNOWN },
};
#endif
#ifdef HAVE_X11
#ifndef XF68XK_Calculator

View File

@ -58,6 +58,7 @@ extern const struct rarch_key_map rarch_key_map_apple_hid[];
extern const struct rarch_key_map rarch_key_map_android[];
extern const struct rarch_key_map rarch_key_map_qnx[];
extern const struct rarch_key_map rarch_key_map_dos[];
extern const struct rarch_key_map rarch_key_map_wiiu[];
/**
* input_keymaps_init_keyboard_lut:

View File

@ -0,0 +1,40 @@
#pragma once
#include <wiiu/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum _KEYState
{
KBD_WIIU_DOWN = 0x01,
KBD_WIIU_REPEAT = 0x02,
KBD_WIIU_NULL = 0x00
} KEYState;
typedef enum _KBDModifier
{
KBD_WIIU_CTRL = 0x0001,
KBD_WIIU_SHIFT = 0x0002,
KBD_WIIU_ALT = 0x0004,
KBD_WIIU_NUM_LOCK = 0x0100,
KBD_WIIU_CAPS_LOCK = 0x0200,
KBD_WIIU_SCROLL_LOCK = 0x0400,
} KBDModifier;
typedef struct _KBDKeyEvent
{
unsigned char channel;
unsigned char scancode; // scancode
KEYState state; // when held, value is 0x03, which is KBD_DOWN & KBD_REPEAT
KBDModifier modifier; // modifier state
unsigned short UTF16; // unicode, if any
} KBDKeyEvent;
char KBDSetup(void *connection_callback, void *disconnection_callback, void *key_callback);
char KBDTeardown();
#ifdef __cplusplus
}
#endif

View File

@ -194,3 +194,10 @@ IMPORT(KPADRead);
IMPORT_END();
/* nsyskbd */
IMPORT_BEGIN(nsyskbd);
IMPORT(KBDSetup);
IMPORT(KBDTeardown);
IMPORT_END();