From 4ff0a7276500c903556a4694c0218e60cc12ccbd Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 9 Jul 2021 17:00:15 -0300 Subject: [PATCH 01/52] Add CS423x EEPROM persistence --- src/sound/snd_cs423x.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 0f70c2f8d..7ea1deb65 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -34,6 +34,7 @@ #include <86box/snd_ad1848.h> #include <86box/snd_opl.h> #include <86box/snd_sb.h> +#include <86box/nvr.h> enum { @@ -135,6 +136,7 @@ typedef struct cs423x_t uint16_t wss_base, opl_base, sb_base, ctrl_base, ram_addr, eeprom_size: 11; uint8_t type, ad1848_type, pnp_offset, regs[8], indirect_regs[16], eeprom_data[2048], ram_data[384], ram_dl: 2, opl_wss: 1; + char *nvr_path; uint8_t pnp_enable: 1, key_pos: 5, slam_enable: 1, slam_state: 2, slam_ld, slam_reg; isapnp_device_config_t *slam_config; @@ -146,6 +148,20 @@ static void cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_ static void cs423x_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv); +static void +cs423x_nvram(cs423x_t *dev, uint8_t save) +{ + FILE *f = nvr_fopen(dev->nvr_path, save ? "wb" : "rb"); + if (f) { + if (save) + fwrite(dev->eeprom_data, sizeof(dev->eeprom_data), 1, f); + else + fread(dev->eeprom_data, sizeof(dev->eeprom_data), 1, f); + fclose(f); + } +} + + static uint8_t cs423x_read(uint16_t addr, void *priv) { @@ -678,10 +694,14 @@ cs423x_reset(void *priv) cs423x_t *dev = (cs423x_t *) priv; /* Load EEPROM data to RAM, or just clear RAM if there's no EEPROM. */ - if (dev->eeprom) + if (dev->eeprom) { memcpy(dev->ram_data, &dev->eeprom_data[4], MIN(sizeof(dev->ram_data), sizeof(dev->eeprom_data) - 4)); - else + + /* Save EEPROM contents to file. */ + cs423x_nvram(dev, 1); + } else { memset(dev->ram_data, 0, sizeof(dev->ram_data)); + } /* Reset registers. */ memset(dev->indirect_regs, 0, sizeof(dev->indirect_regs)); @@ -729,17 +749,26 @@ cs423x_init(const device_t *info) dev->eeprom_data[2] = sizeof(cs4236b_eeprom) >> 8; dev->eeprom_data[3] = sizeof(cs4236b_eeprom) & 0xff; - /* Set PnP card ID. */ + /* Set PnP card ID and EEPROM file name. */ switch (dev->type) { + case CRYSTAL_CS4236B: + dev->nvr_path = "cs4236b.nvr"; + break; + case CRYSTAL_CS4237B: dev->eeprom_data[26] = 0x37; + dev->nvr_path = "cs4237b.nvr"; break; case CRYSTAL_CS4238B: dev->eeprom_data[26] = 0x38; + dev->nvr_path = "cs4238b.nvr"; break; } + /* Load EEPROM contents from file if present. */ + cs423x_nvram(dev, 0); + /* Initialize game port. The '7B and '8B game port only responds to 6 I/O ports; the remaining 2 ports are reserved on those chips, and probably connected to the Digital Assist feature. */ dev->gameport = gameport_add((dev->type == CRYSTAL_CS4236B) ? &gameport_pnp_device : &gameport_pnp_6io_device); @@ -774,8 +803,11 @@ cs423x_close(void *priv) { cs423x_t *dev = (cs423x_t *) priv; - if (dev->eeprom) + /* Save EEPROM contents to file. */ + if (dev->eeprom) { + cs423x_nvram(dev, 1); i2c_eeprom_close(dev->eeprom); + } i2c_gpio_close(dev->i2c); From ee253ad0e98f62bd354a45e6805ecf987a1e8f43 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 9 Jul 2021 17:01:12 -0300 Subject: [PATCH 02/52] Remove TRC reset workaround from ICS9xxx --- src/device/clock_ics9xxx.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/device/clock_ics9xxx.c b/src/device/clock_ics9xxx.c index ddca7712b..df7aaf5fa 100644 --- a/src/device/clock_ics9xxx.c +++ b/src/device/clock_ics9xxx.c @@ -1280,13 +1280,11 @@ ics9xxx_get(uint8_t model) dev->name = "ICS9xxx-xx Clock Generator"; dev->local = model; + dev->flags = DEVICE_ISA; #ifdef ENABLE_ICS9xxx_DETECT - if (model == ICS9xxx_xx) { - dev->flags = DEVICE_PCI; + if (model == ICS9xxx_xx) dev->reset = ics9xxx_detect_reset; - } else #endif - dev->flags = DEVICE_ISA; dev->init = ics9xxx_init; dev->close = ics9xxx_close; From b9c68bf277af8d7167900d57fb8580819ecac105 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 11 Jul 2021 16:58:52 -0300 Subject: [PATCH 03/52] Initial commit for AC97 --- src/chipset/via_pipc.c | 206 +++++++++-- src/device/hasp.c | 3 +- src/game/gameport.c | 2 +- src/include/86box/device.h | 3 +- src/include/86box/snd_ac97.h | 49 +++ src/machine/m_at_socket370.c | 7 +- src/machine/machine_table.c | 2 +- src/pci.c | 2 +- src/sound/CMakeLists.txt | 2 +- src/sound/snd_ac97_codec.c | 227 +++++++++++++ src/sound/snd_ac97_via.c | 638 +++++++++++++++++++++++++++++++++++ src/sound/snd_cs423x.c | 2 +- src/win/Makefile.mingw | 1 + 13 files changed, 1115 insertions(+), 29 deletions(-) create mode 100644 src/include/86box/snd_ac97.h create mode 100644 src/sound/snd_ac97_codec.c create mode 100644 src/sound/snd_ac97_via.c diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 46d2f8597..9ad32deca 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -49,6 +49,8 @@ #include <86box/chipset.h> #include <86box/sio.h> #include <86box/hwm.h> +#include <86box/gameport.h> +#include <86box/snd_ac97.h> /* Most revision numbers (PCI-ISA bridge or otherwise) were lifted from PCI device listings on forums, as VIA's datasheets are not very helpful regarding those. */ @@ -77,6 +79,8 @@ typedef struct smbus_piix4_t *smbus; usb_t *usb[2]; acpi_t *acpi; + void *gameport, *ac97; + uint16_t midigame_base; } pipc_t; @@ -100,6 +104,13 @@ pipc_log(const char *fmt, ...) #endif +static void pipc_sgd_handlers(pipc_t *dev, uint8_t modem); +static void pipc_midigame_handlers(pipc_t *dev, uint8_t modem); +static void pipc_codec_handlers(pipc_t *dev, uint8_t modem); +static uint8_t pipc_read(int func, int addr, void *priv); +static void pipc_write(int func, int addr, uint8_t val, void *priv); + + static void pipc_reset_hard(void *priv) { @@ -332,19 +343,29 @@ pipc_reset_hard(void *priv) } dev->ac97_regs[i][0x10] = 0x01; - dev->ac97_regs[i][(dev->local >= VIA_PIPC_8231) ? 0x1c : 0x14] = 0x01; - - if ((i == 0) && (dev->local >= VIA_PIPC_8231)) { - dev->ac97_regs[i][0x18] = 0x31; - dev->ac97_regs[i][0x19] = 0x03; + if (i == 0) { + dev->ac97_regs[i][0x14] = 0x01; + dev->ac97_regs[i][0x18] = 0x01; } + dev->ac97_regs[i][0x1c] = 0x01; dev->ac97_regs[i][0x3d] = 0x03; + if (i == 0) + dev->ac97_regs[i][0x40] = 0x01; + dev->ac97_regs[i][0x43] = 0x1c; + dev->ac97_regs[i][0x4b] = 0x02; + + pipc_sgd_handlers(dev, i); + pipc_midigame_handlers(dev, i); + pipc_codec_handlers(dev, i); } } + if (dev->gameport) + gameport_remap(dev->gameport, 0x200); + pci_set_irq_routing(PCI_INTA, PCI_IRQ_DISABLED); pci_set_irq_routing(PCI_INTB, PCI_IRQ_DISABLED); pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED); @@ -428,6 +449,79 @@ pipc_bus_master_handlers(pipc_t *dev) } +static void +pipc_sgd_handlers(pipc_t *dev, uint8_t modem) +{ + if (!dev->ac97) + return; + + if (modem) + ac97_via_remap_modem_sgd(dev->ac97, dev->ac97_regs[1][0x11] << 8, dev->ac97_regs[1][0x04] & PCI_COMMAND_IO); + else + ac97_via_remap_audio_sgd(dev->ac97, dev->ac97_regs[0][0x11] << 8, dev->ac97_regs[0][0x04] & PCI_COMMAND_IO); +} + + +static uint8_t +pipc_midigame_read(uint16_t addr, void *priv) +{ + pipc_t *dev = (pipc_t *) priv; + uint8_t ret = 0xff; + + addr &= 0x03; + switch (addr) { + case 0x02: case 0x03: + ret = pipc_read(5, 0x48 + addr, dev); + break; + } + + return ret; +} + + +static void +pipc_midigame_write(uint16_t addr, uint8_t val, void *priv) +{ + pipc_t *dev = (pipc_t *) priv; + + addr &= 0x03; + switch (addr) { + case 0x02: case 0x03: + pipc_write(5, 0x48 + addr, val, dev); + break; + } +} + + +static void +pipc_midigame_handlers(pipc_t *dev, uint8_t modem) +{ + if (!dev->ac97 || modem) + return; + + if (dev->midigame_base) + io_removehandler(dev->midigame_base, 4, pipc_midigame_read, NULL, NULL, pipc_midigame_write, NULL, NULL, dev); + + dev->midigame_base = (dev->ac97_regs[0][0x19] << 8) | (dev->ac97_regs[0][0x18] & 0xfc); + + if (dev->midigame_base && (dev->ac97_regs[0][0x04] & PCI_COMMAND_IO)) + io_sethandler(dev->midigame_base, 4, pipc_midigame_read, NULL, NULL, pipc_midigame_write, NULL, NULL, dev); +} + + +static void +pipc_codec_handlers(pipc_t *dev, uint8_t modem) +{ + if (!dev->ac97) + return; + + if (modem) + ac97_via_remap_modem_codec(dev->ac97, dev->ac97_regs[1][0x1d] << 8, dev->ac97_regs[1][0x04] & PCI_COMMAND_IO); + else + ac97_via_remap_audio_codec(dev->ac97, dev->ac97_regs[0][0x1d] << 8, dev->ac97_regs[0][0x04] & PCI_COMMAND_IO); +} + + static uint8_t pipc_read(int func, int addr, void *priv) { @@ -487,8 +581,12 @@ pipc_read(int func, int addr, void *priv) ret |= 0x10; } } - else if ((func <= (pm_func + 2)) && !(dev->pci_isa_regs[0x85] & ((func == (pm_func + 1)) ? 0x04 : 0x08))) /* AC97 / MC97 */ - ret = dev->ac97_regs[func - pm_func - 1][addr]; + else if ((func <= (pm_func + 2)) && !(dev->pci_isa_regs[0x85] & ((func == (pm_func + 1)) ? 0x04 : 0x08))) { /* AC97 / MC97 */ + if (addr == 0x40) + ret = ac97_via_read_status(dev->ac97, func - pm_func - 1); + else + ret = dev->ac97_regs[func - pm_func - 1][addr]; + } pipc_log("PIPC: read(%d, %02X) = %02X\n", func, addr, ret); @@ -528,7 +626,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) pipc_log("PIPC: write(%d, %02X, %02X)\n", func, addr, val); if (func == 0) { /* PCI-ISA bridge */ - /* Read-only addresses */ + /* Read-only addresses. */ if ((addr < 4) || (addr == 5) || ((addr >= 8) && (addr < 0x40)) || (addr == 0x49) || (addr == 0x4b) || (addr == 0x53) || ((addr >= 0x5d) && (addr < 0x5f)) || (addr >= 0x90)) return; @@ -693,7 +791,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) break; } } else if (func == 1) { /* IDE */ - /* Read-only addresses and disable bit */ + /* Read-only addresses. */ if ((addr < 4) || (addr == 5) || (addr == 8) || ((addr >= 0xa) && (addr < 0x0d)) || ((addr >= 0x0e) && (addr < 0x10)) || ((addr >= 0x12) && (addr < 0x13)) || ((addr >= 0x16) && (addr < 0x17)) || ((addr >= 0x1a) && (addr < 0x1b)) || @@ -702,12 +800,16 @@ pipc_write(int func, int addr, uint8_t val, void *priv) ((addr >= 0x62) && (addr < 0x68)) || ((addr >= 0x6a) && (addr < 0x70)) || (addr == 0x72) || (addr == 0x73) || (addr == 0x76) || (addr == 0x77) || (addr == 0x7a) || (addr == 0x7b) || (addr == 0x7e) || (addr == 0x7f) || - ((addr >= 0x84) && (addr < 0x88)) || (addr >= 0x8c) || (dev->pci_isa_regs[0x48] & 0x02)) + ((addr >= 0x84) && (addr < 0x88)) || (addr >= 0x8c)) return; if ((dev->local <= VIA_PIPC_586B) && ((addr == 0x54) || (addr >= 0x70))) return; + /* Check disable bit. */ + if (dev->pci_isa_regs[0x48] & 0x02) + return; + switch (addr) { case 0x04: dev->ide_regs[0x04] = val & 0x85; @@ -851,18 +953,18 @@ pipc_write(int func, int addr, uint8_t val, void *priv) break; } } else if (func < pm_func) { /* USB */ - /* Read-only addresses */ + /* Read-only addresses. */ if ((addr < 4) || (addr == 5) || (addr == 6) || ((addr >= 8) && (addr < 0xd)) || ((addr >= 0xe) && (addr < 0x20)) || ((addr >= 0x22) && (addr < 0x3c)) || ((addr >= 0x3e) && (addr < 0x40)) || ((addr >= 0x42) && (addr < 0x44)) || ((addr >= 0x46) && (addr < 0x84)) || ((addr >= 0x85) && (addr < 0xc0)) || (addr >= 0xc2)) return; - /* Check disable bits for both controllers */ - if ((func == 2) ? (dev->pci_isa_regs[0x48] & 0x04) : (dev->pci_isa_regs[0x85] & 0x10)) + if ((dev->local <= VIA_PIPC_596B) && (addr == 0x84)) return; - if ((dev->local <= VIA_PIPC_596B) && (addr == 0x84)) + /* Check disable bits for both controllers. */ + if ((func == 2) ? (dev->pci_isa_regs[0x48] & 0x04) : (dev->pci_isa_regs[0x85] & 0x10)) return; switch (addr) { @@ -965,22 +1067,78 @@ pipc_write(int func, int addr, uint8_t val, void *priv) break; } } else if (func <= pm_func + 2) { /* AC97 / MC97 */ - /* Read-only addresses */ - if ((addr < 0x4) || ((addr >= 0x6) && (addr < 0xd)) || ((addr >= 0xe) && (addr < 0x10)) || ((addr >= 0x1c) && (addr < 0x2c)) || + /* Read-only addresses. */ + if ((addr < 0x4) || ((addr >= 0x6) && (addr < 0x9)) || ((addr >= 0xc) && (addr < 0x11)) || (addr == 0x16) || + (addr == 0x17) || (addr == 0x1a) || (addr == 0x1b) || ((addr >= 0x1e) && (addr < 0x2c)) || ((addr >= 0x30) && (addr < 0x34)) || ((addr >= 0x35) && (addr < 0x3c)) || ((addr >= 0x3d) && (addr < 0x41)) || ((addr >= 0x45) && (addr < 0x4a)) || (addr >= 0x4c)) return; - /* Also check disable bits for both controllers */ - if ((func == (pm_func + 1)) && ((addr == 0x44) || (dev->pci_isa_regs[0x85] & 0x04))) + /* Small shortcut. */ + func = func - pm_func - 1; + + /* Check disable bits and specific read-only addresses for both controllers. */ + if ((func == 0) && (((addr >= 0x09) && (addr < 0xc)) || (addr == 0x44) || (dev->pci_isa_regs[0x85] & 0x04))) return; - if ((func == (pm_func + 2)) && ((addr == 0x4a) || (addr == 0x4b) || (dev->pci_isa_regs[0x85] & 0x08))) + if ((func == 1) && ((addr == 0x14) || (addr == 0x15) || (addr == 0x18) || (addr == 0x19) || (addr == 0x42) || + (addr == 0x43) || (addr == 0x48) || (addr == 0x4a) || (addr == 0x4b) || (dev->pci_isa_regs[0x85] & 0x08))) return; switch (addr) { + case 0x04: + dev->ac97_regs[func][addr] = val; + pipc_midigame_handlers(dev, func); + pipc_sgd_handlers(dev, func); + pipc_codec_handlers(dev, func); + break; + + case 0x09: case 0x0a: case 0x0b: + if (dev->ac97_regs[func][0x44] & 0x20) + dev->ac97_regs[func][addr] = val; + break; + + case 0x11: + dev->ac97_regs[func][addr] = val; + pipc_sgd_handlers(dev, func); + break; + + case 0x18: case 0x19: + if (addr == 0x18) + val = (val & 0xfc) | 1; + dev->ac97_regs[func][addr] = val; + pipc_midigame_handlers(dev, func); + break; + + case 0x1c: + dev->ac97_regs[func][addr] = val; + pipc_codec_handlers(dev, func); + break; + + case 0x2c: case 0x2d: case 0x2e: case 0x2f: + if ((func == 0) && (dev->ac97_regs[func][0x42] & 0x20)) + dev->ac97_regs[func][addr] = val; + break; + + case 0x42: case 0x4a: case 0x4b: + dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; + gameport_remap(dev->gameport, (dev->ac97_regs[0][0x42] & 0x08) ? ((dev->ac97_regs[0][0x4b] << 8) | dev->ac97_regs[0][0x4a]) : 0); + break; + + case 0x43: + dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; + break; + + case 0x44: + dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0xf0; + break; + + case 0x45: + dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0x0f; + break; + default: - dev->ac97_regs[func - pm_func - 1][addr] = val; + dev->ac97_regs[func][addr] = val; break; } } @@ -1052,9 +1210,15 @@ pipc_init(const device_t *info) dev->acpi = device_add(&acpi_via_device); dev->usb[0] = device_add_inst(&usb_device, 1); - if (dev->local >= VIA_PIPC_686A) + if (dev->local >= VIA_PIPC_686A) { dev->usb[1] = device_add_inst(&usb_device, 2); + dev->ac97 = device_add(&ac97_via_device); + ac97_via_set_slot(dev->ac97, dev->slot, PCI_INTC); + + dev->gameport = gameport_add(&gameport_sio_device); + } + pipc_reset_hard(dev); device_add(&port_92_pci_device); diff --git a/src/device/hasp.c b/src/device/hasp.c index 2c6aca190..60dae74c6 100644 --- a/src/device/hasp.c +++ b/src/device/hasp.c @@ -50,6 +50,7 @@ enum { HASP_TYPE_SAVQUEST = 0 }; + typedef struct { const uint8_t *password, *prodinfo; const uint8_t password_size, prodinfo_size; @@ -266,7 +267,7 @@ hasp_read_status(void *priv) static void * hasp_init(void *lpt, int type) { - hasp_t *dev = (hasp_t *) malloc(sizeof(hasp_t)); + hasp_t *dev = malloc(sizeof(hasp_t)); memset(dev, 0, sizeof(hasp_t)); hasp_log("HASP: init(%d)\n", type); diff --git a/src/game/gameport.c b/src/game/gameport.c index b0caff22a..80c686ec2 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -324,7 +324,7 @@ gameport_remap(void *priv, uint16_t address) if (dev->addr) { /* Add this port to the active ports list. */ - if ( !active_gameports || ((dev->addr & 0xfff8) == 0x200)) { + if (!active_gameports || ((dev->addr & 0xfff8) == 0x200)) { /* No ports have been added yet, or port within 200-207h: add to top. */ dev->next = active_gameports; active_gameports = dev; diff --git a/src/include/86box/device.h b/src/include/86box/device.h index 4226eee81..ec567bf57 100644 --- a/src/include/86box/device.h +++ b/src/include/86box/device.h @@ -65,7 +65,8 @@ enum { DEVICE_EISA = 0x100, /* requires the EISA bus */ DEVICE_VLB = 0x200, /* requires the PCI bus */ DEVICE_PCI = 0x400, /* requires the VLB bus */ - DEVICE_AGP = 0x800 /* requires the AGP bus */ + DEVICE_AGP = 0x800, /* requires the AGP bus */ + DEVICE_AC97 = 0x1000 /* requires the AC'97 bus */ }; diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h new file mode 100644 index 000000000..8d66cdea4 --- /dev/null +++ b/src/include/86box/snd_ac97.h @@ -0,0 +1,49 @@ +/* + * 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. + * + * Definitions for AC'97 audio emulation. + * + * + * + * Authors: RichardG, + * + * Copyright 2021 RichardG. + */ +#ifndef EMU_SND_AC97_H +# define EMU_SND_AC97_H + + +typedef struct { + uint32_t id; + uint8_t regs[128]; +} ac97_codec_t; + + +extern uint8_t ac97_codec_read(ac97_codec_t *dev, uint8_t reg); +extern void ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val); +extern void ac97_codec_reset(void *priv); + +extern void ac97_via_set_slot(void *priv, int slot, int irq_pin); +extern uint8_t ac97_via_read_status(void *priv, uint8_t modem); +extern void ac97_via_remap_audio_sgd(void *priv, uint16_t new_io_base, uint8_t enable); +extern void ac97_via_remap_modem_sgd(void *priv, uint16_t new_io_base, uint8_t enable); +extern void ac97_via_remap_audio_codec(void *priv, uint16_t new_io_base, uint8_t enable); +extern void ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t enable); + + +#ifdef EMU_DEVICE_H +extern ac97_codec_t **ac97_codec, **ac97_modem_codec; +extern int ac97_codec_count, ac97_modem_codec_count; + +extern const device_t alc100_device; + +extern const device_t ac97_via_device; +#endif + + +#endif diff --git a/src/machine/m_at_socket370.c b/src/machine/m_at_socket370.c index b7a83befb..cc2e1718a 100644 --- a/src/machine/m_at_socket370.c +++ b/src/machine/m_at_socket370.c @@ -37,6 +37,7 @@ #include "cpu.h" #include <86box/machine.h> #include <86box/clock.h> +#include <86box/snd_ac97.h> int @@ -432,7 +433,7 @@ machine_at_6via90ap_init(const machine_t *model) pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); - pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 1, 2, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); pci_register_slot(0x09, PCI_CARD_NORMAL, 1, 2, 3, 4); pci_register_slot(0x0A, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x0B, PCI_CARD_NORMAL, 3, 4, 1, 2); @@ -451,6 +452,10 @@ machine_at_6via90ap_init(const machine_t *model) hwm_values.temperatures[1] += 2; /* System offset */ hwm_values.temperatures[2] = 0; /* unused */ + /* I recall identifying this board's codec as the ALC100 while studying AC97, but I couldn't find + that information again. Other Acorp boards have the ALC100, though, so it's a safe bet. -RG */ + device_add(&alc100_device); + return ret; } diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index a952c2b4e..c60982831 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -461,7 +461,7 @@ const machine_t machines[] = { { "[VIA Apollo Pro133] ECS P6BAP", "p6bap", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, 1.5, 8.0, MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192,1572864, 8192, 255, machine_at_p6bap_init, NULL }, { "[VIA Apollo Pro133A] AEWIN WCF-681", "wcf681", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 133333333, 1300, 3500, 1.5, 8.0, /* limits assumed */ MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192,1048576, 8192, 255, machine_at_wcf681_init, NULL }, { "[VIA Apollo Pro133A] ASUS CUV4X-LS", "cuv4xls", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, 1.5, 8.0, (MACHINE_AGP & ~MACHINE_AT) | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 16384,1572864, 8192, 255, machine_at_cuv4xls_init, NULL }, - { "[VIA Apollo Pro133A] Acorp 6VIA90AP", "6via90ap", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, MACHINE_MULTIPLIER_FIXED, MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192,1572864, 8192, 255, machine_at_6via90ap_init, NULL }, + { "[VIA Apollo Pro133A] Acorp 6VIA90AP", "6via90ap", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, MACHINE_MULTIPLIER_FIXED, MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL | MACHINE_GAMEPORT, 8192,1572864, 8192, 255, machine_at_6via90ap_init, NULL }, { "[VIA Apollo ProMedia] Jetway 603TCF", "603tcf", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, 1.5, 8.0, MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192,1048576, 8192, 255, machine_at_603tcf_init, NULL }, /* Miscellaneous/Fake/Hypervisor machines */ diff --git a/src/pci.c b/src/pci.c index 5f1c48f50..a4272e6bd 100644 --- a/src/pci.c +++ b/src/pci.c @@ -73,7 +73,7 @@ static int trc_reg = 0; static void pci_reset_regs(void); - +#define ENABLE_PCI_LOG 1 #ifdef ENABLE_PCI_LOG int pci_do_log = ENABLE_PCI_LOG; diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index d991e5cc2..f5a6435c4 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -14,7 +14,7 @@ # add_library(snd OBJECT sound.c openal.c snd_opl.c snd_opl_nuked.c snd_resid.cc - midi.c midi_system.c snd_speaker.c snd_pssj.c snd_lpt_dac.c + midi.c midi_system.c snd_speaker.c snd_pssj.c snd_lpt_dac.c snd_ac97_codec.c snd_ac97_via.c snd_lpt_dss.c snd_adlib.c snd_adlibgold.c snd_ad1848.c snd_audiopci.c snd_azt2316a.c snd_cms.c snd_cs423x.c snd_gus.c snd_sb.c snd_sb_dsp.c snd_emu8k.c snd_mpu401.c snd_sn76489.c snd_ssi2001.c snd_wss.c snd_ym7128.c) diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c new file mode 100644 index 000000000..e96795011 --- /dev/null +++ b/src/sound/snd_ac97_codec.c @@ -0,0 +1,227 @@ +/* + * 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. + * + * AC'97 audio codec emulation. + * + * + * + * Authors: RichardG, + * + * Copyright 2021 RichardG. + */ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/snd_ac97.h> + +#define AC97_CODEC_ID(f, s, t, dev) ((((f) & 0xff) << 24) | (((s) & 0xff) << 16) | (((t) & 0xff) << 8) | ((dev) & 0xff)) + + +enum { + AC97_CODEC_ALC100 = AC97_CODEC_ID('A', 'L', 'C', 0x20) +}; + +#define ENABLE_AC97_CODEC_LOG 1 +#ifdef ENABLE_AC97_CODEC_LOG +int ac97_codec_do_log = ENABLE_AC97_CODEC_LOG; + +static void +ac97_codec_log(const char *fmt, ...) +{ + va_list ap; + + if (ac97_codec_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +#define ac97_codec_log(fmt, ...) +#endif + +ac97_codec_t **ac97_codec = NULL, **ac97_modem_codec = NULL; +int ac97_codec_count = 0, ac97_modem_codec_count = 0; + + +uint8_t +ac97_codec_read(ac97_codec_t *dev, uint8_t reg) +{ + uint8_t ret = dev->regs[reg & 0x7f]; + + ac97_codec_log("AC97 Codec: read(%02X) = %02X\n", reg, ret); + + return ret; +} + + +void +ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) +{ + ac97_codec_log("AC97 Codec: write(%02X, %02X)\n", reg, val); + + reg &= 0x7f; + + switch (reg) { + case 0x00: case 0x01: /* Reset / ID code */ + ac97_codec_reset(dev); + /* fall-through */ + + case 0x08: case 0x09: /* Master Tone Control (optional) */ + case 0x0d: /* Phone Volume MSB */ + case 0x0f: /* Mic Volume MSB */ + case 0x1e: case 0x1f: /* Record Gain Mic (optional) */ + case 0x22: case 0x23: /* 3D Control (optional) */ + case 0x24: case 0x25: /* Audio Interrupt and Paging Mechanism (optional) */ + case 0x26: /* Powerdown Ctrl/Stat LSB */ + case 0x28: case 0x29: /* Extended Audio ID */ + //case 0x2a ... 0x59: /* Linux tests for audio capability by writing to 38-39 */ + case 0x5a ... 0x5f: /* Vendor Reserved */ + //case 0x60 ... 0x6f: + case 0x70 ... 0x7b: /* Vendor Reserved */ + /* Read-only registers. */ + return; + + case 0x03: /* Master Volume MSB */ + case 0x05: /* Aux Out Volume MSB */ + val &= 0xbf; + break; + + case 0x07: /* Mono Volume MSB */ + case 0x20: /* General Purpose LSB */ + val &= 0x80; + break; + + case 0x02: /* Master Volume LSB */ + case 0x04: /* Aux Out Volume LSB */ + case 0x06: /* Mono Volume LSB */ + case 0x0b: /* PC Beep Volume MSB */ + val &= 0x3f; + break; + + case 0x0a: /* PC Beep Volume LSB */ + val &= 0xfe; + break; + + case 0x0c: /* Phone Volume LSB */ + case 0x10: /* Line In Volume LSB */ + case 0x12: /* CD Volume LSB */ + case 0x14: /* Video Volume LSB */ + case 0x16: /* Aux In Volume LSB */ + case 0x18: /* PCM Out Volume LSB */ + val &= 0x1f; + break; + + case 0x0e: /* Mic Volume LSB */ + val &= 0x5f; + break; + + case 0x11: /* Line In Volume MSB */ + case 0x13: /* CD Volume MSB */ + case 0x15: /* Video Volume MSB */ + case 0x17: /* Aux In Volume MSB */ + case 0x19: /* PCM Out Volume MSB */ + val &= 0x9f; + break; + + case 0x1a: case 0x1b: /* Record Select */ + val &= 0x07; + break; + + case 0x1c: /* Record Gain LSB */ + val &= 0x0f; + break; + + case 0x1d: /* Record Gain MSB */ + val &= 0x8f; + break; + + case 0x21: /* General Purpose MSB */ + val &= 0x83; + break; + } + + dev->regs[reg] = val; +} + + +void +ac97_codec_reset(void *priv) +{ + ac97_codec_t *dev = (ac97_codec_t *) priv; + + ac97_codec_log("AC97 Codec: reset()\n"); + + memset(dev->regs, 0, sizeof(dev->regs)); + + /* Mute outputs by default. */ + dev->regs[0x02] = dev->regs[0x04] = dev->regs[0x06] = 0x80; + + /* Flag codec as ready. */ + dev->regs[0x26] = 0x0f; + + /* Set Vendor ID. */ + dev->regs[0x7c] = dev->id >> 16; + dev->regs[0x7d] = dev->id >> 24; + dev->regs[0x7e] = dev->id >> 8; + dev->regs[0x7f] = dev->id; +} + + +static void * +ac97_codec_init(const device_t *info) +{ + ac97_codec_t *dev = malloc(sizeof(ac97_codec_t)); + memset(dev, 0, sizeof(ac97_codec_t)); + + dev->id = info->local; + ac97_codec_log("AC97 Codec: init(%c%c%c%02X)\n", (dev->id >> 24) & 0xff, (dev->id >> 16) & 0xff, (dev->id >> 8) & 0xff, dev->id & 0xff); + + /* Associate this codec to the current controller. */ + if (!ac97_codec || (ac97_codec_count <= 0)) { + fatal("AC97 Codec: No controller to associate codec"); + return NULL; + } + *ac97_codec = dev; + if (--ac97_codec_count == 0) + ac97_codec = NULL; + else + ac97_codec += sizeof(ac97_codec_t *); + + return dev; +} + + +static void +ac97_codec_close(void *priv) +{ + ac97_codec_t *dev = (ac97_codec_t *) priv; + + ac97_codec_log("AC97 Codec: close()\n"); + + free(dev); +} + + +const device_t alc100_device = +{ + "Avance Logic ALC100", + DEVICE_AC97, + AC97_CODEC_ALC100, + ac97_codec_init, ac97_codec_close, ac97_codec_reset, + { NULL }, + NULL, + NULL, + NULL +}; diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c new file mode 100644 index 000000000..3e83e20c2 --- /dev/null +++ b/src/sound/snd_ac97_via.c @@ -0,0 +1,638 @@ +/* + * 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. + * + * VIA AC'97 audio controller emulation. + * + * + * + * Authors: RichardG, + * + * Copyright 2021 RichardG. + */ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/mem.h> +#include <86box/pic.h> +#include <86box/timer.h> +#include <86box/pci.h> +#include <86box/sound.h> +#include <86box/snd_ac97.h> + +#define SGD_UNPAUSED (dev->sgd_regs[0x00] & 0xc4) == 0x80 + + +typedef struct { + uint16_t audio_sgd_base, audio_codec_base, modem_sgd_base, modem_codec_base; + uint8_t sgd_regs[256], irq_stuck; + int slot, irq_pin, losticount; + uint64_t sgd_entry; + uint32_t sgd_entry_ptr, sgd_sample_ptr; + int32_t sgd_sample_count; + + ac97_codec_t *codec[4]; + + pc_timer_t timer_count; + uint64_t timer_latch; + int16_t out_l, out_r; + double cd_vol_l, cd_vol_r; + int16_t buffer[SOUNDBUFLEN * 2]; + int pos; +} ac97_via_t; + +#define ENABLE_AC97_VIA_LOG 1 +#ifdef ENABLE_AC97_VIA_LOG +int ac97_via_do_log = ENABLE_AC97_VIA_LOG; + +static void +ac97_via_log(const char *fmt, ...) +{ + va_list ap; + + if (ac97_via_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +#define ac97_via_log(fmt, ...) +#endif + + +static void ac97_via_poll(void *priv); + + +void +ac97_via_set_slot(void *priv, int slot, int irq_pin) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + + ac97_via_log("AC97 VIA: set_slot(%d, %d)\n", slot, irq_pin); + + dev->slot = slot; + dev->irq_pin = irq_pin; +} + + +uint8_t +ac97_via_read_status(void *priv, uint8_t modem) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t ret = 0x00; + + /* Flag codecs as ready if present. */ + for (uint8_t i = 0; i <= 1; i++) { + if (dev->codec[(modem << 1) | i]) + ret |= 0x01 << (i << 1); + } + + ac97_via_log("AC97 VIA %d: read_status() = %02X\n", modem, ret); + + return ret; +} + + +static void +ac97_via_sgd_startstop(ac97_via_t *dev) +{ + /* Start polling timer if SGD is unpaused. */ +#if 0 + if (SGD_UNPAUSED) { + ac97_via_log("AC97 VIA: Starting SGD at %08X\n", dev->sgd_entry_ptr); + timer_set_delay_u64(&dev->timer_count, dev->timer_latch); + } else { + ac97_via_log("AC97 VIA: Stopping SGD\n"); + timer_disable(&dev->timer_count); + dev->out_l = dev->out_r = 0; + } +#endif +} + + +static void +ac97_via_sgd_block_start(ac97_via_t *dev) +{ + /* Start at first entry. */ + /*if (!dev->sgd_entry_ptr) + dev->sgd_entry_ptr = (dev->sgd_regs[0x07] << 24) | (dev->sgd_regs[0x06] << 16) | (dev->sgd_regs[0x05] << 8) | (dev->sgd_regs[0x04] & 0xfe);*/ + + /* Read entry. */ + dev->sgd_entry = ((uint64_t) mem_readl_phys(dev->sgd_entry_ptr + 4) << 32ULL) | (uint64_t) mem_readl_phys(dev->sgd_entry_ptr); + if (dev->sgd_entry == 0xffffffffffffffffULL) + fatal("AC97 VIA: Invalid SGD entry at %08X\n", dev->sgd_entry_ptr); + + /* Set sample pointer and count. */ + dev->sgd_sample_ptr = dev->sgd_entry & 0xffffffff; + dev->sgd_sample_count = (dev->sgd_entry >> 32) & 0xffffff; + + ac97_via_log("AC97 VIA: Starting SGD block at %08X entry %08X%08X (start %08X len %06X) losticount %d\n", + dev->sgd_entry_ptr, mem_readl_phys(dev->sgd_entry_ptr + 4), mem_readl_phys(dev->sgd_entry_ptr), dev->sgd_sample_ptr, dev->sgd_sample_count, dev->losticount); +} + + +uint8_t +ac97_via_sgd_read(uint16_t addr, void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base; + addr &= 0xff; + uint8_t ret = 0x00; + + switch (addr) { + case 0x04: + ret = dev->sgd_entry_ptr; + break; + + case 0x05: + ret = dev->sgd_entry_ptr >> 8; + break; + + case 0x06: + ret = dev->sgd_entry_ptr >> 16; + break; + + case 0x07: + ret = dev->sgd_entry_ptr >> 24; + /*pclog("sgd state %02X unpaused %d rct %02X\n", dev->sgd_regs[0x00], SGD_UNPAUSED, dev->sgd_regs[0x02]); + pci_clear_irq(dev->slot, dev->irq_pin);*/ + break; + + case 0x0c: + ret = dev->sgd_sample_count; + break; + + case 0x0d: + ret = dev->sgd_sample_count >> 8; + break; + + case 0x0e: + ret = dev->sgd_sample_count >> 16; + break; + + case 0x84: + ret |= (dev->sgd_regs[0x00] & 0x01); + ret |= (dev->sgd_regs[0x10] & 0x01) << 1; + ret |= (dev->sgd_regs[0x20] & 0x01) << 2; + + ret |= (dev->sgd_regs[0x00] & 0x02) << 3; + ret |= (dev->sgd_regs[0x10] & 0x02) << 4; + ret |= (dev->sgd_regs[0x20] & 0x02) << 5; + break; + + case 0x85: + ret |= (dev->sgd_regs[0x00] & 0x04) >> 2; + ret |= (dev->sgd_regs[0x10] & 0x04) >> 1; + ret |= (dev->sgd_regs[0x20] & 0x04); + + ret |= (dev->sgd_regs[0x00] & 0x80) >> 3; + ret |= (dev->sgd_regs[0x10] & 0x80) >> 2; + ret |= (dev->sgd_regs[0x20] & 0x80) >> 1; + break; + + case 0x86: + ret |= (dev->sgd_regs[0x40] & 0x01); + ret |= (dev->sgd_regs[0x50] & 0x01) << 1; + + ret |= (dev->sgd_regs[0x40] & 0x02) << 3; + ret |= (dev->sgd_regs[0x50] & 0x02) << 4; + break; + + case 0x87: + ret |= (dev->sgd_regs[0x40] & 0x04) >> 2; + ret |= (dev->sgd_regs[0x50] & 0x04) >> 1; + + ret |= (dev->sgd_regs[0x40] & 0x80) >> 3; + ret |= (dev->sgd_regs[0x50] & 0x80) >> 2; + break; + + default: + ret = dev->sgd_regs[addr]; + break; + } + + ac97_via_log("AC97 VIA %d: sgd_read(%02X) = %02X\n", modem, addr, ret); + + return ret; +} + + +void +ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base, i; + ac97_codec_t *codec; + addr &= 0xff; + + ac97_via_log("AC97 VIA %d: sgd_write(%02X, %02X)\n", modem, addr, val); + + /* Check function-specific read only registers. */ + if ((addr >= (modem ? 0x00 : 0x40)) && (addr < (modem ? 0x40 : 0x60))) + return; + if (addr >= (modem ? 0x90 : 0x88)) + return; + + /* Check read-only registers for each SGD channel. */ + if (!(addr & 0x80)) { + switch (addr & 0xf) { + case 0x0: + /* Clear RWC status bits. */ + for (i = 0x01; i <= 0x04; i <<= 1) { + if (val & i) + dev->sgd_regs[addr] &= ~i; + } + + if (addr == 0x00) { + if (!(dev->sgd_regs[0x00] & (dev->sgd_regs[0x02] & 0x03))) { + ac97_via_log("AC97 VIA: Clearing IRQ (iflags %02X)\n", dev->sgd_regs[0x00] & (dev->sgd_regs[0x02] & 0x03)); + pci_clear_irq(dev->slot, dev->irq_pin); + dev->irq_stuck = 0; + } + + /* Resume SGD if requested. */ + if (val & 0x04) + ac97_via_sgd_startstop(dev); + } + + /* fall-through */ + + case 0x3: case 0x8 ... 0xf: + return; + } + } + + switch (addr) { + case 0x30 ... 0x3f: + case 0x60 ... 0x7f: + /* Read-only registers. */ + return; + + case 0x01: + /* Start SGD if requested. */ + if (val & 0x80) { + if (dev->sgd_regs[0x00] & 0x80) { + /* Queue SGD trigger. */ + dev->sgd_regs[0x00] |= 0x08; + } else { + /* Start SGD immediately. */ + dev->sgd_regs[0x00] |= 0x80; + dev->sgd_regs[0x00] &= ~0x44; + + dev->sgd_entry = 0; + dev->sgd_entry_ptr = (dev->sgd_regs[0x07] << 24) | (dev->sgd_regs[0x06] << 16) | (dev->sgd_regs[0x05] << 8) | (dev->sgd_regs[0x04] & 0xfe); + } + } + /* Stop SGD if requested. */ + if (val & 0x40) { + dev->sgd_regs[0x00] &= ~0x88; + } + + val &= 0x04; + + /* (Un)pause SGD if requested. */ + if (val & 0x04) + dev->sgd_regs[0x00] |= 0x40; + else + dev->sgd_regs[0x00] &= ~0x40; + + ac97_via_sgd_startstop(dev); + break; + + case 0x82: + /* Determine the selected codec. */ + i = !!(dev->sgd_regs[0x83] & 0x40); + codec = dev->codec[(modem << 1) | i]; + + /* Read from or write to codec. */ + if (codec) { + if (val & 0x80) { + val <<= 1; + dev->sgd_regs[0x80] = ac97_codec_read(codec, val); + dev->sgd_regs[0x81] = ac97_codec_read(codec, val | 1); + } else { + val <<= 1; + ac97_codec_write(codec, val, dev->sgd_regs[0x80]); + ac97_codec_write(codec, val | 1, dev->sgd_regs[0x81]); + } + } else if (val & 0x80) { + /* Unknown behavior when reading from a non-existent codec. */ + dev->sgd_regs[0x80] = dev->sgd_regs[0x81] = 0xff; + } + + /* Flag data/status/index for this codec as valid. */ + dev->sgd_regs[0x83] |= 0x02 << (i * 2); + break; + + case 0x83: + val &= 0xca; + + /* Clear RWC bits. */ + for (i = 0x02; i <= 0x08; i <<= 2) { +#if 0 /* race condition with Linux clearing bits and starting SGD on the same dword write */ + if (val & i) + val &= ~i; + else + val |= dev->sgd_regs[addr] & i; +#else + val |= i; +#endif + } + break; + } + + dev->sgd_regs[addr] = val; +} + + +void +ac97_via_remap_audio_sgd(void *priv, uint16_t new_io_base, uint8_t enable) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + + if (dev->audio_sgd_base) + io_removehandler(dev->audio_sgd_base, 256, ac97_via_sgd_read, NULL, NULL, ac97_via_sgd_write, NULL, NULL, dev); + + dev->audio_sgd_base = new_io_base; + + if (dev->audio_sgd_base && enable) + io_sethandler(dev->audio_sgd_base, 256, ac97_via_sgd_read, NULL, NULL, ac97_via_sgd_write, NULL, NULL, dev); +} + + +void +ac97_via_remap_modem_sgd(void *priv, uint16_t new_io_base, uint8_t enable) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + + if (dev->modem_sgd_base) + io_removehandler(dev->modem_sgd_base, 256, ac97_via_sgd_read, NULL, NULL, ac97_via_sgd_write, NULL, NULL, dev); + + dev->modem_sgd_base = new_io_base; + + if (dev->modem_sgd_base && enable) + io_sethandler(dev->modem_sgd_base, 256, ac97_via_sgd_read, NULL, NULL, ac97_via_sgd_write, NULL, NULL, dev); +} + + +uint8_t +ac97_via_codec_read(uint16_t addr, void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t modem = (addr & 0xff00) == dev->modem_codec_base; + addr &= 0xff; + uint8_t ret = 0xff; + + /* Bit 7 selects secondary codec. */ + ac97_codec_t *codec = dev->codec[(modem << 1) | (addr >> 7)]; + if (codec) + ret = ac97_codec_read(codec, addr & 0x7f); + + ac97_via_log("AC97 VIA %d: codec_read(%02X) = %02X\n", modem, addr, ret); + + return ret; +} + + +void +ac97_via_codec_write(uint16_t addr, uint8_t val, void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t modem = (addr & 0xff00) == dev->modem_codec_base; + addr &= 0xff; + + ac97_via_log("AC97 VIA %d: codec_write(%02X, %02X)\n", modem, addr, val); + + /* Bit 7 selects secondary codec. */ + ac97_codec_t *codec = dev->codec[(modem << 1) | (addr >> 7)]; + if (codec) + ac97_codec_write(codec, addr, val); +} + + +void +ac97_via_remap_audio_codec(void *priv, uint16_t new_io_base, uint8_t enable) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + + if (dev->audio_codec_base) + io_removehandler(dev->audio_codec_base, 256, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); + + dev->audio_codec_base = new_io_base; + + if (dev->audio_codec_base && enable) + io_sethandler(dev->audio_codec_base, 256, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); +} + + +void +ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t enable) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + + if (dev->modem_codec_base) + io_removehandler(dev->modem_codec_base, 256, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); + + dev->modem_codec_base = new_io_base; + + if (dev->modem_codec_base && enable) + io_sethandler(dev->modem_codec_base, 256, ac97_via_codec_read, NULL, NULL, ac97_via_codec_write, NULL, NULL, dev); +} + + +static void +ac97_via_update(ac97_via_t *dev) +{ + for (; dev->pos < sound_pos_global; dev->pos++) { + dev->buffer[dev->pos*2] = dev->out_l; + dev->buffer[dev->pos*2 + 1] = dev->out_r; + } +} + + +static void +ac97_via_poll(void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t irq = 0; + + timer_advance_u64(&dev->timer_count, dev->timer_latch); + + ac97_via_update(dev); + + /* Read only if SGD is active and not paused. */ + if (SGD_UNPAUSED) { + if (!dev->sgd_entry) { + /* Move on to the next block. */ + ac97_via_sgd_block_start(dev); + } + + switch (dev->sgd_regs[0x02] & 0x30) { + case 0x00: /* Mono, 8-bit PCM */ + dev->out_l = dev->out_r = (mem_readb_phys(dev->sgd_sample_ptr++) ^ 0x80) * 256; + dev->sgd_sample_count--; + break; + + case 0x10: /* Stereo, 8-bit PCM */ + dev->out_l = (mem_readb_phys(dev->sgd_sample_ptr++) ^ 0x80) * 256; + dev->out_r = (mem_readb_phys(dev->sgd_sample_ptr++) ^ 0x80) * 256; + dev->sgd_sample_count -= 2; + break; + + case 0x20: /* Mono, 16-bit PCM */ + dev->out_l = dev->out_r = mem_readw_phys(dev->sgd_sample_ptr); + dev->sgd_sample_ptr += 2; + dev->sgd_sample_count -= 2; + break; + + case 0x30: /* Stereo, 16-bit PCM */ + dev->out_l = mem_readw_phys(dev->sgd_sample_ptr); + dev->sgd_sample_ptr += 2; + dev->out_r = mem_readw_phys(dev->sgd_sample_ptr); + dev->sgd_sample_ptr += 2; + dev->sgd_sample_count -= 4; + break; + } + + /* Check if we've hit the end of this block. */ + if (dev->sgd_sample_count <= 0) { + ac97_via_log("AC97 VIA: Ending SGD block"); + + /* Move on to the next block on the next poll. */ + dev->sgd_entry_ptr += 8; + + if (dev->sgd_entry & 0x2000000000000000ULL) { + ac97_via_log(" with STOP"); + dev->sgd_regs[0x00] |= 0x04; + } + if (dev->sgd_entry & 0x4000000000000000ULL) { + ac97_via_log(" with FLAG"); + dev->sgd_regs[0x00] |= 0x01; + + /* Pause SGD. */ + dev->sgd_regs[0x00] |= 0x04; + + /* Fire interrupt if requested. */ + if (dev->sgd_regs[0x02] & 0x01) + ac97_via_log(" interrupt"); + } + if (dev->sgd_entry & 0x8000000000000000ULL) { + ac97_via_log(" with EOL"); + dev->sgd_regs[0x00] |= 0x02; + + /* Fire interrupt if requested. */ + if (dev->sgd_regs[0x02] & 0x02) + ac97_via_log(" interrupt"); + + /* Restart SGD if a trigger is queued or auto-start is enabled. */ + if ((dev->sgd_regs[0x00] & 0x08) || (dev->sgd_regs[0x02] & 0x80)) { + ac97_via_log(" restart\n"); + dev->sgd_regs[0x00] &= ~0x08; + + dev->sgd_entry_ptr = (dev->sgd_regs[0x07] << 24) | (dev->sgd_regs[0x06] << 16) | (dev->sgd_regs[0x05] << 8) | (dev->sgd_regs[0x04] & 0xfe); + } else { + ac97_via_log(" finish\n"); + dev->sgd_regs[0x00] &= ~0x80; + } + } else { + ac97_via_log("\n"); + } + + dev->sgd_entry = dev->sgd_sample_count = 0; + } + } else { + dev->out_l = dev->out_r = 0; + dev->cd_vol_l = dev->cd_vol_r = 0; + } + + if (dev->sgd_regs[0x00] & (dev->sgd_regs[0x02] & 0x03)) { + ac97_via_log("AC97 VIA: Setting IRQ (iflags %02X stuck %d)\n", dev->sgd_regs[0x00] & (dev->sgd_regs[0x02] & 0x03), dev->irq_stuck); + if (dev->irq_stuck) { + dev->losticount++; + pci_clear_irq(dev->slot, dev->irq_pin); + } else { + pci_set_irq(dev->slot, dev->irq_pin); + } + dev->irq_stuck = !dev->irq_stuck; + } +} + + +static void +ac97_via_get_buffer(int32_t *buffer, int len, void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + + ac97_via_update(dev); + + for (int c = 0; c < len * 2; c++) { + buffer[c] += dev->buffer[c]; + } + + dev->pos = 0; +} + + +static void +ac97_via_speed_changed(void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + dev->timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / 48000.0)); +} + + +static void * +ac97_via_init(const device_t *info) +{ + ac97_via_t *dev = malloc(sizeof(ac97_via_t)); + memset(dev, 0, sizeof(ac97_via_t)); + + ac97_via_log("AC97 VIA: init()\n"); + + ac97_codec = &dev->codec[0]; + ac97_modem_codec = &dev->codec[2]; + ac97_codec_count = ac97_modem_codec_count = 2; + + timer_add(&dev->timer_count, ac97_via_poll, dev, 0); + ac97_via_speed_changed(dev); + timer_advance_u64(&dev->timer_count, dev->timer_latch); + + sound_add_handler(ac97_via_get_buffer, dev); + + return dev; +} + + +static void +ac97_via_close(void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + + ac97_via_log("AC97 VIA: close()\n"); + + free(dev); +} + + +const device_t ac97_via_device = +{ + "VIA VT82C686 AC97 Controller", + DEVICE_PCI, + 0, + ac97_via_init, ac97_via_close, NULL, + { NULL }, + ac97_via_speed_changed, + NULL, + NULL +}; diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 7ea1deb65..03a258f30 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include <86box/86box.h> #include <86box/io.h> #include <86box/timer.h> diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 3fa401f1e..47d5638bf 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -724,6 +724,7 @@ SNDOBJ := sound.o \ snd_pssj.o \ snd_lpt_dac.o snd_lpt_dss.o \ snd_adlib.o snd_adlibgold.o snd_ad1848.o snd_audiopci.o \ + snd_ac97_codec.o snd_ac97_via.o \ snd_azt2316a.o snd_cs423x.o \ snd_cms.o \ snd_gus.o \ From 2fa909ab91d3e0e46d0801d87c2a9d30d13e4a07 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 11 Jul 2021 17:04:41 -0300 Subject: [PATCH 04/52] Revert to the code which was working on XP --- src/sound/snd_ac97_via.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 3e83e20c2..b8d92fe8a 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -125,8 +125,8 @@ static void ac97_via_sgd_block_start(ac97_via_t *dev) { /* Start at first entry. */ - /*if (!dev->sgd_entry_ptr) - dev->sgd_entry_ptr = (dev->sgd_regs[0x07] << 24) | (dev->sgd_regs[0x06] << 16) | (dev->sgd_regs[0x05] << 8) | (dev->sgd_regs[0x04] & 0xfe);*/ + if (!dev->sgd_entry_ptr) + dev->sgd_entry_ptr = (dev->sgd_regs[0x07] << 24) | (dev->sgd_regs[0x06] << 16) | (dev->sgd_regs[0x05] << 8) | (dev->sgd_regs[0x04] & 0xfe); /* Read entry. */ dev->sgd_entry = ((uint64_t) mem_readl_phys(dev->sgd_entry_ptr + 4) << 32ULL) | (uint64_t) mem_readl_phys(dev->sgd_entry_ptr); @@ -291,7 +291,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) dev->sgd_regs[0x00] &= ~0x44; dev->sgd_entry = 0; - dev->sgd_entry_ptr = (dev->sgd_regs[0x07] << 24) | (dev->sgd_regs[0x06] << 16) | (dev->sgd_regs[0x05] << 8) | (dev->sgd_regs[0x04] & 0xfe); + dev->sgd_entry_ptr = 0; } } /* Stop SGD if requested. */ @@ -465,7 +465,6 @@ static void ac97_via_poll(void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; - uint8_t irq = 0; timer_advance_u64(&dev->timer_count, dev->timer_latch); @@ -540,7 +539,7 @@ ac97_via_poll(void *priv) ac97_via_log(" restart\n"); dev->sgd_regs[0x00] &= ~0x08; - dev->sgd_entry_ptr = (dev->sgd_regs[0x07] << 24) | (dev->sgd_regs[0x06] << 16) | (dev->sgd_regs[0x05] << 8) | (dev->sgd_regs[0x04] & 0xfe); + dev->sgd_entry_ptr = 0; } else { ac97_via_log(" finish\n"); dev->sgd_regs[0x00] &= ~0x80; From 5bce2f09c7c7e7f2d3b3a816e4db831e820bdced Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 11 Jul 2021 17:12:48 -0300 Subject: [PATCH 05/52] Fix small oversight on codec shadow write --- src/sound/snd_ac97_via.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index b8d92fe8a..85e18b71b 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -417,7 +417,7 @@ ac97_via_codec_write(uint16_t addr, uint8_t val, void *priv) /* Bit 7 selects secondary codec. */ ac97_codec_t *codec = dev->codec[(modem << 1) | (addr >> 7)]; if (codec) - ac97_codec_write(codec, addr, val); + ac97_codec_write(codec, addr & 0x7f, val); } From ff1a55d08d3a8be7160860971c4a6e48f51757eb Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 13 Jul 2021 00:53:26 -0300 Subject: [PATCH 06/52] More AC97, now with VIA kinda sorta working and ES1371 --- src/chipset/via_pipc.c | 4 + src/include/86box/snd_ac97.h | 1 + src/pci.c | 2 +- src/sound/snd_ac97_codec.c | 15 +- src/sound/snd_ac97_via.c | 610 +++++++++++++++++++---------------- src/sound/snd_audiopci.c | 86 ++--- 6 files changed, 402 insertions(+), 316 deletions(-) diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 9ad32deca..95e900b5e 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -1125,6 +1125,10 @@ pipc_write(int func, int addr, uint8_t val, void *priv) gameport_remap(dev->gameport, (dev->ac97_regs[0][0x42] & 0x08) ? ((dev->ac97_regs[0][0x4b] << 8) | dev->ac97_regs[0][0x4a]) : 0); break; + case 0x41: + dev->ac97_regs[func][addr] = val; + break; + case 0x43: dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; break; diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index 8d66cdea4..e0345227a 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -41,6 +41,7 @@ extern ac97_codec_t **ac97_codec, **ac97_modem_codec; extern int ac97_codec_count, ac97_modem_codec_count; extern const device_t alc100_device; +extern const device_t cs4297a_device; extern const device_t ac97_via_device; #endif diff --git a/src/pci.c b/src/pci.c index a4272e6bd..5f1c48f50 100644 --- a/src/pci.c +++ b/src/pci.c @@ -73,7 +73,7 @@ static int trc_reg = 0; static void pci_reset_regs(void); -#define ENABLE_PCI_LOG 1 + #ifdef ENABLE_PCI_LOG int pci_do_log = ENABLE_PCI_LOG; diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index e96795011..f97b1c551 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -29,7 +29,8 @@ enum { - AC97_CODEC_ALC100 = AC97_CODEC_ID('A', 'L', 'C', 0x20) + AC97_CODEC_ALC100 = AC97_CODEC_ID('A', 'L', 'C', 0x20), + AC97_CODEC_CS4297A = AC97_CODEC_ID('C', 'R', 'Y', 0x11) }; #define ENABLE_AC97_CODEC_LOG 1 @@ -225,3 +226,15 @@ const device_t alc100_device = NULL, NULL }; + +const device_t cs4297a_device = +{ + "Crystal CS4297A", + DEVICE_AC97, + AC97_CODEC_CS4297A, + ac97_codec_init, ac97_codec_close, ac97_codec_reset, + { NULL }, + NULL, + NULL, + NULL +}; diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 85e18b71b..0ee33b94c 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -30,21 +30,29 @@ #include <86box/sound.h> #include <86box/snd_ac97.h> -#define SGD_UNPAUSED (dev->sgd_regs[0x00] & 0xc4) == 0x80 - typedef struct { + uint8_t id; + struct _ac97_via_ *dev; + + uint64_t entry; + uint32_t entry_ptr, sample_ptr, fifo_pos, fifo_end; + int32_t sample_count; + uint8_t fifo[32]; + + pc_timer_t timer; +} ac97_via_sgd_t; + +typedef struct _ac97_via_ { uint16_t audio_sgd_base, audio_codec_base, modem_sgd_base, modem_codec_base; uint8_t sgd_regs[256], irq_stuck; - int slot, irq_pin, losticount; - uint64_t sgd_entry; - uint32_t sgd_entry_ptr, sgd_sample_ptr; - int32_t sgd_sample_count; + int slot, irq_pin; - ac97_codec_t *codec[4]; + ac97_codec_t *codec[2][2]; + ac97_via_sgd_t sgd[6]; pc_timer_t timer_count; - uint64_t timer_latch; + uint64_t timer_latch, timer_fifo_latch; int16_t out_l, out_r; double cd_vol_l, cd_vol_r; int16_t buffer[SOUNDBUFLEN * 2]; @@ -54,6 +62,7 @@ typedef struct { #define ENABLE_AC97_VIA_LOG 1 #ifdef ENABLE_AC97_VIA_LOG int ac97_via_do_log = ENABLE_AC97_VIA_LOG; +unsigned int ac97_via_lost_irqs = 0; static void ac97_via_log(const char *fmt, ...) @@ -71,7 +80,7 @@ ac97_via_log(const char *fmt, ...) #endif -static void ac97_via_poll(void *priv); +static void ac97_via_sgd_process(void *priv); void @@ -94,7 +103,7 @@ ac97_via_read_status(void *priv, uint8_t modem) /* Flag codecs as ready if present. */ for (uint8_t i = 0; i <= 1; i++) { - if (dev->codec[(modem << 1) | i]) + if (dev->codec[modem][i]) ret |= 0x01 << (i << 1); } @@ -105,40 +114,32 @@ ac97_via_read_status(void *priv, uint8_t modem) static void -ac97_via_sgd_startstop(ac97_via_t *dev) +ac97_via_update_irqs(ac97_via_t *dev, uint8_t iflag_clear) { - /* Start polling timer if SGD is unpaused. */ -#if 0 - if (SGD_UNPAUSED) { - ac97_via_log("AC97 VIA: Starting SGD at %08X\n", dev->sgd_entry_ptr); - timer_set_delay_u64(&dev->timer_count, dev->timer_latch); - } else { - ac97_via_log("AC97 VIA: Stopping SGD\n"); - timer_disable(&dev->timer_count); - dev->out_l = dev->out_r = 0; - } + /* Check interrupt flags on all SGDs. */ + for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { + if (dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03)) { + ac97_via_log("AC97 VIA: Setting IRQ (sgd %d iflags %02X stuck %d)\n", + i, dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03), dev->irq_stuck); + + if (dev->irq_stuck && !iflag_clear) { +#ifdef ENABLE_AC97_VIA_LOG + ac97_via_lost_irqs++; #endif -} + pci_clear_irq(dev->slot, dev->irq_pin); + } else { + pci_set_irq(dev->slot, dev->irq_pin); + } + dev->irq_stuck = !dev->irq_stuck; + return; + } + } -static void -ac97_via_sgd_block_start(ac97_via_t *dev) -{ - /* Start at first entry. */ - if (!dev->sgd_entry_ptr) - dev->sgd_entry_ptr = (dev->sgd_regs[0x07] << 24) | (dev->sgd_regs[0x06] << 16) | (dev->sgd_regs[0x05] << 8) | (dev->sgd_regs[0x04] & 0xfe); - - /* Read entry. */ - dev->sgd_entry = ((uint64_t) mem_readl_phys(dev->sgd_entry_ptr + 4) << 32ULL) | (uint64_t) mem_readl_phys(dev->sgd_entry_ptr); - if (dev->sgd_entry == 0xffffffffffffffffULL) - fatal("AC97 VIA: Invalid SGD entry at %08X\n", dev->sgd_entry_ptr); - - /* Set sample pointer and count. */ - dev->sgd_sample_ptr = dev->sgd_entry & 0xffffffff; - dev->sgd_sample_count = (dev->sgd_entry >> 32) & 0xffffff; - - ac97_via_log("AC97 VIA: Starting SGD block at %08X entry %08X%08X (start %08X len %06X) losticount %d\n", - dev->sgd_entry_ptr, mem_readl_phys(dev->sgd_entry_ptr + 4), mem_readl_phys(dev->sgd_entry_ptr), dev->sgd_sample_ptr, dev->sgd_sample_count, dev->losticount); + /* No interrupt pending. */ + //ac97_via_log("AC97 VIA: Clearing IRQ\n"); + pci_clear_irq(dev->slot, dev->irq_pin); + dev->irq_stuck = 0; } @@ -148,78 +149,86 @@ ac97_via_sgd_read(uint16_t addr, void *priv) ac97_via_t *dev = (ac97_via_t *) priv; uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base; addr &= 0xff; - uint8_t ret = 0x00; + uint8_t ret; - switch (addr) { - case 0x04: - ret = dev->sgd_entry_ptr; - break; + if (!(addr & 0x80)) { + /* Process SGD channel registers. */ + switch (addr & 0xf) { + case 0x4: + ret = dev->sgd[addr >> 4].entry_ptr; + break; - case 0x05: - ret = dev->sgd_entry_ptr >> 8; - break; + case 0x5: + ret = dev->sgd[addr >> 4].entry_ptr >> 8; + break; - case 0x06: - ret = dev->sgd_entry_ptr >> 16; - break; + case 0x6: + ret = dev->sgd[addr >> 4].entry_ptr >> 16; + break; - case 0x07: - ret = dev->sgd_entry_ptr >> 24; - /*pclog("sgd state %02X unpaused %d rct %02X\n", dev->sgd_regs[0x00], SGD_UNPAUSED, dev->sgd_regs[0x02]); - pci_clear_irq(dev->slot, dev->irq_pin);*/ - break; + case 0x7: + ret = dev->sgd[addr >> 4].entry_ptr >> 24; + break; - case 0x0c: - ret = dev->sgd_sample_count; - break; + case 0xc: + ret = dev->sgd[addr >> 4].sample_count; + break; - case 0x0d: - ret = dev->sgd_sample_count >> 8; - break; + case 0xd: + ret = dev->sgd[addr >> 4].sample_count >> 8; + break; - case 0x0e: - ret = dev->sgd_sample_count >> 16; - break; + case 0xe: + ret = dev->sgd[addr >> 4].sample_count >> 16; + break; - case 0x84: - ret |= (dev->sgd_regs[0x00] & 0x01); - ret |= (dev->sgd_regs[0x10] & 0x01) << 1; - ret |= (dev->sgd_regs[0x20] & 0x01) << 2; + default: + ret = dev->sgd_regs[addr]; + break; + } + } else { + /* Process regular registers. */ + switch (addr) { + case 0x84: + ret = (dev->sgd_regs[0x00] & 0x01); + ret |= (dev->sgd_regs[0x10] & 0x01) << 1; + ret |= (dev->sgd_regs[0x20] & 0x01) << 2; - ret |= (dev->sgd_regs[0x00] & 0x02) << 3; - ret |= (dev->sgd_regs[0x10] & 0x02) << 4; - ret |= (dev->sgd_regs[0x20] & 0x02) << 5; - break; + ret |= (dev->sgd_regs[0x00] & 0x02) << 3; + ret |= (dev->sgd_regs[0x10] & 0x02) << 4; + ret |= (dev->sgd_regs[0x20] & 0x02) << 5; + break; - case 0x85: - ret |= (dev->sgd_regs[0x00] & 0x04) >> 2; - ret |= (dev->sgd_regs[0x10] & 0x04) >> 1; - ret |= (dev->sgd_regs[0x20] & 0x04); + case 0x85: + ret = (dev->sgd_regs[0x00] & 0x04) >> 2; + ret |= (dev->sgd_regs[0x10] & 0x04) >> 1; + ret |= (dev->sgd_regs[0x20] & 0x04); - ret |= (dev->sgd_regs[0x00] & 0x80) >> 3; - ret |= (dev->sgd_regs[0x10] & 0x80) >> 2; - ret |= (dev->sgd_regs[0x20] & 0x80) >> 1; - break; + ret |= (dev->sgd_regs[0x00] & 0x80) >> 3; + ret |= (dev->sgd_regs[0x10] & 0x80) >> 2; + ret |= (dev->sgd_regs[0x20] & 0x80) >> 1; + break; - case 0x86: - ret |= (dev->sgd_regs[0x40] & 0x01); - ret |= (dev->sgd_regs[0x50] & 0x01) << 1; + case 0x86: + ret = (dev->sgd_regs[0x40] & 0x01); + ret |= (dev->sgd_regs[0x50] & 0x01) << 1; - ret |= (dev->sgd_regs[0x40] & 0x02) << 3; - ret |= (dev->sgd_regs[0x50] & 0x02) << 4; - break; + ret |= (dev->sgd_regs[0x40] & 0x02) << 3; + ret |= (dev->sgd_regs[0x50] & 0x02) << 4; + break; - case 0x87: - ret |= (dev->sgd_regs[0x40] & 0x04) >> 2; - ret |= (dev->sgd_regs[0x50] & 0x04) >> 1; + case 0x87: + ret = (dev->sgd_regs[0x40] & 0x04) >> 2; + ret |= (dev->sgd_regs[0x50] & 0x04) >> 1; - ret |= (dev->sgd_regs[0x40] & 0x80) >> 3; - ret |= (dev->sgd_regs[0x50] & 0x80) >> 2; - break; + ret |= (dev->sgd_regs[0x40] & 0x80) >> 3; + ret |= (dev->sgd_regs[0x50] & 0x80) >> 2; + break; - default: - ret = dev->sgd_regs[addr]; - break; + default: + ret = dev->sgd_regs[addr]; + break; + } } ac97_via_log("AC97 VIA %d: sgd_read(%02X) = %02X\n", modem, addr, ret); @@ -244,8 +253,8 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) if (addr >= (modem ? 0x90 : 0x88)) return; - /* Check read-only registers for each SGD channel. */ if (!(addr & 0x80)) { + /* Process SGD channel registers. */ switch (addr & 0xf) { case 0x0: /* Clear RWC status bits. */ @@ -254,102 +263,102 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) dev->sgd_regs[addr] &= ~i; } - if (addr == 0x00) { - if (!(dev->sgd_regs[0x00] & (dev->sgd_regs[0x02] & 0x03))) { - ac97_via_log("AC97 VIA: Clearing IRQ (iflags %02X)\n", dev->sgd_regs[0x00] & (dev->sgd_regs[0x02] & 0x03)); - pci_clear_irq(dev->slot, dev->irq_pin); - dev->irq_stuck = 0; + ac97_via_update_irqs(dev, 1); + + return; + + case 0x1: + /* Start SGD if requested. */ + if (val & 0x80) { + if (dev->sgd_regs[addr & 0xf0] & 0x80) { + /* Queue SGD trigger. */ + dev->sgd_regs[addr & 0xf0] |= 0x08; + } else { + /* Start SGD immediately. */ + dev->sgd_regs[addr & 0xf0] |= 0x80; + dev->sgd_regs[addr & 0xf0] &= ~0x44; + + /* Start at the specified entry pointer. */ + dev->sgd[addr >> 4].entry = 0; + dev->sgd[addr >> 4].entry_ptr = (dev->sgd_regs[(addr & 0xf0) | 0x7] << 24) | (dev->sgd_regs[(addr & 0xf0) | 0x6] << 16) | (dev->sgd_regs[(addr & 0xf0) | 0x5] << 8) | (dev->sgd_regs[(addr & 0xf0) | 0x4] & 0xfe); + + /* Start the actual SGD process. */ + timer_advance_u64(&dev->sgd[addr >> 4].timer, 0); } - - /* Resume SGD if requested. */ - if (val & 0x04) - ac97_via_sgd_startstop(dev); } + /* Stop SGD if requested. */ + if (val & 0x40) + dev->sgd_regs[addr & 0xf0] &= ~0x88; - /* fall-through */ + val &= 0x04; + + /* (Un)pause SGD if requested. */ + if (val & 0x04) + dev->sgd_regs[addr & 0xf0] |= 0x40; + else + dev->sgd_regs[addr & 0xf0] &= ~0x40; + + break; + + case 0x2: + if (addr & 0x10) + val &= 0xf3; + break; case 0x3: case 0x8 ... 0xf: + /* Read-only registers. */ return; } - } + } else { + /* Process regular registers. */ + switch (addr) { + case 0x30 ... 0x3f: + case 0x60 ... 0x7f: + case 0x84 ... 0x87: + /* Read-only registers. */ + return; - switch (addr) { - case 0x30 ... 0x3f: - case 0x60 ... 0x7f: - /* Read-only registers. */ - return; + case 0x82: + /* Determine the selected codec. */ + i = !!(dev->sgd_regs[0x83] & 0x40); + codec = dev->codec[modem][i]; - case 0x01: - /* Start SGD if requested. */ - if (val & 0x80) { - if (dev->sgd_regs[0x00] & 0x80) { - /* Queue SGD trigger. */ - dev->sgd_regs[0x00] |= 0x08; - } else { - /* Start SGD immediately. */ - dev->sgd_regs[0x00] |= 0x80; - dev->sgd_regs[0x00] &= ~0x44; - - dev->sgd_entry = 0; - dev->sgd_entry_ptr = 0; + /* Read from or write to codec. */ + if (codec) { + if (val & 0x80) { + val <<= 1; + dev->sgd_regs[0x80] = ac97_codec_read(codec, val); + dev->sgd_regs[0x81] = ac97_codec_read(codec, val | 1); + } else { + val <<= 1; + ac97_codec_write(codec, val, dev->sgd_regs[0x80]); + ac97_codec_write(codec, val | 1, dev->sgd_regs[0x81]); + } + } else if (val & 0x80) { + /* Unknown behavior when reading from a non-existent codec. */ + dev->sgd_regs[0x80] = dev->sgd_regs[0x81] = 0xff; } - } - /* Stop SGD if requested. */ - if (val & 0x40) { - dev->sgd_regs[0x00] &= ~0x88; - } - val &= 0x04; + /* Flag data/status/index for this codec as valid. */ + dev->sgd_regs[0x83] |= 0x02 << (i * 2); + break; - /* (Un)pause SGD if requested. */ - if (val & 0x04) - dev->sgd_regs[0x00] |= 0x40; - else - dev->sgd_regs[0x00] &= ~0x40; + case 0x83: + val &= 0xca; - ac97_via_sgd_startstop(dev); - break; - - case 0x82: - /* Determine the selected codec. */ - i = !!(dev->sgd_regs[0x83] & 0x40); - codec = dev->codec[(modem << 1) | i]; - - /* Read from or write to codec. */ - if (codec) { - if (val & 0x80) { - val <<= 1; - dev->sgd_regs[0x80] = ac97_codec_read(codec, val); - dev->sgd_regs[0x81] = ac97_codec_read(codec, val | 1); - } else { - val <<= 1; - ac97_codec_write(codec, val, dev->sgd_regs[0x80]); - ac97_codec_write(codec, val | 1, dev->sgd_regs[0x81]); + /* Clear RWC bits. */ + for (i = 0x02; i <= 0x08; i <<= 2) { + #if 0 /* race condition with Linux clearing bits and starting SGD on the same dword write */ + if (val & i) + val &= ~i; + else + val |= dev->sgd_regs[addr] & i; + #else + val |= i; + #endif } - } else if (val & 0x80) { - /* Unknown behavior when reading from a non-existent codec. */ - dev->sgd_regs[0x80] = dev->sgd_regs[0x81] = 0xff; - } - - /* Flag data/status/index for this codec as valid. */ - dev->sgd_regs[0x83] |= 0x02 << (i * 2); - break; - - case 0x83: - val &= 0xca; - - /* Clear RWC bits. */ - for (i = 0x02; i <= 0x08; i <<= 2) { -#if 0 /* race condition with Linux clearing bits and starting SGD on the same dword write */ - if (val & i) - val &= ~i; - else - val |= dev->sgd_regs[addr] & i; -#else - val |= i; -#endif - } - break; + break; + } } dev->sgd_regs[addr] = val; @@ -395,7 +404,7 @@ ac97_via_codec_read(uint16_t addr, void *priv) uint8_t ret = 0xff; /* Bit 7 selects secondary codec. */ - ac97_codec_t *codec = dev->codec[(modem << 1) | (addr >> 7)]; + ac97_codec_t *codec = dev->codec[modem][addr >> 7]; if (codec) ret = ac97_codec_read(codec, addr & 0x7f); @@ -415,7 +424,7 @@ ac97_via_codec_write(uint16_t addr, uint8_t val, void *priv) ac97_via_log("AC97 VIA %d: codec_write(%02X, %02X)\n", modem, addr, val); /* Bit 7 selects secondary codec. */ - ac97_codec_t *codec = dev->codec[(modem << 1) | (addr >> 7)]; + ac97_codec_t *codec = dev->codec[modem][addr >> 7]; if (codec) ac97_codec_write(codec, addr & 0x7f, val); } @@ -461,109 +470,151 @@ ac97_via_update(ac97_via_t *dev) } +static void +ac97_via_sgd_process(void *priv) +{ + ac97_via_sgd_t *sgd = (ac97_via_sgd_t *) priv; + ac97_via_t *dev = sgd->dev; + + /* Process SGD if active, unless this is Audio Read and there's no room in the FIFO. */ + if (((dev->sgd_regs[sgd->id] & 0xc4) == 0x80) && (sgd->id || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { + /* Move on to the next block if no entry is present. */ + if (!sgd->entry) { + /* Start at first entry if no pointer is present. */ + if (!sgd->entry_ptr) + sgd->entry_ptr = (dev->sgd_regs[sgd->id | 0x7] << 24) | (dev->sgd_regs[sgd->id | 0x6] << 16) | (dev->sgd_regs[sgd->id | 0x5] << 8) | (dev->sgd_regs[sgd->id | 0x4] & 0xfe); + + /* Read entry. */ + sgd->entry = ((uint64_t) mem_readl_phys(sgd->entry_ptr + 4) << 32ULL) | (uint64_t) mem_readl_phys(sgd->entry_ptr); + if (sgd->entry == 0xffffffffffffffffULL) + fatal("AC97 VIA: Invalid SGD %d entry at %08X\n", sgd->id >> 4, sgd->entry_ptr); + + /* Set sample pointer and count. */ + sgd->sample_ptr = sgd->entry & 0xffffffff; + sgd->sample_count = (sgd->entry >> 32) & 0xffffff; + + ac97_via_log("AC97 VIA: Starting SGD %d block at %08X entry %08X%08X (start %08X len %06X) lostirqs %d\n", sgd->id >> 4, sgd->entry_ptr, + mem_readl_phys(sgd->entry_ptr + 4), mem_readl_phys(sgd->entry_ptr), sgd->sample_ptr, sgd->sample_count, ac97_via_lost_irqs); + } + + if (sgd->id & 0x10) { + /* Write channel: read data from FIFO. */ + mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); + } else { + /* Read channel: write data to FIFO. */ + *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)]) = mem_readl_phys(sgd->sample_ptr); + } + sgd->fifo_end += 4; + sgd->sample_ptr += 4; + sgd->sample_count -= 4; + + /* Check if we've hit the end of this block. */ + if (sgd->sample_count <= 0) { + ac97_via_log("AC97 VIA: Ending SGD %d block", sgd->id >> 4); + + /* Move on to the next block on the next run. */ + sgd->entry_ptr += 8; + + if (sgd->entry & 0x2000000000000000ULL) { + ac97_via_log(" with STOP"); + dev->sgd_regs[sgd->id] |= 0x04; + } + + if (sgd->entry & 0x4000000000000000ULL) { + ac97_via_log(" with FLAG"); + + /* Raise FLAG while also pausing SGD. */ + dev->sgd_regs[sgd->id] |= 0x05; + +#ifdef ENABLE_AC97_VIA_LOG + if (dev->sgd_regs[sgd->id | 0x2] & 0x01) + ac97_via_log(" interrupt"); +#endif + } + + if (sgd->entry & 0x8000000000000000ULL) { + ac97_via_log(" with EOL"); + + /* Raise EOL. */ + dev->sgd_regs[sgd->id] |= 0x02; + +#ifdef ENABLE_AC97_VIA_LOG + if (dev->sgd_regs[sgd->id | 0x2] & 0x02) + ac97_via_log(" interrupt"); +#endif + + /* Restart SGD if a trigger is queued or auto-start is enabled. */ + if ((dev->sgd_regs[sgd->id] & 0x08) || (dev->sgd_regs[sgd->id | 0x2] & 0x80)) { + ac97_via_log(" restart"); + + /* Un-queue trigger. */ + dev->sgd_regs[sgd->id] &= ~0x08; + + /* Go back to the starting block. */ + sgd->entry_ptr = 0; + } else { + ac97_via_log(" finish"); + + /* Terminate SGD. */ + dev->sgd_regs[sgd->id] &= ~0x80; + } + } + ac97_via_log("\n"); + + /* Start a new block. */ + sgd->entry = sgd->sample_count = 0; + } + } + + ac97_via_update_irqs(dev, 0); + + /* Continue SGD processing if active or an interrupt is pending. */ + if (dev->sgd_regs[sgd->id] & (0x80 | (dev->sgd_regs[sgd->id | 0x02] & 0x03))) + timer_advance_u64(&sgd->timer, dev->timer_fifo_latch); +} + + static void ac97_via_poll(void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; + ac97_via_sgd_t *sgd = &dev->sgd[0]; /* Audio Read */ timer_advance_u64(&dev->timer_count, dev->timer_latch); ac97_via_update(dev); - /* Read only if SGD is active and not paused. */ - if (SGD_UNPAUSED) { - if (!dev->sgd_entry) { - /* Move on to the next block. */ - ac97_via_sgd_block_start(dev); - } + dev->out_l = dev->out_r = 0; - switch (dev->sgd_regs[0x02] & 0x30) { - case 0x00: /* Mono, 8-bit PCM */ - dev->out_l = dev->out_r = (mem_readb_phys(dev->sgd_sample_ptr++) ^ 0x80) * 256; - dev->sgd_sample_count--; - break; + switch (dev->sgd_regs[0x02] & 0x30) { + case 0x00: /* Mono, 8-bit PCM */ + if ((sgd->fifo_end - sgd->fifo_pos) >= 1) + dev->out_l = dev->out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + break; - case 0x10: /* Stereo, 8-bit PCM */ - dev->out_l = (mem_readb_phys(dev->sgd_sample_ptr++) ^ 0x80) * 256; - dev->out_r = (mem_readb_phys(dev->sgd_sample_ptr++) ^ 0x80) * 256; - dev->sgd_sample_count -= 2; - break; - - case 0x20: /* Mono, 16-bit PCM */ - dev->out_l = dev->out_r = mem_readw_phys(dev->sgd_sample_ptr); - dev->sgd_sample_ptr += 2; - dev->sgd_sample_count -= 2; - break; - - case 0x30: /* Stereo, 16-bit PCM */ - dev->out_l = mem_readw_phys(dev->sgd_sample_ptr); - dev->sgd_sample_ptr += 2; - dev->out_r = mem_readw_phys(dev->sgd_sample_ptr); - dev->sgd_sample_ptr += 2; - dev->sgd_sample_count -= 4; - break; - } - - /* Check if we've hit the end of this block. */ - if (dev->sgd_sample_count <= 0) { - ac97_via_log("AC97 VIA: Ending SGD block"); - - /* Move on to the next block on the next poll. */ - dev->sgd_entry_ptr += 8; - - if (dev->sgd_entry & 0x2000000000000000ULL) { - ac97_via_log(" with STOP"); - dev->sgd_regs[0x00] |= 0x04; + case 0x10: /* Stereo, 8-bit PCM */ + if ((sgd->fifo_end - sgd->fifo_pos) >= 2) { + dev->out_l = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + dev->out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; } - if (dev->sgd_entry & 0x4000000000000000ULL) { - ac97_via_log(" with FLAG"); - dev->sgd_regs[0x00] |= 0x01; + break; - /* Pause SGD. */ - dev->sgd_regs[0x00] |= 0x04; - - /* Fire interrupt if requested. */ - if (dev->sgd_regs[0x02] & 0x01) - ac97_via_log(" interrupt"); + case 0x20: /* Mono, 16-bit PCM */ + if ((sgd->fifo_end - sgd->fifo_pos) >= 2) { + dev->out_l = dev->out_r = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); + sgd->fifo_pos += 2; } - if (dev->sgd_entry & 0x8000000000000000ULL) { - ac97_via_log(" with EOL"); - dev->sgd_regs[0x00] |= 0x02; + break; - /* Fire interrupt if requested. */ - if (dev->sgd_regs[0x02] & 0x02) - ac97_via_log(" interrupt"); - - /* Restart SGD if a trigger is queued or auto-start is enabled. */ - if ((dev->sgd_regs[0x00] & 0x08) || (dev->sgd_regs[0x02] & 0x80)) { - ac97_via_log(" restart\n"); - dev->sgd_regs[0x00] &= ~0x08; - - dev->sgd_entry_ptr = 0; - } else { - ac97_via_log(" finish\n"); - dev->sgd_regs[0x00] &= ~0x80; - } - } else { - ac97_via_log("\n"); + case 0x30: /* Stereo, 16-bit PCM */ + pclog("fifo_end - fifo_pos = %d\n", sgd->fifo_end - sgd->fifo_pos); + if ((sgd->fifo_end - sgd->fifo_pos) >= 4) { + dev->out_l = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); + sgd->fifo_pos += 2; + dev->out_r = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); + sgd->fifo_pos += 2; } - - dev->sgd_entry = dev->sgd_sample_count = 0; - } - } else { - dev->out_l = dev->out_r = 0; - dev->cd_vol_l = dev->cd_vol_r = 0; - } - - if (dev->sgd_regs[0x00] & (dev->sgd_regs[0x02] & 0x03)) { - ac97_via_log("AC97 VIA: Setting IRQ (iflags %02X stuck %d)\n", dev->sgd_regs[0x00] & (dev->sgd_regs[0x02] & 0x03), dev->irq_stuck); - if (dev->irq_stuck) { - dev->losticount++; - pci_clear_irq(dev->slot, dev->irq_pin); - } else { - pci_set_irq(dev->slot, dev->irq_pin); - } - dev->irq_stuck = !dev->irq_stuck; + break; } } @@ -575,9 +626,8 @@ ac97_via_get_buffer(int32_t *buffer, int len, void *priv) ac97_via_update(dev); - for (int c = 0; c < len * 2; c++) { + for (int c = 0; c < len * 2; c++) buffer[c] += dev->buffer[c]; - } dev->pos = 0; } @@ -588,6 +638,7 @@ ac97_via_speed_changed(void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; dev->timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / 48000.0)); + dev->timer_fifo_latch = (uint64_t) ((double) TIMER_USEC * 10.0); } @@ -599,14 +650,25 @@ ac97_via_init(const device_t *info) ac97_via_log("AC97 VIA: init()\n"); - ac97_codec = &dev->codec[0]; - ac97_modem_codec = &dev->codec[2]; - ac97_codec_count = ac97_modem_codec_count = 2; + /* Set up codecs. */ + ac97_codec = &dev->codec[0][0]; + ac97_modem_codec = &dev->codec[1][0]; + ac97_codec_count = ac97_modem_codec_count = sizeof(dev->codec[0]) / sizeof(dev->codec[0][0]); + /* Set up SGD channels. */ + for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { + dev->sgd[i].id = i << 4; + dev->sgd[i].dev = dev; + + timer_add(&dev->sgd[i].timer, ac97_via_sgd_process, &dev->sgd[i], 0); + } + + /* Set up playback poller. */ timer_add(&dev->timer_count, ac97_via_poll, dev, 0); ac97_via_speed_changed(dev); timer_advance_u64(&dev->timer_count, dev->timer_latch); + /* Set up playback handler. */ sound_add_handler(ac97_via_get_buffer, dev); return dev; @@ -626,7 +688,7 @@ ac97_via_close(void *priv) const device_t ac97_via_device = { - "VIA VT82C686 AC97 Controller", + "VIA VT82C686 Integrated AC97 Controller", DEVICE_PCI, 0, ac97_via_init, ac97_via_close, NULL, diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index 1c697a3a8..9c65052f0 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -17,6 +17,7 @@ #include <86box/sound.h> #include <86box/midi.h> #include <86box/snd_mpu401.h> +#include <86box/snd_ac97.h> #define N 16 @@ -51,7 +52,7 @@ typedef struct { uint8_t uart_ctrl; uint8_t uart_status; - uint16_t codec_regs[128]; + ac97_codec_t *codec; uint32_t codec_ctrl; struct { @@ -358,11 +359,7 @@ static uint32_t es1371_inl(uint16_t port, void *p) break; case 0x14: - ret = es1371->codec_ctrl & 0x00ff0000; - ret |= es1371->codec_regs[(es1371->codec_ctrl >> 16) & 0x7f]; - if (((es1371->codec_ctrl >> 16) & 0x7f) == 0x26) - ret |= 0x0f; - ret |= CODEC_READY; + ret = es1371->codec_ctrl | CODEC_READY; break; case 0x30: @@ -593,39 +590,48 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p) break; case 0x14: - es1371->codec_ctrl = val; - if (!(val & CODEC_READ)) - { -// audiopci_log("Write codec %02x %04x\n", (val >> 16) & 0x7f, val & 0xffff); - if ((((val >> 16) & 0x7f) != 0x7c) && (((val >> 16) & 0x7f) != 0x7e)) - es1371->codec_regs[(val >> 16) & 0x7f] = val & 0xffff; - switch ((val >> 16) & 0x7f) - { - case 0x02: /*Master volume*/ - if (val & 0x8000) - es1371->master_vol_l = es1371->master_vol_r = 0; - else - { - if (val & 0x2000) + if (val & CODEC_READ) { + es1371->codec_ctrl &= 0x00ff0000; + es1371->codec_ctrl |= ac97_codec_read(es1371->codec, (val >> 16) & 0x7f); + es1371->codec_ctrl |= ac97_codec_read(es1371->codec, ((val >> 16) & 0x7f) + 1) << 8; + } else { + es1371->codec_ctrl &= 0x00ffffff; + ac97_codec_write(es1371->codec, (val >> 16) & 0x7f, val & 0xff); + ac97_codec_write(es1371->codec, ((val >> 16) & 0x7f) + 1, val >> 8); + + switch ((val >> 16) & 0x7f) { + case 0x02: /* Master Volume LSB */ + if (es1371->codec->regs[0x03] & 0x80) + es1371->master_vol_l = es1371->master_vol_r = 0; + else if (val & 0x20) + es1371->master_vol_r = codec_attn[0]; + else + es1371->master_vol_r = codec_attn[0x1f - (val & 0x1f)]; + break; + + case 0x03: /* Master Volume MSB */ + if (val & 0x80) + es1371->master_vol_l = es1371->master_vol_r = 0; + else if (val & 0x20) es1371->master_vol_l = codec_attn[0]; else - es1371->master_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; - if (val & 0x20) - es1371->master_vol_r = codec_attn[0]; - else - es1371->master_vol_r = codec_attn[0x1f - (val & 0x1f)]; - } - break; - case 0x12: /*CD volume*/ - if (val & 0x8000) - es1371->cd_vol_l = es1371->cd_vol_r = 0; - else - { - es1371->cd_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; - es1371->cd_vol_r = codec_attn[0x1f - (val & 0x1f)]; - } - break; - } + es1371->master_vol_l = codec_attn[0x1f - (val & 0x1f)]; + break; + + case 0x12: /* CD Volume LSB */ + if (es1371->codec->regs[0x13] & 0x80) + es1371->cd_vol_l = es1371->cd_vol_r = 0; + else + es1371->cd_vol_r = codec_attn[0x1f - (val & 0x1f)]; + break; + + case 0x13: /* CD Volume MSB */ + if (val & 0x80) + es1371->cd_vol_l = es1371->cd_vol_r = 0; + else + es1371->cd_vol_l = codec_attn[0x1f - (val & 0x1f)]; + break; + } } break; @@ -1362,9 +1368,9 @@ static void *es1371_init(const device_t *info) generate_es1371_filter(); - /* Return a CS4297A like VMware does. */ - es1371->codec_regs[0x7c] = 0x4352; - es1371->codec_regs[0x7e] = 0x5910; + ac97_codec = &es1371->codec; + ac97_codec_count = 1; + device_add(&cs4297a_device); return es1371; } From b14e20b3fbed835c6fb34f435f65f264ae297612 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 13 Jul 2021 21:15:25 -0300 Subject: [PATCH 07/52] Fix AC97 codec ID byte ordering --- src/sound/snd_ac97_codec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index f97b1c551..0074a9601 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -90,7 +90,7 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) //case 0x2a ... 0x59: /* Linux tests for audio capability by writing to 38-39 */ case 0x5a ... 0x5f: /* Vendor Reserved */ //case 0x60 ... 0x6f: - case 0x70 ... 0x7b: /* Vendor Reserved */ + case 0x70 ... 0x7f: /* Vendor Reserved */ /* Read-only registers. */ return; @@ -175,8 +175,8 @@ ac97_codec_reset(void *priv) /* Set Vendor ID. */ dev->regs[0x7c] = dev->id >> 16; dev->regs[0x7d] = dev->id >> 24; - dev->regs[0x7e] = dev->id >> 8; - dev->regs[0x7f] = dev->id; + dev->regs[0x7e] = dev->id; + dev->regs[0x7f] = dev->id >> 8; } From 07c449ada1163400c58eb605484d9966a35c6f39 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 13 Jul 2021 21:16:08 -0300 Subject: [PATCH 08/52] Fix ES1371 codec writes and add I/O fallbacks, Linux now outputs. --- src/sound/snd_audiopci.c | 54 +++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index 9c65052f0..ee529c59f 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -333,7 +333,8 @@ static uint16_t es1371_inw(uint16_t port, void *p) break; default: - audiopci_log("Bad es1371_inw: port=%04x\n", port); + ret = es1371_inb(port, p); + ret |= es1371_inb(port + 1, p) << 8; } // audiopci_log("es1371_inw: port=%04x ret=%04x %04x:%08x\n", port, ret, CS,cpu_state.pc); @@ -413,7 +414,8 @@ static uint32_t es1371_inl(uint16_t port, void *p) break; default: - audiopci_log("Bad es1371_inl: port=%04x\n", port); + ret = es1371_inw(port, p); + ret |= es1371_inw(port + 2, p) << 16; } audiopci_log("es1371_inl: port=%04x ret=%08x\n", port, ret); @@ -524,7 +526,8 @@ static void es1371_outw(uint16_t port, uint16_t val, void *p) break; default: - audiopci_log("Bad es1371_outw: port=%04x val=%04x\n", port, val); + es1371_outb(port, val & 0xff, p); + es1371_outb(port + 1, (val >> 8) & 0xff, p); } } static void es1371_outl(uint16_t port, uint32_t val, void *p) @@ -600,36 +603,28 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p) ac97_codec_write(es1371->codec, ((val >> 16) & 0x7f) + 1, val >> 8); switch ((val >> 16) & 0x7f) { - case 0x02: /* Master Volume LSB */ - if (es1371->codec->regs[0x03] & 0x80) + case 0x02: /* Master Volume */ + if (val & 0x8000) { es1371->master_vol_l = es1371->master_vol_r = 0; - else if (val & 0x20) - es1371->master_vol_r = codec_attn[0]; - else - es1371->master_vol_r = codec_attn[0x1f - (val & 0x1f)]; + } else { + if (val & 0x2000) + es1371->master_vol_l = codec_attn[0]; + else + es1371->master_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; + if (val & 0x20) + es1371->master_vol_r = codec_attn[0]; + else + es1371->master_vol_r = codec_attn[0x1f - (val & 0x1f)]; + } break; - case 0x03: /* Master Volume MSB */ - if (val & 0x80) - es1371->master_vol_l = es1371->master_vol_r = 0; - else if (val & 0x20) - es1371->master_vol_l = codec_attn[0]; - else - es1371->master_vol_l = codec_attn[0x1f - (val & 0x1f)]; - break; - - case 0x12: /* CD Volume LSB */ - if (es1371->codec->regs[0x13] & 0x80) + case 0x12: /* CD Volume */ + if (val & 0x8000) { es1371->cd_vol_l = es1371->cd_vol_r = 0; - else + } else { + es1371->cd_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; es1371->cd_vol_r = codec_attn[0x1f - (val & 0x1f)]; - break; - - case 0x13: /* CD Volume MSB */ - if (val & 0x80) - es1371->cd_vol_l = es1371->cd_vol_r = 0; - else - es1371->cd_vol_l = codec_attn[0x1f - (val & 0x1f)]; + } break; } } @@ -736,7 +731,8 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p) break; default: - audiopci_log("Bad es1371_outl: port=%04x val=%08x\n", port, val); + es1371_outw(port, val & 0xffff, p); + es1371_outw(port + 2, (val >> 16) & 0xffff, p); } } From 67dfb363c13c211d73171d7a2360181492d51c9f Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 13 Jul 2021 21:16:43 -0300 Subject: [PATCH 09/52] 6VIA90AP *should* have the ALC100 codec --- src/machine/m_at_socket370.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/machine/m_at_socket370.c b/src/machine/m_at_socket370.c index cc2e1718a..14f5e0dca 100644 --- a/src/machine/m_at_socket370.c +++ b/src/machine/m_at_socket370.c @@ -452,9 +452,7 @@ machine_at_6via90ap_init(const machine_t *model) hwm_values.temperatures[1] += 2; /* System offset */ hwm_values.temperatures[2] = 0; /* unused */ - /* I recall identifying this board's codec as the ALC100 while studying AC97, but I couldn't find - that information again. Other Acorp boards have the ALC100, though, so it's a safe bet. -RG */ - device_add(&alc100_device); + device_add(&alc100_device); /* ALC100P identified on similar Acorp boards (694TA, 6VIA90A1) */ return ret; } From 9643bbd5793ae25469077fb5289f32710f0c8af6 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 13 Jul 2021 22:06:17 -0300 Subject: [PATCH 10/52] Add AC97 audio to VA-503A --- src/include/86box/snd_ac97.h | 1 + src/machine/m_at_sockets7.c | 5 ++++- src/sound/snd_ac97_codec.c | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index e0345227a..9c4bd308a 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -42,6 +42,7 @@ extern int ac97_codec_count, ac97_modem_codec_count; extern const device_t alc100_device; extern const device_t cs4297a_device; +extern const device_t wm9701a_device; extern const device_t ac97_via_device; #endif diff --git a/src/machine/m_at_sockets7.c b/src/machine/m_at_sockets7.c index f15ddf01b..ca6c957e2 100644 --- a/src/machine/m_at_sockets7.c +++ b/src/machine/m_at_sockets7.c @@ -40,6 +40,7 @@ #include <86box/video.h> #include "cpu.h" #include <86box/machine.h> +#include <86box/snd_ac97.h> int @@ -112,7 +113,7 @@ machine_at_ficva503a_init(const machine_t *model) { int ret; - ret = bios_load_linear("roms/machines/ficva503a/jo4116.bin", + ret = bios_load_linear("roms/machines/ficva503a/jn4116.bin", 0x000c0000, 262144, 0); if (bios_only || !ret) @@ -140,5 +141,7 @@ machine_at_ficva503a_init(const machine_t *model) hwm_values.temperatures[1] += 2; /* System offset */ hwm_values.temperatures[2] = 0; /* unused */ + device_add(&wm9701a_device); /* on daughtercard */ + return ret; } diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 0074a9601..57083d590 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -30,7 +30,8 @@ enum { AC97_CODEC_ALC100 = AC97_CODEC_ID('A', 'L', 'C', 0x20), - AC97_CODEC_CS4297A = AC97_CODEC_ID('C', 'R', 'Y', 0x11) + AC97_CODEC_CS4297A = AC97_CODEC_ID('C', 'R', 'Y', 0x11), + AC97_CODEC_WM9701A = AC97_CODEC_ID('W', 'M', 'L', 0x00) }; #define ENABLE_AC97_CODEC_LOG 1 @@ -238,3 +239,15 @@ const device_t cs4297a_device = NULL, NULL }; + +const device_t wm9701a_device = +{ + "Wolfson WM9701A", + DEVICE_AC97, + AC97_CODEC_WM9701A, + ac97_codec_init, ac97_codec_close, ac97_codec_reset, + { NULL }, + NULL, + NULL, + NULL +}; From a976256b1e455484bcab376b7d8eba9d48484303 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 13 Jul 2021 22:14:39 -0300 Subject: [PATCH 11/52] VIA AC97 updates: Linux now kinda works --- src/sound/snd_ac97_via.c | 44 ++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 0ee33b94c..65b2f889e 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -101,7 +101,7 @@ ac97_via_read_status(void *priv, uint8_t modem) ac97_via_t *dev = (ac97_via_t *) priv; uint8_t ret = 0x00; - /* Flag codecs as ready if present. */ + /* Flag each codec as ready if present. */ for (uint8_t i = 0; i <= 1; i++) { if (dev->codec[modem][i]) ret |= 0x01 << (i << 1); @@ -326,21 +326,19 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) /* Read from or write to codec. */ if (codec) { if (val & 0x80) { - val <<= 1; - dev->sgd_regs[0x80] = ac97_codec_read(codec, val); - dev->sgd_regs[0x81] = ac97_codec_read(codec, val | 1); + dev->sgd_regs[0x80] = ac97_codec_read(codec, val & 0x7e); + dev->sgd_regs[0x81] = ac97_codec_read(codec, (val & 0x7e) | 1); } else { - val <<= 1; - ac97_codec_write(codec, val, dev->sgd_regs[0x80]); - ac97_codec_write(codec, val | 1, dev->sgd_regs[0x81]); + ac97_codec_write(codec, val & 0x7e, dev->sgd_regs[0x80]); + ac97_codec_write(codec, (val & 0x7e) | 1, dev->sgd_regs[0x81]); } + + /* Flag data/status/index for this codec as valid. */ + dev->sgd_regs[0x83] |= 0x02 << (i * 2); } else if (val & 0x80) { - /* Unknown behavior when reading from a non-existent codec. */ + /* Unknown behavior when reading from an absent codec. */ dev->sgd_regs[0x80] = dev->sgd_regs[0x81] = 0xff; } - - /* Flag data/status/index for this codec as valid. */ - dev->sgd_regs[0x83] |= 0x02 << (i * 2); break; case 0x83: @@ -348,14 +346,18 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) /* Clear RWC bits. */ for (i = 0x02; i <= 0x08; i <<= 2) { - #if 0 /* race condition with Linux clearing bits and starting SGD on the same dword write */ +#if 0 /* race condition with Linux clearing bits and starting SGD on the same dword write */ if (val & i) val &= ~i; else val |= dev->sgd_regs[addr] & i; - #else - val |= i; - #endif +#else + /* Don't flag data/status/index as valid if the codec is absent. */ + if (dev->codec[modem][!!(val & 0x40)]) + val |= i; + else + val &= ~i; +#endif } break; } @@ -486,8 +488,10 @@ ac97_via_sgd_process(void *priv) /* Read entry. */ sgd->entry = ((uint64_t) mem_readl_phys(sgd->entry_ptr + 4) << 32ULL) | (uint64_t) mem_readl_phys(sgd->entry_ptr); +#ifdef ENABLE_AC97_VIA_LOG if (sgd->entry == 0xffffffffffffffffULL) fatal("AC97 VIA: Invalid SGD %d entry at %08X\n", sgd->id >> 4, sgd->entry_ptr); +#endif /* Set sample pointer and count. */ sgd->sample_ptr = sgd->entry & 0xffffffff; @@ -495,6 +499,9 @@ ac97_via_sgd_process(void *priv) ac97_via_log("AC97 VIA: Starting SGD %d block at %08X entry %08X%08X (start %08X len %06X) lostirqs %d\n", sgd->id >> 4, sgd->entry_ptr, mem_readl_phys(sgd->entry_ptr + 4), mem_readl_phys(sgd->entry_ptr), sgd->sample_ptr, sgd->sample_count, ac97_via_lost_irqs); + + /* Increment entry pointer now, as Linux expects it to be one block ahead. */ + sgd->entry_ptr += 8; } if (sgd->id & 0x10) { @@ -512,9 +519,6 @@ ac97_via_sgd_process(void *priv) if (sgd->sample_count <= 0) { ac97_via_log("AC97 VIA: Ending SGD %d block", sgd->id >> 4); - /* Move on to the next block on the next run. */ - sgd->entry_ptr += 8; - if (sgd->entry & 0x2000000000000000ULL) { ac97_via_log(" with STOP"); dev->sgd_regs[sgd->id] |= 0x04; @@ -561,7 +565,7 @@ ac97_via_sgd_process(void *priv) } ac97_via_log("\n"); - /* Start a new block. */ + /* Move on to a new block on the next run. */ sgd->entry = sgd->sample_count = 0; } } @@ -586,6 +590,7 @@ ac97_via_poll(void *priv) dev->out_l = dev->out_r = 0; + pclog("fifo_end - fifo_pos = %d\n", sgd->fifo_end - sgd->fifo_pos); switch (dev->sgd_regs[0x02] & 0x30) { case 0x00: /* Mono, 8-bit PCM */ if ((sgd->fifo_end - sgd->fifo_pos) >= 1) @@ -607,7 +612,6 @@ ac97_via_poll(void *priv) break; case 0x30: /* Stereo, 16-bit PCM */ - pclog("fifo_end - fifo_pos = %d\n", sgd->fifo_end - sgd->fifo_pos); if ((sgd->fifo_end - sgd->fifo_pos) >= 4) { dev->out_l = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); sgd->fifo_pos += 2; From 292874f772664fc82413e342d60f83a7a5550b99 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 16 Jul 2021 15:39:19 -0300 Subject: [PATCH 12/52] Fix unused variable warning with logging disabled --- src/sound/snd_ac97_via.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 65b2f889e..382978526 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -59,7 +59,7 @@ typedef struct _ac97_via_ { int pos; } ac97_via_t; -#define ENABLE_AC97_VIA_LOG 1 +//#define ENABLE_AC97_VIA_LOG 1 #ifdef ENABLE_AC97_VIA_LOG int ac97_via_do_log = ENABLE_AC97_VIA_LOG; unsigned int ac97_via_lost_irqs = 0; @@ -147,7 +147,9 @@ uint8_t ac97_via_sgd_read(uint16_t addr, void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; +#ifdef ENABLE_AC97_VIA_LOG uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base; +#endif addr &= 0xff; uint8_t ret; @@ -590,7 +592,7 @@ ac97_via_poll(void *priv) dev->out_l = dev->out_r = 0; - pclog("fifo_end - fifo_pos = %d\n", sgd->fifo_end - sgd->fifo_pos); + //pclog("fifo_end - fifo_pos = %d\n", sgd->fifo_end - sgd->fifo_pos); switch (dev->sgd_regs[0x02] & 0x30) { case 0x00: /* Mono, 8-bit PCM */ if ((sgd->fifo_end - sgd->fifo_pos) >= 1) From 7db35aa9b67663884f5dbed69662205fa428c26e Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 18 Jul 2021 16:17:56 -0300 Subject: [PATCH 13/52] De-duplicate entry field on the SGD structure --- src/sound/snd_ac97_via.c | 74 ++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 382978526..fb9d1da98 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -35,10 +35,9 @@ typedef struct { uint8_t id; struct _ac97_via_ *dev; - uint64_t entry; uint32_t entry_ptr, sample_ptr, fifo_pos, fifo_end; int32_t sample_count; - uint8_t fifo[32]; + uint8_t entry_flags, fifo[32]; pc_timer_t timer; } ac97_via_sgd_t; @@ -118,11 +117,11 @@ ac97_via_update_irqs(ac97_via_t *dev, uint8_t iflag_clear) { /* Check interrupt flags on all SGDs. */ for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { - if (dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03)) { - ac97_via_log("AC97 VIA: Setting IRQ (sgd %d iflags %02X stuck %d)\n", + if (dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03)) { + ac97_via_log("AC97 VIA: Setting IRQ (sgd %d iflags %02X stuck %d)\n", i, dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03), dev->irq_stuck); - if (dev->irq_stuck && !iflag_clear) { + if (dev->irq_stuck && !iflag_clear) { #ifdef ENABLE_AC97_VIA_LOG ac97_via_lost_irqs++; #endif @@ -133,7 +132,7 @@ ac97_via_update_irqs(ac97_via_t *dev, uint8_t iflag_clear) dev->irq_stuck = !dev->irq_stuck; return; - } + } } /* No interrupt pending. */ @@ -154,9 +153,9 @@ ac97_via_sgd_read(uint16_t addr, void *priv) uint8_t ret; if (!(addr & 0x80)) { - /* Process SGD channel registers. */ - switch (addr & 0xf) { - case 0x4: + /* Process SGD channel registers. */ + switch (addr & 0xf) { + case 0x4: ret = dev->sgd[addr >> 4].entry_ptr; break; @@ -187,9 +186,9 @@ ac97_via_sgd_read(uint16_t addr, void *priv) default: ret = dev->sgd_regs[addr]; break; - } + } } else { - /* Process regular registers. */ + /* Process regular registers. */ switch (addr) { case 0x84: ret = (dev->sgd_regs[0x00] & 0x01); @@ -256,7 +255,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) return; if (!(addr & 0x80)) { - /* Process SGD channel registers. */ + /* Process SGD channel registers. */ switch (addr & 0xf) { case 0x0: /* Clear RWC status bits. */ @@ -281,7 +280,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) dev->sgd_regs[addr & 0xf0] &= ~0x44; /* Start at the specified entry pointer. */ - dev->sgd[addr >> 4].entry = 0; + dev->sgd[addr >> 4].sample_ptr = 0; dev->sgd[addr >> 4].entry_ptr = (dev->sgd_regs[(addr & 0xf0) | 0x7] << 24) | (dev->sgd_regs[(addr & 0xf0) | 0x6] << 16) | (dev->sgd_regs[(addr & 0xf0) | 0x5] << 8) | (dev->sgd_regs[(addr & 0xf0) | 0x4] & 0xfe); /* Start the actual SGD process. */ @@ -312,7 +311,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) return; } } else { - /* Process regular registers. */ + /* Process regular registers. */ switch (addr) { case 0x30 ... 0x3f: case 0x60 ... 0x7f: @@ -482,34 +481,35 @@ ac97_via_sgd_process(void *priv) /* Process SGD if active, unless this is Audio Read and there's no room in the FIFO. */ if (((dev->sgd_regs[sgd->id] & 0xc4) == 0x80) && (sgd->id || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { - /* Move on to the next block if no entry is present. */ - if (!sgd->entry) { + /* Move on to the next block if no entry is present. */ + if (!sgd->sample_ptr) { /* Start at first entry if no pointer is present. */ if (!sgd->entry_ptr) sgd->entry_ptr = (dev->sgd_regs[sgd->id | 0x7] << 24) | (dev->sgd_regs[sgd->id | 0x6] << 16) | (dev->sgd_regs[sgd->id | 0x5] << 8) | (dev->sgd_regs[sgd->id | 0x4] & 0xfe); /* Read entry. */ - sgd->entry = ((uint64_t) mem_readl_phys(sgd->entry_ptr + 4) << 32ULL) | (uint64_t) mem_readl_phys(sgd->entry_ptr); + sgd->sample_ptr = mem_readl_phys(sgd->entry_ptr); + sgd->entry_ptr += 4; + sgd->sample_count = mem_readl_phys(sgd->entry_ptr); + sgd->entry_ptr += 4; #ifdef ENABLE_AC97_VIA_LOG - if (sgd->entry == 0xffffffffffffffffULL) + if ((sgd->sample_ptr == 0xffffffff) || (sgd->sample_ptr == 0x00000000) || + (sgd->sample_count == 0xffffffff) || (sgd->sample_count == 0x00000000)) fatal("AC97 VIA: Invalid SGD %d entry at %08X\n", sgd->id >> 4, sgd->entry_ptr); #endif - /* Set sample pointer and count. */ - sgd->sample_ptr = sgd->entry & 0xffffffff; - sgd->sample_count = (sgd->entry >> 32) & 0xffffff; + /* Extract flags from the most significant byte. */ + sgd->entry_flags = sgd->sample_count >> 24; + sgd->sample_count &= 0xffffff; - ac97_via_log("AC97 VIA: Starting SGD %d block at %08X entry %08X%08X (start %08X len %06X) lostirqs %d\n", sgd->id >> 4, sgd->entry_ptr, - mem_readl_phys(sgd->entry_ptr + 4), mem_readl_phys(sgd->entry_ptr), sgd->sample_ptr, sgd->sample_count, ac97_via_lost_irqs); - - /* Increment entry pointer now, as Linux expects it to be one block ahead. */ - sgd->entry_ptr += 8; + ac97_via_log("AC97 VIA: Starting SGD %d block at %08X start %08X len %06X flags %02X lostirqs %d\n", sgd->id >> 4, + sgd->entry_ptr, sgd->sample_ptr, sgd->sample_count, sgd->entry_flags, ac97_via_lost_irqs); } - if (sgd->id & 0x10) { - /* Write channel: read data from FIFO. */ - mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); - } else { + if (sgd->id & 0x10) { + /* Write channel: read data from FIFO. */ + mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); + } else { /* Read channel: write data to FIFO. */ *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)]) = mem_readl_phys(sgd->sample_ptr); } @@ -521,12 +521,12 @@ ac97_via_sgd_process(void *priv) if (sgd->sample_count <= 0) { ac97_via_log("AC97 VIA: Ending SGD %d block", sgd->id >> 4); - if (sgd->entry & 0x2000000000000000ULL) { + if (sgd->entry_flags & 0x20) { ac97_via_log(" with STOP"); dev->sgd_regs[sgd->id] |= 0x04; } - if (sgd->entry & 0x4000000000000000ULL) { + if (sgd->entry_flags & 0x40) { ac97_via_log(" with FLAG"); /* Raise FLAG while also pausing SGD. */ @@ -538,7 +538,7 @@ ac97_via_sgd_process(void *priv) #endif } - if (sgd->entry & 0x8000000000000000ULL) { + if (sgd->entry_flags & 0x80) { ac97_via_log(" with EOL"); /* Raise EOL. */ @@ -568,7 +568,7 @@ ac97_via_sgd_process(void *priv) ac97_via_log("\n"); /* Move on to a new block on the next run. */ - sgd->entry = sgd->sample_count = 0; + sgd->sample_ptr = sgd->sample_count = 0; } } @@ -663,10 +663,10 @@ ac97_via_init(const device_t *info) /* Set up SGD channels. */ for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { - dev->sgd[i].id = i << 4; - dev->sgd[i].dev = dev; + dev->sgd[i].id = i << 4; + dev->sgd[i].dev = dev; - timer_add(&dev->sgd[i].timer, ac97_via_sgd_process, &dev->sgd[i], 0); + timer_add(&dev->sgd[i].timer, ac97_via_sgd_process, &dev->sgd[i], 0); } /* Set up playback poller. */ From dffca679c0a9980b4ac6d342373ac4902e31c303 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 18 Jul 2021 19:03:01 -0300 Subject: [PATCH 14/52] Make CS423x Sound Blaster Pro a generic compatibility device in preparation for VT82C686 --- src/include/86box/sound.h | 2 +- src/sound/snd_cs423x.c | 2 +- src/sound/snd_sb.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/include/86box/sound.h b/src/include/86box/sound.h index b15724cdd..1ca29ea18 100644 --- a/src/include/86box/sound.h +++ b/src/include/86box/sound.h @@ -110,7 +110,7 @@ extern const device_t sb_2_device; extern const device_t sb_pro_v1_device; extern const device_t sb_pro_v2_device; extern const device_t sb_pro_mcv_device; -extern const device_t sb_pro_cs423x_device; +extern const device_t sb_pro_compat_device; extern const device_t sb_16_device; extern const device_t sb_16_pnp_device; extern const device_t sb_32_pnp_device; diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 03a258f30..17b386360 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -788,7 +788,7 @@ cs423x_init(const device_t *info) /* Initialize SBPro codec first to get the correct CD audio filter for the default context, which is SBPro. The WSS codec is initialized later by cs423x_reset */ - dev->sb = (sb_t *) device_add(&sb_pro_cs423x_device); + dev->sb = device_add(&sb_pro_compat_device); /* Initialize RAM, registers and WSS codec. */ cs423x_reset(dev); diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 8e1ea61a4..9e458c740 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -1625,12 +1625,12 @@ sb_pro_mcv_init(const device_t *info) static void * -sb_pro_cs423x_init(const device_t *info) +sb_pro_compat_init(const device_t *info) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0, sizeof(sb_t)); - sb->opl_enabled = 0; /* updated by cs423x code */ + sb->opl_enabled = 0; /* CS423x updates this, while VT82C686 lacks OPL */ opl3_init(&sb->opl); sb_dsp_init(&sb->dsp, SBPRO2, SB_SUBTYPE_DEFAULT, sb); @@ -2534,12 +2534,12 @@ const device_t sb_pro_mcv_device = NULL }; -const device_t sb_pro_cs423x_device = +const device_t sb_pro_compat_device = { - "Crystal CS423x Sound Blaster Pro compatibility", + "Sound Blaster Pro (Compatibility)", DEVICE_ISA | DEVICE_AT, 0, - sb_pro_cs423x_init, sb_close, NULL, { NULL }, + sb_pro_compat_init, sb_close, NULL, { NULL }, sb_speed_changed, NULL, NULL From ce63373613c7aab15e690ad3d5ab3443ef419e3b Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 22 Jul 2021 11:10:05 -0300 Subject: [PATCH 15/52] Add incomplete VIA AC97 FM implementation --- src/chipset/via_pipc.c | 146 ++++++++++++++++++++++++++++++++++----- src/sound/snd_ac97_via.c | 59 ++++++++++++---- 2 files changed, 175 insertions(+), 30 deletions(-) diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index d0fbdfa63..b984aa07a 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -50,7 +50,10 @@ #include <86box/sio.h> #include <86box/hwm.h> #include <86box/gameport.h> +#include <86box/sound.h> #include <86box/snd_ac97.h> +#include <86box/snd_sb.h> +#include <86box/nmi.h> /* Most revision numbers (PCI-ISA bridge or otherwise) were lifted from PCI device listings on forums, as VIA's datasheets are not very helpful regarding those. */ @@ -68,11 +71,11 @@ typedef struct uint32_t local; uint8_t max_func; - uint8_t pci_isa_regs[256]; - uint8_t ide_regs[256]; - uint8_t usb_regs[2][256]; - uint8_t power_regs[256]; - uint8_t ac97_regs[2][256]; + uint8_t pci_isa_regs[256], + ide_regs[256], + usb_regs[2][256], + power_regs[256], + ac97_regs[2][256], fmnmi_regs[4], fm_regs[4]; sff8038i_t *bm[2]; nvr_t *nvr; int nvr_enabled, slot; @@ -80,7 +83,9 @@ typedef struct usb_t *usb[2]; acpi_t *acpi; void *gameport, *ac97; - uint16_t midigame_base; + sb_t *sb; + uint16_t midigame_base, fmnmi_base; + uint8_t fm_enabled; } pipc_t; @@ -355,6 +360,7 @@ pipc_reset_hard(void *priv) dev->ac97_regs[i][0x40] = 0x01; dev->ac97_regs[i][0x43] = 0x1c; + dev->ac97_regs[i][0x48] = 0x01; dev->ac97_regs[i][0x4b] = 0x02; pipc_sgd_handlers(dev, i); @@ -456,12 +462,12 @@ static void pipc_sgd_handlers(pipc_t *dev, uint8_t modem) { if (!dev->ac97) - return; + return; if (modem) - ac97_via_remap_modem_sgd(dev->ac97, dev->ac97_regs[1][0x11] << 8, dev->ac97_regs[1][0x04] & PCI_COMMAND_IO); + ac97_via_remap_modem_sgd(dev->ac97, dev->ac97_regs[1][0x11] << 8, dev->ac97_regs[1][0x04] & PCI_COMMAND_IO); else - ac97_via_remap_audio_sgd(dev->ac97, dev->ac97_regs[0][0x11] << 8, dev->ac97_regs[0][0x04] & PCI_COMMAND_IO); + ac97_via_remap_audio_sgd(dev->ac97, dev->ac97_regs[0][0x11] << 8, dev->ac97_regs[0][0x04] & PCI_COMMAND_IO); } @@ -516,12 +522,94 @@ static void pipc_codec_handlers(pipc_t *dev, uint8_t modem) { if (!dev->ac97) - return; + return; if (modem) - ac97_via_remap_modem_codec(dev->ac97, dev->ac97_regs[1][0x1d] << 8, dev->ac97_regs[1][0x04] & PCI_COMMAND_IO); + ac97_via_remap_modem_codec(dev->ac97, dev->ac97_regs[1][0x1d] << 8, dev->ac97_regs[1][0x04] & PCI_COMMAND_IO); else - ac97_via_remap_audio_codec(dev->ac97, dev->ac97_regs[0][0x1d] << 8, dev->ac97_regs[0][0x04] & PCI_COMMAND_IO); + ac97_via_remap_audio_codec(dev->ac97, dev->ac97_regs[0][0x1d] << 8, dev->ac97_regs[0][0x04] & PCI_COMMAND_IO); +} + + +static uint8_t +pipc_fmnmi_read(uint16_t addr, void *priv) +{ + pipc_t *dev = (pipc_t *) priv; + uint8_t ret = dev->fmnmi_regs[addr & 0x03]; + + pipc_log("PIPC: fmnmi_read(%02X) = %02X\n", addr & 0x03, ret); + + if (dev->ac97_regs[0][0x48] & 0x04) + smi_line = 0; + else + nmi = 0; + + return ret; +} + + +static void +pipc_fmnmi_write(uint16_t addr, uint8_t val, void *priv) +{ + pipc_t *dev = (pipc_t *) priv; + + pipc_log("PIPC: fmnmi_write(%02X, %02X)\n", addr & 0x03, val); +} + + +static uint8_t +pipc_fm_read(uint16_t addr, void *priv) +{ + pipc_t *dev = (pipc_t *) priv; + uint8_t ret = opl3_read(addr, &dev->sb->opl); + + pipc_log("PIPC: fm_read(%02X) = %02X\n", addr & 0x03, ret); + + return ret; +} + + +static void +pipc_fm_write(uint16_t addr, uint8_t val, void *priv) +{ + pipc_t *dev = (pipc_t *) priv; + + pipc_log("PIPC: fm_write(%02X, %02X)\n", addr & 0x03, val); + + opl3_write(addr, val, &dev->sb->opl); + dev->fm_regs[addr & 0x03] = val; + + dev->fmnmi_regs[0x00] = (addr & 0x02) ? 0x02 : 0x01; + dev->fmnmi_regs[0x01] = dev->fm_regs[addr & 0x02]; + dev->fmnmi_regs[0x02] = dev->fm_regs[(addr & 0x02) | 0x01]; + + if (dev->ac97_regs[0][0x48] & 0x04) + smi_line = 1; + else + nmi = 1; +} + + +static void +pipc_fmnmi_handlers(pipc_t *dev, uint8_t modem) +{ + if (!dev->ac97 || modem) + return; + + if (dev->fmnmi_base) + io_removehandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, pipc_fmnmi_write, NULL, NULL, dev); + + if (dev->fm_enabled) + io_removehandler(0x388, 4, pipc_fm_read, NULL, NULL, pipc_fm_write, NULL, NULL, dev); + + dev->fmnmi_base = (dev->ac97_regs[0][0x15] << 8) | (dev->ac97_regs[0][0x14] & 0xfc); + dev->fm_enabled = !!(dev->ac97_regs[0][0x42] & 0x04); + + if (dev->fmnmi_base && (dev->ac97_regs[0][0x04] & PCI_COMMAND_IO)) + io_sethandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, pipc_fmnmi_write, NULL, NULL, dev); + + if (dev->fm_enabled) + io_sethandler(0x388, 4, pipc_fm_read, NULL, NULL, pipc_fm_write, NULL, NULL, dev); } @@ -1096,6 +1184,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) pipc_midigame_handlers(dev, func); pipc_sgd_handlers(dev, func); pipc_codec_handlers(dev, func); + pipc_fmnmi_handlers(dev, func); break; case 0x09: case 0x0a: case 0x0b: @@ -1103,11 +1192,18 @@ pipc_write(int func, int addr, uint8_t val, void *priv) dev->ac97_regs[func][addr] = val; break; - case 0x11: + case 0x10: case 0x11: dev->ac97_regs[func][addr] = val; pipc_sgd_handlers(dev, func); break; + case 0x14: case 0x15: + if (addr == 0x14) + val = (val & 0xfc) | 1; + dev->ac97_regs[func][addr] = val; + pipc_fmnmi_handlers(dev, func); + break; + case 0x18: case 0x19: if (addr == 0x18) val = (val & 0xfc) | 1; @@ -1115,7 +1211,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) pipc_midigame_handlers(dev, func); break; - case 0x1c: + case 0x1c: case 0x1d: dev->ac97_regs[func][addr] = val; pipc_codec_handlers(dev, func); break; @@ -1128,10 +1224,8 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x42: case 0x4a: case 0x4b: dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; gameport_remap(dev->gameport, (dev->ac97_regs[0][0x42] & 0x08) ? ((dev->ac97_regs[0][0x4b] << 8) | dev->ac97_regs[0][0x4a]) : 0); - break; - - case 0x41: - dev->ac97_regs[func][addr] = val; + if (addr == 0x42) + pipc_fmnmi_handlers(dev, func); break; case 0x43: @@ -1146,6 +1240,20 @@ pipc_write(int func, int addr, uint8_t val, void *priv) dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0x0f; break; + case 0x48: + dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0x0f; + /*if (!(val & 0x01)) { + if (val & 0x04) + smi_line = 0; + else + nmi = 0; + }*/ + if (val & 0x04) + smi_line = !!(val & 0x01); + else + nmi = !!(val & 0x01); + break; + default: dev->ac97_regs[func][addr] = val; break; @@ -1227,6 +1335,8 @@ pipc_init(const device_t *info) dev->ac97 = device_add(&ac97_via_device); ac97_via_set_slot(dev->ac97, dev->slot, PCI_INTC); + dev->sb = device_add(&sb_pro_compat_device); + dev->gameport = gameport_add(&gameport_sio_device); } diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index fb9d1da98..b29bc01d3 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -50,15 +50,15 @@ typedef struct _ac97_via_ { ac97_codec_t *codec[2][2]; ac97_via_sgd_t sgd[6]; - pc_timer_t timer_count; + pc_timer_t timer_count, timer_count_fm; uint64_t timer_latch, timer_fifo_latch; - int16_t out_l, out_r; + int16_t out_l, out_r, fm_out_l, fm_out_r; double cd_vol_l, cd_vol_r; - int16_t buffer[SOUNDBUFLEN * 2]; - int pos; + int16_t buffer[SOUNDBUFLEN * 2], fm_buffer[SOUNDBUFLEN * 2]; + int pos, fm_pos; } ac97_via_t; -//#define ENABLE_AC97_VIA_LOG 1 +#define ENABLE_AC97_VIA_LOG 1 #ifdef ENABLE_AC97_VIA_LOG int ac97_via_do_log = ENABLE_AC97_VIA_LOG; unsigned int ac97_via_lost_irqs = 0; @@ -111,7 +111,7 @@ ac97_via_read_status(void *priv, uint8_t modem) return ret; } - +#include <86box/nmi.h> static void ac97_via_update_irqs(ac97_via_t *dev, uint8_t iflag_clear) { @@ -473,6 +473,16 @@ ac97_via_update(ac97_via_t *dev) } +static void +ac97_via_update_fm(ac97_via_t *dev) +{ + for (; dev->fm_pos < sound_pos_global; dev->fm_pos++) { + dev->fm_buffer[dev->fm_pos*2] = dev->fm_out_l; + dev->fm_buffer[dev->fm_pos*2 + 1] = dev->fm_out_r; + } +} + + static void ac97_via_sgd_process(void *priv) { @@ -503,12 +513,12 @@ ac97_via_sgd_process(void *priv) sgd->sample_count &= 0xffffff; ac97_via_log("AC97 VIA: Starting SGD %d block at %08X start %08X len %06X flags %02X lostirqs %d\n", sgd->id >> 4, - sgd->entry_ptr, sgd->sample_ptr, sgd->sample_count, sgd->entry_flags, ac97_via_lost_irqs); + sgd->entry_ptr - 8, sgd->sample_ptr, sgd->sample_count, sgd->entry_flags, ac97_via_lost_irqs); } if (sgd->id & 0x10) { - /* Write channel: read data from FIFO. */ - mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); + /* Write channel: read data from FIFO. */ + mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); } else { /* Read channel: write data to FIFO. */ *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)]) = mem_readl_phys(sgd->sample_ptr); @@ -625,17 +635,40 @@ ac97_via_poll(void *priv) } +static void +ac97_via_poll_fm(void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + ac97_via_sgd_t *sgd = &dev->sgd[2]; /* FM Read */ + + timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); + + ac97_via_update_fm(dev); + + dev->fm_out_l = dev->fm_out_r = 0; + + /* Unknown format, assumed. */ + if ((sgd->fifo_end - sgd->fifo_pos) >= 2) { + dev->out_l = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + dev->out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + } +} + + static void ac97_via_get_buffer(int32_t *buffer, int len, void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; ac97_via_update(dev); + ac97_via_update_fm(dev); - for (int c = 0; c < len * 2; c++) + for (int c = 0; c < len * 2; c++) { buffer[c] += dev->buffer[c]; + buffer[c] += dev->fm_buffer[c]; + } - dev->pos = 0; + dev->pos = dev->fm_pos = 0; } @@ -669,10 +702,12 @@ ac97_via_init(const device_t *info) timer_add(&dev->sgd[i].timer, ac97_via_sgd_process, &dev->sgd[i], 0); } - /* Set up playback poller. */ + /* Set up playback pollers. */ timer_add(&dev->timer_count, ac97_via_poll, dev, 0); + timer_add(&dev->timer_count_fm, ac97_via_poll_fm, dev, 0); ac97_via_speed_changed(dev); timer_advance_u64(&dev->timer_count, dev->timer_latch); + timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); /* Set up playback handler. */ sound_add_handler(ac97_via_get_buffer, dev); From c2e9ba1db57a13eace63ffa101b6ce551df5e87d Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 22 Jul 2021 16:06:45 -0300 Subject: [PATCH 16/52] Add CS4297 codec to onboard ES1371 implementations --- src/include/86box/snd_ac97.h | 1 + src/machine/m_at_slot1.c | 12 ++++++++---- src/sound/snd_ac97_codec.c | 13 +++++++++++++ src/sound/snd_audiopci.c | 3 ++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index 9c4bd308a..da2bb8b95 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -41,6 +41,7 @@ extern ac97_codec_t **ac97_codec, **ac97_modem_codec; extern int ac97_codec_count, ac97_modem_codec_count; extern const device_t alc100_device; +extern const device_t cs4297_device; extern const device_t cs4297a_device; extern const device_t wm9701a_device; diff --git a/src/machine/m_at_slot1.c b/src/machine/m_at_slot1.c index a14d75cd7..535e8ad74 100644 --- a/src/machine/m_at_slot1.c +++ b/src/machine/m_at_slot1.c @@ -468,8 +468,10 @@ machine_at_tsunamiatx_init(const machine_t *model) device_add(&i440bx_device); device_add(&piix4e_device); - if (sound_card_current == SOUND_INTERNAL) - device_add(&es1371_onboard_device); + if (sound_card_current == SOUND_INTERNAL) { + device_add(&es1371_onboard_device); + device_add(&cs4297_device); /* found on other Tyan boards around the same time */ + } device_add(&pc87309_device); device_add(&keyboard_ps2_ami_pci_device); @@ -678,8 +680,10 @@ machine_at_ms6168_common_init(const machine_t *model) if (gfxcard == VID_INTERNAL) device_add(&voodoo_3_2000_agp_onboard_8m_device); - if (sound_card_current == SOUND_INTERNAL) - device_add(&es1371_onboard_device); + if (sound_card_current == SOUND_INTERNAL) { + device_add(&es1371_onboard_device); + device_add(&cs4297_device); + } } diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 57083d590..a4b3c7e1c 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -30,6 +30,7 @@ enum { AC97_CODEC_ALC100 = AC97_CODEC_ID('A', 'L', 'C', 0x20), + AC97_CODEC_CS4297 = AC97_CODEC_ID('C', 'R', 'Y', 0x03), AC97_CODEC_CS4297A = AC97_CODEC_ID('C', 'R', 'Y', 0x11), AC97_CODEC_WM9701A = AC97_CODEC_ID('W', 'M', 'L', 0x00) }; @@ -228,6 +229,18 @@ const device_t alc100_device = NULL }; +const device_t cs4297_device = +{ + "Crystal CS4297", + DEVICE_AC97, + AC97_CODEC_CS4297, + ac97_codec_init, ac97_codec_close, ac97_codec_reset, + { NULL }, + NULL, + NULL, + NULL +}; + const device_t cs4297a_device = { "Crystal CS4297A", diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index ee529c59f..a41b9afff 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -1366,7 +1366,8 @@ static void *es1371_init(const device_t *info) ac97_codec = &es1371->codec; ac97_codec_count = 1; - device_add(&cs4297a_device); + if (!info->local) + device_add(&cs4297a_device); return es1371; } From 1fc1171011ea8f593f2f3a2663d97d1a3fa61a74 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 22 Jul 2021 16:07:38 -0300 Subject: [PATCH 17/52] Return the same CS4297A revision VMware does --- src/sound/snd_ac97_codec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index a4b3c7e1c..6a6d45f87 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -31,7 +31,7 @@ enum { AC97_CODEC_ALC100 = AC97_CODEC_ID('A', 'L', 'C', 0x20), AC97_CODEC_CS4297 = AC97_CODEC_ID('C', 'R', 'Y', 0x03), - AC97_CODEC_CS4297A = AC97_CODEC_ID('C', 'R', 'Y', 0x11), + AC97_CODEC_CS4297A = AC97_CODEC_ID('C', 'R', 'Y', 0x13), AC97_CODEC_WM9701A = AC97_CODEC_ID('W', 'M', 'L', 0x00) }; From 42b4073b10a288331332a044b05400741c815360 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 22 Jul 2021 23:47:32 -0300 Subject: [PATCH 18/52] Fix build --- src/machine/m_at_slot1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/machine/m_at_slot1.c b/src/machine/m_at_slot1.c index 535e8ad74..c69226ebc 100644 --- a/src/machine/m_at_slot1.c +++ b/src/machine/m_at_slot1.c @@ -38,6 +38,7 @@ #include <86box/machine.h> #include <86box/sound.h> #include <86box/clock.h> +#include <86box/snd_ac97.h> int machine_at_p65up5_cpknd_init(const machine_t *model) From 562bbe167c50fa4a3c6ea55226b6f5e5732d2ef1 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 23 Jul 2021 01:07:53 -0300 Subject: [PATCH 19/52] Improvements to VIA AC97 per suggestions --- src/sound/snd_ac97_via.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index b29bc01d3..eb12234e5 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -111,34 +111,20 @@ ac97_via_read_status(void *priv, uint8_t modem) return ret; } -#include <86box/nmi.h> + static void ac97_via_update_irqs(ac97_via_t *dev, uint8_t iflag_clear) { + uint8_t do_irq = 0; + /* Check interrupt flags on all SGDs. */ - for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { - if (dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03)) { - ac97_via_log("AC97 VIA: Setting IRQ (sgd %d iflags %02X stuck %d)\n", - i, dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03), dev->irq_stuck); + for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) + do_irq |= (dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03)); - if (dev->irq_stuck && !iflag_clear) { -#ifdef ENABLE_AC97_VIA_LOG - ac97_via_lost_irqs++; -#endif - pci_clear_irq(dev->slot, dev->irq_pin); - } else { - pci_set_irq(dev->slot, dev->irq_pin); - } - dev->irq_stuck = !dev->irq_stuck; - - return; - } - } - - /* No interrupt pending. */ - //ac97_via_log("AC97 VIA: Clearing IRQ\n"); - pci_clear_irq(dev->slot, dev->irq_pin); - dev->irq_stuck = 0; + if (do_irq) + pci_set_irq(dev->slot, dev->irq_pin); + else + pci_clear_irq(dev->slot, dev->irq_pin); } @@ -495,7 +481,7 @@ ac97_via_sgd_process(void *priv) if (!sgd->sample_ptr) { /* Start at first entry if no pointer is present. */ if (!sgd->entry_ptr) - sgd->entry_ptr = (dev->sgd_regs[sgd->id | 0x7] << 24) | (dev->sgd_regs[sgd->id | 0x6] << 16) | (dev->sgd_regs[sgd->id | 0x5] << 8) | (dev->sgd_regs[sgd->id | 0x4] & 0xfe); + sgd->entry_ptr = *((uint32_t *) &dev->sgd_regs[sgd->id | 0x4]) & 0xfffffffe; /* Read entry. */ sgd->sample_ptr = mem_readl_phys(sgd->entry_ptr); @@ -517,8 +503,8 @@ ac97_via_sgd_process(void *priv) } if (sgd->id & 0x10) { - /* Write channel: read data from FIFO. */ - mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); + /* Write channel: read data from FIFO. */ + mem_writel_phys(sgd->sample_ptr, *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)])); } else { /* Read channel: write data to FIFO. */ *((uint32_t *) &sgd->fifo[sgd->fifo_end & (sizeof(sgd->fifo) - 1)]) = mem_readl_phys(sgd->sample_ptr); From 293c4a02810b9fddf80284054e19007756d03640 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 24 Jul 2021 22:37:05 -0300 Subject: [PATCH 20/52] Fix unused variable warning --- src/chipset/via_pipc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index b984aa07a..7c8757b81 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -551,7 +551,9 @@ pipc_fmnmi_read(uint16_t addr, void *priv) static void pipc_fmnmi_write(uint16_t addr, uint8_t val, void *priv) { +#ifdef ENABLE_PIPC_LOG pipc_t *dev = (pipc_t *) priv; +#endif pipc_log("PIPC: fmnmi_write(%02X, %02X)\n", addr & 0x03, val); } From 0fe3a712b00a1979381af5626a88cc97bdc2123a Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 24 Jul 2021 22:38:05 -0300 Subject: [PATCH 21/52] Move SGD restart to a dedicated flag variable --- src/sound/snd_ac97_via.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index eb12234e5..8ddc590a4 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -37,7 +37,7 @@ typedef struct { uint32_t entry_ptr, sample_ptr, fifo_pos, fifo_end; int32_t sample_count; - uint8_t entry_flags, fifo[32]; + uint8_t entry_flags, fifo[32], restart; pc_timer_t timer; } ac97_via_sgd_t; @@ -267,7 +267,8 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) /* Start at the specified entry pointer. */ dev->sgd[addr >> 4].sample_ptr = 0; - dev->sgd[addr >> 4].entry_ptr = (dev->sgd_regs[(addr & 0xf0) | 0x7] << 24) | (dev->sgd_regs[(addr & 0xf0) | 0x6] << 16) | (dev->sgd_regs[(addr & 0xf0) | 0x5] << 8) | (dev->sgd_regs[(addr & 0xf0) | 0x4] & 0xfe); + dev->sgd[addr >> 4].entry_ptr = *((uint32_t *) &dev->sgd_regs[(addr & 0xf0) | 0x4]) & 0xfffffffe; + dev->sgd[addr >> 4].restart = 1; /* Start the actual SGD process. */ timer_advance_u64(&dev->sgd[addr >> 4].timer, 0); @@ -478,7 +479,9 @@ ac97_via_sgd_process(void *priv) /* Process SGD if active, unless this is Audio Read and there's no room in the FIFO. */ if (((dev->sgd_regs[sgd->id] & 0xc4) == 0x80) && (sgd->id || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { /* Move on to the next block if no entry is present. */ - if (!sgd->sample_ptr) { + if (sgd->restart) { + sgd->restart = 0; + /* Start at first entry if no pointer is present. */ if (!sgd->entry_ptr) sgd->entry_ptr = *((uint32_t *) &dev->sgd_regs[sgd->id | 0x4]) & 0xfffffffe; @@ -489,9 +492,10 @@ ac97_via_sgd_process(void *priv) sgd->sample_count = mem_readl_phys(sgd->entry_ptr); sgd->entry_ptr += 4; #ifdef ENABLE_AC97_VIA_LOG - if ((sgd->sample_ptr == 0xffffffff) || (sgd->sample_ptr == 0x00000000) || - (sgd->sample_count == 0xffffffff) || (sgd->sample_count == 0x00000000)) - fatal("AC97 VIA: Invalid SGD %d entry at %08X\n", sgd->id >> 4, sgd->entry_ptr); + if (((sgd->sample_ptr == 0xffffffff) && (sgd->sample_count == 0xffffffff)) || + ((sgd->sample_ptr == 0x00000000) && (sgd->sample_count == 0x00000000))) + fatal("AC97 VIA: Invalid SGD %d entry %08X%08X at %08X\n", sgd->id >> 4, + sgd->sample_ptr, sgd->sample_count, sgd->entry_ptr - 8); #endif /* Extract flags from the most significant byte. */ @@ -553,6 +557,7 @@ ac97_via_sgd_process(void *priv) dev->sgd_regs[sgd->id] &= ~0x08; /* Go back to the starting block. */ + //sgd->entry_ptr = *((uint32_t *) &dev->sgd_regs[sgd->id | 0x4]) & 0xfffffffe; /* why does XP not like this? */ sgd->entry_ptr = 0; } else { ac97_via_log(" finish"); @@ -564,7 +569,7 @@ ac97_via_sgd_process(void *priv) ac97_via_log("\n"); /* Move on to a new block on the next run. */ - sgd->sample_ptr = sgd->sample_count = 0; + sgd->restart = 1; } } @@ -588,7 +593,6 @@ ac97_via_poll(void *priv) dev->out_l = dev->out_r = 0; - //pclog("fifo_end - fifo_pos = %d\n", sgd->fifo_end - sgd->fifo_pos); switch (dev->sgd_regs[0x02] & 0x30) { case 0x00: /* Mono, 8-bit PCM */ if ((sgd->fifo_end - sgd->fifo_pos) >= 1) From 07c61a62a3b491869a9333d3365ff59851a378b7 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 25 Jul 2021 19:18:46 -0300 Subject: [PATCH 22/52] ES1371: query volumes on every codec write (for codec resets) --- src/sound/snd_audiopci.c | 45 +++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index a41b9afff..d64066ccc 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -602,31 +602,28 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p) ac97_codec_write(es1371->codec, (val >> 16) & 0x7f, val & 0xff); ac97_codec_write(es1371->codec, ((val >> 16) & 0x7f) + 1, val >> 8); - switch ((val >> 16) & 0x7f) { - case 0x02: /* Master Volume */ - if (val & 0x8000) { - es1371->master_vol_l = es1371->master_vol_r = 0; - } else { - if (val & 0x2000) - es1371->master_vol_l = codec_attn[0]; - else - es1371->master_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; - if (val & 0x20) - es1371->master_vol_r = codec_attn[0]; - else - es1371->master_vol_r = codec_attn[0x1f - (val & 0x1f)]; - } - break; - - case 0x12: /* CD Volume */ - if (val & 0x8000) { - es1371->cd_vol_l = es1371->cd_vol_r = 0; - } else { - es1371->cd_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; - es1371->cd_vol_r = codec_attn[0x1f - (val & 0x1f)]; - } - break; + val = *((uint16_t *) &es1371->codec->regs[0x02]); /* Master Volume */ + if (val & 0x8000) { + es1371->master_vol_l = es1371->master_vol_r = 0; + } else { + if (val & 0x2000) + es1371->master_vol_l = codec_attn[0]; + else + es1371->master_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; + if (val & 0x20) + es1371->master_vol_r = codec_attn[0]; + else + es1371->master_vol_r = codec_attn[0x1f - (val & 0x1f)]; } + + val = *((uint16_t *) &es1371->codec->regs[0x12]); /* CD Volume */ + if (val & 0x8000) { + es1371->cd_vol_l = es1371->cd_vol_r = 0; + } else { + es1371->cd_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; + es1371->cd_vol_r = codec_attn[0x1f - (val & 0x1f)]; + } + break; } break; From b24d5219a6ed8d5a82aa7b7294caf8147b34fcb7 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 25 Jul 2021 22:43:04 -0300 Subject: [PATCH 23/52] Change some entries in the legacy CPU table conversion code to match renamed machines --- src/cpu/cpu_table.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/cpu/cpu_table.c b/src/cpu/cpu_table.c index fca0d60e3..b980c5cf0 100644 --- a/src/cpu/cpu_table.c +++ b/src/cpu/cpu_table.c @@ -1736,7 +1736,7 @@ const cpu_legacy_machine_t cpu_legacy_table[] = { {"dtk", cputables_8088}, {"genxt", cputables_8088}, {"jukopc", cputables_8088}, - {"open_xt", cputables_8088}, + {"openxt", cputables_8088}, {"pxxt", cputables_8088}, {"europc", cputables_europc}, {"tandy", cputables_europc}, @@ -1793,7 +1793,7 @@ const cpu_legacy_machine_t cpu_legacy_table[] = { {"shuttle386sx", cputables_i386SX_Am386SX_486SLC}, {"dtk386", cputables_i386SX_Am386SX_486SLC}, {"awardsx", cputables_i386SX_Am386SX_486SLC}, - {"cbm_sl386sx25", cputables_i386SX_Am386SX_486SLC}, + {"cmdsl386sx25", cputables_i386SX_Am386SX_486SLC}, {"kmxc02", cputables_i386SX_Am386SX_486SLC}, {"megapc", cputables_i386SX_Am386SX_486SLC}, {"ibmps2_m55sx", cputables_i386SX_Am386SX_486SLC_IBM486SLC}, @@ -1804,8 +1804,6 @@ const cpu_legacy_machine_t cpu_legacy_table[] = { {"asus386", cputables_i386DX_Am386DX_486DLC}, {"ustechnologies386", cputables_i386DX_Am386DX_486DLC}, {"award386dx", cputables_i386DX_Am386DX_486DLC}, - {"ami386dx", cputables_i386DX_Am386DX_486DLC}, - {"mr386dx", cputables_i386DX_Am386DX_486DLC}, {"ibmps2_m70_type3", cputables_i386DX_Am386DX_486DLC_IBM486BL}, {"ibmps2_m80", cputables_i386DX_Am386DX_486DLC_IBM486BL}, {"pb410a", cputables_i486_Am486_Cx486}, @@ -1923,7 +1921,6 @@ const cpu_legacy_machine_t cpu_legacy_table[] = { {"tsunamiatx", cputables_PentiumII_Celeron_Cyrix3}, {"p6sba", cputables_PentiumII_Celeron_Cyrix3}, {"ergox365", cputables_PentiumII_Celeron_Cyrix3}, - {"fw6400gx_s1", cputables_PentiumII_Celeron_Cyrix3}, {"ficka6130", cputables_PentiumII_Celeron_Cyrix3}, {"6gxu", cputables_Xeon}, {"fw6400gx", cputables_Xeon}, @@ -1937,7 +1934,7 @@ const cpu_legacy_machine_t cpu_legacy_table[] = { {"63a", cputables_Celeron_Cyrix3}, {"apas3", cputables_Celeron_Cyrix3}, {"wcf681", cputables_Celeron_Cyrix3}, - {"6via85x", cputables_Celeron_Cyrix3}, + {"6via90ap", cputables_Celeron_Cyrix3}, {"p6bap", cputables_Celeron_Cyrix3}, {"603tcf", cputables_Celeron_Cyrix3}, {"vpc2007", cputables_PentiumIID_Celeron}, From 2fdda7bd4720d58df5e11264128b7cbcac18b27f Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 25 Jul 2021 22:46:51 -0300 Subject: [PATCH 24/52] Migrate enhanced Am486 to a standard naming convention --- src/config.c | 7 ++++++- src/cpu/cpu_table.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index f9347a0a4..cf66f160b 100644 --- a/src/config.c +++ b/src/config.c @@ -687,7 +687,12 @@ load_machine(void) cpu_f = NULL; p = config_get_string(cat, "cpu_family", NULL); if (p) { - cpu_f = cpu_get_family(p); + if (! strcmp(p, "enh_am486dx2")) /* migrate modified names */ + cpu_f = cpu_get_family("am486dx2_slenh"); + else if (! strcmp(p, "enh_am486dx4")) /* migrate modified names */ + cpu_f = cpu_get_family("am486dx4_slenh"); + else + cpu_f = cpu_get_family(p); if (cpu_f && !cpu_family_is_eligible(cpu_f, machine)) /* only honor eligible families */ cpu_f = NULL; diff --git a/src/cpu/cpu_table.c b/src/cpu/cpu_table.c index b980c5cf0..0bc66e1c1 100644 --- a/src/cpu/cpu_table.c +++ b/src/cpu/cpu_table.c @@ -493,7 +493,7 @@ const cpu_family_t cpu_families[] = { .package = CPU_PKG_SOCKET3, .manufacturer = "AMD", .name = "Am486DX2 (Enhanced)", - .internal_name = "enh_am486dx2", + .internal_name = "am486dx2_slenh", .cpus = (const CPU[]) { {"66", CPU_ENH_Am486DX, fpus_internal, 66666666, 2, 5000, 0x435, 0x435, 0, CPU_SUPPORTS_DYNAREC, 12,12, 6, 6, 8}, {"80", CPU_ENH_Am486DX, fpus_internal, 80000000, 2, 5000, 0x435, 0x435, 0, CPU_SUPPORTS_DYNAREC, 14,14, 6, 6, 10}, @@ -503,7 +503,7 @@ const cpu_family_t cpu_families[] = { .package = CPU_PKG_SOCKET3, .manufacturer = "AMD", .name = "Am486DX4 (Enhanced)", - .internal_name = "enh_am486dx4", + .internal_name = "am486dx4_slenh", .cpus = (const CPU[]) { {"75", CPU_ENH_Am486DX, fpus_internal, 75000000, 3.0, 5000, 0x482, 0x482, 0, CPU_SUPPORTS_DYNAREC, 12,12, 9, 9, 9}, {"100", CPU_ENH_Am486DX, fpus_internal, 100000000, 3.0, 5000, 0x482, 0x482, 0, CPU_SUPPORTS_DYNAREC, 15,15, 9, 9, 12}, From 45ebe545444a7e6242f88e9e3ab1e43279cb3f41 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 25 Jul 2021 22:48:04 -0300 Subject: [PATCH 25/52] Fix CPU table formatting --- src/cpu/cpu_table.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/cpu/cpu_table.c b/src/cpu/cpu_table.c index 0bc66e1c1..57aa3f7ca 100644 --- a/src/cpu/cpu_table.c +++ b/src/cpu/cpu_table.c @@ -316,8 +316,7 @@ const cpu_family_t cpu_families[] = { {"33", CPU_i486SX, fpus_486sx, 33333333, 1, 5000, 0x422, 0, 0, CPU_SUPPORTS_DYNAREC, 6, 6,3,3, 4}, {"", 0} } - }, - { + }, { .package = CPU_PKG_SOCKET1, .manufacturer = "Intel", .name = "i486SX (SL-Enhanced)", @@ -327,8 +326,7 @@ const cpu_family_t cpu_families[] = { {"33", CPU_i486SX_SLENH, fpus_486sx, 33333333, 1, 5000, 0x42a, 0x42a, 0, CPU_SUPPORTS_DYNAREC, 6, 6,3,3, 4}, {"", 0} } - }, - { + }, { .package = CPU_PKG_SOCKET1, .manufacturer = "Intel", .name = "i486SX2", @@ -349,8 +347,7 @@ const cpu_family_t cpu_families[] = { {"50", CPU_i486DX, fpus_internal, 50000000, 1, 5000, 0x411, 0, 0, CPU_SUPPORTS_DYNAREC, 8, 8,4,4, 6}, {"", 0} } - }, - { + }, { .package = CPU_PKG_SOCKET1, .manufacturer = "Intel", .name = "i486DX (SL-Enhanced)", @@ -371,8 +368,7 @@ const cpu_family_t cpu_families[] = { {"66", CPU_i486DX, fpus_internal, 66666666, 2, 5000, 0x433, 0, 0, CPU_SUPPORTS_DYNAREC, 12,12,6,6, 8}, {"", 0} } - }, - { + }, { .package = CPU_PKG_SOCKET1, .manufacturer = "Intel", .name = "i486DX2 (SL-Enhanced)", @@ -383,7 +379,7 @@ const cpu_family_t cpu_families[] = { {"66", CPU_i486DX_SLENH, fpus_internal, 66666666, 2, 5000, 0x435, 0x435, 0, CPU_SUPPORTS_DYNAREC, 12,12,6,6, 8}, {"", 0} } - }, { + }, { .package = CPU_PKG_SOCKET3_PC330, .manufacturer = "Intel", .name = "i486DX2", @@ -454,8 +450,7 @@ const cpu_family_t cpu_families[] = { {"80", CPU_Am486DX, fpus_internal, 80000000, 2, 5000, 0x432, 0, 0, CPU_SUPPORTS_DYNAREC, 14,14, 6, 6, 10}, {"", 0} } - }, - { + }, { .package = CPU_PKG_SOCKET1, .manufacturer = "AMD", .name = "Am486DXL", From 42eada3122d575ad039f596773c0d6c4d0732383 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 25 Jul 2021 22:58:03 -0300 Subject: [PATCH 26/52] VIA AC97 improvements, almost ready --- src/chipset/via_pipc.c | 5 + src/include/86box/snd_ac97.h | 1 + src/sound/snd_ac97_via.c | 197 ++++++++++++++++++++++------------- 3 files changed, 129 insertions(+), 74 deletions(-) diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 7c8757b81..85b36bf8b 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -1223,6 +1223,11 @@ pipc_write(int func, int addr, uint8_t val, void *priv) dev->ac97_regs[func][addr] = val; break; + case 0x41: + dev->ac97_regs[func][addr] = val; + ac97_via_write_control(dev->ac97, func, val); + break; + case 0x42: case 0x4a: case 0x4b: dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; gameport_remap(dev->gameport, (dev->ac97_regs[0][0x42] & 0x08) ? ((dev->ac97_regs[0][0x4b] << 8) | dev->ac97_regs[0][0x4a]) : 0); diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index da2bb8b95..d8f165dbd 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -30,6 +30,7 @@ extern void ac97_codec_reset(void *priv); extern void ac97_via_set_slot(void *priv, int slot, int irq_pin); extern uint8_t ac97_via_read_status(void *priv, uint8_t modem); +extern void ac97_via_write_control(void *priv, uint8_t modem, uint8_t val); extern void ac97_via_remap_audio_sgd(void *priv, uint16_t new_io_base, uint8_t enable); extern void ac97_via_remap_modem_sgd(void *priv, uint16_t new_io_base, uint8_t enable); extern void ac97_via_remap_audio_codec(void *priv, uint16_t new_io_base, uint8_t enable); diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 8ddc590a4..44b9ad825 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -32,7 +32,7 @@ typedef struct { - uint8_t id; + uint8_t id, always_run; struct _ac97_via_ *dev; uint32_t entry_ptr, sample_ptr, fifo_pos, fifo_end; @@ -44,7 +44,13 @@ typedef struct { typedef struct _ac97_via_ { uint16_t audio_sgd_base, audio_codec_base, modem_sgd_base, modem_codec_base; - uint8_t sgd_regs[256], irq_stuck; + uint8_t sgd_regs[256], pcm_enabled: 1, fm_enabled: 1; + struct { + union { + uint8_t regs_codec[2][128]; + uint8_t regs_linear[256]; + }; + } codec_shadow[2]; int slot, irq_pin; ac97_codec_t *codec[2][2]; @@ -61,7 +67,6 @@ typedef struct _ac97_via_ { #define ENABLE_AC97_VIA_LOG 1 #ifdef ENABLE_AC97_VIA_LOG int ac97_via_do_log = ENABLE_AC97_VIA_LOG; -unsigned int ac97_via_lost_irqs = 0; static void ac97_via_log(const char *fmt, ...) @@ -112,19 +117,54 @@ ac97_via_read_status(void *priv, uint8_t modem) } -static void -ac97_via_update_irqs(ac97_via_t *dev, uint8_t iflag_clear) +void +ac97_via_write_control(void *priv, uint8_t modem, uint8_t val) { - uint8_t do_irq = 0; + ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t i; - /* Check interrupt flags on all SGDs. */ - for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) - do_irq |= (dev->sgd_regs[i << 4] & (dev->sgd_regs[(i << 4) | 0x02] & 0x03)); + ac97_via_log("AC97 VIA %d: write_control(%02X)\n", modem, val); - if (do_irq) - pci_set_irq(dev->slot, dev->irq_pin); - else - pci_clear_irq(dev->slot, dev->irq_pin); + /* Reset codecs if requested. */ + if (val & 0x40) { + for (i = 0; i <= 1; i++) { + if (dev->codec[modem][i]) + ac97_codec_reset(dev->codec[modem][i]); + } + } + + if (!modem) { + /* Start or stop PCM playback. */ + i = (val & 0xf4) == 0xc4; + if (i && !dev->pcm_enabled) + timer_advance_u64(&dev->timer_count, dev->timer_latch); + dev->pcm_enabled = i; + + /* Start or stop FM playback. */ + i = (val & 0xf2) == 0xc2; + if (i && !dev->fm_enabled) + timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); + dev->fm_enabled = i; + } +} + + +static void +ac97_via_update_irqs(ac97_via_t *dev) +{ + /* Check interrupt flags in all SGDs. */ + uint8_t i, sgd_id; + for (i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { + sgd_id = i << 4; + /* Stop immediately if any flag is set. Doing it this way optimizes + rising edges for the playback SGD (0 - first to be checked). */ + if (dev->sgd_regs[sgd_id] & (dev->sgd_regs[sgd_id | 0x2] & 0x03)) { + pci_set_irq(dev->slot, dev->irq_pin); + return; + } + } + + pci_clear_irq(dev->slot, dev->irq_pin); } @@ -245,12 +285,10 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) switch (addr & 0xf) { case 0x0: /* Clear RWC status bits. */ - for (i = 0x01; i <= 0x04; i <<= 1) { - if (val & i) - dev->sgd_regs[addr] &= ~i; - } + dev->sgd_regs[addr] &= ~(val & 0x07); - ac97_via_update_irqs(dev, 1); + /* Update status interrupts. */ + ac97_via_update_irqs(dev); return; @@ -258,7 +296,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) /* Start SGD if requested. */ if (val & 0x80) { if (dev->sgd_regs[addr & 0xf0] & 0x80) { - /* Queue SGD trigger. */ + /* Queue SGD trigger if already running. */ dev->sgd_regs[addr & 0xf0] |= 0x08; } else { /* Start SGD immediately. */ @@ -271,7 +309,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) dev->sgd[addr >> 4].restart = 1; /* Start the actual SGD process. */ - timer_advance_u64(&dev->sgd[addr >> 4].timer, 0); + ac97_via_sgd_process(&dev->sgd[addr >> 4]); } } /* Stop SGD if requested. */ @@ -314,11 +352,15 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) /* Read from or write to codec. */ if (codec) { if (val & 0x80) { - dev->sgd_regs[0x80] = ac97_codec_read(codec, val & 0x7e); - dev->sgd_regs[0x81] = ac97_codec_read(codec, (val & 0x7e) | 1); + val &= 0x7e; + dev->sgd_regs[0x80] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); + val |= 1; + dev->sgd_regs[0x81] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); } else { - ac97_codec_write(codec, val & 0x7e, dev->sgd_regs[0x80]); - ac97_codec_write(codec, (val & 0x7e) | 1, dev->sgd_regs[0x81]); + val &= 0x7e; + ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x80]); + val |= 1; + ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x81]); } /* Flag data/status/index for this codec as valid. */ @@ -330,23 +372,12 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) break; case 0x83: - val &= 0xca; - - /* Clear RWC bits. */ - for (i = 0x02; i <= 0x08; i <<= 2) { -#if 0 /* race condition with Linux clearing bits and starting SGD on the same dword write */ - if (val & i) - val &= ~i; - else - val |= dev->sgd_regs[addr] & i; + /* Clear RWC status bits. */ +#if 0 /* race condition with Linux accessing a register and clearing status bits on the same dword write */ + val = (dev->sgd_regs[addr] & ~(val & 0x0a)) | (val & 0xc0); #else - /* Don't flag data/status/index as valid if the codec is absent. */ - if (dev->codec[modem][!!(val & 0x40)]) - val |= i; - else - val &= ~i; + val = dev->sgd_regs[addr] | 0x0a | (val & 0xc0); #endif - } break; } } @@ -393,10 +424,7 @@ ac97_via_codec_read(uint16_t addr, void *priv) addr &= 0xff; uint8_t ret = 0xff; - /* Bit 7 selects secondary codec. */ - ac97_codec_t *codec = dev->codec[modem][addr >> 7]; - if (codec) - ret = ac97_codec_read(codec, addr & 0x7f); + ret = dev->codec_shadow[modem].regs_linear[addr]; ac97_via_log("AC97 VIA %d: codec_read(%02X) = %02X\n", modem, addr, ret); @@ -413,10 +441,8 @@ ac97_via_codec_write(uint16_t addr, uint8_t val, void *priv) ac97_via_log("AC97 VIA %d: codec_write(%02X, %02X)\n", modem, addr, val); - /* Bit 7 selects secondary codec. */ - ac97_codec_t *codec = dev->codec[modem][addr >> 7]; - if (codec) - ac97_codec_write(codec, addr & 0x7f, val); + /* Unknown behavior, maybe it does write to the shadow registers? */ + dev->codec_shadow[modem].regs_linear[addr] = val; } @@ -476,11 +502,19 @@ ac97_via_sgd_process(void *priv) ac97_via_sgd_t *sgd = (ac97_via_sgd_t *) priv; ac97_via_t *dev = sgd->dev; - /* Process SGD if active, unless this is Audio Read and there's no room in the FIFO. */ - if (((dev->sgd_regs[sgd->id] & 0xc4) == 0x80) && (sgd->id || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { + /* Stop if this SGD is not active. */ + uint8_t sgd_status = dev->sgd_regs[sgd->id] & 0xc4; + if (!(sgd_status & 0x80)) + return; + + /* Schedule next run. */ + timer_advance_u64(&sgd->timer, dev->timer_fifo_latch); + + /* Process SGD if it's active, and the FIFO has room or is disabled. */ + if ((sgd_status == 0x80) && (sgd->always_run || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { /* Move on to the next block if no entry is present. */ - if (sgd->restart) { - sgd->restart = 0; + if (sgd->restart) { + sgd->restart = 0; /* Start at first entry if no pointer is present. */ if (!sgd->entry_ptr) @@ -502,8 +536,8 @@ ac97_via_sgd_process(void *priv) sgd->entry_flags = sgd->sample_count >> 24; sgd->sample_count &= 0xffffff; - ac97_via_log("AC97 VIA: Starting SGD %d block at %08X start %08X len %06X flags %02X lostirqs %d\n", sgd->id >> 4, - sgd->entry_ptr - 8, sgd->sample_ptr, sgd->sample_count, sgd->entry_flags, ac97_via_lost_irqs); + ac97_via_log("AC97 VIA: Starting SGD %d block at %08X start %08X len %06X flags %02X\n", sgd->id >> 4, + sgd->entry_ptr - 8, sgd->sample_ptr, sgd->sample_count, sgd->entry_flags); } if (sgd->id & 0x10) { @@ -557,8 +591,7 @@ ac97_via_sgd_process(void *priv) dev->sgd_regs[sgd->id] &= ~0x08; /* Go back to the starting block. */ - //sgd->entry_ptr = *((uint32_t *) &dev->sgd_regs[sgd->id | 0x4]) & 0xfffffffe; /* why does XP not like this? */ - sgd->entry_ptr = 0; + sgd->entry_ptr = 0; /* ugly, but Windows XP plays too fast if the pointer is reloaded now */ } else { ac97_via_log(" finish"); @@ -568,16 +601,13 @@ ac97_via_sgd_process(void *priv) } ac97_via_log("\n"); + /* Fire any requested status interrupts. */ + ac97_via_update_irqs(dev); + /* Move on to a new block on the next run. */ sgd->restart = 1; } } - - ac97_via_update_irqs(dev, 0); - - /* Continue SGD processing if active or an interrupt is pending. */ - if (dev->sgd_regs[sgd->id] & (0x80 | (dev->sgd_regs[sgd->id | 0x02] & 0x03))) - timer_advance_u64(&sgd->timer, dev->timer_fifo_latch); } @@ -587,22 +617,27 @@ ac97_via_poll(void *priv) ac97_via_t *dev = (ac97_via_t *) priv; ac97_via_sgd_t *sgd = &dev->sgd[0]; /* Audio Read */ - timer_advance_u64(&dev->timer_count, dev->timer_latch); + /* Schedule next run if PCM playback is enabled. */ + if (dev->pcm_enabled) + timer_advance_u64(&dev->timer_count, dev->timer_latch); + /* Update audio buffer. */ ac97_via_update(dev); - dev->out_l = dev->out_r = 0; - + /* Feed next sample from the FIFO. */ switch (dev->sgd_regs[0x02] & 0x30) { case 0x00: /* Mono, 8-bit PCM */ - if ((sgd->fifo_end - sgd->fifo_pos) >= 1) + if ((sgd->fifo_end - sgd->fifo_pos) >= 1) { dev->out_l = dev->out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + return; + } break; case 0x10: /* Stereo, 8-bit PCM */ if ((sgd->fifo_end - sgd->fifo_pos) >= 2) { dev->out_l = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; dev->out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + return; } break; @@ -610,6 +645,7 @@ ac97_via_poll(void *priv) if ((sgd->fifo_end - sgd->fifo_pos) >= 2) { dev->out_l = dev->out_r = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); sgd->fifo_pos += 2; + return; } break; @@ -619,9 +655,13 @@ ac97_via_poll(void *priv) sgd->fifo_pos += 2; dev->out_r = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); sgd->fifo_pos += 2; + return; } break; } + + /* Feed silence if the FIFO is empty. */ + dev->out_l = dev->out_r = 0; } @@ -631,17 +671,23 @@ ac97_via_poll_fm(void *priv) ac97_via_t *dev = (ac97_via_t *) priv; ac97_via_sgd_t *sgd = &dev->sgd[2]; /* FM Read */ - timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); + /* Schedule next run if FM playback is enabled. */ + if (dev->fm_enabled) + timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); + /* Update FM audio buffer. */ ac97_via_update_fm(dev); - dev->fm_out_l = dev->fm_out_r = 0; - - /* Unknown format, assumed. */ + /* Feed next sample from the FIFO. + Unknown data format assumed to be 8-bit stereo. */ if ((sgd->fifo_end - sgd->fifo_pos) >= 2) { - dev->out_l = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; - dev->out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + dev->fm_out_l = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + dev->fm_out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + return; } + + /* Feed silence if the FIFO is empty. */ + dev->fm_out_l = dev->fm_out_r = 0; } @@ -654,10 +700,11 @@ ac97_via_get_buffer(int32_t *buffer, int len, void *priv) ac97_via_update_fm(dev); for (int c = 0; c < len * 2; c++) { - buffer[c] += dev->buffer[c]; + buffer[c] += dev->buffer[c] / 2; buffer[c] += dev->fm_buffer[c]; } + /* Feed silence if the FIFO is empty. */ dev->pos = dev->fm_pos = 0; } @@ -689,6 +736,10 @@ ac97_via_init(const device_t *info) dev->sgd[i].id = i << 4; dev->sgd[i].dev = dev; + /* Disable the FIFO on SGDs we don't care about. */ + if ((i != 0) && (i != 2)) + dev->sgd[i].always_run = 1; + timer_add(&dev->sgd[i].timer, ac97_via_sgd_process, &dev->sgd[i], 0); } @@ -696,8 +747,6 @@ ac97_via_init(const device_t *info) timer_add(&dev->timer_count, ac97_via_poll, dev, 0); timer_add(&dev->timer_count_fm, ac97_via_poll_fm, dev, 0); ac97_via_speed_changed(dev); - timer_advance_u64(&dev->timer_count, dev->timer_latch); - timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); /* Set up playback handler. */ sound_add_handler(ac97_via_get_buffer, dev); From 70285df61b19d4232853ef7ec6d7644176d52d58 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Mon, 26 Jul 2021 00:19:39 -0300 Subject: [PATCH 27/52] The start of AC97 volume control --- src/include/86box/snd_ac97.h | 1 + src/sound/snd_ac97_codec.c | 34 +++++++++++++++++++++++++++++ src/sound/snd_ac97_via.c | 42 ++++++++++++++++++++++++++---------- src/sound/snd_audiopci.c | 41 +++++++---------------------------- 4 files changed, 74 insertions(+), 44 deletions(-) diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index d8f165dbd..a72a874d9 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -27,6 +27,7 @@ typedef struct { extern uint8_t ac97_codec_read(ac97_codec_t *dev, uint8_t reg); extern void ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val); extern void ac97_codec_reset(void *priv); +extern void ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r); extern void ac97_via_set_slot(void *priv, int slot, int irq_pin); extern uint8_t ac97_via_read_status(void *priv, uint8_t modem); diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 6a6d45f87..d215b8145 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -54,6 +54,11 @@ ac97_codec_log(const char *fmt, ...) #define ac97_codec_log(fmt, ...) #endif +static const int32_t codec_attn[] = { + 25, 32, 41, 51, 65, 82, 103, 130, 164, 206, 260, 327, 412, 519, 653, 822, + 1036, 1304, 1641, 2067, 2602, 3276, 4125, 5192, 6537, 8230, 10362, 13044, 16422, 20674, 26027, 32767 +}; + ac97_codec_t **ac97_codec = NULL, **ac97_modem_codec = NULL; int ac97_codec_count = 0, ac97_modem_codec_count = 0; @@ -182,6 +187,35 @@ ac97_codec_reset(void *priv) } +void +ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) +{ + ac97_codec_t *dev = (ac97_codec_t *) priv; + uint8_t r_val = dev->regs[reg], + l_val = dev->regs[reg | 1]; + + if (l_val & 0x80) { /* mute */ + *l = 0; + *r = 0; + return; + } + + if (reg < 0x10) { /* 6-bit volume */ + if (l_val & 0x20) + *l = codec_attn[0]; + else + *l = codec_attn[0x1f - (l_val & 0x1f)]; + if (r_val & 0x20) + *r = codec_attn[0]; + else + *r = codec_attn[0x1f - (r_val & 0x1f)]; + } else { /* 5-bit gain */ + *l = codec_attn[0x1f - (l_val & 0x1f)]; + *r = codec_attn[0x1f - (r_val & 0x1f)]; + } +} + + static void * ac97_codec_init(const device_t *info) { diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 44b9ad825..bc2ec8ee9 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -59,12 +59,12 @@ typedef struct _ac97_via_ { pc_timer_t timer_count, timer_count_fm; uint64_t timer_latch, timer_fifo_latch; int16_t out_l, out_r, fm_out_l, fm_out_r; - double cd_vol_l, cd_vol_r; - int16_t buffer[SOUNDBUFLEN * 2], fm_buffer[SOUNDBUFLEN * 2]; + int master_vol_l, master_vol_r, pcm_vol_l, pcm_vol_r, cd_vol_l, cd_vol_r; + int32_t buffer[SOUNDBUFLEN * 2], fm_buffer[SOUNDBUFLEN * 2]; int pos, fm_pos; } ac97_via_t; -#define ENABLE_AC97_VIA_LOG 1 + #ifdef ENABLE_AC97_VIA_LOG int ac97_via_do_log = ENABLE_AC97_VIA_LOG; @@ -85,6 +85,7 @@ ac97_via_log(const char *fmt, ...) static void ac97_via_sgd_process(void *priv); +static void ac97_via_update_volumes(ac97_via_t *dev, ac97_codec_t *codec); void @@ -125,11 +126,15 @@ ac97_via_write_control(void *priv, uint8_t modem, uint8_t val) ac97_via_log("AC97 VIA %d: write_control(%02X)\n", modem, val); - /* Reset codecs if requested. */ - if (val & 0x40) { - for (i = 0; i <= 1; i++) { - if (dev->codec[modem][i]) + /* Reset and/or update volumes on all codecs. */ + for (i = 0; i <= 1; i++) { + if (dev->codec[modem][i]) { + /* Reset codec if requested. */ + if (val & 0x40) ac97_codec_reset(dev->codec[modem][i]); + + /* Update volumes. */ + ac97_via_update_volumes(dev, dev->codec[modem][i]); } } @@ -168,6 +173,16 @@ ac97_via_update_irqs(ac97_via_t *dev) } +static void +ac97_via_update_volumes(ac97_via_t *dev, ac97_codec_t *codec) { + ac97_codec_getattn(codec, 0x02, &dev->master_vol_l, &dev->master_vol_r); + ac97_codec_getattn(codec, 0x18, &dev->pcm_vol_l, &dev->pcm_vol_r); + ac97_codec_getattn(codec, 0x12, &dev->cd_vol_l, &dev->cd_vol_r); + + pclog("master %d %d\npcm %d %d\ncd %d %d\n", dev->master_vol_l, dev->master_vol_r, dev->pcm_vol_l, dev->pcm_vol_r, dev->cd_vol_l, dev->cd_vol_r); +} + + uint8_t ac97_via_sgd_read(uint16_t addr, void *priv) { @@ -361,6 +376,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x80]); val |= 1; ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x81]); + + /* Update volumes. */ + ac97_via_update_volumes(dev, codec); } /* Flag data/status/index for this codec as valid. */ @@ -479,9 +497,12 @@ ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t enable) static void ac97_via_update(ac97_via_t *dev) { + int32_t l = (((dev->out_l * dev->pcm_vol_l) >> 15) * dev->master_vol_l) >> 15, + r = (((dev->out_r * dev->pcm_vol_r) >> 15) * dev->master_vol_r) >> 15; + for (; dev->pos < sound_pos_global; dev->pos++) { - dev->buffer[dev->pos*2] = dev->out_l; - dev->buffer[dev->pos*2 + 1] = dev->out_r; + dev->buffer[dev->pos*2] = l; + dev->buffer[dev->pos*2 + 1] = r; } } @@ -701,10 +722,9 @@ ac97_via_get_buffer(int32_t *buffer, int len, void *priv) for (int c = 0; c < len * 2; c++) { buffer[c] += dev->buffer[c] / 2; - buffer[c] += dev->fm_buffer[c]; + buffer[c] += dev->fm_buffer[c] / 2; } - /* Feed silence if the FIFO is empty. */ dev->pos = dev->fm_pos = 0; } diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index d64066ccc..cd8288d4d 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -148,12 +148,6 @@ typedef struct { #define FORMAT_MONO_16 2 #define FORMAT_STEREO_16 3 -const int32_t codec_attn[]= { - 25,32,41,51,65,82,103,130,164,206,260,327,412,519,653, - 822,1036,1304,1641,2067,2602,3276,4125,5192,6537,8230,10362,13044, - 16422,20674,26027,32767 -}; - static void es1371_fetch(es1371_t *es1371, int dac_nr); static void update_legacy(es1371_t *es1371, uint32_t old_legacy_ctrl); @@ -595,35 +589,16 @@ static void es1371_outl(uint16_t port, uint32_t val, void *p) case 0x14: if (val & CODEC_READ) { es1371->codec_ctrl &= 0x00ff0000; - es1371->codec_ctrl |= ac97_codec_read(es1371->codec, (val >> 16) & 0x7f); - es1371->codec_ctrl |= ac97_codec_read(es1371->codec, ((val >> 16) & 0x7f) + 1) << 8; + val = (val >> 16) & 0x7e; + es1371->codec_ctrl |= ac97_codec_read(es1371->codec, val); + es1371->codec_ctrl |= ac97_codec_read(es1371->codec, val | 1) << 8; } else { - es1371->codec_ctrl &= 0x00ffffff; - ac97_codec_write(es1371->codec, (val >> 16) & 0x7f, val & 0xff); - ac97_codec_write(es1371->codec, ((val >> 16) & 0x7f) + 1, val >> 8); + es1371->codec_ctrl = val & 0x00ffffff; + ac97_codec_write(es1371->codec, (val >> 16) & 0x7e, val & 0xff); + ac97_codec_write(es1371->codec, ((val >> 16) & 0x7e) | 1, val >> 8); - val = *((uint16_t *) &es1371->codec->regs[0x02]); /* Master Volume */ - if (val & 0x8000) { - es1371->master_vol_l = es1371->master_vol_r = 0; - } else { - if (val & 0x2000) - es1371->master_vol_l = codec_attn[0]; - else - es1371->master_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; - if (val & 0x20) - es1371->master_vol_r = codec_attn[0]; - else - es1371->master_vol_r = codec_attn[0x1f - (val & 0x1f)]; - } - - val = *((uint16_t *) &es1371->codec->regs[0x12]); /* CD Volume */ - if (val & 0x8000) { - es1371->cd_vol_l = es1371->cd_vol_r = 0; - } else { - es1371->cd_vol_l = codec_attn[0x1f - ((val >> 8) & 0x1f)]; - es1371->cd_vol_r = codec_attn[0x1f - (val & 0x1f)]; - } - break; + ac97_codec_getattn(es1371->codec, 0x02, &es1371->master_vol_l, &es1371->master_vol_r); + ac97_codec_getattn(es1371->codec, 0x12, &es1371->cd_vol_l, &es1371->cd_vol_r); } break; From 35d0aa0df4c5ad2f58f17db70943cd8f0c2c06c0 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 27 Jul 2021 16:01:17 -0300 Subject: [PATCH 28/52] Change VIA FM and other behavior to match real hardware, and add "real fake OPL" mode --- src/chipset/via_pipc.c | 111 ++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 69 deletions(-) diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 85b36bf8b..18c3296a1 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -75,7 +75,7 @@ typedef struct ide_regs[256], usb_regs[2][256], power_regs[256], - ac97_regs[2][256], fmnmi_regs[4], fm_regs[4]; + ac97_regs[2][256], fmnmi_regs[4]; sff8038i_t *bm[2]; nvr_t *nvr; int nvr_enabled, slot; @@ -475,30 +475,10 @@ static uint8_t pipc_midigame_read(uint16_t addr, void *priv) { pipc_t *dev = (pipc_t *) priv; - uint8_t ret = 0xff; - addr &= 0x03; - switch (addr) { - case 0x02: case 0x03: - ret = pipc_read(5, 0x48 + addr, dev); - break; - } - - return ret; -} - - -static void -pipc_midigame_write(uint16_t addr, uint8_t val, void *priv) -{ - pipc_t *dev = (pipc_t *) priv; - - addr &= 0x03; - switch (addr) { - case 0x02: case 0x03: - pipc_write(5, 0x48 + addr, val, dev); - break; - } + /* This BAR apparently doesn't work at all on a real 686B. It doesn't react to writes, + and reads always return 0x80 or 0xff depending on AC97 audio register 0x42 bit 7. */ + return (dev->ac97_regs[0][0x42] & 0x80) ? 0x80 : 0xff; } @@ -509,12 +489,12 @@ pipc_midigame_handlers(pipc_t *dev, uint8_t modem) return; if (dev->midigame_base) - io_removehandler(dev->midigame_base, 4, pipc_midigame_read, NULL, NULL, pipc_midigame_write, NULL, NULL, dev); + io_removehandler(dev->midigame_base, 4, pipc_midigame_read, NULL, NULL, NULL, NULL, NULL, dev); dev->midigame_base = (dev->ac97_regs[0][0x19] << 8) | (dev->ac97_regs[0][0x18] & 0xfc); if (dev->midigame_base && (dev->ac97_regs[0][0x04] & PCI_COMMAND_IO)) - io_sethandler(dev->midigame_base, 4, pipc_midigame_read, NULL, NULL, pipc_midigame_write, NULL, NULL, dev); + io_sethandler(dev->midigame_base, 4, pipc_midigame_read, NULL, NULL, NULL, NULL, NULL, dev); } @@ -539,31 +519,29 @@ pipc_fmnmi_read(uint16_t addr, void *priv) pipc_log("PIPC: fmnmi_read(%02X) = %02X\n", addr & 0x03, ret); - if (dev->ac97_regs[0][0x48] & 0x04) - smi_line = 0; - else - nmi = 0; - - return ret; -} - - -static void -pipc_fmnmi_write(uint16_t addr, uint8_t val, void *priv) -{ -#ifdef ENABLE_PIPC_LOG - pipc_t *dev = (pipc_t *) priv; +#ifdef VIA_PIPC_FM_EMULATION + /* Clear NMI/SMI if enabled. */ + if (dev->ac97_regs[0][0x48] & 0x01) { + if (dev->ac97_regs[0][0x48] & 0x04) + smi_line = 0; + else + nmi = 0; + } #endif - pipc_log("PIPC: fmnmi_write(%02X, %02X)\n", addr & 0x03, val); + return ret; } static uint8_t pipc_fm_read(uint16_t addr, void *priv) { +#ifdef VIA_PIPC_FM_EMULATION + uint8_t ret = 0x00; +#else pipc_t *dev = (pipc_t *) priv; uint8_t ret = opl3_read(addr, &dev->sb->opl); +#endif pipc_log("PIPC: fm_read(%02X) = %02X\n", addr & 0x03, ret); @@ -578,17 +556,26 @@ pipc_fm_write(uint16_t addr, uint8_t val, void *priv) pipc_log("PIPC: fm_write(%02X, %02X)\n", addr & 0x03, val); +#ifdef VIA_PIPC_FM_EMULATION + /* Real 686B only updates the bank ID register when writing to the + index port, and only fires NMI/SMI when writing to the data port. */ + if (!(addr & 0x01)) { + dev->fmnmi_regs[0x00] = (addr & 0x02) ? 0x02 : 0x01; + dev->fmnmi_regs[0x01] = val; + } else { + dev->fmnmi_regs[0x02] = val; + + /* Fire NMI/SMI if enabled. */ + if (dev->ac97_regs[0][0x48] & 0x01) { + if (dev->ac97_regs[0][0x48] & 0x04) + smi_line = 1; + else + nmi = 1; + } + } +#else opl3_write(addr, val, &dev->sb->opl); - dev->fm_regs[addr & 0x03] = val; - - dev->fmnmi_regs[0x00] = (addr & 0x02) ? 0x02 : 0x01; - dev->fmnmi_regs[0x01] = dev->fm_regs[addr & 0x02]; - dev->fmnmi_regs[0x02] = dev->fm_regs[(addr & 0x02) | 0x01]; - - if (dev->ac97_regs[0][0x48] & 0x04) - smi_line = 1; - else - nmi = 1; +#endif } @@ -599,7 +586,7 @@ pipc_fmnmi_handlers(pipc_t *dev, uint8_t modem) return; if (dev->fmnmi_base) - io_removehandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, pipc_fmnmi_write, NULL, NULL, dev); + io_removehandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, NULL, NULL, NULL, dev); if (dev->fm_enabled) io_removehandler(0x388, 4, pipc_fm_read, NULL, NULL, pipc_fm_write, NULL, NULL, dev); @@ -608,7 +595,7 @@ pipc_fmnmi_handlers(pipc_t *dev, uint8_t modem) dev->fm_enabled = !!(dev->ac97_regs[0][0x42] & 0x04); if (dev->fmnmi_base && (dev->ac97_regs[0][0x04] & PCI_COMMAND_IO)) - io_sethandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, pipc_fmnmi_write, NULL, NULL, dev); + io_sethandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, NULL, NULL, NULL, dev); if (dev->fm_enabled) io_sethandler(0x388, 4, pipc_fm_read, NULL, NULL, pipc_fm_write, NULL, NULL, dev); @@ -1230,7 +1217,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x42: case 0x4a: case 0x4b: dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; - gameport_remap(dev->gameport, (dev->ac97_regs[0][0x42] & 0x08) ? ((dev->ac97_regs[0][0x4b] << 8) | dev->ac97_regs[0][0x4a]) : 0); + gameport_remap(dev->gameport, (dev->ac97_regs[0][0x42] & 0x08) ? ((dev->ac97_regs[0][0x4b] << 8) | (dev->ac97_regs[0][0x4a] & 0xf8)) : 0); if (addr == 0x42) pipc_fmnmi_handlers(dev, func); break; @@ -1243,24 +1230,10 @@ pipc_write(int func, int addr, uint8_t val, void *priv) dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0xf0; break; - case 0x45: + case 0x45: case 0x48: dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0x0f; break; - case 0x48: - dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val & 0x0f; - /*if (!(val & 0x01)) { - if (val & 0x04) - smi_line = 0; - else - nmi = 0; - }*/ - if (val & 0x04) - smi_line = !!(val & 0x01); - else - nmi = !!(val & 0x01); - break; - default: dev->ac97_regs[func][addr] = val; break; From 54b8fb57aa5ae3ca6ff1a0c73f13bf3d2282d5fb Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 27 Jul 2021 16:01:30 -0300 Subject: [PATCH 29/52] Add separate table for AC97 gain (not quite right) --- src/sound/snd_ac97_codec.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index d215b8145..5532a1441 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -58,6 +58,10 @@ static const int32_t codec_attn[] = { 25, 32, 41, 51, 65, 82, 103, 130, 164, 206, 260, 327, 412, 519, 653, 822, 1036, 1304, 1641, 2067, 2602, 3276, 4125, 5192, 6537, 8230, 10362, 13044, 16422, 20674, 26027, 32767 }; +static const int32_t codec_gain[] = { + 8545, 8552, 8561, 8571, 8585, 8602, 8623, 8650, 8684, 8726, 8780, 8847, 8932, 9039, 9173, 9342, + 9556, 9824, 10161, 10587, 11122, 11796, 12645, 13712, 15057, 16750, 18882, 21564, 24942, 29194, 34547, 41287 +}; ac97_codec_t **ac97_codec = NULL, **ac97_modem_codec = NULL; int ac97_codec_count = 0, ac97_modem_codec_count = 0; @@ -210,8 +214,8 @@ ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) else *r = codec_attn[0x1f - (r_val & 0x1f)]; } else { /* 5-bit gain */ - *l = codec_attn[0x1f - (l_val & 0x1f)]; - *r = codec_attn[0x1f - (r_val & 0x1f)]; + *l = codec_gain[0x1f - (l_val & 0x1f)]; + *r = codec_gain[0x1f - (r_val & 0x1f)]; } } From 8485852b07cc7db364bc6efdb1b96345f867101a Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 27 Jul 2021 17:13:49 -0300 Subject: [PATCH 30/52] Add AC97 multi-codec support (unused) and fix gain calculation --- src/include/86box/snd_ac97.h | 7 ++-- src/sound/snd_ac97_codec.c | 74 ++++++++++++++++++++---------------- src/sound/snd_ac97_via.c | 1 + src/sound/snd_audiopci.c | 3 +- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index a72a874d9..8b5e89920 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -19,8 +19,8 @@ typedef struct { - uint32_t id; - uint8_t regs[128]; + uint32_t vendor_id; + uint8_t codec_id, regs[128]; } ac97_codec_t; @@ -40,7 +40,8 @@ extern void ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t #ifdef EMU_DEVICE_H extern ac97_codec_t **ac97_codec, **ac97_modem_codec; -extern int ac97_codec_count, ac97_modem_codec_count; +extern int ac97_codec_count, ac97_modem_codec_count, + ac97_codec_id, ac97_modem_codec_id; extern const device_t alc100_device; extern const device_t cs4297_device; diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 5532a1441..133b9f0c5 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -55,16 +55,14 @@ ac97_codec_log(const char *fmt, ...) #endif static const int32_t codec_attn[] = { - 25, 32, 41, 51, 65, 82, 103, 130, 164, 206, 260, 327, 412, 519, 653, 822, - 1036, 1304, 1641, 2067, 2602, 3276, 4125, 5192, 6537, 8230, 10362, 13044, 16422, 20674, 26027, 32767 -}; -static const int32_t codec_gain[] = { - 8545, 8552, 8561, 8571, 8585, 8602, 8623, 8650, 8684, 8726, 8780, 8847, 8932, 9039, 9173, 9342, - 9556, 9824, 10161, 10587, 11122, 11796, 12645, 13712, 15057, 16750, 18882, 21564, 24942, 29194, 34547, 41287 + 25, 32, 41, 51, 65, 82, 103, 130, 164, 206, 260, 327, 412, 519, 653, 822, + 1036, 1304, 1641, 2067, 2602, 3276, 4125, 5192, 6537, 8230, 10362, 13044, 16422, 20674, 26027, 32767, + 41305, 52068, 65636, 82739, 104299, 131477, 165737, 208925 }; ac97_codec_t **ac97_codec = NULL, **ac97_modem_codec = NULL; -int ac97_codec_count = 0, ac97_modem_codec_count = 0; +int ac97_codec_count = 0, ac97_modem_codec_count = 0, + ac97_codec_id = 0, ac97_modem_codec_id = 0; uint8_t @@ -72,7 +70,7 @@ ac97_codec_read(ac97_codec_t *dev, uint8_t reg) { uint8_t ret = dev->regs[reg & 0x7f]; - ac97_codec_log("AC97 Codec: read(%02X) = %02X\n", reg, ret); + ac97_codec_log("AC97 Codec %d: read(%02X) = %02X\n", dev->codec_id, reg, ret); return ret; } @@ -81,7 +79,7 @@ ac97_codec_read(ac97_codec_t *dev, uint8_t reg) void ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) { - ac97_codec_log("AC97 Codec: write(%02X, %02X)\n", reg, val); + ac97_codec_log("AC97 Codec %d: write(%02X, %02X)\n", dev->codec_id, reg, val); reg &= 0x7f; @@ -108,9 +106,16 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) case 0x03: /* Master Volume MSB */ case 0x05: /* Aux Out Volume MSB */ val &= 0xbf; + + /* Convert 6-bit level 1xxxxx to 011111 per specification. */ + if (val & 0x20) { + val &= ~0x20; + val |= 0x1f; + } break; case 0x07: /* Mono Volume MSB */ + case 0x0b: /* PC Beep Volume MSB */ case 0x20: /* General Purpose LSB */ val &= 0x80; break; @@ -118,12 +123,17 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) case 0x02: /* Master Volume LSB */ case 0x04: /* Aux Out Volume LSB */ case 0x06: /* Mono Volume LSB */ - case 0x0b: /* PC Beep Volume MSB */ val &= 0x3f; + + /* Convert 6-bit level 1xxxxx to 011111 per specification. */ + if (val & 0x20) { + val &= ~0x20; + val |= 0x1f; + } break; case 0x0a: /* PC Beep Volume LSB */ - val &= 0xfe; + val &= 0x1e; break; case 0x0c: /* Phone Volume LSB */ @@ -173,7 +183,7 @@ ac97_codec_reset(void *priv) { ac97_codec_t *dev = (ac97_codec_t *) priv; - ac97_codec_log("AC97 Codec: reset()\n"); + ac97_codec_log("AC97 Codec %d: reset()\n", dev->codec_id); memset(dev->regs, 0, sizeof(dev->regs)); @@ -183,11 +193,12 @@ ac97_codec_reset(void *priv) /* Flag codec as ready. */ dev->regs[0x26] = 0x0f; - /* Set Vendor ID. */ - dev->regs[0x7c] = dev->id >> 16; - dev->regs[0x7d] = dev->id >> 24; - dev->regs[0x7e] = dev->id; - dev->regs[0x7f] = dev->id >> 8; + /* Set Codec and Vendor IDs. */ + dev->regs[0x29] = (dev->codec_id << 6) | 0x02; + dev->regs[0x7c] = dev->vendor_id >> 16; + dev->regs[0x7d] = dev->vendor_id >> 24; + dev->regs[0x7e] = dev->vendor_id; + dev->regs[0x7f] = dev->vendor_id >> 8; } @@ -204,18 +215,14 @@ ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) return; } - if (reg < 0x10) { /* 6-bit volume */ - if (l_val & 0x20) - *l = codec_attn[0]; - else - *l = codec_attn[0x1f - (l_val & 0x1f)]; - if (r_val & 0x20) - *r = codec_attn[0]; - else - *r = codec_attn[0x1f - (r_val & 0x1f)]; + l_val &= 0x1f; + r_val &= 0x1f; + if (reg < 0x10) { /* 5-bit level (converted from 6-bit on register write) */ + *l = codec_attn[0x1f - l_val]; + *r = codec_attn[0x1f - r_val]; } else { /* 5-bit gain */ - *l = codec_gain[0x1f - (l_val & 0x1f)]; - *r = codec_gain[0x1f - (r_val & 0x1f)]; + *l = codec_attn[0x27 - l_val]; + *r = codec_attn[0x27 - r_val]; } } @@ -226,19 +233,20 @@ ac97_codec_init(const device_t *info) ac97_codec_t *dev = malloc(sizeof(ac97_codec_t)); memset(dev, 0, sizeof(ac97_codec_t)); - dev->id = info->local; - ac97_codec_log("AC97 Codec: init(%c%c%c%02X)\n", (dev->id >> 24) & 0xff, (dev->id >> 16) & 0xff, (dev->id >> 8) & 0xff, dev->id & 0xff); + dev->vendor_id = info->local; + ac97_codec_log("AC97 Codec %d: init(%c%c%c%02X)\n", ac97_codec_id, (dev->vendor_id >> 24) & 0xff, (dev->vendor_id >> 16) & 0xff, (dev->vendor_id >> 8) & 0xff, dev->vendor_id & 0xff); /* Associate this codec to the current controller. */ if (!ac97_codec || (ac97_codec_count <= 0)) { - fatal("AC97 Codec: No controller to associate codec"); - return NULL; + fatal("AC97 Codec %d: No controller to associate codec\n", ac97_codec_id); + return NULL; } *ac97_codec = dev; if (--ac97_codec_count == 0) ac97_codec = NULL; else ac97_codec += sizeof(ac97_codec_t *); + dev->codec_id = ac97_codec_id++; return dev; } @@ -249,7 +257,7 @@ ac97_codec_close(void *priv) { ac97_codec_t *dev = (ac97_codec_t *) priv; - ac97_codec_log("AC97 Codec: close()\n"); + ac97_codec_log("AC97 Codec %d: close()\n", dev->codec_id); free(dev); } diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index bc2ec8ee9..a83ddc17a 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -750,6 +750,7 @@ ac97_via_init(const device_t *info) ac97_codec = &dev->codec[0][0]; ac97_modem_codec = &dev->codec[1][0]; ac97_codec_count = ac97_modem_codec_count = sizeof(dev->codec[0]) / sizeof(dev->codec[0][0]); + ac97_codec_id = ac97_modem_codec_id = 0; /* Set up SGD channels. */ for (uint8_t i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index cd8288d4d..886ab4ff2 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -1338,7 +1338,8 @@ static void *es1371_init(const device_t *info) ac97_codec = &es1371->codec; ac97_codec_count = 1; - if (!info->local) + ac97_codec_id = 0; + if (!info->local) /* let the machine decide the codec on onboard implementations */ device_add(&cs4297a_device); return es1371; From 8cf651db5719f82495dfe28657268cee419525c5 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 27 Jul 2021 22:53:24 -0300 Subject: [PATCH 31/52] AC97 improvements, including variable sample rate support on VIA --- src/include/86box/snd_ac97.h | 1 + src/sound/snd_ac97_codec.c | 75 +++++++++++++++++++++++++++++++++--- src/sound/snd_ac97_via.c | 64 ++++++++++++++++++++++-------- 3 files changed, 119 insertions(+), 21 deletions(-) diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index 8b5e89920..99601e2e7 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -28,6 +28,7 @@ extern uint8_t ac97_codec_read(ac97_codec_t *dev, uint8_t reg); extern void ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val); extern void ac97_codec_reset(void *priv); extern void ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r); +extern uint32_t ac97_codec_getrate(void *priv, uint8_t reg); extern void ac97_via_set_slot(void *priv, int slot, int irq_pin); extern uint8_t ac97_via_read_status(void *priv, uint8_t modem); diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 133b9f0c5..02ae9cbe9 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -79,6 +79,8 @@ ac97_codec_read(ac97_codec_t *dev, uint8_t reg) void ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) { + uint8_t i; + ac97_codec_log("AC97 Codec %d: write(%02X, %02X)\n", dev->codec_id, reg, val); reg &= 0x7f; @@ -86,7 +88,7 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) switch (reg) { case 0x00: case 0x01: /* Reset / ID code */ ac97_codec_reset(dev); - /* fall-through */ + return; case 0x08: case 0x09: /* Master Tone Control (optional) */ case 0x0d: /* Phone Volume MSB */ @@ -96,7 +98,8 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) case 0x24: case 0x25: /* Audio Interrupt and Paging Mechanism (optional) */ case 0x26: /* Powerdown Ctrl/Stat LSB */ case 0x28: case 0x29: /* Extended Audio ID */ - //case 0x2a ... 0x59: /* Linux tests for audio capability by writing to 38-39 */ + case 0x2b: /* Extended Audio Status/Control MSB */ + //case 0x36 ... 0x59: /* Linux tests for audio capability by writing to 38-39 */ case 0x5a ... 0x5f: /* Vendor Reserved */ //case 0x60 ... 0x6f: case 0x70 ... 0x7f: /* Vendor Reserved */ @@ -107,7 +110,7 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) case 0x05: /* Aux Out Volume MSB */ val &= 0xbf; - /* Convert 6-bit level 1xxxxx to 011111 per specification. */ + /* Convert 6-bit level 1xxxxx to 011111. */ if (val & 0x20) { val &= ~0x20; val |= 0x1f; @@ -125,7 +128,7 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) case 0x06: /* Mono Volume LSB */ val &= 0x3f; - /* Convert 6-bit level 1xxxxx to 011111 per specification. */ + /* Convert 6-bit level 1xxxxx to 011111. */ if (val & 0x20) { val &= ~0x20; val |= 0x1f; @@ -172,6 +175,34 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) case 0x21: /* General Purpose MSB */ val &= 0x83; break; + + case 0x2a: /* Extended Audio Status/Control LSB */ + val &= 0x0b; + + /* Reset DAC sample rates to 48 KHz if VRA is being cleared. */ + if (!(val & 0x01)) { + for (i = 0x2c; i <= 0x30; i += 2) + *((uint16_t *) &dev->regs[i]) = 48000; + } + + /* Reset ADC sample rates to 48 KHz if VRM is being cleared. */ + if (!(val & 0x08)) { + for (i = 0x32; i <= 0x34; i += 2) + *((uint16_t *) &dev->regs[i]) = 48000; + } + break; + + case 0x2c ... 0x31: /* DAC Rates */ + /* Writable only if VRA is set. */ + if (!(dev->regs[0x2a] & 0x01)) + return; + break; + + case 0x32 ... 0x35: /* ADC Rates */ + /* Writable only if VRM is set. */ + if (!(dev->regs[0x2a] & 0x08)) + return; + break; } dev->regs[reg] = val; @@ -182,17 +213,28 @@ void ac97_codec_reset(void *priv) { ac97_codec_t *dev = (ac97_codec_t *) priv; + uint8_t i; ac97_codec_log("AC97 Codec %d: reset()\n", dev->codec_id); memset(dev->regs, 0, sizeof(dev->regs)); - /* Mute outputs by default. */ - dev->regs[0x02] = dev->regs[0x04] = dev->regs[0x06] = 0x80; + /* Set default level and gain values. */ + for (i = 0x02; i <= 0x18; i += 2) { + if (i == 0x08) + continue; + if (i >= 0x0c) + dev->regs[i] = 0x08; + dev->regs[i | 1] = (i >= 0x10) ? 0x88 : 0x80; + } /* Flag codec as ready. */ dev->regs[0x26] = 0x0f; + /* Set up variable sample rate support. */ + dev->regs[0x28] = 0x0b; + ac97_codec_write(dev, 0x2a, 0x00); /* reset DAC/ADC sample rates */ + /* Set Codec and Vendor IDs. */ dev->regs[0x29] = (dev->codec_id << 6) | 0x02; dev->regs[0x7c] = dev->vendor_id >> 16; @@ -227,6 +269,24 @@ ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) } +uint32_t +ac97_codec_getrate(void *priv, uint8_t reg) +{ + ac97_codec_t *dev = (ac97_codec_t *) priv; + + /* Get configured sample rate, which is always 48000 if VRA/VRM is not set. */ + uint32_t ret = *((uint16_t *) &dev->regs[reg]); + + /* If this is a DAC, double sample rate if DRA is set. */ + if ((reg < 0x32) && (dev->regs[0x2a] & 0x02)) + ret <<= 1; + + ac97_codec_log("AC97 Codec %d: getrate(%02X) = %d\n", dev->codec_id, reg, ret); + + return ret; +} + + static void * ac97_codec_init(const device_t *info) { @@ -248,6 +308,9 @@ ac97_codec_init(const device_t *info) ac97_codec += sizeof(ac97_codec_t *); dev->codec_id = ac97_codec_id++; + /* Initialize codec registers. */ + ac97_codec_reset(dev); + return dev; } diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index a83ddc17a..476d05474 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -44,7 +44,7 @@ typedef struct { typedef struct _ac97_via_ { uint16_t audio_sgd_base, audio_codec_base, modem_sgd_base, modem_codec_base; - uint8_t sgd_regs[256], pcm_enabled: 1, fm_enabled: 1; + uint8_t sgd_regs[256], pcm_enabled: 1, fm_enabled: 1, vsr_enabled: 1; struct { union { uint8_t regs_codec[2][128]; @@ -85,7 +85,8 @@ ac97_via_log(const char *fmt, ...) static void ac97_via_sgd_process(void *priv); -static void ac97_via_update_volumes(ac97_via_t *dev, ac97_codec_t *codec); +static void ac97_via_update_codec(ac97_via_t *dev, ac97_codec_t *codec); +static void ac97_via_speed_changed(void *priv); void @@ -126,20 +127,28 @@ ac97_via_write_control(void *priv, uint8_t modem, uint8_t val) ac97_via_log("AC97 VIA %d: write_control(%02X)\n", modem, val); + if (!modem) { + /* Set the variable sample rate flag now, so that the upcoming + update_codec can properly update the poller timer interval. */ + dev->vsr_enabled = !!(val & 0x08); + } + /* Reset and/or update volumes on all codecs. */ for (i = 0; i <= 1; i++) { - if (dev->codec[modem][i]) { - /* Reset codec if requested. */ - if (val & 0x40) - ac97_codec_reset(dev->codec[modem][i]); + if (!dev->codec[modem][i]) + continue; - /* Update volumes. */ - ac97_via_update_volumes(dev, dev->codec[modem][i]); - } + /* Reset codec if requested. */ + if (!(val & 0x40)) + ac97_codec_reset(dev->codec[modem][i]); + + /* Update primary codec state. */ + if (!modem && !i) + ac97_via_update_codec(dev, dev->codec[modem][i]); } if (!modem) { - /* Start or stop PCM playback. */ + /* Start or stop PCM playback. */ i = (val & 0xf4) == 0xc4; if (i && !dev->pcm_enabled) timer_advance_u64(&dev->timer_count, dev->timer_latch); @@ -174,12 +183,14 @@ ac97_via_update_irqs(ac97_via_t *dev) static void -ac97_via_update_volumes(ac97_via_t *dev, ac97_codec_t *codec) { +ac97_via_update_codec(ac97_via_t *dev, ac97_codec_t *codec) { + /* Update volumes according to codec registers. */ ac97_codec_getattn(codec, 0x02, &dev->master_vol_l, &dev->master_vol_r); ac97_codec_getattn(codec, 0x18, &dev->pcm_vol_l, &dev->pcm_vol_r); ac97_codec_getattn(codec, 0x12, &dev->cd_vol_l, &dev->cd_vol_r); - pclog("master %d %d\npcm %d %d\ncd %d %d\n", dev->master_vol_l, dev->master_vol_r, dev->pcm_vol_l, dev->pcm_vol_r, dev->cd_vol_l, dev->cd_vol_r); + /* Update sample rate according to codec registers and the variable sample rate bit. */ + ac97_via_speed_changed(dev); } @@ -377,8 +388,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) val |= 1; ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x81]); - /* Update volumes. */ - ac97_via_update_volumes(dev, codec); + /* Update primary codec state. */ + if (!modem && !i) + ac97_via_update_codec(dev, codec); } /* Flag data/status/index for this codec as valid. */ @@ -729,11 +741,30 @@ ac97_via_get_buffer(int32_t *buffer, int len, void *priv) } +static void +via_ac97_filter_cd_audio(int channel, double *buffer, void *priv) +{ + ac97_via_t *dev = (ac97_via_t *) priv; + double c, volume = channel ? dev->cd_vol_r : dev->cd_vol_l; + + c = ((*buffer) * volume) / 65536.0; + *buffer = c; +} + + static void ac97_via_speed_changed(void *priv) { ac97_via_t *dev = (ac97_via_t *) priv; - dev->timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / 48000.0)); + double freq; + + /* Get variable sample rate if enabled. */ + if (dev->vsr_enabled && dev->codec[0][0]) + freq = ac97_codec_getrate(dev->codec[0][0], 0x2c); + else + freq = 48000.0; + + dev->timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / freq)); dev->timer_fifo_latch = (uint64_t) ((double) TIMER_USEC * 10.0); } @@ -772,6 +803,9 @@ ac97_via_init(const device_t *info) /* Set up playback handler. */ sound_add_handler(ac97_via_get_buffer, dev); + /* Set up CD audio filter. */ + sound_set_cd_audio_filter(via_ac97_filter_cd_audio, dev); + return dev; } From 89d6a67e86d05c00dd245e4a07d6f104e727fd7a Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 29 Jul 2021 00:47:39 -0300 Subject: [PATCH 32/52] More AC97 work, including 48 KHz sample rate cap --- src/device/smbus_piix4.c | 4 +-- src/sound/snd_ac97_codec.c | 52 +++++++++++++++++++++----------------- src/sound/snd_ac97_via.c | 50 +++++++++++++++++------------------- 3 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/device/smbus_piix4.c b/src/device/smbus_piix4.c index 91ee5566e..271747d92 100644 --- a/src/device/smbus_piix4.c +++ b/src/device/smbus_piix4.c @@ -124,13 +124,13 @@ smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) if (val & 0x40) { /* dispatch command if START is set */ timer_bytes++; /* address */ - smbus_addr = (dev->addr >> 1); + smbus_addr = dev->addr >> 1; read = dev->addr & 0x01; cmd = (dev->ctl >> 2) & 0xf; smbus_piix4_log("SMBus PIIX4: addr=%02X read=%d protocol=%X cmd=%02X data0=%02X data1=%02X\n", smbus_addr, read, cmd, dev->cmd, dev->data0, dev->data1); - /* Raise DEV_ERR if no device is at this address, or if the device returned NAK when starting the transfer. */ + /* Raise DEV_ERR if no device is at this address, or if the device returned NAK. */ if (!i2c_start(i2c_smbus, smbus_addr, read)) { dev->next_stat = 0x04; break; diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 02ae9cbe9..2ae310465 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -106,11 +106,17 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) /* Read-only registers. */ return; + case 0x02: /* Master Volume LSB */ + case 0x04: /* Aux Out Volume LSB */ + case 0x06: /* Mono Volume LSB */ + val &= 0x3f; + /* fall-through */ + case 0x03: /* Master Volume MSB */ case 0x05: /* Aux Out Volume MSB */ val &= 0xbf; - /* Convert 6-bit level 1xxxxx to 011111. */ + /* Limit level to a maximum of 011111. */ if (val & 0x20) { val &= ~0x20; val |= 0x1f; @@ -123,18 +129,6 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) val &= 0x80; break; - case 0x02: /* Master Volume LSB */ - case 0x04: /* Aux Out Volume LSB */ - case 0x06: /* Mono Volume LSB */ - val &= 0x3f; - - /* Convert 6-bit level 1xxxxx to 011111. */ - if (val & 0x20) { - val &= ~0x20; - val |= 0x1f; - } - break; - case 0x0a: /* PC Beep Volume LSB */ val &= 0x1e; break; @@ -177,9 +171,12 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) break; case 0x2a: /* Extended Audio Status/Control LSB */ +#ifdef AC97_CODEC_FULL_RATE_RANGE /* enable DRA (double rate) support */ val &= 0x0b; - - /* Reset DAC sample rates to 48 KHz if VRA is being cleared. */ +#else + val &= 0x09; +#endif + /* Reset DAC sample rates to 48 KHz (96 KHz with DRA) if VRA is being cleared. */ if (!(val & 0x01)) { for (i = 0x2c; i <= 0x30; i += 2) *((uint16_t *) &dev->regs[i]) = 48000; @@ -192,16 +189,19 @@ ac97_codec_write(ac97_codec_t *dev, uint8_t reg, uint8_t val) } break; - case 0x2c ... 0x31: /* DAC Rates */ - /* Writable only if VRA is set. */ - if (!(dev->regs[0x2a] & 0x01)) + case 0x2c ... 0x35: /* DAC/ADC Rates */ + /* Writable only if VRA/VRM is set. */ + i = (reg >= 0x32) ? 0x08 : 0x01; + if (!(dev->regs[0x2a] & i)) return; - break; - case 0x32 ... 0x35: /* ADC Rates */ - /* Writable only if VRM is set. */ - if (!(dev->regs[0x2a] & 0x08)) +#ifndef AC97_CODEC_FULL_RATE_RANGE + /* Limit to 48 KHz on MSB write. */ + if ((reg & 1) && (((val << 8) | dev->regs[reg & 0x7e]) > 48000)) { + *((uint16_t *) &dev->regs[reg & 0x7e]) = 48000; return; + } +#endif break; } @@ -232,10 +232,14 @@ ac97_codec_reset(void *priv) dev->regs[0x26] = 0x0f; /* Set up variable sample rate support. */ +#ifdef AC97_CODEC_FULL_RATE_RANGE /* enable DRA (double rate) support */ dev->regs[0x28] = 0x0b; +#else + dev->regs[0x28] = 0x09; +#endif ac97_codec_write(dev, 0x2a, 0x00); /* reset DAC/ADC sample rates */ - /* Set Codec and Vendor IDs. */ + /* Set codec and vendor IDs. */ dev->regs[0x29] = (dev->codec_id << 6) | 0x02; dev->regs[0x7c] = dev->vendor_id >> 16; dev->regs[0x7d] = dev->vendor_id >> 24; @@ -277,9 +281,11 @@ ac97_codec_getrate(void *priv, uint8_t reg) /* Get configured sample rate, which is always 48000 if VRA/VRM is not set. */ uint32_t ret = *((uint16_t *) &dev->regs[reg]); +#ifdef AC97_CODEC_FULL_RATE_RANGE /* If this is a DAC, double sample rate if DRA is set. */ if ((reg < 0x32) && (dev->regs[0x2a] & 0x02)) ret <<= 1; +#endif ac97_codec_log("AC97 Codec %d: getrate(%02X) = %d\n", dev->codec_id, reg, ret); diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 476d05474..262872e5e 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -85,7 +85,7 @@ ac97_via_log(const char *fmt, ...) static void ac97_via_sgd_process(void *priv); -static void ac97_via_update_codec(ac97_via_t *dev, ac97_codec_t *codec); +static void ac97_via_update_codec(ac97_via_t *dev); static void ac97_via_speed_changed(void *priv); @@ -127,27 +127,18 @@ ac97_via_write_control(void *priv, uint8_t modem, uint8_t val) ac97_via_log("AC97 VIA %d: write_control(%02X)\n", modem, val); - if (!modem) { - /* Set the variable sample rate flag now, so that the upcoming - update_codec can properly update the poller timer interval. */ - dev->vsr_enabled = !!(val & 0x08); - } - - /* Reset and/or update volumes on all codecs. */ - for (i = 0; i <= 1; i++) { - if (!dev->codec[modem][i]) - continue; - - /* Reset codec if requested. */ - if (!(val & 0x40)) - ac97_codec_reset(dev->codec[modem][i]); - - /* Update primary codec state. */ - if (!modem && !i) - ac97_via_update_codec(dev, dev->codec[modem][i]); + /* Reset codecs if requested. */ + if (!(val & 0x40)) { + for (i = 0; i <= 1; i++) { + if (dev->codec[modem][i]) + ac97_codec_reset(dev->codec[modem][i]); + } } if (!modem) { + /* Set the variable sample rate flag. */ + dev->vsr_enabled = (val & 0xf8) == 0xc8; + /* Start or stop PCM playback. */ i = (val & 0xf4) == 0xc4; if (i && !dev->pcm_enabled) @@ -159,6 +150,10 @@ ac97_via_write_control(void *priv, uint8_t modem, uint8_t val) if (i && !dev->fm_enabled) timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); dev->fm_enabled = i; + + /* Update primary audio codec state. */ + if (dev->codec[0][0]) + ac97_via_update_codec(dev); } } @@ -167,12 +162,10 @@ static void ac97_via_update_irqs(ac97_via_t *dev) { /* Check interrupt flags in all SGDs. */ - uint8_t i, sgd_id; - for (i = 0; i < (sizeof(dev->sgd) / sizeof(dev->sgd[0])); i++) { - sgd_id = i << 4; + for (uint8_t i = 0x00; i < ((sizeof(dev->sgd) / sizeof(dev->sgd[0])) << 4); i += 0x10) { /* Stop immediately if any flag is set. Doing it this way optimizes rising edges for the playback SGD (0 - first to be checked). */ - if (dev->sgd_regs[sgd_id] & (dev->sgd_regs[sgd_id | 0x2] & 0x03)) { + if (dev->sgd_regs[i] & (dev->sgd_regs[i | 0x2] & 0x03)) { pci_set_irq(dev->slot, dev->irq_pin); return; } @@ -183,13 +176,16 @@ ac97_via_update_irqs(ac97_via_t *dev) static void -ac97_via_update_codec(ac97_via_t *dev, ac97_codec_t *codec) { +ac97_via_update_codec(ac97_via_t *dev) { + /* Get primary audio codec. */ + ac97_codec_t *codec = dev->codec[0][0]; + /* Update volumes according to codec registers. */ ac97_codec_getattn(codec, 0x02, &dev->master_vol_l, &dev->master_vol_r); ac97_codec_getattn(codec, 0x18, &dev->pcm_vol_l, &dev->pcm_vol_r); ac97_codec_getattn(codec, 0x12, &dev->cd_vol_l, &dev->cd_vol_r); - /* Update sample rate according to codec registers and the variable sample rate bit. */ + /* Update sample rate according to codec registers and the variable sample rate flag. */ ac97_via_speed_changed(dev); } @@ -388,9 +384,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) val |= 1; ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x81]); - /* Update primary codec state. */ + /* Update primary audio codec state if that codec was written to. */ if (!modem && !i) - ac97_via_update_codec(dev, codec); + ac97_via_update_codec(dev); } /* Flag data/status/index for this codec as valid. */ From 733af3b2fbe61ce41bb4c9bf5af61a1a4e61a961 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 29 Jul 2021 00:50:21 -0300 Subject: [PATCH 33/52] Remove extraneous comment --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index cf66f160b..6aec4db72 100644 --- a/src/config.c +++ b/src/config.c @@ -689,7 +689,7 @@ load_machine(void) if (p) { if (! strcmp(p, "enh_am486dx2")) /* migrate modified names */ cpu_f = cpu_get_family("am486dx2_slenh"); - else if (! strcmp(p, "enh_am486dx4")) /* migrate modified names */ + else if (! strcmp(p, "enh_am486dx4")) cpu_f = cpu_get_family("am486dx4_slenh"); else cpu_f = cpu_get_family(p); From 8cf5e3d77f302504a2aa7716f79212f2b9a33aa4 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 29 Jul 2021 13:21:12 -0300 Subject: [PATCH 34/52] Update VIA AC97 codec write behavior to match hardware --- src/sound/snd_ac97_codec.c | 12 ++++++------ src/sound/snd_ac97_via.c | 29 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 2ae310465..9cd47ad90 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -25,17 +25,17 @@ #include <86box/io.h> #include <86box/snd_ac97.h> -#define AC97_CODEC_ID(f, s, t, dev) ((((f) & 0xff) << 24) | (((s) & 0xff) << 16) | (((t) & 0xff) << 8) | ((dev) & 0xff)) +#define AC97_VENDOR_ID(f, s, t, dev) ((((f) & 0xff) << 24) | (((s) & 0xff) << 16) | (((t) & 0xff) << 8) | ((dev) & 0xff)) enum { - AC97_CODEC_ALC100 = AC97_CODEC_ID('A', 'L', 'C', 0x20), - AC97_CODEC_CS4297 = AC97_CODEC_ID('C', 'R', 'Y', 0x03), - AC97_CODEC_CS4297A = AC97_CODEC_ID('C', 'R', 'Y', 0x13), - AC97_CODEC_WM9701A = AC97_CODEC_ID('W', 'M', 'L', 0x00) + AC97_CODEC_ALC100 = AC97_VENDOR_ID('A', 'L', 'C', 0x20), + AC97_CODEC_CS4297 = AC97_VENDOR_ID('C', 'R', 'Y', 0x03), + AC97_CODEC_CS4297A = AC97_VENDOR_ID('C', 'R', 'Y', 0x13), + AC97_CODEC_WM9701A = AC97_VENDOR_ID('W', 'M', 'L', 0x00) }; -#define ENABLE_AC97_CODEC_LOG 1 + #ifdef ENABLE_AC97_CODEC_LOG int ac97_codec_do_log = ENABLE_AC97_CODEC_LOG; diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 262872e5e..9d46dfccd 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -371,15 +371,22 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) i = !!(dev->sgd_regs[0x83] & 0x40); codec = dev->codec[modem][i]; - /* Read from or write to codec. */ + /* Keep value in register if this codec is not present. */ if (codec) { + /* Read from or write to codec. */ if (val & 0x80) { - val &= 0x7e; - dev->sgd_regs[0x80] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); - val |= 1; - dev->sgd_regs[0x81] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); - } else { - val &= 0x7e; + if (val & 1) { /* return 0x00 on unaligned reads */ + dev->sgd_regs[0x80] = dev->sgd_regs[0x81] = 0x00; + } else { + dev->sgd_regs[0x80] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); + val |= 1; + dev->sgd_regs[0x81] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); + } + + /* Flag data/status/index for this codec as valid. */ + if (val & 0x80) + dev->sgd_regs[0x83] |= 0x02 << (i << 1); + } else if (!(val & 1)) { /* do nothing on unaligned writes */ ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x80]); val |= 1; ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x81]); @@ -388,12 +395,6 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) if (!modem && !i) ac97_via_update_codec(dev); } - - /* Flag data/status/index for this codec as valid. */ - dev->sgd_regs[0x83] |= 0x02 << (i * 2); - } else if (val & 0x80) { - /* Unknown behavior when reading from an absent codec. */ - dev->sgd_regs[0x80] = dev->sgd_regs[0x81] = 0xff; } break; @@ -402,7 +403,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) #if 0 /* race condition with Linux accessing a register and clearing status bits on the same dword write */ val = (dev->sgd_regs[addr] & ~(val & 0x0a)) | (val & 0xc0); #else - val = dev->sgd_regs[addr] | 0x0a | (val & 0xc0); + val = dev->sgd_regs[addr] | (val & 0xc0); #endif break; } From c5c6cb715c76db99def5fe5a7a20d2739946c078 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 29 Jul 2021 13:23:18 -0300 Subject: [PATCH 35/52] Fix overwritten register index value oversight --- src/sound/snd_ac97_via.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 9d46dfccd..1349d0849 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -378,18 +378,16 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) if (val & 1) { /* return 0x00 on unaligned reads */ dev->sgd_regs[0x80] = dev->sgd_regs[0x81] = 0x00; } else { - dev->sgd_regs[0x80] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); - val |= 1; - dev->sgd_regs[0x81] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); + dev->sgd_regs[0x80] = dev->codec_shadow[modem].regs_codec[i][val] = ac97_codec_read(codec, val); + dev->sgd_regs[0x81] = dev->codec_shadow[modem].regs_codec[i][val | 1] = ac97_codec_read(codec, val | 1); } /* Flag data/status/index for this codec as valid. */ if (val & 0x80) dev->sgd_regs[0x83] |= 0x02 << (i << 1); } else if (!(val & 1)) { /* do nothing on unaligned writes */ - ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x80]); - val |= 1; - ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x81]); + ac97_codec_write(codec, val, dev->codec_shadow[modem].regs_codec[i][val] = dev->sgd_regs[0x80]); + ac97_codec_write(codec, val | 1, dev->codec_shadow[modem].regs_codec[i][val | 1] = dev->sgd_regs[0x81]); /* Update primary audio codec state if that codec was written to. */ if (!modem && !i) From d61e3b1e94096b418e16dff9704f4d1c1bf375d8 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 30 Jul 2021 00:17:49 -0300 Subject: [PATCH 36/52] Add AMR bus for optional AC97 audio on CUV4X-LS --- src/device.c | 4 ++++ src/include/86box/machine.h | 1 + src/machine/machine_table.c | 16 ++++++++-------- src/sound/sound.c | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/device.c b/src/device.c index 439f558a1..265fdf215 100644 --- a/src/device.c +++ b/src/device.c @@ -394,6 +394,8 @@ device_get_name(const device_t *d, int bus, char *name) sbus = "PCI"; else if (d->flags & DEVICE_AGP) sbus = "AGP"; + else if (d->flags & DEVICE_AC97) + sbus = "AMR"; if (sbus != NULL) { /* First concatenate [] before the device's name. */ @@ -666,6 +668,8 @@ device_is_valid(const device_t *device, int mflags) if ((device->flags & DEVICE_PS2) && !(mflags & MACHINE_BUS_PS2)) return(0); + if ((device->flags & DEVICE_AC97) && !(mflags & MACHINE_BUS_AC97)) return(0); + return(1); } diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 2996133dc..fd01e37eb 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -37,6 +37,7 @@ #define MACHINE_BUS_PCI 0x00000200 /* sys has PCI bus */ #define MACHINE_BUS_PCMCIA 0x00000400 /* sys has PCMCIA bus */ #define MACHINE_BUS_AGP 0x00000800 /* sys has AGP bus */ +#define MACHINE_BUS_AC97 0x00080000 /* sys has AC97 bus (ACR/AMR/CNR slot) */ /* Combined flags. */ #define MACHINE_PC 0x00000004 /* sys is PC/XT-compatible (ISA) */ #define MACHINE_AT 0x0000000C /* sys is AT-compatible (ISA + ISA16) */ diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 99165c58e..f8a4f3bb7 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -190,7 +190,7 @@ const machine_t machines[] = { /* 386DX machines which utilize the MCA bus */ { "[MCA] IBM PS/2 model 70 (type 3)", "ibmps2_m70_type3", MACHINE_TYPE_386DX, CPU_PKG_386DX | CPU_PKG_486BL, 0, 0, 0, 0, 0, 0, 0, MACHINE_MCA | MACHINE_BUS_PS2 | MACHINE_VIDEO, 2048, 16384, 2048, 63, machine_ps2_model_70_type3_init, NULL }, { "[MCA] IBM PS/2 model 80", "ibmps2_m80", MACHINE_TYPE_386DX, CPU_PKG_386DX | CPU_PKG_486BL, 0, 0, 0, 0, 0, 0, 0, MACHINE_MCA | MACHINE_BUS_PS2 | MACHINE_VIDEO, 1024, 12288, 1024, 63, machine_ps2_model_80_init, NULL }, - { "[MCA] IBM PS/2 model 80 (type 3)", "ibmps2_m80_type3", MACHINE_TYPE_386DX, CPU_PKG_386DX | CPU_PKG_486BL, 0, 0, 0, 0, 0, 0, 0, MACHINE_MCA | MACHINE_BUS_PS2 | MACHINE_VIDEO, 2048, 12288, 2048, 63, machine_ps2_model_80_axx_init, NULL }, + { "[MCA] IBM PS/2 model 80 (type 3)", "ibmps2_m80_type3", MACHINE_TYPE_386DX, CPU_PKG_386DX | CPU_PKG_486BL, 0, 0, 0, 0, 0, 0, 0, MACHINE_MCA | MACHINE_BUS_PS2 | MACHINE_VIDEO, 2048, 12288, 2048, 63, machine_ps2_model_80_axx_init, NULL }, /* 386DX/486 machines */ { "[OPTi 495] Award 486 clone", "award486", MACHINE_TYPE_386DX_486, CPU_PKG_386DX | CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_VLB | MACHINE_IDE, 1024, 32768, 1024, 127, machine_at_opti495_init, NULL }, @@ -200,11 +200,11 @@ const machine_t machines[] = { /* 486 machines - Socket 1 */ { "[ALi M1429] Olystar LIL1429", "ali1429", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_VLB | MACHINE_IDE, 1024, 32768, 1024, 127, machine_at_ali1429_init, NULL }, { "[CS4031] AMI 486 CS4031", "cs4031", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_VLB, 1024, 65536, 1024, 127, machine_at_cs4031_init, NULL }, - { "[ETEQ ET6000] Olivetti PCS-46C", "pcs46c", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_VLB | MACHINE_IDE | MACHINE_VIDEO, 4096, 32768, 4096, 127, machine_at_pcs46c_init, at_pcs46c_get_device }, + { "[ETEQ ET6000] Olivetti PCS-46C", "pcs46c", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_VLB | MACHINE_IDE | MACHINE_VIDEO, 4096, 32768, 4096, 127, machine_at_pcs46c_init, at_pcs46c_get_device }, { "[OPTi 895] Mylex MVI486", "mvi486", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_VLB | MACHINE_IDE_DUAL, 1024, 65536, 1024, 127, machine_at_mvi486_init, NULL }, { "[VIA VT82C495] FIC 486-VC-HD", "486vchd", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_AT, 1024, 64512, 1024, 127, machine_at_486vchd_init, NULL }, { "[VLSI 82C480] HP Vectra 486VL", "vect486vl", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_AT | MACHINE_BUS_PS2 | MACHINE_IDE | MACHINE_VIDEO, 2048, 32768, 2048, 127, machine_at_vect486vl_init, at_vect486vl_get_device }, - { "[VLSI 82C481] Siemens Nixdorf D824", "d824", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_AT | MACHINE_BUS_PS2 | MACHINE_IDE | MACHINE_VIDEO, 2048, 32768, 2048, 127, machine_at_d824_init, at_d824_get_device }, + { "[VLSI 82C481] Siemens Nixdorf D824", "d824", MACHINE_TYPE_486, CPU_PKG_SOCKET1, 0, 0, 0, 0, 0, 0, 0, MACHINE_AT | MACHINE_BUS_PS2 | MACHINE_IDE | MACHINE_VIDEO, 2048, 32768, 2048, 127, machine_at_d824_init, at_d824_get_device }, /* 486 machines - Socket 3 */ /* 486 machines with just the ISA slot */ @@ -295,7 +295,7 @@ const machine_t machines[] = { { "[SiS 85C50x] BCM SQ-588", "sq588", MACHINE_TYPE_SOCKET5, CPU_PKG_SOCKET5_7, CPU_BLOCK(CPU_PENTIUMMMX), 50000000, 66666667, 3520, 3520, 1.5, 1.5, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 131072, 8192, 127, machine_at_sq588_init, NULL }, /* UMC 889x */ - { "[UMC 889x] Shuttle HOT-539", "hot539", MACHINE_TYPE_SOCKET5, CPU_PKG_SOCKET5_7, CPU_BLOCK(CPU_K5, CPU_5K86), 40000000, 66666667, 3380, 3600, 1.5, 2.0, MACHINE_PCI | MACHINE_IDE_DUAL, 8192, 262144, 8192, 127, machine_at_hot539_init, NULL }, + { "[UMC 889x] Shuttle HOT-539", "hot539", MACHINE_TYPE_SOCKET5, CPU_PKG_SOCKET5_7, CPU_BLOCK(CPU_K5, CPU_5K86), 40000000, 66666667, 3380, 3600, 1.5, 2.0, MACHINE_PCI | MACHINE_IDE_DUAL, 8192, 262144, 8192, 127, machine_at_hot539_init, NULL }, /* Socket 7 (Single Voltage) machines */ /* 430FX */ @@ -318,7 +318,7 @@ const machine_t machines[] = { { "[i430VX] Gateway 2000 Tigereye", "gw2kte", MACHINE_TYPE_SOCKET7_3V, CPU_PKG_SOCKET5_7, 0, 50000000, 66666667, 3380, 3520, 1.5, 3.0, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 131072, 8192, 127, machine_at_gw2kte_init, NULL }, /* SiS 5511 */ - { "[SiS 5511] AOpen AP5S", "ap5s", MACHINE_TYPE_SOCKET7_3V, CPU_PKG_SOCKET5_7, 0, 50000000, 66666667, 3380, 3520, 1.5, 3.0, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 524288, 8192, 127, machine_at_ap5s_init, NULL }, + { "[SiS 5511] AOpen AP5S", "ap5s", MACHINE_TYPE_SOCKET7_3V, CPU_PKG_SOCKET5_7, 0, 50000000, 66666667, 3380, 3520, 1.5, 3.0, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 524288, 8192, 127, machine_at_ap5s_init, NULL }, /* Socket 7 (Dual Voltage) machines */ /* 430HX */ @@ -363,8 +363,8 @@ const machine_t machines[] = { { "[SiS 5571] MSI MS-5146", "ms5146", MACHINE_TYPE_SOCKET7, CPU_PKG_SOCKET5_7, 0, 50000000, 66666667, 2500, 3520, 1.5, 3.0, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 262144, 8192, 127, machine_at_ms5146_init, NULL }, /* SiS 5598 */ - { "[SiS 5598] ASUS SP97-XV", "sp97xv", MACHINE_TYPE_SOCKET7, CPU_PKG_SOCKET5_7, 0, 60000000, 66666667, 2100, 3200, 1.5, 2.5, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 262144, 8192, 255, machine_at_sp97xv_init, NULL }, - { "[SiS 5598] PC Chips M571", "m571", MACHINE_TYPE_SOCKET7, CPU_PKG_SOCKET5_7, 0, 50000000, 75000000, 2500, 3500, 1.5, 3.5, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 262144, 8192, 255, machine_at_m571_init, NULL }, + { "[SiS 5598] ASUS SP97-XV", "sp97xv", MACHINE_TYPE_SOCKET7, CPU_PKG_SOCKET5_7, 0, 60000000, 66666667, 2100, 3200, 1.5, 2.5, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 262144, 8192, 255, machine_at_sp97xv_init, NULL }, + { "[SiS 5598] PC Chips M571", "m571", MACHINE_TYPE_SOCKET7, CPU_PKG_SOCKET5_7, 0, 50000000, 75000000, 2500, 3500, 1.5, 3.5, MACHINE_PCI | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 262144, 8192, 255, machine_at_m571_init, NULL }, /* ALi ALADDiN IV */ #if defined(DEV_BRANCH) && defined(USE_M154X) @@ -460,7 +460,7 @@ const machine_t machines[] = { { "[VIA Apollo Pro] PC Partner APAS3", "apas3", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 100000000, 1800, 3500, 1.5, 8.0, MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192, 786432, 8192, 255, machine_at_apas3_init, NULL }, { "[VIA Apollo Pro133] ECS P6BAP", "p6bap", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, 1.5, 8.0, MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192,1572864, 8192, 255, machine_at_p6bap_init, NULL }, { "[VIA Apollo Pro133A] AEWIN WCF-681", "wcf681", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 133333333, 1300, 3500, 1.5, 8.0, /* limits assumed */ MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192,1048576, 8192, 255, machine_at_wcf681_init, NULL }, - { "[VIA Apollo Pro133A] ASUS CUV4X-LS", "cuv4xls", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, 1.5, 8.0, (MACHINE_AGP & ~MACHINE_AT) | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 16384,1572864, 8192, 255, machine_at_cuv4xls_init, NULL }, + { "[VIA Apollo Pro133A] ASUS CUV4X-LS", "cuv4xls", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, 1.5, 8.0, (MACHINE_AGP & ~MACHINE_AT) | MACHINE_BUS_PS2 | MACHINE_BUS_AC97 | MACHINE_IDE_DUAL,16384,1572864, 8192, 255, machine_at_cuv4xls_init, NULL }, { "[VIA Apollo Pro133A] Acorp 6VIA90AP", "6via90ap", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, MACHINE_MULTIPLIER_FIXED, MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL | MACHINE_GAMEPORT, 8192,1572864, 8192, 255, machine_at_6via90ap_init, NULL }, { "[VIA Apollo ProMedia] Jetway 603TCF", "603tcf", MACHINE_TYPE_SOCKET370, CPU_PKG_SOCKET370, 0, 66666667, 150000000, 1300, 3500, 1.5, 8.0, MACHINE_AGP | MACHINE_BUS_PS2 | MACHINE_IDE_DUAL, 8192,1048576, 8192, 255, machine_at_603tcf_init, NULL }, diff --git a/src/sound/sound.c b/src/sound/sound.c index cddd83359..fa5d180ac 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -37,6 +37,7 @@ #include <86box/snd_mpu401.h> #include <86box/snd_sb_dsp.h> #include <86box/snd_azt2316a.h> +#include <86box/snd_ac97.h> #include <86box/filters.h> @@ -109,6 +110,7 @@ static const SOUND_CARD sound_cards[] = { "sbmcv", &sb_mcv_device }, { "sbpromcv", &sb_pro_mcv_device }, { "es1371", &es1371_device }, + { "cs4297a", &cs4297a_device }, { "", NULL } }; From 720375bfd4052697b4eefc3302f1a8e44fb80ef3 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Mon, 2 Aug 2021 16:15:04 -0300 Subject: [PATCH 37/52] VIA AC97: workaround for V7.00b WDM driver hangs, and fix delayed starts caused by the SGD timer --- src/sound/snd_ac97_via.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 1349d0849..3d9956ae7 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -37,7 +37,7 @@ typedef struct { uint32_t entry_ptr, sample_ptr, fifo_pos, fifo_end; int32_t sample_count; - uint8_t entry_flags, fifo[32], restart; + uint8_t entry_flags, fifo[32], restart, status_shadow; pc_timer_t timer; } ac97_via_sgd_t; @@ -57,7 +57,7 @@ typedef struct _ac97_via_ { ac97_via_sgd_t sgd[6]; pc_timer_t timer_count, timer_count_fm; - uint64_t timer_latch, timer_fifo_latch; + uint64_t timer_latch; int16_t out_l, out_r, fm_out_l, fm_out_r; int master_vol_l, master_vol_r, pcm_vol_l, pcm_vol_r, cd_vol_l, cd_vol_r; int32_t buffer[SOUNDBUFLEN * 2], fm_buffer[SOUNDBUFLEN * 2]; @@ -166,11 +166,13 @@ ac97_via_update_irqs(ac97_via_t *dev) /* Stop immediately if any flag is set. Doing it this way optimizes rising edges for the playback SGD (0 - first to be checked). */ if (dev->sgd_regs[i] & (dev->sgd_regs[i | 0x2] & 0x03)) { + pclog("irq set\n"); pci_set_irq(dev->slot, dev->irq_pin); return; } } + pclog("irq cleared\n"); pci_clear_irq(dev->slot, dev->irq_pin); } @@ -203,6 +205,10 @@ ac97_via_sgd_read(uint16_t addr, void *priv) if (!(addr & 0x80)) { /* Process SGD channel registers. */ switch (addr & 0xf) { + case 0x0: + ret = dev->sgd[addr >> 4].status_shadow; + break; + case 0x4: ret = dev->sgd[addr >> 4].entry_ptr; break; @@ -235,6 +241,9 @@ ac97_via_sgd_read(uint16_t addr, void *priv) ret = dev->sgd_regs[addr]; break; } + + /* Reset SGD status shadow register. See comment on SGD register 0x0 write for more information. */ + dev->sgd[addr >> 4].status_shadow = dev->sgd_regs[addr & 0xf0]; } else { /* Process regular registers. */ switch (addr) { @@ -312,6 +321,11 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) /* Update status interrupts. */ ac97_via_update_irqs(dev); + /* Work around a race condition with the V7.00b WDM driver expecting SGD Active to + not clear immediately. It reads this register next, so set up a shadow register + to ensure SGD Active is set for that specific read (but not subsequent ones). */ + dev->sgd[addr >> 4].status_shadow = dev->sgd_regs[addr] | 0x80; + return; case 0x1: @@ -394,6 +408,7 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) ac97_via_update_codec(dev); } } + break; case 0x83: @@ -536,7 +551,7 @@ ac97_via_sgd_process(void *priv) return; /* Schedule next run. */ - timer_advance_u64(&sgd->timer, dev->timer_fifo_latch); + timer_on_auto(&sgd->timer, 10.0); /* Process SGD if it's active, and the FIFO has room or is disabled. */ if ((sgd_status == 0x80) && (sgd->always_run || ((sgd->fifo_end - sgd->fifo_pos) <= (sizeof(sgd->fifo) - 4)))) { @@ -585,13 +600,15 @@ ac97_via_sgd_process(void *priv) if (sgd->entry_flags & 0x20) { ac97_via_log(" with STOP"); + + /* Raise STOP to pause SGD. */ dev->sgd_regs[sgd->id] |= 0x04; } if (sgd->entry_flags & 0x40) { ac97_via_log(" with FLAG"); - /* Raise FLAG while also pausing SGD. */ + /* Raise FLAG and STOP. */ dev->sgd_regs[sgd->id] |= 0x05; #ifdef ENABLE_AC97_VIA_LOG @@ -760,7 +777,6 @@ ac97_via_speed_changed(void *priv) freq = 48000.0; dev->timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / freq)); - dev->timer_fifo_latch = (uint64_t) ((double) TIMER_USEC * 10.0); } From 413c4562b496b659b34f8983877e878c0030b55a Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Mon, 2 Aug 2021 16:18:21 -0300 Subject: [PATCH 38/52] Add AD1881 codec for the WIP branch's Gigabyte GA-6VX-4X --- src/include/86box/snd_ac97.h | 1 + src/sound/snd_ac97_codec.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index 99601e2e7..08f5747f6 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -44,6 +44,7 @@ extern ac97_codec_t **ac97_codec, **ac97_modem_codec; extern int ac97_codec_count, ac97_modem_codec_count, ac97_codec_id, ac97_modem_codec_id; +extern const device_t ad1881_device; extern const device_t alc100_device; extern const device_t cs4297_device; extern const device_t cs4297a_device; diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 9cd47ad90..d9dd75d76 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -29,6 +29,7 @@ enum { + AC97_CODEC_AD1881 = AC97_VENDOR_ID('A', 'D', 'S', 0x40), AC97_CODEC_ALC100 = AC97_VENDOR_ID('A', 'L', 'C', 0x20), AC97_CODEC_CS4297 = AC97_VENDOR_ID('C', 'R', 'Y', 0x03), AC97_CODEC_CS4297A = AC97_VENDOR_ID('C', 'R', 'Y', 0x13), @@ -332,6 +333,18 @@ ac97_codec_close(void *priv) } +const device_t ad1881_device = +{ + "Analog Devices AD1881", + DEVICE_AC97, + AC97_CODEC_AD1881, + ac97_codec_init, ac97_codec_close, ac97_codec_reset, + { NULL }, + NULL, + NULL, + NULL +}; + const device_t alc100_device = { "Avance Logic ALC100", From 1d57246ee84d739efb57cf9aa68255b43f42947d Mon Sep 17 00:00:00 2001 From: Ompronce <88358700+Ompronce@users.noreply.github.com> Date: Tue, 3 Aug 2021 02:46:09 -0400 Subject: [PATCH 39/52] Added correct AWE64 Gold RAM amounts Corrected AWE64 Gold RAM amounts based on formulas seen here - https://www.vogons.org/viewtopic.php?p=988235#p988235 --- src/sound/snd_sb.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 3d8e51806..f7914a46d 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -2560,21 +2560,18 @@ static const device_config_t sb_awe64_gold_config[] = { "onboard_ram", "Onboard RAM", CONFIG_SELECTION, "", 4096, "", { 0 }, { - { - "None", 0 - }, - { - "512 KB", 512 - }, - { - "2 MB", 2048 - }, { "4 MB", 4096 }, { "8 MB", 8192 }, + { + "12 MB", 12288 + }, + { + "16 MB", 16384 + }, { "28 MB", 28*1024 }, From d2d5906e2fb9accdd08bf55569a8d97437ae7a40 Mon Sep 17 00:00:00 2001 From: Ompronce <88358700+Ompronce@users.noreply.github.com> Date: Tue, 3 Aug 2021 02:57:54 -0400 Subject: [PATCH 40/52] Added correct SB 32 PnP RAM amounts Corrected Sound Blaster 32 PnP RAM amounts based on formulas seen here - https://www.vogons.org/viewtopic.php?p=988235#p988235 --- src/sound/snd_sb.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index f7914a46d..7361d90cd 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -2341,9 +2341,6 @@ static const device_config_t sb_32_pnp_config[] = { "None", 0 }, - { - "512 KB", 512 - }, { "2 MB", 2048 }, From a25eeed22850fc1ffcec8c8b95b4030be535b3a2 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 13:03:33 -0300 Subject: [PATCH 41/52] Improve VIA 686 Super I/O and hardware monitor to match probed hardware behavior --- src/device/hwm_vt82c686.c | 42 +++++++++++----- src/sio/sio_vt82c686.c | 102 +++++++++++++++++++++++++++----------- 2 files changed, 104 insertions(+), 40 deletions(-) diff --git a/src/device/hwm_vt82c686.c b/src/device/hwm_vt82c686.c index 70a01a6ac..1790cd483 100644 --- a/src/device/hwm_vt82c686.c +++ b/src/device/hwm_vt82c686.c @@ -29,18 +29,17 @@ #define CLAMP(a, min, max) (((a) < (min)) ? (min) : (((a) > (max)) ? (max) : (a))) #define VT82C686_RPM_TO_REG(r, d) ((r) ? CLAMP(1350000 / (r * d), 1, 255) : 0) -/* Temperature/voltage formulas and factors derived from Linux's via686a.c driver */ +/* Temperature/voltage formulas and factors derived from Linux's via686a.c driver. */ #define VT82C686_TEMP_TO_REG(t) (-1.160370e-10*(t*t*t*t*t*t) + 3.193693e-08*(t*t*t*t*t) - 1.464447e-06*(t*t*t*t) - 2.525453e-04*(t*t*t) + 1.424593e-02*(t*t) + 2.148941e+00*t + 7.275808e+01) #define VT82C686_VOLTAGE_TO_REG(v, f) CLAMP((((v) * (2.628 / (f))) - 120.5) / 25, 0, 255) typedef struct { hwm_values_t *values; - device_t *lm75[2]; uint8_t enable; uint16_t io_base; - uint8_t regs[80]; + uint8_t regs[128]; } vt82c686_t; @@ -59,6 +58,11 @@ vt82c686_read(uint16_t addr, void *priv) addr -= dev->io_base; switch (addr) { + case 0x00 ... 0x0f: case 0x50 ... 0x7f: /* undefined registers */ + /* Real 686B returns the contents of 0x40. */ + ret = dev->regs[0x40]; + break; + case 0x1f: case 0x20: case 0x21: /* temperatures */ ret = VT82C686_TEMP_TO_REG(dev->values->temperatures[(addr == 0x1f) ? 2 : (addr & 1)]); break; @@ -84,14 +88,26 @@ static void vt82c686_write(uint16_t port, uint8_t val, void *priv) { vt82c686_t *dev = (vt82c686_t *) priv; - uint8_t reg = port - dev->io_base; + uint8_t reg = port & 0x7f; - if ((reg == 0x41) || (reg == 0x42) || (reg == 0x45) || (reg == 0x46) || (reg == 0x48) || (reg == 0x4a) || (reg >= 0x4c)) - return; + switch (reg) { + case 0x00 ... 0x0f: + case 0x3f: case 0x41: case 0x42: case 0x4a: + case 0x4c ... 0x7f: + /* Read-only registers. */ + return; - if ((reg == 0x40) && (val & 0x80)) { - val &= 0x7f; - vt82c686_reset(dev, 1); + case 0x40: + /* Reset if requested. */ + if (val & 0x80) { + vt82c686_reset(dev, 1); + return; + } + break; + + case 0x48: + val &= 0x7f; + break; } dev->regs[reg] = val; @@ -106,7 +122,7 @@ vt82c686_hwm_write(uint8_t addr, uint8_t val, void *priv) vt82c686_t *dev = (vt82c686_t *) priv; if (dev->io_base) - io_removehandler(dev->io_base, 0x0050, + io_removehandler(dev->io_base, 128, vt82c686_read, NULL, NULL, vt82c686_write, NULL, NULL, dev); switch (addr) { @@ -126,7 +142,7 @@ vt82c686_hwm_write(uint8_t addr, uint8_t val, void *priv) } if (dev->enable && dev->io_base) - io_sethandler(dev->io_base, 0x0050, + io_sethandler(dev->io_base, 128, vt82c686_read, NULL, NULL, vt82c686_write, NULL, NULL, dev); } @@ -134,8 +150,10 @@ vt82c686_hwm_write(uint8_t addr, uint8_t val, void *priv) static void vt82c686_reset(vt82c686_t *dev, uint8_t initialization) { - memset(dev->regs, 0, 80); + memset(dev->regs, 0, sizeof(dev->regs)); + dev->regs[0x17] = 0x80; + dev->regs[0x3f] = 0xa2; dev->regs[0x40] = 0x08; dev->regs[0x47] = 0x50; dev->regs[0x4b] = 0x15; diff --git a/src/sio/sio_vt82c686.c b/src/sio/sio_vt82c686.c index 3c887fce0..007ae6d93 100644 --- a/src/sio/sio_vt82c686.c +++ b/src/sio/sio_vt82c686.c @@ -34,7 +34,8 @@ typedef struct { - uint8_t cur_reg, regs[32], fdc_dma, fdc_irq, uart_irq[2], lpt_dma, lpt_irq; + uint8_t cur_reg, last_val, regs[25], + fdc_dma, fdc_irq, uart_irq[2], lpt_dma, lpt_irq; fdc_t *fdc; serial_t *uart[2]; } vt82c686_t; @@ -43,10 +44,10 @@ typedef struct { static uint8_t get_lpt_length(vt82c686_t *dev) { - uint8_t length = 4; + uint8_t length = 4; /* non-EPP */ - if ((dev->regs[0x02] & 0x03) == 0x2) - length = 8; + if ((dev->regs[0x02] & 0x03) == 0x02) + length = 8; /* EPP */ return length; } @@ -64,6 +65,7 @@ vt82c686_fdc_handler(vt82c686_t *dev) fdc_set_dma_ch(dev->fdc, dev->fdc_dma); fdc_set_irq(dev->fdc, dev->fdc_irq); + fdc_set_swap(dev->fdc, dev->regs[0x16] & 0x01); } @@ -73,16 +75,20 @@ vt82c686_lpt_handler(vt82c686_t *dev) uint16_t io_mask, io_base = dev->regs[0x06] << 2; int io_len = get_lpt_length(dev); io_base &= (0xff8 | io_len); - io_mask = 0x3fc; + io_mask = 0x3fc; /* non-EPP */ if (io_len == 8) - io_mask = 0x3f8; + io_mask = 0x3f8; /* EPP */ lpt1_remove(); if (((dev->regs[0x02] & 0x03) != 0x03) && (io_base >= 0x100) && (io_base <= io_mask)) lpt1_init(io_base); - lpt1_irq(dev->lpt_irq); + if (dev->lpt_irq) { + lpt1_irq(dev->lpt_irq); + } else { + lpt1_irq(0xff); + } } @@ -91,8 +97,8 @@ vt82c686_serial_handler(vt82c686_t *dev, int uart) { serial_remove(dev->uart[uart]); - if (dev->regs[0x02] & (uart ? 0x08 : 0x04)) - serial_setup(dev->uart[uart], (dev->regs[0x07 + uart] & 0xfe) << 2, dev->uart_irq[uart]); + if (dev->regs[0x02] & (0x04 << uart)) + serial_setup(dev->uart[uart], dev->regs[0x07 + uart] << 2, dev->uart_irq[uart]); } @@ -101,25 +107,31 @@ vt82c686_write(uint16_t port, uint8_t val, void *priv) { vt82c686_t *dev = (vt82c686_t *) priv; + /* Store last written value for echo (see comment on read). */ + dev->last_val = val; + + /* Write current register index on port 0. */ if (!(port & 1)) { dev->cur_reg = val; return; } - /* NOTE: Registers are [0xE0:0xFF] but we store them as [0x00:0x1F]. */ - if (dev->cur_reg < 0xe0) - return; + /* NOTE: Registers are [0xE0:0xF8] but we store them as [0x00:0x18]. */ + if ((dev->cur_reg < 0xe0) || (dev->cur_reg > 0xf8)) + return; uint8_t reg = dev->cur_reg & 0x1f; - /* Read-only registers */ - if ((reg < 0x02) || (reg == 0x04) || (reg == 0x05) || ((reg >= 0x09) && (reg < 0x0e)) || - (reg == 0x13) || (reg == 0x15) || (reg == 0x17) || (reg >= 0x19)) + /* Read-only registers. */ + if ((reg < 0x02) || (reg == 0x0c)) return; + /* Write current register value on port 1. */ dev->regs[reg] = val; + /* Update device state. */ switch (reg) { case 0x02: + dev->regs[reg] &= 0xbf; vt82c686_lpt_handler(dev); vt82c686_serial_handler(dev, 0); vt82c686_serial_handler(dev, 1); @@ -127,19 +139,54 @@ vt82c686_write(uint16_t port, uint8_t val, void *priv) break; case 0x03: + dev->regs[reg] &= 0xfc; vt82c686_fdc_handler(dev); break; + case 0x04: + dev->regs[reg] &= 0xfc; + break; + + case 0x05: + dev->regs[reg] |= 0x03; + break; + case 0x06: vt82c686_lpt_handler(dev); break; - case 0x07: - vt82c686_serial_handler(dev, 0); + case 0x07: case 0x08: + dev->regs[reg] &= 0xfe; + vt82c686_serial_handler(dev, reg == 0x08); break; - case 0x08: - vt82c686_serial_handler(dev, 1); + case 0x0d: + dev->regs[reg] &= 0x0f; + break; + + case 0x0f: + dev->regs[reg] &= 0x7f; + break; + + case 0x10: + dev->regs[reg] &= 0xf4; + break; + + case 0x11: + dev->regs[reg] &= 0x3f; + break; + + case 0x13: + dev->regs[reg] &= 0xfb; + break; + + case 0x14: case 0x17: + dev->regs[reg] &= 0xfe; + break; + + case 0x16: + dev->regs[reg] &= 0xf7; + vt82c686_fdc_handler(dev); break; } } @@ -149,17 +196,16 @@ static uint8_t vt82c686_read(uint16_t port, void *priv) { vt82c686_t *dev = (vt82c686_t *) priv; - uint8_t ret = 0xff; - /* NOTE: Registers are [0xE0:0xFF] but we store them as [0x00:0x1F]. */ + /* NOTE: Registers are [0xE0:0xF8] but we store them as [0x00:0x18]. + Real 686B echoes the last read/written value when reading from + registers outside that range. */ if (!(port & 1)) - ret = dev->cur_reg; - else if (dev->cur_reg < 0xe0) - ret = 0xff; - else - ret = dev->regs[dev->cur_reg & 0x1f]; + dev->last_val = dev->cur_reg; + else if ((dev->cur_reg >= 0xe0) && (dev->cur_reg <= 0xf8)) + dev->last_val = dev->regs[dev->cur_reg & 0x1f]; - return ret; + return dev->last_val; } @@ -205,7 +251,7 @@ static void vt82c686_reset(vt82c686_t *dev) { memset(dev->regs, 0, 20); - + dev->regs[0x00] = 0x3c; dev->regs[0x02] = 0x03; dev->regs[0x03] = 0xfc; From ceea08f032662976d335e156136d18c5108355bc Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 13:17:49 -0300 Subject: [PATCH 42/52] Implement full CS423x RAM access (assumed 64k) --- src/sound/snd_cs423x.c | 55 ++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 17b386360..dadce7672 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -133,9 +133,9 @@ typedef struct cs423x_t void *gameport; void *i2c, *eeprom; - uint16_t wss_base, opl_base, sb_base, ctrl_base, ram_addr, eeprom_size: 11; - uint8_t type, ad1848_type, pnp_offset, regs[8], indirect_regs[16], - eeprom_data[2048], ram_data[384], ram_dl: 2, opl_wss: 1; + uint16_t wss_base, opl_base, sb_base, ctrl_base, ram_addr, eeprom_size: 11, pnp_offset; + uint8_t type, ad1848_type, regs[8], indirect_regs[16], + eeprom_data[2048], ram_data[65536], ram_dl: 2, opl_wss: 1; char *nvr_path; uint8_t pnp_enable: 1, key_pos: 5, slam_enable: 1, slam_state: 2, slam_ld, slam_reg; @@ -181,14 +181,9 @@ cs423x_read(uint16_t addr, void *priv) break; case 5: /* Control/RAM Access */ - /* Reading RAM is undocumented; the WDM driver does so. */ - if (dev->ram_dl == 3) { - if ((dev->ram_addr >= 0x4000) && (dev->ram_addr < 0x4180)) /* chip configuration and PnP resources */ - ret = dev->ram_data[dev->ram_addr & 0x01ff]; - else - ret = 0xff; - dev->ram_addr++; - } + /* Reading RAM is undocumented; the Windows drivers do so. */ + if (dev->ram_dl == 3) + ret = dev->ram_data[dev->ram_addr++]; break; case 7: /* Global Status */ @@ -311,9 +306,7 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) break; case 3: /* data */ - if ((dev->ram_addr >= 0x4000) && (dev->ram_addr < 0x4180)) /* chip configuration and PnP resources */ - dev->ram_data[dev->ram_addr & 0x01ff] = val; - dev->ram_addr++; + dev->ram_data[dev->ram_addr++] = val; break; } break; @@ -468,7 +461,7 @@ cs423x_slam_enable(cs423x_t *dev, uint8_t enable) } /* Enable SLAM if the CKD bit is not set. */ - if (enable && !(dev->ram_data[2] & 0x10)) { + if (enable && !(dev->ram_data[0x4002] & 0x10)) { dev->slam_enable = 1; io_sethandler(0x279, 1, NULL, NULL, NULL, cs423x_slam_write, NULL, NULL, dev); } @@ -543,25 +536,22 @@ cs423x_get_buffer(int32_t *buffer, int len, void *priv) static void cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig) { - uint8_t enable = ISAPNP_CARD_ENABLE; - if (dev->pnp_card) { - /* Hide PnP card if the PKD bit is set, or if PnP was disabled by command 0x55. */ - if ((dev->ram_data[2] & 0x20) || !dev->pnp_enable) - enable = ISAPNP_CARD_DISABLE; - /* Update PnP resource data if requested. */ if (update_rom) isapnp_update_card_rom(dev->pnp_card, &dev->ram_data[dev->pnp_offset], sizeof(dev->ram_data) - dev->pnp_offset); - /* Update PnP state. */ - isapnp_enable_card(dev->pnp_card, enable); + /* Hide PnP card if the PKD bit is set, or if PnP was disabled by command 0x55. */ + if ((dev->ram_data[0x4002] & 0x20) || !dev->pnp_enable) + isapnp_enable_card(dev->pnp_card, ISAPNP_CARD_DISABLE); + else + isapnp_enable_card(dev->pnp_card, ISAPNP_CARD_ENABLE); } /* Update some register bits based on the config data in RAM if requested. */ if (update_hwconfig) { /* Update WTEN. */ - if (dev->ram_data[3] & 0x08) { + if (dev->ram_data[0x4003] & 0x08) { dev->indirect_regs[8] |= 0x08; dev->ad1848.wten = 1; } else { @@ -570,13 +560,13 @@ cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig) } /* Update SPS. */ - if (dev->ram_data[3] & 0x04) + if (dev->ram_data[0x4003] & 0x04) dev->indirect_regs[8] |= 0x04; else dev->indirect_regs[8] &= ~0x04; /* Update IFM. */ - if (dev->ram_data[3] & 0x80) + if (dev->ram_data[0x4003] & 0x80) dev->ad1848.xregs[4] |= 0x10; else dev->ad1848.xregs[4] &= ~0x10; @@ -693,17 +683,20 @@ cs423x_reset(void *priv) { cs423x_t *dev = (cs423x_t *) priv; - /* Load EEPROM data to RAM, or just clear RAM if there's no EEPROM. */ + /* Clear RAM. */ + memset(dev->ram_data, 0, sizeof(dev->ram_data)); + if (dev->eeprom) { - memcpy(dev->ram_data, &dev->eeprom_data[4], MIN(sizeof(dev->ram_data), sizeof(dev->eeprom_data) - 4)); + /* Load EEPROM data to RAM. */ + memcpy(&dev->ram_data[0x4000], &dev->eeprom_data[4], MIN(384, ((dev->eeprom_data[2] << 8) | dev->eeprom_data[3]) - 4)); /* Save EEPROM contents to file. */ cs423x_nvram(dev, 1); - } else { - memset(dev->ram_data, 0, sizeof(dev->ram_data)); } /* Reset registers. */ + memset(dev->regs, 0, sizeof(dev->regs)); + dev->regs[1] = 0x80; memset(dev->indirect_regs, 0, sizeof(dev->indirect_regs)); dev->indirect_regs[1] = dev->type; if (dev->type == CRYSTAL_CS4238B) @@ -737,7 +730,7 @@ cs423x_init(const device_t *info) case CRYSTAL_CS4238B: /* Same WSS codec and EEPROM structure. */ dev->ad1848_type = AD1848_TYPE_CS4236; - dev->pnp_offset = 19; + dev->pnp_offset = 0x4013; /* Different Chip Version and ID registers, which shouldn't be reset by ad1848_init */ dev->ad1848.xregs[25] = dev->type; From b58fda26e9d4f392b5452a81710b7aa0558c99e3 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 13:18:05 -0300 Subject: [PATCH 43/52] Remove VIA AC97 debug logging --- src/sound/snd_ac97_via.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 3d9956ae7..fd0f81c9d 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -166,13 +166,11 @@ ac97_via_update_irqs(ac97_via_t *dev) /* Stop immediately if any flag is set. Doing it this way optimizes rising edges for the playback SGD (0 - first to be checked). */ if (dev->sgd_regs[i] & (dev->sgd_regs[i | 0x2] & 0x03)) { - pclog("irq set\n"); pci_set_irq(dev->slot, dev->irq_pin); return; } } - pclog("irq cleared\n"); pci_clear_irq(dev->slot, dev->irq_pin); } From 79c395afa66ffe84cccbefa40b9a0dead2ed0126 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 13:18:34 -0300 Subject: [PATCH 44/52] Fix small CS423x oversight --- src/sound/snd_cs423x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index dadce7672..f3d95828d 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -539,7 +539,7 @@ cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig) if (dev->pnp_card) { /* Update PnP resource data if requested. */ if (update_rom) - isapnp_update_card_rom(dev->pnp_card, &dev->ram_data[dev->pnp_offset], sizeof(dev->ram_data) - dev->pnp_offset); + isapnp_update_card_rom(dev->pnp_card, &dev->ram_data[dev->pnp_offset], 384); /* Hide PnP card if the PKD bit is set, or if PnP was disabled by command 0x55. */ if ((dev->ram_data[0x4002] & 0x20) || !dev->pnp_enable) From 8889e9477f829cddce4c834071100d9694d11b0d Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 16:39:46 -0300 Subject: [PATCH 45/52] Switch UM8669F dummy device to the more technically correct PNPFFFF --- src/sio/sio_um8669f.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sio/sio_um8669f.c b/src/sio/sio_um8669f.c index 516685629..6fd2d1477 100644 --- a/src/sio/sio_um8669f.c +++ b/src/sio/sio_um8669f.c @@ -61,7 +61,7 @@ static uint8_t um8669f_pnp_rom[] = { 0x22, 0xfa, 0x1f, /* IRQ 1/3/4/5/6/7/8/9/10/11/12 */ 0x47, 0x00, 0x00, 0x01, 0xf8, 0x03, 0x08, 0x08, /* I/O 0x100-0x3F8, decodes 10-bit, 8-byte alignment, 8 addresses */ - 0x15, 0x55, 0xa3, 0x86, 0x69, 0x00, /* logical device UMC8669 (just a dummy to create a gap in LDNs) */ + 0x15, 0x41, 0xd0, 0xff, 0xff, 0x00, /* logical device PNPFFFF (just a dummy to create a gap in LDNs) */ 0x15, 0x41, 0xd0, 0xb0, 0x2f, 0x01, /* logical device PNPB02F, can participate in boot */ 0x47, 0x00, 0x00, 0x01, 0xf8, 0x03, 0x08, 0x08, /* I/O 0x100-0x3F8, decodes 10-bit, 8-byte alignment, 8 addresses */ From f0176ceab672e9d95d482abcf0a5c5da05e201ff Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 16:43:58 -0300 Subject: [PATCH 46/52] Sound Blaster PnP/IDE overhaul, closes 86Box#1578 --- src/disk/hdc_ide.c | 66 ++++-- src/include/86box/hdc.h | 2 + src/include/86box/hdc_ide.h | 3 + src/include/86box/snd_sb.h | 2 +- src/sound/snd_sb.c | 407 ++++++++++++++---------------------- 5 files changed, 214 insertions(+), 266 deletions(-) diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index f7740fab8..c0cc93159 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -2765,7 +2765,7 @@ ide_board_init(int board, int irq, int base_main, int side_main, int type) } -static void +void ide_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) { if (ld) @@ -2796,12 +2796,23 @@ ide_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) static void * ide_ter_init(const device_t *info) { - int irq = device_get_config_int("irq"); - if (irq == -1) { - ide_board_init(2, -1, 0, 0, info->local); - isapnp_add_card(ide_ter_pnp_rom, sizeof(ide_ter_pnp_rom), ide_pnp_config_changed, NULL, NULL, NULL, (void *) 2); - } else - ide_board_init(2, irq, 0x168, 0x36e, info->local); + /* Don't claim this channel again if it was already claimed. */ + if (ide_boards[2]) + return(NULL); + + int irq; + if (info->local) + irq = -2; + else + irq = device_get_config_int("irq"); + + if (irq < 0) { + ide_board_init(2, -1, 0, 0, 0); + if (irq == -1) + isapnp_add_card(ide_ter_pnp_rom, sizeof(ide_ter_pnp_rom), ide_pnp_config_changed, NULL, NULL, NULL, (void *) 2); + } else { + ide_board_init(2, irq, 0x168, 0x36e, 0); + } return(ide_boards[2]); } @@ -2818,12 +2829,23 @@ ide_ter_close(void *priv) static void * ide_qua_init(const device_t *info) { - int irq = device_get_config_int("irq"); - if (irq == -1) { - ide_board_init(3, -1, 0, 0, info->local); - isapnp_add_card(ide_qua_pnp_rom, sizeof(ide_qua_pnp_rom), ide_pnp_config_changed, NULL, NULL, NULL, (void *) 3); - } else - ide_board_init(3, irq, 0x1e8, 0x3ee, info->local); + /* Don't claim this channel again if it was already claimed. */ + if (ide_boards[3]) + return(NULL); + + int irq; + if (info->local) + irq = -2; + else + irq = device_get_config_int("irq"); + + if (irq < 0) { + ide_board_init(3, -1, 0, 0, 0); + if (irq == -1) + isapnp_add_card(ide_qua_pnp_rom, sizeof(ide_qua_pnp_rom), ide_pnp_config_changed, NULL, NULL, NULL, (void *) 3); + } else { + ide_board_init(3, irq, 0x1e8, 0x3ee, 0); + } return(ide_boards[3]); } @@ -3103,6 +3125,15 @@ const device_t ide_ter_device = { ide_ter_config }; +const device_t ide_ter_pnp_device = { + "Tertiary IDE Controller (Plug and Play only)", + DEVICE_AT, + 1, + ide_ter_init, ide_ter_close, NULL, + { NULL }, NULL, NULL, + NULL +}; + const device_t ide_qua_device = { "Quaternary IDE Controller", DEVICE_AT, @@ -3111,3 +3142,12 @@ const device_t ide_qua_device = { { NULL }, NULL, NULL, ide_qua_config }; + +const device_t ide_qua_pnp_device = { + "Quaternary IDE Controller (Plug and Play only)", + DEVICE_AT, + 1, + ide_qua_init, ide_qua_close, NULL, + { NULL }, NULL, NULL, + ide_qua_config +}; diff --git a/src/include/86box/hdc.h b/src/include/86box/hdc.h index e840de3cf..9175dddaf 100644 --- a/src/include/86box/hdc.h +++ b/src/include/86box/hdc.h @@ -60,7 +60,9 @@ extern const device_t ide_cmd640_pci_single_channel_device; /* CMD PCI-640B PCI extern const device_t ide_opti611_vlb_device; /* OPTi 82c611/611A VLB */ extern const device_t ide_ter_device; +extern const device_t ide_ter_pnp_device; extern const device_t ide_qua_device; +extern const device_t ide_qua_pnp_device; extern const device_t xta_wdxt150_device; /* xta_wdxt150 */ extern const device_t xta_hd20_device; /* EuroPC internal */ diff --git a/src/include/86box/hdc_ide.h b/src/include/86box/hdc_ide.h index 48b7c8939..20742004e 100644 --- a/src/include/86box/hdc_ide.h +++ b/src/include/86box/hdc_ide.h @@ -136,6 +136,9 @@ extern void ide_sec_enable(void); extern void ide_sec_disable(void); extern void ide_board_set_force_ata3(int board, int force_ata3); +#ifdef EMU_ISAPNP_H +extern void ide_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv); +#endif extern double ide_atapi_get_period(uint8_t channel); #ifdef SCSI_DEVICE_H diff --git a/src/include/86box/snd_sb.h b/src/include/86box/snd_sb.h index cb850584c..8641a58f2 100644 --- a/src/include/86box/snd_sb.h +++ b/src/include/86box/snd_sb.h @@ -125,7 +125,7 @@ typedef struct sb_t int pos; - uint8_t pos_regs[8]; + uint8_t pos_regs[8], pnp_rom[512]; uint16_t opl_pnp_addr; } sb_t; diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 1d81447c8..287de664e 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -38,6 +38,8 @@ #include <86box/filters.h> #include <86box/isapnp.h> #include <86box/snd_sb.h> +#include <86box/hdc.h> +#include <86box/hdc_ide.h> /* 0 to 7 -> -14dB to 0dB i 2dB steps. 8 to 15 -> 0 to +14dB in 2dB steps. @@ -73,24 +75,81 @@ static const int sb_pro_mcv_irqs[4] = {7, 5, 3, 3}; /* Each card in the SB16 family has a million variants, and it shows in the large variety of device IDs for the PnP models. - These ROMs were reconstructed in a best-effort basis, around what Linux pnpdump configs and kernel logs could be found - in mailing lists, forums and other places, as well as Linux's own SB PnP card tables for ALSA and OSS. */ + This ROM was reconstructed in a best-effort basis around a pnpdump output log found in a forum. */ static uint8_t sb_16_pnp_rom[] = { - 0x0e, 0x8c, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, /* CTL0028, dummy checksum (filled in by isapnp_add_card) */ + 0x0e, 0x8c, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, /* CTL0024, dummy checksum (filled in by isapnp_add_card) */ 0x0a, 0x10, 0x10, /* PnP version 1.0, vendor version 1.0 */ 0x82, 0x11, 0x00, 'C', 'r', 'e', 'a', 't', 'i', 'v', 'e', ' ', 'S', 'B', '1', '6', ' ', 'P', 'n', 'P', /* ANSI identifier */ - 0x15, 0x0e, 0x8c, 0x00, 0x31, 0x00, /* logical device CTL0031 */ + 0x16, 0x0e, 0x8c, 0x00, 0x31, 0x00, 0x65, /* logical device CTL0031, supports vendor-specific registers 0x39/0x3A/0x3D/0x3F */ 0x82, 0x05, 0x00, 'A', 'u', 'd', 'i', 'o', /* ANSI identifier */ - 0x30, /* start dependent functions, acceptable */ + 0x31, 0x00, /* start dependent functions, preferred */ + 0x22, 0x20, 0x00, /* IRQ 5 */ + 0x2a, 0x02, 0x08, /* DMA 1, compatibility, no count by word, count by byte, not bus master, 8-bit only */ + 0x2a, 0x20, 0x12, /* DMA 5, compatibility, count by word, no count by byte, not bus master, 16-bit only */ + 0x47, 0x01, 0x20, 0x02, 0x20, 0x02, 0x01, 0x10, /* I/O 0x220, decodes 16-bit, 1-byte alignment, 16 addresses */ + 0x47, 0x01, 0x30, 0x03, 0x30, 0x03, 0x01, 0x02, /* I/O 0x330, decodes 16-bit, 1-byte alignment, 2 addresses */ + 0x47, 0x01, 0x88, 0x03, 0x88, 0x03, 0x01, 0x04, /* I/O 0x388, decodes 16-bit, 1-byte alignment, 4 addresses */ + 0x31, 0x01, /* start dependent functions, acceptable */ 0x22, 0xa0, 0x04, /* IRQ 5/7/10 */ 0x2a, 0x0b, 0x08, /* DMA 0/1/3, compatibility, no count by word, count by byte, not bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ + 0x2a, 0xe0, 0x12, /* DMA 5/6/7, compatibility, count by word, no count by byte, not bus master, 16-bit only */ 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ 0x47, 0x01, 0x88, 0x03, 0x88, 0x03, 0x01, 0x04, /* I/O 0x388, decodes 16-bit, 1-byte alignment, 4 addresses */ + 0x31, 0x01, /* start dependent functions, acceptable */ + 0x22, 0xa0, 0x04, /* IRQ 5/7/10 */ + 0x2a, 0x0b, 0x08, /* DMA 0/1/3, compatibility, no count by word, count by byte, not bus master, 8-bit only */ + 0x2a, 0xe0, 0x12, /* DMA 5/6/7, compatibility, count by word, no count by byte, not bus master, 16-bit only */ + 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ + 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ + 0x31, 0x02, /* start dependent functions, functional */ + 0x22, 0xa0, 0x04, /* IRQ 5/7/10 */ + 0x2a, 0x0b, 0x08, /* DMA 0/1/3, compatibility, no count by word, count by byte, not bus master, 8-bit only */ + 0x2a, 0xe0, 0x12, /* DMA 5/6/7, compatibility, count by word, no count by byte, not bus master, 16-bit only */ + 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ + 0x31, 0x02, /* start dependent functions, functional */ + 0x22, 0xa0, 0x04, /* IRQ 5/7/10 */ + 0x2a, 0x0b, 0x08, /* DMA 0/1/3, compatibility, no count by word, count by byte, not bus master, 8-bit only */ + 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ + 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ + 0x47, 0x01, 0x88, 0x03, 0x88, 0x03, 0x01, 0x04, /* I/O 0x388, decodes 16-bit, 1-byte alignment, 4 addresses */ + 0x31, 0x02, /* start dependent functions, functional */ + 0x22, 0xa0, 0x04, /* IRQ 5/7/10 */ + 0x2a, 0x0b, 0x08, /* DMA 0/1/3, compatibility, no count by word, count by byte, not bus master, 8-bit only */ + 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ + 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ + 0x31, 0x02, /* start dependent functions, functional */ + 0x22, 0xa0, 0x04, /* IRQ 5/7/10 */ + 0x2a, 0x0b, 0x08, /* DMA 0/1/3, compatibility, no count by word, count by byte, not bus master, 8-bit only */ + 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ 0x38, /* end dependent functions */ + 0x16, 0x0e, 0x8c, 0x20, 0x11, 0x00, 0x5a, /* logical device CTL2011, supports vendor-specific registers 0x39/0x3B/0x3C/0x3E */ + 0x1c, 0x41, 0xd0, 0x06, 0x00, /* compatible device PNP0600 */ + 0x82, 0x03, 0x00, 'I', 'D', 'E', /* ANSI identifier */ + 0x31, 0x00, /* start dependent functions, preferred */ + 0x22, 0x00, 0x04, /* IRQ 10 */ + 0x47, 0x01, 0x68, 0x01, 0x68, 0x01, 0x01, 0x08, /* I/O 0x168, decodes 16-bit, 1-byte alignment, 8 addresses */ + 0x47, 0x01, 0x6e, 0x03, 0x6e, 0x03, 0x01, 0x02, /* I/O 0x36E, decodes 16-bit, 1-byte alignment, 2 addresses */ + 0x31, 0x01, /* start dependent functions, acceptable */ + 0x22, 0x00, 0x08, /* IRQ 11 */ + 0x47, 0x01, 0xe8, 0x01, 0xe8, 0x01, 0x01, 0x08, /* I/O 0x1E8, decodes 16-bit, 1-byte alignment, 8 addresses */ + 0x47, 0x01, 0xee, 0x03, 0xee, 0x03, 0x01, 0x02, /* I/O 0x3EE, decodes 16-bit, 1-byte alignment, 2 addresses */ + 0x31, 0x01, /* start dependent functions, acceptable */ + 0x22, 0x00, 0x8c, /* IRQ 10/11/15 */ + 0x47, 0x01, 0x00, 0x01, 0xf8, 0x01, 0x08, 0x08, /* I/O 0x100-0x1F8, decodes 16-bit, 8-byte alignment, 8 addresses */ + 0x47, 0x01, 0x00, 0x03, 0xfe, 0x03, 0x02, 0x02, /* I/O 0x300-0x3FE, decodes 16-bit, 2-byte alignment, 2 addresses */ + 0x31, 0x02, /* start dependent functions, functional */ + 0x22, 0x00, 0x80, /* IRQ 15 */ + 0x47, 0x01, 0x70, 0x01, 0x70, 0x01, 0x01, 0x08, /* I/O 0x170, decodes 16-bit, 1-byte alignment, 8 addresses */ + 0x47, 0x01, 0x76, 0x03, 0x76, 0x03, 0x01, 0x02, /* I/O 0x376, decodes 16-bit, 1-byte alignment, 1 addresses */ + 0x38, /* end dependent functions */ + + 0x16, 0x41, 0xd0, 0xff, 0xff, 0x00, 0xda, /* logical device PNPFFFF, supports vendor-specific registers 0x38/0x39/0x3B/0x3C/0x3E */ + 0x82, 0x08, 0x00, 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', /* ANSI identifier */ + 0x47, 0x01, 0x00, 0x01, 0xf8, 0x03, 0x08, 0x01, /* I/O 0x100-0x3F8, decodes 16-bit, 8-byte alignment, 1 address */ + 0x15, 0x0e, 0x8c, 0x70, 0x01, 0x00, /* logical device CTL7001 */ 0x1c, 0x41, 0xd0, 0xb0, 0x2f, /* compatible device PNPB02F */ 0x82, 0x04, 0x00, 'G', 'a', 'm', 'e', /* ANSI identifier */ @@ -98,227 +157,6 @@ static uint8_t sb_16_pnp_rom[] = { 0x79, 0x00 /* end tag, dummy checksum (filled in by isapnp_add_card) */ }; -static uint8_t sb_32_pnp_rom[] = { - 0x0e, 0x8c, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, /* CTL0048, dummy checksum (filled in by isapnp_add_card) */ - 0x0a, 0x10, 0x10, /* PnP version 1.0, vendor version 1.0 */ - 0x82, 0x11, 0x00, 'C', 'r', 'e', 'a', 't', 'i', 'v', 'e', ' ', 'S', 'B', '3', '2', ' ', 'P', 'n', 'P', /* ANSI identifier */ - - 0x16, 0x0e, 0x8c, 0x00, 0x31, 0x00, 0xa9, /* logical device CTL0031, supports vendor-specific registers 0x38/0x3A/0x3C/0x3F */ - 0x82, 0x05, 0x00, 'A', 'u', 'd', 'i', 'o', /* ANSI identifier */ - 0x31, 0x00, /* start dependent functions, preferred */ - 0x22, 0x20, 0x00, /* IRQ 5 */ - 0x2a, 0x02, 0x0c, /* DMA 1, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0x20, 0x16, /* DMA 5, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x20, 0x02, 0x01, 0x10, /* I/O 0x220, decodes 16-bit, 1-byte alignment, 16 addresses */ - 0x47, 0x01, 0x30, 0x03, 0x30, 0x03, 0x01, 0x02, /* I/O 0x330, decodes 16-bit, 1-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0x88, 0x03, 0x01, 0x04, /* I/O 0x388, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0x88, 0x03, 0x01, 0x04, /* I/O 0x388, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0x88, 0x03, 0x01, 0x04, /* I/O 0x388, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0x94, 0x03, 0x04, 0x04, /* I/O 0x388-0x394, decodes 16-bit, 4-byte alignment, 4 addresses */ - 0x38, /* end dependent functions */ - - 0x16, 0x0e, 0x8c, 0x00, 0x21, 0x00, 0xa9, /* logical device CTL0021, supports vendor-specific registers 0x38/0x3A/0x3C/0x3F */ - 0x82, 0x09, 0x00, 'W', 'a', 'v', 'e', 'T', 'a', 'b', 'l', 'e', /* ANSI identifier */ - 0x31, 0x00, /* start dependent functions, preferred */ - 0x47, 0x01, 0x20, 0x06, 0x20, 0x06, 0x01, 0x04, /* I/O 0x620, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x47, 0x01, 0x20, 0x06, 0x80, 0x06, 0x20, 0x04, /* I/O 0x620-0x680, decodes 16-bit, 32-byte alignment, 4 addresses */ - 0x38, /* end dependent functions */ - - 0x15, 0x0e, 0x8c, 0x70, 0x01, 0x00, /* logical device CTL7001 */ - 0x1c, 0x41, 0xd0, 0xb0, 0x2f, /* compatible device PNPB02F */ - 0x82, 0x04, 0x00, 'G', 'a', 'm', 'e', /* ANSI identifier */ - 0x47, 0x01, 0x00, 0x02, 0x00, 0x02, 0x01, 0x08, /* I/O 0x200, decodes 16-bit, 1-byte alignment, 8 addresses */ - - 0x79, 0x00 /* end tag, dummy checksum (filled in by isapnp_add_card) */ -}; -static uint8_t sb_awe32_pnp_rom[] = { - 0x0e, 0x8c, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, /* CTL0043, dummy checksum (filled in by isapnp_add_card) */ - 0x0a, 0x10, 0x10, /* PnP version 1.0, vendor version 1.0 */ - 0x82, 0x15, 0x00, 'C', 'r', 'e', 'a', 't', 'i', 'v', 'e', ' ', 'S', 'B', ' ', 'A', 'W', 'E', '3', '2', ' ', 'P', 'n', 'P', /* ANSI identifier */ - - 0x16, 0x0e, 0x8c, 0x00, 0x31, 0x00, 0xa9, /* logical device CTL0031, supports vendor-specific registers 0x38/0x3A/0x3C/0x3F */ - 0x82, 0x05, 0x00, 'A', 'u', 'd', 'i', 'o', /* ANSI identifier */ - 0x31, 0x00, /* start dependent functions, preferred */ - 0x22, 0x20, 0x00, /* IRQ 5 */ - 0x2a, 0x02, 0x0c, /* DMA 1, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0x20, 0x16, /* DMA 5, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x20, 0x02, 0x01, 0x10, /* I/O 0x220, decodes 16-bit, 1-byte alignment, 16 addresses */ - 0x47, 0x01, 0x30, 0x03, 0x30, 0x03, 0x01, 0x02, /* I/O 0x330, decodes 16-bit, 1-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0xf8, 0x03, 0x01, 0x04, /* I/O 0x388-0x3F8, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0x88, 0x03, 0x01, 0x04, /* I/O 0x388, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0x88, 0x03, 0x01, 0x04, /* I/O 0x388, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x31, 0x02, /* start dependent functions, sub-optimal */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0x94, 0x03, 0x04, 0x04, /* I/O 0x388-0x394, decodes 16-bit, 4-byte alignment, 4 addresses */ - 0x38, /* end dependent functions */ - - 0x16, 0x0e, 0x8c, 0x00, 0x21, 0x00, 0xa9, /* logical device CTL0021, supports vendor-specific registers 0x38/0x3A/0x3C/0x3F */ - 0x82, 0x09, 0x00, 'W', 'a', 'v', 'e', 'T', 'a', 'b', 'l', 'e', /* ANSI identifier */ - 0x31, 0x00, /* start dependent functions, preferred */ - 0x47, 0x01, 0x20, 0x06, 0x20, 0x06, 0x01, 0x04, /* I/O 0x620, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x47, 0x01, 0x20, 0x0a, 0x20, 0x0a, 0x01, 0x04, /* I/O 0xA20, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x47, 0x01, 0x20, 0x0e, 0x20, 0x0e, 0x01, 0x04, /* I/O 0xE20, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x47, 0x01, 0x20, 0x06, 0x80, 0x06, 0x20, 0x04, /* I/O 0x620-0x680, decodes 16-bit, 32-byte alignment, 4 addresses */ - 0x47, 0x01, 0x20, 0x0a, 0x80, 0x0a, 0x20, 0x04, /* I/O 0xA20-0xA80, decodes 16-bit, 32-byte alignment, 4 addresses */ - 0x47, 0x01, 0x20, 0x0e, 0x80, 0x0e, 0x20, 0x04, /* I/O 0xE20-0xE80, decodes 16-bit, 32-byte alignment, 4 addresses */ - 0x38, /* end dependent functions */ - - 0x15, 0x0e, 0x8c, 0x70, 0x01, 0x00, /* logical device CTL7001 */ - 0x1c, 0x41, 0xd0, 0xb0, 0x2f, /* compatible device PNPB02F */ - 0x82, 0x04, 0x00, 'G', 'a', 'm', 'e', /* ANSI identifier */ - 0x47, 0x01, 0x00, 0x02, 0x00, 0x02, 0x01, 0x08, /* I/O 0x200, decodes 16-bit, 1-byte alignment, 8 addresses */ - - 0x79, 0x00 /* end tag, dummy checksum (filled in by isapnp_add_card) */ -}; -static uint8_t sb_awe64_gold_pnp_rom[] = { - 0x0e, 0x8c, 0x00, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, /* CTL009E, dummy checksum (filled in by isapnp_add_card) */ - 0x0a, 0x10, 0x20, /* PnP version 1.0, vendor version 2.0 */ - 0x82, 0x16, 0x00, 'C', 'r', 'e', 'a', 't', 'i', 'v', 'e', ' ', 'S', 'B', ' ', 'A', 'W', 'E', '6', '4', ' ', 'G', 'o', 'l', 'd', /* ANSI identifier */ - - 0x16, 0x0e, 0x8c, 0x00, 0x44, 0x00, 0xa9, /* logical device CTL0044, supports vendor-specific registers 0x38/0x3A/0x3C/0x3F */ - 0x82, 0x05, 0x00, 'A', 'u', 'd', 'i', 'o', /* ANSI identifier */ - 0x31, 0x00, /* start dependent functions, preferred */ - 0x22, 0x20, 0x00, /* IRQ 5 */ - 0x2a, 0x02, 0x0c, /* DMA 1, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0x20, 0x16, /* DMA 5, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x20, 0x02, 0x01, 0x10, /* I/O 0x220, decodes 16-bit, 1-byte alignment, 16 addresses */ - 0x47, 0x01, 0x30, 0x03, 0x30, 0x03, 0x01, 0x02, /* I/O 0x330, decodes 16-bit, 1-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0xf8, 0x03, 0x01, 0x04, /* I/O 0x388-0x3F8, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0xf8, 0x03, 0x01, 0x04, /* I/O 0x388-0x3F8, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0xf8, 0x03, 0x01, 0x04, /* I/O 0x388-0x3F8, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x31, 0x02, /* start dependent functions, sub-optimal */ - 0x22, 0xa0, 0x06, /* IRQ 5/7/9/10 */ - 0x2a, 0x0b, 0x0c, /* DMA 0/1/3, compatibility, no count by word, count by byte, is bus master, 8-bit only */ - 0x2a, 0xe0, 0x16, /* DMA 5/6/7, compatibility, count by word, no count by byte, is bus master, 16-bit only */ - 0x47, 0x01, 0x20, 0x02, 0x80, 0x02, 0x20, 0x10, /* I/O 0x220-0x280, decodes 16-bit, 32-byte alignment, 16 addresses */ - 0x47, 0x01, 0x00, 0x03, 0x30, 0x03, 0x30, 0x02, /* I/O 0x300-0x330, decodes 16-bit, 48-byte alignment, 2 addresses */ - 0x47, 0x01, 0x88, 0x03, 0x94, 0x03, 0x04, 0x04, /* I/O 0x388-0x394, decodes 16-bit, 4-byte alignment, 4 addresses */ - 0x38, /* end dependent functions */ - - 0x15, 0x0e, 0x8c, 0x70, 0x02, 0x00, /* logical device CTL7002 */ - 0x1c, 0x41, 0xd0, 0xb0, 0x2f, /* compatible device PNPB02F */ - 0x82, 0x04, 0x00, 'G', 'a', 'm', 'e', /* ANSI identifier */ - 0x47, 0x01, 0x00, 0x02, 0x00, 0x02, 0x01, 0x08, /* I/O 0x200, decodes 16-bit, 1-byte alignment, 8 addresses */ - - 0x16, 0x0e, 0x8c, 0x00, 0x23, 0x00, 0xa9, /* logical device CTL0023, supports vendor-specific registers 0x38/0x3A/0x3C/0x3F */ - 0x82, 0x09, 0x00, 'W', 'a', 'v', 'e', 'T', 'a', 'b', 'l', 'e', /* ANSI identifier */ - 0x31, 0x00, /* start dependent functions, preferred */ - 0x47, 0x01, 0x20, 0x06, 0x20, 0x06, 0x01, 0x04, /* I/O 0x620, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x47, 0x01, 0x20, 0x0a, 0x20, 0x0a, 0x01, 0x04, /* I/O 0xA20, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x47, 0x01, 0x20, 0x0e, 0x20, 0x0e, 0x01, 0x04, /* I/O 0xE20, decodes 16-bit, 1-byte alignment, 4 addresses */ - 0x30, /* start dependent functions, acceptable */ - 0x47, 0x01, 0x20, 0x06, 0x80, 0x06, 0x20, 0x04, /* I/O 0x620-0x680, decodes 16-bit, 32-byte alignment, 4 addresses */ - 0x47, 0x01, 0x20, 0x0a, 0x80, 0x0a, 0x20, 0x04, /* I/O 0xA20-0xA80, decodes 16-bit, 32-byte alignment, 4 addresses */ - 0x47, 0x01, 0x20, 0x0e, 0x80, 0x0e, 0x20, 0x04, /* I/O 0xE20-0xE80, decodes 16-bit, 32-byte alignment, 4 addresses */ - 0x38, /* end dependent functions */ - - 0x79, 0x00 /* end tag, dummy checksum (filled in by isapnp_add_card) */ -}; #ifdef ENABLE_SB_LOG @@ -1348,9 +1186,21 @@ sb_16_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) break; - case 1: /* Game */ + case 1: /* IDE */ + ide_pnp_config_changed(0, config, (void *) 2); + break; + + case 2: /* Reserved (16) / WaveTable (32+) */ + if (sb->dsp.sb_type > SB16) + emu8k_change_addr(&sb->emu8k, (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) ? config->io[0].base : 0); + break; + + case 3: /* Game */ gameport_remap(sb->gameport, (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) ? config->io[0].base : 0); break; + + case 4: /* StereoEnhance (32) */ + break; } } @@ -1362,15 +1212,13 @@ sb_awe32_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pr switch (ld) { case 0: /* Audio */ - sb_16_pnp_config_changed(0, config, sb); - break; - - case 1: /* WaveTable */ - emu8k_change_addr(&sb->emu8k, (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) ? config->io[0].base : 0); + case 1: /* IDE */ + sb_16_pnp_config_changed(ld, config, sb); break; case 2: /* Game */ - sb_16_pnp_config_changed(1, config, sb); + case 3: /* WaveTable */ + sb_16_pnp_config_changed(ld ^ 1, config, sb); break; } } @@ -1383,15 +1231,12 @@ sb_awe64_gold_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, voi switch (ld) { case 0: /* Audio */ - sb_16_pnp_config_changed(0, config, sb); + case 2: /* WaveTable */ + sb_16_pnp_config_changed(ld, config, sb); break; case 1: /* Game */ - sb_16_pnp_config_changed(1, config, sb); - break; - - case 2: /* WaveTable */ - emu8k_change_addr(&sb->emu8k, (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) ? config->io[0].base : 0); + sb_16_pnp_config_changed(3, config, sb); break; } } @@ -1821,6 +1666,8 @@ sb_16_pnp_init(const device_t *info) sb->gameport = gameport_add(&gameport_pnp_device); + device_add(&ide_ter_pnp_device); + isapnp_add_card(sb_16_pnp_rom, sizeof(sb_16_pnp_rom), sb_16_pnp_config_changed, NULL, NULL, NULL, sb); return sb; @@ -1834,6 +1681,27 @@ sb_awe32_available() } +static int +sb_32_pnp_available() +{ + return sb_awe32_available() && rom_present("roms/sound/CT3600 PnP.BIN"); +} + + +static int +sb_awe32_pnp_available() +{ + return sb_awe32_available() && rom_present("roms/sound/CT3980 PnP.BIN"); +} + + +static int +sb_awe64_gold_available() +{ + return sb_awe32_available() && rom_present("roms/sound/CT4540 PnP.BIN"); +} + + static void * sb_awe32_init(const device_t *info) { @@ -1899,7 +1767,7 @@ sb_awe32_pnp_init(const device_t *info) sb->opl_enabled = 1; opl3_init(&sb->opl); - sb_dsp_init(&sb->dsp, ((info->local == 2) ? SBAWE64 : SBAWE32), SB_SUBTYPE_DEFAULT, sb); + sb_dsp_init(&sb->dsp, (info->local == 2) ? SBAWE64 : SBAWE32, SB_SUBTYPE_DEFAULT, sb); sb_ct1745_mixer_reset(sb); sb->mixer_enabled = 1; @@ -1918,12 +1786,47 @@ sb_awe32_pnp_init(const device_t *info) sb->gameport = gameport_add(&gameport_pnp_device); - if (info->local == 2) - isapnp_add_card(sb_awe64_gold_pnp_rom, sizeof(sb_awe64_gold_pnp_rom), sb_awe64_gold_pnp_config_changed, NULL, NULL, NULL, sb); - else if (info->local == 1) - isapnp_add_card(sb_32_pnp_rom, sizeof(sb_32_pnp_rom), sb_awe32_pnp_config_changed, NULL, NULL, NULL, sb); - else - isapnp_add_card(sb_awe32_pnp_rom, sizeof(sb_awe32_pnp_rom), sb_awe32_pnp_config_changed, NULL, NULL, NULL, sb); + if (info->local != 2) + device_add(&ide_ter_pnp_device); + + char *pnp_rom_file = NULL; + switch (info->local) { + case 0: + pnp_rom_file = "roms/sound/CT3600 PnP.BIN"; + break; + + case 1: + pnp_rom_file = "roms/sound/CT3980 PnP.BIN"; + break; + + case 2: + pnp_rom_file = "roms/sound/CT4540 PnP.BIN"; + break; + } + + uint8_t *pnp_rom = NULL; + if (pnp_rom_file) { + FILE *f = rom_fopen(pnp_rom_file, "rb"); + if (f) { + if (fread(sb->pnp_rom, 1, 512, f) == 512) + pnp_rom = sb->pnp_rom; + fclose(f); + } + } + + switch (info->local) { + case 0: + isapnp_add_card(pnp_rom, sizeof(sb->pnp_rom), sb_16_pnp_config_changed, NULL, NULL, NULL, sb); + break; + + case 1: + isapnp_add_card(pnp_rom, sizeof(sb->pnp_rom), sb_awe32_pnp_config_changed, NULL, NULL, NULL, sb); + break; + + case 2: + isapnp_add_card(pnp_rom, sizeof(sb->pnp_rom), sb_awe64_gold_pnp_config_changed, NULL, NULL, NULL, sb); + break; + } return sb; } @@ -2708,9 +2611,9 @@ const device_t sb_32_pnp_device = { "Sound Blaster 32 PnP", DEVICE_ISA | DEVICE_AT, - 1, + 0, sb_awe32_pnp_init, sb_awe32_close, NULL, - { sb_awe32_available }, + { sb_32_pnp_available }, sb_speed_changed, NULL, sb_32_pnp_config @@ -2733,9 +2636,9 @@ const device_t sb_awe32_pnp_device = { "Sound Blaster AWE32 PnP", DEVICE_ISA | DEVICE_AT, - 0, + 1, sb_awe32_pnp_init, sb_awe32_close, NULL, - { sb_awe32_available }, + { sb_awe32_pnp_available }, sb_speed_changed, NULL, sb_awe32_pnp_config @@ -2747,7 +2650,7 @@ const device_t sb_awe64_gold_device = DEVICE_ISA | DEVICE_AT, 2, sb_awe32_pnp_init, sb_awe32_close, NULL, - { sb_awe32_available }, + { sb_awe64_gold_available }, sb_speed_changed, NULL, sb_awe64_gold_config From 3c997880717e2d0aeeb47cb81e03b9b41e04d20e Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 16:48:15 -0300 Subject: [PATCH 47/52] More UM8669F semantics stuff --- src/sio/sio_um8669f.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sio/sio_um8669f.c b/src/sio/sio_um8669f.c index 6fd2d1477..91b5c8d56 100644 --- a/src/sio/sio_um8669f.c +++ b/src/sio/sio_um8669f.c @@ -39,7 +39,7 @@ #include <86box/isapnp.h> -/* This ROM is reconstructed out of several assumptions, some of which are based on the IT8671F. */ +/* This ROM was reconstructed out of many assumptions, some of which based on the IT8671F. */ static uint8_t um8669f_pnp_rom[] = { 0x55, 0xa3, 0x86, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, /* UMC8669, dummy checksum (filled in by isapnp_add_card) */ 0x0a, 0x10, 0x10, /* PnP version 1.0, vendor version 1.0 */ @@ -151,8 +151,9 @@ um8669f_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pri fdc_set_irq(dev->fdc, config->irq[0].irq); fdc_set_dma_ch(dev->fdc, (config->dma[0].dma == ISAPNP_DMA_DISABLED) ? -1 : config->dma[0].dma); - } else + } else { um8669f_log("UM8669F: FDC disabled\n"); + } break; @@ -163,8 +164,9 @@ um8669f_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pri if (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) { um8669f_log("UM8669F: UART %d enabled at port %04X IRQ %d\n", ld - 1, config->io[0].base, config->irq[0].irq); serial_setup(dev->uart[ld - 1], config->io[0].base, config->irq[0].irq); - } else + } else { um8669f_log("UM8669F: UART %d disabled\n", ld - 1); + } break; @@ -174,8 +176,9 @@ um8669f_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pri if (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) { um8669f_log("UM8669F: LPT enabled at port %04X IRQ %d\n", config->io[0].base, config->irq[0].irq); lpt1_init(config->io[0].base); - } else + } else { um8669f_log("UM8669F: LPT disabled\n"); + } break; From 3babec62189ce34f13cdbee64473172d551748d3 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 20:28:03 -0300 Subject: [PATCH 48/52] Implement VIA AC97 clipping (not great atm) --- src/sound/snd_ac97_via.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index fd0f81c9d..72ff913f0 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -520,6 +520,15 @@ ac97_via_update(ac97_via_t *dev) int32_t l = (((dev->out_l * dev->pcm_vol_l) >> 15) * dev->master_vol_l) >> 15, r = (((dev->out_r * dev->pcm_vol_r) >> 15) * dev->master_vol_r) >> 15; + if (l < -32768) + l = -32768; + else if (l > 32767) + l = 32767; + if (r < -32768) + r = -32768; + else if (r > 32767) + r = 32767; + for (; dev->pos < sound_pos_global; dev->pos++) { dev->buffer[dev->pos*2] = l; dev->buffer[dev->pos*2 + 1] = r; From e937de67605b1c68ba4aef73c55ca829aa95d825 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 20:28:24 -0300 Subject: [PATCH 49/52] Implement VIA SBPro emulation --- src/chipset/via_pipc.c | 107 ++++++++++++++++++++++++----------------- src/sound/snd_sb.c | 1 - 2 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 18c3296a1..f62775dc7 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -84,8 +84,7 @@ typedef struct acpi_t *acpi; void *gameport, *ac97; sb_t *sb; - uint16_t midigame_base, fmnmi_base; - uint8_t fm_enabled; + uint16_t midigame_base, sb_base, fmnmi_base; } pipc_t; @@ -110,8 +109,8 @@ pipc_log(const char *fmt, ...) static void pipc_sgd_handlers(pipc_t *dev, uint8_t modem); -static void pipc_midigame_handlers(pipc_t *dev, uint8_t modem); static void pipc_codec_handlers(pipc_t *dev, uint8_t modem); +static void pipc_sb_handlers(pipc_t *dev, uint8_t modem); static uint8_t pipc_read(int func, int addr, void *priv); static void pipc_write(int func, int addr, uint8_t val, void *priv); @@ -364,8 +363,8 @@ pipc_reset_hard(void *priv) dev->ac97_regs[i][0x4b] = 0x02; pipc_sgd_handlers(dev, i); - pipc_midigame_handlers(dev, i); pipc_codec_handlers(dev, i); + pipc_sb_handlers(dev, i); } } @@ -471,33 +470,6 @@ pipc_sgd_handlers(pipc_t *dev, uint8_t modem) } -static uint8_t -pipc_midigame_read(uint16_t addr, void *priv) -{ - pipc_t *dev = (pipc_t *) priv; - - /* This BAR apparently doesn't work at all on a real 686B. It doesn't react to writes, - and reads always return 0x80 or 0xff depending on AC97 audio register 0x42 bit 7. */ - return (dev->ac97_regs[0][0x42] & 0x80) ? 0x80 : 0xff; -} - - -static void -pipc_midigame_handlers(pipc_t *dev, uint8_t modem) -{ - if (!dev->ac97 || modem) - return; - - if (dev->midigame_base) - io_removehandler(dev->midigame_base, 4, pipc_midigame_read, NULL, NULL, NULL, NULL, NULL, dev); - - dev->midigame_base = (dev->ac97_regs[0][0x19] << 8) | (dev->ac97_regs[0][0x18] & 0xfc); - - if (dev->midigame_base && (dev->ac97_regs[0][0x04] & PCI_COMMAND_IO)) - io_sethandler(dev->midigame_base, 4, pipc_midigame_read, NULL, NULL, NULL, NULL, NULL, dev); -} - - static void pipc_codec_handlers(pipc_t *dev, uint8_t modem) { @@ -533,6 +505,22 @@ pipc_fmnmi_read(uint16_t addr, void *priv) } +static void +pipc_fmnmi_handlers(pipc_t *dev, uint8_t modem) +{ + if (!dev->ac97 || modem) + return; + + if (dev->fmnmi_base) + io_removehandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, NULL, NULL, NULL, dev); + + dev->fmnmi_base = (dev->ac97_regs[0][0x15] << 8) | (dev->ac97_regs[0][0x14] & 0xfc); + + if (dev->fmnmi_base && (dev->ac97_regs[0][0x04] & PCI_COMMAND_IO)) + io_sethandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, NULL, NULL, NULL, dev); +} + + static uint8_t pipc_fm_read(uint16_t addr, void *priv) { @@ -580,25 +568,53 @@ pipc_fm_write(uint16_t addr, uint8_t val, void *priv) static void -pipc_fmnmi_handlers(pipc_t *dev, uint8_t modem) +pipc_sb_handlers(pipc_t *dev, uint8_t modem) { if (!dev->ac97 || modem) return; - if (dev->fmnmi_base) - io_removehandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, NULL, NULL, NULL, dev); + sb_dsp_setaddr(&dev->sb->dsp, 0); + if (dev->sb_base) { + io_removehandler(dev->sb_base, 4, opl3_read, NULL, NULL, opl3_write, NULL, NULL, &dev->sb->opl); + io_removehandler(dev->sb_base + 8, 2, opl3_read, NULL, NULL, opl3_write, NULL, NULL, &dev->sb->opl); + io_removehandler(dev->sb_base + 4, 2, sb_ct1345_mixer_read, NULL, NULL, sb_ct1345_mixer_write, NULL, NULL, dev->sb); + } - if (dev->fm_enabled) - io_removehandler(0x388, 4, pipc_fm_read, NULL, NULL, pipc_fm_write, NULL, NULL, dev); + mpu401_change_addr(dev->sb->mpu, 0); + mpu401_setirq(dev->sb->mpu, 0); - dev->fmnmi_base = (dev->ac97_regs[0][0x15] << 8) | (dev->ac97_regs[0][0x14] & 0xfc); - dev->fm_enabled = !!(dev->ac97_regs[0][0x42] & 0x04); + io_removehandler(0x388, 4, opl3_read, NULL, NULL, opl3_write, NULL, NULL, &dev->sb->opl); - if (dev->fmnmi_base && (dev->ac97_regs[0][0x04] & PCI_COMMAND_IO)) - io_sethandler(dev->fmnmi_base, 4, pipc_fmnmi_read, NULL, NULL, NULL, NULL, NULL, dev); + if (dev->ac97_regs[0][0x42] & 0x01) { + dev->sb_base = 0x220 + (0x20 * (dev->ac97_regs[0][0x43] & 0x03)); + sb_dsp_setaddr(&dev->sb->dsp, dev->sb_base); + if (dev->ac97_regs[0][0x42] & 0x04) { + io_sethandler(dev->sb_base, 4, opl3_read, NULL, NULL, opl3_write, NULL, NULL, &dev->sb->opl); + io_sethandler(dev->sb_base + 8, 2, opl3_read, NULL, NULL, opl3_write, NULL, NULL, &dev->sb->opl); + } + io_sethandler(dev->sb_base + 4, 2, sb_ct1345_mixer_read, NULL, NULL, sb_ct1345_mixer_write, NULL, NULL, dev->sb); - if (dev->fm_enabled) + uint8_t irq = 5 + (2 * ((dev->ac97_regs[0][0x43] >> 6) & 0x03)); + sb_dsp_setirq(&dev->sb->dsp, (irq == 11) ? 10 : irq); + + sb_dsp_setdma8(&dev->sb->dsp, (dev->ac97_regs[0][0x43] >> 4) & 0x03); + } + + if (dev->ac97_regs[0][0x42] & 0x02) { + /* BAR 2 is a mess. The MPU and game port remapping registers that VIA claims to be there don't + seem to actually exist on a real 686B. Remapping the MPU to BAR 2 itself does work, though. */ + if (dev->ac97_regs[0][0x42] & 0x80) + mpu401_change_addr(dev->sb->mpu, (dev->ac97_regs[0][0x19] << 8) | (dev->ac97_regs[0][0x18] & 0xfc)); + else + mpu401_change_addr(dev->sb->mpu, 0x300 | ((dev->ac97_regs[0][0x43] << 2) & 0x30)); + + if (!(dev->ac97_regs[0][0x42] & 0x40)) + mpu401_setirq(dev->sb->mpu, dev->sb->dsp.sb_irqnum); + } + + if (dev->ac97_regs[0][0x42] & 0x04) { io_sethandler(0x388, 4, pipc_fm_read, NULL, NULL, pipc_fm_write, NULL, NULL, dev); + } } @@ -1170,7 +1186,6 @@ pipc_write(int func, int addr, uint8_t val, void *priv) switch (addr) { case 0x04: dev->ac97_regs[func][addr] = val; - pipc_midigame_handlers(dev, func); pipc_sgd_handlers(dev, func); pipc_codec_handlers(dev, func); pipc_fmnmi_handlers(dev, func); @@ -1197,7 +1212,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) if (addr == 0x18) val = (val & 0xfc) | 1; dev->ac97_regs[func][addr] = val; - pipc_midigame_handlers(dev, func); + pipc_sb_handlers(dev, func); break; case 0x1c: case 0x1d: @@ -1219,7 +1234,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) dev->ac97_regs[0][addr] = dev->ac97_regs[1][addr] = val; gameport_remap(dev->gameport, (dev->ac97_regs[0][0x42] & 0x08) ? ((dev->ac97_regs[0][0x4b] << 8) | (dev->ac97_regs[0][0x4a] & 0xf8)) : 0); if (addr == 0x42) - pipc_fmnmi_handlers(dev, func); + pipc_sb_handlers(dev, func); break; case 0x43: @@ -1316,6 +1331,10 @@ pipc_init(const device_t *info) ac97_via_set_slot(dev->ac97, dev->slot, PCI_INTC); dev->sb = device_add(&sb_pro_compat_device); +#ifndef VIA_PIPC_FM_EMULATION + dev->sb->opl_enabled = 1; +#endif + sound_add_handler(sb_get_buffer_sbpro, dev->sb); dev->gameport = gameport_add(&gameport_sio_device); } diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 287de664e..24d3dc2af 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -1571,7 +1571,6 @@ sb_pro_compat_init(const device_t *info) sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0, sizeof(sb_t)); - sb->opl_enabled = 0; /* CS423x updates this, while VT82C686 lacks OPL */ opl3_init(&sb->opl); sb_dsp_init(&sb->dsp, SBPRO2, SB_SUBTYPE_DEFAULT, sb); From b0c1e4726fd9b33c47ad1a9e2c1da8d34632743e Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 21:24:08 -0300 Subject: [PATCH 50/52] VIA AC97: Fix SGD pause bit, fixes mpxplay looping on stop --- src/sound/snd_ac97_via.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 72ff913f0..18abf8a90 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -350,10 +350,10 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) if (val & 0x40) dev->sgd_regs[addr & 0xf0] &= ~0x88; - val &= 0x04; + val &= 0x08; /* (Un)pause SGD if requested. */ - if (val & 0x04) + if (val & 0x08) dev->sgd_regs[addr & 0xf0] |= 0x40; else dev->sgd_regs[addr & 0xf0] &= ~0x40; From 61784ca9f49e02f23443779aee0efbcef6e1a917 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 3 Aug 2021 21:36:20 -0300 Subject: [PATCH 51/52] VIA AC97: Remove status register workaround, fixed by the SGD pause bit fix --- src/sound/snd_ac97_via.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 18abf8a90..a09af6575 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -37,7 +37,7 @@ typedef struct { uint32_t entry_ptr, sample_ptr, fifo_pos, fifo_end; int32_t sample_count; - uint8_t entry_flags, fifo[32], restart, status_shadow; + uint8_t entry_flags, fifo[32], restart; pc_timer_t timer; } ac97_via_sgd_t; @@ -203,10 +203,6 @@ ac97_via_sgd_read(uint16_t addr, void *priv) if (!(addr & 0x80)) { /* Process SGD channel registers. */ switch (addr & 0xf) { - case 0x0: - ret = dev->sgd[addr >> 4].status_shadow; - break; - case 0x4: ret = dev->sgd[addr >> 4].entry_ptr; break; @@ -239,9 +235,6 @@ ac97_via_sgd_read(uint16_t addr, void *priv) ret = dev->sgd_regs[addr]; break; } - - /* Reset SGD status shadow register. See comment on SGD register 0x0 write for more information. */ - dev->sgd[addr >> 4].status_shadow = dev->sgd_regs[addr & 0xf0]; } else { /* Process regular registers. */ switch (addr) { @@ -319,11 +312,6 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) /* Update status interrupts. */ ac97_via_update_irqs(dev); - /* Work around a race condition with the V7.00b WDM driver expecting SGD Active to - not clear immediately. It reads this register next, so set up a shadow register - to ensure SGD Active is set for that specific read (but not subsequent ones). */ - dev->sgd[addr >> 4].status_shadow = dev->sgd_regs[addr] | 0x80; - return; case 0x1: From 6ee927458284652fb0692d305bc2c2cf3bb4aec0 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Wed, 4 Aug 2021 01:00:44 -0300 Subject: [PATCH 52/52] VIA AC97: Change FM data format after an exhaustive probe --- src/sound/snd_ac97_via.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index a09af6575..1707c0c9a 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -57,7 +57,7 @@ typedef struct _ac97_via_ { ac97_via_sgd_t sgd[6]; pc_timer_t timer_count, timer_count_fm; - uint64_t timer_latch; + uint64_t timer_latch, timer_latch_fm; int16_t out_l, out_r, fm_out_l, fm_out_r; int master_vol_l, master_vol_r, pcm_vol_l, pcm_vol_r, cd_vol_l, cd_vol_r; int32_t buffer[SOUNDBUFLEN * 2], fm_buffer[SOUNDBUFLEN * 2]; @@ -713,16 +713,18 @@ ac97_via_poll_fm(void *priv) /* Schedule next run if FM playback is enabled. */ if (dev->fm_enabled) - timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); + timer_advance_u64(&dev->timer_count_fm, dev->timer_latch_fm); /* Update FM audio buffer. */ ac97_via_update_fm(dev); /* Feed next sample from the FIFO. - Unknown data format assumed to be 8-bit stereo. */ - if ((sgd->fifo_end - sgd->fifo_pos) >= 2) { - dev->fm_out_l = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; - dev->fm_out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + The data format is not documented, but it probes as 16-bit stereo at 24 KHz. */ + if ((sgd->fifo_end - sgd->fifo_pos) >= 4) { + dev->out_l = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); + sgd->fifo_pos += 2; + dev->out_r = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); + sgd->fifo_pos += 2; return; } @@ -772,6 +774,7 @@ ac97_via_speed_changed(void *priv) freq = 48000.0; dev->timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / freq)); + dev->timer_latch_fm = (uint64_t) ((double) TIMER_USEC * (1000000.0 / 24000.0)); }