Initial code for joystick port instancing

This commit is contained in:
Jasmine Iwanek
2025-01-10 18:42:09 -05:00
parent 3b29b769c3
commit ac891a05a5
12 changed files with 172 additions and 174 deletions

View File

@@ -524,23 +524,23 @@ load_input_devices(void)
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
sprintf(temp, "joystick_%i_nr", js); sprintf(temp, "joystick_%i_nr", js);
joystick_state[js].plat_joystick_nr = ini_section_get_int(cat, temp, 0); joystick_state[0][js].plat_joystick_nr = ini_section_get_int(cat, temp, 0);
if (joystick_state[js].plat_joystick_nr) { if (joystick_state[0][js].plat_joystick_nr) {
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) {
sprintf(temp, "joystick_%i_axis_%i", js, axis_nr); sprintf(temp, "joystick_%i_axis_%i", js, axis_nr);
joystick_state[js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr); joystick_state[0][js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr);
} }
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) { for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) {
sprintf(temp, "joystick_%i_button_%i", js, button_nr); sprintf(temp, "joystick_%i_button_%i", js, button_nr);
joystick_state[js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr); joystick_state[0][js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr);
} }
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
sprintf(temp, "joystick_%i_pov_%i", js, pov_nr); sprintf(temp, "joystick_%i_pov_%i", js, pov_nr);
p = ini_section_get_string(cat, temp, "0, 0"); p = ini_section_get_string(cat, temp, "0, 0");
joystick_state[js].pov_mapping[pov_nr][0] = joystick_state[js].pov_mapping[pov_nr][1] = 0; joystick_state[0][js].pov_mapping[pov_nr][0] = joystick_state[0][js].pov_mapping[pov_nr][1] = 0;
sscanf(p, "%i, %i", &joystick_state[js].pov_mapping[pov_nr][0], sscanf(p, "%i, %i", &joystick_state[0][js].pov_mapping[pov_nr][0],
&joystick_state[js].pov_mapping[pov_nr][1]); &joystick_state[0][js].pov_mapping[pov_nr][1]);
} }
} }
} }
@@ -2195,21 +2195,21 @@ save_input_devices(void)
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
sprintf(tmp2, "joystick_%i_nr", js); sprintf(tmp2, "joystick_%i_nr", js);
ini_section_set_int(cat, tmp2, joystick_state[js].plat_joystick_nr); ini_section_set_int(cat, tmp2, joystick_state[0][js].plat_joystick_nr);
if (joystick_state[js].plat_joystick_nr) { if (joystick_state[0][js].plat_joystick_nr) {
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) {
sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr); sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr);
ini_section_set_int(cat, tmp2, joystick_state[js].axis_mapping[axis_nr]); ini_section_set_int(cat, tmp2, joystick_state[0][js].axis_mapping[axis_nr]);
} }
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) { for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) {
sprintf(tmp2, "joystick_%i_button_%i", js, button_nr); sprintf(tmp2, "joystick_%i_button_%i", js, button_nr);
ini_section_set_int(cat, tmp2, joystick_state[js].button_mapping[button_nr]); ini_section_set_int(cat, tmp2, joystick_state[0][js].button_mapping[button_nr]);
} }
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr); sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr);
sprintf(temp, "%i, %i", joystick_state[js].pov_mapping[pov_nr][0], sprintf(temp, "%i, %i", joystick_state[0][js].pov_mapping[pov_nr][0],
joystick_state[js].pov_mapping[pov_nr][1]); joystick_state[0][js].pov_mapping[pov_nr][1]);
ini_section_set_string(cat, tmp2, temp); ini_section_set_string(cat, tmp2, temp);
} }
} }

View File

@@ -102,7 +102,7 @@ static const struct {
{ NULL } { NULL }
}; };
static joystick_instance_t *joystick_instance = NULL; static joystick_instance_t *joystick_instance[GAMEPORT_MAX] = { NULL, NULL };
static uint8_t gameport_pnp_rom[] = { static uint8_t gameport_pnp_rom[] = {
0x09, 0xf8, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, /* BOX0002, dummy checksum (filled in by isapnp_add_card) */ 0x09, 0xf8, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, /* BOX0002, dummy checksum (filled in by isapnp_add_card) */
@@ -284,10 +284,10 @@ gameport_update_joystick_type(void)
gameport_add(standalone_gameport_type); gameport_add(standalone_gameport_type);
/* Reset the joystick interface. */ /* Reset the joystick interface. */
if (joystick_instance) { if (joystick_instance[0]) {
joystick_instance->intf->close(joystick_instance->dat); joystick_instance[0]->intf->close(joystick_instance[0]->dat);
joystick_instance->intf = joysticks[joystick_type].joystick; joystick_instance[0]->intf = joysticks[joystick_type].joystick;
joystick_instance->dat = joystick_instance->intf->init(); joystick_instance[0]->dat = joystick_instance[0]->intf->init();
} }
} }
@@ -372,30 +372,30 @@ gameport_init(const device_t *info)
memset(dev, 0x00, sizeof(gameport_t)); memset(dev, 0x00, sizeof(gameport_t));
/* Allocate global instance. */ /* Allocate global instance. */
if (!joystick_instance && joystick_type) { if (!joystick_instance[0] && joystick_type) {
joystick_instance = malloc(sizeof(joystick_instance_t)); joystick_instance[0] = malloc(sizeof(joystick_instance_t));
memset(joystick_instance, 0x00, sizeof(joystick_instance_t)); memset(joystick_instance[0], 0x00, sizeof(joystick_instance_t));
joystick_instance->axis[0].joystick = joystick_instance; joystick_instance[0]->axis[0].joystick = joystick_instance[0];
joystick_instance->axis[1].joystick = joystick_instance; joystick_instance[0]->axis[1].joystick = joystick_instance[0];
joystick_instance->axis[2].joystick = joystick_instance; joystick_instance[0]->axis[2].joystick = joystick_instance[0];
joystick_instance->axis[3].joystick = joystick_instance; joystick_instance[0]->axis[3].joystick = joystick_instance[0];
joystick_instance->axis[0].axis_nr = 0; joystick_instance[0]->axis[0].axis_nr = 0;
joystick_instance->axis[1].axis_nr = 1; joystick_instance[0]->axis[1].axis_nr = 1;
joystick_instance->axis[2].axis_nr = 2; joystick_instance[0]->axis[2].axis_nr = 2;
joystick_instance->axis[3].axis_nr = 3; joystick_instance[0]->axis[3].axis_nr = 3;
timer_add(&joystick_instance->axis[0].timer, timer_over, &joystick_instance->axis[0], 0); timer_add(&joystick_instance[0]->axis[0].timer, timer_over, &joystick_instance[0]->axis[0], 0);
timer_add(&joystick_instance->axis[1].timer, timer_over, &joystick_instance->axis[1], 0); timer_add(&joystick_instance[0]->axis[1].timer, timer_over, &joystick_instance[0]->axis[1], 0);
timer_add(&joystick_instance->axis[2].timer, timer_over, &joystick_instance->axis[2], 0); timer_add(&joystick_instance[0]->axis[2].timer, timer_over, &joystick_instance[0]->axis[2], 0);
timer_add(&joystick_instance->axis[3].timer, timer_over, &joystick_instance->axis[3], 0); timer_add(&joystick_instance[0]->axis[3].timer, timer_over, &joystick_instance[0]->axis[3], 0);
joystick_instance->intf = joysticks[joystick_type].joystick; joystick_instance[0]->intf = joysticks[joystick_type].joystick;
joystick_instance->dat = joystick_instance->intf->init(); joystick_instance[0]->dat = joystick_instance[0]->intf->init();
} }
dev->joystick = joystick_instance; dev->joystick = joystick_instance[0];
/* Map game port to the default address. Not applicable on PnP-only ports. */ /* Map game port to the default address. Not applicable on PnP-only ports. */
dev->len = (info->local >> 16) & 0xff; dev->len = (info->local >> 16) & 0xff;
@@ -464,11 +464,11 @@ gameport_close(void *priv)
gameport_remap(dev, 0); gameport_remap(dev, 0);
/* Free the global instance here, if it wasn't already freed. */ /* Free the global instance here, if it wasn't already freed. */
if (joystick_instance) { if (joystick_instance[0]) {
joystick_instance->intf->close(joystick_instance->dat); joystick_instance[0]->intf->close(joystick_instance[0]->dat);
free(joystick_instance); free(joystick_instance[0]);
joystick_instance = NULL; joystick_instance[0] = NULL;
} }
free(dev); free(dev);

View File

@@ -62,23 +62,23 @@ ch_flightstick_pro_read(UNUSED(void *priv))
{ {
uint8_t ret = 0xf0; uint8_t ret = 0xf0;
if (JOYSTICK_PRESENT(0)) { if (JOYSTICK_PRESENT(0, 0)) {
if (joystick_state[0].button[0]) if (joystick_state[0][0].button[0])
ret &= ~0x10; ret &= ~0x10;
if (joystick_state[0].button[1]) if (joystick_state[0][0].button[1])
ret &= ~0x20; ret &= ~0x20;
if (joystick_state[0].button[2]) if (joystick_state[0][0].button[2])
ret &= ~0x40; ret &= ~0x40;
if (joystick_state[0].button[3]) if (joystick_state[0][0].button[3])
ret &= ~0x80; ret &= ~0x80;
if (joystick_state[0].pov[0] != -1) { if (joystick_state[0][0].pov[0] != -1) {
if (joystick_state[0].pov[0] > 315 || joystick_state[0].pov[0] < 45) if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45)
ret &= ~0xf0; ret &= ~0xf0;
else if (joystick_state[0].pov[0] >= 45 && joystick_state[0].pov[0] < 135) else if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135)
ret &= ~0xb0; ret &= ~0xb0;
else if (joystick_state[0].pov[0] >= 135 && joystick_state[0].pov[0] < 225) else if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225)
ret &= ~0x70; ret &= ~0x70;
else if (joystick_state[0].pov[0] >= 225 && joystick_state[0].pov[0] < 315) else if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315)
ret &= ~0x30; ret &= ~0x30;
} }
} }
@@ -95,18 +95,18 @@ ch_flightstick_pro_write(UNUSED(void *priv))
static int static int
ch_flightstick_pro_read_axis(UNUSED(void *priv), int axis) ch_flightstick_pro_read_axis(UNUSED(void *priv), int axis)
{ {
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
switch (axis) { switch (axis) {
case 0: case 0:
return joystick_state[0].axis[0]; return joystick_state[0][0].axis[0];
case 1: case 1:
return joystick_state[0].axis[1]; return joystick_state[0][0].axis[1];
case 2: case 2:
return 0; return 0;
case 3: case 3:
return joystick_state[0].axis[2]; return joystick_state[0][0].axis[2];
default: default:
return 0; return 0;
} }

View File

@@ -63,10 +63,10 @@ joystick_standard_read(UNUSED(void *priv))
uint8_t ret = 0xf0; uint8_t ret = 0xf0;
for (int js = 0; js < 2; js++) { for (int js = 0; js < 2; js++) {
if (JOYSTICK_PRESENT(js)) { if (JOYSTICK_PRESENT(0, js)) {
if (joystick_state[js].button[0]) if (joystick_state[0][js].button[0])
ret &= ~0x10; ret &= ~0x10;
if (joystick_state[js].button[1]) if (joystick_state[0][js].button[1])
ret &= ~0x20; ret &= ~0x20;
} }
} }
@@ -79,14 +79,14 @@ joystick_standard_read_4button(UNUSED(void *priv))
{ {
uint8_t ret = 0xf0; uint8_t ret = 0xf0;
if (JOYSTICK_PRESENT(0)) { if (JOYSTICK_PRESENT(0, 0)) {
if (joystick_state[0].button[0]) if (joystick_state[0][0].button[0])
ret &= ~0x10; ret &= ~0x10;
if (joystick_state[0].button[1]) if (joystick_state[0][0].button[1])
ret &= ~0x20; ret &= ~0x20;
if (joystick_state[0].button[2]) if (joystick_state[0][0].button[2])
ret &= ~0x40; ret &= ~0x40;
if (joystick_state[0].button[3]) if (joystick_state[0][0].button[3])
ret &= ~0x80; ret &= ~0x80;
} }
@@ -104,21 +104,21 @@ joystick_standard_read_axis(UNUSED(void *priv), int axis)
{ {
switch (axis) { switch (axis) {
case 0: case 0:
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
return joystick_state[0].axis[0]; return joystick_state[0][0].axis[0];
case 1: case 1:
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
return joystick_state[0].axis[1]; return joystick_state[0][0].axis[1];
case 2: case 2:
if (!JOYSTICK_PRESENT(1)) if (!JOYSTICK_PRESENT(0, 1))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
return joystick_state[1].axis[0]; return joystick_state[0][1].axis[0];
case 3: case 3:
if (!JOYSTICK_PRESENT(1)) if (!JOYSTICK_PRESENT(0, 1))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
return joystick_state[1].axis[1]; return joystick_state[0][1].axis[1];
default: default:
return 0; return 0;
} }
@@ -127,14 +127,14 @@ joystick_standard_read_axis(UNUSED(void *priv), int axis)
static int static int
joystick_standard_read_axis_4button(UNUSED(void *priv), int axis) joystick_standard_read_axis_4button(UNUSED(void *priv), int axis)
{ {
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
switch (axis) { switch (axis) {
case 0: case 0:
return joystick_state[0].axis[0]; return joystick_state[0][0].axis[0];
case 1: case 1:
return joystick_state[0].axis[1]; return joystick_state[0][0].axis[1];
case 2: case 2:
case 3: case 3:
default: default:
@@ -145,16 +145,16 @@ joystick_standard_read_axis_4button(UNUSED(void *priv), int axis)
static int static int
joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis)
{ {
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
switch (axis) { switch (axis) {
case 0: case 0:
return joystick_state[0].axis[0]; return joystick_state[0][0].axis[0];
case 1: case 1:
return joystick_state[0].axis[1]; return joystick_state[0][0].axis[1];
case 2: case 2:
return joystick_state[0].axis[2]; return joystick_state[0][0].axis[2];
case 3: case 3:
default: default:
return 0; return 0;
@@ -164,18 +164,18 @@ joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis)
static int static int
joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis)
{ {
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
switch (axis) { switch (axis) {
case 0: case 0:
return joystick_state[0].axis[0]; return joystick_state[0][0].axis[0];
case 1: case 1:
return joystick_state[0].axis[1]; return joystick_state[0][0].axis[1];
case 2: case 2:
return joystick_state[0].axis[2]; return joystick_state[0][0].axis[2];
case 3: case 3:
return joystick_state[0].axis[3]; return joystick_state[0][0].axis[3];
default: default:
return 0; return 0;
} }
@@ -184,18 +184,18 @@ joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis)
static int static int
joystick_standard_read_axis_6button(UNUSED(void *priv), int axis) joystick_standard_read_axis_6button(UNUSED(void *priv), int axis)
{ {
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
switch (axis) { switch (axis) {
case 0: case 0:
return joystick_state[0].axis[0]; return joystick_state[0][0].axis[0];
case 1: case 1:
return joystick_state[0].axis[1]; return joystick_state[0][0].axis[1];
case 2: case 2:
return joystick_state[0].button[4] ? -32767 : 32768; return joystick_state[0][0].button[4] ? -32767 : 32768;
case 3: case 3:
return joystick_state[0].button[5] ? -32767 : 32768; return joystick_state[0][0].button[5] ? -32767 : 32768;
default: default:
return 0; return 0;
} }
@@ -203,24 +203,24 @@ joystick_standard_read_axis_6button(UNUSED(void *priv), int axis)
static int static int
joystick_standard_read_axis_8button(UNUSED(void *priv), int axis) joystick_standard_read_axis_8button(UNUSED(void *priv), int axis)
{ {
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
switch (axis) { switch (axis) {
case 0: case 0:
return joystick_state[0].axis[0]; return joystick_state[0][0].axis[0];
case 1: case 1:
return joystick_state[0].axis[1]; return joystick_state[0][0].axis[1];
case 2: case 2:
if (joystick_state[0].button[4]) if (joystick_state[0][0].button[4])
return -32767; return -32767;
if (joystick_state[0].button[6]) if (joystick_state[0][0].button[6])
return 32768; return 32768;
return 0; return 0;
case 3: case 3:
if (joystick_state[0].button[5]) if (joystick_state[0][0].button[5])
return -32767; return -32767;
if (joystick_state[0].button[7]) if (joystick_state[0][0].button[7])
return 32768; return 32768;
return 0; return 0;
default: default:

View File

@@ -141,7 +141,7 @@ sw_read(void *priv)
sw_data *sw = (sw_data *) priv; sw_data *sw = (sw_data *) priv;
uint8_t temp = 0; uint8_t temp = 0;
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return 0xff; return 0xff;
if (timer_is_enabled(&sw->poll_timer)) { if (timer_is_enabled(&sw->poll_timer)) {
@@ -167,7 +167,7 @@ sw_write(void *priv)
sw_data *sw = (sw_data *) priv; sw_data *sw = (sw_data *) priv;
int64_t time_since_last = timer_get_remaining_us(&sw->trigger_timer); int64_t time_since_last = timer_get_remaining_us(&sw->trigger_timer);
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return; return;
if (!sw->poll_left) { if (!sw->poll_left) {
@@ -193,20 +193,20 @@ sw_write(void *priv)
for (uint8_t js = 0; js < 4; js++) { for (uint8_t js = 0; js < 4; js++) {
uint16_t data = 0x3fff; uint16_t data = 0x3fff;
if (!JOYSTICK_PRESENT(js)) if (!JOYSTICK_PRESENT(0, js))
break; break;
if (joystick_state[js].axis[1] < -16383) if (joystick_state[0][js].axis[1] < -16383)
data &= ~1; data &= ~1;
if (joystick_state[js].axis[1] > 16383) if (joystick_state[0][js].axis[1] > 16383)
data &= ~2; data &= ~2;
if (joystick_state[js].axis[0] > 16383) if (joystick_state[0][js].axis[0] > 16383)
data &= ~4; data &= ~4;
if (joystick_state[js].axis[0] < -16383) if (joystick_state[0][js].axis[0] < -16383)
data &= ~8; data &= ~8;
for (uint8_t button_nr = 0; button_nr < 10; button_nr++) { for (uint8_t button_nr = 0; button_nr < 10; button_nr++) {
if (joystick_state[js].button[button_nr]) if (joystick_state[0][js].button[button_nr])
data &= ~(1 << (button_nr + 4)); data &= ~(1 << (button_nr + 4));
} }
@@ -230,7 +230,7 @@ sw_write(void *priv)
static int static int
sw_read_axis(UNUSED(void *priv), UNUSED(int axis)) sw_read_axis(UNUSED(void *priv), UNUSED(int axis))
{ {
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
return 0; /*No analogue support on Sidewinder game pad*/ return 0; /*No analogue support on Sidewinder game pad*/

View File

@@ -62,14 +62,14 @@ tm_fcs_read(UNUSED(void *priv))
{ {
uint8_t ret = 0xf0; uint8_t ret = 0xf0;
if (JOYSTICK_PRESENT(0)) { if (JOYSTICK_PRESENT(0, 0)) {
if (joystick_state[0].button[0]) if (joystick_state[0][0].button[0])
ret &= ~0x10; ret &= ~0x10;
if (joystick_state[0].button[1]) if (joystick_state[0][0].button[1])
ret &= ~0x20; ret &= ~0x20;
if (joystick_state[0].button[2]) if (joystick_state[0][0].button[2])
ret &= ~0x40; ret &= ~0x40;
if (joystick_state[0].button[3]) if (joystick_state[0][0].button[3])
ret &= ~0x80; ret &= ~0x80;
} }
@@ -85,26 +85,26 @@ tm_fcs_write(UNUSED(void *priv))
static int static int
tm_fcs_read_axis(UNUSED(void *priv), int axis) tm_fcs_read_axis(UNUSED(void *priv), int axis)
{ {
if (!JOYSTICK_PRESENT(0)) if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT; return AXIS_NOT_PRESENT;
switch (axis) { switch (axis) {
case 0: case 0:
return joystick_state[0].axis[0]; return joystick_state[0][0].axis[0];
case 1: case 1:
return joystick_state[0].axis[1]; return joystick_state[0][0].axis[1];
case 2: case 2:
return 0; return 0;
case 3: case 3:
if (joystick_state[0].pov[0] == -1) if (joystick_state[0][0].pov[0] == -1)
return 32767; return 32767;
if (joystick_state[0].pov[0] > 315 || joystick_state[0].pov[0] < 45) if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45)
return -32768; return -32768;
if (joystick_state[0].pov[0] >= 45 && joystick_state[0].pov[0] < 135) if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135)
return -16384; return -16384;
if (joystick_state[0].pov[0] >= 135 && joystick_state[0].pov[0] < 225) if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225)
return 0; return 0;
if (joystick_state[0].pov[0] >= 225 && joystick_state[0].pov[0] < 315) if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315)
return 16384; return 16384;
return 0; return 0;
default: default:

View File

@@ -45,7 +45,7 @@
#define AXIS_NOT_PRESENT -99999 #define AXIS_NOT_PRESENT -99999
#define JOYSTICK_PRESENT(n) (joystick_state[n].plat_joystick_nr != 0) #define JOYSTICK_PRESENT(gp, js) (joystick_state[gp][js].plat_joystick_nr != 0)
#define GAMEPORT_1ADDR 0x010000 #define GAMEPORT_1ADDR 0x010000
#define GAMEPORT_6ADDR 0x060000 #define GAMEPORT_6ADDR 0x060000
@@ -146,7 +146,7 @@ extern const device_t *standalone_gameport_type;
#endif #endif
extern int gameport_instance_id; extern int gameport_instance_id;
extern plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; extern plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
extern joystick_t joystick_state[MAX_JOYSTICKS]; extern joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
extern int joysticks_present; extern int joysticks_present;
extern int joystick_type; extern int joystick_type;

View File

@@ -41,7 +41,7 @@ JoystickConfiguration::JoystickConfiguration(int type, int joystick_nr, QWidget
Models::AddEntry(model, plat_joystick_state[c].name, c + 1); Models::AddEntry(model, plat_joystick_state[c].name, c + 1);
} }
ui->comboBoxDevice->setCurrentIndex(joystick_state[joystick_nr].plat_joystick_nr); ui->comboBoxDevice->setCurrentIndex(joystick_state[0][joystick_nr].plat_joystick_nr);
layout()->setSizeConstraint(QLayout::SetFixedSize); layout()->setSizeConstraint(QLayout::SetFixedSize);
} }
@@ -119,7 +119,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
} }
int nr_axes = plat_joystick_state[joystick].nr_axes; int nr_axes = plat_joystick_state[joystick].nr_axes;
int mapping = joystick_state[joystick_nr].axis_mapping[c]; int mapping = joystick_state[0][joystick_nr].axis_mapping[c];
if (mapping & POV_X) if (mapping & POV_X)
cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2); cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2);
else if (mapping & POV_Y) else if (mapping & POV_Y)
@@ -147,7 +147,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
Models::AddEntry(model, plat_joystick_state[joystick].button[d].name, 0); Models::AddEntry(model, plat_joystick_state[joystick].button[d].name, 0);
} }
cbox->setCurrentIndex(joystick_state[joystick_nr].button_mapping[c]); cbox->setCurrentIndex(joystick_state[0][joystick_nr].button_mapping[c]);
ui->ct->addWidget(label, row, 0); ui->ct->addWidget(label, row, 0);
ui->ct->addWidget(cbox, row, 1); ui->ct->addWidget(cbox, row, 1);
@@ -179,7 +179,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
Models::AddEntry(model, plat_joystick_state[joystick].axis[d].name, 0); Models::AddEntry(model, plat_joystick_state[joystick].axis[d].name, 0);
} }
int mapping = joystick_state[joystick_nr].pov_mapping[c / 2][c & 1]; int mapping = joystick_state[0][joystick_nr].pov_mapping[c / 2][c & 1];
int nr_povs = plat_joystick_state[joystick].nr_povs; int nr_povs = plat_joystick_state[joystick].nr_povs;
if (mapping & POV_X) if (mapping & POV_X)
cbox->setCurrentIndex((mapping & 3) * 2); cbox->setCurrentIndex((mapping & 3) * 2);

View File

@@ -136,7 +136,7 @@ static int
get_axis(JoystickConfiguration &jc, int axis, int joystick_nr) get_axis(JoystickConfiguration &jc, int axis, int joystick_nr)
{ {
int axis_sel = jc.selectedAxis(axis); int axis_sel = jc.selectedAxis(axis);
int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_axes; int nr_axes = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_axes;
if (axis_sel < nr_axes) { if (axis_sel < nr_axes) {
return axis_sel; return axis_sel;
@@ -153,7 +153,7 @@ static int
get_pov(JoystickConfiguration &jc, int pov, int joystick_nr) get_pov(JoystickConfiguration &jc, int pov, int joystick_nr)
{ {
int pov_sel = jc.selectedPov(pov); int pov_sel = jc.selectedPov(pov);
int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs * 2; int nr_povs = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_povs * 2;
if (pov_sel < nr_povs) { if (pov_sel < nr_povs) {
if (pov_sel & 1) if (pov_sel & 1)
@@ -176,19 +176,19 @@ updateJoystickConfig(int type, int joystick_nr, QWidget *parent)
break; break;
} }
joystick_state[joystick_nr].plat_joystick_nr = jc.selectedDevice(); joystick_state[0][joystick_nr].plat_joystick_nr = jc.selectedDevice();
if (joystick_state[joystick_nr].plat_joystick_nr) { if (joystick_state[0][joystick_nr].plat_joystick_nr) {
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(type); axis_nr++) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(type); axis_nr++) {
joystick_state[joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr); joystick_state[0][joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr);
} }
for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++) { for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++) {
joystick_state[joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr); joystick_state[0][joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr);
} }
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(type) * 2; pov_nr += 2) { for (int pov_nr = 0; pov_nr < joystick_get_pov_count(type) * 2; pov_nr += 2) {
joystick_state[joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr); joystick_state[0][joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr);
joystick_state[joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr); joystick_state[0][joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr);
} }
} }
} }

View File

@@ -8,13 +8,13 @@
* *
* SDL2 joystick interface. * SDL2 joystick interface.
* *
*
*
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/> * Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
* Joakim L. Gilje <jgilje@jgilje.net> * Joakim L. Gilje, <jgilje@jgilje.net>
* Jasmine Iwanek, jriwanek@gmail.com>
* *
* Copyright 2017-2021 Sarah Walker * Copyright 2017-2021 Sarah Walker.
* Copyright 2021 Joakim L. Gilje * Copyright 2021 Joakim L. Gilje.
* Copyright 2021-2025 Jasmine Iwanek.
*/ */
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
@@ -33,8 +33,8 @@
#include <86box/gameport.h> #include <86box/gameport.h>
#include <86box/plat_unused.h> #include <86box/plat_unused.h>
int joysticks_present; int joysticks_present = 0;
joystick_t joystick_state[MAX_JOYSTICKS]; joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
static SDL_Joystick *sdl_joy[MAX_PLAT_JOYSTICKS]; static SDL_Joystick *sdl_joy[MAX_PLAT_JOYSTICKS];
@@ -89,7 +89,7 @@ joystick_close(void)
} }
static int static int
joystick_get_axis(int joystick_nr, int mapping) joystick_get_axis(int gameport, int joystick_nr, int mapping)
{ {
if (mapping & POV_X) { if (mapping & POV_X) {
switch (plat_joystick_state[joystick_nr].p[mapping & 3]) { switch (plat_joystick_state[joystick_nr].p[mapping & 3]) {
@@ -144,44 +144,44 @@ joystick_process(void)
#if 0 #if 0
pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", js, pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", js,
joystick_state[js].x, joystick_state[0][js].x,
joystick_state[js].y, joystick_state[0][js].y,
joystick_state[js].b[0], joystick_state[0][js].b[0],
joystick_state[js].b[1], joystick_state[0][js].b[1],
joysticks_present); joysticks_present);
#endif #endif
} }
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
if (joystick_state[js].plat_joystick_nr) { if (joystick_state[0][js].plat_joystick_nr) {
int joystick_nr = joystick_state[js].plat_joystick_nr - 1; int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1;
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
joystick_state[js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[js].axis_mapping[axis_nr]); joystick_state[0][js].axis[axis_nr] = joystick_get_axis(0, joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]);
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
joystick_state[js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[js].button_mapping[button_nr]]; joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]];
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]); int x = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]);
int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]); int y = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]);
double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI);
double magnitude = sqrt((double) x * (double) x + (double) y * (double) y); double magnitude = sqrt((double) x * (double) x + (double) y * (double) y);
if (magnitude < 16384) if (magnitude < 16384)
joystick_state[js].pov[pov_nr] = -1; joystick_state[0][js].pov[pov_nr] = -1;
else else
joystick_state[js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360;
} }
} else { } else {
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
joystick_state[js].axis[axis_nr] = 0; joystick_state[0][js].axis[axis_nr] = 0;
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
joystick_state[js].button[button_nr] = 0; joystick_state[0][js].button[button_nr] = 0;
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++)
joystick_state[js].pov[pov_nr] = -1; joystick_state[0][js].pov[pov_nr] = -1;
} }
} }
} }

View File

@@ -8,15 +8,13 @@
* *
* RawInput joystick interface. * RawInput joystick interface.
* *
*
*
* Authors: Miran Grca, <mgrca8@gmail.com> * Authors: Miran Grca, <mgrca8@gmail.com>
* GH Cao, <driver1998.ms@outlook.com> * GH Cao, <driver1998.ms@outlook.com>
* Jasmine Iwanek, * Jasmine Iwanek, <jriwanek@gmail.com>
* *
* Copyright 2016-2018 Miran Grca. * Copyright 2016-2018 Miran Grca.
* Copyright 2020 GH Cao. * Copyright 2020 GH Cao.
* Copyright 2021-2023 Jasmine Iwanek. * Copyright 2021-2025 Jasmine Iwanek.
*/ */
#include <windows.h> #include <windows.h>
#include <windowsx.h> #include <windowsx.h>
@@ -98,9 +96,9 @@ typedef struct {
} pov[MAX_JOY_POVS]; } pov[MAX_JOY_POVS];
} raw_joystick_t; } raw_joystick_t;
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
joystick_t joystick_state[MAX_JOYSTICKS];
int joysticks_present = 0; int joysticks_present = 0;
joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
raw_joystick_t raw_joystick_state[MAX_PLAT_JOYSTICKS]; raw_joystick_t raw_joystick_state[MAX_PLAT_JOYSTICKS];
@@ -455,7 +453,7 @@ win_joystick_handle(PRAWINPUT raw)
plat_joystick_state[j].a[axis_nr] = value; plat_joystick_state[j].a[axis_nr] = value;
#if 0 #if 0
joystick_log("%s %-06d ", plat_joystick_state[j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]); joystick_log("%s %-06d ", plat_joystick_state[0][j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]);
#endif #endif
} }
@@ -477,7 +475,7 @@ win_joystick_handle(PRAWINPUT raw)
plat_joystick_state[j].p[pov_nr] = value; plat_joystick_state[j].p[pov_nr] = value;
#if 0 #if 0
joystick_log("%s %-3d ", plat_joystick_state[j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]); joystick_log("%s %-3d ", plat_joystick_state[0][j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]);
#endif #endif
} }
#if 0 #if 0
@@ -512,35 +510,35 @@ joystick_process(void)
return; return;
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
if (joystick_state[js].plat_joystick_nr) { if (joystick_state[0][js].plat_joystick_nr) {
int joystick_nr = joystick_state[js].plat_joystick_nr - 1; int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1;
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
joystick_state[js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[js].axis_mapping[axis_nr]); joystick_state[0][js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]);
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
joystick_state[js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[js].button_mapping[button_nr]]; joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]];
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]); int x = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]);
int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]); int y = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]);
double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI);
double magnitude = sqrt((double) x * (double) x + (double) y * (double) y); double magnitude = sqrt((double) x * (double) x + (double) y * (double) y);
if (magnitude < 16384) if (magnitude < 16384)
joystick_state[js].pov[pov_nr] = -1; joystick_state[0][js].pov[pov_nr] = -1;
else else
joystick_state[js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360;
} }
} else { } else {
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
joystick_state[js].axis[axis_nr] = 0; joystick_state[0][js].axis[axis_nr] = 0;
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
joystick_state[js].button[button_nr] = 0; joystick_state[0][js].button[button_nr] = 0;
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++)
joystick_state[js].pov[pov_nr] = -1; joystick_state[0][js].pov[pov_nr] = -1;
} }
} }
} }

View File

@@ -61,7 +61,7 @@ int fixed_size_y = 480;
extern int title_set; extern int title_set;
extern wchar_t sdl_win_title[512]; extern wchar_t sdl_win_title[512];
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
joystick_t joystick_state[MAX_JOYSTICKS]; joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
int joysticks_present; int joysticks_present;
SDL_mutex *blitmtx; SDL_mutex *blitmtx;
SDL_threadID eventthread; SDL_threadID eventthread;