diff --git a/Makefile.ctr b/Makefile.ctr index ea29f89935..b54c29d1e6 100644 --- a/Makefile.ctr +++ b/Makefile.ctr @@ -39,8 +39,8 @@ CFLAGS += -I. -Ideps/zlib -Ideps/7zip -Ilibretro-common/include CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE -DSINC_LOWEST_QUALITY CFLAGS += -DHAVE_GRIFFIN=1 -DHAVE_FILTERS_BUILTIN -DHAVE_MENU -DHAVE_RGUI -CFLAGS += -DHAVE_ZLIB -DWANT_ZLIB -#-DHAVE_LIBRETRO_MANAGEMENT -DWANT_RPNG -DHAVE_BUILTIN_AUTOCONFIG -DHAVE_FILTERS_BUILTIN -DHAVE_7ZIP +CFLAGS += -DHAVE_ZLIB -DWANT_ZLIB -DHAVE_BUILTIN_AUTOCONFIG +#-DHAVE_LIBRETRO_MANAGEMENT -DWANT_RPNG -DHAVE_7ZIP CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 diff --git a/input/autoconf/builtin_ctr.c b/input/autoconf/builtin_ctr.c index 8b13789179..5a314133dd 100644 --- a/input/autoconf/builtin_ctr.c +++ b/input/autoconf/builtin_ctr.c @@ -1 +1,49 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2015 - Daniel De Matteis + * Copyright (C) 2014-2015 - Ali Bouhlel + * + * 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 "builtin.h" + +#define CTRINPUT_DEFAULT_BINDS \ +DECL_BTN(a, 8) \ +DECL_BTN(b, 0) \ +DECL_BTN(x, 9) \ +DECL_BTN(y, 1) \ +DECL_BTN(start, 3) \ +DECL_BTN(select, 2) \ +DECL_BTN(up, 4) \ +DECL_BTN(down, 5) \ +DECL_BTN(left, 6) \ +DECL_BTN(right, 7) \ +DECL_BTN(l, 10) \ +DECL_BTN(r, 11) \ +DECL_BTN(l2, 12) \ +DECL_BTN(r2, 13) \ +DECL_AXIS(l_x_plus, +0) \ +DECL_AXIS(l_x_minus, -0) \ +DECL_AXIS(l_y_plus, +1) \ +DECL_AXIS(l_y_minus, -1) \ +DECL_AXIS(r_x_plus, +2) \ +DECL_AXIS(r_x_minus, -2) \ +DECL_AXIS(r_y_plus, -3) \ +DECL_AXIS(r_y_minus, +3) + +const char* const input_builtin_autoconfs[] = +{ + DECL_AUTOCONF_DEVICE("3DS Controller", "ctr", CTRINPUT_DEFAULT_BINDS), + NULL +}; + diff --git a/input/drivers/ctr_input.c b/input/drivers/ctr_input.c index ca60d7bf57..781b0e2c52 100644 --- a/input/drivers/ctr_input.c +++ b/input/drivers/ctr_input.c @@ -13,68 +13,35 @@ * If not, see . */ -#include "3ds.h" +#include +#include -#include "../../general.h" #include "../../driver.h" -#include "retroarch.h" +#include "../../libretro.h" +#include "../../general.h" +#include "../input_common.h" +#include "../input_joypad.h" -static uint32_t kDown; -static int16_t pad_state; +#define MAX_PADS 1 -static void *ctr_input_init(void) +typedef struct ctr_input { - return (void*)-1; -} + const rarch_joypad_driver_t *joypad; +} ctr_input_t; static void ctr_input_poll(void *data) -{ - (void)data; - global_t *global = global_get_ptr(); - uint64_t *lifecycle_state = (uint64_t*)&global->lifecycle_state; - - hidScanInput(); - kDown = hidKeysHeld(); - - pad_state = 0; - pad_state |= (kDown & KEY_DLEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - pad_state |= (kDown & KEY_DDOWN) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - pad_state |= (kDown & KEY_DRIGHT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - pad_state |= (kDown & KEY_DUP) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - pad_state |= (kDown & KEY_START) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0; - pad_state |= (kDown & KEY_SELECT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0; - pad_state |= (kDown & KEY_X) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0; - pad_state |= (kDown & KEY_Y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - pad_state |= (kDown & KEY_B) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0; - pad_state |= (kDown & KEY_A) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0; - pad_state |= (kDown & KEY_R) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0; - pad_state |= (kDown & KEY_L) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0; - - - *lifecycle_state &= ~((1ULL << RARCH_MENU_TOGGLE)); - - if(kDown & KEY_TOUCH) - *lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE); - - /* panic button */ - if((kDown & KEY_START) && - (kDown & KEY_SELECT) && - (kDown & KEY_L) && - (kDown & KEY_R)) - rarch_main_command(RARCH_CMD_QUIT); +{ + ctr_input_t *ctr = (ctr_input_t*)data; + if (ctr->joypad) + ctr->joypad->poll(); } -static int16_t ctr_input_state(void *data, - const struct retro_keybind **retro_keybinds, unsigned port, - unsigned device, unsigned idx, unsigned id) +static int16_t ctr_input_state(void *data, const struct retro_keybind **binds, + unsigned port, unsigned device, + unsigned idx, unsigned id) { - (void)data; - (void)retro_keybinds; - (void)port; - (void)device; - (void)idx; - (void)id; + ctr_input_t *ctr = (ctr_input_t*)data; if (port > 0) return 0; @@ -82,42 +49,59 @@ static int16_t ctr_input_state(void *data, switch (device) { case RETRO_DEVICE_JOYPAD: - return pad_state; - + return input_joypad_pressed(ctr->joypad, port, binds[port], id); case RETRO_DEVICE_ANALOG: - return 0; + return input_joypad_analog(ctr->joypad, port, idx, id, binds[port]); } return 0; } -static bool ctr_input_key_pressed(void *data, int key) -{ - (void)data; - global_t *global = global_get_ptr(); - - return (global->lifecycle_state & (1ULL << key))|| - (pad_state & (1ULL << key)); -} - static void ctr_input_free_input(void *data) { - (void)data; + ctr_input_t *ctr = (ctr_input_t*)data; + + if (ctr && ctr->joypad) + ctr->joypad->destroy(); + + free(data); +} + +static void* ctr_input_initialize(void) +{ + settings_t *settings = config_get_ptr(); + ctr_input_t *ctr = (ctr_input_t*)calloc(1, sizeof(*ctr)); + if (!ctr) + return NULL; + + ctr->joypad = input_joypad_init_driver(settings->input.joypad_driver); + + return ctr; +} + +static bool ctr_input_key_pressed(void *data, int key) +{ + settings_t *settings = config_get_ptr(); + global_t *global = global_get_ptr(); + ctr_input_t *ctr = (ctr_input_t*)data; + + return (global->lifecycle_state & (1ULL << key)) || + input_joypad_pressed(ctr->joypad, 0, settings->input.binds[0], key); } static uint64_t ctr_input_get_capabilities(void *data) { - uint64_t caps = 0; + (void)data; - caps |= (1 << RETRO_DEVICE_JOYPAD); - - return caps; + return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); } -static bool ctr_input_set_sensor_state(void *data, - unsigned port, enum retro_sensor_action action, unsigned event_rate) +static const rarch_joypad_driver_t *ctr_input_get_joypad_driver(void *data) { - return false; + ctr_input_t *ctr = (ctr_input_t*)data; + if (ctr) + return ctr->joypad; + return NULL; } static void ctr_input_grab_mouse(void *data, bool state) @@ -138,15 +122,16 @@ static bool ctr_input_set_rumble(void *data, unsigned port, } input_driver_t input_ctr = { - ctr_input_init, + ctr_input_initialize, ctr_input_poll, ctr_input_state, ctr_input_key_pressed, ctr_input_free_input, - ctr_input_set_sensor_state, + NULL, NULL, ctr_input_get_capabilities, "ctr", ctr_input_grab_mouse, ctr_input_set_rumble, + ctr_input_get_joypad_driver, }; diff --git a/input/drivers_joypad/ctr_joypad.c b/input/drivers_joypad/ctr_joypad.c index 1f67d99374..26b0fd374f 100644 --- a/input/drivers_joypad/ctr_joypad.c +++ b/input/drivers_joypad/ctr_joypad.c @@ -1,7 +1,6 @@ /* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2015 - Daniel De Matteis - * Copyright (C) 2013-2014 - CatalystG + * Copyright (C) 2014-2015 - Ali Bouhlel * * 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- @@ -15,43 +14,164 @@ * If not, see . */ -#include -#include -#include #include "../input_joypad_driver.h" +#include "../input_autodetect.h" +#include "../../general.h" +#include "../../driver.h" +#include "../../configuration.h" +#include "../../retroarch.h" +#include "string.h" +#include "3ds.h" + +#ifndef MAX_PADS +#define MAX_PADS 1 +#endif + +static uint64_t pad_state; +static int16_t analog_state[1][2][2]; static const char *ctr_joypad_name(unsigned pad) { - return "ctr"; + return "3DS Controller"; +} + +static void ctr_joypad_autodetect_add(unsigned autoconf_pad) +{ + settings_t *settings = config_get_ptr(); + autoconfig_params_t params = {{0}}; + + strlcpy(settings->input.device_names[autoconf_pad], + ctr_joypad_name(autoconf_pad), + sizeof(settings->input.device_names[autoconf_pad])); + + /* TODO - implement VID/PID? */ + params.idx = autoconf_pad; + strlcpy(params.name, ctr_joypad_name(autoconf_pad), sizeof(params.name)); + strlcpy(params.driver, ctr_joypad.ident, sizeof(params.driver)); + input_config_autoconfigure_joypad(¶ms); } static bool ctr_joypad_init(void) { + ctr_joypad_autodetect_add(0); + return true; } static bool ctr_joypad_button(unsigned port_num, uint16_t joykey) { - return false; + if (port_num >= MAX_PADS) + return false; + + return (pad_state & (1ULL << joykey)); } static uint64_t ctr_joypad_get_buttons(unsigned port_num) { - return 0; + return pad_state; } static int16_t ctr_joypad_axis(unsigned port_num, uint32_t joyaxis) { - return 0; + int val = 0; + int axis = -1; + bool is_neg = false; + bool is_pos = false; + + if (joyaxis == AXIS_NONE || port_num >= MAX_PADS) + return 0; + + if (AXIS_NEG_GET(joyaxis) < 4) + { + axis = AXIS_NEG_GET(joyaxis); + is_neg = true; + } + else if (AXIS_POS_GET(joyaxis) < 4) + { + axis = AXIS_POS_GET(joyaxis); + is_pos = true; + } + + switch (axis) + { + case 0: + val = analog_state[port_num][0][0]; + break; + case 1: + val = analog_state[port_num][0][1]; + break; + case 2: + val = analog_state[port_num][1][0]; + break; + case 3: + val = analog_state[port_num][1][1]; + break; + } + + if (is_neg && val > 0) + val = 0; + else if (is_pos && val < 0) + val = 0; + + return val; } static void ctr_joypad_poll(void) { + int32_t ret; + uint32_t state_tmp; + circlePosition state_tmp_analog; + + global_t *global = global_get_ptr(); + uint64_t *lifecycle_state = (uint64_t*)&global->lifecycle_state; + + hidScanInput(); + + state_tmp = hidKeysHeld(); + hidCircleRead(&state_tmp_analog); + + analog_state[0][0][0] = analog_state[0][0][1] = + analog_state[0][1][0] = analog_state[0][1][1] = 0; + pad_state = 0; + pad_state |= (state_tmp & KEY_DLEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + pad_state |= (state_tmp & KEY_DDOWN) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + pad_state |= (state_tmp & KEY_DRIGHT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + pad_state |= (state_tmp & KEY_DUP) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + pad_state |= (state_tmp & KEY_START) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0; + pad_state |= (state_tmp & KEY_SELECT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0; + pad_state |= (state_tmp & KEY_X) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0; + pad_state |= (state_tmp & KEY_Y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + pad_state |= (state_tmp & KEY_B) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0; + pad_state |= (state_tmp & KEY_A) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0; + pad_state |= (state_tmp & KEY_R) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0; + pad_state |= (state_tmp & KEY_L) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0; + + analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = state_tmp_analog.dx; + analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = state_tmp_analog.dy; + + for (int i = 0; i < 2; i++) + for (int j = 0; j < 2; j++) + if (analog_state[0][i][j] == -0x8000) + analog_state[0][i][j] = -0x7fff; + + *lifecycle_state &= ~((1ULL << RARCH_MENU_TOGGLE)); + + if(state_tmp & KEY_TOUCH) + *lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE); + + /* panic button */ + if((state_tmp & KEY_START) && + (state_tmp & KEY_SELECT) && + (state_tmp & KEY_L) && + (state_tmp & KEY_R)) + rarch_main_command(RARCH_CMD_QUIT); + } static bool ctr_joypad_query_pad(unsigned pad) { - return true; + /* FIXME */ + return pad < MAX_USERS && pad_state; }