diff --git a/src/input.cpp b/src/input.cpp index 0baaf959..31946d3b 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -243,7 +243,7 @@ void input_update_input_devices() #endif } -uint16_t input_get_state(uint8_t id, void *response, bool *combo_pressed) +uint16_t input_get_state(uint8_t id, void *response, bool *combo_pressed, uint8_t swap_thumb_sticks) { uint32_t _buttons = 0; int32_t _axis[JoystickController::STANDARD_AXIS_COUNT] = {0}; @@ -300,18 +300,31 @@ uint16_t input_get_state(uint8_t id, void *response, bool *combo_pressed) N64_CL | N64_CR; //Analog stick (Normalise 0 to +/-100) - state->x_axis = _axis[0] * 100 / 32768; - state->y_axis = _axis[1] * 100 / 32768; + if (swap_thumb_sticks == 1) { + state->x_axis = _axis[2] * 100 / 32768; + state->y_axis = _axis[3] * 100 / 32768; + } else { + state->x_axis = _axis[0] * 100 / 32768; + state->y_axis = _axis[1] * 100 / 32768; + } + //Z button if (_axis[4] > 10) state->dButtons |= N64_Z; //LT if (_axis[5] > 10) state->dButtons |= N64_Z; //RT //C usb_buttons - if (_axis[2] > 16000) state->dButtons |= N64_CR; - if (_axis[2] < -16000) state->dButtons |= N64_CL; - if (_axis[3] > 16000) state->dButtons |= N64_CU; - if (_axis[3] < -16000) state->dButtons |= N64_CD; + if (swap_thumb_sticks == 1) { + if (_axis[0] > 16000) state->dButtons |= N64_CR; + if (_axis[0] < -16000) state->dButtons |= N64_CL; + if (_axis[1] > 16000) state->dButtons |= N64_CU; + if (_axis[1] < -16000) state->dButtons |= N64_CD; + } else { + if (_axis[2] > 16000) state->dButtons |= N64_CR; + if (_axis[2] < -16000) state->dButtons |= N64_CL; + if (_axis[3] > 16000) state->dButtons |= N64_CU; + if (_axis[3] < -16000) state->dButtons |= N64_CD; + } //Button to hold for 'combos' if (combo_pressed) @@ -337,7 +350,7 @@ uint16_t input_get_state(uint8_t id, void *response, bool *combo_pressed) if (_buttons & (1 << 5)) state->dButtons |= N64_B; //B if (_buttons & (1 << 6)) state->dButtons |= N64_B; //X if (_buttons & (1 << 7)) state->dButtons |= 0; //Y - if (_buttons & (1 << 15)) state->dButtons |= N64_CU | //RS triggers + if (_buttons & (1 << 15)) state->dButtons |= N64_CU | //RS triggers N64_CD | //all C usb_buttons N64_CL | N64_CR; diff --git a/src/input.h b/src/input.h index b96df167..3ed16e2c 100644 --- a/src/input.h +++ b/src/input.h @@ -129,7 +129,7 @@ uint16_t input_get_id_product(int id); uint16_t input_get_id_vendor(int id); const char *input_get_manufacturer_string(int id); const char *input_get_product_string(int id); -uint16_t input_get_state(uint8_t id, void *n64_response, bool *combo_pressed); +uint16_t input_get_state(uint8_t id, void *n64_response, bool *combo_pressed, uint8_t swap_thumb_sticks); void input_apply_rumble(int id, uint8_t strength); void input_enable_dualstick_mode(int id); void input_disable_dualstick_mode(int id); diff --git a/src/main.cpp b/src/main.cpp index 9b9e3fae..807e3529 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -154,7 +154,7 @@ void loop() if (input_is_gamecontroller(c)) { n64_buttonmap *new_state = (n64_buttonmap *)n64_response[c]; - input_get_state(c, new_state, &n64_combo); + input_get_state(c, new_state, &n64_combo, settings->swap_thumb_sticks[c]); if(n64_in_dev[c].is_mouse == true || n64_in_dev[c].is_kb == true) { @@ -162,7 +162,6 @@ void loop() n64_in_dev[c].is_kb = false; tft_flag_update(); } - n64_settings *settings = n64_settings_get(); float x, y, range; astick_apply_deadzone(&x, &y, new_state->x_axis / 100.0f, new_state->y_axis / 100.0f, @@ -195,7 +194,7 @@ void loop() else if (input_is_mouse(c)) { n64_buttonmap *new_state = (n64_buttonmap *)n64_response[c]; - input_get_state(c, new_state, &n64_combo); + input_get_state(c, new_state, &n64_combo, settings->swap_thumb_sticks[c]); if(n64_in_dev[c].is_mouse == false) { @@ -215,7 +214,7 @@ void loop() //Maintain the old led state new_state->led_state = n64_in_dev[c].kb_state.led_state; - input_get_state(c, new_state, &n64_combo); + input_get_state(c, new_state, &n64_combo, settings->swap_thumb_sticks[c]); if (n64_in_dev[c].is_kb == false) { diff --git a/src/n64/n64_settings.c b/src/n64/n64_settings.c index ab66ad65..53ba75e8 100644 --- a/src/n64/n64_settings.c +++ b/src/n64/n64_settings.c @@ -34,6 +34,7 @@ void n64_settings_init(n64_settings *settings) settings->deadzone[i] = DEFAULT_DEADZONE; settings->sensitivity[i] = DEFAULT_SENSITIVITY; settings->snap_axis[i] = DEFAULT_SNAP; + settings->swap_thumb_sticks[i] = DEFAULT_SWAP_THUMB_STICKS; settings->octa_correct[i] = DEFAULT_OCTA_CORRECT; } n64_settings_update_checksum(settings); diff --git a/src/n64/n64_settings.h b/src/n64/n64_settings.h index 24c12076..86e1091f 100644 --- a/src/n64/n64_settings.h +++ b/src/n64/n64_settings.h @@ -17,6 +17,7 @@ typedef struct uint8_t sensitivity[MAX_CONTROLLERS]; //0 to 4 uint8_t deadzone[MAX_CONTROLLERS]; //0 to 4 uint8_t snap_axis[MAX_CONTROLLERS]; //0 or 1 + uint8_t swap_thumb_sticks[MAX_CONTROLLERS]; //0 or 1 uint8_t octa_correct[MAX_CONTROLLERS]; //0 or 1 uint8_t checksum; } n64_settings; diff --git a/src/n64/n64_virtualpak.c b/src/n64/n64_virtualpak.c index 33ec1026..49e973b1 100644 --- a/src/n64/n64_virtualpak.c +++ b/src/n64/n64_virtualpak.c @@ -366,6 +366,7 @@ void n64_virtualpak_update(n64_mempack *vpak) n64_virtualpak_write_string("DEADZONE+", SUBHEADING + 7, MENU_NAME_FIELD); n64_virtualpak_write_string("DEADZONE-", SUBHEADING + 8, MENU_NAME_FIELD); + n64_virtualpak_write_string("SWAP THUMB STICKS TOGGLE", SUBHEADING + 9, MENU_NAME_FIELD); n64_virtualpak_write_string("SNAP TOGGLE", SUBHEADING + 10, MENU_NAME_FIELD); n64_virtualpak_write_string("OCTA TOGGLE", SUBHEADING + 11, MENU_NAME_FIELD); @@ -383,6 +384,8 @@ void n64_virtualpak_update(n64_mempack *vpak) settings->deadzone[controller_page]++; //Deadzone increase else if (selected_row == SUBHEADING + 8 && settings->deadzone[controller_page] > 0) settings->deadzone[controller_page]--; //Deadzone decrease + else if (selected_row == SUBHEADING + 9) + settings->swap_thumb_sticks[controller_page] ^= 1; //Toggle control thumb stick swap for FPS games else if (selected_row == SUBHEADING + 10) settings->snap_axis[controller_page] ^= 1; //Toggle axis 45 degree snapping else if (selected_row == SUBHEADING + 11) @@ -391,6 +394,7 @@ void n64_virtualpak_update(n64_mempack *vpak) { settings->deadzone[controller_page] = DEFAULT_DEADZONE; settings->sensitivity[controller_page] = DEFAULT_SENSITIVITY; + settings->swap_thumb_sticks[controller_page] = DEFAULT_SWAP_THUMB_STICKS; settings->snap_axis[controller_page] = DEFAULT_SNAP; settings->octa_correct[controller_page] = DEFAULT_OCTA_CORRECT; } @@ -404,6 +408,9 @@ void n64_virtualpak_update(n64_mempack *vpak) sprintf(buff, "%u\0", settings->deadzone[controller_page]); n64_virtualpak_write_string(buff, SUBHEADING + 7, MENU_EXT_FIELD); + sprintf(buff, "%u\0", settings->swap_thumb_sticks[controller_page]); + n64_virtualpak_write_string(buff, SUBHEADING + 9, MENU_EXT_FIELD); + sprintf(buff, "%u\0", settings->snap_axis[controller_page]); n64_virtualpak_write_string(buff, SUBHEADING + 10, MENU_EXT_FIELD); diff --git a/src/usb64_conf.h b/src/usb64_conf.h index 593c4dba..9c49863d 100644 --- a/src/usb64_conf.h +++ b/src/usb64_conf.h @@ -63,10 +63,11 @@ #define MEMPAK_SAVE_EXT ".MPK" //MEMPAKXX.MPK /* FIRMWARE DEFAULTS (CONFIGURABLE DURING USE) */ -#define DEFAULT_SENSITIVITY 2 //0 to 4 (0 = low sensitivity, 4 = max) -#define DEFAULT_DEADZONE 2 //0 to 4 (0 = no deadzone correction, 4 = max (40%)) -#define DEFAULT_SNAP 1 //0 or 1 (0 = will output raw analog stick angle, 1 will snap to 45deg angles) -#define DEFAULT_OCTA_CORRECT 1 //0 or 1 (Will correct the circular analog stuck shape to N64 octagonal) +#define DEFAULT_SENSITIVITY 2 //0 to 4 (0 = low sensitivity, 4 = max) +#define DEFAULT_DEADZONE 2 //0 to 4 (0 = no deadzone correction, 4 = max (40%)) +#define DEFAULT_SNAP 1 //0 or 1 (0 = will output raw analog stick angle, 1 will snap to 45deg angles) +#define DEFAULT_OCTA_CORRECT 1 //0 or 1 (Will correct the circular analog stuck shape to N64 octagonal) +#define DEFAULT_SWAP_THUMB_STICKS 0 //0 or 1 (0 = will disable C-Button mapping to left-hand stick, 1 will enable C-Button mapping to left-hand stick) /* FIRMWARE DEFAULTS (NOT CONFIGURABLE DURING USE) */ #define SNAP_RANGE 5 //+/- what angle range will snap. 5 will snap to 45 degree if between 40 and 50 degrees.