Initial commit for AC97
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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 */
|
||||
};
|
||||
|
||||
|
||||
|
49
src/include/86box/snd_ac97.h
Normal file
49
src/include/86box/snd_ac97.h
Normal file
@@ -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, <richardg867@gmail.com>
|
||||
*
|
||||
* 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
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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 */
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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)
|
||||
|
227
src/sound/snd_ac97_codec.c
Normal file
227
src/sound/snd_ac97_codec.c
Normal file
@@ -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, <richardg867@gmail.com>
|
||||
*
|
||||
* Copyright 2021 RichardG.
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#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
|
||||
};
|
638
src/sound/snd_ac97_via.c
Normal file
638
src/sound/snd_ac97_via.c
Normal file
@@ -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, <richardg867@gmail.com>
|
||||
*
|
||||
* Copyright 2021 RichardG.
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#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
|
||||
};
|
@@ -19,7 +19,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <math.h>
|
||||
#include <math.h>
|
||||
#include <86box/86box.h>
|
||||
#include <86box/io.h>
|
||||
#include <86box/timer.h>
|
||||
|
@@ -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 \
|
||||
|
Reference in New Issue
Block a user