Initial code for joystick port instancing
This commit is contained in:
@@ -102,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) */
|
||||
@@ -284,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,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;
|
||||
@@ -464,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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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*/
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user