From 0b4d175aa8bec084cda21cc7075cde3a0a704fd0 Mon Sep 17 00:00:00 2001 From: "therealmogminer@gmail.com" Date: Fri, 19 Aug 2016 13:22:45 +0200 Subject: [PATCH] -vgmplay.cpp: Added YM3812 support. [Ryan Holtz] --- src/devices/sound/3526intf.cpp | 6 ++++-- src/devices/sound/3812intf.cpp | 22 +++++++++++++++++++--- src/devices/sound/3812intf.h | 3 +++ src/devices/sound/fmopl.cpp | 9 +++++++-- src/devices/sound/fmopl.h | 3 ++- src/mame/drivers/vgmplay.cpp | 33 ++++++++++++++++++++++++--------- 6 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/devices/sound/3526intf.cpp b/src/devices/sound/3526intf.cpp index b91c8e76498..4cc55081492 100644 --- a/src/devices/sound/3526intf.cpp +++ b/src/devices/sound/3526intf.cpp @@ -98,15 +98,17 @@ void ym3526_device::sound_stream_update(sound_stream &stream, stream_sample_t ** void ym3526_device::device_start() { - int rate = clock()/72; + int rate = clock() / 72; // resolve callbacks m_irq_handler.resolve(); /* stream system initialize */ - m_chip = ym3526_init(this,clock(),rate); + m_chip = ym3526_init(this, clock(), rate); assert_always(m_chip != nullptr, "Error creating YM3526 chip"); + calculate_rates(); + /* YM3526 setup */ ym3526_set_timer_handler (m_chip, timer_handler, this); ym3526_set_irq_handler (m_chip, IRQHandler, this); diff --git a/src/devices/sound/3812intf.cpp b/src/devices/sound/3812intf.cpp index 192d5bba6c8..5650668f659 100644 --- a/src/devices/sound/3812intf.cpp +++ b/src/devices/sound/3812intf.cpp @@ -96,15 +96,15 @@ void ym3812_device::sound_stream_update(sound_stream &stream, stream_sample_t ** void ym3812_device::device_start() { - int rate = clock()/72; + int rate = clock() / 72; m_irq_handler.resolve(); /* stream system initialize */ - m_chip = ym3812_init(this,clock(),rate); + m_chip = ym3812_init(this, clock(), rate); assert_always(m_chip != nullptr, "Error creating YM3812 chip"); - m_stream = machine().sound().stream_alloc(*this,0,1,rate); + calculate_rates(); /* YM3812 setup */ ym3812_set_timer_handler (m_chip, timer_handler, this); @@ -115,6 +115,22 @@ void ym3812_device::device_start() m_timer[1] = timer_alloc(1); } +void ym3812_device::device_clock_changed() +{ + calculate_rates(); + ym3812_clock_changed(m_chip, clock(), clock() / 72); +} + +void ym3812_device::calculate_rates() +{ + int rate = clock() / 72; + + if (m_stream != nullptr) + m_stream->set_sample_rate(rate); + else + m_stream = machine().sound().stream_alloc(*this, 0, 1, rate); +} + //------------------------------------------------- // device_stop - device-specific stop //------------------------------------------------- diff --git a/src/devices/sound/3812intf.h b/src/devices/sound/3812intf.h index a62c88302ab..5f0c1e47f00 100644 --- a/src/devices/sound/3812intf.h +++ b/src/devices/sound/3812intf.h @@ -37,6 +37,7 @@ protected: virtual void device_start() override; virtual void device_stop() override; virtual void device_reset() override; + virtual void device_clock_changed() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; @@ -44,6 +45,8 @@ protected: virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) override; private: + void calculate_rates(); + sound_stream * m_stream; emu_timer * m_timer[2]; void * m_chip; diff --git a/src/devices/sound/fmopl.cpp b/src/devices/sound/fmopl.cpp index de8182bd171..3a9bcebdd70 100644 --- a/src/devices/sound/fmopl.cpp +++ b/src/devices/sound/fmopl.cpp @@ -2158,6 +2158,11 @@ static int OPLTimerOver(FM_OPL *OPL,int c) #if (BUILD_YM3812) +void ym3812_clock_changed(void *chip, UINT32 clock, UINT32 rate) +{ + OPL_clock_changed((FM_OPL *)chip, clock, rate); +} + void * ym3812_init(device_t *device, UINT32 clock, UINT32 rate) { /* emulator create */ @@ -2286,9 +2291,9 @@ void ym3812_update_one(void *chip, OPLSAMPLE *buffer, int length) #if (BUILD_YM3526) -void ym3526_clock_changed(void *opl, UINT32 clock, UINT32 rate) +void ym3526_clock_changed(void *chip, UINT32 clock, UINT32 rate) { - OPL_clock_changed((FM_OPL *)opl, clock, rate); + OPL_clock_changed((FM_OPL *)chip, clock, rate); } void *ym3526_init(device_t *device, UINT32 clock, UINT32 rate) diff --git a/src/devices/sound/fmopl.h b/src/devices/sound/fmopl.h index 51becf4e370..55d8b49c6e9 100644 --- a/src/devices/sound/fmopl.h +++ b/src/devices/sound/fmopl.h @@ -44,6 +44,7 @@ typedef unsigned char (*OPL_PORTHANDLER_R)(void *param); #if BUILD_YM3812 void *ym3812_init(device_t *device, UINT32 clock, UINT32 rate); +void ym3812_clock_changed(void *chip, UINT32 clock, UINT32 rate); void ym3812_shutdown(void *chip); void ym3812_reset_chip(void *chip); int ym3812_write(void *chip, int a, int v); @@ -68,7 +69,7 @@ void ym3812_set_update_handler(void *chip, OPL_UPDATEHANDLER UpdateHandler, void ** 'rate' is sampling rate */ void *ym3526_init(device_t *device, UINT32 clock, UINT32 rate); -void ym3526_clock_changed(void *opl, UINT32 clock, UINT32 rate); +void ym3526_clock_changed(void *chip, UINT32 clock, UINT32 rate); /* shutdown the YM3526 emulators*/ void ym3526_shutdown(void *chip); void ym3526_reset_chip(void *chip); diff --git a/src/mame/drivers/vgmplay.cpp b/src/mame/drivers/vgmplay.cpp index ce57b9d36ad..3416cabdec3 100644 --- a/src/mame/drivers/vgmplay.cpp +++ b/src/mame/drivers/vgmplay.cpp @@ -17,6 +17,7 @@ #include "sound/ym2413.h" #include "sound/2203intf.h" #include "sound/3526intf.h" +#include "sound/3812intf.h" #include "sound/ay8910.h" #include "sound/c6280.h" #include "sound/sn76496.h" @@ -37,11 +38,12 @@ public: A_YM2203A = 0x00000040, A_YM2203B = 0x00000050, A_YM3526 = 0x00000060, - A_AY8910A = 0x00000070, - A_AY8910B = 0x00000080, - A_SN76496 = 0x00000090, - A_K053260 = 0x000000a0, - A_C6280 = 0x000000d0, + A_YM3812 = 0x00000070, + A_AY8910A = 0x00000080, + A_AY8910B = 0x00000090, + A_SN76496 = 0x000000a0, + A_K053260 = 0x000000b0, + A_C6280 = 0x000000e0, A_SEGAPCM = 0x00001000, A_GAMEBOY = 0x00002000, A_NESAPU = 0x00002030, @@ -133,6 +135,7 @@ private: required_device m_ym2203a; required_device m_ym2203b; required_device m_ym3526; + required_device m_ym3812; required_device m_ay8910a; required_device m_ay8910b; required_device m_sn76496; @@ -315,6 +318,12 @@ void vgmplay_device::execute_run() m_pc += 3; break; + case 0x5a: + m_io->write_byte(A_YM3812+0, m_file->read_byte(m_pc+1)); + m_io->write_byte(A_YM3812+1, m_file->read_byte(m_pc+2)); + m_pc += 3; + break; + case 0x5b: m_io->write_byte(A_YM3526+0, m_file->read_byte(m_pc+1)); m_io->write_byte(A_YM3526+1, m_file->read_byte(m_pc+2)); @@ -832,6 +841,7 @@ vgmplay_state::vgmplay_state(const machine_config &mconfig, device_type type, co , m_ym2203a(*this, "ym2203a") , m_ym2203b(*this, "ym2203b") , m_ym3526(*this, "ym3526") + , m_ym3812(*this, "ym3812") , m_ay8910a(*this, "ay8910a") , m_ay8910b(*this, "ay8910b") , m_sn76496(*this, "sn76496") @@ -941,8 +951,9 @@ void vgmplay_state::machine_start() logerror("Warning: file requests an unsupported YM2608\n"); if(version >= 0x151 && r32(0x4c)) logerror("Warning: file requests an unsupported %s\n", r32(0x4c) & 0x80000000 ? "YM2610B" : "YM2610"); - if(version >= 0x151 && r32(0x50)) - logerror("Warning: file requests an unsupported YM3812\n"); + if(version >= 0x151 && r32(0x50)) { + m_ym3812->set_unscaled_clock(r32(0x50)); + } if(version >= 0x151 && r32(0x54)) { m_ym3526->set_unscaled_clock(r32(0x54)); } @@ -1080,6 +1091,7 @@ static ADDRESS_MAP_START( soundchips_map, AS_IO, 8, vgmplay_state ) AM_RANGE(vgmplay_device::A_YM2203A, vgmplay_device::A_YM2203A+1) AM_DEVWRITE ("ym2203a", ym2203_device, write) AM_RANGE(vgmplay_device::A_YM2203B, vgmplay_device::A_YM2203B+1) AM_DEVWRITE ("ym2203b", ym2203_device, write) AM_RANGE(vgmplay_device::A_YM3526, vgmplay_device::A_YM3526+1) AM_DEVWRITE ("ym3526", ym3526_device, write) + AM_RANGE(vgmplay_device::A_YM3812, vgmplay_device::A_YM3812+1) AM_DEVWRITE ("ym3812", ym3812_device, write) AM_RANGE(vgmplay_device::A_AY8910A, vgmplay_device::A_AY8910A) AM_DEVWRITE ("ay8910a", ay8910_device, data_w) AM_RANGE(vgmplay_device::A_AY8910A+1, vgmplay_device::A_AY8910A+1) AM_DEVWRITE ("ay8910a", ay8910_device, address_w) AM_RANGE(vgmplay_device::A_AY8910B, vgmplay_device::A_AY8910B) AM_DEVWRITE ("ay8910b", ay8910_device, data_w) @@ -1194,8 +1206,11 @@ static MACHINE_CONFIG_START( vgmplay, vgmplay_state ) MCFG_SOUND_ROUTE(3, "mono", 0.25) MCFG_SOUND_ADD("ym3526", YM3526, 4000000) - MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1) - MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1) + MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.5) + MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.5) + + MCFG_SOUND_ADD("ym3812", YM3812, 4000000) + MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) MCFG_CPU_ADD("nescpu", N2A03, 1000000) MCFG_CPU_PROGRAM_MAP(nescpu_map)