RetroArch/wii/input.c

154 lines
4.9 KiB
C
Raw Normal View History

2012-04-21 21:13:50 +00:00
/* RetroArch - A frontend for libretro.
2012-01-08 00:08:18 +00:00
* Copyright (C) 2012 - Hans-Kristian Arntzen
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>
#ifdef HW_RVL
2012-01-03 11:11:02 +00:00
#include <wiiuse/wpad.h>
#endif
2012-01-03 11:11:02 +00:00
#include <string.h>
2011-12-14 12:20:22 +00:00
#include "../driver.h"
#include "../libretro.h"
2011-12-14 12:20:22 +00:00
#include <stdlib.h>
2012-04-21 21:25:32 +00:00
static bool pad_state[5][RARCH_FIRST_META_KEY]; /* Gamecube pads */
#ifdef HW_RVL
2012-04-21 21:25:32 +00:00
static bool wpad_state[5][RARCH_FIRST_META_KEY]; /* Wii Classic pads */
#endif
2012-04-11 02:22:41 +00:00
2011-12-14 12:20:22 +00:00
static bool g_quit;
static int16_t wii_input_state(void *data, const struct snes_keybind **binds,
unsigned port, unsigned device,
2011-12-14 12:20:22 +00:00
unsigned index, unsigned id)
{
(void)data;
(void)binds;
(void)index;
unsigned player = port;
2011-12-14 12:20:22 +00:00
2012-01-03 11:11:02 +00:00
return pad_state[player][id] || wpad_state[player][id];
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-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();
#ifdef HW_RVL
2012-01-07 23:57:44 +00:00
WPAD_Init();
#endif
2012-01-07 23:57:44 +00:00
SYS_SetResetCallback(reset_callback);
SYS_SetPowerCallback(reset_callback);
2011-12-14 12:20:22 +00:00
return (void*)-1;
}
static void wii_input_poll(void *data)
{
(void)data;
unsigned pads = PAD_ScanPads();
#ifdef HW_RVL
2012-01-03 11:11:02 +00:00
unsigned wpads = WPAD_ScanPads();
#endif
2012-04-11 02:22:41 +00:00
/* Gamecube controller */
2011-12-14 12:20:22 +00:00
for (unsigned i = 0; i < pads; i++)
{
2012-01-03 11:11:02 +00:00
uint16_t down = PAD_ButtonsHeld(i) | PAD_ButtonsDown(i);
down &= ~PAD_ButtonsUp(i);
2012-04-11 02:22:41 +00:00
pad_state[i][RETRO_DEVICE_ID_JOYPAD_B] = down & PAD_BUTTON_B;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_Y] = down & PAD_BUTTON_Y;
2012-04-10 01:14:21 +00:00
pad_state[i][RETRO_DEVICE_ID_JOYPAD_SELECT] = down & PAD_TRIGGER_Z;
2012-04-11 02:22:41 +00:00
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;
2012-04-10 01:14:21 +00:00
pad_state[i][RETRO_DEVICE_ID_JOYPAD_L] = down & PAD_TRIGGER_L;
pad_state[i][RETRO_DEVICE_ID_JOYPAD_R] = down & PAD_TRIGGER_R;
2011-12-14 12:20:22 +00:00
}
#ifdef HW_RVL
2012-04-11 02:22:41 +00:00
/* Wii Classic controller */
2012-01-03 11:11:02 +00:00
for (unsigned i = 0; i < wpads; i++)
{
uint32_t down = WPAD_ButtonsHeld(i) | WPAD_ButtonsDown(i);
down &= ~WPAD_ButtonsUp(i);
2012-04-11 02:22:41 +00:00
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_B] = down & WPAD_CLASSIC_BUTTON_B;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_Y] = down & WPAD_CLASSIC_BUTTON_Y;
2012-04-10 01:14:21 +00:00
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_SELECT] = down & WPAD_CLASSIC_BUTTON_MINUS;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_START] = down & WPAD_CLASSIC_BUTTON_PLUS;
2012-04-11 02:22:41 +00:00
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_UP] = down & WPAD_CLASSIC_BUTTON_UP;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_DOWN] = down & WPAD_CLASSIC_BUTTON_DOWN;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_LEFT] = down & WPAD_CLASSIC_BUTTON_LEFT;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_RIGHT] = down & WPAD_CLASSIC_BUTTON_RIGHT;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_A] = down & WPAD_CLASSIC_BUTTON_A;
wpad_state[i][RETRO_DEVICE_ID_JOYPAD_X] = down & WPAD_CLASSIC_BUTTON_X;
2012-04-10 01:14:21 +00:00
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;
2012-01-03 11:11:02 +00:00
}
#endif
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-01-03 10:32:07 +00:00
return g_quit ||
2012-04-10 01:14:21 +00:00
(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
||
2012-04-10 01:14:21 +00:00
(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
;
2011-12-14 12:20:22 +00:00
default:
return false;
}
}
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,
.ident = "wii",
};