The CD-ROM IOCTL direct pass through code now does sanity check on the requested data size before passing the command - fixes crashes with some DMA-only host DVD drives; The network poller is now in its own thread; The hack is back in the emulation of the National Semiconductors PC87306 Super I/O Chip - it's the only way right now to have serial working on that board; Fixed a part of the code that was still using NukedOPL even when OPL 3 was set to DOSBox OPL; Applied all mainline PCem commits.
174 lines
4.9 KiB
C++
174 lines
4.9 KiB
C++
/* Copyright holders: The DOSBox Team, SA1988
|
|
see COPYING for more details
|
|
*/
|
|
#include "dosbox/dbopl.h"
|
|
#include "dosbox/nukedopl.h"
|
|
#include "sound_dbopl.h"
|
|
|
|
int opl3_type = 0;
|
|
|
|
static struct
|
|
{
|
|
DBOPL::Chip chip;
|
|
struct opl3_chip opl3chip;
|
|
int addr;
|
|
int timer[2];
|
|
uint8_t timer_ctrl;
|
|
uint8_t status_mask;
|
|
uint8_t status;
|
|
int is_opl3;
|
|
|
|
void (*timer_callback)(void *param, int timer, int64_t period);
|
|
void *timer_param;
|
|
} opl[2];
|
|
|
|
enum
|
|
{
|
|
STATUS_TIMER_1 = 0x40,
|
|
STATUS_TIMER_2 = 0x20,
|
|
STATUS_TIMER_ALL = 0x80
|
|
};
|
|
|
|
enum
|
|
{
|
|
CTRL_IRQ_RESET = 0x80,
|
|
CTRL_TIMER1_MASK = 0x40,
|
|
CTRL_TIMER2_MASK = 0x20,
|
|
CTRL_TIMER2_CTRL = 0x02,
|
|
CTRL_TIMER1_CTRL = 0x01
|
|
};
|
|
|
|
void opl_init(void (*timer_callback)(void *param, int timer, int64_t period), void *timer_param, int nr, int is_opl3)
|
|
{
|
|
if (!is_opl3 || !opl3_type)
|
|
{
|
|
DBOPL::InitTables();
|
|
opl[nr].chip.Setup(48000, 0);
|
|
opl[nr].timer_callback = timer_callback;
|
|
opl[nr].timer_param = timer_param;
|
|
opl[nr].is_opl3 = is_opl3;
|
|
}
|
|
else
|
|
{
|
|
OPL3_Reset(&opl[nr].opl3chip, 48000);
|
|
opl[nr].timer_callback = timer_callback;
|
|
opl[nr].timer_param = timer_param;
|
|
opl[nr].is_opl3 = is_opl3;
|
|
}
|
|
}
|
|
|
|
void opl_status_update(int nr)
|
|
{
|
|
if (opl[nr].status & (STATUS_TIMER_1 | STATUS_TIMER_2) & opl[nr].status_mask)
|
|
opl[nr].status |= STATUS_TIMER_ALL;
|
|
else
|
|
opl[nr].status &= ~STATUS_TIMER_ALL;
|
|
}
|
|
|
|
void opl_timer_over(int nr, int timer)
|
|
{
|
|
if (!timer)
|
|
{
|
|
opl[nr].status |= STATUS_TIMER_1;
|
|
opl[nr].timer_callback(opl[nr].timer_param, 0, opl[nr].timer[0] * 4);
|
|
}
|
|
else
|
|
{
|
|
opl[nr].status |= STATUS_TIMER_2;
|
|
opl[nr].timer_callback(opl[nr].timer_param, 1, opl[nr].timer[1] * 16);
|
|
}
|
|
|
|
opl_status_update(nr);
|
|
}
|
|
|
|
void opl_write(int nr, uint16_t addr, uint8_t val)
|
|
{
|
|
if (!(addr & 1))
|
|
{
|
|
if (!opl[nr].is_opl3 || !opl3_type)
|
|
opl[nr].addr = (int)opl[nr].chip.WriteAddr(addr, val) & 0xff;
|
|
else
|
|
opl[nr].addr = (int)OPL3_WriteAddr(&opl[nr].opl3chip, addr, val) & 0x1ff;
|
|
}
|
|
else
|
|
{
|
|
if (!opl[nr].is_opl3 || !opl3_type)
|
|
opl[nr].chip.WriteReg(opl[nr].addr, val);
|
|
else
|
|
OPL3_WriteReg(&opl[nr].opl3chip, opl[nr].addr, val);
|
|
|
|
switch (opl[nr].addr)
|
|
{
|
|
case 0x02: /*Timer 1*/
|
|
opl[nr].timer[0] = 256 - val;
|
|
break;
|
|
case 0x03: /*Timer 2*/
|
|
opl[nr].timer[1] = 256 - val;
|
|
break;
|
|
case 0x04: /*Timer control*/
|
|
if (val & CTRL_IRQ_RESET) /*IRQ reset*/
|
|
{
|
|
opl[nr].status &= ~(STATUS_TIMER_1 | STATUS_TIMER_2);
|
|
opl_status_update(nr);
|
|
return;
|
|
}
|
|
if ((val ^ opl[nr].timer_ctrl) & CTRL_TIMER1_CTRL)
|
|
{
|
|
if (val & CTRL_TIMER1_CTRL)
|
|
opl[nr].timer_callback(opl[nr].timer_param, 0, opl[nr].timer[0] * 4);
|
|
else
|
|
opl[nr].timer_callback(opl[nr].timer_param, 0, 0);
|
|
}
|
|
if ((val ^ opl[nr].timer_ctrl) & CTRL_TIMER2_CTRL)
|
|
{
|
|
if (val & CTRL_TIMER2_CTRL)
|
|
opl[nr].timer_callback(opl[nr].timer_param, 1, opl[nr].timer[1] * 16);
|
|
else
|
|
opl[nr].timer_callback(opl[nr].timer_param, 1, 0);
|
|
}
|
|
opl[nr].status_mask = (~val & (CTRL_TIMER1_MASK | CTRL_TIMER2_MASK)) | 0x80;
|
|
opl[nr].timer_ctrl = val;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
uint8_t opl_read(int nr, uint16_t addr)
|
|
{
|
|
if (!(addr & 1))
|
|
{
|
|
return (opl[nr].status & opl[nr].status_mask) | (opl[nr].is_opl3 ? 0 : 0x06);
|
|
}
|
|
return opl[nr].is_opl3 ? 0 : 0xff;
|
|
}
|
|
|
|
void opl2_update(int nr, int16_t *buffer, int samples)
|
|
{
|
|
int c;
|
|
Bit32s buffer_32[samples];
|
|
|
|
opl[nr].chip.GenerateBlock2(samples, buffer_32);
|
|
|
|
for (c = 0; c < samples; c++)
|
|
buffer[c*2] = (int16_t)buffer_32[c];
|
|
}
|
|
|
|
void opl3_update(int nr, int16_t *buffer, int samples)
|
|
{
|
|
int c;
|
|
Bit32s buffer_32[samples*2];
|
|
|
|
if (opl3_type)
|
|
{
|
|
OPL3_GenerateStream(&opl[nr].opl3chip, buffer, samples);
|
|
}
|
|
else
|
|
{
|
|
opl[nr].chip.GenerateBlock3(samples, buffer_32);
|
|
|
|
for (c = 0; c < samples*2; c++)
|
|
buffer[c] = (int16_t)buffer_32[c];
|
|
}
|
|
}
|