Moved the gameport and joysticks into subfolder.
This commit is contained in:
280
src/game/gameport.c
Normal file
280
src/game/gameport.c
Normal file
@@ -0,0 +1,280 @@
|
||||
/* Copyright holders: Sarah Walker
|
||||
see COPYING for more details
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include "../ibm.h"
|
||||
#include "../cpu/cpu.h"
|
||||
#include "../device.h"
|
||||
#include "../io.h"
|
||||
#include "../timer.h"
|
||||
#include "gameport.h"
|
||||
#include "joystick_ch_flightstick_pro.h"
|
||||
#include "joystick_standard.h"
|
||||
#include "joystick_sw_pad.h"
|
||||
#include "joystick_tm_fcs.h"
|
||||
#include "../win/plat_joystick.h"
|
||||
|
||||
|
||||
int joystick_type;
|
||||
|
||||
|
||||
joystick_if_t joystick_none =
|
||||
{
|
||||
"No joystick",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
static joystick_if_t *joystick_list[] =
|
||||
{
|
||||
&joystick_standard,
|
||||
&joystick_standard_4button,
|
||||
&joystick_standard_6button,
|
||||
&joystick_standard_8button,
|
||||
&joystick_ch_flightstick_pro,
|
||||
&joystick_sw_pad,
|
||||
&joystick_tm_fcs,
|
||||
&joystick_none,
|
||||
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;
|
||||
}
|
||||
|
||||
int joystick_get_pov_count(int joystick)
|
||||
{
|
||||
return joystick_list[joystick]->pov_count;
|
||||
}
|
||||
|
||||
char *joystick_get_axis_name(int joystick, int id)
|
||||
{
|
||||
return joystick_list[joystick]->axis_names[id];
|
||||
}
|
||||
|
||||
char *joystick_get_button_name(int joystick, int id)
|
||||
{
|
||||
return joystick_list[joystick]->button_names[id];
|
||||
}
|
||||
|
||||
char *joystick_get_pov_name(int joystick, int id)
|
||||
{
|
||||
return joystick_list[joystick]->pov_names[id];
|
||||
}
|
||||
|
||||
typedef struct gameport_axis_t
|
||||
{
|
||||
int count;
|
||||
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;
|
||||
pclog("gameport_write : joysticks_present=%i\n", joysticks_present);
|
||||
|
||||
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();
|
||||
ret = gameport->state | gameport->joystick->read(gameport->joystick_dat);
|
||||
|
||||
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;
|
||||
|
||||
if (gameport)
|
||||
{
|
||||
gameport->joystick->close(gameport->joystick_dat);
|
||||
gameport->joystick = joystick_list[joystick_type];
|
||||
gameport->joystick_dat = gameport->joystick->init();
|
||||
}
|
||||
}
|
||||
|
||||
void *gameport_init()
|
||||
{
|
||||
gameport_t *gameport = NULL;
|
||||
|
||||
if (joystick_type == 7)
|
||||
{
|
||||
gameport = NULL;
|
||||
return gameport;
|
||||
}
|
||||
|
||||
gameport = gameport_init_common();
|
||||
|
||||
io_sethandler(0x0200, 0x0008, gameport_read, NULL, NULL, gameport_write, NULL, NULL, gameport);
|
||||
|
||||
return gameport;
|
||||
}
|
||||
|
||||
void *gameport_201_init()
|
||||
{
|
||||
gameport_t *gameport;
|
||||
|
||||
if (joystick_type == 7)
|
||||
{
|
||||
gameport = NULL;
|
||||
return gameport;
|
||||
}
|
||||
|
||||
gameport = gameport_init_common();
|
||||
|
||||
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;
|
||||
|
||||
if (!p)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
45
src/game/gameport.h
Normal file
45
src/game/gameport.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Copyright holders: Sarah Walker
|
||||
see COPYING for more details
|
||||
*/
|
||||
#ifndef EMU_GAMEPORT_H
|
||||
# define EMU_GAMEPORT_H
|
||||
|
||||
|
||||
#define AXIS_NOT_PRESENT -99999
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[80];
|
||||
void *(*init)(void);
|
||||
void (*close)(void *p);
|
||||
uint8_t (*read)(void *p);
|
||||
void (*write)(void *p);
|
||||
int (*read_axis)(void *p, int axis);
|
||||
void (*a0_over)(void *p);
|
||||
int axis_count, button_count, pov_count;
|
||||
int max_joysticks;
|
||||
char axis_names[8][32];
|
||||
char button_names[32][32];
|
||||
char pov_names[4][32];
|
||||
} joystick_if_t;
|
||||
|
||||
extern device_t gameport_device;
|
||||
extern device_t gameport_201_device;
|
||||
|
||||
extern int joystick_type;
|
||||
|
||||
|
||||
extern char *joystick_get_name(int joystick);
|
||||
extern int joystick_get_max_joysticks(int joystick);
|
||||
extern int joystick_get_axis_count(int joystick);
|
||||
extern int joystick_get_button_count(int joystick);
|
||||
extern int joystick_get_pov_count(int joystick);
|
||||
extern char *joystick_get_axis_name(int joystick, int id);
|
||||
extern char *joystick_get_button_name(int joystick, int id);
|
||||
extern char *joystick_get_pov_name(int joystick, int id);
|
||||
|
||||
extern void gameport_update_joystick_type(void);
|
||||
|
||||
|
||||
#endif /*EMU_GAMEPORT_H*/
|
||||
97
src/game/joystick_ch_flightstick_pro.c
Normal file
97
src/game/joystick_ch_flightstick_pro.c
Normal file
@@ -0,0 +1,97 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include "../ibm.h"
|
||||
#include "../device.h"
|
||||
#include "../timer.h"
|
||||
#include "../win/plat_joystick.h"
|
||||
#include "gameport.h"
|
||||
#include "joystick_standard.h"
|
||||
|
||||
|
||||
static void *ch_flightstick_pro_init()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ch_flightstick_pro_close(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
static uint8_t ch_flightstick_pro_read(void *p)
|
||||
{
|
||||
uint8_t ret = 0xf0;
|
||||
|
||||
if (JOYSTICK_PRESENT(0))
|
||||
{
|
||||
if (joystick_state[0].button[0])
|
||||
ret &= ~0x10;
|
||||
if (joystick_state[0].button[1])
|
||||
ret &= ~0x20;
|
||||
if (joystick_state[0].button[2])
|
||||
ret &= ~0x40;
|
||||
if (joystick_state[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)
|
||||
ret &= ~0xf0;
|
||||
else if (joystick_state[0].pov[0] >= 45 && joystick_state[0].pov[0] < 135)
|
||||
ret &= ~0xb0;
|
||||
else if (joystick_state[0].pov[0] >= 135 && joystick_state[0].pov[0] < 225)
|
||||
ret &= ~0x70;
|
||||
else if (joystick_state[0].pov[0] >= 225 && joystick_state[0].pov[0] < 315)
|
||||
ret &= ~0x30;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ch_flightstick_pro_write(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
static int ch_flightstick_pro_read_axis(void *p, int axis)
|
||||
{
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return AXIS_NOT_PRESENT;
|
||||
|
||||
switch (axis)
|
||||
{
|
||||
case 0:
|
||||
return joystick_state[0].axis[0];
|
||||
case 1:
|
||||
return joystick_state[0].axis[1];
|
||||
case 2:
|
||||
return 0;
|
||||
case 3:
|
||||
return joystick_state[0].axis[2];
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void ch_flightstick_pro_a0_over(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
joystick_if_t joystick_ch_flightstick_pro =
|
||||
{
|
||||
"CH Flightstick Pro",
|
||||
ch_flightstick_pro_init,
|
||||
ch_flightstick_pro_close,
|
||||
ch_flightstick_pro_read,
|
||||
ch_flightstick_pro_write,
|
||||
ch_flightstick_pro_read_axis,
|
||||
ch_flightstick_pro_a0_over,
|
||||
1,
|
||||
3,
|
||||
4,
|
||||
1,
|
||||
{"X axis", "Y axis", "Throttle"},
|
||||
{"Button 1", "Button 2", "Button 3", "Button 4"},
|
||||
{"POV"}
|
||||
};
|
||||
1
src/game/joystick_ch_flightstick_pro.h
Normal file
1
src/game/joystick_ch_flightstick_pro.h
Normal file
@@ -0,0 +1 @@
|
||||
extern joystick_if_t joystick_ch_flightstick_pro;
|
||||
226
src/game/joystick_standard.c
Normal file
226
src/game/joystick_standard.c
Normal file
@@ -0,0 +1,226 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include "../ibm.h"
|
||||
#include "../device.h"
|
||||
#include "../timer.h"
|
||||
#include "../win/plat_joystick.h"
|
||||
#include "gameport.h"
|
||||
#include "joystick_standard.h"
|
||||
|
||||
|
||||
static void *joystick_standard_init()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void joystick_standard_close(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
static uint8_t joystick_standard_read(void *p)
|
||||
{
|
||||
uint8_t ret = 0xf0;
|
||||
|
||||
if (JOYSTICK_PRESENT(0))
|
||||
{
|
||||
if (joystick_state[0].button[0])
|
||||
ret &= ~0x10;
|
||||
if (joystick_state[0].button[1])
|
||||
ret &= ~0x20;
|
||||
}
|
||||
if (JOYSTICK_PRESENT(1))
|
||||
{
|
||||
if (joystick_state[1].button[0])
|
||||
ret &= ~0x40;
|
||||
if (joystick_state[1].button[1])
|
||||
ret &= ~0x80;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint8_t joystick_standard_read_4button(void *p)
|
||||
{
|
||||
uint8_t ret = 0xf0;
|
||||
|
||||
if (JOYSTICK_PRESENT(0))
|
||||
{
|
||||
if (joystick_state[0].button[0])
|
||||
ret &= ~0x10;
|
||||
if (joystick_state[0].button[1])
|
||||
ret &= ~0x20;
|
||||
if (joystick_state[0].button[2])
|
||||
ret &= ~0x40;
|
||||
if (joystick_state[0].button[3])
|
||||
ret &= ~0x80;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void joystick_standard_write(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
static int joystick_standard_read_axis(void *p, int axis)
|
||||
{
|
||||
switch (axis)
|
||||
{
|
||||
case 0:
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return AXIS_NOT_PRESENT;
|
||||
return joystick_state[0].axis[0];
|
||||
case 1:
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return AXIS_NOT_PRESENT;
|
||||
return joystick_state[0].axis[1];
|
||||
case 2:
|
||||
if (!JOYSTICK_PRESENT(1))
|
||||
return AXIS_NOT_PRESENT;
|
||||
return joystick_state[1].axis[0];
|
||||
case 3:
|
||||
if (!JOYSTICK_PRESENT(1))
|
||||
return AXIS_NOT_PRESENT;
|
||||
return joystick_state[1].axis[1];
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int joystick_standard_read_axis_4button(void *p, int axis)
|
||||
{
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return AXIS_NOT_PRESENT;
|
||||
|
||||
switch (axis)
|
||||
{
|
||||
case 0:
|
||||
return joystick_state[0].axis[0];
|
||||
case 1:
|
||||
return joystick_state[0].axis[1];
|
||||
case 2:
|
||||
return 0;
|
||||
case 3:
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static int joystick_standard_read_axis_6button(void *p, int axis)
|
||||
{
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return AXIS_NOT_PRESENT;
|
||||
|
||||
switch (axis)
|
||||
{
|
||||
case 0:
|
||||
return joystick_state[0].axis[0];
|
||||
case 1:
|
||||
return joystick_state[0].axis[1];
|
||||
case 2:
|
||||
return joystick_state[0].button[4] ? -32767 : 32768;
|
||||
case 3:
|
||||
return joystick_state[0].button[5] ? -32767 : 32768;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static int joystick_standard_read_axis_8button(void *p, int axis)
|
||||
{
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return AXIS_NOT_PRESENT;
|
||||
|
||||
switch (axis)
|
||||
{
|
||||
case 0:
|
||||
return joystick_state[0].axis[0];
|
||||
case 1:
|
||||
return joystick_state[0].axis[1];
|
||||
case 2:
|
||||
if (joystick_state[0].button[4])
|
||||
return -32767;
|
||||
if (joystick_state[0].button[6])
|
||||
return 32768;
|
||||
return 0;
|
||||
case 3:
|
||||
if (joystick_state[0].button[5])
|
||||
return -32767;
|
||||
if (joystick_state[0].button[7])
|
||||
return 32768;
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void joystick_standard_a0_over(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
joystick_if_t joystick_standard =
|
||||
{
|
||||
"Standard 2-button joystick(s)",
|
||||
joystick_standard_init,
|
||||
joystick_standard_close,
|
||||
joystick_standard_read,
|
||||
joystick_standard_write,
|
||||
joystick_standard_read_axis,
|
||||
joystick_standard_a0_over,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
0,
|
||||
{"X axis", "Y axis"},
|
||||
{"Button 1", "Button 2"}
|
||||
};
|
||||
joystick_if_t joystick_standard_4button =
|
||||
{
|
||||
"Standard 4-button joystick",
|
||||
joystick_standard_init,
|
||||
joystick_standard_close,
|
||||
joystick_standard_read_4button,
|
||||
joystick_standard_write,
|
||||
joystick_standard_read_axis_4button,
|
||||
joystick_standard_a0_over,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
0,
|
||||
{"X axis", "Y axis"},
|
||||
{"Button 1", "Button 2", "Button 3", "Button 4"}
|
||||
};
|
||||
joystick_if_t joystick_standard_6button =
|
||||
{
|
||||
"Standard 6-button joystick",
|
||||
joystick_standard_init,
|
||||
joystick_standard_close,
|
||||
joystick_standard_read_4button,
|
||||
joystick_standard_write,
|
||||
joystick_standard_read_axis_6button,
|
||||
joystick_standard_a0_over,
|
||||
1,
|
||||
2,
|
||||
6,
|
||||
0,
|
||||
{"X axis", "Y axis"},
|
||||
{"Button 1", "Button 2", "Button 3", "Button 4", "Button 5", "Button 6"}
|
||||
};
|
||||
joystick_if_t joystick_standard_8button =
|
||||
{
|
||||
"Standard 8-button joystick",
|
||||
joystick_standard_init,
|
||||
joystick_standard_close,
|
||||
joystick_standard_read_4button,
|
||||
joystick_standard_write,
|
||||
joystick_standard_read_axis_8button,
|
||||
joystick_standard_a0_over,
|
||||
1,
|
||||
2,
|
||||
8,
|
||||
0,
|
||||
{"X axis", "Y axis"},
|
||||
{"Button 1", "Button 2", "Button 3", "Button 4", "Button 5", "Button 6", "Button 7", "Button 8"}
|
||||
};
|
||||
4
src/game/joystick_standard.h
Normal file
4
src/game/joystick_standard.h
Normal file
@@ -0,0 +1,4 @@
|
||||
extern joystick_if_t joystick_standard;
|
||||
extern joystick_if_t joystick_standard_4button;
|
||||
extern joystick_if_t joystick_standard_6button;
|
||||
extern joystick_if_t joystick_standard_8button;
|
||||
253
src/game/joystick_sw_pad.c
Normal file
253
src/game/joystick_sw_pad.c
Normal file
@@ -0,0 +1,253 @@
|
||||
/*Sidewinder game pad notes :
|
||||
|
||||
- Write to 0x201 starts packet transfer (5*N or 15*N bits)
|
||||
- Currently alternates between Mode A and Mode B (is there any way of
|
||||
actually controlling which is used?)
|
||||
- Windows 9x drivers require Mode B when more than 1 pad connected
|
||||
- Packet preceeded by high data (currently 50us), and followed by low
|
||||
data (currently 160us) - timings are probably wrong, but good enough
|
||||
for everything I've tried
|
||||
- Analogue inputs are only used to time ID packet request. If A0 timing
|
||||
out is followed after ~64us by another 0x201 write then an ID packet
|
||||
is triggered
|
||||
- Sidewinder game pad ID is 'H0003'
|
||||
- ID is sent in Mode A (1 bit per clock), but data bit 2 must change
|
||||
during ID packet transfer, or Windows 9x drivers won't use Mode B. I
|
||||
don't know if it oscillates, mirrors the data transfer, or something
|
||||
else - the drivers only check that it changes at least 10 times during
|
||||
the transfer
|
||||
- Some DOS stuff will write to 0x201 while a packet is being transferred.
|
||||
This seems to be ignored.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include "../ibm.h"
|
||||
#include "../device.h"
|
||||
#include "../timer.h"
|
||||
#include "../win/plat_joystick.h"
|
||||
#include "gameport.h"
|
||||
#include "joystick_sw_pad.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int poll_time;
|
||||
int poll_left;
|
||||
int poll_clock;
|
||||
uint64_t poll_data;
|
||||
int poll_mode;
|
||||
|
||||
int trigger_time;
|
||||
int data_mode;
|
||||
} sw_data;
|
||||
|
||||
static void sw_timer_over(void *p)
|
||||
{
|
||||
sw_data *sw = (sw_data *)p;
|
||||
|
||||
while (sw->poll_time <= 0 && sw->poll_left)
|
||||
{
|
||||
sw->poll_clock = !sw->poll_clock;
|
||||
|
||||
if (sw->poll_clock)
|
||||
{
|
||||
sw->poll_data >>= (sw->poll_mode ? 3 : 1);
|
||||
sw->poll_left--;
|
||||
}
|
||||
|
||||
if (sw->poll_left == 1 && !sw->poll_clock)
|
||||
sw->poll_time += TIMER_USEC * 160;
|
||||
else if (sw->poll_left)
|
||||
sw->poll_time += TIMER_USEC * 5;
|
||||
else
|
||||
sw->poll_time = 0;
|
||||
}
|
||||
|
||||
if (!sw->poll_left)
|
||||
sw->poll_time = 0;
|
||||
}
|
||||
|
||||
static void sw_trigger_timer_over(void *p)
|
||||
{
|
||||
sw_data *sw = (sw_data *)p;
|
||||
|
||||
sw->trigger_time = 0;
|
||||
}
|
||||
|
||||
static int sw_parity(uint16_t data)
|
||||
{
|
||||
int bits_set = 0;
|
||||
|
||||
while (data)
|
||||
{
|
||||
bits_set++;
|
||||
data &= (data - 1);
|
||||
}
|
||||
|
||||
return bits_set & 1;
|
||||
}
|
||||
|
||||
static void *sw_init()
|
||||
{
|
||||
sw_data *sw = (sw_data *)malloc(sizeof(sw_data));
|
||||
memset(sw, 0, sizeof(sw_data));
|
||||
|
||||
timer_add(sw_timer_over, &sw->poll_time, &sw->poll_time, sw);
|
||||
timer_add(sw_trigger_timer_over, &sw->trigger_time, &sw->trigger_time, sw);
|
||||
|
||||
return sw;
|
||||
}
|
||||
|
||||
static void sw_close(void *p)
|
||||
{
|
||||
sw_data *sw = (sw_data *)p;
|
||||
|
||||
free(sw);
|
||||
}
|
||||
|
||||
static uint8_t sw_read(void *p)
|
||||
{
|
||||
sw_data *sw = (sw_data *)p;
|
||||
uint8_t temp = 0;
|
||||
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return 0xff;
|
||||
|
||||
if (sw->poll_time)
|
||||
{
|
||||
if (sw->poll_clock)
|
||||
temp |= 0x10;
|
||||
|
||||
if (sw->poll_mode)
|
||||
temp |= (sw->poll_data & 7) << 5;
|
||||
else
|
||||
{
|
||||
temp |= ((sw->poll_data & 1) << 5) | 0xc0;
|
||||
if (sw->poll_left > 31 && !(sw->poll_left & 1))
|
||||
temp &= ~0x80;
|
||||
}
|
||||
}
|
||||
else
|
||||
temp |= 0xf0;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
static void sw_write(void *p)
|
||||
{
|
||||
sw_data *sw = (sw_data *)p;
|
||||
int time_since_last = sw->trigger_time / TIMER_USEC;
|
||||
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return;
|
||||
|
||||
timer_process();
|
||||
|
||||
if (!sw->poll_left)
|
||||
{
|
||||
sw->poll_clock = 1;
|
||||
sw->poll_time = TIMER_USEC * 50;
|
||||
|
||||
if (time_since_last > 9900 && time_since_last < 9940)
|
||||
{
|
||||
sw->poll_mode = 0;
|
||||
sw->poll_left = 49;
|
||||
sw->poll_data = 0x2400ull | (0x1830ull << 15) | (0x19b0ull << 30);
|
||||
}
|
||||
else
|
||||
{
|
||||
int c;
|
||||
|
||||
sw->poll_mode = sw->data_mode;
|
||||
sw->data_mode = !sw->data_mode;
|
||||
|
||||
if (sw->poll_mode)
|
||||
{
|
||||
sw->poll_left = 1;
|
||||
sw->poll_data = 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
sw->poll_left = 1;
|
||||
sw->poll_data = 1;
|
||||
}
|
||||
|
||||
for (c = 0; c < 4; c++)
|
||||
{
|
||||
uint64_t data = 0x3fff;
|
||||
int b;
|
||||
|
||||
if (!JOYSTICK_PRESENT(c))
|
||||
break;
|
||||
|
||||
if (joystick_state[c].axis[1] < -16383)
|
||||
data &= ~1;
|
||||
if (joystick_state[c].axis[1] > 16383)
|
||||
data &= ~2;
|
||||
if (joystick_state[c].axis[0] > 16383)
|
||||
data &= ~4;
|
||||
if (joystick_state[c].axis[0] < -16383)
|
||||
data &= ~8;
|
||||
|
||||
for (b = 0; b < 10; b++)
|
||||
{
|
||||
if (joystick_state[c].button[b])
|
||||
data &= ~(1 << (b + 4));
|
||||
}
|
||||
|
||||
if (sw_parity(data))
|
||||
data |= 0x4000;
|
||||
|
||||
if (sw->poll_mode)
|
||||
{
|
||||
sw->poll_left += 5;
|
||||
sw->poll_data |= (data << (c*15 + 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
sw->poll_left += 15;
|
||||
sw->poll_data |= (data << (c*15 + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sw->trigger_time = 0;
|
||||
|
||||
timer_update_outstanding();
|
||||
}
|
||||
|
||||
static int sw_read_axis(void *p, int axis)
|
||||
{
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return AXIS_NOT_PRESENT;
|
||||
|
||||
return 0; /*No analogue support on Sidewinder game pad*/
|
||||
}
|
||||
|
||||
static void sw_a0_over(void *p)
|
||||
{
|
||||
sw_data *sw = (sw_data *)p;
|
||||
|
||||
sw->trigger_time = TIMER_USEC * 10000;
|
||||
}
|
||||
|
||||
joystick_if_t joystick_sw_pad =
|
||||
{
|
||||
"Microsoft SideWinder Pad",
|
||||
sw_init,
|
||||
sw_close,
|
||||
sw_read,
|
||||
sw_write,
|
||||
sw_read_axis,
|
||||
sw_a0_over,
|
||||
4,
|
||||
2,
|
||||
10,
|
||||
0,
|
||||
{"X axis", "Y axis"},
|
||||
{"A", "B", "C", "X", "Y", "Z", "L", "R", "Start", "M"}
|
||||
};
|
||||
1
src/game/joystick_sw_pad.h
Normal file
1
src/game/joystick_sw_pad.h
Normal file
@@ -0,0 +1 @@
|
||||
extern joystick_if_t joystick_sw_pad;
|
||||
96
src/game/joystick_tm_fcs.c
Normal file
96
src/game/joystick_tm_fcs.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include "../ibm.h"
|
||||
#include "../device.h"
|
||||
#include "../timer.h"
|
||||
#include "../win/plat_joystick.h"
|
||||
#include "gameport.h"
|
||||
#include "joystick_standard.h"
|
||||
|
||||
|
||||
static void *tm_fcs_init(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void tm_fcs_close(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
static uint8_t tm_fcs_read(void *p)
|
||||
{
|
||||
uint8_t ret = 0xf0;
|
||||
|
||||
if (JOYSTICK_PRESENT(0))
|
||||
{
|
||||
if (joystick_state[0].button[0])
|
||||
ret &= ~0x10;
|
||||
if (joystick_state[0].button[1])
|
||||
ret &= ~0x20;
|
||||
if (joystick_state[0].button[2])
|
||||
ret &= ~0x40;
|
||||
if (joystick_state[0].button[3])
|
||||
ret &= ~0x80;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void tm_fcs_write(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
static int tm_fcs_read_axis(void *p, int axis)
|
||||
{
|
||||
if (!JOYSTICK_PRESENT(0))
|
||||
return AXIS_NOT_PRESENT;
|
||||
|
||||
switch (axis)
|
||||
{
|
||||
case 0:
|
||||
return joystick_state[0].axis[0];
|
||||
case 1:
|
||||
return joystick_state[0].axis[1];
|
||||
case 2:
|
||||
return 0;
|
||||
case 3:
|
||||
if (joystick_state[0].pov[0] == -1)
|
||||
return 32767;
|
||||
if (joystick_state[0].pov[0] > 315 || joystick_state[0].pov[0] < 45)
|
||||
return -32768;
|
||||
if (joystick_state[0].pov[0] >= 45 && joystick_state[0].pov[0] < 135)
|
||||
return -16384;
|
||||
if (joystick_state[0].pov[0] >= 135 && joystick_state[0].pov[0] < 225)
|
||||
return 0;
|
||||
if (joystick_state[0].pov[0] >= 225 && joystick_state[0].pov[0] < 315)
|
||||
return 16384;
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void tm_fcs_a0_over(void *p)
|
||||
{
|
||||
}
|
||||
|
||||
joystick_if_t joystick_tm_fcs =
|
||||
{
|
||||
"Thrustmaster Flight Control System",
|
||||
tm_fcs_init,
|
||||
tm_fcs_close,
|
||||
tm_fcs_read,
|
||||
tm_fcs_write,
|
||||
tm_fcs_read_axis,
|
||||
tm_fcs_a0_over,
|
||||
1,
|
||||
2,
|
||||
4,
|
||||
1,
|
||||
{"X axis", "Y axis"},
|
||||
{"Button 1", "Button 2", "Button 3", "Button 4"},
|
||||
{"POV"}
|
||||
};
|
||||
1
src/game/joystick_tm_fcs.h
Normal file
1
src/game/joystick_tm_fcs.h
Normal file
@@ -0,0 +1 @@
|
||||
extern joystick_if_t joystick_tm_fcs;
|
||||
Reference in New Issue
Block a user