From a4065ae34dd8083c688f6f9b6e0385753c4d33d6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 25 Oct 2014 19:56:22 +0200 Subject: [PATCH] Split off input_context code into separate file --- Makefile | 5 ++ Makefile.common | 2 + griffin/griffin.c | 1 + input/input_common.c | 83 --------------------------------- input/input_common.h | 53 +-------------------- input/input_context.c | 104 ++++++++++++++++++++++++++++++++++++++++++ input/input_context.h | 69 ++++++++++++++++++++++++++++ 7 files changed, 182 insertions(+), 135 deletions(-) create mode 100644 input/input_context.c create mode 100644 input/input_context.h diff --git a/Makefile b/Makefile index 8134251bc6..0f0a305a32 100644 --- a/Makefile +++ b/Makefile @@ -124,6 +124,11 @@ $(OBJDIR)/tools/udev_joypad.o: input/udev_joypad.c @$(if $(Q), $(shell echo echo CC $<),) $(Q)$(CC) $(CFLAGS) $(DEFINES) -MMD -DIS_JOYCONFIG -c -o $@ $< +$(OBJDIR)/tools/input_context_joyconfig.o: input/input_context.c + @mkdir -p $(dir $@) + @$(if $(Q), $(shell echo echo CC $<),) + $(Q)$(CC) $(CFLAGS) $(DEFINES) -MMD -DIS_JOYCONFIG -c -o $@ $< + $(OBJDIR)/tools/input_common_joyconfig.o: input/input_common.c @mkdir -p $(dir $@) @$(if $(Q), $(shell echo echo CC $<),) diff --git a/Makefile.common b/Makefile.common index aaf34763e2..922d32353a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -111,6 +111,7 @@ OBJ += frontend/frontend.o \ gfx/gfx_common.o \ gfx/fonts/bitmapfont.o \ input/input_autodetect.o \ + input/input_context.o \ input/input_common.o \ input/keyboard_line.o \ input/overlay.o \ @@ -636,4 +637,5 @@ JOYCONFIG_OBJ += tools/retroarch-joyconfig.o \ libretro-sdk/file/file_path.o \ libretro-sdk/string/string_list.o \ libretro-sdk/compat/compat.o \ + tools/input_context_joyconfig.o \ tools/input_common_joyconfig.o diff --git a/griffin/griffin.c b/griffin/griffin.c index 5e66ba0cdf..8df9fbc417 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -281,6 +281,7 @@ FONTS INPUT ============================================================ */ #include "../input/input_autodetect.c" +#include "../input/input_context.c" #include "../input/input_common.c" #include "../input/keyboard_line.c" diff --git a/input/input_common.c b/input/input_common.c index a8405e1a60..6ab71f245c 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -49,89 +49,6 @@ #endif -rarch_joypad_driver_t *joypad_drivers[] = { -#ifdef __CELLOS_LV2__ - &ps3_joypad, -#endif -#ifdef HAVE_WINXINPUT - &winxinput_joypad, -#endif -#ifdef GEKKO - &gx_joypad, -#endif -#ifdef _XBOX - &xdk_joypad, -#endif -#ifdef PSP - &psp_joypad, -#endif -#ifdef HAVE_DINPUT - &dinput_joypad, -#endif -#ifdef HAVE_UDEV - &udev_joypad, -#endif -#if defined(__linux) && !defined(ANDROID) - &linuxraw_joypad, -#endif -#ifdef HAVE_PARPORT - &parport_joypad, -#endif -#ifdef ANDROID - &android_joypad, -#endif -#if defined(HAVE_SDL) || defined(HAVE_SDL2) - &sdl_joypad, -#endif -#ifdef __MACH__ -#ifdef HAVE_HID - &apple_hid_joypad, -#endif -#ifdef IOS - &apple_ios_joypad, -#endif -#endif -#ifdef __QNX__ - &qnx_joypad, -#endif - NULL, -}; - -const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident) -{ - unsigned i; - if (!ident || !*ident) - return input_joypad_init_first(); - - for (i = 0; joypad_drivers[i]; i++) - { - if (strcmp(ident, joypad_drivers[i]->ident) == 0 - && joypad_drivers[i]->init()) - { - RARCH_LOG("Found joypad driver: \"%s\".\n", - joypad_drivers[i]->ident); - return joypad_drivers[i]; - } - } - - return input_joypad_init_first(); -} - -const rarch_joypad_driver_t *input_joypad_init_first(void) -{ - unsigned i; - for (i = 0; joypad_drivers[i]; i++) - { - if (joypad_drivers[i]->init()) - { - RARCH_LOG("Found joypad driver: \"%s\".\n", - joypad_drivers[i]->ident); - return joypad_drivers[i]; - } - } - - return NULL; -} const char *input_joypad_name(const rarch_joypad_driver_t *drv, unsigned joypad) diff --git a/input/input_common.h b/input/input_common.h index 83ac2d480e..ac01e4ae70 100644 --- a/input/input_common.h +++ b/input/input_common.h @@ -17,6 +17,7 @@ #define INPUT_COMMON_H__ #include "input_autodetect.h" +#include "input_context.h" #include "../driver.h" #include #include "../general.h" @@ -55,23 +56,6 @@ static inline void input_conv_analog_id_to_bind_id(unsigned idx, unsigned ident, } } -#if 0 -static inline bool get_bit(const uint8_t *buf, unsigned bit) -{ - return buf[bit >> 3] & (1 << (bit & 7)); -} - -static inline void clear_bit(uint8_t *buf, unsigned bit) -{ - buf[bit >> 3] &= ~(1 << (bit & 7)); -} - -static inline void set_bit(uint8_t *buf, unsigned bit) -{ - buf[bit >> 3] |= 1 << (bit & 7); -} -#endif - bool input_translate_coord_viewport(int mouse_x, int mouse_y, int16_t *res_x, int16_t *res_y, int16_t *res_screen_x, int16_t *res_screen_y); @@ -85,26 +69,6 @@ enum back_button_enums }; #endif -struct rarch_joypad_driver -{ - bool (*init)(void); - bool (*query_pad)(unsigned); - void (*destroy)(void); - bool (*button)(unsigned, uint16_t); - int16_t (*axis)(unsigned, uint32_t); - void (*poll)(void); - bool (*set_rumble)(unsigned, enum retro_rumble_effect, uint16_t); - const char *(*name)(unsigned); - - const char *ident; -}; - -/* If ident points to NULL or a zero-length string, - * equivalent to calling input_joypad_init_first(). */ -const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident); - -const rarch_joypad_driver_t *input_joypad_init_first(void); - bool input_joypad_pressed(const rarch_joypad_driver_t *driver, unsigned port, const struct retro_keybind *binds, unsigned key); @@ -127,21 +91,6 @@ bool input_joypad_hat_raw(const rarch_joypad_driver_t *driver, const char *input_joypad_name(const rarch_joypad_driver_t *driver, unsigned joypad); -extern rarch_joypad_driver_t dinput_joypad; -extern rarch_joypad_driver_t linuxraw_joypad; -extern rarch_joypad_driver_t parport_joypad; -extern rarch_joypad_driver_t udev_joypad; -extern rarch_joypad_driver_t winxinput_joypad; -extern rarch_joypad_driver_t sdl_joypad; -extern rarch_joypad_driver_t ps3_joypad; -extern rarch_joypad_driver_t psp_joypad; -extern rarch_joypad_driver_t xdk_joypad; -extern rarch_joypad_driver_t gx_joypad; -extern rarch_joypad_driver_t apple_hid_joypad; -extern rarch_joypad_driver_t apple_ios_joypad; -extern rarch_joypad_driver_t android_joypad; -extern rarch_joypad_driver_t qnx_joypad; - struct rarch_key_map { unsigned sym; diff --git a/input/input_context.c b/input/input_context.c new file mode 100644 index 0000000000..b57c32d485 --- /dev/null +++ b/input/input_context.c @@ -0,0 +1,104 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - Daniel De Matteis + * + * 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 . + */ + +#include "input_context.h" +#include +#include +#include "../general.h" + +rarch_joypad_driver_t *joypad_drivers[] = { +#ifdef __CELLOS_LV2__ + &ps3_joypad, +#endif +#ifdef HAVE_WINXINPUT + &winxinput_joypad, +#endif +#ifdef GEKKO + &gx_joypad, +#endif +#ifdef _XBOX + &xdk_joypad, +#endif +#ifdef PSP + &psp_joypad, +#endif +#ifdef HAVE_DINPUT + &dinput_joypad, +#endif +#ifdef HAVE_UDEV + &udev_joypad, +#endif +#if defined(__linux) && !defined(ANDROID) + &linuxraw_joypad, +#endif +#ifdef HAVE_PARPORT + &parport_joypad, +#endif +#ifdef ANDROID + &android_joypad, +#endif +#if defined(HAVE_SDL) || defined(HAVE_SDL2) + &sdl_joypad, +#endif +#ifdef __MACH__ +#ifdef HAVE_HID + &apple_hid_joypad, +#endif +#ifdef IOS + &apple_ios_joypad, +#endif +#endif +#ifdef __QNX__ + &qnx_joypad, +#endif + NULL, +}; + +const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident) +{ + unsigned i; + if (!ident || !*ident) + return input_joypad_init_first(); + + for (i = 0; joypad_drivers[i]; i++) + { + if (strcmp(ident, joypad_drivers[i]->ident) == 0 + && joypad_drivers[i]->init()) + { + RARCH_LOG("Found joypad driver: \"%s\".\n", + joypad_drivers[i]->ident); + return joypad_drivers[i]; + } + } + + return input_joypad_init_first(); +} + +const rarch_joypad_driver_t *input_joypad_init_first(void) +{ + unsigned i; + for (i = 0; joypad_drivers[i]; i++) + { + if (joypad_drivers[i]->init()) + { + RARCH_LOG("Found joypad driver: \"%s\".\n", + joypad_drivers[i]->ident); + return joypad_drivers[i]; + } + } + + return NULL; +} diff --git a/input/input_context.h b/input/input_context.h new file mode 100644 index 0000000000..3461373743 --- /dev/null +++ b/input/input_context.h @@ -0,0 +1,69 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - Daniel De Matteis + * + * 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 . + */ + +#ifndef INPUT_CONTEXT_H__ +#define INPUT_CONTEXT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef struct rarch_joypad_driver rarch_joypad_driver_t; +enum retro_rumble_effect; + +struct rarch_joypad_driver +{ + bool (*init)(void); + bool (*query_pad)(unsigned); + void (*destroy)(void); + bool (*button)(unsigned, uint16_t); + int16_t (*axis)(unsigned, uint32_t); + void (*poll)(void); + bool (*set_rumble)(unsigned, enum retro_rumble_effect, uint16_t); + const char *(*name)(unsigned); + + const char *ident; +}; + +/* If ident points to NULL or a zero-length string, + * equivalent to calling input_joypad_init_first(). */ +const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident); + +const rarch_joypad_driver_t *input_joypad_init_first(void); + +extern rarch_joypad_driver_t dinput_joypad; +extern rarch_joypad_driver_t linuxraw_joypad; +extern rarch_joypad_driver_t parport_joypad; +extern rarch_joypad_driver_t udev_joypad; +extern rarch_joypad_driver_t winxinput_joypad; +extern rarch_joypad_driver_t sdl_joypad; +extern rarch_joypad_driver_t ps3_joypad; +extern rarch_joypad_driver_t psp_joypad; +extern rarch_joypad_driver_t xdk_joypad; +extern rarch_joypad_driver_t gx_joypad; +extern rarch_joypad_driver_t apple_hid_joypad; +extern rarch_joypad_driver_t apple_ios_joypad; +extern rarch_joypad_driver_t android_joypad; +extern rarch_joypad_driver_t qnx_joypad; + +#ifdef __cplusplus +} +#endif + +#endif