Changeset 9326 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Jun 2, 2008 9:20:46 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DevSB16.cpp
r7882 r9326 1 /* $Id$ */ 1 2 /** @file 3 * VBox SB16 Audio Controller. 4 * (r3917 sb16.c) 2 5 * 3 * VBox SB16 Audio Controller 4 * 5 * TODO: hiccups on NT4 and Win98. 6 * @todo hiccups on NT4 and Win98. 6 7 */ 7 8 … … 45 46 46 47 #define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0]))) 48 47 49 #define dolog(...) AUD_log ("sb16", __VA_ARGS__) 48 50 … … 56 58 #endif 57 59 58 #else 60 #else /* VBOX */ 59 61 60 62 DECLINLINE(void) dolog (const char *fmt, ...) … … 66 68 } 67 69 68 # ifdef DEBUG70 # ifdef DEBUG 69 71 static void ldebug (const char *fmt, ...) 70 72 { … … 75 77 va_end (ap); 76 78 } 77 # else79 # else 78 80 DECLINLINE(void) ldebug (const char *fmt, ...) 79 81 { 80 82 (void)fmt; 81 83 } 82 # endif84 # endif 83 85 84 86 #endif /* VBOX */ 85 87 88 #ifndef VBOX 89 #define IO_READ_PROTO(name) \ 90 uint32_t name (void *opaque, uint32_t nport) 91 #define IO_WRITE_PROTO(name) \ 92 void name (void *opaque, uint32_t nport, uint32_t val) 93 #else /* VBOX */ 86 94 #define IO_READ_PROTO(name) \ 87 88 95 DECLCALLBACK(int) name (PPDMDEVINS pDevIns, void *opaque, \ 96 RTIOPORT nport, uint32_t *pu32, unsigned cb) 89 97 90 98 #define IO_WRITE_PROTO(name) \ 91 DECLCALLBACK(int) name (PPDMDEVINS pDevIns, void *opaque, \ 92 RTIOPORT nport, uint32_t val, unsigned cb) 99 DECLCALLBACK(int) name (PPDMDEVINS pDevIns, void *opaque, \ 100 RTIOPORT nport, uint32_t val, unsigned cb) 101 #endif /* VBOX */ 93 102 94 103 static const char e3[] = "COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992."; … … 103 112 int port; 104 113 } conf = {5, 4, 5, 1, 5, 0x220}; 105 #endif 114 #endif /* !VBOX */ 106 115 107 116 typedef struct SB16State { … … 247 256 AUD_set_active_out (s->voice, 0); 248 257 } 249 #else 258 #else /* VBOX */ 250 259 if (hold) 251 260 { … … 259 268 AUD_set_active_out (s->voice, 0); 260 269 } 261 #endif 270 #endif /* VBOX */ 262 271 } 263 272 … … 265 274 static void aux_timer (void *opaque) 266 275 { 267 SB16State *s = (SB16State*)opaque;276 SB16State *s = opaque; 268 277 s->can_write = 1; 269 278 qemu_irq_raise (s->pic[s->irq]); 270 279 } 271 #else 280 #else /* VBOX */ 272 281 static DECLCALLBACK(void) sb16Timer(PPDMDEVINS pDevIns, PTMTIMER pTimer) 273 282 { … … 276 285 PDMDevHlpISASetIrq(s->pDevIns, s->irq, 1); 277 286 } 278 #endif 287 #endif /* VBOX */ 279 288 280 289 #define DMA8_AUTO 1 … … 374 383 break; 375 384 } 376 377 385 378 386 if (-1 != s->time_const) { … … 867 875 } 868 876 } 869 #else 877 ldebug ("mix silence %d %d %" PRId64 "\n", samples, bytes, ticks); 878 #else /* VBOX */ 870 879 ticks = (bytes * TMTimerGetFreq(s->pTimer)) / freq; 871 880 if (ticks < TMTimerGetFreq(s->pTimer) / 1024) 872 {873 881 PDMDevHlpISASetIrq(s->pDevIns, s->irq, 1); 874 }875 882 else 876 883 TMTimerSet(s->pTimer, TMTimerGet(s->pTimer) + ticks); 877 #endif878 884 ldebug ("mix silence %d %d % %RU64\n", samples, bytes, ticks); 885 #endif /* VBOX */ 879 886 } 880 887 break; … … 964 971 qemu_irq_lower (s->pic[s->irq]); 965 972 } 966 #else 973 #else /* VBOX */ 967 974 PDMDevHlpISASetIrq(s->pDevIns, s->irq, 0); 968 975 if (s->dma_auto) { … … 970 977 PDMDevHlpISASetIrq(s->pDevIns, s->irq, 0); 971 978 } 972 #endif 979 #endif /* VBOX */ 973 980 974 981 s->mixer_regs[0x82] = 0; … … 996 1003 997 1004 ldebug ("write %#x <- %#x\n", nport, val); 998 999 1005 switch (iport) { 1000 1006 case 0x06: … … 1077 1083 } 1078 1084 1085 #ifdef VBOX 1079 1086 return VINF_SUCCESS; 1087 #endif 1080 1088 } 1081 1089 … … 1086 1094 1087 1095 iport = nport - s->port; 1096 #ifdef VBOX 1097 /** @todo reject non-byte access? */ 1098 #endif 1088 1099 1089 1100 switch (iport) { … … 1202 1213 s->mixer_nreg = val; 1203 1214 1215 #ifdef VBOX 1204 1216 return VINF_SUCCESS; 1217 #endif 1205 1218 } 1206 1219 … … 1249 1262 dolog ("attempt to write into IRQ status register (val=%#x)\n", 1250 1263 val); 1264 #ifdef VBOX 1251 1265 return VINF_SUCCESS; 1266 #endif 1252 1267 1253 1268 default: … … 1260 1275 s->mixer_regs[s->mixer_nreg] = val; 1261 1276 1277 #ifdef VBOX /*???*/ 1262 1278 if (s->mixer_nreg == 0x30 || s->mixer_nreg == 0x31) 1263 1279 { … … 1267 1283 AUD_set_volume (AUD_MIXER_VOLUME, &mute, &lvol, &rvol); 1268 1284 } 1269 1285 #endif /* VBOX ??? */ 1286 1287 #ifdef VBOX 1270 1288 return VINF_SUCCESS; 1289 #endif 1271 1290 } 1272 1291 1273 1292 static IO_WRITE_PROTO(mixer_write) 1274 1293 { 1294 #ifndef VBOX 1295 mixer_write_indexb (opaque, nport, val & 0xff); 1296 mixer_write_datab (opaque, nport, (val >> 8) & 0xff); 1297 #else /* VBOX */ 1275 1298 SB16State *s = (SB16State*)opaque; 1276 1299 int iport = nport - s->port; … … 1297 1320 } 1298 1321 return VINF_SUCCESS; 1322 #endif /* VBOX */ 1299 1323 } 1300 1324 … … 1449 1473 } 1450 1474 1475 #ifndef VBOX 1476 static void SB_save (QEMUFile *f, void *opaque) 1477 { 1478 SB16State *s = opaque; 1479 #else 1451 1480 static DECLCALLBACK(int) SaveExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle) 1452 1481 { 1453 1482 SB16State *s = PDMINS2DATA (pDevIns, SB16State *); 1454 1483 QEMUFile *f = pSSMHandle; 1484 #endif 1455 1485 1456 1486 qemu_put_be32 (f, s->irq); … … 1502 1532 qemu_put_buffer (f, s->mixer_regs, 256); 1503 1533 1534 #ifdef VBOX 1504 1535 return VINF_SUCCESS; 1505 } 1506 1536 #endif 1537 } 1538 1539 #ifndef VBOX 1540 static int SB_load (QEMUFile *f, void *opaque, int version_id) 1541 { 1542 SB16State *s = opaque; 1543 1544 if (version_id != 1) { 1545 return -EINVAL; 1546 } 1547 #else /* VBOX */ 1507 1548 static DECLCALLBACK(int) LoadExec (PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, 1508 1549 uint32_t u32Version) … … 1516 1557 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION; 1517 1558 } 1559 #endif /* VBOX */ 1518 1560 1519 1561 s->irq=qemu_get_be32 (f); … … 1595 1637 } 1596 1638 1639 #ifdef VBOX 1597 1640 return VINF_SUCCESS; 1641 #endif 1598 1642 } 1599 1643 … … 1660 1704 return 0; 1661 1705 } 1662 #endif 1706 1707 #else /* VBOX */ 1663 1708 1664 1709 static DECLCALLBACK(void *) sb16QueryInterface (struct PDMIBASE *pInterface, … … 1682 1727 int rc; 1683 1728 1729 /* 1730 * Validations. 1731 */ 1684 1732 Assert(iInstance == 0); 1685 1686 uint32_t value; 1687 if (!CFGMR3AreValuesValid(pCfgHandle, "IRQ\0DMA\0DMA16\0Port\0Version\0")) 1733 if (!CFGMR3AreValuesValid(pCfgHandle, 1734 "IRQ\0" 1735 "DMA\0" 1736 "DMA16\0" 1737 "Port\0" 1738 "Version\0")) 1688 1739 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 1689 1740 N_("Invalid configuraton for sb16 device")); 1690 rc = CFGMR3QueryU32(pCfgHandle, "IRQ", &value); 1691 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 1692 s->irq = 5; 1693 else if (VBOX_FAILURE(rc)) 1741 1742 /* 1743 * Read config data. 1744 */ 1745 rc = CFGMR3QuerySIntDef(pCfgHandle, "IRQ", &s->irq, 5); 1746 if (VBOX_FAILURE(rc)) 1694 1747 return PDMDEV_SET_ERROR(pDevIns, rc, 1695 1748 N_("Configuration error: Failed to get the \"IRQ\" value")); 1696 else s->irq = value; 1697 rc = CFGMR3QueryU32(pCfgHandle, "DMA", &value); 1698 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 1699 s->dma = 1; 1700 else if (VBOX_FAILURE(rc)) 1749 1750 rc = CFGMR3QuerySIntDef(pCfgHandle, "DMA", &s->dma, 1); 1751 if (VBOX_FAILURE(rc)) 1701 1752 return PDMDEV_SET_ERROR(pDevIns, rc, 1702 1753 N_("Configuration error: Failed to get the \"DMA\" value")); 1703 else 1704 s->dma = value; 1705 rc = CFGMR3QueryU32(pCfgHandle, "DMA16", &value); 1706 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 1707 s->hdma = 5; 1708 else if (VBOX_FAILURE(rc)) 1754 1755 rc = CFGMR3QuerySIntDef(pCfgHandle, "DMA16", &s->hdma, 5); 1756 if (VBOX_FAILURE(rc)) 1709 1757 return PDMDEV_SET_ERROR(pDevIns, rc, 1710 1758 N_("Configuration error: Failed to get the \"DMA16\" value")); 1711 else 1712 s->hdma = value; 1713 rc = CFGMR3QueryU32(pCfgHandle, "Port", &value); 1714 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 1715 s->port = 0x220; 1716 else if (VBOX_FAILURE(rc)) 1759 1760 RTIOPORT Port; 1761 rc = CFGMR3QueryPortDef(pCfgHandle, "Port", &Port, 0x220); 1762 if (VBOX_FAILURE(rc)) 1717 1763 return PDMDEV_SET_ERROR(pDevIns, rc, 1718 1764 N_("Configuration error: Failed to get the \"Port\" value")); 1719 else 1720 s->port = value; 1721 uint16_t version; 1722 rc = CFGMR3QueryU16(pCfgHandle, "Version", &version); 1723 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 1724 s->ver = 0x0405; 1725 else if (VBOX_FAILURE(rc)) 1765 s->port = Port; 1766 1767 uint16_t u16Version; 1768 rc = CFGMR3QueryU16Def(pCfgHandle, "Version", &u16Version, 0x0405); 1769 if (VBOX_FAILURE(rc)) 1726 1770 return PDMDEV_SET_ERROR(pDevIns, rc, 1727 1771 N_("Configuration error: Failed to get the \"Version\" value")); 1728 else 1729 s->ver = version; 1730 1772 s->ver = u16Version; 1773 1774 /* 1775 * Init instance data. 1776 */ 1731 1777 s->pDevIns = pDevIns; 1732 1778 s->IBase.pfnQueryInterface = sb16QueryInterface; … … 1740 1786 s->csp_regs[9] = 0xf8; 1741 1787 1742 reset_mixer (s); 1743 1788 reset_mixer(s); 1789 1790 /* 1791 * Create timer, register & attach stuff. 1792 */ 1744 1793 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, sb16Timer, "SB16 timer", &s->pTimer); 1745 1794 if (VBOX_FAILURE(rc)) 1746 1795 AssertMsgFailedReturn(("pfnTMTimerCreate -> %Vrc\n", rc), rc); 1747 1796 1748 rc = PDMDevHlpIOPortRegister (pDevIns, s->port + 0x04, 2, s, 1749 mixer_write, mixer_read, NULL, NULL, "SB16"); 1750 if (VBOX_FAILURE (rc)) 1751 return rc; 1752 rc = PDMDevHlpIOPortRegister (pDevIns, s->port + 0x06, 10, s, 1753 dsp_write, dsp_read, NULL, NULL, "SB16"); 1754 if (VBOX_FAILURE (rc)) 1755 return rc; 1756 1757 rc = PDMDevHlpDMARegister (pDevIns, s->hdma, SB_read_DMA, s); 1758 if (VBOX_FAILURE (rc)) 1759 return rc; 1760 rc = PDMDevHlpDMARegister (pDevIns, s->dma, SB_read_DMA, s); 1761 if (VBOX_FAILURE (rc)) 1762 return rc; 1763 1764 s->can_write = 1; 1765 1766 rc = PDMDevHlpSSMRegister (pDevIns, pDevIns->pDevReg->szDeviceName, iInstance, SB16_SSM_VERSION, 1767 sizeof (*s), NULL, SaveExec, NULL, NULL, LoadExec, NULL); 1797 rc = PDMDevHlpIOPortRegister(pDevIns, s->port + 0x04, 2, s, 1798 mixer_write, mixer_read, NULL, NULL, "SB16"); 1768 1799 if (VBOX_FAILURE(rc)) 1769 1800 return rc; 1770 1771 rc = PDMDevHlpDriverAttach (pDevIns, 0, &s->IBase, &s->pDrvBase, "Audio Driver Port"); 1801 rc = PDMDevHlpIOPortRegister(pDevIns, s->port + 0x06, 10, s, 1802 dsp_write, dsp_read, NULL, NULL, "SB16"); 1803 if (VBOX_FAILURE(rc)) 1804 return rc; 1805 1806 rc = PDMDevHlpDMARegister(pDevIns, s->hdma, SB_read_DMA, s); 1807 if (VBOX_FAILURE(rc)) 1808 return rc; 1809 rc = PDMDevHlpDMARegister(pDevIns, s->dma, SB_read_DMA, s); 1810 if (VBOX_FAILURE(rc)) 1811 return rc; 1812 1813 s->can_write = 1; 1814 1815 rc = PDMDevHlpSSMRegister(pDevIns, pDevIns->pDevReg->szDeviceName, iInstance, SB16_SSM_VERSION, 1816 sizeof(*s), NULL, SaveExec, NULL, NULL, LoadExec, NULL); 1817 if (VBOX_FAILURE(rc)) 1818 return rc; 1819 1820 rc = PDMDevHlpDriverAttach(pDevIns, 0, &s->IBase, &s->pDrvBase, "Audio Driver Port"); 1772 1821 if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 1773 Log 1822 Log(("sb16: No attached driver!\n")); 1774 1823 else if (VBOX_FAILURE(rc)) 1775 1824 AssertMsgFailedReturn(("Failed to attach SB16 LUN #0! rc=%Vrc\n", rc), rc); 1776 1825 1777 AUD_register_card 1778 legacy_reset 1826 AUD_register_card("sb16", &s->card); 1827 legacy_reset(s); 1779 1828 1780 1829 if (!s->voice) … … 1784 1833 AUD_init_null(); 1785 1834 PDMDevHlpVMSetRuntimeError(pDevIns, false, "HostAudioNotResponding", 1786 1787 1835 N_("No audio devices could be opened. Selecting the NULL audio backend " 1836 "with the consequence that no sound is audible.")); 1788 1837 } 1789 1838 return VINF_SUCCESS; … … 1831 1880 NULL 1832 1881 }; 1882 1883 #endif /* VBOX */ 1884
Note:
See TracChangeset
for help on using the changeset viewer.