2017-05-07 02:14:44 -04:00
|
|
|
/*
|
|
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the 86Box distribution.
|
|
|
|
|
*
|
|
|
|
|
* Implementation of Serial Mouse devices.
|
|
|
|
|
*
|
|
|
|
|
* Based on the 86Box Serial Mouse driver as a framework.
|
|
|
|
|
*
|
2017-06-16 16:00:44 -04:00
|
|
|
* Version: @(#)mouse_serial.c 1.0.4 2017/06/11
|
2017-05-07 02:14:44 -04:00
|
|
|
*
|
|
|
|
|
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
|
|
|
|
*/
|
2017-05-05 01:49:42 +02:00
|
|
|
#include <stdlib.h>
|
2016-06-26 00:34:39 +02:00
|
|
|
#include "ibm.h"
|
|
|
|
|
#include "timer.h"
|
2017-05-07 02:14:44 -04:00
|
|
|
#include "serial.h"
|
|
|
|
|
#include "mouse.h"
|
|
|
|
|
#include "mouse_serial.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
#define SERMOUSE_TYPE_MSYSTEMS 1 /* Mouse Systems */
|
|
|
|
|
#define SERMOUSE_TYPE_MICROSOFT 2 /* Microsoft */
|
|
|
|
|
#define SERMOUSE_TYPE_LOGITECH 3 /* Logitech */
|
|
|
|
|
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
typedef struct mouse_serial_t {
|
2017-06-16 16:00:44 -04:00
|
|
|
int8_t port,
|
|
|
|
|
type;
|
2017-05-05 01:49:42 +02:00
|
|
|
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
|
|
|
|
2017-05-07 02:14:44 -04:00
|
|
|
/* Callback from serial driver: RTS was toggled. */
|
2017-05-05 01:49:42 +02:00
|
|
|
static void
|
2017-05-07 23:39:45 -04:00
|
|
|
sermouse_callback(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;
|
2017-05-07 02:14:44 -04:00
|
|
|
|
|
|
|
|
/* Start a timer to wake us up in a little while. */
|
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
|
|
|
|
2017-05-07 02:14:44 -04:00
|
|
|
/* Callback timer expired, now send our "mouse ID" to the serial port. */
|
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;
|
2017-05-07 02:14:44 -04:00
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
switch(ms->type) {
|
|
|
|
|
case SERMOUSE_TYPE_MICROSOFT:
|
2017-05-29 01:18:32 +02:00
|
|
|
/* This identifies a two-button Microsoft Serial mouse. */
|
2017-06-16 16:00:44 -04:00
|
|
|
serial_write_fifo(ms->serial, 'M', 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* No action needed. */
|
|
|
|
|
break;
|
2017-05-05 01:49:42 +02:00
|
|
|
}
|
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;
|
2017-06-16 16:00:44 -04:00
|
|
|
uint8_t buff[16];
|
|
|
|
|
int len;
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
if (!x && !y && b == ms->oldb) return(1);
|
|
|
|
|
|
|
|
|
|
ms->oldb = b;
|
2017-06-16 16:00:44 -04:00
|
|
|
|
|
|
|
|
if (ms->type == SERMOUSE_TYPE_MSYSTEMS) y = -y;
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
if (x>127) x = 127;
|
|
|
|
|
if (y>127) y = 127;
|
|
|
|
|
if (x<-128) x = -128;
|
|
|
|
|
if (y<-128) y = -128;
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
len = 0;
|
|
|
|
|
switch(ms->type) {
|
|
|
|
|
case SERMOUSE_TYPE_MSYSTEMS:
|
|
|
|
|
buff[0] = 0x80;
|
|
|
|
|
buff[0] |= (b&0x01) ? 0x00 : 0x04; /* left button */
|
|
|
|
|
buff[0] |= (b&0x02) ? 0x00 : 0x01; /* middle button */
|
|
|
|
|
buff[0] |= (b&0x04) ? 0x00 : 0x02; /* right button */
|
|
|
|
|
buff[1] = x;
|
|
|
|
|
buff[2] = y;
|
|
|
|
|
buff[3] = x; /* same as byte 1 */
|
|
|
|
|
buff[4] = y; /* same as byte 2 */
|
|
|
|
|
len = 5;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SERMOUSE_TYPE_MICROSOFT:
|
|
|
|
|
buff[0] = 0x40;
|
|
|
|
|
buff[0] |= (((y>>6)&03)<<2);
|
|
|
|
|
buff[0] |= ((x>>6)&03);
|
|
|
|
|
if (b&0x01) buff[0] |= 0x20;
|
|
|
|
|
if (b&0x02) buff[0] |= 0x10;
|
|
|
|
|
buff[1] = x & 0x3F;
|
|
|
|
|
buff[2] = y & 0x3F;
|
|
|
|
|
len = 3;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SERMOUSE_TYPE_LOGITECH:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-05-07 02:14:44 -04:00
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
#if 0
|
2017-06-16 16:00:44 -04:00
|
|
|
pclog("Mouse_Serial(%d): [", ms->type);
|
|
|
|
|
for (b=0; b<len; b++) pclog(" %02X", buff[b]);
|
|
|
|
|
pclog(" ] (%d)\n", len);
|
2017-05-05 01:49:42 +02:00
|
|
|
#endif
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
/* Send the packet to the bottom-half of the attached port. */
|
|
|
|
|
for (b=0; b<len; b++)
|
|
|
|
|
serial_write_fifo(ms->serial, buff[b], 1);
|
2017-05-05 01:49:42 +02:00
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
return(0);
|
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. */
|
2017-05-07 02:14:44 -04:00
|
|
|
serial_attach(ms->port, NULL, NULL);
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
free(ms);
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
|
2017-05-29 01:18:32 +02:00
|
|
|
static void *
|
2017-06-16 16:00:44 -04:00
|
|
|
sermouse_init(int type)
|
2017-05-29 01:18:32 +02:00
|
|
|
{
|
|
|
|
|
mouse_serial_t *ms = (mouse_serial_t *)malloc(sizeof(mouse_serial_t));
|
|
|
|
|
memset(ms, 0x00, sizeof(mouse_serial_t));
|
|
|
|
|
ms->port = SERMOUSE_PORT;
|
2017-06-16 16:00:44 -04:00
|
|
|
ms->type = type;
|
|
|
|
|
|
2017-05-29 01:18:32 +02:00
|
|
|
/* Attach a serial port to the mouse. */
|
|
|
|
|
ms->serial = serial_attach(ms->port, sermouse_callback, ms);
|
|
|
|
|
|
|
|
|
|
timer_add(sermouse_timer, &ms->delay, &ms->delay, ms);
|
|
|
|
|
|
|
|
|
|
return(ms);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
sermouse_init_microsoft(void)
|
|
|
|
|
{
|
|
|
|
|
return(sermouse_init(SERMOUSE_TYPE_MICROSOFT));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
sermouse_init_msystems(void)
|
|
|
|
|
{
|
|
|
|
|
return(sermouse_init(SERMOUSE_TYPE_MSYSTEMS));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-29 01:18:32 +02:00
|
|
|
mouse_t mouse_msystems = {
|
|
|
|
|
"Mouse Systems Mouse (serial)",
|
|
|
|
|
"mssystems",
|
|
|
|
|
MOUSE_TYPE_MSYSTEMS,
|
2017-06-16 16:00:44 -04:00
|
|
|
sermouse_init_msystems,
|
2017-05-29 01:18:32 +02:00
|
|
|
sermouse_close,
|
2017-06-16 16:00:44 -04:00
|
|
|
sermouse_poll
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mouse_t mouse_serial_microsoft = {
|
|
|
|
|
"Microsoft 2-button mouse (serial)",
|
|
|
|
|
"msserial",
|
|
|
|
|
MOUSE_TYPE_SERIAL,
|
|
|
|
|
sermouse_init_microsoft,
|
|
|
|
|
sermouse_close,
|
|
|
|
|
sermouse_poll
|
|
|
|
|
};
|