Merge pull request #5193 from jriwanek-forks/gameports

Initial work for Gameport instancing
This commit is contained in:
Miran Grča
2025-02-01 13:23:11 +01:00
committed by GitHub
15 changed files with 322 additions and 188 deletions

View File

@@ -11,6 +11,7 @@
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
* Jasmine Iwanek, <jriwanek@gmail.com>
*
* Copyright 2008-2020 Sarah Walker.
* Copyright 2016-2020 Miran Grca.
@@ -18,7 +19,7 @@
* Copyright 2021 Laci bá'
* Copyright 2021 dob205
* Copyright 2021 Andreas J. Reichel.
* Copyright 2021-2022 Jasmine Iwanek.
* Copyright 2021-2025 Jasmine Iwanek.
*/
#include <inttypes.h>
#include <stdarg.h>
@@ -178,6 +179,7 @@ int bugger_enabled = 0; /* (C) enable
int novell_keycard_enabled = 0; /* (C) enable Novell NetWare 2.x key card emulation. */
int postcard_enabled = 0; /* (C) enable POST card */
int unittester_enabled = 0; /* (C) enable unit tester device */
int gameport_type[GAMEPORT_MAX] = { 0, 0 }; /* (C) enable gameports */
int isamem_type[ISAMEM_MAX] = { 0, 0, 0, 0 }; /* (C) enable ISA mem cards */
int isartc_type = 0; /* (C) enable ISA RTC card */
int gfxcard[GFXCARD_MAX] = { 0, 0 }; /* (C) graphics/video card */

View File

@@ -8,20 +8,19 @@
*
* Configuration file handler.
*
*
*
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
* Overdoze,
* David Hrdlička, <hrdlickadavid@outlook.com>
* Jasmine Iwanek, <jriwanek@gmail.com>
*
* Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2019 Miran Grca.
* Copyright 2017-2019 Fred N. van Kempen.
* Copyright 2018-2019 David Hrdlička.
* Copyright 2021 Andreas J. Reichel.
* Copyright 2021-2022 Jasmine Iwanek.
* Copyright 2021-2025 Jasmine Iwanek.
*
* NOTE: Forcing config files to be in Unicode encoding breaks
* it on Windows XP, and possibly also Vista. Use the
@@ -525,23 +524,23 @@ load_input_devices(void)
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); 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++) {
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++) {
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++) {
sprintf(temp, "joystick_%i_pov_%i", js, pov_nr);
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;
sscanf(p, "%i, %i", &joystick_state[js].pov_mapping[pov_nr][0],
&joystick_state[js].pov_mapping[pov_nr][1]);
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[0][js].pov_mapping[pov_nr][0],
&joystick_state[0][js].pov_mapping[pov_nr][1]);
}
}
}
@@ -760,6 +759,28 @@ load_ports(void)
p = ini_section_get_string(cat, temp, "none");
lpt_ports[c].device = lpt_device_get_from_internal_name(p);
}
#if 0
// TODO: Load
for (c = 0; c < GAMEPORT_MAX; c++) {
sprintf(temp, "gameport%d_enabled", c + 1);
game_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0);
sprintf(temp, "gameport%d_device", c + 1);
p = ini_section_get_string(cat, temp, "none");
game_ports[c].device = gameport_get_from_internal_name(p);
}
for (uint8_t c = 0; c < GAMEPORT_MAX; c++) {
sprintf(temp, "gameport%d_type", c);
p = ini_section_get_string(cat, temp, "none");
gameport_type[c] = gameport_get_from_internal_name(p);
if (!strcmp(p, "none"))
ini_section_delete_var(cat, temp);
}
#endif
}
/* Load "Storage Controllers" section. */
@@ -2174,21 +2195,21 @@ save_input_devices(void)
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); 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++) {
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++) {
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++) {
sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr);
sprintf(temp, "%i, %i", joystick_state[js].pov_mapping[pov_nr][0],
joystick_state[js].pov_mapping[pov_nr][1]);
sprintf(temp, "%i, %i", joystick_state[0][js].pov_mapping[pov_nr][0],
joystick_state[0][js].pov_mapping[pov_nr][1]);
ini_section_set_string(cat, tmp2, temp);
}
}
@@ -2377,6 +2398,34 @@ save_ports(void)
lpt_device_get_internal_name(lpt_ports[c].device));
}
#if 0
// TODO: Save
for (c = 0; c < GAMEPORT_MAX; c++) {
sprintf(temp, "gameport%d_enabled", c + 1);
d = (c == 0) ? 1 : 0;
if (game_ports[c].enabled == d)
ini_section_delete_var(cat, temp);
else
ini_section_set_int(cat, temp, game_ports[c].enabled);
sprintf(temp, "gameport%d_device", c + 1);
if (game_ports[c].device == 0)
ini_section_delete_var(cat, temp);
else
ini_section_set_string(cat, temp,
gameport_get_internal_name(game_ports[c].device));
}
for (uint8_t c = 0; c < GAMEPORT_MAX; c++) {
sprintf(temp, "gameport%d_enabled", c);
if (gameport_type[c] == 0)
ini_section_delete_var(cat, temp);
else
ini_section_set_string(cat, temp,
gameport_get_internal_name(gameport_type[c]));
}
#endif
ini_delete_section_if_empty(config, cat);
}

View File

@@ -8,8 +8,6 @@
*
* Implementation of a generic Game Port.
*
*
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Sarah Walker, <https://pcem-emulator.co.uk/>
* RichardG, <richardg867@gmail.com>
@@ -18,7 +16,7 @@
* Copyright 2016-2022 Miran Grca.
* Copyright 2008-2018 Sarah Walker.
* Copyright 2021 RichardG.
* Copyright 2021-2024 Jasmine Iwanek.
* Copyright 2021-2025 Jasmine Iwanek.
*/
#include <stdio.h>
#include <stdint.h>
@@ -35,6 +33,12 @@
#include <86box/gameport.h>
#include <86box/plat_unused.h>
device_t game_ports[GAMEPORT_MAX];
typedef struct {
const device_t *device;
} GAMEPORT;
typedef struct g_axis_t {
pc_timer_t timer;
int axis_nr;
@@ -98,7 +102,7 @@ static const struct {
{ NULL }
};
static joystick_instance_t *joystick_instance = NULL;
static joystick_instance_t *joystick_instance[GAMEPORT_MAX] = { NULL, NULL };
static uint8_t gameport_pnp_rom[] = {
0x09, 0xf8, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, /* BOX0002, dummy checksum (filled in by isapnp_add_card) */
@@ -280,10 +284,10 @@ gameport_update_joystick_type(void)
gameport_add(standalone_gameport_type);
/* Reset the joystick interface. */
if (joystick_instance) {
joystick_instance->intf->close(joystick_instance->dat);
joystick_instance->intf = joysticks[joystick_type].joystick;
joystick_instance->dat = joystick_instance->intf->init();
if (joystick_instance[0]) {
joystick_instance[0]->intf->close(joystick_instance[0]->dat);
joystick_instance[0]->intf = joysticks[joystick_type].joystick;
joystick_instance[0]->dat = joystick_instance[0]->intf->init();
}
}
@@ -368,30 +372,30 @@ gameport_init(const device_t *info)
memset(dev, 0x00, sizeof(gameport_t));
/* Allocate global instance. */
if (!joystick_instance && joystick_type) {
joystick_instance = malloc(sizeof(joystick_instance_t));
memset(joystick_instance, 0x00, sizeof(joystick_instance_t));
if (!joystick_instance[0] && joystick_type) {
joystick_instance[0] = malloc(sizeof(joystick_instance_t));
memset(joystick_instance[0], 0x00, sizeof(joystick_instance_t));
joystick_instance->axis[0].joystick = joystick_instance;
joystick_instance->axis[1].joystick = joystick_instance;
joystick_instance->axis[2].joystick = joystick_instance;
joystick_instance->axis[3].joystick = joystick_instance;
joystick_instance[0]->axis[0].joystick = joystick_instance[0];
joystick_instance[0]->axis[1].joystick = joystick_instance[0];
joystick_instance[0]->axis[2].joystick = joystick_instance[0];
joystick_instance[0]->axis[3].joystick = joystick_instance[0];
joystick_instance->axis[0].axis_nr = 0;
joystick_instance->axis[1].axis_nr = 1;
joystick_instance->axis[2].axis_nr = 2;
joystick_instance->axis[3].axis_nr = 3;
joystick_instance[0]->axis[0].axis_nr = 0;
joystick_instance[0]->axis[1].axis_nr = 1;
joystick_instance[0]->axis[2].axis_nr = 2;
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->axis[1].timer, timer_over, &joystick_instance->axis[1], 0);
timer_add(&joystick_instance->axis[2].timer, timer_over, &joystick_instance->axis[2], 0);
timer_add(&joystick_instance->axis[3].timer, timer_over, &joystick_instance->axis[3], 0);
timer_add(&joystick_instance[0]->axis[0].timer, timer_over, &joystick_instance[0]->axis[0], 0);
timer_add(&joystick_instance[0]->axis[1].timer, timer_over, &joystick_instance[0]->axis[1], 0);
timer_add(&joystick_instance[0]->axis[2].timer, timer_over, &joystick_instance[0]->axis[2], 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->dat = joystick_instance->intf->init();
joystick_instance[0]->intf = joysticks[joystick_type].joystick;
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. */
dev->len = (info->local >> 16) & 0xff;
@@ -460,11 +464,11 @@ gameport_close(void *priv)
gameport_remap(dev, 0);
/* Free the global instance here, if it wasn't already freed. */
if (joystick_instance) {
joystick_instance->intf->close(joystick_instance->dat);
if (joystick_instance[0]) {
joystick_instance[0]->intf->close(joystick_instance[0]->dat);
free(joystick_instance);
joystick_instance = NULL;
free(joystick_instance[0]);
joystick_instance[0] = NULL;
}
free(dev);
@@ -733,3 +737,63 @@ const device_t gameport_sio_1io_device = {
.force_redraw = NULL,
.config = NULL
};
static const GAMEPORT gameports[] = {
{ &device_none },
{ &device_internal },
{ &gameport_device },
{ &gameport_208_device },
{ &gameport_pnp_device },
{ &gameport_tm_acm_device },
{ NULL }
// clang-format on
};
/* UI */
int
gameport_available(int port)
{
if (gameports[port].device)
return (device_available(gameports[port].device));
return 1;
}
/* UI */
const device_t *
gameports_getdevice(int port)
{
return (gameports[port].device);
}
/* UI */
int
gameport_has_config(int port)
{
if (!gameports[port].device)
return 0;
return (device_has_config(gameports[port].device) ? 1 : 0);
}
/* UI */
const char *
gameport_get_internal_name(int port)
{
return device_get_internal_name(gameports[port].device);
}
/* UI */
int
gameport_get_from_internal_name(const char *str)
{
int c = 0;
while (gameports[c].device != NULL) {
if (!strcmp(gameports[c].device->internal_name, str))
return c;
c++;
}
return 0;
}

View File

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

View File

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

View File

@@ -141,7 +141,7 @@ sw_read(void *priv)
sw_data *sw = (sw_data *) priv;
uint8_t temp = 0;
if (!JOYSTICK_PRESENT(0))
if (!JOYSTICK_PRESENT(0, 0))
return 0xff;
if (timer_is_enabled(&sw->poll_timer)) {
@@ -167,7 +167,7 @@ sw_write(void *priv)
sw_data *sw = (sw_data *) priv;
int64_t time_since_last = timer_get_remaining_us(&sw->trigger_timer);
if (!JOYSTICK_PRESENT(0))
if (!JOYSTICK_PRESENT(0, 0))
return;
if (!sw->poll_left) {
@@ -193,20 +193,20 @@ sw_write(void *priv)
for (uint8_t js = 0; js < 4; js++) {
uint16_t data = 0x3fff;
if (!JOYSTICK_PRESENT(js))
if (!JOYSTICK_PRESENT(0, js))
break;
if (joystick_state[js].axis[1] < -16383)
if (joystick_state[0][js].axis[1] < -16383)
data &= ~1;
if (joystick_state[js].axis[1] > 16383)
if (joystick_state[0][js].axis[1] > 16383)
data &= ~2;
if (joystick_state[js].axis[0] > 16383)
if (joystick_state[0][js].axis[0] > 16383)
data &= ~4;
if (joystick_state[js].axis[0] < -16383)
if (joystick_state[0][js].axis[0] < -16383)
data &= ~8;
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));
}
@@ -230,7 +230,7 @@ sw_write(void *priv)
static int
sw_read_axis(UNUSED(void *priv), UNUSED(int axis))
{
if (!JOYSTICK_PRESENT(0))
if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT;
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;
if (JOYSTICK_PRESENT(0)) {
if (joystick_state[0].button[0])
if (JOYSTICK_PRESENT(0, 0)) {
if (joystick_state[0][0].button[0])
ret &= ~0x10;
if (joystick_state[0].button[1])
if (joystick_state[0][0].button[1])
ret &= ~0x20;
if (joystick_state[0].button[2])
if (joystick_state[0][0].button[2])
ret &= ~0x40;
if (joystick_state[0].button[3])
if (joystick_state[0][0].button[3])
ret &= ~0x80;
}
@@ -85,26 +85,26 @@ tm_fcs_write(UNUSED(void *priv))
static int
tm_fcs_read_axis(UNUSED(void *priv), int axis)
{
if (!JOYSTICK_PRESENT(0))
if (!JOYSTICK_PRESENT(0, 0))
return AXIS_NOT_PRESENT;
switch (axis) {
case 0:
return joystick_state[0].axis[0];
return joystick_state[0][0].axis[0];
case 1:
return joystick_state[0].axis[1];
return joystick_state[0][0].axis[1];
case 2:
return 0;
case 3:
if (joystick_state[0].pov[0] == -1)
if (joystick_state[0][0].pov[0] == -1)
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;
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;
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;
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 0;
default:

View File

@@ -8,14 +8,14 @@
*
* Main include file for the application.
*
*
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
* Jasmine Iwanek, <jriwanek@gmail.com>
*
* Copyright 2016-2020 Miran Grca.
* Copyright 2017-2020 Fred N. van Kempen.
* Copyright 2021 Laci bá'
* Copyright 2021-2025 Jasmine Iwanek.
*/
#ifndef EMU_86BOX_H
#define EMU_86BOX_H
@@ -131,6 +131,7 @@ extern int bugger_enabled; /* (C) enable ISAbugger */
extern int novell_keycard_enabled; /* (C) enable Novell NetWare 2.x key card emulation. */
extern int postcard_enabled; /* (C) enable POST card */
extern int unittester_enabled; /* (C) enable unit tester device */
extern int gameport_type[]; /* (C) enable gameports */
extern int isamem_type[]; /* (C) enable ISA mem cards */
extern int isartc_type; /* (C) enable ISA RTC card */
extern int sound_is_float; /* (C) sound uses FP values */

View File

@@ -8,16 +8,16 @@
*
* Configuration file handler header.
*
*
*
* Authors: Sarah Walker,
* Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
* Overdoze,
* Jasmine Iwanek, <jriwanek@gmail.com>
*
* Copyright 2008-2017 Sarah Walker.
* Copyright 2016-2017 Miran Grca.
* Copyright 2017 Fred N. van Kempen.
* Copyright 2021-2025 Jasmine Iwanek.
*/
#ifndef EMU_CONFIG_H
#define EMU_CONFIG_H
@@ -111,6 +111,7 @@ typedef struct config_t {
# ifdef USE_SERIAL_DEVICES
char serial_devices[SERIAL_MAX][32]; /* Serial device names */
# endif
char gameport_devices[GAMEPORT_MAX][32]; /* gameport device names */
/* Other peripherals category */
int fdc_current[FDC_MAX]; /* Floppy disk controller type */

View File

@@ -8,8 +8,6 @@
*
* Definitions for the generic game port handlers.
*
*
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Sarah Walker, <https://pcem-emulator.co.uk/>
* RichardG, <richardg867@gmail.com>
@@ -18,11 +16,13 @@
* Copyright 2016-2022 Miran Grca.
* Copyright 2008-2018 Sarah Walker.
* Copyright 2021 RichardG.
* Copyright 2021-2024 Jasmine Iwanek.
* Copyright 2021-2025 Jasmine Iwanek.
*/
#ifndef EMU_GAMEPORT_H
#define EMU_GAMEPORT_H
#define GAMEPORT_MAX 2
#define MAX_PLAT_JOYSTICKS 8
#define MAX_JOYSTICKS 4
@@ -45,7 +45,7 @@
#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_6ADDR 0x060000
@@ -110,10 +110,20 @@ typedef struct joystick_if_t {
const char *pov_names[MAX_JOY_POVS];
} joystick_if_t;
extern device_t game_ports[GAMEPORT_MAX];
#ifdef __cplusplus
extern "C" {
#endif
extern int gameport_available(int port);
#ifdef EMU_DEVICE_H
extern const device_t *gameport_getdevice(int port);
#endif
extern int gameport_has_config(int port);
extern const char *gameport_get_internal_name(int port);
extern int gameport_get_from_internal_name(const char *str);
#ifdef EMU_DEVICE_H
extern const device_t gameport_device;
extern const device_t gameport_201_device;
@@ -136,7 +146,7 @@ extern const device_t *standalone_gameport_type;
#endif
extern int gameport_instance_id;
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 joystick_type;
@@ -173,6 +183,15 @@ extern const joystick_if_t joystick_ch_flightstick_pro;
extern const joystick_if_t joystick_sw_pad;
extern const joystick_if_t joystick_tm_fcs;
extern int gameport_available(int);
extern int gameport_has_config(int);
extern const char *gameport_get_internal_name(int);
extern int gampeport_get_from_internal_name(char *);
#ifdef EMU_DEVICE_H
extern const device_t *gameport_getdevice(int);
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -41,7 +41,7 @@ JoystickConfiguration::JoystickConfiguration(int type, int joystick_nr, QWidget
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);
}
@@ -119,7 +119,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
}
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)
cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2);
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);
}
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(cbox, row, 1);
@@ -179,7 +179,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
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;
if (mapping & POV_X)
cbox->setCurrentIndex((mapping & 3) * 2);

View File

@@ -136,7 +136,7 @@ static int
get_axis(JoystickConfiguration &jc, int axis, int joystick_nr)
{
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) {
return axis_sel;
@@ -153,7 +153,7 @@ static int
get_pov(JoystickConfiguration &jc, int pov, int joystick_nr)
{
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 & 1)
@@ -176,19 +176,19 @@ updateJoystickConfig(int type, int joystick_nr, QWidget *parent)
break;
}
joystick_state[joystick_nr].plat_joystick_nr = jc.selectedDevice();
if (joystick_state[joystick_nr].plat_joystick_nr) {
joystick_state[0][joystick_nr].plat_joystick_nr = jc.selectedDevice();
if (joystick_state[0][joystick_nr].plat_joystick_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++) {
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) {
joystick_state[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][0] = get_pov(jc, pov_nr, 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.
*
*
*
* 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 2021 Joakim L. Gilje
* Copyright 2017-2021 Sarah Walker.
* Copyright 2021 Joakim L. Gilje.
* Copyright 2021-2025 Jasmine Iwanek.
*/
#include <SDL2/SDL.h>
@@ -33,8 +33,8 @@
#include <86box/gameport.h>
#include <86box/plat_unused.h>
int joysticks_present;
joystick_t joystick_state[MAX_JOYSTICKS];
int joysticks_present = 0;
joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
static SDL_Joystick *sdl_joy[MAX_PLAT_JOYSTICKS];
@@ -89,7 +89,7 @@ joystick_close(void)
}
static int
joystick_get_axis(int joystick_nr, int mapping)
joystick_get_axis(int gameport, int joystick_nr, int mapping)
{
if (mapping & POV_X) {
switch (plat_joystick_state[joystick_nr].p[mapping & 3]) {
@@ -144,44 +144,44 @@ joystick_process(void)
#if 0
pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", js,
joystick_state[js].x,
joystick_state[js].y,
joystick_state[js].b[0],
joystick_state[js].b[1],
joystick_state[0][js].x,
joystick_state[0][js].y,
joystick_state[0][js].b[0],
joystick_state[0][js].b[1],
joysticks_present);
#endif
}
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
if (joystick_state[js].plat_joystick_nr) {
int joystick_nr = joystick_state[js].plat_joystick_nr - 1;
if (joystick_state[0][js].plat_joystick_nr) {
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++)
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++)
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++) {
int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]);
int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]);
int x = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]);
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 magnitude = sqrt((double) x * (double) x + (double) y * (double) y);
if (magnitude < 16384)
joystick_state[js].pov[pov_nr] = -1;
joystick_state[0][js].pov[pov_nr] = -1;
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 {
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++)
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++)
joystick_state[js].pov[pov_nr] = -1;
joystick_state[0][js].pov[pov_nr] = -1;
}
}
}

View File

@@ -8,15 +8,13 @@
*
* RawInput joystick interface.
*
*
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* GH Cao, <driver1998.ms@outlook.com>
* Jasmine Iwanek,
* Jasmine Iwanek, <jriwanek@gmail.com>
*
* Copyright 2016-2018 Miran Grca.
* Copyright 2020 GH Cao.
* Copyright 2021-2023 Jasmine Iwanek.
* Copyright 2021-2025 Jasmine Iwanek.
*/
#include <windows.h>
#include <windowsx.h>
@@ -98,9 +96,9 @@ typedef struct {
} pov[MAX_JOY_POVS];
} raw_joystick_t;
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
joystick_t joystick_state[MAX_JOYSTICKS];
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];
@@ -419,7 +417,7 @@ win_joystick_handle(PRAWINPUT raw)
if (r == HIDP_STATUS_SUCCESS) {
for (int i = 0; i < usage_length; i++) {
int button = raw_joystick_state[j].usage_button[usage_list[i]];
int button = raw_joystick_state[j].usage_button[usage_list[i]];
plat_joystick_state[j].b[button] = 128;
}
}
@@ -455,7 +453,7 @@ win_joystick_handle(PRAWINPUT raw)
plat_joystick_state[j].a[axis_nr] = value;
#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
}
@@ -477,7 +475,7 @@ win_joystick_handle(PRAWINPUT raw)
plat_joystick_state[j].p[pov_nr] = value;
#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
}
#if 0
@@ -512,35 +510,35 @@ joystick_process(void)
return;
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
if (joystick_state[js].plat_joystick_nr) {
int joystick_nr = joystick_state[js].plat_joystick_nr - 1;
if (joystick_state[0][js].plat_joystick_nr) {
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++)
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++)
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++) {
int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]);
int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]);
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[0][js].pov_mapping[pov_nr][1]);
double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI);
double magnitude = sqrt((double) x * (double) x + (double) y * (double) y);
if (magnitude < 16384)
joystick_state[js].pov[pov_nr] = -1;
joystick_state[0][js].pov[pov_nr] = -1;
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 {
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++)
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++)
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 wchar_t sdl_win_title[512];
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;
SDL_mutex *blitmtx;
SDL_threadID eventthread;