From 6dea8d76ea964246e8faa46af5fe349b04f6f8ac Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 23 Jul 2023 15:15:25 +0200 Subject: [PATCH] Added the secondary version of the OPTi 82c611 VLB IDE controller. --- src/disk/hdc_ide_opti611.c | 83 +++++++++++++++++++++++++++++--------- src/include/86box/hdc.h | 3 +- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/disk/hdc_ide_opti611.c b/src/disk/hdc_ide_opti611.c index 4e44c55f8..1679cefa6 100644 --- a/src/disk/hdc_ide_opti611.c +++ b/src/disk/hdc_ide_opti611.c @@ -31,6 +31,7 @@ #include <86box/plat_unused.h> typedef struct opti611_t { + uint8_t is_sec; uint8_t tries; uint8_t in_cfg; uint8_t cfg_locked; @@ -254,28 +255,54 @@ opti611_ide_readl(uint16_t addr, void *priv) static void opti611_ide_handler(opti611_t *dev) { - ide_pri_disable(); - io_removehandler(0x01f0, 0x0007, - opti611_ide_read, opti611_ide_readw, opti611_ide_readl, - opti611_ide_write, opti611_ide_writew, opti611_ide_writel, - dev); - io_removehandler(0x01f0, 0x0007, - opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, - opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, - dev); + if (dev->is_sec) { + ide_sec_disable(); + io_removehandler(0x0170, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + io_removehandler(0x0170, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); - if (dev->in_cfg && !dev->cfg_locked) { - io_sethandler(0x01f0, 0x0007, - opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, - opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, - dev); + if (dev->in_cfg && !dev->cfg_locked) { + io_sethandler(0x0170, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + } else { + if (dev->regs[0x03] & 0x01) + ide_sec_enable(); + io_sethandler(0x0170, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + } } else { - if (dev->regs[0x03] & 0x01) - ide_pri_enable(); - io_sethandler(0x01f0, 0x0007, - opti611_ide_read, opti611_ide_readw, opti611_ide_readl, - opti611_ide_write, opti611_ide_writew, opti611_ide_writel, - dev); + ide_pri_disable(); + io_removehandler(0x01f0, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + io_removehandler(0x01f0, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + + if (dev->in_cfg && !dev->cfg_locked) { + io_sethandler(0x01f0, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + } else { + if (dev->regs[0x03] & 0x01) + ide_pri_enable(); + io_sethandler(0x01f0, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + } } } @@ -293,6 +320,8 @@ opti611_init(UNUSED(const device_t *info)) opti611_t *dev = (opti611_t *) malloc(sizeof(opti611_t)); memset(dev, 0, sizeof(opti611_t)); + dev->is_sec = info->local; + dev->regs[0x12] = 0x80; dev->regs[0x03] = 0x01; dev->regs[0x05] = 0x20; @@ -317,3 +346,17 @@ const device_t ide_opti611_vlb_device = { .force_redraw = NULL, .config = NULL }; + +const device_t ide_opti611_vlb_sec_device = { + .name = "OPTi 82C611/82C611A VLB (Secondary)", + .internal_name = "ide_opti611_vlb", + .flags = DEVICE_VLB, + .local = 1, + .init = opti611_init, + .close = opti611_close, + .reset = NULL, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/include/86box/hdc.h b/src/include/86box/hdc.h index 9018cfd71..64fd88659 100644 --- a/src/include/86box/hdc.h +++ b/src/include/86box/hdc.h @@ -74,7 +74,8 @@ extern const device_t ide_cmd646_device; /* CMD PCI-646 * extern const device_t ide_cmd646_legacy_only_device; /* CMD PCI-646 (Legacy Mode Only) */ extern const device_t ide_cmd646_single_channel_device; /* CMD PCI-646 (Only primary channel) */ -extern const device_t ide_opti611_vlb_device; /* OPTi 82c611/611A VLB */ +extern const device_t ide_opti611_vlb_device; /* OPTi 82c611/611A VLB */ +extern const device_t ide_opti611_vlb_sec_device; /* OPTi 82c611/611A VLB (Secondary channel) */ extern const device_t ide_ter_device; extern const device_t ide_ter_pnp_device;