Merge remote-tracking branch 'origin/master' into version/4.1

This commit is contained in:
OBattler
2023-10-10 00:23:30 +02:00
36 changed files with 1153 additions and 400 deletions

View File

@@ -98,7 +98,7 @@ public:
memset(m_samples, 0, sizeof(m_samples));
memset(m_oldsamples, 0, sizeof(m_oldsamples));
m_rateratio = (samplerate << RSM_FRAC) / m_chip.sample_rate(m_clock);
m_clock_us = 1000000 / (double) m_clock;
m_clock_us = 1000000.0 / (double) m_clock;
m_subtract[0] = 80.0;
m_subtract[1] = 320.0;
m_type = type;
@@ -139,7 +139,7 @@ public:
virtual void set_clock(uint32_t clock) override
{
m_clock = clock;
m_clock_us = 1000000 / (double) m_clock;
m_clock_us = 1000000.0 / (double) m_clock;
m_rateratio = (m_samplerate << RSM_FRAC) / m_chip.sample_rate(m_clock);
ymfm_set_timer(0, m_duration_in_clocks[0]);
@@ -150,9 +150,14 @@ public:
{
for (uint32_t i = 0; i < num_samples; i++) {
m_chip.generate(&m_output);
if(m_type == FM_YMF278B) {
*data++ += m_output.data[4 % ChipType::OUTPUTS];
*data++ += m_output.data[5 % ChipType::OUTPUTS];
if ((m_type == FM_YMF278B) && (sizeof(m_output.data) > (4 * sizeof(int32_t)))) {
if (ChipType::OUTPUTS == 1) {
*data++ += m_output.data[4];
*data++ += m_output.data[4];
} else {
*data++ += m_output.data[4];
*data++ += m_output.data[5];
}
} else if (ChipType::OUTPUTS == 1) {
*data++ = m_output.data[0];
*data++ = m_output.data[0];
@@ -170,9 +175,14 @@ public:
m_oldsamples[0] = m_samples[0];
m_oldsamples[1] = m_samples[1];
m_chip.generate(&m_output);
if(m_type == FM_YMF278B) {
m_samples[0] += m_output.data[4 % ChipType::OUTPUTS];
m_samples[1] += m_output.data[5 % ChipType::OUTPUTS];
if ((m_type == FM_YMF278B) && (sizeof(m_output.data) > (4 * sizeof(int32_t)))) {
if (ChipType::OUTPUTS == 1) {
m_samples[0] += m_output.data[4];
m_samples[1] += m_output.data[4];
} else {
m_samples[0] += m_output.data[4];
m_samples[1] += m_output.data[5];
}
} else if (ChipType::OUTPUTS == 1) {
m_samples[0] = m_output.data[0];
m_samples[1] = m_output.data[0];
@@ -312,11 +322,13 @@ ymfm_drv_init(const device_t *info)
break;
case FM_YMF289B:
fm = (YMFMChipBase *) new YMFMChip<ymfm::ymf289b>(33868800, FM_YMF289B, OPL_FREQ);
/* According to the datasheet, we should be using 33868800, but YMFM appears
to cheat and does it using the same values as the YMF262. */
fm = (YMFMChipBase *) new YMFMChip<ymfm::ymf289b>(14318181, FM_YMF289B, 44100);
break;
case FM_YMF278B:
fm = (YMFMChipBase *) new YMFMChip<ymfm::ymf278b>(33868800, FM_YMF278B, 48000);
fm = (YMFMChipBase *) new YMFMChip<ymfm::ymf278b>(33868800, FM_YMF278B, 44100);
break;
}

View File

@@ -854,6 +854,15 @@ sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *priv)
case 0x84:
/* MPU Control register, per the Linux source code. */
/* Bits 2-1: MPU-401 address:
0, 0 = 330h;
0, 1 = Disabled;
1, 0 = 300h;
1, 1 = ???? (Reserved?)
Bit 0: Gameport address:
0, 0 = 200-207h;
0, 1 = Disabled
*/
if (sb->mpu != NULL) {
if ((val & 0x06) == 0x00)
mpu401_change_addr(sb->mpu, 0x330);
@@ -862,6 +871,12 @@ sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *priv)
else if ((val & 0x06) == 0x02)
mpu401_change_addr(sb->mpu, 0);
}
sb->gameport_addr = 0;
gameport_remap(sb->gameport, 0);
if (!(val & 0x01)) {
sb->gameport_addr = 0x200;
gameport_remap(sb->gameport, 0x200);
}
break;
default:
@@ -1055,6 +1070,8 @@ sb_ct1745_mixer_read(uint16_t addr, void *priv)
else
ret = 0x06; /* Should never happen. */
}
if (!sb->gameport_addr)
ret |= 0x01;
break;
case 0x90:
@@ -1375,6 +1392,45 @@ sb_16_reply_mca_write(int port, uint8_t val, void *priv)
sb_dsp_setdma16(&sb->dsp, high_dma);
}
void
sb_vibra16s_onboard_relocate_base(uint16_t new_addr, void *priv)
{
sb_t *sb = (sb_t *) priv;
uint16_t addr = sb->dsp.sb_addr;
io_removehandler(addr, 0x0004,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
io_removehandler(addr + 8, 0x0002,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
io_removehandler(addr + 4, 0x0002,
sb_ct1745_mixer_read, NULL, NULL,
sb_ct1745_mixer_write, NULL, NULL,
sb);
sb_dsp_setaddr(&sb->dsp, 0);
addr = new_addr;
io_sethandler(addr, 0x0004,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
io_sethandler(addr + 8, 0x0002,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
io_sethandler(addr + 4, 0x0002,
sb_ct1745_mixer_read, NULL, NULL,
sb_ct1745_mixer_write, NULL, NULL,
sb);
sb_dsp_setaddr(&sb->dsp, addr);
}
static void
sb_16_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv)
{
@@ -1481,6 +1537,100 @@ sb_16_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv)
}
}
static void
sb_vibra16_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv)
{
sb_t *sb = (sb_t *) priv;
uint16_t addr = sb->dsp.sb_addr;
uint8_t val;
switch (ld) {
case 0: /* Audio */
io_removehandler(addr, 0x0004,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
io_removehandler(addr + 8, 0x0002,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
io_removehandler(addr + 4, 0x0002,
sb_ct1745_mixer_read, NULL, NULL,
sb_ct1745_mixer_write, NULL, NULL,
sb);
addr = sb->opl_pnp_addr;
if (addr) {
sb->opl_pnp_addr = 0;
io_removehandler(addr, 0x0004,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
}
sb_dsp_setaddr(&sb->dsp, 0);
sb_dsp_setirq(&sb->dsp, 0);
sb_dsp_setdma8(&sb->dsp, ISAPNP_DMA_DISABLED);
sb_dsp_setdma16(&sb->dsp, ISAPNP_DMA_DISABLED);
mpu401_change_addr(sb->mpu, 0);
if (config->activate) {
addr = config->io[0].base;
if (addr != ISAPNP_IO_DISABLED) {
io_sethandler(addr, 0x0004,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
io_sethandler(addr + 8, 0x0002,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
io_sethandler(addr + 4, 0x0002,
sb_ct1745_mixer_read, NULL, NULL,
sb_ct1745_mixer_write, NULL, NULL,
sb);
sb_dsp_setaddr(&sb->dsp, addr);
}
addr = config->io[1].base;
if (addr != ISAPNP_IO_DISABLED)
mpu401_change_addr(sb->mpu, addr);
addr = config->io[2].base;
if (addr != ISAPNP_IO_DISABLED) {
sb->opl_pnp_addr = addr;
io_sethandler(addr, 0x0004,
sb->opl.read, NULL, NULL,
sb->opl.write, NULL, NULL,
sb->opl.priv);
}
val = config->irq[0].irq;
if (val != ISAPNP_IRQ_DISABLED)
sb_dsp_setirq(&sb->dsp, val);
val = config->dma[0].dma;
if (val != ISAPNP_DMA_DISABLED)
sb_dsp_setdma8(&sb->dsp, val);
val = config->dma[1].dma;
if (val != ISAPNP_DMA_DISABLED)
sb_dsp_setdma16(&sb->dsp, val);
}
break;
case 1: /* Game */
gameport_remap(sb->gameport, (config->activate && (config->io[0].base != ISAPNP_IO_DISABLED)) ? config->io[0].base : 0);
break;
default:
break;
}
}
static void
sb_awe32_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv)
{
@@ -1926,7 +2076,7 @@ sb_16_init(UNUSED(const device_t *info))
sb->opl_enabled = device_get_config_int("opl");
if (sb->opl_enabled)
fm_driver_get(FM_YMF262, &sb->opl);
fm_driver_get(info->local, &sb->opl);
sb_dsp_init(&sb->dsp, SB16, SB_SUBTYPE_DEFAULT, sb);
sb_dsp_setaddr(&sb->dsp, addr);
@@ -1968,6 +2118,9 @@ sb_16_init(UNUSED(const device_t *info))
if (device_get_config_int("receive_input"))
midi_in_handler(1, sb_dsp_input_msg, sb_dsp_input_sysex, &sb->dsp);
sb->gameport = gameport_add(&gameport_pnp_device);
sb->gameport_addr = 0x200;
return sb;
}
@@ -2003,6 +2156,8 @@ sb_16_reply_mca_init(UNUSED(const device_t *info))
sb->pos_regs[0] = 0x38;
sb->pos_regs[1] = 0x51;
sb->gameport_addr = 0x200;
return sb;
}
@@ -2045,6 +2200,94 @@ sb_16_pnp_init(UNUSED(const device_t *info))
mpu401_change_addr(sb->mpu, 0);
ide_remove_handlers(2);
sb->gameport_addr = 0;
gameport_remap(sb->gameport, 0);
return sb;
}
static int
sb_vibra16xv_available(void)
{
return rom_present("roms/sound/CT4170 PnP.BIN");
}
static int
sb_vibra16c_available(void)
{
return rom_present("roms/sound/CT4180 PnP.BIN");
}
static void *
sb_vibra16_pnp_init(UNUSED(const device_t *info))
{
sb_t *sb = malloc(sizeof(sb_t));
memset(sb, 0x00, sizeof(sb_t));
sb->opl_enabled = 1;
fm_driver_get(FM_YMF262, &sb->opl);
sb_dsp_init(&sb->dsp, SB16, SB_SUBTYPE_DEFAULT, sb);
sb_ct1745_mixer_reset(sb);
sb->mixer_enabled = 1;
sb->mixer_sb16.output_filter = 1;
sound_add_handler(sb_get_buffer_sb16_awe32, sb);
sound_set_cd_audio_filter(sb16_awe32_filter_cd_audio, sb);
sb->mpu = (mpu_t *) malloc(sizeof(mpu_t));
memset(sb->mpu, 0, sizeof(mpu_t));
mpu401_init(sb->mpu, 0, 0, M_UART, device_get_config_int("receive_input401"));
sb_dsp_set_mpu(&sb->dsp, sb->mpu);
if (device_get_config_int("receive_input"))
midi_in_handler(1, sb_dsp_input_msg, sb_dsp_input_sysex, &sb->dsp);
sb->gameport = gameport_add(&gameport_pnp_device);
const char *pnp_rom_file = NULL;
switch (info->local) {
case 0:
pnp_rom_file = "roms/sound/CT4170 PnP.BIN";
break;
case 1:
pnp_rom_file = "roms/sound/CT4180 PnP.BIN";
break;
default:
break;
}
uint8_t *pnp_rom = NULL;
if (pnp_rom_file) {
FILE *fp = rom_fopen(pnp_rom_file, "rb");
if (fp) {
if (fread(sb->pnp_rom, 1, 512, fp) == 512)
pnp_rom = sb->pnp_rom;
fclose(fp);
}
}
switch (info->local) {
case 0:
case 1:
isapnp_add_card(pnp_rom, sizeof(sb->pnp_rom), sb_vibra16_pnp_config_changed,
NULL, NULL, NULL, sb);
break;
default:
break;
}
sb_dsp_setaddr(&sb->dsp, 0);
sb_dsp_setirq(&sb->dsp, 0);
sb_dsp_setdma8(&sb->dsp, ISAPNP_DMA_DISABLED);
sb_dsp_setdma16(&sb->dsp, ISAPNP_DMA_DISABLED);
mpu401_change_addr(sb->mpu, 0);
sb->gameport_addr = 0;
gameport_remap(sb->gameport, 0);
return sb;
@@ -2069,6 +2312,9 @@ sb_16_compat_init(const device_t *info)
mpu401_init(sb->mpu, 0, 0, M_UART, info->local);
sb_dsp_set_mpu(&sb->dsp, sb->mpu);
sb->gameport = gameport_add(&gameport_pnp_device);
sb->gameport_addr = 0x200;
return sb;
}
@@ -2165,6 +2411,9 @@ sb_awe32_init(UNUSED(const device_t *info))
if (device_get_config_int("receive_input"))
midi_in_handler(1, sb_dsp_input_msg, sb_dsp_input_sysex, &sb->dsp);
sb->gameport = gameport_add(&gameport_pnp_device);
sb->gameport_addr = 0x200;
return sb;
}
@@ -2264,6 +2513,8 @@ sb_awe32_pnp_init(const device_t *info)
emu8k_change_addr(&sb->emu8k, 0);
sb->gameport_addr = 0;
gameport_remap(sb->gameport, 0);
return sb;
@@ -3599,7 +3850,7 @@ const device_t sb_16_device = {
.name = "Sound Blaster 16",
.internal_name = "sb16",
.flags = DEVICE_ISA | DEVICE_AT,
.local = 0,
.local = FM_YMF262,
.init = sb_16_init,
.close = sb_close,
.reset = NULL,
@@ -3609,6 +3860,76 @@ const device_t sb_16_device = {
.config = sb_16_config
};
const device_t sb_vibra16s_onboard_device = {
.name = "Sound Blaster Vibra 16S (On-Board)",
.internal_name = "sb_vibra16s_onboard",
.flags = DEVICE_ISA | DEVICE_AT,
.local = FM_YMF289B,
.init = sb_16_init,
.close = sb_close,
.reset = NULL,
{ .available = NULL },
.speed_changed = sb_speed_changed,
.force_redraw = NULL,
.config = sb_16_config
};
const device_t sb_vibra16s_device = {
.name = "Sound Blaster Vibra 16S",
.internal_name = "sb_vibra16s",
.flags = DEVICE_ISA | DEVICE_AT,
.local = FM_YMF289B,
.init = sb_16_init,
.close = sb_close,
.reset = NULL,
{ .available = NULL },
.speed_changed = sb_speed_changed,
.force_redraw = NULL,
.config = sb_16_config
};
const device_t sb_vibra16xv_device = {
.name = "Sound Blaster Vibra 16XV",
.internal_name = "sb_vibra16xv",
.flags = DEVICE_ISA | DEVICE_AT,
.local = 0,
.init = sb_vibra16_pnp_init,
.close = sb_close,
.reset = NULL,
{ .available = sb_vibra16xv_available },
.speed_changed = sb_speed_changed,
.force_redraw = NULL,
.config = sb_16_pnp_config
};
const device_t sb_vibra16c_onboard_device = {
.name = "Sound Blaster Vibra 16C (On-Board)",
.internal_name = "sb_vibra16c_onboard",
.flags = DEVICE_ISA | DEVICE_AT,
.local = 1,
.init = sb_vibra16_pnp_init,
.close = sb_close,
.reset = NULL,
{ .available = sb_vibra16c_available },
.speed_changed = sb_speed_changed,
.force_redraw = NULL,
.config = sb_16_pnp_config
};
const device_t sb_vibra16c_device = {
.name = "Sound Blaster Vibra 16C",
.internal_name = "sb_vibra16c",
.flags = DEVICE_ISA | DEVICE_AT,
.local = 1,
.init = sb_vibra16_pnp_init,
.close = sb_close,
.reset = NULL,
{ .available = sb_vibra16c_available },
.speed_changed = sb_speed_changed,
.force_redraw = NULL,
.config = sb_16_pnp_config
};
const device_t sb_16_reply_mca_device = {
.name = "Sound Blaster 16 Reply MCA",
.internal_name = "sb16_reply_mca",

View File

@@ -134,6 +134,9 @@ static const SOUND_CARD sound_cards[] = {
{ &sb_awe64_value_device },
{ &sb_awe64_device },
{ &sb_awe64_gold_device },
{ &sb_vibra16c_device },
{ &sb_vibra16s_device },
{ &sb_vibra16xv_device },
{ &ssi2001_device },
#if defined(DEV_BRANCH) && defined(USE_PAS16)
{ &pas16_device },
@@ -219,7 +222,7 @@ sound_card_get_from_internal_name(const char *s)
void
sound_card_init(void)
{
if (sound_cards[sound_card_current[0]].device)
if ((sound_card_current[0] != SOUND_INTERNAL) && (sound_cards[sound_card_current[0]].device))
device_add(sound_cards[sound_card_current[0]].device);
if (sound_cards[sound_card_current[1]].device)
device_add(sound_cards[sound_card_current[1]].device);
@@ -512,14 +515,14 @@ sound_reset(void)
filter_cd_audio_p = NULL;
sound_set_cd_volume(65535, 65535);
/* Reset the MPU-401 already loaded flag and the chain of input/output handlers. */
midi_in_handlers_clear();
}
void
sound_card_reset(void)
{
/* Reset the MPU-401 already loaded flag and the chain of input/output handlers. */
midi_in_handlers_clear();
sound_card_init();
if (mpu401_standalone_enable)

View File

@@ -1523,7 +1523,7 @@ void fm_engine_base<RegisterType>::engine_timer_expired(uint32_t tnum)
}
// Make sure the array does not go out of bounds to keep gcc happy
if(tnum < 2) {
if ((tnum < 2) || (sizeof(m_timer_running) > (2 * sizeof(uint8_t)))) {
// reset
m_timer_running[tnum] = false;
}