From 7cc614263a49629cfe4e98bfe74b6391d5f44c3d Mon Sep 17 00:00:00 2001 From: misson20000 Date: Sat, 30 Dec 2017 16:13:56 -0800 Subject: [PATCH] (NSW) add default button bindings and fix right joystick --- input/drivers/switch_input.c | 5 ----- input/drivers_joypad/switch_joypad.c | 21 +++----------------- input/input_autodetect_builtin.c | 29 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/input/drivers/switch_input.c b/input/drivers/switch_input.c index 0d27ab1fb0..a50bcdc80f 100644 --- a/input/drivers/switch_input.c +++ b/input/drivers/switch_input.c @@ -41,13 +41,8 @@ static int16_t switch_input_state(void *data, switch (device) { case RETRO_DEVICE_JOYPAD: -#if 0 return input_joypad_pressed(sw->joypad, joypad_info, port, binds[port], id); -#else - if (sw->joypad) - return sw->joypad->button(port, id); -#endif break; case RETRO_DEVICE_ANALOG: if (binds[port]) diff --git a/input/drivers_joypad/switch_joypad.c b/input/drivers_joypad/switch_joypad.c index a37baf595c..0ed63b0f29 100644 --- a/input/drivers_joypad/switch_joypad.c +++ b/input/drivers_joypad/switch_joypad.c @@ -134,26 +134,11 @@ static void switch_joypad_poll(void) hid_controller_t *controllers = hid_get_shared_memory()->controllers; hid_controller_t *cont = &controllers[0]; hid_controller_state_entry_t ent = cont->main.entries[cont->main.latest_idx]; - pad_state[0] = 0; - pad_state[0] |= (ent.button_state & 0x1000) ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - pad_state[0] |= (ent.button_state & 0x8000) ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - pad_state[0] |= (ent.button_state & 0x4000) ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - pad_state[0] |= (ent.button_state & 0x2000) ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - pad_state[0] |= (ent.button_state & 0x0400) ? (1 << RETRO_DEVICE_ID_JOYPAD_START) : 0; - pad_state[0] |= (ent.button_state & 0x0800) ? (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0; - pad_state[0] |= (ent.button_state & 0x0004) ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - pad_state[0] |= (ent.button_state & 0x0008) ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - pad_state[0] |= (ent.button_state & 0x0002) ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - pad_state[0] |= (ent.button_state & 0x0001) ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - pad_state[0] |= (ent.button_state & 0x0080) ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; - pad_state[0] |= (ent.button_state & 0x0040) ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - pad_state[0] |= (ent.button_state & 0x0200) ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0; - pad_state[0] |= (ent.button_state & 0x0100) ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0; - + pad_state[0] = ent.button_state; analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ent.left_stick_x / 0x20000; analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ent.left_stick_y / 0x20000; - analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = ent.left_stick_x / 0x20000; - analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = ent.left_stick_y / 0x20000; + analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = ent.right_stick_x / 0x20000; + analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = ent.right_stick_y / 0x20000; } input_device_driver_t switch_joypad = { diff --git a/input/input_autodetect_builtin.c b/input/input_autodetect_builtin.c index 32c723b4ac..a00c90123b 100644 --- a/input/input_autodetect_builtin.c +++ b/input/input_autodetect_builtin.c @@ -502,6 +502,32 @@ DECL_AXIS(r_y_plus, -3) \ DECL_AXIS(r_y_minus, +3) #endif +#define SWITCH_DEFAULT_BINDS \ +DECL_BTN(a, 0) \ +DECL_BTN(b, 1) \ +DECL_BTN(x, 2) \ +DECL_BTN(y, 3) \ +DECL_BTN(start, 10) \ +DECL_BTN(select, 11) \ +DECL_BTN(up, 13) \ +DECL_BTN(down, 15) \ +DECL_BTN(left, 12) \ +DECL_BTN(right, 14) \ +DECL_BTN(l, 6) \ +DECL_BTN(r, 7) \ +DECL_BTN(l2, 8) \ +DECL_BTN(r2, 9) \ +DECL_BTN(l3, 4) \ +DECL_BTN(r3, 5) \ +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[] = { #if defined(_WIN32) && defined(_XBOX) @@ -559,6 +585,9 @@ const char* const input_builtin_autoconfs[] = #endif #ifdef __CELLOS_LV2__ DECL_AUTOCONF_DEVICE("SixAxis Controller", "ps3", PS3INPUT_DEFAULT_BINDS), +#endif +#ifdef __SWITCH__ + DECL_AUTOCONF_DEVICE("Switch Controller", "switch", SWITCH_DEFAULT_BINDS), #endif NULL };