mirror of
https://github.com/ekeeke/Genesis-Plus-GX.git
synced 2025-01-13 11:49:06 +01:00
[Wii] fixed support for 3rd-party classic controllers with invalid calibration settings
This commit is contained in:
parent
35f3509e36
commit
1ebb43ca34
Binary file not shown.
Before Width: | Height: | Size: 3.8 MiB After Width: | Height: | Size: 3.8 MiB |
@ -490,23 +490,29 @@ static int wpad_StickX(WPADData *data, u8 right)
|
|||||||
|
|
||||||
if (js)
|
if (js)
|
||||||
{
|
{
|
||||||
/* raw X value */
|
/* raw X position */
|
||||||
int x = js->pos.x;
|
int pos = js->pos.x;
|
||||||
|
|
||||||
/* value returned is sometime above calibrated limits */
|
/* X range calibration */
|
||||||
if (x > js->max.x) return 127;
|
int min = js->min.x;
|
||||||
if (x < js->min.x) return -128;
|
int max = js->max.x;
|
||||||
|
int center = js->center.x;
|
||||||
|
|
||||||
|
/* value returned could be above calibration limits */
|
||||||
|
if (pos > max) return 127;
|
||||||
|
if (pos < min) return -128;
|
||||||
|
|
||||||
/* adjust against center position */
|
/* adjust against center position */
|
||||||
x -= js->center.x;
|
pos -= center;
|
||||||
|
|
||||||
/* return interpolated range [-128;127] */
|
/* return interpolated range [-128;127] */
|
||||||
if (x > 0)
|
if (pos > 0)
|
||||||
{
|
{
|
||||||
return (int)(127.0 * ((float)x / (float)(js->max.x - js->center.x)));
|
return (int)(127.0 * ((float)pos / (float)(max - center)));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return (int)(128.0 * ((float)x / (float)(js->center.x - js->min.x)));
|
return (int)(128.0 * ((float)pos / (float)(center - min)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,23 +539,29 @@ static int wpad_StickY(WPADData *data, u8 right)
|
|||||||
|
|
||||||
if (js)
|
if (js)
|
||||||
{
|
{
|
||||||
/* raw Y value */
|
/* raw Y position */
|
||||||
int y = js->pos.y;
|
int pos = js->pos.y;
|
||||||
|
|
||||||
/* value returned is sometime above calibrated limits */
|
/* Y range calibration */
|
||||||
if (y > js->max.y) return 127;
|
int min = js->min.y;
|
||||||
if (y < js->min.y) return -128;
|
int max = js->max.y;
|
||||||
|
int center = js->center.y;
|
||||||
|
|
||||||
|
/* value returned could be above calibration limits */
|
||||||
|
if (pos > max) return 127;
|
||||||
|
if (pos < min) return -128;
|
||||||
|
|
||||||
/* adjust against center position */
|
/* adjust against center position */
|
||||||
y -= js->center.y;
|
pos -= center;
|
||||||
|
|
||||||
/* return interpolated range [-128;127] */
|
/* return interpolated range [-128;127] */
|
||||||
if (y > 0)
|
if (pos > 0)
|
||||||
{
|
{
|
||||||
return (int)(127.0 * ((float)y / (float)(js->max.y - js->center.y)));
|
return (int)(127.0 * ((float)pos / (float)(max - center)));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return (int)(128.0 * ((float)y / (float)(js->center.y - js->min.y)));
|
return (int)(128.0 * ((float)pos / (float)(center - min)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1113,6 +1125,45 @@ int gx_input_FindDevices(void)
|
|||||||
if (wpad == (config.input[player].device - 1))
|
if (wpad == (config.input[player].device - 1))
|
||||||
{
|
{
|
||||||
found++;
|
found++;
|
||||||
|
|
||||||
|
/* some 3rd party classic controllers return invalid factory calibration data */
|
||||||
|
if (wpad == EXP_CLASSIC)
|
||||||
|
{
|
||||||
|
/* WPAD data */
|
||||||
|
WPADData *data = WPAD_Data(config.input[player].port);
|
||||||
|
|
||||||
|
/* Left analog stick */
|
||||||
|
struct joystick_t* js = &data->exp.classic.ljs;
|
||||||
|
|
||||||
|
/* Check acquired calibration data */
|
||||||
|
if ((js->max.x <= js->center.x) || (js->min.x >= js->center.x) ||
|
||||||
|
(js->max.y <= js->center.y) || (js->min.y >= js->center.y))
|
||||||
|
{
|
||||||
|
/* Reset to default values */
|
||||||
|
js->min.x = 0;
|
||||||
|
js->max.x = 64;
|
||||||
|
js->center.x = 32;
|
||||||
|
js->min.y = 0;
|
||||||
|
js->max.y = 32;
|
||||||
|
js->center.y = 16 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Right analog stick */
|
||||||
|
js = &data->exp.classic.rjs;
|
||||||
|
|
||||||
|
/* Check acquired calibration data */
|
||||||
|
if ((js->max.x <= js->center.x) || (js->min.x >= js->center.x) ||
|
||||||
|
(js->max.y <= js->center.y) || (js->min.y >= js->center.y))
|
||||||
|
{
|
||||||
|
/* Reset to default values */
|
||||||
|
js->min.x = 0;
|
||||||
|
js->max.x = 64;
|
||||||
|
js->center.x = 32;
|
||||||
|
js->min.y = 0;
|
||||||
|
js->max.y = 32;
|
||||||
|
js->center.y = 16 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user