Reversed serial port and serial mouse code to the old ones.

This commit is contained in:
OBattler
2017-06-16 23:47:08 +02:00
parent c9aac82b94
commit 20178cb1bb
3 changed files with 172 additions and 261 deletions

View File

@@ -10,7 +10,7 @@
* *
* Based on the 86Box Serial Mouse driver as a framework. * 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> * Author: Fred N. van Kempen, <decwiz@yahoo.com>
*/ */
@@ -22,18 +22,13 @@
#include "mouse_serial.h" #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 { typedef struct mouse_serial_t {
int8_t port, int port;
type;
int pos, int pos,
delay; delay;
int oldb; int oldb;
SERIAL *serial; SERIAL *serial;
int is_ms_format;
} mouse_serial_t; } mouse_serial_t;
@@ -56,16 +51,12 @@ sermouse_timer(void *priv)
mouse_serial_t *ms = (mouse_serial_t *)priv; mouse_serial_t *ms = (mouse_serial_t *)priv;
ms->delay = 0; 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. */ /* This identifies a two-button Microsoft Serial mouse. */
serial_write_fifo(ms->serial, 'M', 1); serial_write_fifo(ms->serial, 'M');
break;
default:
/* No action needed. */
break;
} }
} }
@@ -74,63 +65,53 @@ static uint8_t
sermouse_poll(int x, int y, int z, int b, void *priv) sermouse_poll(int x, int y, int z, int b, void *priv)
{ {
mouse_serial_t *ms = (mouse_serial_t *)priv; mouse_serial_t *ms = (mouse_serial_t *)priv;
uint8_t buff[16]; uint8_t data[3];
int len;
if (!x && !y && b == ms->oldb) return(1); if (!x && !y && b == ms->oldb) return(1);
ms->oldb = b; ms->oldb = b;
if (ms->type == SERMOUSE_TYPE_MSYSTEMS) y = -y;
if (x>127) x = 127; if (x>127) x = 127;
if (y>127) y = 127; if (y>127) y = 127;
if (x<-128) x = -128; if (x<-128) x = -128;
if (y<-128) y = -128; if (y<-128) y = -128;
len = 0; /* Use Microsoft format. */
switch(ms->type) { data[0] = 0x40;
case SERMOUSE_TYPE_MSYSTEMS: data[0] |= (((y>>6)&3)<<2);
buff[0] = 0x80; data[0] |= ((x>>6)&3);
buff[0] |= (b&0x01) ? 0x00 : 0x04; /* left button */ if (b&1) data[0] |= 0x20;
buff[0] |= (b&0x02) ? 0x00 : 0x01; /* middle button */ if (b&2) data[0] |= 0x10;
buff[0] |= (b&0x04) ? 0x00 : 0x02; /* right button */ data[1] = x & 0x3F;
buff[1] = x; data[2] = y & 0x3F;
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
/* Send the packet to the bottom-half of the attached port. */ /* Send the packet to the bottom-half of the attached port. */
for (b=0; b<len; b++) #if 0
serial_write_fifo(ms->serial, buff[b], 1); 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); 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 static void
sermouse_close(void *priv) sermouse_close(void *priv)
{ {
@@ -143,14 +124,59 @@ 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 * static void *
sermouse_init(int type) mssystems_mouse_init(void)
{ {
mouse_serial_t *ms = (mouse_serial_t *)malloc(sizeof(mouse_serial_t)); mouse_serial_t *ms = (mouse_serial_t *)malloc(sizeof(mouse_serial_t));
memset(ms, 0x00, sizeof(mouse_serial_t)); memset(ms, 0x00, sizeof(mouse_serial_t));
ms->port = SERMOUSE_PORT; ms->port = SERMOUSE_PORT;
ms->type = type;
/* Attach a serial port to the mouse. */ /* Attach a serial port to the mouse. */
ms->serial = serial_attach(ms->port, sermouse_callback, ms); ms->serial = serial_attach(ms->port, sermouse_callback, ms);
@@ -159,36 +185,11 @@ sermouse_init(int type)
return(ms); 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_t mouse_msystems = {
"Mouse Systems Mouse (serial)", "Mouse Systems Mouse (serial)",
"mssystems", "mssystems",
MOUSE_TYPE_MSYSTEMS, MOUSE_TYPE_MSYSTEMS,
sermouse_init_msystems, mssystems_mouse_init,
sermouse_close, sermouse_close,
sermouse_poll mssystems_mouse_poll
}; };
mouse_t mouse_serial_microsoft = {
"Microsoft 2-button mouse (serial)",
"msserial",
MOUSE_TYPE_SERIAL,
sermouse_init_microsoft,
sermouse_close,
sermouse_poll
};

View File

@@ -15,29 +15,25 @@
* *
* So, for the PC, the offerings were for an IBM Asynchronous * So, for the PC, the offerings were for an IBM Asynchronous
* Communications Adapter, and, later, a model for synchronous * Communications Adapter, and, later, a model for synchronous
* communications. The "Async Adapter" was based on the NS8250 * communications.
* UART chip, and is what we now call the "com" port of the PC. *
* 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, * Of course, many system builders came up with similar boards,
* and even more boards were designed where several I/O functions * and even more boards were designed where several I/O functions
* were combined into a single "multi-I/O" board, as that saved * were combined into a single board: the Multi-I/O adapters.
* space and buts slots. Initially, these had the chips as-is, * Initially, these had all the chips as-is, but later many of
* but later many of these functions were integrated into a * these functions were integrated into a single MIO chip.
* single "super-I/O" chip.
* *
* This file implements the standard NS8250, as well as the later * This file implements the standard NS8250 series of chips, with
* 16450 and 16550 series, which fixed bugs and added features * support for the later (16450 and 16550) FIFO additions. On the
* like FIFO buffers, higher line speeds and DMA transfers. * lower half of the driver, we interface to the host system's
* * serial ports for real-world access.
* 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. * Based on the 86Box serial port driver as a framework.
* *
* **NOTE** This module is currently UNDER CONSTRUCTION, do not mess * Version: @(#)serial.c 1.0.7 2017/06/04
* with it please!
*
* Version: @(#)serial.c 1.0.8 2017/06/17
* *
* Author: Fred N. van Kempen, <decwiz@yahoo.com> * Author: Fred N. van Kempen, <decwiz@yahoo.com>
* Copyright 2017 Fred N. van Kempen. * Copyright 2017 Fred N. van Kempen.
@@ -78,10 +74,10 @@ enum {
# define IID_IDTX (0x02) # define IID_IDTX (0x02)
# define IID_IDRX (0x04) # define IID_IDRX (0x04)
# define IID_IDERR (0x06) # define IID_IDERR (0x06)
# define IID_IDTMO (0x0c) /* 16550+ */ # define IID_IDTMO (0x0c)
#define IIR_IIRFE (0xc0) /* 16550+ */ #define IIR_IIRFE (0xc0)
# define IIR_FIFO64 (0x20) # define IIR_FIFO64 (0x20)
# define IIR_FIFOBAD (0x80) # define IIR_FIFOBAD (0x80) /* 16550 */
# define IIR_FIFOENB (0xc0) # define IIR_FIFOENB (0xc0)
/* FCR register bits. */ /* FCR register bits. */
@@ -148,6 +144,7 @@ static SERIAL ports[NUM_SERIAL]; /* serial port data */
int serial_do_log; int serial_do_log;
#if 0
static void static void
serial_log(int lvl, const char *fmt, ...) serial_log(int lvl, const char *fmt, ...)
{ {
@@ -162,6 +159,7 @@ serial_log(int lvl, const char *fmt, ...)
} }
#endif #endif
} }
#endif
static void static void
@@ -188,20 +186,11 @@ update_ints(SERIAL *sp)
sp->iir = IID_IDMDM; 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); /* Raise or clear the level-based IRQ. */
if (sp->type < UART_TYPE_16450) { if (stat && ((sp->mctrl & MCR_OUT2) || PCJR))
/* Edge-triggered, so always send a pulse. */ picintlevel(1 << sp->irq);
// if ((sp->mctrl & MCR_OUT2) || PCJR) else
picint(1 << sp->irq); picintc(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);
}
}
} }
@@ -223,14 +212,13 @@ serial_timer(void *priv)
/* Write data to the (input) FIFO. Used by MOUSE driver. */ /* Write data to the (input) FIFO. Used by MOUSE driver. */
void 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[sp->fifo_write] = dat;
sp->fifo_write = (sp->fifo_write + 1) & 0xFF; sp->fifo_write = (sp->fifo_write + 1) & 0xFF;
/* If requested, generate interrupt. */ if (! (sp->lsr & LSR_DR)) {
if (intr && !(sp->lsr & LSR_DR)) {
sp->lsr |= LSR_DR; sp->lsr |= LSR_DR;
sp->int_status |= SERINT_RECEIVE; sp->int_status |= SERINT_RECEIVE;
update_ints(sp); 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 static uint8_t
serial_read_fifo(SERIAL *sp) read_fifo(SERIAL *sp)
{ {
if (sp->fifo_read != sp->fifo_write) { if (sp->fifo_read != sp->fifo_write) {
/* Grab data from the fifo. */
sp->dat = sp->fifo[sp->fifo_read]; sp->dat = sp->fifo[sp->fifo_read];
sp->fifo_read = (sp->fifo_read+1) & 0xFF; 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
}
} }
return(sp->dat); return(sp->dat);
@@ -284,46 +253,41 @@ serial_write(uint16_t addr, uint8_t val, void *priv)
switch (addr & 0x07) { switch (addr & 0x07) {
case 0: /* DATA / DLAB1 */ case 0: /* DATA / DLAB1 */
if (sp->lcr & LCR_DLAB) { if (sp->lcr & LCR_DLAB) {
/* DLAB set, set DLAB low byte. */
sp->dlab1 = val; sp->dlab1 = val;
} else { return;
/* DLAB clear, regular data write. */ }
sp->thr = val; sp->thr = val;
if (sp->bh != NULL) { if (sp->bh != NULL) {
/* We are linked, so send to BH layer. */ /* We are linked, so send to BH layer. */
bhtty_write((BHTTY *)sp->bh, sp->thr); 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->lsr |= LSR_THRE;
sp->int_status |= SERINT_TRANSMIT; sp->int_status |= SERINT_TRANSMIT;
update_ints(sp); 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) { if (sp->mctrl & MCR_LMS) {
/* Echo data back to RX. */ /* Echo data back to RX. */
serial_write_fifo(sp, val, 1); serial_write_fifo(sp, val);
}
} }
break; break;
case 1: /* IER / DLAB2 */ case 1: /* IER / DLAB2 */
if (sp->lcr & LCR_DLAB) { if (sp->lcr & LCR_DLAB) {
/* DLAB set, set DLAB high byte. */
sp->dlab2 = val; sp->dlab2 = val;
} else { return;
/* DLAB clear, set IER register bits. */
sp->ier = (val & IER_MASK);
/* Generate interrupt if needed. */
update_ints(sp);
} }
sp->ier = (val & IER_MASK);
update_ints(sp);
break; break;
case 2: /* FCR */ case 2: /* FCR */
if (sp->type >= UART_TYPE_16550A) { sp->fcr = val;
serial_log(0, "Serial%d: tried to enable FIFO (%02x), type %d!\n", sp->port, val, sp->type);
sp->fcr = val;
}
break; break;
case 3: /* LCR */ 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 #ifdef ENABLE_SERIAL_LOG
serial_log(2, "Serial%d: WL=%d SB=%d PA=%d\n", sp->port, wl, sb, pa); serial_log(2, "Serial%d: WL=%d SB=%d PA=%d\n", sp->port, wl, sb, pa);
#endif #endif
sp->lcr = val;
if (sp->bh != NULL) if (sp->bh != NULL)
bhtty_params((BHTTY *)sp->bh, wl, pa, sb); bhtty_params((BHTTY *)sp->bh, wl, pa, sb);
sp->lcr = val;
break; break;
case 4: /*MCR*/ case 4:
if (sp->bh == NULL) {
/* Not linked, force LOOPBACK mode. */
val |= MCR_LMS;
}
if ((val & MCR_RTS) && !(sp->mctrl & MCR_RTS)) { if ((val & MCR_RTS) && !(sp->mctrl & MCR_RTS)) {
/* /*
* This is old code for use by the Serial Mouse * 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; sp->mctrl = val;
if (val & MCR_LMS) { /* loopback mode */ if (val & MCR_LMS) { /* loopback mode */
uint8_t new_msr; uint8_t new_msr;
/*FIXME: WTF does this do?? --FvK */
new_msr = (val & 0x0c) << 4; new_msr = (val & 0x0c) << 4;
new_msr |= (val & MCR_RTS) ? MCR_LMS : 0; new_msr |= (val & MCR_RTS) ? MCR_LMS : 0;
new_msr |= (val & MCR_DTR) ? MCR_AUTOFLOW : 0; new_msr |= (val & MCR_DTR) ? MCR_AUTOFLOW : 0;
if ((sp->msr ^ new_msr) & MSR_CTS) if ((sp->msr ^ new_msr) & 0x10)
new_msr |= MSR_DCTS; new_msr |= MCR_DTR;
if ((sp->msr ^ new_msr) & MSR_DSR) if ((sp->msr ^ new_msr) & 0x20)
new_msr |= MSR_DDSR; new_msr |= MCR_RTS;
if ((sp->msr ^ new_msr) & MSR_DCD) if ((sp->msr ^ new_msr) & 0x80)
new_msr |= MSR_DDCD; new_msr |= 0x08;
if ((sp->msr & MSR_TERI) && !(new_msr & MSR_RI)) if ((sp->msr & 0x40) && !(new_msr & 0x40))
new_msr |= MSR_TERI; new_msr |= 0x04;
sp->msr = new_msr; sp->msr = new_msr;
} }
break; break;
case 5: /*LSR*/ case 5:
sp->lsr = val; sp->lsr = val;
if (sp->lsr & LSR_DR) if (sp->lsr & LSR_DR)
sp->int_status |= SERINT_RECEIVE; 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); update_ints(sp);
break; break;
case 6: /*MSR*/ case 6:
sp->msr = val; sp->msr = val;
if (sp->msr & MSR_MASK) if (sp->msr & MSR_MASK)
sp->int_status |= SERINT_MSR; 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; break;
case 7: case 7:
if (sp->type > UART_TYPE_8250) { sp->scratch = val;
sp->scratch = val;
}
break; break;
} }
} }
@@ -456,17 +413,8 @@ serial_rd_done(void *arg, int num)
if (bhtty_read(sp->bh, &sp->hold, 1) < 0) break; if (bhtty_read(sp->bh, &sp->hold, 1) < 0) break;
/* Stuff it into the FIFO and set intr. */ /* Stuff it into the FIFO and set intr. */
#if 1 serial_write_fifo(sp, sp->hold);
serial_write_fifo(sp, sp->hold, 0);
#else
serial_write_fifo(sp, sp->hold, 1);
#endif
} }
#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) { switch (addr&0x07) {
case 0: /* DATA / DLAB1 */ case 0: /* DATA / DLAB1 */
if (sp->lcr & LCR_DLAB) { if (sp->lcr & LCR_DLAB) {
/* DLAB set, read DLAB low byte. */
ret = sp->dlab1; ret = sp->dlab1;
} else { } else {
/*
* DLAB clear, regular data read.
* First, clear the RXDATA interrupt.
*/
sp->int_status &= ~SERINT_RECEIVE;
sp->lsr &= ~LSR_DR; sp->lsr &= ~LSR_DR;
sp->int_status &= ~SERINT_RECEIVE;
/* If there is data in the RX FIFO, grab it. */ update_ints(sp);
ret = serial_read_fifo(sp); ret = read_fifo(sp);
serial_log(0, "Serial%d: read RBR: %02X\n",sp->port, ret); if ((sp->bh == NULL) &&
(sp->fifo_read != sp->fifo_write))
sp->receive_delay = 1000 * TIMER_USEC;
} }
break; break;
case 1: /* LCR / DLAB2 */ case 1: /* LCR / DLAB2 */
if (sp->lcr & LCR_DLAB) { ret = (sp->lcr & LCR_DLAB) ? sp->dlab2 : sp->ier;
/* DLAB set, read DLAB high byte. */
ret = sp->dlab2;
} else {
/* DLAB clear, read IER register bits. */
ret = sp->ier;
}
break; break;
case 2: /* IIR */ case 2: /* IIR */
ret = sp->iir; ret = sp->iir;
serial_log(0, "Serial%d: read IIR: %02X\n",sp->port, sp->iir);
if ((ret & IIR_IID) == IID_IDTX) { if ((ret & IIR_IID) == IID_IDTX) {
/* Transmit is done. */
sp->int_status &= ~SERINT_TRANSMIT; sp->int_status &= ~SERINT_TRANSMIT;
update_ints(sp); update_ints(sp);
} }
if (sp->fcr & 0x01)
if (sp->type >= UART_TYPE_16550A) { ret |= 0xc0;
/* If FIFO enabled.. */
if (sp->fcr & 0x01)
/* Report FIFO active. */
ret |= 0xc0;
}
break; break;
case 3: /* LCR */ case 3: /* LCR */
@@ -533,10 +463,6 @@ serial_log(0, "Serial%d: read IIR: %02X\n",sp->port, sp->iir);
break; break;
case 5: /* LSR */ case 5: /* LSR */
/* Clear interrupt state. */
sp->int_status &= ~SERINT_LSR;
update_ints(sp);
if (sp->lsr & LSR_THRE) if (sp->lsr & LSR_THRE)
sp->lsr |= LSR_TEMT; sp->lsr |= LSR_TEMT;
sp->lsr |= LSR_THRE; sp->lsr |= LSR_THRE;
@@ -546,24 +472,19 @@ serial_log(0, "Serial%d: read IIR: %02X\n",sp->port, sp->iir);
#if 0 #if 0
sp->lsr |= (LSR_THRE | LSR_TEMT); sp->lsr |= (LSR_THRE | LSR_TEMT);
#endif #endif
sp->int_status &= ~SERINT_LSR;
update_ints(sp);
break; break;
case 6: case 6:
/* Clear MSR interrupt status. */ ret = sp->msr;
sp->msr &= ~0x0f;
sp->int_status &= ~SERINT_MSR; sp->int_status &= ~SERINT_MSR;
update_ints(sp); update_ints(sp);
/* Grab current modem status. */
ret = sp->msr;
/* Reset the delta bits. */
sp->msr &= ~0x0f;
break; break;
case 7: case 7:
if (sp->type > UART_TYPE_8250) { ret = sp->scratch;
ret = sp->scratch;
}
break; break;
} }
@@ -642,7 +563,6 @@ serial_init(void)
sp = &ports[i]; sp = &ports[i];
memset(sp, 0x00, sizeof(SERIAL)); memset(sp, 0x00, sizeof(SERIAL));
sp->port = (i+1); sp->port = (i+1);
sp->type = UART_TYPE_8250;
if (i == 0) if (i == 0)
serial_setup(sp->port, SERIAL1_ADDR, SERIAL1_IRQ); serial_setup(sp->port, SERIAL1_ADDR, SERIAL1_IRQ);
@@ -650,9 +570,9 @@ serial_init(void)
serial_setup(sp->port, SERIAL2_ADDR, SERIAL2_IRQ); serial_setup(sp->port, SERIAL2_ADDR, SERIAL2_IRQ);
} }
/* Link to host port. */
#ifdef WALTJE #ifdef WALTJE
// serial_link(1, "COM1"); /* Link to host port. */
serial_link(1, "COM1");
serial_link(2, "COM2"); serial_link(2, "COM2");
#endif #endif
} }

View File

@@ -8,7 +8,7 @@
* *
* Definitions for the SERIAL card. * 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> * Author: Fred N. van Kempen, <decwiz@yahoo.com>
* Copyright 2017 Fred N. van Kempen. * Copyright 2017 Fred N. van Kempen.
@@ -24,27 +24,16 @@
#define SERIAL2_IRQ 3 #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_ { typedef struct _serial_ {
int8_t port; /* port number (1,2,..) */ int8_t port; /* port number (1,2,..) */
int8_t irq; /* IRQ channel used */ int8_t irq; /* IRQ channel used */
uint16_t addr; /* I/O address 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 */ uint8_t lsr, thr, mctrl, rcr, /* UART registers */
iir, ier, lcr, msr; iir, ier, lcr, msr;
uint8_t dlab1, dlab2; uint8_t dlab1, dlab2;
uint8_t dat, uint8_t dat;
hold; uint8_t int_status;
uint8_t scratch; uint8_t scratch;
uint8_t fcr; uint8_t fcr;
@@ -52,6 +41,7 @@ typedef struct _serial_ {
void (*rts_callback)(void *); void (*rts_callback)(void *);
void *rts_callback_p; void *rts_callback_p;
uint8_t hold;
uint8_t fifo[256]; uint8_t fifo[256];
int fifo_read, fifo_write; 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 void serial_remove(int port);
extern SERIAL *serial_attach(int, void *, void *); extern SERIAL *serial_attach(int, void *, void *);
extern int serial_link(int, char *); 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*/ #endif /*EMU_SERIAL_H*/