Reversed serial port and serial mouse code to the old ones.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
*
|
||||
* Based on the 86Box Serial Mouse driver as a framework.
|
||||
*
|
||||
* Version: @(#)mouse_serial.c 1.0.4 2017/06/11
|
||||
* Version: @(#)mouse_serial.c 1.0.3 2017/05/07
|
||||
*
|
||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
*/
|
||||
@@ -22,18 +22,13 @@
|
||||
#include "mouse_serial.h"
|
||||
|
||||
|
||||
#define SERMOUSE_TYPE_MSYSTEMS 1 /* Mouse Systems */
|
||||
#define SERMOUSE_TYPE_MICROSOFT 2 /* Microsoft */
|
||||
#define SERMOUSE_TYPE_LOGITECH 3 /* Logitech */
|
||||
|
||||
|
||||
typedef struct mouse_serial_t {
|
||||
int8_t port,
|
||||
type;
|
||||
int port;
|
||||
int pos,
|
||||
delay;
|
||||
int oldb;
|
||||
SERIAL *serial;
|
||||
int is_ms_format;
|
||||
} mouse_serial_t;
|
||||
|
||||
|
||||
@@ -56,16 +51,12 @@ sermouse_timer(void *priv)
|
||||
mouse_serial_t *ms = (mouse_serial_t *)priv;
|
||||
|
||||
ms->delay = 0;
|
||||
if (ms->pos == -1)
|
||||
{
|
||||
ms->pos = 0;
|
||||
|
||||
switch(ms->type) {
|
||||
case SERMOUSE_TYPE_MICROSOFT:
|
||||
/* This identifies a two-button Microsoft Serial mouse. */
|
||||
serial_write_fifo(ms->serial, 'M', 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* No action needed. */
|
||||
break;
|
||||
serial_write_fifo(ms->serial, 'M');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,63 +65,53 @@ static uint8_t
|
||||
sermouse_poll(int x, int y, int z, int b, void *priv)
|
||||
{
|
||||
mouse_serial_t *ms = (mouse_serial_t *)priv;
|
||||
uint8_t buff[16];
|
||||
int len;
|
||||
uint8_t data[3];
|
||||
|
||||
if (!x && !y && b == ms->oldb) return(1);
|
||||
|
||||
ms->oldb = b;
|
||||
|
||||
if (ms->type == SERMOUSE_TYPE_MSYSTEMS) y = -y;
|
||||
|
||||
if (x>127) x = 127;
|
||||
if (y>127) y = 127;
|
||||
if (x<-128) x = -128;
|
||||
if (y<-128) y = -128;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#if 0
|
||||
pclog("Mouse_Serial(%d): [", ms->type);
|
||||
for (b=0; b<len; b++) pclog(" %02X", buff[b]);
|
||||
pclog(" ] (%d)\n", len);
|
||||
#endif
|
||||
/* Use Microsoft format. */
|
||||
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;
|
||||
|
||||
/* 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);
|
||||
#if 0
|
||||
pclog("Mouse_Serial: data %02X %02X %02X\n", data[0], data[1], data[2]);
|
||||
#endif
|
||||
serial_write_fifo(ms->serial, data[0]);
|
||||
serial_write_fifo(ms->serial, data[1]);
|
||||
serial_write_fifo(ms->serial, data[2]);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
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 = serial_attach(ms->port, sermouse_callback, ms);
|
||||
|
||||
timer_add(sermouse_timer, &ms->delay, &ms->delay, ms);
|
||||
|
||||
return(ms);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
sermouse_close(void *priv)
|
||||
{
|
||||
@@ -143,13 +124,58 @@ sermouse_close(void *priv)
|
||||
}
|
||||
|
||||
|
||||
mouse_t mouse_serial_microsoft = {
|
||||
"Microsoft 2-button mouse (serial)",
|
||||
"msserial",
|
||||
MOUSE_TYPE_SERIAL,
|
||||
sermouse_init,
|
||||
sermouse_close,
|
||||
sermouse_poll
|
||||
};
|
||||
|
||||
static uint8_t
|
||||
mssystems_mouse_poll(int x, int y, int z, int b, void *priv)
|
||||
{
|
||||
mouse_serial_t *ms = (mouse_serial_t *)priv;
|
||||
uint8_t data[5];
|
||||
|
||||
if (!x && !y && b == ms->oldb) return(1);
|
||||
|
||||
ms->oldb = b;
|
||||
|
||||
y=-y;
|
||||
|
||||
if (x>127) x = 127;
|
||||
if (y>127) y = 127;
|
||||
if (x<-128) x = -128;
|
||||
if (y<-128) y = -128;
|
||||
|
||||
data[0] = 0x80;
|
||||
data[0] |= (b & 0x01 ? 0x00 : 0x04); /*Left button*/
|
||||
data[0] |= (b & 0x02 ? 0x00 : 0x01); /*Middle button*/
|
||||
data[0] |= (b & 0x04 ? 0x00 : 0x02); /*Right button*/
|
||||
data[1] = x;
|
||||
data[2] = y;
|
||||
data[3] = x;/*Same as byte 1*/
|
||||
data[4] = y;/*Same as byte 2*/
|
||||
|
||||
pclog("Mouse_Systems_Serial: data %02X %02X %02X\n", data[0], data[1], data[2]);
|
||||
|
||||
serial_write_fifo(ms->serial, data[0]);
|
||||
serial_write_fifo(ms->serial, data[1]);
|
||||
serial_write_fifo(ms->serial, data[2]);
|
||||
serial_write_fifo(ms->serial, data[3]);
|
||||
serial_write_fifo(ms->serial, data[4]);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
static void *
|
||||
sermouse_init(int type)
|
||||
mssystems_mouse_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;
|
||||
ms->type = type;
|
||||
|
||||
/* Attach a serial port to the mouse. */
|
||||
ms->serial = serial_attach(ms->port, sermouse_callback, ms);
|
||||
@@ -159,36 +185,11 @@ sermouse_init(int type)
|
||||
return(ms);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
sermouse_init_microsoft(void)
|
||||
{
|
||||
return(sermouse_init(SERMOUSE_TYPE_MICROSOFT));
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
sermouse_init_msystems(void)
|
||||
{
|
||||
return(sermouse_init(SERMOUSE_TYPE_MSYSTEMS));
|
||||
}
|
||||
|
||||
|
||||
mouse_t mouse_msystems = {
|
||||
"Mouse Systems Mouse (serial)",
|
||||
"mssystems",
|
||||
MOUSE_TYPE_MSYSTEMS,
|
||||
sermouse_init_msystems,
|
||||
mssystems_mouse_init,
|
||||
sermouse_close,
|
||||
sermouse_poll
|
||||
};
|
||||
|
||||
|
||||
mouse_t mouse_serial_microsoft = {
|
||||
"Microsoft 2-button mouse (serial)",
|
||||
"msserial",
|
||||
MOUSE_TYPE_SERIAL,
|
||||
sermouse_init_microsoft,
|
||||
sermouse_close,
|
||||
sermouse_poll
|
||||
mssystems_mouse_poll
|
||||
};
|
||||
236
src/serial.c
236
src/serial.c
@@ -15,29 +15,25 @@
|
||||
*
|
||||
* So, for the PC, the offerings were for an IBM Asynchronous
|
||||
* Communications Adapter, and, later, a model for synchronous
|
||||
* communications. The "Async Adapter" was based on the NS8250
|
||||
* UART chip, and is what we now call the "com" port of the PC.
|
||||
* communications.
|
||||
*
|
||||
* The "Async Adapter" was based on the NS8250 UART chip, and
|
||||
* is what we now call the "serial" or "com" port of the PC.
|
||||
*
|
||||
* Of course, many system builders came up with similar boards,
|
||||
* and even more boards were designed where several I/O functions
|
||||
* were combined into a single "multi-I/O" board, as that saved
|
||||
* space and buts slots. Initially, these had the chips as-is,
|
||||
* but later many of these functions were integrated into a
|
||||
* single "super-I/O" chip.
|
||||
* were combined into a single board: the Multi-I/O adapters.
|
||||
* Initially, these had all the chips as-is, but later many of
|
||||
* these functions were integrated into a single MIO chip.
|
||||
*
|
||||
* This file implements the standard NS8250, as well as the later
|
||||
* 16450 and 16550 series, which fixed bugs and added features
|
||||
* like FIFO buffers, higher line speeds and DMA transfers.
|
||||
*
|
||||
* On the lower half of the driver we interface to the host
|
||||
* system's serial ports for real-world access.
|
||||
* This file implements the standard NS8250 series of chips, with
|
||||
* support for the later (16450 and 16550) FIFO additions. On the
|
||||
* lower half of the driver, we interface to the host system's
|
||||
* serial ports for real-world access.
|
||||
*
|
||||
* Based on the 86Box serial port driver as a framework.
|
||||
*
|
||||
* **NOTE** This module is currently UNDER CONSTRUCTION, do not mess
|
||||
* with it please!
|
||||
*
|
||||
* Version: @(#)serial.c 1.0.8 2017/06/17
|
||||
* Version: @(#)serial.c 1.0.7 2017/06/04
|
||||
*
|
||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Copyright 2017 Fred N. van Kempen.
|
||||
@@ -78,10 +74,10 @@ enum {
|
||||
# define IID_IDTX (0x02)
|
||||
# define IID_IDRX (0x04)
|
||||
# define IID_IDERR (0x06)
|
||||
# define IID_IDTMO (0x0c) /* 16550+ */
|
||||
#define IIR_IIRFE (0xc0) /* 16550+ */
|
||||
# define IID_IDTMO (0x0c)
|
||||
#define IIR_IIRFE (0xc0)
|
||||
# define IIR_FIFO64 (0x20)
|
||||
# define IIR_FIFOBAD (0x80)
|
||||
# define IIR_FIFOBAD (0x80) /* 16550 */
|
||||
# define IIR_FIFOENB (0xc0)
|
||||
|
||||
/* FCR register bits. */
|
||||
@@ -148,6 +144,7 @@ static SERIAL ports[NUM_SERIAL]; /* serial port data */
|
||||
int serial_do_log;
|
||||
|
||||
|
||||
#if 0
|
||||
static void
|
||||
serial_log(int lvl, const char *fmt, ...)
|
||||
{
|
||||
@@ -162,6 +159,7 @@ serial_log(int lvl, const char *fmt, ...)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
@@ -188,20 +186,11 @@ update_ints(SERIAL *sp)
|
||||
sp->iir = IID_IDMDM;
|
||||
}
|
||||
|
||||
serial_log(0, "Serial%d: intr, IIR=%02X, type=%d, mcr=%02X\n",sp->port, sp->iir, sp->type, sp->mctrl);
|
||||
if (sp->type < UART_TYPE_16450) {
|
||||
/* Edge-triggered, so always send a pulse. */
|
||||
// if ((sp->mctrl & MCR_OUT2) || PCJR)
|
||||
picint(1 << sp->irq);
|
||||
} else {
|
||||
/* Raise or clear the level-based IRQ. */
|
||||
if ((sp->mctrl & MCR_OUT2) || PCJR) {
|
||||
if (stat)
|
||||
picintlevel(1 << sp->irq);
|
||||
else
|
||||
picintc(1 << sp->irq);
|
||||
}
|
||||
}
|
||||
/* Raise or clear the level-based IRQ. */
|
||||
if (stat && ((sp->mctrl & MCR_OUT2) || PCJR))
|
||||
picintlevel(1 << sp->irq);
|
||||
else
|
||||
picintc(1 << sp->irq);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,14 +212,13 @@ serial_timer(void *priv)
|
||||
|
||||
/* Write data to the (input) FIFO. Used by MOUSE driver. */
|
||||
void
|
||||
serial_write_fifo(SERIAL *sp, uint8_t dat, int intr)
|
||||
serial_write_fifo(SERIAL *sp, uint8_t dat)
|
||||
{
|
||||
/* Stuff data into RX FIFO. */
|
||||
/* Stuff data into FIFO. */
|
||||
sp->fifo[sp->fifo_write] = dat;
|
||||
sp->fifo_write = (sp->fifo_write + 1) & 0xFF;
|
||||
|
||||
/* If requested, generate interrupt. */
|
||||
if (intr && !(sp->lsr & LSR_DR)) {
|
||||
if (! (sp->lsr & LSR_DR)) {
|
||||
sp->lsr |= LSR_DR;
|
||||
sp->int_status |= SERINT_RECEIVE;
|
||||
update_ints(sp);
|
||||
@@ -238,31 +226,12 @@ serial_write_fifo(SERIAL *sp, uint8_t dat, int intr)
|
||||
}
|
||||
|
||||
|
||||
/* Grab data from the RX fifo. */
|
||||
static uint8_t
|
||||
serial_read_fifo(SERIAL *sp)
|
||||
read_fifo(SERIAL *sp)
|
||||
{
|
||||
if (sp->fifo_read != sp->fifo_write) {
|
||||
/* Grab data from the fifo. */
|
||||
if (sp->fifo_read != sp->fifo_write) {
|
||||
sp->dat = sp->fifo[sp->fifo_read];
|
||||
sp->fifo_read = (sp->fifo_read+1) & 0xFF;
|
||||
|
||||
/* If we have more, generate (new) int. */
|
||||
if (sp->fifo_read != sp->fifo_write) {
|
||||
#if 1
|
||||
sp->receive_delay = 1000*TIMER_USEC;
|
||||
#else
|
||||
if (sp->bh != NULL) {
|
||||
sp->int_status |= SERINT_RECEIVE;
|
||||
sp->lsr |= LSR_DR;
|
||||
|
||||
/* Update interrupt state. */
|
||||
update_ints(sp);
|
||||
} else {
|
||||
sp->receive_delay = 1000*TIMER_USEC;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
sp->fifo_read = (sp->fifo_read + 1) & 0xFF;
|
||||
}
|
||||
|
||||
return(sp->dat);
|
||||
@@ -284,46 +253,41 @@ serial_write(uint16_t addr, uint8_t val, void *priv)
|
||||
switch (addr & 0x07) {
|
||||
case 0: /* DATA / DLAB1 */
|
||||
if (sp->lcr & LCR_DLAB) {
|
||||
/* DLAB set, set DLAB low byte. */
|
||||
sp->dlab1 = val;
|
||||
} else {
|
||||
/* DLAB clear, regular data write. */
|
||||
sp->thr = val;
|
||||
if (sp->bh != NULL) {
|
||||
/* We are linked, so send to BH layer. */
|
||||
bhtty_write((BHTTY *)sp->bh, sp->thr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
sp->thr = val;
|
||||
if (sp->bh != NULL) {
|
||||
/* We are linked, so send to BH layer. */
|
||||
bhtty_write((BHTTY *)sp->bh, sp->thr);
|
||||
|
||||
/* WRITE completed, we are ready for more. */
|
||||
/* The WRITE completed, we are ready for more. */
|
||||
sp->lsr |= LSR_THRE;
|
||||
sp->int_status |= SERINT_TRANSMIT;
|
||||
update_ints(sp);
|
||||
} else {
|
||||
/* Not linked. Just fake LOOPBACK mode. */
|
||||
if (! (sp->mctrl & MCR_LMS))
|
||||
serial_write_fifo(sp, val);
|
||||
}
|
||||
|
||||
if (sp->mctrl & MCR_LMS) {
|
||||
/* Echo data back to RX. */
|
||||
serial_write_fifo(sp, val, 1);
|
||||
}
|
||||
if (sp->mctrl & MCR_LMS) {
|
||||
/* Echo data back to RX. */
|
||||
serial_write_fifo(sp, val);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: /* IER / DLAB2 */
|
||||
if (sp->lcr & LCR_DLAB) {
|
||||
/* DLAB set, set DLAB high byte. */
|
||||
sp->dlab2 = val;
|
||||
} else {
|
||||
/* DLAB clear, set IER register bits. */
|
||||
sp->ier = (val & IER_MASK);
|
||||
|
||||
/* Generate interrupt if needed. */
|
||||
update_ints(sp);
|
||||
return;
|
||||
}
|
||||
sp->ier = (val & IER_MASK);
|
||||
update_ints(sp);
|
||||
break;
|
||||
|
||||
case 2: /* FCR */
|
||||
if (sp->type >= UART_TYPE_16550A) {
|
||||
serial_log(0, "Serial%d: tried to enable FIFO (%02x), type %d!\n", sp->port, val, sp->type);
|
||||
sp->fcr = val;
|
||||
}
|
||||
sp->fcr = val;
|
||||
break;
|
||||
|
||||
case 3: /* LCR */
|
||||
@@ -351,17 +315,12 @@ serial_log(0, "Serial%d: tried to enable FIFO (%02x), type %d!\n", sp->port, val
|
||||
#ifdef ENABLE_SERIAL_LOG
|
||||
serial_log(2, "Serial%d: WL=%d SB=%d PA=%d\n", sp->port, wl, sb, pa);
|
||||
#endif
|
||||
sp->lcr = val;
|
||||
if (sp->bh != NULL)
|
||||
bhtty_params((BHTTY *)sp->bh, wl, pa, sb);
|
||||
sp->lcr = val;
|
||||
break;
|
||||
|
||||
case 4: /*MCR*/
|
||||
if (sp->bh == NULL) {
|
||||
/* Not linked, force LOOPBACK mode. */
|
||||
val |= MCR_LMS;
|
||||
}
|
||||
|
||||
case 4:
|
||||
if ((val & MCR_RTS) && !(sp->mctrl & MCR_RTS)) {
|
||||
/*
|
||||
* This is old code for use by the Serial Mouse
|
||||
@@ -396,28 +355,28 @@ serial_log(0, "Serial%d: tried to enable FIFO (%02x), type %d!\n", sp->port, val
|
||||
}
|
||||
}
|
||||
sp->mctrl = val;
|
||||
|
||||
if (val & MCR_LMS) { /* loopback mode */
|
||||
uint8_t new_msr;
|
||||
|
||||
/*FIXME: WTF does this do?? --FvK */
|
||||
new_msr = (val & 0x0c) << 4;
|
||||
new_msr |= (val & MCR_RTS) ? MCR_LMS : 0;
|
||||
new_msr |= (val & MCR_DTR) ? MCR_AUTOFLOW : 0;
|
||||
|
||||
if ((sp->msr ^ new_msr) & MSR_CTS)
|
||||
new_msr |= MSR_DCTS;
|
||||
if ((sp->msr ^ new_msr) & MSR_DSR)
|
||||
new_msr |= MSR_DDSR;
|
||||
if ((sp->msr ^ new_msr) & MSR_DCD)
|
||||
new_msr |= MSR_DDCD;
|
||||
if ((sp->msr & MSR_TERI) && !(new_msr & MSR_RI))
|
||||
new_msr |= MSR_TERI;
|
||||
if ((sp->msr ^ new_msr) & 0x10)
|
||||
new_msr |= MCR_DTR;
|
||||
if ((sp->msr ^ new_msr) & 0x20)
|
||||
new_msr |= MCR_RTS;
|
||||
if ((sp->msr ^ new_msr) & 0x80)
|
||||
new_msr |= 0x08;
|
||||
if ((sp->msr & 0x40) && !(new_msr & 0x40))
|
||||
new_msr |= 0x04;
|
||||
|
||||
sp->msr = new_msr;
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: /*LSR*/
|
||||
case 5:
|
||||
sp->lsr = val;
|
||||
if (sp->lsr & LSR_DR)
|
||||
sp->int_status |= SERINT_RECEIVE;
|
||||
@@ -428,7 +387,7 @@ serial_log(0, "Serial%d: tried to enable FIFO (%02x), type %d!\n", sp->port, val
|
||||
update_ints(sp);
|
||||
break;
|
||||
|
||||
case 6: /*MSR*/
|
||||
case 6:
|
||||
sp->msr = val;
|
||||
if (sp->msr & MSR_MASK)
|
||||
sp->int_status |= SERINT_MSR;
|
||||
@@ -436,9 +395,7 @@ serial_log(0, "Serial%d: tried to enable FIFO (%02x), type %d!\n", sp->port, val
|
||||
break;
|
||||
|
||||
case 7:
|
||||
if (sp->type > UART_TYPE_8250) {
|
||||
sp->scratch = val;
|
||||
}
|
||||
sp->scratch = val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -456,17 +413,8 @@ serial_rd_done(void *arg, int num)
|
||||
if (bhtty_read(sp->bh, &sp->hold, 1) < 0) break;
|
||||
|
||||
/* Stuff it into the FIFO and set intr. */
|
||||
#if 1
|
||||
serial_write_fifo(sp, sp->hold, 0);
|
||||
#else
|
||||
serial_write_fifo(sp, sp->hold, 1);
|
||||
#endif
|
||||
serial_write_fifo(sp, sp->hold);
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* We have data waiting for us.. delay a little, and then read it. */
|
||||
timer_add(serial_timer, &sp->receive_delay, &sp->receive_delay, sp);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -480,48 +428,30 @@ serial_read(uint16_t addr, void *priv)
|
||||
switch (addr&0x07) {
|
||||
case 0: /* DATA / DLAB1 */
|
||||
if (sp->lcr & LCR_DLAB) {
|
||||
/* DLAB set, read DLAB low byte. */
|
||||
ret = sp->dlab1;
|
||||
} else {
|
||||
/*
|
||||
* DLAB clear, regular data read.
|
||||
* First, clear the RXDATA interrupt.
|
||||
*/
|
||||
sp->int_status &= ~SERINT_RECEIVE;
|
||||
sp->lsr &= ~LSR_DR;
|
||||
|
||||
/* If there is data in the RX FIFO, grab it. */
|
||||
ret = serial_read_fifo(sp);
|
||||
serial_log(0, "Serial%d: read RBR: %02X\n",sp->port, ret);
|
||||
sp->int_status &= ~SERINT_RECEIVE;
|
||||
update_ints(sp);
|
||||
ret = read_fifo(sp);
|
||||
if ((sp->bh == NULL) &&
|
||||
(sp->fifo_read != sp->fifo_write))
|
||||
sp->receive_delay = 1000 * TIMER_USEC;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: /* LCR / DLAB2 */
|
||||
if (sp->lcr & LCR_DLAB) {
|
||||
/* DLAB set, read DLAB high byte. */
|
||||
ret = sp->dlab2;
|
||||
} else {
|
||||
/* DLAB clear, read IER register bits. */
|
||||
ret = sp->ier;
|
||||
}
|
||||
ret = (sp->lcr & LCR_DLAB) ? sp->dlab2 : sp->ier;
|
||||
break;
|
||||
|
||||
case 2: /* IIR */
|
||||
ret = sp->iir;
|
||||
serial_log(0, "Serial%d: read IIR: %02X\n",sp->port, sp->iir);
|
||||
|
||||
if ((ret & IIR_IID) == IID_IDTX) {
|
||||
/* Transmit is done. */
|
||||
sp->int_status &= ~SERINT_TRANSMIT;
|
||||
update_ints(sp);
|
||||
}
|
||||
|
||||
if (sp->type >= UART_TYPE_16550A) {
|
||||
/* If FIFO enabled.. */
|
||||
if (sp->fcr & 0x01)
|
||||
/* Report FIFO active. */
|
||||
ret |= 0xc0;
|
||||
}
|
||||
if (sp->fcr & 0x01)
|
||||
ret |= 0xc0;
|
||||
break;
|
||||
|
||||
case 3: /* LCR */
|
||||
@@ -533,10 +463,6 @@ serial_log(0, "Serial%d: read IIR: %02X\n",sp->port, sp->iir);
|
||||
break;
|
||||
|
||||
case 5: /* LSR */
|
||||
/* Clear interrupt state. */
|
||||
sp->int_status &= ~SERINT_LSR;
|
||||
update_ints(sp);
|
||||
|
||||
if (sp->lsr & LSR_THRE)
|
||||
sp->lsr |= LSR_TEMT;
|
||||
sp->lsr |= LSR_THRE;
|
||||
@@ -546,24 +472,19 @@ serial_log(0, "Serial%d: read IIR: %02X\n",sp->port, sp->iir);
|
||||
#if 0
|
||||
sp->lsr |= (LSR_THRE | LSR_TEMT);
|
||||
#endif
|
||||
sp->int_status &= ~SERINT_LSR;
|
||||
update_ints(sp);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
/* Clear MSR interrupt status. */
|
||||
ret = sp->msr;
|
||||
sp->msr &= ~0x0f;
|
||||
sp->int_status &= ~SERINT_MSR;
|
||||
update_ints(sp);
|
||||
|
||||
/* Grab current modem status. */
|
||||
ret = sp->msr;
|
||||
|
||||
/* Reset the delta bits. */
|
||||
sp->msr &= ~0x0f;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
if (sp->type > UART_TYPE_8250) {
|
||||
ret = sp->scratch;
|
||||
}
|
||||
ret = sp->scratch;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -642,7 +563,6 @@ serial_init(void)
|
||||
sp = &ports[i];
|
||||
memset(sp, 0x00, sizeof(SERIAL));
|
||||
sp->port = (i+1);
|
||||
sp->type = UART_TYPE_8250;
|
||||
|
||||
if (i == 0)
|
||||
serial_setup(sp->port, SERIAL1_ADDR, SERIAL1_IRQ);
|
||||
@@ -650,9 +570,9 @@ serial_init(void)
|
||||
serial_setup(sp->port, SERIAL2_ADDR, SERIAL2_IRQ);
|
||||
}
|
||||
|
||||
/* Link to host port. */
|
||||
#ifdef WALTJE
|
||||
// serial_link(1, "COM1");
|
||||
/* Link to host port. */
|
||||
serial_link(1, "COM1");
|
||||
serial_link(2, "COM2");
|
||||
#endif
|
||||
}
|
||||
|
||||
20
src/serial.h
20
src/serial.h
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Definitions for the SERIAL card.
|
||||
*
|
||||
* Version: @(#)serial.h 1.0.5 2017/06/07
|
||||
* Version: @(#)serial.h 1.0.4 2017/06/03
|
||||
*
|
||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Copyright 2017 Fred N. van Kempen.
|
||||
@@ -24,27 +24,16 @@
|
||||
#define SERIAL2_IRQ 3
|
||||
|
||||
|
||||
/* Supported UART types. */
|
||||
#define UART_TYPE_8250 0 /* standard NS8250 */
|
||||
#define UART_TYPE_8250A 1 /* updated NS8250(A) */
|
||||
#define UART_TYPE_16450 2 /* 16450 */
|
||||
#define UART_TYPE_16550 3 /* 16550 (broken fifo) */
|
||||
#define UART_TYPE_16550A 4 /* 16550a (working fifo) */
|
||||
#define UART_TYPE_16670 5 /* 64b fifo */
|
||||
|
||||
|
||||
typedef struct _serial_ {
|
||||
int8_t port; /* port number (1,2,..) */
|
||||
int8_t irq; /* IRQ channel used */
|
||||
uint16_t addr; /* I/O address used */
|
||||
int8_t type; /* UART type */
|
||||
uint8_t int_status;
|
||||
|
||||
uint8_t lsr, thr, mctrl, rcr, /* UART registers */
|
||||
iir, ier, lcr, msr;
|
||||
uint8_t dlab1, dlab2;
|
||||
uint8_t dat,
|
||||
hold;
|
||||
uint8_t dat;
|
||||
uint8_t int_status;
|
||||
uint8_t scratch;
|
||||
uint8_t fcr;
|
||||
|
||||
@@ -52,6 +41,7 @@ typedef struct _serial_ {
|
||||
void (*rts_callback)(void *);
|
||||
void *rts_callback_p;
|
||||
|
||||
uint8_t hold;
|
||||
uint8_t fifo[256];
|
||||
int fifo_read, fifo_write;
|
||||
|
||||
@@ -68,7 +58,7 @@ extern void serial_setup(int port, uint16_t addr, int irq);
|
||||
extern void serial_remove(int port);
|
||||
extern SERIAL *serial_attach(int, void *, void *);
|
||||
extern int serial_link(int, char *);
|
||||
extern void serial_write_fifo(SERIAL *, uint8_t, int);
|
||||
extern void serial_write_fifo(SERIAL *, uint8_t);
|
||||
|
||||
|
||||
#endif /*EMU_SERIAL_H*/
|
||||
|
||||
Reference in New Issue
Block a user