Merge git://github.com/ToadKing/RetroArch-Rpi

This commit is contained in:
Twinaphex 2012-07-26 21:38:37 +02:00
commit 6ed82854bf
3 changed files with 529 additions and 124 deletions

View File

@ -20,6 +20,7 @@
#include "../../driver.h"
#include "../../general.h"
#include "../../libretro.h"
#include "../../console/retroarch_console_input.h"
#include <stdlib.h>
#include <stddef.h>
@ -40,6 +41,31 @@ FILE * log_fp;
static uint16_t menu_framebuf[RGUI_WIDTH * RGUI_HEIGHT];
static const uint64_t wii_nav_buttons[9] = {
WII_GC_UP | WII_GC_LSTICK_UP | WII_GC_RSTICK_UP | WII_CLASSIC_UP | WII_CLASSIC_LSTICK_UP | WII_CLASSIC_RSTICK_UP | WII_WIIMOTE_UP | WII_NUNCHUK_UP,
WII_GC_DOWN | WII_GC_LSTICK_DOWN | WII_GC_RSTICK_DOWN | WII_CLASSIC_DOWN | WII_CLASSIC_LSTICK_DOWN | WII_CLASSIC_RSTICK_DOWN | WII_WIIMOTE_DOWN | WII_NUNCHUK_DOWN,
WII_GC_LEFT | WII_GC_LSTICK_LEFT | WII_GC_RSTICK_LEFT | WII_CLASSIC_LEFT | WII_CLASSIC_LSTICK_LEFT | WII_CLASSIC_RSTICK_LEFT | WII_WIIMOTE_LEFT | WII_NUNCHUK_LEFT,
WII_GC_RIGHT | WII_GC_LSTICK_RIGHT | WII_GC_RSTICK_RIGHT | WII_CLASSIC_RIGHT | WII_CLASSIC_LSTICK_RIGHT | WII_CLASSIC_RSTICK_RIGHT | WII_WIIMOTE_RIGHT | WII_NUNCHUK_RIGHT,
WII_GC_A | WII_CLASSIC_A | WII_WIIMOTE_A | WII_WIIMOTE_2,
WII_GC_B | WII_CLASSIC_B | WII_WIIMOTE_B | WII_WIIMOTE_1,
WII_GC_START | WII_CLASSIC_PLUS | WII_WIIMOTE_PLUS,
WII_GC_Z_TRIGGER | WII_CLASSIC_MINUS | WII_WIIMOTE_MINUS,
WII_WIIMOTE_HOME | WII_CLASSIC_HOME,
};
enum
{
WII_DEVICE_NAV_UP = 0,
WII_DEVICE_NAV_DOWN,
WII_DEVICE_NAV_LEFT,
WII_DEVICE_NAV_RIGHT,
WII_DEVICE_NAV_A,
WII_DEVICE_NAV_B,
WII_DEVICE_NAV_START,
WII_DEVICE_NAV_SELECT,
WII_DEVICE_NAV_EXIT,
};
static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb,
void *userdata, void *ctx)
{
@ -92,40 +118,42 @@ static bool get_rom_path(rgui_handle_t *rgui)
for (;;)
{
uint16_t input_state = 0;
input_wii.poll(NULL);
uint64_t input_poll = wii_input_update(0);
if (input_wii.key_pressed(NULL, RARCH_QUIT_KEY))
for (unsigned i = 0; i < sizeof(wii_nav_buttons) / sizeof(wii_nav_buttons[0]); i++)
{
if (can_quit)
return false;
}
else
can_quit = true;
for (unsigned i = 0; i < RARCH_FIRST_META_KEY; i++)
{
input_state |= input_wii.input_state(NULL, NULL, false,
RETRO_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0;
input_state |= input_poll & wii_nav_buttons[i] ? (1 << i) : 0;
}
uint16_t trigger_state = input_state & ~old_input_state;
if (!first)
{
if (trigger_state & (1 << WII_DEVICE_NAV_EXIT))
{
if (can_quit)
return false;
}
else
can_quit = true;
}
rgui_action_t action = RGUI_ACTION_NOOP;
if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_B))
if (trigger_state & (1 << WII_DEVICE_NAV_B))
action = RGUI_ACTION_CANCEL;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_A))
else if (trigger_state & (1 << WII_DEVICE_NAV_A))
action = RGUI_ACTION_OK;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_UP))
else if (trigger_state & (1 << WII_DEVICE_NAV_UP))
action = RGUI_ACTION_UP;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN))
else if (trigger_state & (1 << WII_DEVICE_NAV_DOWN))
action = RGUI_ACTION_DOWN;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT))
else if (trigger_state & (1 << WII_DEVICE_NAV_LEFT))
action = RGUI_ACTION_LEFT;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT))
else if (trigger_state & (1 << WII_DEVICE_NAV_RIGHT))
action = RGUI_ACTION_RIGHT;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_START))
else if (trigger_state & (1 << WII_DEVICE_NAV_START))
action = RGUI_ACTION_START;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) && !first) // don't catch start+select+l+r when exiting
else if (trigger_state & (1 << WII_DEVICE_NAV_SELECT) && !first) // don't catch start+select+l+r when exiting
action = RGUI_ACTION_SETTINGS;
const char *ret = rgui_iterate(rgui, action);
@ -172,6 +200,7 @@ int main(void)
wii_video_init();
input_wii.init();
rarch_input_set_controls_default(&input_wii);
rgui_handle_t *rgui = rgui_init("",
menu_framebuf, RGUI_WIDTH * sizeof(uint16_t),

View File

@ -20,50 +20,111 @@
#include <wiiuse/wpad.h>
#endif
#include <string.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif
#include "wii_input.h"
#include "../driver.h"
#include "../libretro.h"
#include <stdlib.h>
static bool pad_state[5][RARCH_FIRST_META_KEY]; /* Gamecube pads */
#ifdef HW_RVL
static bool wpad_state[5][RARCH_FIRST_META_KEY]; /* Wii Classic pads */
#endif
#define JOYSTICK_THRESHOLD 64
static uint64_t pad_state[4];
const struct platform_bind platform_keys[] = {
{ PAD_BUTTON_B, "(NGC) B button" },
{ PAD_BUTTON_A, "(NGC) A button" },
{ PAD_BUTTON_Y, "(NGC) Y button" },
{ PAD_BUTTON_X, "(NGC) X button" },
{ PAD_BUTTON_UP, "(NGC) D-Pad Up" },
{ PAD_BUTTON_DOWN, "(NGC) D-Pad Down" },
{ PAD_BUTTON_LEFT, "(NGC) D-Pad Left" },
{ PAD_BUTTON_RIGHT, "(NGC) D-Pad Right" },
{ PAD_TRIGGER_Z, "(NGC) Z trigger" },
{ PAD_BUTTON_START, "(NGC) Start button" },
{ PAD_TRIGGER_L, "(NGC) Left Trigger" },
{ PAD_TRIGGER_R, "(NGC) Right Trigger" },
{ WII_GC_A, "GC A button" },
{ WII_GC_B, "GC B button" },
{ WII_GC_X, "GC X button" },
{ WII_GC_Y, "GC Y button" },
{ WII_GC_UP, "GC D-Pad Up" },
{ WII_GC_DOWN, "GC D-Pad Down" },
{ WII_GC_LEFT, "GC D-Pad Left" },
{ WII_GC_RIGHT, "GC D-Pad Right" },
{ WII_GC_Z_TRIGGER, "GC Z Trigger" },
{ WII_GC_START, "GC Start button" },
{ WII_GC_L_TRIGGER, "GC Left Trigger" },
{ WII_GC_R_TRIGGER, "GC Right Trigger" },
{ WII_GC_LSTICK_LEFT, "GC Main Stick Left" },
{ WII_GC_LSTICK_RIGHT, "GC Main Stick Right" },
{ WII_GC_LSTICK_UP, "GC Main Stick Up" },
{ WII_GC_LSTICK_DOWN, "GC Main Stick Down" },
{ WII_GC_LSTICK_LEFT | WII_GC_LEFT, "GC Main Stick D-Pad Left" },
{ WII_GC_LSTICK_RIGHT | WII_GC_RIGHT, "GC Main Stick D-Pad Right" },
{ WII_GC_LSTICK_UP | WII_GC_UP, "GC Main Stick D-Pad Up" },
{ WII_GC_LSTICK_DOWN | WII_GC_DOWN, "GC Main Stick D-Pad Down" },
{ WII_GC_RSTICK_LEFT, "GC C-Stick Left" },
{ WII_GC_RSTICK_RIGHT, "GC C-Stick Right" },
{ WII_GC_RSTICK_UP, "GC C-Stick Up" },
{ WII_GC_RSTICK_DOWN, "GC C-Stick Down" },
{ WII_GC_RSTICK_LEFT | WII_GC_LEFT, "GC C-Stick D-Pad Left" },
{ WII_GC_RSTICK_RIGHT | WII_GC_RIGHT, "GC C-Stick D-Pad Right" },
{ WII_GC_RSTICK_UP | WII_GC_UP, "GC C-Stick D-Pad Up" },
{ WII_GC_RSTICK_DOWN | WII_GC_DOWN, "GC C-Stick D-Pad Down" },
#ifdef HW_RVL
{ WPAD_CLASSIC_BUTTON_B, "(Wii Classici) B button" },
{ WPAD_CLASSIC_BUTTON_A, "(Wii Classic) A button" },
{ WPAD_CLASSIC_BUTTON_Y, "(Wii Classic) Y button" },
{ WPAD_CLASSIC_BUTTON_X, "(Wii Classic) X button" },
{ WPAD_CLASSIC_BUTTON_UP, "(Wii Classic) D-Pad Up" },
{ WPAD_CLASSIC_BUTTON_DOWN, "(Wii Classic) D-Pad Down" },
{ WPAD_CLASSIC_BUTTON_LEFT, "(Wii Classic) D-Pad Left" },
{ WPAD_CLASSIC_BUTTON_RIGHT, "(Wii Classic) D-Pad Right" },
{ WPAD_CLASSIC_BUTTON_MINUS, "(Wii Classic) Select/Minus button" },
{ WPAD_CLASSIC_BUTTON_PLUS, "(Wii Classic) Start/Plus button" },
{ WPAD_CLASSIC_BUTTON_HOME, "(Wii Classic) Home button" },
{ WPAD_CLASSIC_BUTTON_FULL_L, "(Wii Classic) Left Trigger" },
{ WPAD_CLASSIC_BUTTON_FULL_R, "(Wii Classic) Right Trigger" },
{ WPAD_CLASSIC_BUTTON_ZL, "(Wii Classic) ZL button" },
{ WPAD_CLASSIC_BUTTON_ZR, "(Wii Classic) ZR button" },
// CLASSIC CONTROLLER
{ WII_CLASSIC_A, "Classic A button" },
{ WII_CLASSIC_B, "Classic B button" },
{ WII_CLASSIC_X, "Classic X button" },
{ WII_CLASSIC_Y, "Classic Y button" },
{ WII_CLASSIC_UP, "Classic D-Pad Up" },
{ WII_CLASSIC_DOWN, "Classic D-Pad Down" },
{ WII_CLASSIC_LEFT, "Classic D-Pad Left" },
{ WII_CLASSIC_RIGHT, "Classic D-Pad Right" },
{ WII_CLASSIC_PLUS, "Classic Plus button" },
{ WII_CLASSIC_MINUS, "Classic Minus button" },
{ WII_CLASSIC_HOME, "Classic Home button" },
{ WII_CLASSIC_L_TRIGGER, "Classic L Trigger" },
{ WII_CLASSIC_R_TRIGGER, "Classic R Trigger" },
{ WII_CLASSIC_ZL_TRIGGER, "Classic ZL Trigger" },
{ WII_CLASSIC_ZR_TRIGGER, "Classic ZR Trigger" },
{ WII_CLASSIC_LSTICK_LEFT, "Classic LStick Left" },
{ WII_CLASSIC_LSTICK_RIGHT, "Classic LStick Right" },
{ WII_CLASSIC_LSTICK_UP, "Classic LStick Up" },
{ WII_CLASSIC_LSTICK_DOWN, "Classic LStick Down" },
{ WII_CLASSIC_LSTICK_LEFT | WII_CLASSIC_LEFT, "Classic LStick D-Pad Left" },
{ WII_CLASSIC_LSTICK_RIGHT | WII_CLASSIC_RIGHT, "Classic LStick D-Pad Right" },
{ WII_CLASSIC_LSTICK_UP | WII_CLASSIC_UP, "Classic LStick D-Pad Up" },
{ WII_CLASSIC_LSTICK_DOWN | WII_CLASSIC_DOWN, "Classic LStick D-Pad Down" },
{ WII_CLASSIC_RSTICK_LEFT, "Classic RStick Left" },
{ WII_CLASSIC_RSTICK_RIGHT, "Classic RStick Right" },
{ WII_CLASSIC_RSTICK_UP, "Classic RStick Up" },
{ WII_CLASSIC_RSTICK_DOWN, "Classic RStick Down" },
{ WII_CLASSIC_RSTICK_LEFT | WII_CLASSIC_LEFT, "Classic RStick D-Pad Left" },
{ WII_CLASSIC_RSTICK_RIGHT | WII_CLASSIC_RIGHT, "Classic RStick D-Pad Right" },
{ WII_CLASSIC_RSTICK_UP | WII_CLASSIC_UP, "Classic RStick D-Pad Up" },
{ WII_CLASSIC_RSTICK_DOWN | WII_CLASSIC_DOWN, "Classic RStick D-Pad Down" },
// WIIMOTE (PLUS OPTIONAL NUNCHUK)
{ WII_WIIMOTE_A, "Wiimote A button" },
{ WII_WIIMOTE_B, "Wiimote B button" },
{ WII_WIIMOTE_1, "Wiimote 1 button" },
{ WII_WIIMOTE_2, "Wiimote 2 button" },
{ WII_WIIMOTE_UP, "Wiimote D-Pad Up" },
{ WII_WIIMOTE_DOWN, "Wiimote D-Pad Down" },
{ WII_WIIMOTE_LEFT, "Wiimote D-Pad Left" },
{ WII_WIIMOTE_RIGHT, "Wiimote D-Pad Right" },
{ WII_WIIMOTE_PLUS, "Wiimote Plus button" },
{ WII_WIIMOTE_MINUS, "Wiimote Minus button" },
{ WII_WIIMOTE_HOME, "Wiimote Home button" },
{ WII_NUNCHUK_Z, "Nunchuk Z button" },
{ WII_NUNCHUK_C, "Nunchuk C button" },
{ WII_NUNCHUK_LEFT, "Nunchuk Stick Left" },
{ WII_NUNCHUK_RIGHT, "Nunchuk Stick Right" },
{ WII_NUNCHUK_UP, "Nunchuk Stick Up" },
{ WII_NUNCHUK_DOWN, "Nunchuk Stick Down" },
{ WII_NUNCHUK_LEFT | WII_WIIMOTE_LEFT, "Nunchuk Stick D-Pad Left" },
{ WII_NUNCHUK_RIGHT | WII_WIIMOTE_RIGHT, "Nunchuk Stick D-Pad Right" },
{ WII_NUNCHUK_UP | WII_WIIMOTE_UP, "Nunchuk Stick D-Pad Up" },
{ WII_NUNCHUK_DOWN | WII_WIIMOTE_DOWN, "Nunchuk Stick D-Pad Down" },
#endif
};
const unsigned int platform_keys_size = sizeof(platform_keys);
static bool g_quit;
static int16_t wii_input_state(void *data, const struct retro_keybind **binds,
@ -71,16 +132,12 @@ static int16_t wii_input_state(void *data, const struct retro_keybind **binds,
unsigned index, unsigned id)
{
(void)data;
(void)binds;
(void)index;
unsigned player = port;
if (port >= 4 || device != RETRO_DEVICE_JOYPAD)
return 0;
return pad_state[player][id]
#ifdef HW_RVL
|| wpad_state[player][id]
#endif
;
return (binds[port][id].joykey & pad_state[port]) ? 1 : 0;
}
static void wii_free_input(void *data)
@ -93,6 +150,32 @@ static void reset_callback(void)
g_quit = true;
}
void wii_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id)
{
// TODO: how do we choose a classic controller configuration over a gc controller one?
switch(map_dpad_enum)
{
case DPAD_EMULATION_NONE:
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = platform_keys[WII_DEVICE_GC_ID_JOYPAD_UP].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = platform_keys[WII_DEVICE_GC_ID_JOYPAD_DOWN].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = platform_keys[WII_DEVICE_GC_ID_JOYPAD_LEFT].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = platform_keys[WII_DEVICE_GC_ID_JOYPAD_RIGHT].joykey;
break;
case DPAD_EMULATION_LSTICK:
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = platform_keys[WII_DEVICE_GC_ID_LSTICK_UP_DPAD].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = platform_keys[WII_DEVICE_GC_ID_LSTICK_DOWN_DPAD].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = platform_keys[WII_DEVICE_GC_ID_LSTICK_LEFT_DPAD].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = platform_keys[WII_DEVICE_GC_ID_LSTICK_RIGHT_DPAD].joykey;
break;
case DPAD_EMULATION_RSTICK:
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = platform_keys[WII_DEVICE_GC_ID_RSTICK_UP_DPAD].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = platform_keys[WII_DEVICE_GC_ID_RSTICK_DOWN_DPAD].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = platform_keys[WII_DEVICE_GC_ID_RSTICK_LEFT_DPAD].joykey;
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = platform_keys[WII_DEVICE_GC_ID_RSTICK_RIGHT_DPAD].joykey;
break;
}
}
static void *wii_input_initialize(void)
{
PAD_Init();
@ -101,63 +184,178 @@ static void *wii_input_initialize(void)
#endif
SYS_SetResetCallback(reset_callback);
SYS_SetPowerCallback(reset_callback);
for(unsigned i = 0; i < 4; i++)
wii_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i);
return (void*)-1;
}
#define wii_stick_x(x) ((s8)((sin((x).ang * M_PI / 180.0f)) * (x).mag * 128.0f))
#define wii_stick_y(x) ((s8)((cos((x).ang * M_PI / 180.0f)) * (x).mag * 128.0f))
uint64_t wii_input_update(unsigned port)
{
unsigned pads = PAD_ScanPads();
#ifdef HW_RVL
unsigned wpads = WPAD_ScanPads();
#endif
uint64_t state = 0;
if (port < pads)
{
uint16_t down = PAD_ButtonsHeld(port) | PAD_ButtonsDown(port);
down &= ~PAD_ButtonsUp(port);
state |= (down & PAD_BUTTON_A) ? WII_GC_A : 0;
state |= (down & PAD_BUTTON_B) ? WII_GC_B : 0;
state |= (down & PAD_BUTTON_X) ? WII_GC_X : 0;
state |= (down & PAD_BUTTON_Y) ? WII_GC_Y : 0;
state |= (down & PAD_BUTTON_UP) ? WII_GC_UP : 0;
state |= (down & PAD_BUTTON_DOWN) ? WII_GC_DOWN : 0;
state |= (down & PAD_BUTTON_LEFT) ? WII_GC_LEFT : 0;
state |= (down & PAD_BUTTON_RIGHT) ? WII_GC_RIGHT : 0;
state |= (down & PAD_BUTTON_START) ? WII_GC_START : 0;
state |= (down & PAD_TRIGGER_Z) ? WII_GC_Z_TRIGGER : 0;
state |= (PAD_TriggerL(port) > 127) ? WII_GC_L_TRIGGER : 0;
state |= (PAD_TriggerR(port) > 127) ? WII_GC_R_TRIGGER : 0;
s8 x = PAD_StickX(port);
s8 y = PAD_StickY(port);
if (abs(x) > JOYSTICK_THRESHOLD)
{
state |= x > 0 ? WII_GC_LSTICK_RIGHT : WII_GC_LSTICK_LEFT;
}
if (abs(y) > JOYSTICK_THRESHOLD)
{
state |= y > 0 ? WII_GC_LSTICK_UP : WII_GC_LSTICK_DOWN;
}
x = PAD_SubStickX(port);
y = PAD_SubStickY(port);
if (abs(x) > JOYSTICK_THRESHOLD)
{
state |= x > 0 ? WII_GC_RSTICK_RIGHT : WII_GC_RSTICK_LEFT;
}
if (abs(y) > JOYSTICK_THRESHOLD)
{
state |= y > 0 ? WII_GC_RSTICK_UP : WII_GC_RSTICK_DOWN;
}
}
#ifdef HW_RVL
if (port < wpads)
{
uint32_t down = WPAD_ButtonsHeld(port) | WPAD_ButtonsDown(port);
down &= ~WPAD_ButtonsUp(port);
state |= (down & WPAD_BUTTON_A) ? WII_WIIMOTE_A : 0;
state |= (down & WPAD_BUTTON_B) ? WII_WIIMOTE_B : 0;
state |= (down & WPAD_BUTTON_1) ? WII_WIIMOTE_1 : 0;
state |= (down & WPAD_BUTTON_2) ? WII_WIIMOTE_2 : 0;
state |= (down & WPAD_BUTTON_PLUS) ? WII_WIIMOTE_PLUS : 0;
state |= (down & WPAD_BUTTON_MINUS) ? WII_WIIMOTE_MINUS : 0;
state |= (down & WPAD_BUTTON_HOME) ? WII_WIIMOTE_HOME : 0;
expansion_t exp;
WPAD_Expansion(port, &exp);
switch (exp.type)
{
case WPAD_EXP_NUNCHUK:
{
// wiimote is held upright with nunchuk, do not change d-pad orientation
state |= (down & WPAD_BUTTON_UP) ? WII_WIIMOTE_UP : 0;
state |= (down & WPAD_BUTTON_DOWN) ? WII_WIIMOTE_DOWN : 0;
state |= (down & WPAD_BUTTON_LEFT) ? WII_WIIMOTE_LEFT : 0;
state |= (down & WPAD_BUTTON_RIGHT) ? WII_WIIMOTE_RIGHT : 0;
state |= (down & WPAD_NUNCHUK_BUTTON_Z) ? WII_NUNCHUK_Z : 0;
state |= (down & WPAD_NUNCHUK_BUTTON_C) ? WII_NUNCHUK_C : 0;
s8 x = wii_stick_x(exp.nunchuk.js);
s8 y = wii_stick_y(exp.nunchuk.js);
if (abs(x) > JOYSTICK_THRESHOLD)
{
state |= x > 0 ? WII_NUNCHUK_RIGHT : WII_NUNCHUK_LEFT;
}
if (abs(y) > JOYSTICK_THRESHOLD)
{
state |= y > 0 ? WII_NUNCHUK_UP : WII_NUNCHUK_DOWN;
}
break;
}
case WPAD_EXP_CLASSIC:
{
state |= (down & WPAD_CLASSIC_BUTTON_A) ? WII_CLASSIC_A : 0;
state |= (down & WPAD_CLASSIC_BUTTON_B) ? WII_CLASSIC_B : 0;
state |= (down & WPAD_CLASSIC_BUTTON_X) ? WII_CLASSIC_X : 0;
state |= (down & WPAD_CLASSIC_BUTTON_Y) ? WII_CLASSIC_Y : 0;
state |= (down & WPAD_CLASSIC_BUTTON_PLUS) ? WII_CLASSIC_PLUS : 0;
state |= (down & WPAD_CLASSIC_BUTTON_MINUS) ? WII_CLASSIC_MINUS : 0;
state |= (down & WPAD_CLASSIC_BUTTON_HOME) ? WII_CLASSIC_HOME : 0;
state |= (down & WPAD_CLASSIC_BUTTON_FULL_L) ? WII_CLASSIC_L_TRIGGER : 0;
state |= (down & WPAD_CLASSIC_BUTTON_FULL_R) ? WII_CLASSIC_R_TRIGGER : 0;
state |= (down & WPAD_CLASSIC_BUTTON_ZL) ? WII_CLASSIC_ZL_TRIGGER : 0;
state |= (down & WPAD_CLASSIC_BUTTON_ZR) ? WII_CLASSIC_ZR_TRIGGER : 0;
s8 x = wii_stick_x(exp.classic.ljs);
s8 y = wii_stick_y(exp.classic.ljs);
if (abs(x) > JOYSTICK_THRESHOLD)
{
state |= x > 0 ? WII_CLASSIC_LSTICK_RIGHT : WII_CLASSIC_LSTICK_LEFT;
}
if (abs(y) > JOYSTICK_THRESHOLD)
{
state |= y > 0 ? WII_CLASSIC_LSTICK_UP : WII_CLASSIC_LSTICK_DOWN;
}
x = wii_stick_x(exp.classic.rjs);
y = wii_stick_y(exp.classic.rjs);
if (abs(x) > JOYSTICK_THRESHOLD)
{
state |= x > 0 ? WII_CLASSIC_RSTICK_RIGHT : WII_CLASSIC_RSTICK_LEFT;
}
if (abs(y) > JOYSTICK_THRESHOLD)
{
state |= y > 0 ? WII_CLASSIC_RSTICK_UP : WII_CLASSIC_RSTICK_DOWN;
}
// do not return, fall through for wiimote d-pad
}
default:
// rotated d-pad
state |= (down & WPAD_BUTTON_UP) ? WII_WIIMOTE_LEFT : 0;
state |= (down & WPAD_BUTTON_DOWN) ? WII_WIIMOTE_RIGHT : 0;
state |= (down & WPAD_BUTTON_LEFT) ? WII_WIIMOTE_DOWN : 0;
state |= (down & WPAD_BUTTON_RIGHT) ? WII_WIIMOTE_UP : 0;
break;
}
}
#endif
if ((state & (WII_GC_START | WII_GC_Z_TRIGGER | WII_GC_L_TRIGGER | WII_GC_R_TRIGGER)) == (WII_GC_START | WII_GC_Z_TRIGGER | WII_GC_L_TRIGGER | WII_GC_R_TRIGGER))
{
state |= WII_WIIMOTE_HOME;
}
if (port == 0 && g_quit)
{
state |= WII_WIIMOTE_HOME;
g_quit = false;
}
return state;
}
static void wii_input_poll(void *data)
{
(void)data;
unsigned pads = PAD_ScanPads();
#ifdef HW_RVL
unsigned wpads = WPAD_ScanPads();
#endif
/* Gamecube controller */
for (unsigned i = 0; i < pads; i++)
for (unsigned i = 0; i < 4; i++)
{
uint16_t down = PAD_ButtonsHeld(i) | PAD_ButtonsDown(i);
down &= ~PAD_ButtonsUp(i);
pad_state[i][RETRO_DEVICE_ID_JOYPAD_B] = down & PAD_BUTTON_B;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_Y] = down & PAD_BUTTON_Y;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_SELECT] = down & PAD_TRIGGER_Z;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_START] = down & PAD_BUTTON_START;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_UP] = down & PAD_BUTTON_UP;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_DOWN] = down & PAD_BUTTON_DOWN;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_LEFT] = down & PAD_BUTTON_LEFT;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_RIGHT] = down & PAD_BUTTON_RIGHT;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_A] = down & PAD_BUTTON_A;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_X] = down & PAD_BUTTON_X;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_L] = down & PAD_TRIGGER_L;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_R] = down & PAD_TRIGGER_R;
pad_state[i] = wii_input_update(i);
}
#ifdef HW_RVL
/* Wii Classic controller */
for (unsigned i = 0; i < wpads; i++)
{
uint32_t down = WPAD_ButtonsHeld(i) | WPAD_ButtonsDown(i);
down &= ~WPAD_ButtonsUp(i);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_B] = down & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_Y] = down & WPAD_CLASSIC_BUTTON_Y;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_SELECT] = down & (WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_START] = down & (WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_UP] = down & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_DOWN] = down & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_LEFT] = down & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_RIGHT] = down & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_A] = down & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A);
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_X] = down & WPAD_CLASSIC_BUTTON_X;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_L] = down & WPAD_CLASSIC_BUTTON_FULL_L;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_R] = down & WPAD_CLASSIC_BUTTON_FULL_R;
if (down & (WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME) && i == 0)
wpad_state[0][RETRO_DEVICE_ID_JOYPAD_L] = wpad_state[0][RETRO_DEVICE_ID_JOYPAD_R] =
wpad_state[0][RETRO_DEVICE_ID_JOYPAD_START] = wpad_state[0][RETRO_DEVICE_ID_JOYPAD_SELECT] = true;
}
#endif
}
static bool wii_key_pressed(void *data, int key)
@ -166,23 +364,7 @@ static bool wii_key_pressed(void *data, int key)
switch (key)
{
case RARCH_QUIT_KEY:
{
bool r = g_quit ||
(pad_state[0][RETRO_DEVICE_ID_JOYPAD_SELECT] &&
pad_state[0][RETRO_DEVICE_ID_JOYPAD_START] &&
pad_state[0][RETRO_DEVICE_ID_JOYPAD_L] &&
pad_state[0][RETRO_DEVICE_ID_JOYPAD_R])
#ifdef HW_RVL
||
(wpad_state[0][RETRO_DEVICE_ID_JOYPAD_SELECT] &&
wpad_state[0][RETRO_DEVICE_ID_JOYPAD_START] &&
wpad_state[0][RETRO_DEVICE_ID_JOYPAD_L] &&
wpad_state[0][RETRO_DEVICE_ID_JOYPAD_R])
#endif
;
g_quit = false;
return r;
}
return pad_state[0] & (WII_CLASSIC_HOME | WII_WIIMOTE_HOME) ? true : false;
default:
return false;
}
@ -190,6 +372,22 @@ static bool wii_key_pressed(void *data, int key)
static void wii_set_default_keybind_lut(void)
{
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_B].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_Y].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_Z_TRIGGER].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_START].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_UP].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_DOWN].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_LEFT].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_RIGHT].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_A].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_X].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_L_TRIGGER].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_R_TRIGGER].joykey;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = 0;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = 0;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = 0;
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = 0;
}
const input_driver_t input_wii = {

178
wii/wii_input.h Normal file
View File

@ -0,0 +1,178 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* Copyright (C) 2011-2012 - Michael Lelli
*
* 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/>.
*/
#ifndef _WII_INPUT_H
#define _WII_INPUT_H
enum
{
WII_GC_A = 1ULL << 0,
WII_GC_B = 1ULL << 1,
WII_GC_X = 1ULL << 2,
WII_GC_Y = 1ULL << 3,
WII_GC_START = 1ULL << 4,
WII_GC_Z_TRIGGER = 1ULL << 5,
WII_GC_L_TRIGGER = 1ULL << 6,
WII_GC_R_TRIGGER = 1ULL << 7,
WII_GC_UP = 1ULL << 8,
WII_GC_DOWN = 1ULL << 9,
WII_GC_LEFT = 1ULL << 10,
WII_GC_RIGHT = 1ULL << 11,
WII_GC_LSTICK_UP = 1ULL << 12,
WII_GC_LSTICK_DOWN = 1ULL << 13,
WII_GC_LSTICK_LEFT = 1ULL << 14,
WII_GC_LSTICK_RIGHT = 1ULL << 15,
WII_GC_RSTICK_UP = 1ULL << 16,
WII_GC_RSTICK_DOWN = 1ULL << 17,
WII_GC_RSTICK_LEFT = 1ULL << 18,
WII_GC_RSTICK_RIGHT = 1ULL << 19,
WII_CLASSIC_A = 1ULL << 20,
WII_CLASSIC_B = 1ULL << 21,
WII_CLASSIC_X = 1ULL << 22,
WII_CLASSIC_Y = 1ULL << 23,
WII_CLASSIC_PLUS = 1ULL << 24,
WII_CLASSIC_MINUS = 1ULL << 25,
WII_CLASSIC_HOME = 1ULL << 26,
WII_CLASSIC_L_TRIGGER = 1ULL << 27,
WII_CLASSIC_R_TRIGGER = 1ULL << 28,
WII_CLASSIC_ZL_TRIGGER = 1ULL << 29,
WII_CLASSIC_ZR_TRIGGER = 1ULL << 30,
WII_CLASSIC_UP = 1ULL << 31,
WII_CLASSIC_DOWN = 1ULL << 32,
WII_CLASSIC_LEFT = 1ULL << 33,
WII_CLASSIC_RIGHT = 1ULL << 34,
WII_CLASSIC_LSTICK_UP = 1ULL << 35,
WII_CLASSIC_LSTICK_DOWN = 1ULL << 36,
WII_CLASSIC_LSTICK_LEFT = 1ULL << 37,
WII_CLASSIC_LSTICK_RIGHT = 1ULL << 38,
WII_CLASSIC_RSTICK_UP = 1ULL << 39,
WII_CLASSIC_RSTICK_DOWN = 1ULL << 40,
WII_CLASSIC_RSTICK_LEFT = 1ULL << 41,
WII_CLASSIC_RSTICK_RIGHT = 1ULL << 42,
WII_WIIMOTE_A = 1ULL << 43,
WII_WIIMOTE_B = 1ULL << 44,
WII_WIIMOTE_1 = 1ULL << 45,
WII_WIIMOTE_2 = 1ULL << 46,
WII_WIIMOTE_PLUS = 1ULL << 47,
WII_WIIMOTE_MINUS = 1ULL << 48,
WII_WIIMOTE_HOME = 1ULL << 49,
WII_WIIMOTE_UP = 1ULL << 50,
WII_WIIMOTE_DOWN = 1ULL << 51,
WII_WIIMOTE_LEFT = 1ULL << 52,
WII_WIIMOTE_RIGHT = 1ULL << 53,
WII_NUNCHUK_Z = 1ULL << 54,
WII_NUNCHUK_C = 1ULL << 55,
WII_NUNCHUK_UP = 1ULL << 56,
WII_NUNCHUK_DOWN = 1ULL << 57,
WII_NUNCHUK_LEFT = 1ULL << 58,
WII_NUNCHUK_RIGHT = 1ULL << 59,
};
enum wii_device_id
{
WII_DEVICE_GC_ID_JOYPAD_A = 0,
WII_DEVICE_GC_ID_JOYPAD_B,
WII_DEVICE_GC_ID_JOYPAD_X,
WII_DEVICE_GC_ID_JOYPAD_Y,
WII_DEVICE_GC_ID_JOYPAD_UP,
WII_DEVICE_GC_ID_JOYPAD_DOWN,
WII_DEVICE_GC_ID_JOYPAD_LEFT,
WII_DEVICE_GC_ID_JOYPAD_RIGHT,
WII_DEVICE_GC_ID_JOYPAD_Z_TRIGGER,
WII_DEVICE_GC_ID_JOYPAD_START,
WII_DEVICE_GC_ID_JOYPAD_L_TRIGGER,
WII_DEVICE_GC_ID_JOYPAD_R_TRIGGER,
WII_DEVICE_GC_ID_LSTICK_LEFT,
WII_DEVICE_GC_ID_LSTICK_RIGHT,
WII_DEVICE_GC_ID_LSTICK_UP,
WII_DEVICE_GC_ID_LSTICK_DOWN,
WII_DEVICE_GC_ID_LSTICK_LEFT_DPAD,
WII_DEVICE_GC_ID_LSTICK_RIGHT_DPAD,
WII_DEVICE_GC_ID_LSTICK_UP_DPAD,
WII_DEVICE_GC_ID_LSTICK_DOWN_DPAD,
WII_DEVICE_GC_ID_RSTICK_LEFT,
WII_DEVICE_GC_ID_RSTICK_RIGHT,
WII_DEVICE_GC_ID_RSTICK_UP,
WII_DEVICE_GC_ID_RSTICK_DOWN,
WII_DEVICE_GC_ID_RSTICK_LEFT_DPAD,
WII_DEVICE_GC_ID_RSTICK_RIGHT_DPAD,
WII_DEVICE_GC_ID_RSTICK_UP_DPAD,
WII_DEVICE_GC_ID_RSTICK_DOWN_DPAD,
#ifdef HW_RVL
// CLASSIC CONTROLLER
WII_DEVICE_CLASSIC_ID_JOYPAD_A,
WII_DEVICE_CLASSIC_ID_JOYPAD_B,
WII_DEVICE_CLASSIC_ID_JOYPAD_X,
WII_DEVICE_CLASSIC_ID_JOYPAD_Y,
WII_DEVICE_CLASSIC_ID_JOYPAD_UP,
WII_DEVICE_CLASSIC_ID_JOYPAD_DOWN,
WII_DEVICE_CLASSIC_ID_JOYPAD_LEFT,
WII_DEVICE_CLASSIC_ID_JOYPAD_RIGHT,
WII_DEVICE_CLASSIC_ID_JOYPAD_PLUS,
WII_DEVICE_CLASSIC_ID_JOYPAD_MINUS,
WII_DEVICE_CLASSIC_ID_JOYPAD_HOME,
WII_DEVICE_CLASSIC_ID_JOYPAD_L_TRIGGER,
WII_DEVICE_CLASSIC_ID_JOYPAD_R_TRIGGER,
WII_DEVICE_CLASSIC_ID_JOYPAD_ZL_TRIGGER,
WII_DEVICE_CLASSIC_ID_JOYPAD_ZR_TRIGGER,
WII_DEVICE_CLASSIC_ID_LSTICK_LEFT,
WII_DEVICE_CLASSIC_ID_LSTICK_RIGHT,
WII_DEVICE_CLASSIC_ID_LSTICK_UP,
WII_DEVICE_CLASSIC_ID_LSTICK_DOWN,
WII_DEVICE_CLASSIC_ID_LSTICK_LEFT_DPAD,
WII_DEVICE_CLASSIC_ID_LSTICK_RIGHT_DPAD,
WII_DEVICE_CLASSIC_ID_LSTICK_UP_DPAD,
WII_DEVICE_CLASSIC_ID_LSTICK_DOWN_DPAD,
WII_DEVICE_CLASSIC_ID_RSTICK_LEFT,
WII_DEVICE_CLASSIC_ID_RSTICK_RIGHT,
WII_DEVICE_CLASSIC_ID_RSTICK_UP,
WII_DEVICE_CLASSIC_ID_RSTICK_DOWN,
WII_DEVICE_CLASSIC_ID_RSTICK_LEFT_DPAD,
WII_DEVICE_CLASSIC_ID_RSTICK_RIGHT_DPAD,
WII_DEVICE_CLASSIC_ID_RSTICK_UP_DPAD,
WII_DEVICE_CLASSIC_ID_RSTICK_DOWN_DPAD,
// WIIMOTE (PLUS OPTIONAL NUNCHUK)
WII_DEVICE_WIIMOTE_ID_JOYPAD_A,
WII_DEVICE_WIIMOTE_ID_JOYPAD_B,
WII_DEVICE_WIIMOTE_ID_JOYPAD_1,
WII_DEVICE_WIIMOTE_ID_JOYPAD_2,
WII_DEVICE_WIIMOTE_ID_JOYPAD_UP,
WII_DEVICE_WIIMOTE_ID_JOYPAD_DOWN,
WII_DEVICE_WIIMOTE_ID_JOYPAD_LEFT,
WII_DEVICE_WIIMOTE_ID_JOYPAD_RIGHT,
WII_DEVICE_WIIMOTE_ID_JOYPAD_PLUS,
WII_DEVICE_WIIMOTE_ID_JOYPAD_MINUS,
WII_DEVICE_WIIMOTE_ID_JOYPAD_HOME,
WII_DEVICE_WIIMOTE_ID_JOYPAD_Z,
WII_DEVICE_WIIMOTE_ID_JOYPAD_C,
WII_DEVICE_WIIMOTE_ID_LSTICK_LEFT,
WII_DEVICE_WIIMOTE_ID_LSTICK_RIGHT,
WII_DEVICE_WIIMOTE_ID_LSTICK_UP,
WII_DEVICE_WIIMOTE_ID_LSTICK_DOWN,
WII_DEVICE_WIIMOTE_ID_LSTICK_LEFT_DPAD,
WII_DEVICE_WIIMOTE_ID_LSTICK_RIGHT_DPAD,
WII_DEVICE_WIIMOTE_ID_LSTICK_UP_DPAD,
WII_DEVICE_WIIMOTE_ID_LSTICK_DOWN_DPAD,
#endif
RARCH_LAST_PLATFORM_KEY
};
uint64_t wii_input_update(unsigned port);
#endif