Removed the file pointer from the hdd_t struct;

Partially split off the Logitech Serial Mouse emulation from Microsoft Serial Mouse;
Slightly reworked serial port emulation (the two UART's are now device_t's, non-FIFO mode implemented and is now default, FIFO mode reimplemented from scratch so it's now actually correct);
Added the emulation of the SiS 85c497 chip to the SiS 85c496/497 chipset;
Bugfixes to the emulated Super I/O chips and made them all device_t's now.
This commit is contained in:
OBattler
2018-11-08 19:21:55 +01:00
parent 7b1a40164e
commit d386240fcb
34 changed files with 3590 additions and 2952 deletions

View File

@@ -23,6 +23,7 @@ PnP registers :
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include "86box.h"
@@ -36,30 +37,6 @@ PnP registers :
#include "sio.h"
typedef struct um8669f_t
{
int locked;
int cur_reg_108;
uint8_t regs_108[256];
int cur_reg;
int cur_device;
struct
{
int enable;
uint16_t addr;
int irq;
int dma;
} dev[8];
fdc_t *fdc;
int pnp_active;
} um8669f_t;
static um8669f_t um8669f_global;
#define DEV_FDC 0
#define DEV_COM1 1
#define DEV_COM2 2
@@ -74,222 +51,268 @@ static um8669f_t um8669f_global;
#define REG_DMA 0x74
void um8669f_pnp_write(uint16_t port, uint8_t val, void *p)
typedef struct um8669f_t
{
um8669f_t *um8669f = (um8669f_t *)p;
int locked, cur_reg_108,
cur_reg, cur_device,
pnp_active;
uint8_t valxor = 0;
uint8_t regs_108[256];
if (port == 0x279)
um8669f->cur_reg = val;
else
{
if (um8669f->cur_reg == REG_DEVICE)
um8669f->cur_device = val & 7;
else
{
switch (um8669f->cur_reg)
{
case REG_ENABLE:
valxor = um8669f->dev[um8669f->cur_device].enable ^ val;
um8669f->dev[um8669f->cur_device].enable = val;
break;
case REG_ADDRLO:
valxor = (um8669f->dev[um8669f->cur_device].addr & 0xff) ^ val;
um8669f->dev[um8669f->cur_device].addr = (um8669f->dev[um8669f->cur_device].addr & 0xff00) | val;
break;
case REG_ADDRHI:
valxor = ((um8669f->dev[um8669f->cur_device].addr >> 8) & 0xff) ^ val;
um8669f->dev[um8669f->cur_device].addr = (um8669f->dev[um8669f->cur_device].addr & 0x00ff) | (val << 8);
break;
case REG_IRQ:
valxor = um8669f->dev[um8669f->cur_device].irq ^ val;
um8669f->dev[um8669f->cur_device].irq = val;
break;
case REG_DMA:
valxor = um8669f->dev[um8669f->cur_device].dma ^ val;
um8669f->dev[um8669f->cur_device].dma = val;
break;
default:
struct {
int enable;
uint16_t addr;
int irq;
int dma;
} dev[8];
fdc_t *fdc;
serial_t *uart[2];
} um8669f_t;
static void
um8669f_pnp_write(uint16_t port, uint8_t val, void *priv)
{
um8669f_t *dev = (um8669f_t *) priv;
uint8_t valxor = 0;
if (port == 0x279)
dev->cur_reg = val;
else {
if (dev->cur_reg == REG_DEVICE)
dev->cur_device = val & 7;
else {
switch (dev->cur_reg) {
case REG_ENABLE:
valxor = dev->dev[dev->cur_device].enable ^ val;
dev->dev[dev->cur_device].enable = val;
break;
case REG_ADDRLO:
valxor = (dev->dev[dev->cur_device].addr & 0xff) ^ val;
dev->dev[dev->cur_device].addr = (dev->dev[dev->cur_device].addr & 0xff00) | val;
break;
case REG_ADDRHI:
valxor = ((dev->dev[dev->cur_device].addr >> 8) & 0xff) ^ val;
dev->dev[dev->cur_device].addr = (dev->dev[dev->cur_device].addr & 0x00ff) | (val << 8);
break;
case REG_IRQ:
valxor = dev->dev[dev->cur_device].irq ^ val;
dev->dev[dev->cur_device].irq = val;
break;
case REG_DMA:
valxor = dev->dev[dev->cur_device].dma ^ val;
dev->dev[dev->cur_device].dma = val;
break;
default:
valxor = 0;
break;
}
}
switch (um8669f->cur_device)
{
case DEV_FDC:
if ((um8669f->cur_reg == REG_ENABLE) && valxor)
{
fdc_remove(um8669f_global.fdc);
if (um8669f->dev[DEV_FDC].enable & 1)
fdc_set_base(um8669f_global.fdc, 0x03f0);
switch (dev->cur_device) {
case DEV_FDC:
if ((dev->cur_reg == REG_ENABLE) && valxor) {
fdc_remove(dev->fdc);
if (dev->dev[DEV_FDC].enable & 1)
fdc_set_base(dev->fdc, 0x03f0);
}
break;
case DEV_COM1:
if ((um8669f->cur_reg == REG_ENABLE) && valxor)
{
serial_remove(1);
if (um8669f->dev[DEV_COM1].enable & 1)
serial_setup(1, um8669f->dev[DEV_COM1].addr, um8669f->dev[DEV_COM1].irq);
break;
case DEV_COM1:
if ((dev->cur_reg == REG_ENABLE) && valxor) {
serial_remove(dev->uart[0]);
if (dev->dev[DEV_COM1].enable & 1)
serial_setup(dev->uart[0], dev->dev[DEV_COM1].addr, dev->dev[DEV_COM1].irq);
}
break;
case DEV_COM2:
if ((um8669f->cur_reg == REG_ENABLE) && valxor)
{
serial_remove(2);
if (um8669f->dev[DEV_COM2].enable & 1)
serial_setup(2, um8669f->dev[DEV_COM2].addr, um8669f->dev[DEV_COM2].irq);
break;
case DEV_COM2:
if ((dev->cur_reg == REG_ENABLE) && valxor) {
serial_remove(dev->uart[1]);
if (dev->dev[DEV_COM2].enable & 1)
serial_setup(dev->uart[1], dev->dev[DEV_COM2].addr, dev->dev[DEV_COM2].irq);
}
break;
case DEV_LPT1:
if ((um8669f->cur_reg == REG_ENABLE) && valxor)
{
lpt1_remove();
if (um8669f->dev[DEV_LPT1].enable & 1)
lpt1_init(um8669f->dev[DEV_LPT1].addr);
break;
case DEV_LPT1:
if ((dev->cur_reg == REG_ENABLE) && valxor) {
lpt1_remove();
if (dev->dev[DEV_LPT1].enable & 1)
lpt1_init(dev->dev[DEV_LPT1].addr);
}
break;
}
}
}
}
uint8_t um8669f_pnp_read(uint16_t port, void *p)
{
um8669f_t *um8669f = (um8669f_t *)p;
switch (um8669f->cur_reg)
{
case REG_DEVICE:
return um8669f->cur_device;
case REG_ENABLE:
return um8669f->dev[um8669f->cur_device].enable;
case REG_ADDRLO:
return um8669f->dev[um8669f->cur_device].addr & 0xff;
case REG_ADDRHI:
return um8669f->dev[um8669f->cur_device].addr >> 8;
case REG_IRQ:
return um8669f->dev[um8669f->cur_device].irq;
case REG_DMA:
return um8669f->dev[um8669f->cur_device].dma;
}
return 0xff;
}
void um8669f_write(uint16_t port, uint8_t val, void *p)
{
um8669f_t *um8669f = (um8669f_t *)p;
int new_pnp_active;
if (um8669f->locked)
{
if (port == 0x108 && val == 0xaa)
um8669f->locked = 0;
}
else
{
if (port == 0x108)
{
if (val == 0x55)
um8669f->locked = 1;
else
um8669f->cur_reg_108 = val;
}
else
{
um8669f->regs_108[um8669f->cur_reg_108] = val;
if (um8669f->cur_reg_108 == 0xc1) {
new_pnp_active = !!(um8669f->regs_108[0xc1] & 0x80);
if (new_pnp_active != um8669f->pnp_active) {
if (new_pnp_active) {
io_sethandler(0x0279, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, um8669f);
io_sethandler(0x0a79, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, um8669f);
io_sethandler(0x03e3, 0x0001, um8669f_pnp_read, NULL, NULL, NULL, NULL, NULL, um8669f);
} else {
io_removehandler(0x0279, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, um8669f);
io_removehandler(0x0a79, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, um8669f);
io_removehandler(0x03e3, 0x0001, um8669f_pnp_read, NULL, NULL, NULL, NULL, NULL, um8669f);
}
um8669f->pnp_active = new_pnp_active;
}
}
}
}
}
uint8_t um8669f_read(uint16_t port, void *p)
{
um8669f_t *um8669f = (um8669f_t *)p;
if (um8669f->locked)
return 0xff;
if (port == 0x108)
return um8669f->cur_reg_108; /*???*/
else
return um8669f->regs_108[um8669f->cur_reg_108];
}
void um8669f_reset(void)
{
fdc_t *temp_fdc = um8669f_global.fdc;
fdc_reset(um8669f_global.fdc);
serial_remove(1);
serial_setup(1, SERIAL1_ADDR, SERIAL1_IRQ);
serial_remove(2);
serial_setup(2, SERIAL2_ADDR, SERIAL2_IRQ);
lpt2_remove();
lpt1_remove();
lpt1_init(0x378);
if (um8669f_global.pnp_active) {
io_removehandler(0x0279, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, &um8669f_global);
io_removehandler(0x0a79, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, &um8669f_global);
io_removehandler(0x03e3, 0x0001, um8669f_pnp_read, NULL, NULL, NULL, NULL, NULL, &um8669f_global);
um8669f_global.pnp_active = 0;
break;
}
}
memset(&um8669f_global, 0, sizeof(um8669f_t));
um8669f_global.fdc = temp_fdc;
um8669f_global.locked = 1;
um8669f_global.dev[DEV_FDC].enable = 1;
um8669f_global.dev[DEV_FDC].addr = 0x03f0;
um8669f_global.dev[DEV_FDC].irq = 6;
um8669f_global.dev[DEV_FDC].dma = 2;
um8669f_global.dev[DEV_COM1].enable = 1;
um8669f_global.dev[DEV_COM1].addr = 0x03f8;
um8669f_global.dev[DEV_COM1].irq = 4;
um8669f_global.dev[DEV_COM2].enable = 1;
um8669f_global.dev[DEV_COM2].addr = 0x02f8;
um8669f_global.dev[DEV_COM2].irq = 3;
um8669f_global.dev[DEV_LPT1].enable = 1;
um8669f_global.dev[DEV_LPT1].addr = 0x0378;
um8669f_global.dev[DEV_LPT1].irq = 7;
}
}
void um8669f_init(void)
static uint8_t
um8669f_pnp_read(uint16_t port, void *priv)
{
um8669f_global.fdc = device_add(&fdc_at_device);
um8669f_t *dev = (um8669f_t *) priv;
uint8_t ret = 0xff;
io_sethandler(0x0108, 0x0002, um8669f_read, NULL, NULL, um8669f_write, NULL, NULL, &um8669f_global);
switch (dev->cur_reg) {
case REG_DEVICE:
ret = dev->cur_device;
break;
case REG_ENABLE:
ret = dev->dev[dev->cur_device].enable;
break;
case REG_ADDRLO:
ret = dev->dev[dev->cur_device].addr & 0xff;
break;
case REG_ADDRHI:
ret = dev->dev[dev->cur_device].addr >> 8;
break;
case REG_IRQ:
ret = dev->dev[dev->cur_device].irq;
break;
case REG_DMA:
ret = dev->dev[dev->cur_device].dma;
break;
}
um8669f_reset();
return ret;
}
void um8669f_write(uint16_t port, uint8_t val, void *priv)
{
um8669f_t *dev = (um8669f_t *) priv;
int new_pnp_active;
if (dev->locked) {
if ((port == 0x108) && (val == 0xaa))
dev->locked = 0;
} else {
if (port == 0x108) {
if (val == 0x55)
dev->locked = 1;
else
dev->cur_reg_108 = val;
} else {
dev->regs_108[dev->cur_reg_108] = val;
if (dev->cur_reg_108 == 0xc1) {
new_pnp_active = !!(dev->regs_108[0xc1] & 0x80);
if (new_pnp_active != dev->pnp_active) {
if (new_pnp_active) {
io_sethandler(0x0279, 0x0001,
NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, dev);
io_sethandler(0x0a79, 0x0001,
NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, dev);
io_sethandler(0x03e3, 0x0001,
um8669f_pnp_read, NULL, NULL, NULL, NULL, NULL, dev);
} else {
io_removehandler(0x0279, 0x0001,
NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, dev);
io_removehandler(0x0a79, 0x0001,
NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, dev);
io_removehandler(0x03e3, 0x0001,
um8669f_pnp_read, NULL, NULL, NULL, NULL, NULL, dev);
}
dev->pnp_active = new_pnp_active;
}
}
}
}
}
uint8_t um8669f_read(uint16_t port, void *priv)
{
um8669f_t *dev = (um8669f_t *) priv;
uint8_t ret = 0xff;
if (!dev->locked) {
if (port == 0x108)
ret = dev->cur_reg_108; /* ??? */
else
ret = dev->regs_108[dev->cur_reg_108];
}
return ret;
}
void
um8669f_reset(um8669f_t *dev)
{
fdc_reset(dev->fdc);
serial_remove(dev->uart[0]);
serial_setup(dev->uart[0], SERIAL1_ADDR, SERIAL1_IRQ);
serial_remove(dev->uart[1]);
serial_setup(dev->uart[1], SERIAL2_ADDR, SERIAL2_IRQ);
lpt2_remove();
lpt1_remove();
lpt1_init(0x378);
if (dev->pnp_active) {
io_removehandler(0x0279, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, dev);
io_removehandler(0x0a79, 0x0001, NULL, NULL, NULL, um8669f_pnp_write, NULL, NULL, dev);
io_removehandler(0x03e3, 0x0001, um8669f_pnp_read, NULL, NULL, NULL, NULL, NULL, dev);
dev->pnp_active = 0;
}
dev->locked = 1;
dev->dev[DEV_FDC].enable = 1;
dev->dev[DEV_FDC].addr = 0x03f0;
dev->dev[DEV_FDC].irq = 6;
dev->dev[DEV_FDC].dma = 2;
dev->dev[DEV_COM1].enable = 1;
dev->dev[DEV_COM1].addr = 0x03f8;
dev->dev[DEV_COM1].irq = 4;
dev->dev[DEV_COM2].enable = 1;
dev->dev[DEV_COM2].addr = 0x02f8;
dev->dev[DEV_COM2].irq = 3;
dev->dev[DEV_LPT1].enable = 1;
dev->dev[DEV_LPT1].addr = 0x0378;
dev->dev[DEV_LPT1].irq = 7;
}
static void
um8669f_close(void *priv)
{
um8669f_t *dev = (um8669f_t *) priv;
free(dev);
}
static void *
um8669f_init(const device_t *info)
{
um8669f_t *dev = (um8669f_t *) malloc(sizeof(um8669f_t));
memset(dev, 0, sizeof(um8669f_t));
dev->fdc = device_add(&fdc_at_device);
dev->uart[0] = device_add_inst(&ns16550_device, 1);
dev->uart[1] = device_add_inst(&ns16550_device, 2);
io_sethandler(0x0108, 0x0002,
um8669f_read, NULL, NULL, um8669f_write, NULL, NULL, dev);
um8669f_reset(dev);
return dev;
}
const device_t um8669f_device = {
"UMC UM8669F Super I/O",
0,
0,
um8669f_init, um8669f_close, NULL,
NULL, NULL, NULL,
NULL
};