From: notaz Date: Fri, 9 Nov 2012 23:14:46 +0000 (+0200) Subject: frontend: improve pandora nub to PSX analog mapping X-Git-Tag: r16~4 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c5d0a55b2b48b33f6d15b59d6f04a06c90b2ab5;p=pcsx_rearmed.git frontend: improve pandora nub to PSX analog mapping --- diff --git a/frontend/libpicofe b/frontend/libpicofe index e22d791c..c688b90f 160000 --- a/frontend/libpicofe +++ b/frontend/libpicofe @@ -1 +1 @@ -Subproject commit e22d791cf862a5156a05bc4c55f0a90200ec22e6 +Subproject commit c688b90fe2c8b9ceb57a4e6f773397a90ade5d4f diff --git a/frontend/menu.c b/frontend/menu.c index 6fb2c925..333bdb6c 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -248,6 +248,9 @@ static void menu_set_defconfig(void) #define CE_INTVAL(val) \ { #val, sizeof(val), &val } +#define CE_INTVAL_N(name, val) \ + { name, sizeof(val), &val } + #define CE_INTVAL_P(val) \ { #val, sizeof(pl_rearmed_cbs.val), &pl_rearmed_cbs.val } @@ -295,6 +298,8 @@ static const struct { CE_INTVAL(in_type_sel1), CE_INTVAL(in_type_sel2), CE_INTVAL(analog_deadzone), + CE_INTVAL_N("adev0_is_nublike", in_adev_is_nublike[0]), + CE_INTVAL_N("adev1_is_nublike", in_adev_is_nublike[1]), CE_INTVAL_V(frameskip, 3), CE_INTVAL_P(gpu_peops.iUseDither), CE_INTVAL_P(gpu_peops.dwActFixes), @@ -908,17 +913,21 @@ static int key_config_loop_wrap(int id, int keys) return 0; } +static const char h_nubmode[] = "Maps nub-like analog controls to PSX ones better\n" + "Might cause problems with real analog sticks"; static const char *adevnames[IN_MAX_DEVS + 2]; static int stick_sel[2]; static menu_entry e_menu_keyconfig_analog[] = { - mee_enum ("Left stick (L3)", 0, stick_sel[0], adevnames), - mee_range(" X axis", 0, in_adev_axis[0][0], 0, 7), - mee_range(" Y axis", 0, in_adev_axis[0][1], 0, 7), - mee_enum ("Right stick (R3)", 0, stick_sel[1], adevnames), - mee_range(" X axis", 0, in_adev_axis[1][0], 0, 7), - mee_range(" Y axis", 0, in_adev_axis[1][1], 0, 7), + mee_enum ("Left stick (L3)", 0, stick_sel[0], adevnames), + mee_range (" X axis", 0, in_adev_axis[0][0], 0, 7), + mee_range (" Y axis", 0, in_adev_axis[0][1], 0, 7), + mee_onoff_h(" nub mode", 0, in_adev_is_nublike[0], 1, h_nubmode), + mee_enum ("Right stick (R3)", 0, stick_sel[1], adevnames), + mee_range (" X axis", 0, in_adev_axis[1][0], 0, 7), + mee_range (" Y axis", 0, in_adev_axis[1][1], 0, 7), + mee_onoff_h(" nub mode", 0, in_adev_is_nublike[1], 1, h_nubmode), mee_end, }; diff --git a/frontend/plat_pandora.c b/frontend/plat_pandora.c index 5f20d009..28aaaab2 100644 --- a/frontend/plat_pandora.c +++ b/frontend/plat_pandora.c @@ -55,6 +55,7 @@ int plat_init(void) in_adev[0] = in_name_to_id("evdev:nub0"); in_adev[1] = in_name_to_id("evdev:nub1"); + in_adev_is_nublike[0] = in_adev_is_nublike[1] = 1; return 0; } diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c index 5017a1bb..d306cc4f 100644 --- a/frontend/plugin_lib.c +++ b/frontend/plugin_lib.c @@ -35,6 +35,7 @@ int in_type1, in_type2; int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 }; int in_adev[2] = { -1, -1 }, in_adev_axis[2][2] = {{ 0, 1 }, { 0, 1 }}; +int in_adev_is_nublike[2]; int in_keystate, in_state_gun; int in_enable_vibration; void *tsdev; @@ -430,9 +431,25 @@ void pl_switch_dispmode(void) } #ifndef MAEMO +/* adjust circle-like analog inputs to better match + * more square-like analogs in PSX */ +static void update_analog_nub_adjust(int *x_, int *y_) +{ + static const int scale[] = { 0, 0, 0, 12, 30, 60, 75, 60, 60 }; + int x = *x_; + int y = *y_; + + x += x * scale[abs(y) / 16] >> 8; + y += y * scale[abs(x) / 16] >> 8; + + *x_ = x; + *y_ = y; +} + static void update_analogs(void) { int *nubp[2] = { in_a1, in_a2 }; + int vals[2]; int i, a, v, ret; for (i = 0; i < 2; i++) @@ -441,14 +458,23 @@ static void update_analogs(void) continue; for (a = 0; a < 2; a++) { - nubp[i][a] = 127; + vals[a] = 0; ret = in_update_analog(in_adev[i], in_adev_axis[i][a], &v); - if (ret == 0) { - v = v / (IN_ABS_RANGE / 128) + 127; - nubp[i][a] = v < 0 ? 0 : v; - } + if (ret == 0) + vals[a] = 128 * v / IN_ABS_RANGE; } + + if (in_adev_is_nublike[i]) + update_analog_nub_adjust(&vals[0], &vals[1]); + + for (a = 0; a < 2; a++) { + v = vals[a] + 127; + if (v < 0) v = 0; + else if (v > 255) v = 255; + nubp[i][a] = v; + } + } //printf("%4d %4d %4d %4d\n", in_a1[0], in_a1[1], in_a2[0], in_a2[1]); } diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h index 332fbc2e..a96dc4e7 100644 --- a/frontend/plugin_lib.h +++ b/frontend/plugin_lib.h @@ -20,6 +20,7 @@ enum { extern int in_type1, in_type2; extern int in_keystate, in_state_gun, in_a1[2], in_a2[2]; extern int in_adev[2], in_adev_axis[2][2]; +extern int in_adev_is_nublike[2]; extern int in_enable_vibration; extern void *pl_vout_buf;