nes_apu: Make it slightly less horrible [O. Galibert]

This commit is contained in:
Olivier Galibert 2018-03-12 19:14:23 +01:00
parent b9ac659837
commit f338bfa092
11 changed files with 3 additions and 59 deletions

View File

@ -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)
{

View File

@ -45,9 +45,6 @@
#define MCFG_NES_APU_MEM_READ_CALLBACK(_devcb) \
devcb = &downcast<nesapu_device &>(*device).set_mem_read_callback(DEVCB_##_devcb);
#define MCFG_NES_APU_SCREEN_TAG(screen_tag) \
downcast<nesapu_device &>(*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 <class Object> devcb_base &set_irq_handler(Object &&cb) { return m_irq_handler.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_mem_read_callback(Object &&cb) { return m_mem_read_cb.set_callback(std::forward<Object>(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<screen_device> m_screen;
devcb_write_line m_irq_handler;
devcb_read8 m_mem_read_cb;

View File

@ -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")

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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))

View File

@ -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

View File

@ -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)