diff --git a/config.def.h b/config.def.h index bb975a5de5..cbc7ed69d8 100644 --- a/config.def.h +++ b/config.def.h @@ -58,6 +58,7 @@ #define INPUT_X 12 #define INPUT_PS3 19 #define INPUT_XENON360 21 +#define INPUT_WII 23 //////////////////////// #if defined(HAVE_OPENGL) || defined(__CELLOS_LV2__) @@ -112,6 +113,8 @@ #define INPUT_DEFAULT_DRIVER INPUT_PS3 #elif defined(XENON) #define INPUT_DEFAULT_DRIVER INPUT_XENON360 +#elif defined(GEKKO) +#define INPUT_DEFAULT_DRIVER INPUT_WII #elif defined(HAVE_XVIDEO) #define INPUT_DEFAULT_DRIVER INPUT_X #else diff --git a/driver.h b/driver.h index 2da3862213..450c8234c0 100644 --- a/driver.h +++ b/driver.h @@ -178,6 +178,7 @@ extern const input_driver_t input_sdl; extern const input_driver_t input_x; extern const input_driver_t input_ps3; extern const input_driver_t input_xenon360; +extern const input_driver_t input_wii; //////////////////////////////////////////////// #endif diff --git a/ps3/ps3_audio.c b/ps3/ps3_audio.c index e010b04e6c..59c840e5c6 100644 --- a/ps3/ps3_audio.c +++ b/ps3/ps3_audio.c @@ -1,5 +1,5 @@ /* SSNES - A Super Ninteno Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010 - Hans-Kristian Arntzen + * Copyright (C) 2010-2011 - Hans-Kristian Arntzen * Copyright (C) 2011 - Daniel De Matteis * * Some code herein may be based on code found in BSNES. diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index 3db8b90ad0..9e2070aa6a 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -1,5 +1,5 @@ /* SSNES - A Super Ninteno Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010 - Hans-Kristian Arntzen + * Copyright (C) 2010-2011 - Hans-Kristian Arntzen * Copyright (C) 2011 - Daniel De Matteis * * Some code herein may be based on code found in BSNES. @@ -126,10 +126,8 @@ static bool ps3_key_pressed(void *data, int key) case SSNES_REWIND: return CTRL_RSTICK_DOWN(state[0]) && CTRL_R2(~state[0]); default: - break; + return false; } - - return false; } const input_driver_t input_ps3 = { diff --git a/settings.c b/settings.c index 653d976f42..9a1710ac59 100644 --- a/settings.c +++ b/settings.c @@ -122,6 +122,9 @@ static void set_defaults(void) case INPUT_XENON360: def_input = "xenon360"; break; + case INPUT_WII: + def_input = "wii"; + break; default: break; } diff --git a/wii/input.c b/wii/input.c new file mode 100644 index 0000000000..039983b63c --- /dev/null +++ b/wii/input.c @@ -0,0 +1,119 @@ +/* SSNES - A Super Ninteno Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2011 - Hans-Kristian Arntzen + * + * Some code herein may be based on code found in BSNES. + * + * SSNES 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. + * + * SSNES 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 SSNES. + * If not, see . + */ + +#include +#include +#include + +#include "../driver.h" +#include "../libsnes.hpp" +#include + +// Just plain pads for now. +static bool pad_state[5][SSNES_FIRST_META_KEY]; +static bool g_quit; + +static int16_t wii_input_state(void *data, const struct snes_keybind **binds, + bool port, unsigned device, + unsigned index, unsigned id) +{ + (void)data; + (void)binds; + (void)index; + + if (device != SNES_DEVICE_JOYPAD) + return 0; + + unsigned player = 0; + if (port == SNES_PORT_2 && device == SNES_DEVICE_MULTITAP) + player = index + 1; + else if (port == SNES_PORT_2) + player = 1; + + return pad_state[player][id]; +} + +static void wii_free_input(void *data) +{ + (void)data; +} + +static void reset_callback(void) +{ + g_quit = true; +} + +static void *wii_input_init(void) +{ + static bool inited = false; + if (!inited) + { + SYS_SetResetCallback(reset_callback); + SYS_SetPowerCallback(reset_callback); + PAD_Init(); + } + return (void*)-1; +} + +#define _B(btn) pad_state[i][SNES_DEVICE_ID_JOYPAD_##btn] = down & PAD_BUTTON##btn + +static void wii_input_poll(void *data) +{ + (void)data; + + unsigned pads = PAD_ScanPads(); + for (unsigned i = 0; i < pads; i++) + { + uint16_t down = PAD_ButtonsDown(i); + _B(B); + _B(Y); + pad_state[i][SNES_DEVICE_ID_JOYPAD_SELECT] = down & PAD_BUTTON_Z; + _B(START); + _B(UP); + _B(DOWN); + _B(LEFT); + _B(RIGHT); + _B(A); + _B(X); + _B(L); + _B(R); + } +} + +#undef _B + +static bool wii_key_pressed(void *data, int key) +{ + (void)data; + switch (key) + { + case SSNES_QUIT_KEY: + return g_quit; + default: + return false; + } +} + +const input_driver_t input_ps3 = { + .init = wii_input_init, + .poll = wii_input_poll, + .input_state = wii_input_state, + .key_pressed = wii_key_pressed, + .free = wii_free_input, + .ident = "wii", +}; +