From 4c69dad0ce95fecab5ba3584f3fbb3268791dab2 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 19 Jul 2019 12:55:38 +0200 Subject: [PATCH] Define DEFAULT_MAX_PADS inside config.def.h - get rid of the messy MAX_PADS macros everywhere --- config.def.h | 40 +++++++++++++++++++ frontend/drivers/platform_unix.h | 10 ++--- gfx/common/win32_common.c | 6 --- input/drivers/android_input.c | 10 +++-- input/drivers/ctr_input.c | 2 - input/drivers/dos_input.c | 6 ++- input/drivers/gx_input.c | 8 ++-- input/drivers/ps3_input.c | 4 -- input/drivers/qnx_input.c | 27 ++++++------- input/drivers/switch_input.c | 6 +-- input/drivers/wiiu_input.c | 10 ++--- input/drivers/xdk_xinput_input.c | 6 +-- input/drivers/xenon360_input.c | 10 ++--- input/drivers_joypad/android_joypad.c | 6 ++- input/drivers_joypad/ctr_joypad.c | 12 +++--- input/drivers_joypad/dos_joypad.c | 6 ++- input/drivers_joypad/gx_joypad.c | 24 +++++------ input/drivers_joypad/ps2_joypad.c | 19 ++++----- input/drivers_joypad/ps3_joypad.c | 20 +++++----- input/drivers_joypad/psp_joypad.c | 24 +++++------ input/drivers_joypad/qnx_joypad.c | 6 ++- input/drivers_joypad/switch_joypad.c | 40 +++++++------------ input/drivers_joypad/xdk_joypad.c | 14 ++++--- input/drivers_joypad/xinput_joypad.c | 5 ++- .../drivers_keyboard/keyboard_event_android.h | 6 --- input/drivers_keyboard/keyboard_event_dos.h | 8 +--- input/input_keymaps.c | 2 + 27 files changed, 173 insertions(+), 164 deletions(-) diff --git a/config.def.h b/config.def.h index 86ceb1d755..1e34eb37d5 100644 --- a/config.def.h +++ b/config.def.h @@ -53,6 +53,46 @@ #define DEFAULT_ASPECT_RATIO -1.0f #endif +#if defined(ANDROID) +#define DEFAULT_MAX_PADS 8 +#define ANDROID_KEYBOARD_PORT DEFAULT_MAX_PADS +#elif defined(_3DS) +#define DEFAULT_MAX_PADS 1 +#elif defined(SWITCH) || defined(HAVE_LIBNX) +#define DEFAULT_MAX_PADS 8 +#elif defined(WIIU) +#ifdef WIIU_HID +#define DEFAULT_MAX_PADS 16 +#else +#define DEFAULT_MAX_PADS 5 +#endif +#elif defined(DJGPP) +#define DEFAULT_MAX_PADS 1 +#define DOS_KEYBOARD_PORT DEFAULT_MAX_PADS +#elif defined(XENON) +#define DEFAULT_MAX_PADS 4 +#elif defined(VITA) || defined(SN_TARGET_PSP2) +#define DEFAULT_MAX_PADS 4 +#elif defined(PSP) +#define DEFAULT_MAX_PADS 1 +#elif defined(PS2) +#define DEFAULT_MAX_PADS 2 +#elif defined(GEKKO) || defined(HW_RVL) +#define DEFAULT_MAX_PADS 4 +#elif defined(__linux__) || (defined(BSD) && !defined(__MACH__)) +#define DEFAULT_MAX_PADS 8 +#elif defined(__QNX__) +#define DEFAULT_MAX_PADS 8 +#elif defined(__CELLOS_LV2__) +#define DEFAULT_MAX_PADS 7 +#elif defined(_XBOX) +#define DEFAULT_MAX_PADS 4 +#elif defined(HAVE_XINPUT) && !defined(HAVE_DINPUT) +#define DEFAULT_MAX_PADS 4 +#else +#define DEFAULT_MAX_PADS 16 +#endif + #if defined(RARCH_MOBILE) || defined(HAVE_LIBNX) #define DEFAULT_POINTER_ENABLE true #else diff --git a/frontend/drivers/platform_unix.h b/frontend/drivers/platform_unix.h index 0252e3993d..75f5578967 100644 --- a/frontend/drivers/platform_unix.h +++ b/frontend/drivers/platform_unix.h @@ -22,9 +22,7 @@ #include -#ifndef MAX_PADS -#define MAX_PADS 8 -#endif +#include "../../config.def.h" #ifndef MAX_AXIS #define MAX_AXIS 10 @@ -43,6 +41,8 @@ #include +#include "../../config.def.h" + bool test_permissions(const char *path); char internal_storage_path[PATH_MAX_LENGTH]; @@ -144,8 +144,8 @@ struct android_app uint64_t sensor_state_mask; char current_ime[PATH_MAX_LENGTH]; bool input_alive; - int16_t analog_state[MAX_PADS][MAX_AXIS]; - int8_t hat_state[MAX_PADS][2]; + int16_t analog_state[DEFAULT_MAX_PADS][MAX_AXIS]; + int8_t hat_state[DEFAULT_MAX_PADS][2]; jmethodID getIntent; jmethodID onRetroArchExit; jmethodID getStringExtra; diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index 1f5515829f..3fffc9e97e 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -105,12 +105,6 @@ extern void *dinput_wgl; extern void *dinput; #endif -#if defined(HAVE_XINPUT) && !defined(HAVE_DINPUT) -#ifndef MAX_PADS -#define MAX_PADS 4 -#endif -#endif - typedef struct DISPLAYCONFIG_RATIONAL_CUSTOM { UINT32 Numerator; UINT32 Denominator; diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 026dabc0e4..16cd5ea066 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -29,6 +29,8 @@ #include "../../config.h" #endif +#include "../../config.def.h" + #ifdef HAVE_MENU #include "../../menu/menu_driver.h" #endif @@ -81,7 +83,7 @@ enum { /* First ports are used to keep track of gamepad states. * Last port is used for keyboard state */ -static uint8_t android_key_state[MAX_PADS+1][MAX_KEYS]; +static uint8_t android_key_state[DEFAULT_MAX_PADS + 1][MAX_KEYS]; #define android_keyboard_port_input_pressed(binds, id) (BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], rarch_keysym_lut[(binds)[(id)].key])) @@ -96,7 +98,7 @@ static void android_keyboard_free(void) { unsigned i, j; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) for (j = 0; j < MAX_KEYS; j++) android_key_state[i][j] = 0; } @@ -956,7 +958,7 @@ static void handle_hotplug(android_input_t *android, RARCH_LOG("Device model: (%s).\n", device_model); - if (*port > MAX_PADS) + if (*port > DEFAULT_MAX_PADS) { RARCH_ERR("Max number of pads reached.\n"); return; @@ -1348,7 +1350,7 @@ static void android_input_poll_memcpy(android_input_t *android) unsigned i, j; struct android_app *android_app = (struct android_app*)g_android; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) { for (j = 0; j < 2; j++) android_app->hat_state[i][j] = android->hat_state[i][j]; diff --git a/input/drivers/ctr_input.c b/input/drivers/ctr_input.c index 9187d699ca..950b538dba 100644 --- a/input/drivers/ctr_input.c +++ b/input/drivers/ctr_input.c @@ -27,8 +27,6 @@ #include "../input_driver.h" -#define MAX_PADS 1 - /* TODO/FIXME - * fix game focus toggle */ diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index c5a67a4952..f346b689a6 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -20,6 +20,8 @@ #include +#include "../../config.def.h" + #include "../input_driver.h" #include "../input_keymaps.h" #include "../drivers_keyboard/keyboard_event_dos.h" @@ -35,7 +37,7 @@ typedef struct dos_input #define MAX_KEYS LAST_KEYCODE + 1 /* First ports are used to keeping track of gamepad states. Last port is used for keyboard state */ -static uint16_t dos_key_state[MAX_PADS+1][MAX_KEYS]; +static uint16_t dos_key_state[DEFAULT_MAX_PADS+1][MAX_KEYS]; static bool dos_keyboard_port_input_pressed( const struct retro_keybind *binds, unsigned id) @@ -54,7 +56,7 @@ static void dos_keyboard_free(void) { unsigned i, j; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) for (j = 0; j < MAX_KEYS; j++) dos_key_state[i][j] = 0; } diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index e5e25a03cf..40d585fc44 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -25,11 +25,9 @@ #include -#include "../input_driver.h" +#include "../../config.def.h" -#ifndef MAX_PADS -#define MAX_PADS 4 -#endif +#include "../input_driver.h" /* TODO/FIXME - * fix game focus toggle */ @@ -49,7 +47,7 @@ static int16_t gx_input_state(void *data, gx_input_t *gx = (gx_input_t*)data; int16_t ret = 0; - if (port >= MAX_PADS || !gx) + if (port >= DEFAULT_MAX_PADS || !gx) return 0; switch (device) diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 9cb6f89ba0..7fbe1bf183 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -36,10 +36,6 @@ #endif #endif -#ifndef __PSL1GHT__ -#define MAX_PADS 7 -#endif - /* TODO/FIXME - * fix game focus toggle */ diff --git a/input/drivers/qnx_input.c b/input/drivers/qnx_input.c index aa61f13bdb..78681f82ff 100644 --- a/input/drivers/qnx_input.c +++ b/input/drivers/qnx_input.c @@ -27,6 +27,8 @@ #include "../../config.h" #endif +#include "../../config.def.h" + #include "../input_driver.h" #include "../../retroarch.h" @@ -34,8 +36,6 @@ #include "../../command.h" -#define MAX_PADS 8 - #ifdef HAVE_BB10 #define MAX_TOUCH 16 #else @@ -72,6 +72,10 @@ struct input_pointer int map; }; +#define QNX_MAX_KEYS (65535 + 7) / 8 +#define TRACKPAD_CPI 500 +#define TRACKPAD_THRESHOLD TRACKPAD_CPI / 2 + typedef struct qnx_input { bool blocked; @@ -86,16 +90,13 @@ typedef struct qnx_input unsigned pointer_count; int touch_map[MAX_TOUCH]; - qnx_input_device_t devices[MAX_PADS]; + qnx_input_device_t devices[DEFAULT_MAX_PADS]; const input_device_driver_t *joypad; -#define QNX_MAX_KEYS (65535 + 7) / 8 uint8_t keyboard_state[QNX_MAX_KEYS]; - uint64_t pad_state[MAX_PADS]; + uint64_t pad_state[DEFAULT_MAX_PADS]; -#define TRACKPAD_CPI 500 -#define TRACKPAD_THRESHOLD TRACKPAD_CPI / 2 int trackpad_acc[2]; } qnx_input_t; @@ -143,7 +144,7 @@ static void qnx_process_gamepad_event( screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device); - for (i = 0; i < MAX_PADS; ++i) + for (i = 0; i < DEFAULT_MAX_PADS; ++i) { if (device == qnx->devices[i].handle) { @@ -343,7 +344,7 @@ static void qnx_discover_controllers(qnx_input_t *qnx) qnx->devices[qnx->pads_connected].index = qnx->pads_connected; qnx_handle_device(qnx, &qnx->devices[qnx->pads_connected]); - if (qnx->pads_connected == MAX_PADS) + if (qnx->pads_connected == DEFAULT_MAX_PADS) break; } } @@ -563,7 +564,7 @@ static void qnx_handle_screen_event(qnx_input_t *qnx, bps_event_t *event) type == SCREEN_EVENT_KEYBOARD) ) { - for (i = 0; i < MAX_PADS; ++i) + for (i = 0; i < DEFAULT_MAX_PADS; ++i) { if (!qnx->devices[i].handle) { @@ -575,7 +576,7 @@ static void qnx_handle_screen_event(qnx_input_t *qnx, bps_event_t *event) } else { - for (i = 0; i < MAX_PADS; ++i) + for (i = 0; i < DEFAULT_MAX_PADS; ++i) { if (device == qnx->devices[i].handle) { @@ -679,10 +680,8 @@ static void *qnx_input_init(const char *joypad_driver) qnx->joypad = input_joypad_init_driver(joypad_driver, qnx); - for (i = 0; i < MAX_PADS; ++i) - { + for (i = 0; i < DEFAULT_MAX_PADS; ++i) qnx_init_controller(qnx, &qnx->devices[i]); - } #ifdef HAVE_BB10 qnx_discover_controllers(qnx); diff --git a/input/drivers/switch_input.c b/input/drivers/switch_input.c index 066a1c332c..8a29ed3d75 100644 --- a/input/drivers/switch_input.c +++ b/input/drivers/switch_input.c @@ -9,6 +9,8 @@ #include "../../config.h" #endif +#include "../../config.def.h" + #include "../../retroarch.h" #ifdef HAVE_LIBNX @@ -81,8 +83,6 @@ typedef struct #include "../input_driver.h" #include "../input_keymaps.h" -#define MAX_PADS 10 - /* TODO/FIXME - * fix game focus toggle */ @@ -376,7 +376,7 @@ static int16_t switch_input_state(void *data, int16_t ret = 0; switch_input_t *sw = (switch_input_t*) data; - if (port > MAX_PADS-1) + if (port > DEFAULT_MAX_PADS - 1) return 0; switch (device) diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index fae0945f99..385561ad53 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -28,17 +28,13 @@ #include "../../config.h" #endif +#include "../../config.def.h" + #include "../input_driver.h" #include "../input_keymaps.h" #include "wiiu_dbg.h" -#ifdef WIIU_HID -#define MAX_PADS 16 -#else -#define MAX_PADS 5 -#endif - static uint8_t keyboardChannel = 0x00; static bool keyboardState[RETROK_LAST] = { 0 }; @@ -136,7 +132,7 @@ static int16_t wiiu_input_state(void *data, int16_t ret = 0; wiiu_input_t *wiiu = (wiiu_input_t*)data; - if(!wiiu || !(port < MAX_PADS) || !binds || !binds[port]) + if(!wiiu || !(port < DEFAULT_MAX_PADS) || !binds || !binds[port]) return 0; switch (device) diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index 641715e9ab..f203f1683a 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -28,9 +28,9 @@ #include #include -#include "../input_driver.h" +#include "../../config.def.h" -#define MAX_PADS 4 +#include "../input_driver.h" /* TODO/FIXME - * fix game focus toggle */ @@ -58,7 +58,7 @@ static int16_t xdk_input_state(void *data, int16_t ret = 0; xdk_input_t *xdk = (xdk_input_t*)data; - if (port >= MAX_PADS) + if (port >= DEFAULT_MAX_PADS) return 0; switch (device) diff --git a/input/drivers/xenon360_input.c b/input/drivers/xenon360_input.c index bf81e21bd2..2cf8d6b5a2 100644 --- a/input/drivers/xenon360_input.c +++ b/input/drivers/xenon360_input.c @@ -23,19 +23,19 @@ #include -#include "../input_driver.h" +#include "../../config.def.h" -#define MAX_PADS 4 +#include "../input_driver.h" /* TODO/FIXME - * fix game focus toggle */ -static uint64_t state[MAX_PADS]; +static uint64_t state[DEFAULT_MAX_PADS]; static void xenon360_input_poll(void *data) { (void)data; - for (unsigned i = 0; i < MAX_PADS; i++) + for (unsigned i = 0; i < DEFAULT_MAX_PADS; i++) { struct controller_data_s pad; usb_do_poll(); @@ -67,7 +67,7 @@ static int16_t xenon360_input_state(void *data, int16_t ret = 0; uint64_t button = binds[port][id].joykey; - if (port >= MAX_PADS) + if (port >= DEFAULT_MAX_PADS) return 0; switch (device) diff --git a/input/drivers_joypad/android_joypad.c b/input/drivers_joypad/android_joypad.c index fa1b8e3596..164007b263 100644 --- a/input/drivers_joypad/android_joypad.c +++ b/input/drivers_joypad/android_joypad.c @@ -15,6 +15,8 @@ * If not, see . */ +#include "../../config.def.h" + #include "../input_driver.h" #include "../drivers_keyboard/keyboard_event_android.h" @@ -34,7 +36,7 @@ static bool android_joypad_button(unsigned port, uint16_t joykey) struct android_app *android_app = (struct android_app*)g_android; unsigned hat_dir = GET_HAT_DIR(joykey); - if (port >= MAX_PADS) + if (port >= DEFAULT_MAX_PADS) return false; if (hat_dir) @@ -99,7 +101,7 @@ static void android_joypad_destroy(void) unsigned i, j; struct android_app *android_app = (struct android_app*)g_android; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) { for (j = 0; j < 2; j++) android_app->hat_state[i][j] = 0; diff --git a/input/drivers_joypad/ctr_joypad.c b/input/drivers_joypad/ctr_joypad.c index 8f60c9d6fd..1a3473c9a0 100644 --- a/input/drivers_joypad/ctr_joypad.c +++ b/input/drivers_joypad/ctr_joypad.c @@ -18,6 +18,8 @@ #include "../../config.h" #endif +#include "../../config.def.h" + #include "../input_driver.h" #include "../../tasks/tasks_internal.h" @@ -27,10 +29,6 @@ #include "string.h" #include "3ds.h" -#ifndef MAX_PADS -#define MAX_PADS 1 -#endif - static uint32_t pad_state; static int16_t analog_state[1][2][2]; extern uint64_t lifecycle_state; @@ -63,7 +61,7 @@ static bool ctr_joypad_init(void *data) static bool ctr_joypad_button(unsigned port_num, uint16_t key) { - if (port_num >= MAX_PADS) + if (port_num >= DEFAULT_MAX_PADS) return false; return (pad_state & (1 << key)); @@ -71,7 +69,7 @@ static bool ctr_joypad_button(unsigned port_num, uint16_t key) static void ctr_joypad_get_buttons(unsigned port_num, input_bits_t *state) { - if ( port_num < MAX_PADS ) + if (port_num < DEFAULT_MAX_PADS) { BITS_COPY16_PTR( state, pad_state ); } @@ -86,7 +84,7 @@ static int16_t ctr_joypad_axis(unsigned port_num, uint32_t joyaxis) bool is_neg = false; bool is_pos = false; - if (joyaxis == AXIS_NONE || port_num >= MAX_PADS) + if (joyaxis == AXIS_NONE || port_num >= DEFAULT_MAX_PADS) return 0; if (AXIS_NEG_GET(joyaxis) < 4) diff --git a/input/drivers_joypad/dos_joypad.c b/input/drivers_joypad/dos_joypad.c index 4d4dc455c1..658aa6c731 100644 --- a/input/drivers_joypad/dos_joypad.c +++ b/input/drivers_joypad/dos_joypad.c @@ -26,6 +26,8 @@ #include +#include "../../config.def.h" + #include "../input_driver.h" #include "../input_keymaps.h" #include "../../tasks/tasks_internal.h" @@ -176,7 +178,7 @@ static bool dos_joypad_button(unsigned port_num, uint16_t key) { uint16_t *buf = dos_keyboard_state_get(port_num); - if (port_num >= MAX_PADS) + if (port_num >= DEFAULT_MAX_PADS) return false; switch (key) @@ -210,7 +212,7 @@ static void dos_joypad_poll(void) { uint32_t i; - for (i = 0; i <= MAX_PADS; i++) + for (i = 0; i <= DEFAULT_MAX_PADS; i++) { uint16_t *cur_state = dos_keyboard_state_get(i); uint32_t key; diff --git a/input/drivers_joypad/gx_joypad.c b/input/drivers_joypad/gx_joypad.c index f58301f941..5af82e6113 100644 --- a/input/drivers_joypad/gx_joypad.c +++ b/input/drivers_joypad/gx_joypad.c @@ -21,6 +21,8 @@ #include #endif +#include "../../config.def.h" + #include "../../tasks/tasks_internal.h" #ifdef GEKKO @@ -39,10 +41,6 @@ #define NUM_DEVICES 1 #endif -#ifndef MAX_PADS -#define MAX_PADS 4 -#endif - enum { GX_GC_A = 0, @@ -99,9 +97,9 @@ enum #define WII_JOYSTICK_THRESHOLD (40 * 256) extern uint64_t lifecycle_state; -static uint64_t pad_state[MAX_PADS]; -static uint32_t pad_type[MAX_PADS] = { WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER }; -static int16_t analog_state[MAX_PADS][2][2]; +static uint64_t pad_state[DEFAULT_MAX_PADS]; +static uint32_t pad_type[DEFAULT_MAX_PADS] = { WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER }; +static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; static bool g_menu = false; #ifdef HW_RVL @@ -154,14 +152,14 @@ static void handle_hotplug(unsigned port, uint32_t ptype) static bool gx_joypad_button(unsigned port, uint16_t key) { - if (port >= MAX_PADS) + if (port >= DEFAULT_MAX_PADS) return false; return (pad_state[port] & (UINT64_C(1) << key)); } static void gx_joypad_get_buttons(unsigned port, input_bits_t *state) { - if (port < MAX_PADS) + if (port < DEFAULT_MAX_PADS) { BITS_COPY16_PTR( state, pad_state[port] ); } @@ -176,7 +174,7 @@ static int16_t gx_joypad_axis(unsigned port, uint32_t joyaxis) bool is_neg = false; bool is_pos = false; - if (joyaxis == AXIS_NONE || port >= MAX_PADS) + if (joyaxis == AXIS_NONE || port >= DEFAULT_MAX_PADS) return 0; if (AXIS_NEG_GET(joyaxis) < 4) @@ -333,7 +331,7 @@ static void gx_joypad_poll(void) WPAD_ReadPending(WPAD_CHAN_ALL, NULL); #endif - for (port = 0; port < MAX_PADS; port++) + for (port = 0; port < DEFAULT_MAX_PADS; port++) { uint32_t down = 0, ptype = WPAD_EXP_NOCONTROLLER; uint64_t *state_cur = &pad_state[port]; @@ -478,7 +476,7 @@ static bool gx_joypad_init(void *data) (void)data; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) pad_type[i] = WPAD_EXP_NOCONTROLLER; PAD_Init(); @@ -501,7 +499,7 @@ static void gx_joypad_destroy(void) #ifdef HW_RVL #if 0 int i; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) { /* Commenting this out fixes the Wii * remote not reconnecting after diff --git a/input/drivers_joypad/ps2_joypad.c b/input/drivers_joypad/ps2_joypad.c index dc40b6d787..6ea578d310 100644 --- a/input/drivers_joypad/ps2_joypad.c +++ b/input/drivers_joypad/ps2_joypad.c @@ -17,19 +17,20 @@ #include #include +#include "../../config.def.h" + #include "../input_driver.h" #include "libpad.h" -#define PS2_MAX_PADS 2 #define PS2_PAD_SLOT 0 /* Always zero if not using multitap */ #define PS2_ANALOG_STICKS 2 #define PS2_ANALOG_AXIS 2 static unsigned char padBuf[2][256] ALIGNED(64); -static uint64_t pad_state[PS2_MAX_PADS]; -static int16_t analog_state[PS2_MAX_PADS][PS2_ANALOG_STICKS][PS2_ANALOG_AXIS]; +static uint64_t pad_state[DEFAULT_MAX_PADS]; +static int16_t analog_state[DEFAULT_MAX_PADS][PS2_ANALOG_STICKS][PS2_ANALOG_AXIS]; extern uint64_t lifecycle_state; @@ -64,7 +65,7 @@ static bool ps2_joypad_init(void *data) printf("PortMax: %d\n", padGetPortMax()); printf("SlotMax: %d\n", padGetSlotMax(port)); - for (port = 0; port < PS2_MAX_PADS; port++) + for (port = 0; port < DEFAULT_MAX_PADS; port++) { input_autoconfigure_connect( ps2_joypad_name(port), NULL, @@ -87,7 +88,7 @@ static bool ps2_joypad_init(void *data) static bool ps2_joypad_button(unsigned port_num, uint16_t joykey) { - if (port_num >= PS2_MAX_PADS) + if (port_num >= DEFAULT_MAX_PADS) return false; return (pad_state[port_num] & (UINT64_C(1) << joykey)); @@ -105,7 +106,7 @@ static int16_t ps2_joypad_axis(unsigned port_num, uint32_t joyaxis) bool is_neg = false; bool is_pos = false; - if (joyaxis == AXIS_NONE || port_num >= PS2_MAX_PADS) + if (joyaxis == AXIS_NONE || port_num >= DEFAULT_MAX_PADS) return 0; if (AXIS_NEG_GET(joyaxis) < 4) @@ -148,7 +149,7 @@ static void ps2_joypad_poll(void) unsigned player; struct padButtonStatus buttons; - for (player = 0; player < PS2_MAX_PADS; player++) + for (player = 0; player < DEFAULT_MAX_PADS; player++) { int state = padGetState(player, PS2_PAD_SLOT); if (state == PAD_STATE_STABLE) @@ -193,7 +194,7 @@ static void ps2_joypad_poll(void) static bool ps2_joypad_query_pad(unsigned pad) { - return pad < PS2_MAX_PADS && pad_state[pad]; + return pad < DEFAULT_MAX_PADS && pad_state[pad]; } static bool ps2_joypad_rumble(unsigned pad, @@ -205,7 +206,7 @@ static bool ps2_joypad_rumble(unsigned pad, static void ps2_joypad_destroy(void) { unsigned port; - for (port = 0; port < PS2_MAX_PADS; port++) + for (port = 0; port < DEFAULT_MAX_PADS; port++) padPortClose(port, PS2_PAD_SLOT); } diff --git a/input/drivers_joypad/ps3_joypad.c b/input/drivers_joypad/ps3_joypad.c index cee170603e..9847e2c62f 100644 --- a/input/drivers_joypad/ps3_joypad.c +++ b/input/drivers_joypad/ps3_joypad.c @@ -17,13 +17,15 @@ #include #include +#include "../../config.def.h" + #include "../../tasks/tasks_internal.h" -static uint64_t pad_state[MAX_PADS]; -static int16_t analog_state[MAX_PADS][2][2]; -static uint64_t pads_connected[MAX_PADS]; +static uint64_t pad_state[DEFAULT_MAX_PADS]; +static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; +static uint64_t pads_connected[DEFAULT_MAX_PADS]; #if 0 -sensor_t accelerometer_state[MAX_PADS]; +sensor_t accelerometer_state[DEFAULT_MAX_PADS]; #endif static INLINE int16_t convert_u8_to_s16(uint8_t val) @@ -54,14 +56,14 @@ static bool ps3_joypad_init(void *data) { (void)data; - cellPadInit(MAX_PADS); + cellPadInit(DEFAULT_MAX_PADS); return true; } static bool ps3_joypad_button(unsigned port_num, uint16_t joykey) { - if (port_num >= MAX_PADS) + if (port_num >= DEFAULT_MAX_PADS) return false; return pad_state[port_num] & (UINT64_C(1) << joykey); @@ -69,7 +71,7 @@ static bool ps3_joypad_button(unsigned port_num, uint16_t joykey) static void ps3_joypad_get_buttons(unsigned port_num, input_bits_t *state) { - if (port_num < MAX_PADS) + if (port_num < DEFAULT_MAX_PADS) { BITS_COPY16_PTR( state, pad_state[port_num] ); } @@ -84,7 +86,7 @@ static int16_t ps3_joypad_axis(unsigned port_num, uint32_t joyaxis) bool is_neg = false; bool is_pos = false; - if (joyaxis == AXIS_NONE || port_num >= MAX_PADS) + if (joyaxis == AXIS_NONE || port_num >= DEFAULT_MAX_PADS) return 0; if (AXIS_NEG_GET(joyaxis) < 4) @@ -129,7 +131,7 @@ static void ps3_joypad_poll(void) cellPadGetInfo2(&pad_info); - for (port = 0; port < MAX_PADS; port++) + for (port = 0; port < DEFAULT_MAX_PADS; port++) { CellPadData state_tmp; diff --git a/input/drivers_joypad/psp_joypad.c b/input/drivers_joypad/psp_joypad.c index 40cade7047..47712cd8a0 100644 --- a/input/drivers_joypad/psp_joypad.c +++ b/input/drivers_joypad/psp_joypad.c @@ -33,10 +33,9 @@ #include #include #include -#define PSP_MAX_PADS 4 static int psp2_model; static SceCtrlPortInfo old_ctrl_info, curr_ctrl_info; -static SceCtrlActuator actuators[PSP_MAX_PADS] = {0}; +static SceCtrlActuator actuators[DEFAULT_MAX_PADS] = {0}; #define LERP(p, f, t) ((((p * 10) * (t * 10)) / (f * 10)) / 10) #define AREA(lx, ly, rx, ry, x, y) (lx <= x && x < rx && ly <= y && y < ry) @@ -51,13 +50,8 @@ static SceCtrlActuator actuators[PSP_MAX_PADS] = {0}; #define SW_AREA(x, y) AREA(0, SCREEN_HALF_HEIGHT, SCREEN_HALF_WIDTH, SCREEN_HEIGHT, (x), (y)) #define SE_AREA(x, y) AREA(SCREEN_HALF_WIDTH, SCREEN_HALF_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, (x), (y)) -#elif defined(SN_TARGET_PSP2) -#define PSP_MAX_PADS 4 -#else -#define PSP_MAX_PADS 1 -#endif -static uint64_t pad_state[PSP_MAX_PADS]; -static int16_t analog_state[PSP_MAX_PADS][2][2]; +static uint64_t pad_state[DEFAULT_MAX_PADS]; +static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; extern uint64_t lifecycle_state; @@ -84,7 +78,7 @@ static const char *psp_joypad_name(unsigned pad) static bool psp_joypad_init(void *data) { unsigned i; - unsigned players_count = PSP_MAX_PADS; + unsigned players_count = DEFAULT_MAX_PADS; (void)data; @@ -115,7 +109,7 @@ static bool psp_joypad_init(void *data) static bool psp_joypad_button(unsigned port_num, uint16_t key) { - if (port_num >= PSP_MAX_PADS) + if (port_num >= DEFAULT_MAX_PADS) return false; return (pad_state[port_num] & (UINT64_C(1) << key)); @@ -123,7 +117,7 @@ static bool psp_joypad_button(unsigned port_num, uint16_t key) static void psp_joypad_get_buttons(unsigned port_num, input_bits_t *state) { - if (port_num < PSP_MAX_PADS) + if (port_num < DEFAULT_MAX_PADS) { BITS_COPY16_PTR( state, pad_state[port_num] ); } @@ -138,7 +132,7 @@ static int16_t psp_joypad_axis(unsigned port_num, uint32_t joyaxis) bool is_neg = false; bool is_pos = false; - if (joyaxis == AXIS_NONE || port_num >= PSP_MAX_PADS) + if (joyaxis == AXIS_NONE || port_num >= DEFAULT_MAX_PADS) return 0; if (AXIS_NEG_GET(joyaxis) < 4) @@ -179,7 +173,7 @@ static int16_t psp_joypad_axis(unsigned port_num, uint32_t joyaxis) static void psp_joypad_poll(void) { unsigned player; - unsigned players_count = PSP_MAX_PADS; + unsigned players_count = DEFAULT_MAX_PADS; #if defined(VITA) settings_t *settings = config_get_ptr(); #endif @@ -319,7 +313,7 @@ static void psp_joypad_poll(void) static bool psp_joypad_query_pad(unsigned pad) { - return pad < PSP_MAX_PADS && pad_state[pad]; + return pad < DEFAULT_MAX_PADS && pad_state[pad]; } static bool psp_joypad_rumble(unsigned pad, diff --git a/input/drivers_joypad/qnx_joypad.c b/input/drivers_joypad/qnx_joypad.c index 8f516f12f1..586093607e 100644 --- a/input/drivers_joypad/qnx_joypad.c +++ b/input/drivers_joypad/qnx_joypad.c @@ -15,6 +15,8 @@ * If not, see . */ +#include "../../config.def.h" + #include "../../tasks/tasks_internal.h" #include "../../configuration.h" @@ -47,7 +49,7 @@ static bool qnx_joypad_button(unsigned port_num, uint16_t joykey) qnx_input_device_t* controller = NULL; qnx_input_t *qnx = (qnx_input_t*)input_driver_get_data(); - if (!qnx || port_num >= MAX_PADS) + if (!qnx || port_num >= DEFAULT_MAX_PADS) return 0; controller = (qnx_input_device_t*)&qnx->devices[port_num]; @@ -66,7 +68,7 @@ static int16_t qnx_joypad_axis(unsigned port_num, uint32_t joyaxis) bool is_pos = false; qnx_input_t *qnx = (qnx_input_t*)input_driver_get_data(); - if (!qnx || joyaxis == AXIS_NONE || port_num >= MAX_PADS) + if (!qnx || joyaxis == AXIS_NONE || port_num >= DEFAULT_MAX_PADS) return 0; if (AXIS_NEG_GET(joyaxis) < 4) diff --git a/input/drivers_joypad/switch_joypad.c b/input/drivers_joypad/switch_joypad.c index 8e3c8282fe..cb8dcfbcda 100644 --- a/input/drivers_joypad/switch_joypad.c +++ b/input/drivers_joypad/switch_joypad.c @@ -2,6 +2,8 @@ #include "../../config.h" #endif +#include "../../config.def.h" + #ifdef HAVE_LIBNX #include #else @@ -17,28 +19,14 @@ #include "../../command.h" #include "string.h" -#ifdef HAVE_LIBNX - -#ifndef MAX_PADS -#define MAX_PADS 8 -#endif - -#else - -#ifndef MAX_PADS -#define MAX_PADS 10 -#endif - -#endif - -static uint16_t pad_state[MAX_PADS]; -static int16_t analog_state[MAX_PADS][2][2]; +static uint16_t pad_state[DEFAULT_MAX_PADS]; +static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; extern uint64_t lifecycle_state; #ifdef HAVE_LIBNX -static u32 vibration_handles[MAX_PADS][2]; +static u32 vibration_handles[DEFAULT_MAX_PADS][2]; static u32 vibration_handleheld[2]; -static HidVibrationValue vibration_values[MAX_PADS][2]; +static HidVibrationValue vibration_values[DEFAULT_MAX_PADS][2]; static HidVibrationValue vibration_stop; #endif @@ -71,7 +59,7 @@ static bool switch_joypad_init(void *data) vibration_stop.amp_high = 0.0f; vibration_stop.freq_high = 320.0f; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) { switch_joypad_autodetect_add(i); hidInitializeVibrationDevices(vibration_handles[i], 2, i, TYPE_HANDHELD | TYPE_JOYCON_PAIR); @@ -90,7 +78,7 @@ static bool switch_joypad_init(void *data) static bool switch_joypad_button(unsigned port_num, uint16_t key) { - if (port_num >= MAX_PADS) + if (port_num >= DEFAULT_MAX_PADS) return false; #if 0 @@ -102,7 +90,7 @@ static bool switch_joypad_button(unsigned port_num, uint16_t key) static void switch_joypad_get_buttons(unsigned port_num, input_bits_t *state) { - if (port_num < MAX_PADS) + if (port_num < DEFAULT_MAX_PADS) { BITS_COPY16_PTR(state, pad_state[port_num]); } @@ -121,7 +109,7 @@ static int16_t switch_joypad_axis(unsigned port_num, uint32_t joyaxis) #if 0 /* TODO/FIXME - implement */ - if (joyaxis == AXIS_NONE || port_num >= MAX_PADS) { } + if (joyaxis == AXIS_NONE || port_num >= DEFAULT_MAX_PADS) { } #endif if (AXIS_NEG_GET(joyaxis) < 4) @@ -161,14 +149,14 @@ static int16_t switch_joypad_axis(unsigned port_num, uint32_t joyaxis) static bool switch_joypad_query_pad(unsigned pad) { - return pad < MAX_PADS && pad_state[pad]; + return pad < DEFAULT_MAX_PADS && pad_state[pad]; } static void switch_joypad_destroy(void) { #ifdef HAVE_LIBNX unsigned i; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) { memcpy(&vibration_values[i][0], &vibration_stop, sizeof(HidVibrationValue)); @@ -227,7 +215,7 @@ static void switch_joypad_poll(void) } } - for (int i = 0; i < MAX_PADS; i++) + for (int i = 0; i < DEFAULT_MAX_PADS; i++) { HidControllerID target = (i == 0) ? CONTROLLER_P1_AUTO : i; pad_state[i] = hidKeysDown(target) | hidKeysHeld(target); @@ -283,7 +271,7 @@ bool switch_joypad_set_rumble(unsigned pad, u32* handle; float amp; - if (pad >= MAX_PADS || !vibration_handles[pad]) + if (pad >= DEFAULT_MAX_PADS || !vibration_handles[pad]) return false; amp = (float)strength / 65535.0f; diff --git a/input/drivers_joypad/xdk_joypad.c b/input/drivers_joypad/xdk_joypad.c index 9e36268437..1d88746d65 100644 --- a/input/drivers_joypad/xdk_joypad.c +++ b/input/drivers_joypad/xdk_joypad.c @@ -16,6 +16,8 @@ #include +#include "../../config.def.h" + #include "../input_driver.h" #include "../../tasks/tasks_internal.h" @@ -25,10 +27,10 @@ typedef struct bool connected; } xinput_joypad_state; -static xinput_joypad_state g_xinput_states[MAX_PADS]; +static xinput_joypad_state g_xinput_states[DEFAULT_MAX_PADS]; #ifdef _XBOX1 -static HANDLE gamepads[MAX_PADS]; +static HANDLE gamepads[DEFAULT_MAX_PADS]; #endif static const char* const XBOX_CONTROLLER_NAMES[4] = @@ -93,7 +95,7 @@ static bool xdk_joypad_button(unsigned port_num, uint16_t joykey) uint16_t btn_word = 0; unsigned hat_dir = 0; - if (port_num >= MAX_PADS) + if (port_num >= DEFAULT_MAX_PADS) return false; btn_word = g_xinput_states[port_num].xstate.Gamepad.wButtons; @@ -162,7 +164,7 @@ static int16_t xdk_joypad_axis(unsigned port_num, uint32_t joyaxis) bool is_pos = false; XINPUT_GAMEPAD *pad = NULL; - if (joyaxis == AXIS_NONE || port_num >= MAX_PADS) + if (joyaxis == AXIS_NONE || port_num >= DEFAULT_MAX_PADS) return 0; if (AXIS_NEG_GET(joyaxis) <= 3) @@ -233,7 +235,7 @@ static void xdk_joypad_poll(void) #endif #endif - for (port = 0; port < MAX_PADS; port++) + for (port = 0; port < DEFAULT_MAX_PADS; port++) { #if defined(_XBOX1) bool device_removed = false; @@ -307,7 +309,7 @@ static void xdk_joypad_destroy(void) { unsigned i; - for (i = 0; i < MAX_PADS; i++) + for (i = 0; i < DEFAULT_MAX_PADS; i++) { memset(&g_xinput_states[i], 0, sizeof(xinput_joypad_state)); #if defined(_XBOX1) diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index 14c37e0b24..ad943a1375 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -35,6 +35,8 @@ #include "../../config.h" #endif +#include "../../config.def.h" + #include "../../tasks/tasks_internal.h" #include "../input_driver.h" @@ -144,7 +146,8 @@ static INLINE int pad_index_to_xuser_index(unsigned pad) #ifdef HAVE_DINPUT return g_xinput_pad_indexes[pad]; #else - return pad < MAX_PADS && g_xinput_states[pad].connected ? pad : -1; + return pad < DEFAULT_MAX_PADS + && g_xinput_states[pad].connected ? pad : -1; #endif } diff --git a/input/drivers_keyboard/keyboard_event_android.h b/input/drivers_keyboard/keyboard_event_android.h index 069caeac83..ccc8d268d3 100644 --- a/input/drivers_keyboard/keyboard_event_android.h +++ b/input/drivers_keyboard/keyboard_event_android.h @@ -131,12 +131,6 @@ enum { #include -#ifndef MAX_PADS -#define MAX_PADS 8 -#endif - -#define ANDROID_KEYBOARD_PORT MAX_PADS - uint8_t *android_keyboard_state_get(unsigned port); #endif diff --git a/input/drivers_keyboard/keyboard_event_dos.h b/input/drivers_keyboard/keyboard_event_dos.h index d1d2cd68ff..bf65385fd4 100644 --- a/input/drivers_keyboard/keyboard_event_dos.h +++ b/input/drivers_keyboard/keyboard_event_dos.h @@ -116,14 +116,10 @@ enum { #include +#include "../../config.def.h" + #define LAST_KEYCODE 0x1ff -#ifndef MAX_PADS -#define MAX_PADS 1 -#endif - -#define DOS_KEYBOARD_PORT MAX_PADS - uint16_t *dos_keyboard_state_get(unsigned port); #endif diff --git a/input/input_keymaps.c b/input/input_keymaps.c index b0ec268640..1434b5742d 100644 --- a/input/input_keymaps.c +++ b/input/input_keymaps.c @@ -27,6 +27,8 @@ #include "../config.h" #endif +#include "../config.def.h" + #ifdef ANDROID #include #include "drivers_keyboard/keyboard_event_android.h"