From 78edf5f58cffc5a4d3bf50611e538da512a6d973 Mon Sep 17 00:00:00 2001 From: trbocode Date: Mon, 16 Oct 2023 02:08:44 +0300 Subject: [PATCH] Added controller handling for new N64 options (#838) * Added controller handling for new N64 options * Move to N64 folder and add per stick ranges * Improve latency --- input.cpp | 21 ++++++++--------- support/n64/n64_joy_emu.cpp | 45 ++++++++++++++++++++++++++++++++++++- support/n64/n64_joy_emu.h | 1 + 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/input.cpp b/input.cpp index 182322ec..0c139386 100644 --- a/input.cpp +++ b/input.cpp @@ -1199,9 +1199,9 @@ typedef struct char id[80]; char name[128]; char sysfs[512]; - int ss_range; - int max_cardinal; - float max_range; + int ss_range[2]; + int max_cardinal[2]; + float max_range[2]; } devInput; static devInput input[NUMDEV] = {}; @@ -2089,27 +2089,28 @@ static void joy_analog(int dev, int axis, int offset, int stick = 0) pos[stick][num][axis] = offset; int x = pos[stick][num][0]; int y = pos[stick][num][1]; - if (is_n64() && stick == 0) + if (is_n64()) { // Update maximum observed cardinal distance const int abs_x = abs(x); const int abs_y = abs(y); - if (abs_x > input[dev].max_cardinal) input[dev].max_cardinal = abs_x; - if (abs_y > input[dev].max_cardinal) input[dev].max_cardinal = abs_y; + if (abs_x > input[dev].max_cardinal[stick]) input[dev].max_cardinal[stick] = abs_x; + if (abs_y > input[dev].max_cardinal[stick]) input[dev].max_cardinal[stick] = abs_y; // Update maximum observed diag // Use sum of squares and only calc sqrt() when necessary const int ss_range_curr = x*x + y*y; // compare to max ss_range and update if larger - if ((ss_range_curr > input[dev].ss_range) & (abs(abs_x - abs_y) <= 3)) + if ((ss_range_curr > input[dev].ss_range[stick]) & (abs(abs_x - abs_y) <= 3)) { - input[dev].ss_range = ss_range_curr; - input[dev].max_range = sqrt(ss_range_curr); + input[dev].ss_range[stick] = ss_range_curr; + input[dev].max_range[stick] = sqrt(ss_range_curr); } // emulate n64 joystick range and shape for regular -127-+127 controllers - n64_joy_emu(x, y, &x, &y, input[dev].max_cardinal, input[dev].max_range); + n64_joy_emu(x, y, &x, &y, input[dev].max_cardinal[stick], input[dev].max_range[stick]); + stick_swap(num,stick,&num,&stick); } if(stick) user_io_r_analog_joystick(num, (char)x, (char)y); else user_io_l_analog_joystick(num, (char)x, (char)y); diff --git a/support/n64/n64_joy_emu.cpp b/support/n64/n64_joy_emu.cpp index a0b4936d..5e3d9ad4 100644 --- a/support/n64/n64_joy_emu.cpp +++ b/support/n64/n64_joy_emu.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "../../user_io.h" #define N64_MAX_DIAG 69 #define N64_MAX_DIST sqrt(N64_MAX_DIAG * N64_MAX_DIAG * 2) @@ -8,6 +9,48 @@ #define OUTER_DEADZONE 2.0f #define WEDGE_BOUNDARY (N64_MAX_CARDINAL - 69.0f) / 69.0f + + +void stick_swap(int num, int stick, int *num2, int *stick2) +{ + int get=user_io_status_get("TV",1); + int p2=get%2; + int p3=get&2; + int swap=get&4; + if(swap) //reverse sticks + { + stick=1-stick; + } + if(p3) //p1 right stick -> p3 + { + if (stick && num<2) + { + num+=2; + stick=0; + } + else if(!stick && 2 p2 + { + if (stick && ( (num==0) | (num==2))) + { + num++; + stick=0; + } + else if(!stick && num%2==1) + { + num--; + stick=1; + } + } + *num2=num; + *stick2=stick; +} + void n64_joy_emu(int x, int y, int* x2, int* y2, int max_cardinal, float max_range) { // Move to top right quadrant to standardize solutions @@ -66,4 +109,4 @@ void n64_joy_emu(int x, int y, int* x2, int* y2, int max_cardinal, float max_ran #undef N64_MAX_DIST #undef N64_MAX_CARDINAL #undef OUTER_DEADZONE -#undef WEDGE_BOUNDARY \ No newline at end of file +#undef WEDGE_BOUNDARY diff --git a/support/n64/n64_joy_emu.h b/support/n64/n64_joy_emu.h index efce2f12..bf9e20be 100644 --- a/support/n64/n64_joy_emu.h +++ b/support/n64/n64_joy_emu.h @@ -1 +1,2 @@ +void stick_swap(int num, int stick, int *num2, int *stick2); void n64_joy_emu(int x, int y, int* x2, int* y2, int max_cardinal, float max_range);