Add Adlib MCA, Sound Blaster MCV and Sound Blaster Pro MCV emulation.

This commit is contained in:
SarahW 2017-04-06 22:01:31 +01:00
commit 26e46bf61a
5 changed files with 273 additions and 0 deletions

View file

@ -1,7 +1,9 @@
#include <stdlib.h>
#include "ibm.h"
#include "device.h"
#include "io.h"
#include "sound.h"
#include "mca.h"
#include "sound_adlib.h"
#include "sound_opl.h"
@ -9,6 +11,8 @@
typedef struct adlib_t
{
opl_t opl;
uint8_t pos_regs[8];
} adlib_t;
static void adlib_get_buffer(int32_t *buffer, int len, void *p)
@ -24,6 +28,36 @@ static void adlib_get_buffer(int32_t *buffer, int len, void *p)
adlib->opl.pos = 0;
}
uint8_t adlib_mca_read(int port, void *p)
{
adlib_t *adlib = (adlib_t *)p;
pclog("adlib_mca_read: port=%04x\n", port);
return adlib->pos_regs[port & 7];
}
void adlib_mca_write(int port, uint8_t val, void *p)
{
adlib_t *adlib = (adlib_t *)p;
if (port < 0x102)
return;
pclog("adlib_mca_write: port=%04x val=%02x\n", port, val);
switch (port)
{
case 0x102:
if ((adlib->pos_regs[2] & 1) && !(val & 1))
io_removehandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &adlib->opl);
if (!(adlib->pos_regs[2] & 1) && (val & 1))
io_sethandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &adlib->opl);
break;
}
adlib->pos_regs[port & 7] = val;
}
void *adlib_init()
{
adlib_t *adlib = malloc(sizeof(adlib_t));
@ -33,6 +67,19 @@ void *adlib_init()
opl2_init(&adlib->opl);
io_sethandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &adlib->opl);
sound_add_handler(adlib_get_buffer, adlib);
return adlib;
}
void *adlib_mca_init()
{
adlib_t *adlib = adlib_init();
io_removehandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &adlib->opl);
mca_add(adlib_mca_read, adlib_mca_write, adlib);
adlib->pos_regs[0] = 0xd7;
adlib->pos_regs[1] = 0x70;
return adlib;
}
@ -54,3 +101,15 @@ device_t adlib_device =
NULL,
NULL
};
device_t adlib_mca_device =
{
"AdLib (MCA)",
DEVICE_MCA,
adlib_init,
adlib_close,
NULL,
NULL,
NULL,
NULL
};