Mouse type now configurable

This commit is contained in:
SarahW 2016-12-16 20:19:08 +00:00
commit 09dbd1dd65
21 changed files with 494 additions and 238 deletions

View file

@ -35,41 +35,72 @@ void amstrad_write(uint16_t port, uint8_t val, void *priv)
}
}
static uint8_t mousex,mousey;
void amstrad_mouse_write(uint16_t addr, uint8_t val, void *priv)
static uint8_t mousex, mousey;
static void amstrad_mouse_write(uint16_t addr, uint8_t val, void *p)
{
// pclog("Write mouse %04X %02X %04X:%04X\n", addr, val, CS, pc);
if (addr==0x78) mousex=0;
else mousey=0;
if (addr == 0x78)
mousex = 0;
else
mousey = 0;
}
uint8_t amstrad_mouse_read(uint16_t addr, void *priv)
static uint8_t amstrad_mouse_read(uint16_t addr, void *p)
{
// printf("Read mouse %04X %04X:%04X %02X\n", addr, CS, pc, (addr == 0x78) ? mousex : mousey);
if (addr==0x78) return mousex;
if (addr == 0x78)
return mousex;
return mousey;
}
static int oldb = 0;
void amstrad_mouse_poll(int x, int y, int b)
typedef struct mouse_amstrad_t
{
int oldb;
} mouse_amstrad_t;
static void mouse_amstrad_poll(int x, int y, int b, void *p)
{
mouse_amstrad_t *mouse = (mouse_amstrad_t *)p;
mousex += x;
mousey -= y;
if ((b & 1) && !(oldb & 1))
keyboard_send(0x7e);
if ((b & 2) && !(oldb & 2))
keyboard_send(0x7d);
if (!(b & 1) && (oldb & 1))
keyboard_send(0xfe);
if (!(b & 2) && (oldb & 2))
keyboard_send(0xfd);
if ((b & 1) && !(mouse->oldb & 1))
keyboard_send(0x7e);
if ((b & 2) && !(mouse->oldb & 2))
keyboard_send(0x7d);
if (!(b & 1) && (mouse->oldb & 1))
keyboard_send(0xfe);
if (!(b & 2) && (mouse->oldb & 2))
keyboard_send(0xfd);
oldb = b;
mouse->oldb = b;
}
static void *mouse_amstrad_init()
{
mouse_amstrad_t *mouse = (mouse_amstrad_t *)malloc(sizeof(mouse_amstrad_t));
memset(mouse, 0, sizeof(mouse_amstrad_t));
return mouse;
}
static void mouse_amstrad_close(void *p)
{
mouse_amstrad_t *mouse = (mouse_amstrad_t *)p;
free(mouse);
}
mouse_t mouse_amstrad =
{
"Amstrad mouse",
mouse_amstrad_init,
mouse_amstrad_close,
mouse_amstrad_poll,
MOUSE_TYPE_AMSTRAD
};
void amstrad_init()
{
lpt2_remove_ams();
@ -78,6 +109,4 @@ void amstrad_init()
io_sethandler(0x007a, 0x0001, amstrad_mouse_read, NULL, NULL, amstrad_mouse_write, NULL, NULL, NULL);
io_sethandler(0x0379, 0x0002, amstrad_read, NULL, NULL, NULL, NULL, NULL, NULL);
io_sethandler(0xdead, 0x0001, amstrad_read, NULL, NULL, amstrad_write, NULL, NULL, NULL);
mouse_poll = amstrad_mouse_poll;
}