Simplify axis state code of other input joypad drivers

This commit is contained in:
libretroadmin 2023-02-19 19:05:32 +01:00
parent e367f87767
commit 8b200f552d
6 changed files with 194 additions and 179 deletions

View File

@ -268,22 +268,10 @@ static void gx_joypad_get_buttons(unsigned port, input_bits_t *state)
static int16_t gx_joypad_axis_state(unsigned port, uint32_t joyaxis)
{
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
if (AXIS_NEG_GET(joyaxis) < 4)
{
axis = AXIS_NEG_GET(joyaxis);
is_neg = true;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
axis = AXIS_POS_GET(joyaxis);
is_pos = true;
}
int16_t val = 0;
int16_t axis = AXIS_NEG_GET(joyaxis);
switch (axis)
{
case 0:
@ -295,13 +283,29 @@ static int16_t gx_joypad_axis_state(unsigned port, uint32_t joyaxis)
val = analog_state[port][1][axis - 2];
break;
}
if (is_neg && val > 0)
val = 0;
else if (is_pos && val < 0)
val = 0;
if (val < 0)
return val;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
int16_t val = 0;
int16_t axis = AXIS_POS_GET(joyaxis);
switch (axis)
{
case 0:
case 1:
val = analog_state[port][0][axis];
break;
case 2:
case 3:
val = analog_state[port][1][axis - 2];
break;
}
if (val > 0)
return val;
}
return 0;
}
static int16_t gx_joypad_axis(unsigned port, uint32_t joyaxis)
{

View File

@ -87,24 +87,10 @@ static void ps3_joypad_get_buttons(unsigned port_num, input_bits_t *state)
static int16_t ps3_joypad_axis_state(unsigned port, uint32_t joyaxis)
{
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
if (AXIS_NEG_GET(joyaxis) < 4)
{
axis = AXIS_NEG_GET(joyaxis);
is_neg = true;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
axis = AXIS_POS_GET(joyaxis);
is_pos = true;
}
else
return 0;
int16_t val = 0;
int16_t axis = AXIS_NEG_GET(joyaxis);
switch (axis)
{
case 0:
@ -116,13 +102,29 @@ static int16_t ps3_joypad_axis_state(unsigned port, uint32_t joyaxis)
val = analog_state[port][1][axis - 2];
break;
}
if (is_neg && val > 0)
return 0;
else if (is_pos && val < 0)
return 0;
if (val < 0)
return val;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
int16_t val = 0;
int16_t axis = AXIS_POS_GET(joyaxis);
switch (axis)
{
case 0:
case 1:
val = analog_state[port][0][axis];
break;
case 2:
case 3:
val = analog_state[port][1][axis - 2];
break;
}
if (val > 0)
return val;
}
return 0;
}
static int16_t ps3_joypad_axis(unsigned port, uint32_t joyaxis)
{

View File

@ -136,24 +136,10 @@ static void psp_joypad_get_buttons(unsigned port, input_bits_t *state)
static int16_t psp_joypad_axis_state(unsigned port, uint32_t joyaxis)
{
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
if (AXIS_NEG_GET(joyaxis) < 4)
{
axis = AXIS_NEG_GET(joyaxis);
is_neg = true;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
axis = AXIS_POS_GET(joyaxis);
is_pos = true;
}
else
return 0;
int16_t val = 0;
int16_t axis = AXIS_NEG_GET(joyaxis);
switch (axis)
{
case 0:
@ -165,13 +151,29 @@ static int16_t psp_joypad_axis_state(unsigned port, uint32_t joyaxis)
val = analog_state[port][1][axis - 2];
break;
}
if (is_neg && val > 0)
return 0;
else if (is_pos && val < 0)
return 0;
if (val < 0)
return val;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
int16_t val = 0;
int16_t axis = AXIS_POS_GET(joyaxis);
switch (axis)
{
case 0:
case 1:
val = analog_state[port][0][axis];
break;
case 2:
case 3:
val = analog_state[port][1][axis - 2];
break;
}
if (val > 0)
return val;
}
return 0;
}
static int16_t psp_joypad_axis(unsigned port, uint32_t joyaxis)
{

View File

@ -63,22 +63,10 @@ static int16_t qnx_joypad_axis_state(
qnx_input_device_t *controller,
unsigned port, uint32_t joyaxis)
{
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
if (AXIS_NEG_GET(joyaxis) < 4)
{
axis = AXIS_NEG_GET(joyaxis);
is_neg = true;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
axis = AXIS_POS_GET(joyaxis);
is_pos = true;
}
int16_t val = 0;
int16_t axis = AXIS_NEG_GET(joyaxis);
switch (axis)
{
case 0:
@ -90,13 +78,29 @@ static int16_t qnx_joypad_axis_state(
val = controller->analog1[axis - 2];
break;
}
if (is_neg && val > 0)
return 0;
else if (is_pos && val < 0)
return 0;
if (val < 0)
return val;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
int16_t val = 0;
int16_t axis = AXIS_POS_GET(joyaxis);
switch (axis)
{
case 0:
case 1:
val = controller->analog0[axis];
break;
case 2:
case 3:
val = controller->analog1[axis - 2];
break;
}
if (val > 0)
return val;
}
return 0;
}
static int16_t qnx_joypad_axis(unsigned port, uint32_t joyaxis)
{

View File

@ -517,28 +517,13 @@ static void sdl_dingux_joypad_get_buttons(unsigned port, input_bits_t *state)
static int16_t sdl_dingux_joypad_axis_state(unsigned port, uint32_t joyaxis)
{
#if defined(SDL_DINGUX_HAS_ANALOG)
if (port == 0)
{
dingux_joypad_t *joypad = (dingux_joypad_t*)&dingux_joypad;
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
if (port != 0)
return 0;
if (AXIS_NEG_GET(joyaxis) < 4)
{
axis = AXIS_NEG_GET(joyaxis);
is_neg = true;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
axis = AXIS_POS_GET(joyaxis);
is_pos = true;
}
else
return 0;
int16_t val = 0;
int16_t axis = AXIS_NEG_GET(joyaxis);
switch (axis)
{
case 0:
@ -550,16 +535,30 @@ static int16_t sdl_dingux_joypad_axis_state(unsigned port, uint32_t joyaxis)
val = joypad->analog_state[1][axis - 2];
break;
}
if (is_neg && val > 0)
return 0;
else if (is_pos && val < 0)
return 0;
if (val < 0)
return val;
#else
return 0;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
int16_t val = 0;
int16_t axis = AXIS_POS_GET(joyaxis);
switch (axis)
{
case 0:
case 1:
val = joypad->analog_state[0][axis];
break;
case 2:
case 3:
val = joypad->analog_state[1][axis - 2];
break;
}
if (val > 0)
return val;
}
}
#endif
return 0;
}
static int16_t sdl_dingux_joypad_axis(unsigned port, uint32_t joyaxis)

View File

@ -115,22 +115,10 @@ static void switch_joypad_get_buttons(unsigned port_num, input_bits_t *state)
static int16_t switch_joypad_axis_state(unsigned port, uint32_t joyaxis)
{
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
if (AXIS_NEG_GET(joyaxis) < 4)
{
axis = AXIS_NEG_GET(joyaxis);
is_neg = true;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
axis = AXIS_POS_GET(joyaxis);
is_pos = true;
}
int16_t val = 0;
int16_t axis = AXIS_NEG_GET(joyaxis);
switch(axis)
{
case 0:
@ -142,13 +130,29 @@ static int16_t switch_joypad_axis_state(unsigned port, uint32_t joyaxis)
val = analog_state[port][1][axis - 2];
break;
}
if (is_neg && val > 0)
return 0;
else if (is_pos && val < 0)
return 0;
if (val < 0)
return val;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
int16_t val = 0;
int16_t axis = AXIS_POS_GET(joyaxis);
switch(axis)
{
case 0:
case 1:
val = analog_state[port][0][axis];
break;
case 2:
case 3:
val = analog_state[port][1][axis - 2];
break;
}
if (val > 0)
return val;
}
return 0;
}
static int16_t switch_joypad_axis(unsigned port, uint32_t joyaxis)
{