Added Adlib Gold surround module emulation.

This commit is contained in:
SarahW 2016-04-10 21:01:34 +01:00
commit 60440726a9
6 changed files with 239 additions and 16 deletions

View file

@ -4,6 +4,7 @@
#include "device.h"
#include "sound_opl.h"
#include "sound_ym7128.h"
#include "dma.h"
#include "io.h"
#include "pic.h"
@ -45,11 +46,14 @@ typedef struct adgold_t
} adgold_mma;
opl_t opl;
ym7128_t ym7128;
int16_t opl_buffer[SOUNDBUFLEN * 2];
int16_t mma_buffer[2][SOUNDBUFLEN];
int pos;
int surround_enabled;
} adgold_t;
void adgold_timer_poll();
@ -74,7 +78,7 @@ void adgold_update_irq_status(adgold_t *adgold)
if ((adgold->adgold_status ^ 0xf) && !adgold->adgold_irq_status)
{
pclog("adgold irq %02X\n", adgold->adgold_status);
// pclog("adgold irq %02X\n", adgold->adgold_status);
picint(0x80);
}
@ -146,6 +150,11 @@ void adgold_write(uint16_t addr, uint8_t val, void *p)
memcpy(adgold->adgold_eeprom, adgold->adgold_38x_regs, 0x19);
break;
case 0x18: /*Surround*/
adgold->adgold_38x_regs[0x18] = val;
ym7128_write(&adgold->ym7128, val);
break;
default:
adgold->adgold_38x_regs[adgold->adgold_38x_addr] = val;
break;
@ -215,7 +224,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p)
if (!(adgold->adgold_mma_regs[0][0x9] & 1))
adgold->adgold_mma.voice_count[0] = adgold->adgold_mma.voice_latch[0];
pclog("adgold start! FIFO fill %i %i %i %02X\n", (adgold->adgold_mma_fifo_end[0] - adgold->adgold_mma_fifo_start[0]) & 255, adgold->adgold_mma_fifo_end[0], adgold->adgold_mma_fifo_start[0], adgold->adgold_mma_regs[0][0xc]);
// pclog("adgold start! FIFO fill %i %i %i %02X\n", (adgold->adgold_mma_fifo_end[0] - adgold->adgold_mma_fifo_start[0]) & 255, adgold->adgold_mma_fifo_end[0], adgold->adgold_mma_fifo_start[0], adgold->adgold_mma_regs[0][0xc]);
if (adgold->adgold_mma_regs[0][0xc] & 1)
{
if (adgold->adgold_mma_regs[0][0xc] & 0x80)
@ -253,7 +262,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p)
}
}
}
pclog("adgold end\n");
// pclog("adgold end\n");
}
adgold->adgold_mma_enable[0] = val & 0x01;
break;
@ -302,7 +311,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p)
if (!(adgold->adgold_mma_regs[1][0x9] & 1))
adgold->adgold_mma.voice_count[1] = adgold->adgold_mma.voice_latch[1];
pclog("adgold start! FIFO fill %i %i %i %02X\n", (adgold->adgold_mma_fifo_end[1] - adgold->adgold_mma_fifo_start[1]) & 255, adgold->adgold_mma_fifo_end[1], adgold->adgold_mma_fifo_start[1], adgold->adgold_mma_regs[1][0xc]);
// pclog("adgold start! FIFO fill %i %i %i %02X\n", (adgold->adgold_mma_fifo_end[1] - adgold->adgold_mma_fifo_start[1]) & 255, adgold->adgold_mma_fifo_end[1], adgold->adgold_mma_fifo_start[1], adgold->adgold_mma_regs[1][0xc]);
if (adgold->adgold_mma_regs[1][0xc] & 1)
{
while (((adgold->adgold_mma_fifo_end[1] - adgold->adgold_mma_fifo_start[1]) & 255) < 128)
@ -310,7 +319,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p)
adgold_getsamp_dma(adgold, 1);
}
}
pclog("adgold end\n");
// pclog("adgold end\n");
}
adgold->adgold_mma_enable[1] = val & 0x01;
break;
@ -362,7 +371,10 @@ uint8_t adgold_read(uint16_t addr, void *p)
switch (adgold->adgold_38x_addr)
{
case 0x00: /*Control/ID*/
temp = 0x70; /*16-bit ISA, no telephone/surround/CD-ROM*/
if (adgold->surround_enabled)
temp = 0x50; /*16-bit ISA, surround module, no telephone/CDROM*/
else
temp = 0x70; /*16-bit ISA, no telephone/surround/CD-ROM*/
break;
default:
@ -400,7 +412,7 @@ uint8_t adgold_read(uint16_t addr, void *p)
temp = adgold->adgold_mma_regs[1][adgold->adgold_mma_addr];
break;
}
if (addr > 0x389) pclog("adgold_read : addr %04X %02X\n", addr, temp);
// if (addr > 0x389) pclog("adgold_read : addr %04X %02X\n", addr, temp);
return temp;
}
@ -480,7 +492,7 @@ void adgold_timer_poll(void *p)
if (!adgold->adgold_mma.timer0_count)
{
adgold->adgold_mma.timer0_count = adgold->adgold_mma.timer0_latch;
pclog("Timer 0 interrupt\n");
// pclog("Timer 0 interrupt\n");
adgold->adgold_mma_status |= 0x10;
adgold_update_irq_status(adgold);
}
@ -497,7 +509,7 @@ void adgold_timer_poll(void *p)
if (!adgold->adgold_mma.timer1_count)
{
adgold->adgold_mma.timer1_count = adgold->adgold_mma.timer1_latch;
pclog("Timer 1 interrupt\n");
// pclog("Timer 1 interrupt\n");
adgold->adgold_mma_status |= 0x20;
adgold_update_irq_status(adgold);
}
@ -508,7 +520,7 @@ void adgold_timer_poll(void *p)
if (!adgold->adgold_mma.timer2_count)
{
adgold->adgold_mma.timer2_count = adgold->adgold_mma.timer2_latch;
pclog("Timer 2 interrupt\n");
// pclog("Timer 2 interrupt\n");
adgold->adgold_mma_status |= 0x40;
adgold_update_irq_status(adgold);
}
@ -540,14 +552,24 @@ void adgold_timer_poll(void *p)
static void adgold_get_buffer(int16_t *buffer, int len, void *p)
{
adgold_t *adgold = (adgold_t *)p;
int16_t adgold_buffer[len*2];
int c;
opl3_update2(&adgold->opl);
for (c = 0; c < len * 2; c++)
{
buffer[c] += adgold->opl.buffer[c];
buffer[c] += adgold->mma_buffer[c & 1][c >> 1] / 2;
adgold_buffer[c] = adgold->opl.buffer[c] / 2;
adgold_buffer[c] += adgold->mma_buffer[c & 1][c >> 1] / 4;
buffer[c] += adgold_buffer[c];
}
if (adgold->surround_enabled)
{
ym7128_apply(&adgold->ym7128, adgold_buffer, len);
for (c = 0; c < len * 2; c++)
buffer[c] += adgold_buffer[c];
}
adgold->opl.pos = 0;
@ -557,10 +579,22 @@ static void adgold_get_buffer(int16_t *buffer, int len, void *p)
void *adgold_init()
{
FILE *f;
adgold_t *adgold = malloc(sizeof(adgold_t));
memset(adgold, 0, sizeof(adgold_t));
adgold->surround_enabled = device_get_config_int("surround");
opl3_init(&adgold->opl);
if (adgold->surround_enabled)
ym7128_init(&adgold->ym7128);
f = romfopen("nvr/adgold.bin", "rb");
if (f)
{
fread(adgold->adgold_eeprom, 0x18, 1, f);
fclose(f);
}
adgold->adgold_status = 0xf;
adgold->adgold_38x_addr = 0;
@ -585,11 +619,32 @@ void *adgold_init()
void adgold_close(void *p)
{
FILE *f;
adgold_t *adgold = (adgold_t *)p;
f = romfopen("nvr/adgold.bin", "wb");
if (f)
{
fwrite(adgold->adgold_eeprom, 0x18, 1, f);
fclose(f);
}
free(adgold);
}
static device_config_t adgold_config[] =
{
{
.name = "surround",
.description = "Surround module",
.type = CONFIG_BINARY,
.default_int = 1
},
{
.type = -1
}
};
device_t adgold_device =
{
"AdLib Gold",
@ -599,5 +654,6 @@ device_t adgold_device =
NULL,
NULL,
NULL,
NULL
NULL,
adgold_config
};