This commit is contained in:
Jasmine Iwanek
2025-01-11 01:31:57 -05:00
parent 035b8deee2
commit 3b092bcdb2
6 changed files with 155 additions and 174 deletions

View File

@@ -62,17 +62,13 @@ joystick_standard_read(UNUSED(void *priv))
{
uint8_t ret = 0xf0;
if (JOYSTICK_PRESENT(0)) {
if (joystick_state[0].button[0])
ret &= ~0x10;
if (joystick_state[0].button[1])
ret &= ~0x20;
}
if (JOYSTICK_PRESENT(1)) {
if (joystick_state[1].button[0])
ret &= ~0x40;
if (joystick_state[1].button[1])
ret &= ~0x80;
for (int js = 0; js < 2; js++) {
if (JOYSTICK_PRESENT(js)) {
if (joystick_state[js].button[0])
ret &= ~0x10;
if (joystick_state[js].button[1])
ret &= ~0x20;
}
}
return ret;
@@ -140,9 +136,7 @@ joystick_standard_read_axis_4button(UNUSED(void *priv), int axis)
case 1:
return joystick_state[0].axis[1];
case 2:
return 0;
case 3:
return 0;
default:
return 0;
}
@@ -162,7 +156,6 @@ joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis)
case 2:
return joystick_state[0].axis[2];
case 3:
return 0;
default:
return 0;
}

View File

@@ -119,8 +119,7 @@ sw_parity(uint16_t data)
static void *
sw_init(void)
{
sw_data *sw = (sw_data *) malloc(sizeof(sw_data));
memset(sw, 0, sizeof(sw_data));
sw_data *sw = (sw_data *) calloc(1, sizeof(sw_data));
timer_add(&sw->poll_timer, sw_timer_over, sw, 0);
timer_add(&sw->trigger_timer, sw_trigger_timer_over, sw, 0);
@@ -191,24 +190,24 @@ sw_write(void *priv)
sw->poll_data = 1;
}
for (uint8_t c = 0; c < 4; c++) {
for (uint8_t js = 0; js < MAX_JOYSTICKS; js++) {
uint16_t data = 0x3fff;
if (!JOYSTICK_PRESENT(c))
if (!JOYSTICK_PRESENT(js))
break;
if (joystick_state[c].axis[1] < -16383)
if (joystick_state[js].axis[1] < -16383)
data &= ~1;
if (joystick_state[c].axis[1] > 16383)
if (joystick_state[js].axis[1] > 16383)
data &= ~2;
if (joystick_state[c].axis[0] > 16383)
if (joystick_state[js].axis[0] > 16383)
data &= ~4;
if (joystick_state[c].axis[0] < -16383)
if (joystick_state[js].axis[0] < -16383)
data &= ~8;
for (uint8_t b = 0; b < 10; b++) {
if (joystick_state[c].button[b])
data &= ~(1 << (b + 4));
for (uint8_t button_nr = 0; button_nr < 10; button_nr++) {
if (joystick_state[js].button[button_nr])
data &= ~(1 << (button_nr + 4));
}
if (sw_parity(data))
@@ -216,10 +215,10 @@ sw_write(void *priv)
if (sw->poll_mode) {
sw->poll_left += 5;
sw->poll_data |= (data << (c * 15 + 3));
sw->poll_data |= (data << (js * 15 + 3));
} else {
sw->poll_left += 15;
sw->poll_data |= (data << (c * 15 + 1));
sw->poll_data |= (data << (js * 15 + 1));
}
}
}