2016-08-14 22:07:17 -04:00
|
|
|
/* Copyright holders: Sarah Walker
|
|
|
|
|
see COPYING for more details
|
|
|
|
|
*/
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdio.h>
|
2016-07-19 02:44:32 +02:00
|
|
|
#include <stdint.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <string.h>
|
2016-06-26 00:34:39 +02:00
|
|
|
#include <stdlib.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <wchar.h>
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "ibm.h"
|
2017-08-27 04:33:47 +01:00
|
|
|
#include "cpu/cpu.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "device.h"
|
|
|
|
|
#include "io.h"
|
|
|
|
|
#include "timer.h"
|
|
|
|
|
#include "gameport.h"
|
2016-07-23 01:48:47 +02:00
|
|
|
#include "joystick_ch_flightstick_pro.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "joystick_standard.h"
|
|
|
|
|
#include "joystick_sw_pad.h"
|
2016-07-23 01:48:47 +02:00
|
|
|
#include "joystick_tm_fcs.h"
|
2017-05-18 01:57:16 -04:00
|
|
|
#include "plat_joystick.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
int joystick_type;
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2016-09-16 02:32:25 +02:00
|
|
|
joystick_if_t joystick_none =
|
|
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
"No joystick",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0
|
2016-09-16 02:32:25 +02:00
|
|
|
};
|
|
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
static joystick_if_t *joystick_list[] =
|
|
|
|
|
{
|
|
|
|
|
&joystick_standard,
|
|
|
|
|
&joystick_standard_4button,
|
|
|
|
|
&joystick_standard_6button,
|
|
|
|
|
&joystick_standard_8button,
|
2016-07-23 01:48:47 +02:00
|
|
|
&joystick_ch_flightstick_pro,
|
2016-06-26 00:34:39 +02:00
|
|
|
&joystick_sw_pad,
|
2016-07-23 01:48:47 +02:00
|
|
|
&joystick_tm_fcs,
|
2016-09-16 02:32:25 +02:00
|
|
|
&joystick_none,
|
2016-06-26 00:34:39 +02:00
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
char *joystick_get_name(int joystick)
|
|
|
|
|
{
|
|
|
|
|
if (!joystick_list[joystick])
|
|
|
|
|
return NULL;
|
|
|
|
|
return joystick_list[joystick]->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int joystick_get_max_joysticks(int joystick)
|
|
|
|
|
{
|
|
|
|
|
return joystick_list[joystick]->max_joysticks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int joystick_get_axis_count(int joystick)
|
|
|
|
|
{
|
|
|
|
|
return joystick_list[joystick]->axis_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int joystick_get_button_count(int joystick)
|
|
|
|
|
{
|
|
|
|
|
return joystick_list[joystick]->button_count;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 01:48:47 +02:00
|
|
|
int joystick_get_pov_count(int joystick)
|
|
|
|
|
{
|
|
|
|
|
return joystick_list[joystick]->pov_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *joystick_get_axis_name(int joystick, int id)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
return joystick_list[joystick]->axis_names[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *joystick_get_button_name(int joystick, int id)
|
|
|
|
|
{
|
|
|
|
|
return joystick_list[joystick]->button_names[id];
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 01:48:47 +02:00
|
|
|
char *joystick_get_pov_name(int joystick, int id)
|
|
|
|
|
{
|
|
|
|
|
return joystick_list[joystick]->pov_names[id];
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-26 00:34:39 +02:00
|
|
|
typedef struct gameport_axis_t
|
|
|
|
|
{
|
2016-11-07 06:39:20 +01:00
|
|
|
int count;
|
2016-06-26 00:34:39 +02:00
|
|
|
int axis_nr;
|
|
|
|
|
struct gameport_t *gameport;
|
|
|
|
|
} gameport_axis_t;
|
|
|
|
|
|
|
|
|
|
typedef struct gameport_t
|
|
|
|
|
{
|
|
|
|
|
uint8_t state;
|
|
|
|
|
|
|
|
|
|
gameport_axis_t axis[4];
|
|
|
|
|
|
|
|
|
|
joystick_if_t *joystick;
|
|
|
|
|
void *joystick_dat;
|
|
|
|
|
} gameport_t;
|
|
|
|
|
|
|
|
|
|
static gameport_t *gameport_global = NULL;
|
|
|
|
|
|
|
|
|
|
static int gameport_time(int axis)
|
|
|
|
|
{
|
|
|
|
|
if (axis == AXIS_NOT_PRESENT)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
axis += 32768;
|
|
|
|
|
axis = (axis * 100) / 65; /*Axis now in ohms*/
|
|
|
|
|
axis = (axis * 11) / 1000;
|
|
|
|
|
return TIMER_USEC * (axis + 24); /*max = 11.115 ms*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameport_write(uint16_t addr, uint8_t val, void *p)
|
|
|
|
|
{
|
|
|
|
|
gameport_t *gameport = (gameport_t *)p;
|
|
|
|
|
|
|
|
|
|
timer_clock();
|
|
|
|
|
gameport->state |= 0x0f;
|
2017-02-04 06:53:46 +01:00
|
|
|
pclog("gameport_write : joysticks_present=%i\n", joysticks_present);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
gameport->axis[0].count = gameport_time(gameport->joystick->read_axis(gameport->joystick_dat, 0));
|
|
|
|
|
gameport->axis[1].count = gameport_time(gameport->joystick->read_axis(gameport->joystick_dat, 1));
|
|
|
|
|
gameport->axis[2].count = gameport_time(gameport->joystick->read_axis(gameport->joystick_dat, 2));
|
|
|
|
|
gameport->axis[3].count = gameport_time(gameport->joystick->read_axis(gameport->joystick_dat, 3));
|
|
|
|
|
|
|
|
|
|
gameport->joystick->write(gameport->joystick_dat);
|
|
|
|
|
|
|
|
|
|
cycles -= ISA_CYCLES(8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t gameport_read(uint16_t addr, void *p)
|
|
|
|
|
{
|
|
|
|
|
gameport_t *gameport = (gameport_t *)p;
|
|
|
|
|
uint8_t ret;
|
|
|
|
|
|
|
|
|
|
timer_clock();
|
2017-05-05 01:49:42 +02:00
|
|
|
ret = gameport->state | gameport->joystick->read(gameport->joystick_dat);
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
cycles -= ISA_CYCLES(8);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameport_timer_over(void *p)
|
|
|
|
|
{
|
|
|
|
|
gameport_axis_t *axis = (gameport_axis_t *)p;
|
|
|
|
|
gameport_t *gameport = axis->gameport;
|
|
|
|
|
|
|
|
|
|
gameport->state &= ~(1 << axis->axis_nr);
|
|
|
|
|
axis->count = 0;
|
|
|
|
|
|
|
|
|
|
if (axis == &gameport->axis[0])
|
|
|
|
|
gameport->joystick->a0_over(gameport->joystick_dat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *gameport_init_common()
|
|
|
|
|
{
|
|
|
|
|
gameport_t *gameport = malloc(sizeof(gameport_t));
|
|
|
|
|
|
|
|
|
|
memset(gameport, 0, sizeof(gameport_t));
|
|
|
|
|
|
|
|
|
|
gameport->axis[0].gameport = gameport;
|
|
|
|
|
gameport->axis[1].gameport = gameport;
|
|
|
|
|
gameport->axis[2].gameport = gameport;
|
|
|
|
|
gameport->axis[3].gameport = gameport;
|
|
|
|
|
|
|
|
|
|
gameport->axis[0].axis_nr = 0;
|
|
|
|
|
gameport->axis[1].axis_nr = 1;
|
|
|
|
|
gameport->axis[2].axis_nr = 2;
|
|
|
|
|
gameport->axis[3].axis_nr = 3;
|
|
|
|
|
|
|
|
|
|
timer_add(gameport_timer_over, &gameport->axis[0].count, &gameport->axis[0].count, &gameport->axis[0]);
|
|
|
|
|
timer_add(gameport_timer_over, &gameport->axis[1].count, &gameport->axis[1].count, &gameport->axis[1]);
|
|
|
|
|
timer_add(gameport_timer_over, &gameport->axis[2].count, &gameport->axis[2].count, &gameport->axis[2]);
|
|
|
|
|
timer_add(gameport_timer_over, &gameport->axis[3].count, &gameport->axis[3].count, &gameport->axis[3]);
|
|
|
|
|
|
|
|
|
|
gameport->joystick = joystick_list[joystick_type];
|
|
|
|
|
gameport->joystick_dat = gameport->joystick->init();
|
|
|
|
|
|
|
|
|
|
gameport_global = gameport;
|
|
|
|
|
|
|
|
|
|
return gameport;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameport_update_joystick_type()
|
|
|
|
|
{
|
|
|
|
|
gameport_t *gameport = gameport_global;
|
|
|
|
|
|
2016-12-23 03:16:24 +01:00
|
|
|
if (gameport)
|
|
|
|
|
{
|
|
|
|
|
gameport->joystick->close(gameport->joystick_dat);
|
|
|
|
|
gameport->joystick = joystick_list[joystick_type];
|
|
|
|
|
gameport->joystick_dat = gameport->joystick->init();
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *gameport_init()
|
|
|
|
|
{
|
2017-07-18 19:22:16 +02:00
|
|
|
gameport_t *gameport = NULL;
|
2016-09-16 02:32:25 +02:00
|
|
|
|
|
|
|
|
if (joystick_type == 7)
|
|
|
|
|
{
|
|
|
|
|
gameport = NULL;
|
|
|
|
|
return gameport;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 02:37:04 +02:00
|
|
|
gameport = gameport_init_common();
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
io_sethandler(0x0200, 0x0008, gameport_read, NULL, NULL, gameport_write, NULL, NULL, gameport);
|
|
|
|
|
|
|
|
|
|
return gameport;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *gameport_201_init()
|
|
|
|
|
{
|
2016-09-16 02:32:25 +02:00
|
|
|
gameport_t *gameport;
|
|
|
|
|
|
|
|
|
|
if (joystick_type == 7)
|
|
|
|
|
{
|
|
|
|
|
gameport = NULL;
|
|
|
|
|
return gameport;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gameport = gameport_init_common();
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
io_sethandler(0x0201, 0x0001, gameport_read, NULL, NULL, gameport_write, NULL, NULL, gameport);
|
|
|
|
|
|
|
|
|
|
return gameport;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gameport_close(void *p)
|
|
|
|
|
{
|
|
|
|
|
gameport_t *gameport = (gameport_t *)p;
|
2016-09-16 02:32:25 +02:00
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
gameport->joystick->close(gameport->joystick_dat);
|
|
|
|
|
|
|
|
|
|
gameport_global = NULL;
|
|
|
|
|
|
|
|
|
|
free(gameport);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
device_t gameport_device =
|
|
|
|
|
{
|
|
|
|
|
"Game port",
|
|
|
|
|
0,
|
|
|
|
|
gameport_init,
|
|
|
|
|
gameport_close,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
device_t gameport_201_device =
|
|
|
|
|
{
|
|
|
|
|
"Game port (port 201h only)",
|
|
|
|
|
0,
|
|
|
|
|
gameport_201_init,
|
|
|
|
|
gameport_close,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL
|
|
|
|
|
};
|