Removed ALLEGRO, per Kotori's OK.

Fixed serial driver, re-worked API and updated other files accordingly.
Fixed serial mouse driver for new serial port, prepared for Mouse Systems mode.
This commit is contained in:
waltje
2017-05-07 02:14:44 -04:00
parent 3f3471ee7e
commit 79bccfeb77
33 changed files with 858 additions and 2740 deletions

View File

@@ -1,12 +1,29 @@
/*
* 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.
*
* Version: @(#)mouse_serial.c 1.0.2 2017/05/06
*
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
*/
#include <stdlib.h>
#include "ibm.h"
#include "mouse.h"
#include "pic.h"
#include "serial.h"
#include "timer.h"
#include "serial.h"
#include "mouse.h"
#include "mouse_serial.h"
typedef struct mouse_serial_t {
int port;
int pos,
delay;
int oldb;
@@ -14,16 +31,19 @@ typedef struct mouse_serial_t {
} mouse_serial_t;
/* Callback from serial driver: RTS was toggled. */
static void
sermouse_rcr(SERIAL *serial, void *priv)
sermouse_callback(SERIAL *serial, void *priv)
{
mouse_serial_t *ms = (mouse_serial_t *)priv;
/* Start a timer to wake us up in a little while. */
ms->pos = -1;
ms->delay = 5000 * (1 << TIMER_SHIFT);
}
/* Callback timer expired, now send our "mouse ID" to the serial port. */
static void
sermouse_timer(void *priv)
{
@@ -32,6 +52,8 @@ sermouse_timer(void *priv)
ms->delay = 0;
if (ms->pos == -1) {
ms->pos = 0;
/* This identifies a two-button Microsoft Serial mouse. */
serial_write_fifo(ms->serial, 'M');
}
}
@@ -41,10 +63,7 @@ static uint8_t
sermouse_poll(int x, int y, int z, int b, void *priv)
{
mouse_serial_t *ms = (mouse_serial_t *)priv;
SERIAL *sp = ms->serial;
uint8_t mousedat[3];
if (!(sp->ier & 1)) return(1);
uint8_t data[3];
if (!x && !y && b == ms->oldb) return(1);
@@ -55,24 +74,21 @@ sermouse_poll(int x, int y, int z, int b, void *priv)
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;
data[0] = 0x40;
data[0] |= (((y>>6)&3)<<2);
data[0] |= ((x>>6)&3);
if (b&1) data[0] |= 0x20;
if (b&2) data[0] |= 0x10;
data[1] = x & 0x3F;
data[2] = y & 0x3F;
/* FIXME: we should check in serial_write_fifo, not here! --FvK */
if (! (sp->mctrl & 0x10)) {
/* Send the packet to the bottom-half of the attached port. */
#if 0
pclog("Serial data %02X %02X %02X\n",
mousedat[0], mousedat[1], mousedat[2]);
pclog("Mouse_Serial: data %02X %02X %02X\n", data[0], data[1], data[2]);
#endif
serial_write_fifo(ms->serial, mousedat[0]);
serial_write_fifo(ms->serial, mousedat[1]);
serial_write_fifo(ms->serial, mousedat[2]);
}
serial_write_fifo(ms->serial, data[0]);
serial_write_fifo(ms->serial, data[1]);
serial_write_fifo(ms->serial, data[2]);
return(0);
}
@@ -83,11 +99,10 @@ sermouse_init(void)
{
mouse_serial_t *ms = (mouse_serial_t *)malloc(sizeof(mouse_serial_t));
memset(ms, 0x00, sizeof(mouse_serial_t));
ms->port = SERMOUSE_PORT;
/* Attach a serial port to the mouse. */
ms->serial = &serial1;
serial1.rcr_callback = sermouse_rcr;
serial1.rcr_callback_p = ms;
ms->serial = serial_attach(ms->port, sermouse_callback, ms);
timer_add(sermouse_timer, &ms->delay, &ms->delay, ms);
@@ -101,7 +116,7 @@ sermouse_close(void *priv)
mouse_serial_t *ms = (mouse_serial_t *)priv;
/* Detach serial port from the mouse. */
serial1.rcr_callback = NULL;
serial_attach(ms->port, NULL, NULL);
free(ms);
}