Some improvements to code readability

This commit is contained in:
Jasmine Iwanek
2025-07-11 16:54:03 -04:00
parent e40889c5b7
commit 67e7136ff9
9 changed files with 108 additions and 107 deletions

View File

@@ -61,13 +61,13 @@ typedef struct _joystick_instance_ {
uint8_t state;
g_axis_t axis[4];
const joystick_if_t *intf;
void *dat;
const joystick_t *intf;
void *dat;
} joystick_instance_t;
int joystick_type = JS_TYPE_NONE;
static const joystick_if_t joystick_none = {
static const joystick_t joystick_none = {
.name = "None",
.internal_name = "none",
.init = NULL,
@@ -86,7 +86,7 @@ static const joystick_if_t joystick_none = {
};
static const struct {
const joystick_if_t *joystick;
const joystick_t *joystick;
} joysticks[] = {
{ &joystick_none },
{ &joystick_2axis_2button },
@@ -100,7 +100,7 @@ static const struct {
{ &joystick_3axis_2button },
{ &joystick_2button_yoke_throttle },
{ &joystick_3axis_4button },
{ &joystick_win95_steering_wheel }, // Temp
{ &joystick_win95_steering_wheel },
{ &joystick_4button_yoke_throttle },
{ &joystick_4axis_4button },
{ &joystick_ch_flightstick_pro },
@@ -114,24 +114,39 @@ static const struct {
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) */
0x0a, 0x10, 0x10, /* PnP version 1.0, vendor version 1.0 */
0x82, 0x09, 0x00, 'G', 'a', 'm', 'e', ' ', 'P', 'o', 'r', 't', /* ANSI identifier */
/* BOX0002, serial 0, dummy checksum (filled in by isapnp_add_card) */
0x09, 0xf8, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
/* PnP version 1.0, vendor version 1.0 */
0x0a, 0x10, 0x10,
/* ANSI identifier */
0x82, 0x09, 0x00, 'G', 'a', 'm', 'e', ' ', 'P', 'o', 'r', 't',
0x15, 0x09, 0xf8, 0x00, 0x02, 0x01, /* logical device BOX0002, can participate in boot */
0x1c, 0x41, 0xd0, 0xb0, 0x2f, /* compatible device PNPB02F */
0x31, 0x00, /* start dependent functions, preferred */
0x47, 0x01, 0x00, 0x02, 0x00, 0x02, 0x08, 0x08, /* I/O 0x200, decodes 16-bit, 8-byte alignment, 8 addresses */
0x30, /* start dependent functions, acceptable */
0x47, 0x01, 0x08, 0x02, 0x08, 0x02, 0x08, 0x08, /* I/O 0x208, decodes 16-bit, 8-byte alignment, 8 addresses */
0x31, 0x02, /* start dependent functions, sub-optimal */
0x47, 0x01, 0x00, 0x01, 0xf8, 0xff, 0x08, 0x08, /* I/O 0x100-0xFFF8, decodes 16-bit, 8-byte alignment, 8 addresses */
0x38, /* end dependent functions */
/* Logical device BOX0002, can participate in boot */
0x15, 0x09, 0xf8, 0x00, 0x02, 0x01,
/* Compatible device PNPB02F */
0x1c, 0x41, 0xd0, 0xb0, 0x2f,
/* Start dependent functions, preferred */
0x31, 0x00,
/* I/O 0x200, decodes 16-bit, 8-byte alignment, 8 addresses */
0x47, 0x01, 0x00, 0x02, 0x00, 0x02, 0x08, 0x08,
/* Start dependent functions, acceptable */
0x30,
/* I/O 0x208, decodes 16-bit, 8-byte alignment, 8 addresses */
0x47, 0x01, 0x08, 0x02, 0x08, 0x02, 0x08, 0x08,
/* Start dependent functions, sub-optimal */
0x31, 0x02,
/* I/O 0x100-0xFFF8, decodes 16-bit, 8-byte alignment, 8 addresses */
0x47, 0x01, 0x00, 0x01, 0xf8, 0xff, 0x08, 0x08,
/* End dependent functions */
0x38,
0x79, 0x00 /* end tag, dummy checksum (filled in by isapnp_add_card) */
/* End tag, dummy checksum (filled in by isapnp_add_card) */
0x79, 0x00
};
static const isapnp_device_config_t gameport_pnp_defaults[] = {
{.activate = 1,
{
.activate = 1,
.io = {
{ .base = 0x200 },
}
@@ -244,10 +259,8 @@ gameport_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), void *priv)
/* Read all axes. */
joystick->state |= 0x0f;
gameport_time(joystick, 0, joystick->intf->read_axis(joystick->dat, 0));
gameport_time(joystick, 1, joystick->intf->read_axis(joystick->dat, 1));
gameport_time(joystick, 2, joystick->intf->read_axis(joystick->dat, 2));
gameport_time(joystick, 3, joystick->intf->read_axis(joystick->dat, 3));
for (uint8_t i = 0; i < 4; i++)
gameport_time(joystick, i, joystick->intf->read_axis(joystick->dat, i));
/* Notify the interface. */
joystick->intf->write(joystick->dat);
@@ -384,20 +397,14 @@ gameport_init(const device_t *info)
if (!joystick_instance[0] && joystick_type) {
joystick_instance[0] = calloc(1, sizeof(joystick_instance_t));
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];
// For each analog joystick axis
for (uint8_t i = 0; i < 4; i++) {
joystick_instance[0]->axis[i].joystick = joystick_instance[0];
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;
joystick_instance[0]->axis[i].axis_nr = i;
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);
timer_add(&joystick_instance[0]->axis[i].timer, timer_over, &joystick_instance[0]->axis[i], 0);
}
joystick_instance[0]->intf = joysticks[joystick_type].joystick;
joystick_instance[0]->dat = joystick_instance[0]->intf->init();
@@ -771,7 +778,7 @@ gameport_available(int port)
/* UI */
const device_t *
gameports_getdevice(int port)
gameport_getdevice(int port)
{
return (gameports[port].device);
}

View File

@@ -8,8 +8,6 @@
*
* Implementation of the Flight Stick Pro.
*
*
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Sarah Walker, <https://pcem-emulator.co.uk/>
*
@@ -138,7 +136,7 @@ ch_flightstick_pro_a0_over(UNUSED(void *priv))
//
}
const joystick_if_t joystick_ch_flightstick_pro = {
const joystick_t joystick_ch_flightstick_pro = {
.name = "CH Flightstick Pro",
.internal_name = "ch_flightstick_pro",
.init = ch_flightstick_pro_init,
@@ -156,7 +154,7 @@ const joystick_if_t joystick_ch_flightstick_pro = {
.pov_names = { "POV" }
};
const joystick_if_t joystick_ch_flightstick_pro_ch_pedals = {
const joystick_t joystick_ch_flightstick_pro_ch_pedals = {
.name = "CH Flightstick Pro + CH Pedals",
.internal_name = "ch_flightstick_pro_ch_pedals",
.init = ch_flightstick_pro_init,

View File

@@ -274,7 +274,7 @@ joystick_standard_a0_over(UNUSED(void *priv))
//
}
const joystick_if_t joystick_2axis_2button = {
const joystick_t joystick_2axis_2button = {
.name = "2-axis, 2-button joystick(s)",
.internal_name = "2axis_2button",
.init = joystick_standard_init,
@@ -292,7 +292,7 @@ const joystick_if_t joystick_2axis_2button = {
.pov_names = { NULL }
};
const joystick_if_t joystick_2button_gamepad = {
const joystick_t joystick_2button_gamepad = {
.name = "2-button gamepad(s)",
.internal_name = "2button_gamepad",
.init = joystick_standard_init,
@@ -310,7 +310,7 @@ const joystick_if_t joystick_2button_gamepad = {
.pov_names = { NULL }
};
const joystick_if_t joystick_2button_flight_yoke = {
const joystick_t joystick_2button_flight_yoke = {
.name = "2-button flight yoke",
.internal_name = "2button_flight_yoke",
.init = joystick_standard_init,
@@ -328,7 +328,7 @@ const joystick_if_t joystick_2button_flight_yoke = {
.pov_names = { NULL }
};
const joystick_if_t joystick_2axis_4button = {
const joystick_t joystick_2axis_4button = {
.name = "2-axis, 4-button joystick",
.internal_name = "2axis_4button",
.init = joystick_standard_init,
@@ -346,7 +346,7 @@ const joystick_if_t joystick_2axis_4button = {
.pov_names = { NULL }
};
const joystick_if_t joystick_4button_gamepad = {
const joystick_t joystick_4button_gamepad = {
.name = "4-button gamepad",
.internal_name = "4button_gamepad",
.init = joystick_standard_init,
@@ -364,7 +364,7 @@ const joystick_if_t joystick_4button_gamepad = {
.pov_names = { NULL }
};
const joystick_if_t joystick_4button_flight_yoke = {
const joystick_t joystick_4button_flight_yoke = {
.name = "4-button flight yoke",
.internal_name = "4button_flight_yoke",
.init = joystick_standard_init,
@@ -382,7 +382,7 @@ const joystick_if_t joystick_4button_flight_yoke = {
.pov_names = { NULL }
};
const joystick_if_t joystick_3axis_2button = {
const joystick_t joystick_3axis_2button = {
.name = "3-axis, 2-button joystick",
.internal_name = "3axis_2button",
.init = joystick_standard_init,
@@ -400,7 +400,7 @@ const joystick_if_t joystick_3axis_2button = {
.pov_names = { NULL }
};
const joystick_if_t joystick_2button_yoke_throttle = {
const joystick_t joystick_2button_yoke_throttle = {
.name = "2-button flight yoke with throttle",
.internal_name = "2button_yoke_throttle",
.init = joystick_standard_init,
@@ -418,7 +418,7 @@ const joystick_if_t joystick_2button_yoke_throttle = {
.pov_names = { NULL }
};
const joystick_if_t joystick_3axis_4button = {
const joystick_t joystick_3axis_4button = {
.name = "3-axis, 4-button joystick",
.internal_name = "3axis_4button",
.init = joystick_standard_init,
@@ -436,7 +436,7 @@ const joystick_if_t joystick_3axis_4button = {
.pov_names = { NULL }
};
const joystick_if_t joystick_4button_yoke_throttle = {
const joystick_t joystick_4button_yoke_throttle = {
.name = "4-button flight yoke with throttle",
.internal_name = "4button_yoke_throttle",
.init = joystick_standard_init,
@@ -454,7 +454,7 @@ const joystick_if_t joystick_4button_yoke_throttle = {
.pov_names = { NULL }
};
const joystick_if_t joystick_win95_steering_wheel = {
const joystick_t joystick_win95_steering_wheel = {
.name = "Win95 Steering Wheel (3-axis, 4-button)",
.internal_name = "win95_steering_wheel",
.init = joystick_standard_init,
@@ -472,7 +472,7 @@ const joystick_if_t joystick_win95_steering_wheel = {
.pov_names = { NULL }
};
const joystick_if_t joystick_4axis_4button = {
const joystick_t joystick_4axis_4button = {
.name = "4-axis, 4-button joystick",
.internal_name = "4axis_4button",
.init = joystick_standard_init,
@@ -490,7 +490,7 @@ const joystick_if_t joystick_4axis_4button = {
.pov_names = { NULL }
};
const joystick_if_t joystick_2axis_6button = {
const joystick_t joystick_2axis_6button = {
.name = "2-axis, 6-button joystick",
.internal_name = "2axis_6button",
.init = joystick_standard_init,
@@ -508,7 +508,7 @@ const joystick_if_t joystick_2axis_6button = {
.pov_names = { NULL }
};
const joystick_if_t joystick_2axis_8button = {
const joystick_t joystick_2axis_8button = {
.name = "2-axis, 8-button joystick",
.internal_name = "2axis_8button",
.init = joystick_standard_init,

View File

@@ -29,8 +29,6 @@
* - Some DOS stuff will write to 0x201 while a packet is
* being transferred. This seems to be ignored.
*
*
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Sarah Walker, <https://pcem-emulator.co.uk/>
*
@@ -244,7 +242,7 @@ sw_a0_over(void *priv)
timer_set_delay_u64(&sw->trigger_timer, TIMER_USEC * 10000);
}
const joystick_if_t joystick_sw_pad = {
const joystick_t joystick_sw_pad = {
.name = "Microsoft SideWinder Pad",
.internal_name = "sidewinder_pad",
.init = sw_init,

View File

@@ -8,8 +8,6 @@
*
* Implementation of Thrust Master Flight Control System.
*
*
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Sarah Walker, <https://pcem-emulator.co.uk/>
*
@@ -148,7 +146,7 @@ tm_fcs_a0_over(UNUSED(void *priv))
//
}
const joystick_if_t joystick_tm_fcs = {
const joystick_t joystick_tm_fcs = {
.name = "Thrustmaster Flight Control System",
.internal_name = "thrustmaster_fcs",
.init = tm_fcs_init,
@@ -166,7 +164,7 @@ const joystick_if_t joystick_tm_fcs = {
.pov_names = { "POV" }
};
const joystick_if_t joystick_tm_fcs_rcs = {
const joystick_t joystick_tm_fcs_rcs = {
.name = "Thrustmaster FCS + Rudder Control System",
.internal_name = "thrustmaster_fcs_rcs",
.init = tm_fcs_init,