From 757fa714699c4051f7d52cccd96bf8bbcc4b10ed Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Wed, 14 Dec 2011 01:35:17 +0100 Subject: [PATCH] (Libxenon) Added (non-working) input driver --- Makefile.xenon | 4 +- config.def.h | 3 + driver.c | 3 + driver.h | 1 + settings.c | 3 + xenon/xenon360_input.c | 150 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 xenon/xenon360_input.c diff --git a/Makefile.xenon b/Makefile.xenon index 51a59612e4..6cab4bc55c 100644 --- a/Makefile.xenon +++ b/Makefile.xenon @@ -18,11 +18,11 @@ PPU_TARGET_ADJUSTED := ssnes-libxenon.elf32 LDDIRS = -L. -L$(DEVKITXENON)/usr/lib -L$(DEVKITXENON)/xenon/lib/32 INCDIRS = -I. -I$(DEVKITXENON)/usr/include -I$(DEVKITXENON)/usr/include/SDL -OBJ = fifo_buffer.o ssnes.o driver.o file.o settings.o message.o rewind.o movie.o input/sdl.o audio/sdl.o gfx/sdl.o gfx/sdlwrap.o gfx/gfx_common.o ups.o bps.o strl.o screenshot.o audio/hermite.o dynamic.o audio/utils.o conf/config_file.o xenon/cond.o xenon/main.o xenon/xenon360_audio.o +OBJ = fifo_buffer.o ssnes.o driver.o file.o settings.o message.o rewind.o movie.o input/sdl.o audio/sdl.o gfx/sdl.o gfx/sdlwrap.o gfx/gfx_common.o ups.o bps.o strl.o screenshot.o audio/hermite.o dynamic.o audio/utils.o conf/config_file.o xenon/cond.o xenon/main.o xenon/xenon360_audio.o xenon/xenon360_input.o LIBS = -lsnes -lSDL -lxenon -lm -lc DEFINES = -std=gnu99 -DHAVE_CONFIGFILE=1 -DHAVE_SDL=1 -DPACKAGE_VERSION=\"0.9.3\" -DHAVE_GETOPT_LONG=1 -Dmain=ssnes_main -DEFINES += -mno-altivec -mhard-float -m32 -mpowerpc64 -mcpu=cell -mtune=cell -fno-pic -g -Wall -DSDL -DXENON $(INCDIRS) +DEFINES += -maltivec -mhard-float -m32 -mpowerpc64 -mcpu=cell -mtune=cell -fno-pic -g -Wall -DSDL -DXENON $(INCDIRS) DEFINES += -u read -u _start -u exc_base ifeq ($(DEBUG), 1) diff --git a/config.def.h b/config.def.h index 8991ee10bb..a32521a05d 100644 --- a/config.def.h +++ b/config.def.h @@ -56,6 +56,7 @@ #define INPUT_SDL 7 #define INPUT_X 12 #define INPUT_PS3 19 +#define INPUT_XENON360 21 //////////////////////// #if defined(HAVE_OPENGL) || defined(__CELLOS_LV2__) @@ -106,6 +107,8 @@ #define INPUT_DEFAULT_DRIVER INPUT_SDL #elif defined(__CELLOS_LV2__) #define INPUT_DEFAULT_DRIVER INPUT_PS3 +#elif defined(XENON) +#define INPUT_DEFAULT_DRIVER INPUT_XENON360 #elif defined(HAVE_XVIDEO) #define INPUT_DEFAULT_DRIVER INPUT_X #else diff --git a/driver.c b/driver.c index 89eca67f25..1b97379a4b 100644 --- a/driver.c +++ b/driver.c @@ -98,6 +98,9 @@ static const input_driver_t *input_drivers[] = { #ifdef HAVE_XVIDEO &input_x, #endif +#ifdef XENON + &input_xenon360, +#endif }; static void find_audio_driver(void) diff --git a/driver.h b/driver.h index ddeb724478..e78b24aed2 100644 --- a/driver.h +++ b/driver.h @@ -176,6 +176,7 @@ extern const video_driver_t video_ext; 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; //////////////////////////////////////////////// #endif diff --git a/settings.c b/settings.c index d0a4c2f6c7..d2b5c2f99e 100644 --- a/settings.c +++ b/settings.c @@ -115,6 +115,9 @@ static void set_defaults(void) case INPUT_X: def_input = "x"; break; + case INPUT_XENON360: + def_input = "xenon360"; + break; default: break; } diff --git a/xenon/xenon360_input.c b/xenon/xenon360_input.c new file mode 100644 index 0000000000..4d514c9f0a --- /dev/null +++ b/xenon/xenon360_input.c @@ -0,0 +1,150 @@ +/* SSNES - A Super Ninteno Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2010 - Hans-Kristian Arntzen + * Copyright (C) 2011 - Daniel De Matteis + * + * 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 "../driver.h" +#include +#include "../libsnes.hpp" + +#include +#include + +#include + +struct controller_data_s pad[5]; + +static void xenon360_input_poll(void *data) +{ + (void)data; + for (unsigned i = 0; i < 5; i++) + { + usb_poll(); + get_controller_data(&pad[i], i); + } +} + +static int16_t xenon360_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; + + uint64_t button = 0; + + // Hardcoded binds. + switch (id) + { + case SNES_DEVICE_ID_JOYPAD_A: + button = pad[player].b ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_B: + button = pad[player].a ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_X: + button = pad[player].y ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_Y: + button = pad[player].x ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_LEFT: + button = pad[player].left ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_RIGHT: + button = pad[player].right ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_UP: + button = pad[player].up ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_DOWN: + button = pad[player].down ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_START: + button = pad[player].start ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_SELECT: + button = pad[player].select ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_L: + button = pad[player].lt ? 1 : 0; + break; + case SNES_DEVICE_ID_JOYPAD_R: + button = pad[player].rt ? 1 : 0; + break; + default: + button = 0; + } + + return button; +} + +static void xenon360_free_input(void *data) +{ + (void)data; +} + +static void* xenon360_input_init(void) +{ + return (void*)-1; +} + +static bool xenon360_key_pressed(void *data, int key) +{ + (void)data; + #if 0 + switch (key) + { + case SSNES_FAST_FORWARD_HOLD_KEY: + return CTRL_RSTICK_UP(state[0]) && CTRL_R2(~state[0]); + case SSNES_LOAD_STATE_KEY: + return (CTRL_RSTICK_UP(state[0]) && CTRL_R2(state[0])); + case SSNES_SAVE_STATE_KEY: + return (CTRL_RSTICK_DOWN(state[0]) && CTRL_R2(state[0])); + case SSNES_STATE_SLOT_PLUS: + return (CTRL_RSTICK_RIGHT(state[0]) && CTRL_R2(state[0])); + case SSNES_STATE_SLOT_MINUS: + return (CTRL_RSTICK_LEFT(state[0]) && CTRL_R2(state[0])); + case SSNES_REWIND: + return CTRL_RSTICK_DOWN(state[0]) && CTRL_R2(~state[0]); + default: + break; + } + #endif + + return false; +} + +const input_driver_t input_xenon360 = { + .init = xenon360_input_init, + .poll = xenon360_input_poll, + .input_state = xenon360_input_state, + .key_pressed = xenon360_key_pressed, + .free = xenon360_free_input, + .ident = "xenon360", +}; +