RetroArch/input/drivers/wiiu_input.c

173 lines
4.6 KiB
C
Raw Normal View History

2016-10-27 01:34:10 +01:00
/* RetroArch - A frontend for libretro.
2017-01-22 13:40:32 +01:00
* Copyright (C) 2014-2017 - Ali Bouhlel
* Copyright (C) 2014-2017 - Daniel De Matteis
2016-10-27 01:34:10 +01:00
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdlib.h>
#include <boolean.h>
#include <libretro.h>
2017-01-11 08:24:55 +01:00
#include <retro_miscellaneous.h>
2016-10-27 01:34:10 +01:00
#include <wiiu/nsyskbd.h>
#include <wiiu/vpad.h>
2016-10-27 01:34:10 +01:00
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include "../../config.def.h"
#include "../input_driver.h"
#include "../input_keymaps.h"
2016-10-27 01:34:10 +01:00
#include "wiiu_dbg.h"
2020-08-26 15:32:05 +02:00
/* TODO/FIXME - static global variables */
2020-06-11 22:05:30 +02:00
static uint8_t keyboard_channel = 0x00;
static bool keyboard_state[RETROK_LAST] = { 0 };
2020-06-10 04:00:40 +02:00
static void kb_connection_callback(KBDKeyEvent *key)
2017-06-07 00:10:39 +02:00
{
2020-06-11 22:05:30 +02:00
keyboard_channel += (key->channel + 0x01);
}
2020-06-10 04:00:40 +02:00
static void kb_disconnection_callback(KBDKeyEvent *key)
2017-06-07 00:10:39 +02:00
{
2020-06-11 22:05:30 +02:00
keyboard_channel -= (key->channel + 0x01);
}
2020-06-10 04:00:40 +02:00
static void kb_key_callback(KBDKeyEvent *key)
2017-06-07 00:10:39 +02:00
{
2020-08-29 19:59:04 +02:00
uint16_t mod = 0;
unsigned code = 0;
bool pressed = false;
2017-06-07 00:10:39 +02:00
if (key->state > 0)
2020-08-29 19:59:04 +02:00
pressed = true;
2017-06-07 00:10:39 +02:00
2020-06-11 22:05:30 +02:00
code = input_keymaps_translate_keysym_to_rk(
key->scancode);
if (code < RETROK_LAST)
2020-06-11 22:05:30 +02:00
keyboard_state[code] = pressed;
if (key->modifier & KBD_WIIU_SHIFT)
2020-08-29 19:59:04 +02:00
mod |= RETROKMOD_SHIFT;
2017-06-07 00:10:39 +02:00
if (key->modifier & KBD_WIIU_CTRL)
2020-08-29 19:59:04 +02:00
mod |= RETROKMOD_CTRL;
if (key->modifier & KBD_WIIU_ALT)
2020-08-29 19:59:04 +02:00
mod |= RETROKMOD_ALT;
if (key->modifier & KBD_WIIU_NUM_LOCK)
2020-08-29 19:59:04 +02:00
mod |= RETROKMOD_NUMLOCK;
if (key->modifier & KBD_WIIU_CAPS_LOCK)
2020-08-29 19:59:04 +02:00
mod |= RETROKMOD_CAPSLOCK;
if (key->modifier & KBD_WIIU_SCROLL_LOCK)
2020-08-29 19:59:04 +02:00
mod |= RETROKMOD_SCROLLOCK;
input_keyboard_event(pressed, code, (char)key->UTF16, mod,
RETRO_DEVICE_KEYBOARD);
}
2020-08-30 05:29:32 +02:00
static int16_t wiiu_input_state(
void *data,
const input_device_driver_t *joypad,
const input_device_driver_t *sec_joypad,
2020-02-27 07:33:14 +01:00
rarch_joypad_info_t *joypad_info,
const struct retro_keybind **binds,
bool keyboard_mapping_blocked,
unsigned port,
unsigned device,
unsigned idx,
unsigned id)
2016-10-27 01:34:10 +01:00
{
2020-09-02 05:26:24 +02:00
if (!(port < DEFAULT_MAX_PADS) || !binds || !binds[port])
2016-11-02 22:06:15 +01:00
return 0;
2016-10-27 01:34:10 +01:00
switch (device)
{
case RETRO_DEVICE_JOYPAD:
case RETRO_DEVICE_ANALOG:
2019-07-22 01:20:00 +02:00
break;
case RETRO_DEVICE_KEYBOARD:
2020-06-11 22:05:30 +02:00
if (id < RETROK_LAST && keyboard_state[id] && (keyboard_channel > 0))
2020-06-10 04:00:40 +02:00
return 1;
break;
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
2020-08-31 02:07:43 +02:00
/* TODO: Emulate a relative mouse.
* This is suprisingly hard to get working nicely.
*/
switch (id)
{
case RETRO_DEVICE_ID_POINTER_PRESSED:
{
input_bits_t state;
joypad->get_buttons(0, &state);
return BIT256_GET(state, VPAD_BUTTON_TOUCH_BIT) ? 1 : 0;
}
case RETRO_DEVICE_ID_POINTER_X:
return joypad->axis(0, 0xFFFF0004UL);
case RETRO_DEVICE_ID_POINTER_Y:
return joypad->axis(0, 0xFFFF0005UL);
}
break;
2016-10-27 01:34:10 +01:00
}
return 0;
}
static void wiiu_input_free_input(void *data)
{
KBDTeardown();
2016-10-27 01:34:10 +01:00
}
static void* wiiu_input_init(const char *joypad_driver)
2016-10-27 01:34:10 +01:00
{
2020-08-31 02:07:43 +02:00
KBDSetup(
&kb_connection_callback,
&kb_disconnection_callback,
&kb_key_callback);
input_keymaps_init_keyboard_lut(rarch_key_map_wiiu);
2020-09-18 02:50:01 +02:00
return (void*)-1;
2016-10-27 01:34:10 +01:00
}
static uint64_t wiiu_input_get_capabilities(void *data)
{
return (1 << RETRO_DEVICE_JOYPAD) |
(1 << RETRO_DEVICE_ANALOG) |
(1 << RETRO_DEVICE_KEYBOARD) |
(1 << RETRO_DEVICE_POINTER);
2016-10-27 01:34:10 +01:00
}
input_driver_t input_wiiu = {
wiiu_input_init,
2020-08-30 05:29:32 +02:00
NULL, /* poll */
2016-10-27 01:34:10 +01:00
wiiu_input_state,
wiiu_input_free_input,
NULL,
NULL,
wiiu_input_get_capabilities,
"wiiu",
2020-08-30 05:29:32 +02:00
NULL, /* grab_mouse */
NULL
2016-10-27 01:34:10 +01:00
};