2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2012-07-26 21:11:52 +00:00
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2012 - Daniel De Matteis
|
2012-07-26 21:07:47 +00:00
|
|
|
* Copyright (C) 2012 - Michael Lelli
|
2011-12-14 12:20:22 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-12-14 12:20:22 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-12-14 12:20:22 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-12-14 12:20:22 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <ogc/pad.h>
|
2012-04-11 02:25:55 +00:00
|
|
|
#ifdef HW_RVL
|
2012-01-03 11:11:02 +00:00
|
|
|
#include <wiiuse/wpad.h>
|
2012-04-11 02:25:55 +00:00
|
|
|
#endif
|
2012-01-03 11:11:02 +00:00
|
|
|
#include <string.h>
|
2012-07-26 05:28:57 +00:00
|
|
|
#include <math.h>
|
2011-12-14 12:20:22 +00:00
|
|
|
|
2012-07-26 05:28:57 +00:00
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI 3.14159265358979323846264338327
|
|
|
|
#endif
|
|
|
|
|
2012-07-26 21:11:52 +00:00
|
|
|
#include "gx_input.h"
|
2011-12-14 12:20:22 +00:00
|
|
|
#include "../driver.h"
|
2012-04-09 23:00:25 +00:00
|
|
|
#include "../libretro.h"
|
2011-12-14 12:20:22 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-07-26 05:28:57 +00:00
|
|
|
#define JOYSTICK_THRESHOLD 64
|
2012-04-11 02:22:41 +00:00
|
|
|
|
2012-07-26 05:28:57 +00:00
|
|
|
static uint64_t pad_state[4];
|
2012-04-11 02:22:41 +00:00
|
|
|
|
2012-07-25 17:35:21 +00:00
|
|
|
const struct platform_bind platform_keys[] = {
|
2012-07-26 07:20:28 +00:00
|
|
|
{ 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" },
|
|
|
|
|
2012-07-25 17:35:21 +00:00
|
|
|
#ifdef HW_RVL
|
2012-07-26 07:20:28 +00:00
|
|
|
// 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" },
|
2012-07-25 17:35:21 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
const unsigned int platform_keys_size = sizeof(platform_keys);
|
2011-12-14 12:20:22 +00:00
|
|
|
static bool g_quit;
|
|
|
|
|
2012-07-07 15:19:32 +00:00
|
|
|
static int16_t wii_input_state(void *data, const struct retro_keybind **binds,
|
2012-04-09 23:00:25 +00:00
|
|
|
unsigned port, unsigned device,
|
2011-12-14 12:20:22 +00:00
|
|
|
unsigned index, unsigned id)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)index;
|
|
|
|
|
2012-07-26 05:28:57 +00:00
|
|
|
if (port >= 4 || device != RETRO_DEVICE_JOYPAD)
|
|
|
|
return 0;
|
2011-12-14 12:20:22 +00:00
|
|
|
|
2012-07-26 05:28:57 +00:00
|
|
|
return (binds[port][id].joykey & pad_state[port]) ? 1 : 0;
|
2011-12-14 12:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wii_free_input(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_callback(void)
|
|
|
|
{
|
|
|
|
g_quit = true;
|
|
|
|
}
|
|
|
|
|
2012-07-26 05:28:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-28 03:06:25 +00:00
|
|
|
static void *wii_input_initialize(void)
|
2011-12-14 12:20:22 +00:00
|
|
|
{
|
2012-01-07 23:57:44 +00:00
|
|
|
PAD_Init();
|
2012-04-11 02:25:55 +00:00
|
|
|
#ifdef HW_RVL
|
2012-01-07 23:57:44 +00:00
|
|
|
WPAD_Init();
|
2012-04-11 02:25:55 +00:00
|
|
|
#endif
|
2012-01-07 23:57:44 +00:00
|
|
|
SYS_SetResetCallback(reset_callback);
|
|
|
|
SYS_SetPowerCallback(reset_callback);
|
2012-07-26 05:28:57 +00:00
|
|
|
for(unsigned i = 0; i < 4; i++)
|
|
|
|
wii_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i);
|
2011-12-14 12:20:22 +00:00
|
|
|
return (void*)-1;
|
|
|
|
}
|
|
|
|
|
2012-07-26 05:28:57 +00:00
|
|
|
#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))
|
2011-12-14 12:20:22 +00:00
|
|
|
|
2012-07-26 21:07:47 +00:00
|
|
|
static void wii_input_poll(void *data)
|
2012-07-26 05:28:57 +00:00
|
|
|
{
|
2012-07-26 21:07:47 +00:00
|
|
|
(void)data;
|
|
|
|
|
2011-12-14 12:20:22 +00:00
|
|
|
unsigned pads = PAD_ScanPads();
|
2012-04-11 02:25:55 +00:00
|
|
|
#ifdef HW_RVL
|
2012-01-03 11:11:02 +00:00
|
|
|
unsigned wpads = WPAD_ScanPads();
|
2012-04-11 02:25:55 +00:00
|
|
|
#endif
|
2012-07-26 05:28:57 +00:00
|
|
|
|
2012-07-26 21:07:47 +00:00
|
|
|
for (unsigned port = 0; port < 4; port++)
|
2012-01-03 11:11:02 +00:00
|
|
|
{
|
2012-07-26 21:07:47 +00:00
|
|
|
uint64_t state = 0;
|
|
|
|
if (port < pads)
|
2012-07-26 05:28:57 +00:00
|
|
|
{
|
2012-07-26 21:07:47 +00:00
|
|
|
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)
|
2012-07-26 05:28:57 +00:00
|
|
|
{
|
2012-07-26 21:07:47 +00:00
|
|
|
state |= x > 0 ? WII_GC_LSTICK_RIGHT : WII_GC_LSTICK_LEFT;
|
2012-07-26 05:28:57 +00:00
|
|
|
}
|
2012-07-26 21:07:47 +00:00
|
|
|
if (abs(y) > JOYSTICK_THRESHOLD)
|
2012-07-26 05:28:57 +00:00
|
|
|
{
|
2012-07-26 21:07:47 +00:00
|
|
|
state |= y > 0 ? WII_GC_LSTICK_UP : WII_GC_LSTICK_DOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = PAD_SubStickX(port);
|
|
|
|
y = PAD_SubStickY(port);
|
2012-07-26 05:28:57 +00:00
|
|
|
|
2012-07-26 21:07:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 05:28:57 +00:00
|
|
|
|
2012-07-26 21:07:47 +00:00
|
|
|
#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:
|
2012-07-26 05:28:57 +00:00
|
|
|
{
|
2012-07-26 21:07:47 +00:00
|
|
|
// 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;
|
2012-07-26 05:28:57 +00:00
|
|
|
}
|
2012-07-26 21:07:47 +00:00
|
|
|
case WPAD_EXP_CLASSIC:
|
2012-07-26 05:28:57 +00:00
|
|
|
{
|
2012-07-26 21:07:47 +00:00
|
|
|
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
|
2012-07-26 05:28:57 +00:00
|
|
|
}
|
2012-07-26 21:07:47 +00:00
|
|
|
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;
|
2012-07-26 05:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-11 02:25:55 +00:00
|
|
|
#endif
|
2012-07-26 05:28:57 +00:00
|
|
|
|
2012-07-26 21:07:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-07-26 05:28:57 +00:00
|
|
|
|
2012-07-26 21:07:47 +00:00
|
|
|
pad_state[port] = state;
|
2012-07-26 05:28:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 21:07:47 +00:00
|
|
|
if (g_quit)
|
2012-07-26 05:28:57 +00:00
|
|
|
{
|
2012-07-26 21:07:47 +00:00
|
|
|
pad_state[0] |= WII_WIIMOTE_HOME;
|
|
|
|
g_quit = false;
|
2012-07-26 05:28:57 +00:00
|
|
|
}
|
2012-01-03 11:11:02 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 12:20:22 +00:00
|
|
|
static bool wii_key_pressed(void *data, int key)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
switch (key)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_QUIT_KEY:
|
2012-07-26 05:28:57 +00:00
|
|
|
return pad_state[0] & (WII_CLASSIC_HOME | WII_WIIMOTE_HOME) ? true : false;
|
2011-12-14 12:20:22 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-25 19:02:01 +00:00
|
|
|
static void wii_set_default_keybind_lut(void)
|
|
|
|
{
|
2012-07-26 07:20:28 +00:00
|
|
|
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;
|
2012-07-25 19:02:01 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 20:44:03 +00:00
|
|
|
const input_driver_t input_wii = {
|
2012-01-07 23:57:44 +00:00
|
|
|
.init = wii_input_initialize,
|
2011-12-14 12:20:22 +00:00
|
|
|
.poll = wii_input_poll,
|
|
|
|
.input_state = wii_input_state,
|
|
|
|
.key_pressed = wii_key_pressed,
|
|
|
|
.free = wii_free_input,
|
2012-07-25 19:02:01 +00:00
|
|
|
.set_default_keybind_lut = wii_set_default_keybind_lut,
|
2011-12-14 12:20:22 +00:00
|
|
|
.ident = "wii",
|
|
|
|
};
|