From 72065aee0b629c9e87a624086303d35ec9610c10 Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 8 Apr 2018 02:49:46 -0500 Subject: [PATCH] remap-redux part2: analog to analog input rules are working for left stick to left stick and left stick to right, for some reason not for right stick to right stick (inverting axes) or right stick to left... --- input/input_driver.c | 8 ++--- input/input_mapper.c | 76 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 9 deletions(-) diff --git a/input/input_driver.c b/input/input_driver.c index 35cfb2860b..3df9740e19 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -677,13 +677,13 @@ int16_t input_state(unsigned port, unsigned device, } if (idx == 1) { - if (id == 0 && settings->uints.input_remap_ids[port][16] != 20) + if (id == 0 && settings->uints.input_remap_ids[port][20] != 20) reset_state = true; - if (id == 0 && settings->uints.input_remap_ids[port][17] != 21) + if (id == 0 && settings->uints.input_remap_ids[port][21] != 21) reset_state = true; - if (id == 1 && settings->uints.input_remap_ids[port][18] != 22) + if (id == 1 && settings->uints.input_remap_ids[port][22] != 22) reset_state = true; - if (id == 1 && settings->uints.input_remap_ids[port][19] != 23) + if (id == 1 && settings->uints.input_remap_ids[port][23] != 23) reset_state = true; } } diff --git a/input/input_mapper.c b/input/input_mapper.c index 930a757846..add2d226be 100644 --- a/input/input_mapper.c +++ b/input/input_mapper.c @@ -52,7 +52,6 @@ struct input_mapper { /* Left X, Left Y, Right X, Right Y */ int16_t analog_value[MAX_USERS][8]; - int new_axis[MAX_USERS][8]; /* the whole keyboard state */ uint32_t keys[RETROK_LAST / 32 + 1]; /* This is a bitmask of (1 << key_bind_id). */ @@ -149,6 +148,8 @@ void input_mapper_poll(input_mapper_t *handle) is assigned to any other button than the default one, then it sets the bit on the mapper input bitmap, later on the original input is cleared in input_state */ BIT256_CLEAR_ALL(handle->buttons[i]); + for (j = 0; j < 8; j++) + handle->analog_value[i][j] = 0; input_get_state_for_port(settings, i, ¤t_input); @@ -170,6 +171,7 @@ void input_mapper_poll(input_mapper_t *handle) for (j = 0; j < 8; j++) { k = j + RARCH_FIRST_CUSTOM_BIND; + current_axis_value = current_input.analogs[j]; remap_axis = settings->uints.input_remap_ids[i][k]; @@ -178,13 +180,20 @@ void input_mapper_poll(input_mapper_t *handle) if (remap_axis < RARCH_FIRST_CUSTOM_BIND) { BIT256_SET(handle->buttons[i], remap_axis); - //RARCH_LOG("axis %d remapped to button %d val %d\n", j, remap_axis, current_axis_value); + /* RARCH_LOG("axis %d remapped to button %d val %d\n", j, remap_axis, current_axis_value); */ } else { - handle->analog_value[i][remap_axis - RARCH_FIRST_CUSTOM_BIND] = current_axis_value; - handle->new_axis[i][remap_axis - RARCH_FIRST_CUSTOM_BIND] = remap_axis; - RARCH_LOG("axis %d(%d) remapped to axis %d val %d\n", j, k, remap_axis - RARCH_FIRST_CUSTOM_BIND, current_axis_value); + int invert = 1; + /*if ((k == 16 && remap_axis == 17) || (k == 17 && remap_axis == 16) || + (k == 18 && remap_axis == 19) || (k == 19 && remap_axis == 18) || + (k == 20 && remap_axis == 21) || (k == 21 && remap_axis == 20) || + (k == 22 && remap_axis == 23) || (k == 23 && remap_axis == 22))*/ + if ((k % 2 == 0 && remap_axis % 2 != 0) || (k % 2 != 0 && remap_axis % 2 == 0)) + invert = -1; + + handle->analog_value[i][remap_axis - RARCH_FIRST_CUSTOM_BIND] = current_axis_value * invert; + /* RARCH_LOG("axis %d(%d) remapped to axis %d val %d\n", j, k, remap_axis - RARCH_FIRST_CUSTOM_BIND, current_axis_value); */ } } @@ -212,6 +221,63 @@ void input_mapper_state( *ret = 1; break; case RETRO_DEVICE_ANALOG: + { + int val = 0; + if (idx == 0) + { + if (id == 0) + { + if (handle->analog_value[port][0]) + val = handle->analog_value[port][0]; + else if (handle->analog_value[port][1]) + val = handle->analog_value[port][1]; + + if(handle->analog_value[port][0] || handle->analog_value[port][1]) + { + *ret = val; + } + } + if (id == 1) + { + if (handle->analog_value[port][2]) + val = handle->analog_value[port][2]; + else if (handle->analog_value[port][3]) + val = handle->analog_value[port][3]; + + if(handle->analog_value[port][2] || handle->analog_value[port][3]) + { + *ret = val; + } + } + if (idx == 1) + { + if (id == 0) + { + if (handle->analog_value[port][4]) + val = handle->analog_value[port][4]; + else if (handle->analog_value[port][5]) + val = handle->analog_value[port][5]; + + if(handle->analog_value[port][4] || handle->analog_value[port][5]) + { + *ret = val; + } + } + if (id == 1) + { + if (handle->analog_value[port][6]) + val = handle->analog_value[port][6]; + else if (handle->analog_value[port][7]) + val = handle->analog_value[port][7]; + + if(handle->analog_value[port][6] || handle->analog_value[port][7]) + { + *ret = val; + } + } + } + } + } break; case RETRO_DEVICE_KEYBOARD: if (id < RETROK_LAST)