2017-05-05 01:49:42 +02:00
|
|
|
#include <stdlib.h>
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "ibm.h"
|
|
|
|
|
#include "mouse.h"
|
|
|
|
|
#include "pic.h"
|
|
|
|
|
#include "serial.h"
|
|
|
|
|
#include "timer.h"
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
typedef struct mouse_serial_t {
|
|
|
|
|
int pos,
|
|
|
|
|
delay;
|
|
|
|
|
int oldb;
|
|
|
|
|
SERIAL *serial;
|
2016-12-23 03:16:24 +01:00
|
|
|
} mouse_serial_t;
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sermouse_rcr(SERIAL *serial, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
mouse_serial_t *ms = (mouse_serial_t *)priv;
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
ms->pos = -1;
|
|
|
|
|
ms->delay = 5000 * (1 << TIMER_SHIFT);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sermouse_timer(void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
mouse_serial_t *ms = (mouse_serial_t *)priv;
|
|
|
|
|
|
|
|
|
|
ms->delay = 0;
|
|
|
|
|
if (ms->pos == -1) {
|
|
|
|
|
ms->pos = 0;
|
|
|
|
|
serial_write_fifo(ms->serial, 'M');
|
|
|
|
|
}
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t
|
|
|
|
|
sermouse_poll(int x, int y, int z, int b, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
mouse_serial_t *ms = (mouse_serial_t *)priv;
|
|
|
|
|
SERIAL *sp = ms->serial;
|
|
|
|
|
uint8_t mousedat[3];
|
|
|
|
|
|
|
|
|
|
if (!(sp->ier & 1)) return(1);
|
|
|
|
|
|
|
|
|
|
if (!x && !y && b == ms->oldb) return(1);
|
|
|
|
|
|
|
|
|
|
ms->oldb = b;
|
|
|
|
|
if (x>127) x = 127;
|
|
|
|
|
if (y>127) y = 127;
|
|
|
|
|
if (x<-128) x = -128;
|
|
|
|
|
if (y<-128) y = -128;
|
|
|
|
|
|
|
|
|
|
/* Use Microsoft format. */
|
|
|
|
|
mousedat[0] = 0x40;
|
|
|
|
|
mousedat[0] |= (((y>>6)&3)<<2);
|
|
|
|
|
mousedat[0] |= ((x>>6)&3);
|
|
|
|
|
if (b&1) mousedat[0] |= 0x20;
|
|
|
|
|
if (b&2) mousedat[0] |= 0x10;
|
|
|
|
|
mousedat[1] = x & 0x3F;
|
|
|
|
|
mousedat[2] = y & 0x3F;
|
|
|
|
|
|
|
|
|
|
/* FIXME: we should check in serial_write_fifo, not here! --FvK */
|
|
|
|
|
if (! (sp->mctrl & 0x10)) {
|
|
|
|
|
#if 0
|
|
|
|
|
pclog("Serial data %02X %02X %02X\n",
|
|
|
|
|
mousedat[0], mousedat[1], mousedat[2]);
|
|
|
|
|
#endif
|
|
|
|
|
serial_write_fifo(ms->serial, mousedat[0]);
|
|
|
|
|
serial_write_fifo(ms->serial, mousedat[1]);
|
|
|
|
|
serial_write_fifo(ms->serial, mousedat[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(0);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
sermouse_init(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
mouse_serial_t *ms = (mouse_serial_t *)malloc(sizeof(mouse_serial_t));
|
|
|
|
|
memset(ms, 0x00, sizeof(mouse_serial_t));
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
/* Attach a serial port to the mouse. */
|
2017-05-06 22:27:23 +02:00
|
|
|
ms->serial = &serial1;
|
|
|
|
|
serial1.rcr_callback = sermouse_rcr;
|
|
|
|
|
serial1.rcr_callback_p = ms;
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
timer_add(sermouse_timer, &ms->delay, &ms->delay, ms);
|
|
|
|
|
|
|
|
|
|
return(ms);
|
2016-06-26 00:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sermouse_close(void *priv)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2017-05-05 01:49:42 +02:00
|
|
|
mouse_serial_t *ms = (mouse_serial_t *)priv;
|
|
|
|
|
|
|
|
|
|
/* Detach serial port from the mouse. */
|
|
|
|
|
serial1.rcr_callback = NULL;
|
|
|
|
|
|
|
|
|
|
free(ms);
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
mouse_t mouse_serial_microsoft = {
|
|
|
|
|
"Microsoft 2-button mouse (serial)",
|
|
|
|
|
"msserial",
|
|
|
|
|
MOUSE_TYPE_SERIAL,
|
|
|
|
|
sermouse_init,
|
|
|
|
|
sermouse_close,
|
|
|
|
|
sermouse_poll
|
2016-12-23 03:16:24 +01:00
|
|
|
};
|