From f338bfa09291475660ff6f2b6ae5c8814ccb2d0c Mon Sep 17 00:00:00 2001 From: Olivier Galibert Date: Mon, 12 Mar 2018 19:14:23 +0100 Subject: [PATCH] nes_apu: Make it slightly less horrible [O. Galibert] --- src/devices/sound/nes_apu.cpp | 23 +++-------------------- src/devices/sound/nes_apu.h | 5 ----- src/mame/audio/dkong.cpp | 6 ------ src/mame/drivers/cham24.cpp | 3 --- src/mame/drivers/famibox.cpp | 3 --- src/mame/drivers/multigam.cpp | 3 --- src/mame/drivers/nes.cpp | 3 --- src/mame/drivers/nes_vt.cpp | 1 - src/mame/drivers/playch10.cpp | 3 --- src/mame/drivers/punchout.cpp | 3 --- src/mame/drivers/vsnes.cpp | 9 --------- 11 files changed, 3 insertions(+), 59 deletions(-) diff --git a/src/devices/sound/nes_apu.cpp b/src/devices/sound/nes_apu.cpp index d146cc515e1..69c0d9e8138 100644 --- a/src/devices/sound/nes_apu.cpp +++ b/src/devices/sound/nes_apu.cpp @@ -49,10 +49,6 @@ #include "emu.h" #include "nes_apu.h" -#include "screen.h" - - - /* INTERNAL FUNCTIONS */ /* INITIALIZE WAVE TIMES RELATIVE TO SAMPLE RATE */ @@ -107,12 +103,9 @@ DEFINE_DEVICE_TYPE(NES_APU, nesapu_device, "nesapu", "N2A03 APU") nesapu_device::nesapu_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, NES_APU, tag, owner, clock) , device_sound_interface(mconfig, *this) - , m_apu_incsize(0.0) , m_samps_per_sync(0) , m_buffer_size(0) - , m_real_rate(0) , m_stream(nullptr) - , m_screen(*this, finder_base::DUMMY_TAG) , m_irq_handler(*this) , m_mem_read_cb(*this) { @@ -146,18 +139,8 @@ void nesapu_device::calculate_rates() { int rate = clock() / 4; - if (m_screen) - { - m_samps_per_sync = rate / ATTOSECONDS_TO_HZ(m_screen->frame_period().attoseconds()); - m_real_rate = m_samps_per_sync * ATTOSECONDS_TO_HZ(m_screen->frame_period().attoseconds()); - } - else - { - m_samps_per_sync = rate / screen_device::DEFAULT_FRAME_RATE; - m_real_rate = m_samps_per_sync * screen_device::DEFAULT_FRAME_RATE; - } + m_samps_per_sync = 89490; // Is there a different PAL value? m_buffer_size = m_samps_per_sync; - m_apu_incsize = float(clock() / (float) m_real_rate); create_vbltimes(m_vbl_times,vbl_length,m_samps_per_sync); create_syncs(m_samps_per_sync); @@ -168,7 +151,7 @@ void nesapu_device::calculate_rates() if (m_stream != nullptr) m_stream->set_sample_rate(rate); else - m_stream = machine().sound().stream_alloc(*this, 0, 1, rate); + m_stream = machine().sound().stream_alloc(*this, 0, 1, clock()); } //------------------------------------------------- @@ -300,7 +283,7 @@ s8 nesapu_device::apu_square(apu_t::square_t *chan) || (chan->freq >> 16) < 4) return 0; - chan->phaseacc -= (float) m_apu_incsize; /* # of cycles per sample */ + chan->phaseacc --; while (chan->phaseacc < 0) { diff --git a/src/devices/sound/nes_apu.h b/src/devices/sound/nes_apu.h index 47f910effd2..67eb0ac4ff1 100644 --- a/src/devices/sound/nes_apu.h +++ b/src/devices/sound/nes_apu.h @@ -45,9 +45,6 @@ #define MCFG_NES_APU_MEM_READ_CALLBACK(_devcb) \ devcb = &downcast(*device).set_mem_read_callback(DEVCB_##_devcb); -#define MCFG_NES_APU_SCREEN_TAG(screen_tag) \ - downcast(*device).set_screen_tag(("^^" screen_tag)); - class nesapu_device : public device_t, public device_sound_interface { @@ -55,7 +52,6 @@ public: nesapu_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); // configuration helpers - void set_screen_tag(const char *tag) { m_screen.set_tag(tag); } template devcb_base &set_irq_handler(Object &&cb) { return m_irq_handler.set_callback(std::forward(cb)); } template devcb_base &set_mem_read_callback(Object &&cb) { return m_mem_read_cb.set_callback(std::forward(cb)); } @@ -87,7 +83,6 @@ private: u32 m_sync_times1[SYNCS_MAX1]; /* Samples per sync table */ u32 m_sync_times2[SYNCS_MAX2]; /* Samples per sync table */ sound_stream *m_stream; - optional_device m_screen; devcb_write_line m_irq_handler; devcb_read8 m_mem_read_cb; diff --git a/src/mame/audio/dkong.cpp b/src/mame/audio/dkong.cpp index a7eb4703ae8..b9caacf952b 100644 --- a/src/mame/audio/dkong.cpp +++ b/src/mame/audio/dkong.cpp @@ -1431,16 +1431,10 @@ MACHINE_CONFIG_START(dkong_state::dkong3_audio) MCFG_CPU_PROGRAM_MAP(dkong3_sound1_map) MCFG_CPU_VBLANK_INT_DRIVER("screen", dkong_state, nmi_line_pulse) - MCFG_DEVICE_MODIFY("n2a03a:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen") - MCFG_CPU_ADD("n2a03b", N2A03, NTSC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(dkong3_sound2_map) MCFG_CPU_VBLANK_INT_DRIVER("screen", dkong_state, nmi_line_pulse) - MCFG_DEVICE_MODIFY("n2a03b:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen") - /* sound latches */ MCFG_LATCH8_ADD( "latch1") MCFG_LATCH8_ADD( "latch2") diff --git a/src/mame/drivers/cham24.cpp b/src/mame/drivers/cham24.cpp index 9a4f1307d10..d04660392a1 100644 --- a/src/mame/drivers/cham24.cpp +++ b/src/mame/drivers/cham24.cpp @@ -316,9 +316,6 @@ MACHINE_CONFIG_START(cham24_state::cham24) MCFG_CPU_ADD("maincpu", N2A03, NTSC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(cham24_map) - MCFG_DEVICE_MODIFY("maincpu:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen") - /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) diff --git a/src/mame/drivers/famibox.cpp b/src/mame/drivers/famibox.cpp index d0760ca9fe9..22db44c74b7 100644 --- a/src/mame/drivers/famibox.cpp +++ b/src/mame/drivers/famibox.cpp @@ -551,9 +551,6 @@ MACHINE_CONFIG_START(famibox_state::famibox) MCFG_CPU_ADD("maincpu", N2A03, NTSC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(famibox_map) - MCFG_DEVICE_MODIFY("maincpu:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen") - /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) diff --git a/src/mame/drivers/multigam.cpp b/src/mame/drivers/multigam.cpp index 2a2c1a7ba73..fbb7f5cbaeb 100644 --- a/src/mame/drivers/multigam.cpp +++ b/src/mame/drivers/multigam.cpp @@ -1225,9 +1225,6 @@ MACHINE_CONFIG_START(multigam_state::multigam) MCFG_CPU_ADD("maincpu", N2A03, NTSC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(multigam_map) - MCFG_DEVICE_MODIFY("maincpu:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen") - /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) diff --git a/src/mame/drivers/nes.cpp b/src/mame/drivers/nes.cpp index 1c5fbbedde7..da2ba6a2be3 100644 --- a/src/mame/drivers/nes.cpp +++ b/src/mame/drivers/nes.cpp @@ -59,9 +59,6 @@ MACHINE_CONFIG_START(nes_state::nes) MCFG_CPU_ADD("maincpu", N2A03, NTSC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(nes_map) - MCFG_DEVICE_MODIFY("maincpu:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen") - MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60.0988) // This isn't used so much to calulate the vblank duration (the PPU code tracks that manually) but to determine diff --git a/src/mame/drivers/nes_vt.cpp b/src/mame/drivers/nes_vt.cpp index acc80cdfd5e..4e58a69da87 100644 --- a/src/mame/drivers/nes_vt.cpp +++ b/src/mame/drivers/nes_vt.cpp @@ -1402,7 +1402,6 @@ MACHINE_CONFIG_START(nes_vt_state::nes_vt) DMA control still comes from the 1st, but in the new mode, sound always outputs via the 2nd. Probably need to split the APU into interface and sound gen logic. */ MCFG_SOUND_ADD("apu", NES_APU, NTSC_APU_CLOCK) - MCFG_NES_APU_SCREEN_TAG("screen") MCFG_NES_APU_IRQ_HANDLER(WRITELINE(nes_vt_state, apu_irq)) MCFG_NES_APU_MEM_READ_CALLBACK(READ8(nes_vt_state, apu_read_mem)) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) diff --git a/src/mame/drivers/playch10.cpp b/src/mame/drivers/playch10.cpp index 3e19bcc6912..9938b0efbe0 100644 --- a/src/mame/drivers/playch10.cpp +++ b/src/mame/drivers/playch10.cpp @@ -649,9 +649,6 @@ MACHINE_CONFIG_START(playch10_state::playch10) MCFG_CPU_ADD("cart", N2A03, NTSC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(cart_map) - MCFG_DEVICE_MODIFY("cart:nesapu") - MCFG_NES_APU_SCREEN_TAG("bottom") - MCFG_DEVICE_ADD("outlatch1", LS259, 0) // 7D MCFG_ADDRESSABLE_LATCH_Q0_OUT_CB(WRITELINE(playch10_state, sdcs_w)) MCFG_ADDRESSABLE_LATCH_Q1_OUT_CB(WRITELINE(playch10_state, cntrl_mask_w)) diff --git a/src/mame/drivers/punchout.cpp b/src/mame/drivers/punchout.cpp index 7b96043f860..991a45aeb60 100644 --- a/src/mame/drivers/punchout.cpp +++ b/src/mame/drivers/punchout.cpp @@ -626,9 +626,6 @@ MACHINE_CONFIG_START(punchout_state::punchout) MCFG_CPU_PROGRAM_MAP(punchout_sound_map) MCFG_CPU_VBLANK_INT_DRIVER("top", punchout_state, nmi_line_pulse) - MCFG_DEVICE_MODIFY("audiocpu:nesapu") - MCFG_NES_APU_SCREEN_TAG("top") - MCFG_NVRAM_ADD_0FILL("nvram") MCFG_DEVICE_ADD("mainlatch", LS259, 0) // 2B diff --git a/src/mame/drivers/vsnes.cpp b/src/mame/drivers/vsnes.cpp index 78a7a0f4e1e..371cc6a761b 100644 --- a/src/mame/drivers/vsnes.cpp +++ b/src/mame/drivers/vsnes.cpp @@ -1705,9 +1705,6 @@ MACHINE_CONFIG_START(vsnes_state::vsnes) MCFG_MACHINE_RESET_OVERRIDE(vsnes_state,vsnes) MCFG_MACHINE_START_OVERRIDE(vsnes_state,vsnes) - MCFG_DEVICE_MODIFY("maincpu:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen1") - /* video hardware */ MCFG_SCREEN_ADD("screen1", RASTER) MCFG_SCREEN_REFRESH_RATE(60) @@ -1776,15 +1773,9 @@ MACHINE_CONFIG_START(vsnes_state::vsdual) MCFG_CPU_ADD("maincpu", N2A03, NTSC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(vsnes_cpu1_map) - MCFG_DEVICE_MODIFY("maincpu:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen1") - MCFG_CPU_ADD("sub", N2A03, NTSC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(vsnes_cpu2_map) - MCFG_DEVICE_MODIFY("sub:nesapu") - MCFG_NES_APU_SCREEN_TAG("screen2") - MCFG_MACHINE_RESET_OVERRIDE(vsnes_state,vsdual) MCFG_MACHINE_START_OVERRIDE(vsnes_state,vsdual)