summaryrefslogtreecommitdiff
path: root/opl/opl_sdl.c
diff options
context:
space:
mode:
authorSimon Howard2015-05-30 13:04:56 -0400
committerSimon Howard2015-05-30 13:04:56 -0400
commit0e90c19ca717298f4f3b83dfd075cdf0c458de32 (patch)
tree09fae977fd34c03759d5c90e7daf2a087e6e7756 /opl/opl_sdl.c
parent5082f14944442344030d66f6fbdf86a75a1c1c70 (diff)
parent1e516e34911d3a95479c303fe26b59f20e618252 (diff)
downloadchocolate-doom-0e90c19ca717298f4f3b83dfd075cdf0c458de32.tar.gz
chocolate-doom-0e90c19ca717298f4f3b83dfd075cdf0c458de32.tar.bz2
chocolate-doom-0e90c19ca717298f4f3b83dfd075cdf0c458de32.zip
Merge pull request #545 from khokh2001/opl3_mode
opl: Add OPL3 mode. The DMX library had limited support for the features of the OPL3 chip, enabled by setting the DMXOPTIONS variable. This reproduces the OPL3 support in Chocolate Doom's OPL playback and emulation layer. Huge thanks to Alexey Khokholov for researching and developing this. This fixes #470.
Diffstat (limited to 'opl/opl_sdl.c')
-rw-r--r--opl/opl_sdl.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/opl/opl_sdl.c b/opl/opl_sdl.c
index 8834ee07..1334ac07 100644
--- a/opl/opl_sdl.c
+++ b/opl/opl_sdl.c
@@ -71,6 +71,7 @@ static uint64_t pause_offset;
// OPL software emulator structure.
static Chip opl_chip;
+static int opl_opl3mode;
// Temporary mixing buffer used by the mixing callback.
@@ -164,15 +165,30 @@ static void FillBuffer(int16_t *buffer, unsigned int nsamples)
assert(nsamples < mixing_freq);
- Chip__GenerateBlock2(&opl_chip, nsamples, mix_buffer);
+ if (opl_opl3mode)
+ {
+ Chip__GenerateBlock3(&opl_chip, nsamples, mix_buffer);
- // Mix into the destination buffer, doubling up into stereo.
+ // Mix into the destination buffer, doubling up into stereo.
- for (i=0; i<nsamples; ++i)
- {
- buffer[i * 2] = (int16_t) mix_buffer[i];
- buffer[i * 2 + 1] = (int16_t) mix_buffer[i];
+ for (i=0; i<nsamples; ++i)
+ {
+ buffer[i * 2] = (int16_t) mix_buffer[i * 2];
+ buffer[i * 2 + 1] = (int16_t) mix_buffer[i * 2 + 1];
+ }
}
+ else
+ {
+ Chip__GenerateBlock2(&opl_chip, nsamples, mix_buffer);
+
+ // Mix into the destination buffer, doubling up into stereo.
+
+ for (i=0; i<nsamples; ++i)
+ {
+ buffer[i * 2] = (int16_t) mix_buffer[i];
+ buffer[i * 2 + 1] = (int16_t) mix_buffer[i];
+ }
+ }
}
// Callback function to fill a new sound buffer:
@@ -351,13 +367,14 @@ static int OPL_SDL_Init(unsigned int port_base)
// Mix buffer:
- mix_buffer = malloc(mixing_freq * sizeof(uint32_t));
+ mix_buffer = malloc(mixing_freq * sizeof(uint32_t) * 2);
// Create the emulator structure:
DBOPL_InitTables();
Chip__Chip(&opl_chip);
Chip__Setup(&opl_chip, mixing_freq);
+ opl_opl3mode = 0;
callback_mutex = SDL_CreateMutex();
callback_queue_mutex = SDL_CreateMutex();
@@ -372,6 +389,11 @@ static unsigned int OPL_SDL_PortRead(opl_port_t port)
{
unsigned int result = 0;
+ if (port == OPL_REGISTER_PORT_OPL3)
+ {
+ return 0xff;
+ }
+
if (timer1.enabled && current_time > timer1.expire_time)
{
result |= 0x80; // Either have expired
@@ -439,6 +461,9 @@ static void WriteRegister(unsigned int reg_num, unsigned int value)
break;
+ case OPL_REG_NEW:
+ opl_opl3mode = value & 0x01;
+
default:
Chip__WriteReg(&opl_chip, reg_num, value);
break;
@@ -451,6 +476,10 @@ static void OPL_SDL_PortWrite(opl_port_t port, unsigned int value)
{
register_num = value;
}
+ else if (port == OPL_REGISTER_PORT_OPL3)
+ {
+ register_num = value | 0x100;
+ }
else if (port == OPL_DATA_PORT)
{
WriteRegister(register_num, value);