diff options
-rw-r--r-- | src/devices/cpu/i8085/i8085.cpp | 15 | ||||
-rw-r--r-- | src/devices/cpu/i8085/i8085.h | 18 | ||||
-rw-r--r-- | src/emu/device.cpp | 53 | ||||
-rw-r--r-- | src/emu/device.h | 1 | ||||
-rw-r--r-- | src/emu/device.ipp | 6 | ||||
-rw-r--r-- | src/mame/drivers/equites.cpp | 3 | ||||
-rw-r--r-- | src/mame/drivers/nes.cpp | 12 |
7 files changed, 86 insertions, 22 deletions
diff --git a/src/devices/cpu/i8085/i8085.cpp b/src/devices/cpu/i8085/i8085.cpp index febb71e1a46..342bf445d5a 100644 --- a/src/devices/cpu/i8085/i8085.cpp +++ b/src/devices/cpu/i8085/i8085.cpp @@ -220,6 +220,21 @@ i8080a_cpu_device::i8080a_cpu_device(const machine_config &mconfig, const char * } +void i8085a_cpu_device::device_config_complete() +{ + m_clk_out_func.bind_relative_to(*owner()); + if (!m_clk_out_func.isnull()) + m_clk_out_func(clock() / 2); +} + + +void i8085a_cpu_device::device_clock_changed() +{ + if (!m_clk_out_func.isnull()) + m_clk_out_func(clock() / 2); +} + + void i8085a_cpu_device::set_sod(int state) { if (state != 0 && m_sod_state == 0) diff --git a/src/devices/cpu/i8085/i8085.h b/src/devices/cpu/i8085/i8085.h index 46f6e1eee0b..8f7822057b0 100644 --- a/src/devices/cpu/i8085/i8085.h +++ b/src/devices/cpu/i8085/i8085.h @@ -32,22 +32,28 @@ enum #define I8085_STATUS_MEMR 0x80 -/* STATUS changed callback */ +// STATUS changed callback #define MCFG_I8085A_STATUS(_devcb) \ devcb = &i8085a_cpu_device::set_out_status_func(*device, DEVCB_##_devcb); -/* INTE changed callback */ +// INTE changed callback #define MCFG_I8085A_INTE(_devcb) \ devcb = &i8085a_cpu_device::set_out_inte_func(*device, DEVCB_##_devcb); -/* SID changed callback (8085A only) */ +// SID changed callback (8085A only) #define MCFG_I8085A_SID(_devcb) \ devcb = &i8085a_cpu_device::set_in_sid_func(*device, DEVCB_##_devcb); -/* SOD changed callback (8085A only) */ +// SOD changed callback (8085A only) #define MCFG_I8085A_SOD(_devcb) \ devcb = &i8085a_cpu_device::set_out_sod_func(*device, DEVCB_##_devcb); +// CLK rate callback (8085A only) +#define MCFG_I8085A_CLK_OUT_DEVICE(_tag) \ + i8085a_cpu_device::static_set_clk_out(*device, clock_update_delegate(FUNC(device_t::set_unscaled_clock), _tag, (device_t *)nullptr)); +#define MCFG_I8085A_CLK_OUT_CUSTOM(_class, _func) \ + i8085a_cpu_device::static_set_clk_out(*device, clock_update_delegate(&_class::_func, #_class "::" _func, owner)); + class i8085a_cpu_device : public cpu_device { @@ -61,9 +67,12 @@ public: template<class _Object> static devcb_base &set_out_inte_func(device_t &device, _Object object) { return downcast<i8085a_cpu_device &>(device).m_out_inte_func.set_callback(object); } template<class _Object> static devcb_base &set_in_sid_func(device_t &device, _Object object) { return downcast<i8085a_cpu_device &>(device).m_in_sid_func.set_callback(object); } template<class _Object> static devcb_base &set_out_sod_func(device_t &device, _Object object) { return downcast<i8085a_cpu_device &>(device).m_out_sod_func.set_callback(object); } + static void static_set_clk_out(device_t &device, clock_update_delegate &&clk_out) { downcast<i8085a_cpu_device &>(device).m_clk_out_func = std::move(clk_out); } protected: // device-level overrides + virtual void device_config_complete() override; + virtual void device_clock_changed() override; virtual void device_start() override; virtual void device_reset() override; @@ -98,6 +107,7 @@ private: devcb_write_line m_out_inte_func; devcb_read_line m_in_sid_func; devcb_write_line m_out_sod_func; + clock_update_delegate m_clk_out_func; int m_cputype; /* 0 8080, 1 8085A */ PAIR m_PC,m_SP,m_AF,m_BC,m_DE,m_HL,m_WZ; diff --git a/src/emu/device.cpp b/src/emu/device.cpp index 6a137e475a8..60772fd2369 100644 --- a/src/emu/device.cpp +++ b/src/emu/device.cpp @@ -217,15 +217,13 @@ std::string device_t::parameter(const char *tag) const void device_t::static_set_clock(device_t &device, u32 clock) { + device.m_configured_clock = clock; + // derive the clock from our owner if requested if ((clock & 0xff000000) == 0xff000000) - { - assert(device.m_owner != nullptr); - clock = device.m_owner->m_configured_clock * ((clock >> 12) & 0xfff) / ((clock >> 0) & 0xfff); - } - - device.m_clock = device.m_unscaled_clock = device.m_configured_clock = clock; - device.m_attoseconds_per_clock = (clock == 0) ? 0 : HZ_TO_ATTOSECONDS(clock); + device.calculate_derived_clock(); + else + device.set_unscaled_clock(clock); } @@ -297,10 +295,21 @@ void device_t::reset() void device_t::set_unscaled_clock(u32 clock) { + // do nothing if no actual change + if (clock == m_unscaled_clock) + return; + m_unscaled_clock = clock; m_clock = m_unscaled_clock * m_clock_scale; m_attoseconds_per_clock = (m_clock == 0) ? 0 : HZ_TO_ATTOSECONDS(m_clock); - notify_clock_changed(); + + // recalculate all derived clocks + for (device_t &child : subdevices()) + child.calculate_derived_clock(); + + // if the device has already started, make sure it knows about the new clock + if (m_started) + notify_clock_changed(); } @@ -311,10 +320,36 @@ void device_t::set_unscaled_clock(u32 clock) void device_t::set_clock_scale(double clockscale) { + // do nothing if no actual change + if (clockscale == m_clock_scale) + return; + m_clock_scale = clockscale; m_clock = m_unscaled_clock * m_clock_scale; m_attoseconds_per_clock = (m_clock == 0) ? 0 : HZ_TO_ATTOSECONDS(m_clock); - notify_clock_changed(); + + // recalculate all derived clocks + for (device_t &child : subdevices()) + child.calculate_derived_clock(); + + // if the device has already started, make sure it knows about the new clock + if (m_started) + notify_clock_changed(); +} + + +//------------------------------------------------- +// calculate_derived_clock - derive the device's +// clock from its owner, if so configured +//------------------------------------------------- + +void device_t::calculate_derived_clock() +{ + if ((m_configured_clock & 0xff000000) == 0xff000000) + { + assert(m_owner != nullptr); + set_unscaled_clock(m_owner->m_clock * ((m_configured_clock >> 12) & 0xfff) / ((m_configured_clock >> 0) & 0xfff)); + } } diff --git a/src/emu/device.h b/src/emu/device.h index 6e351f77ca6..b20a545dc46 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -517,6 +517,7 @@ protected: private: // internal helpers device_t *subdevice_slow(const char *tag) const; + void calculate_derived_clock(); // private state; accessor use required running_machine * m_machine; diff --git a/src/emu/device.ipp b/src/emu/device.ipp index 74d7eb45f2c..c5c97568313 100644 --- a/src/emu/device.ipp +++ b/src/emu/device.ipp @@ -18,6 +18,12 @@ #define __DEVICE_IPP__ //************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +typedef device_delegate<void (u32)> clock_update_delegate; + +//************************************************************************** // MEMBER TEMPLATES //************************************************************************** diff --git a/src/mame/drivers/equites.cpp b/src/mame/drivers/equites.cpp index 2fd26137390..c3a010481ed 100644 --- a/src/mame/drivers/equites.cpp +++ b/src/mame/drivers/equites.cpp @@ -1039,8 +1039,9 @@ static MACHINE_CONFIG_FRAGMENT( common_sound ) MCFG_CPU_ADD("audiocpu", I8085A, XTAL_6_144MHz) /* verified on pcb */ MCFG_CPU_PROGRAM_MAP(sound_map) MCFG_CPU_IO_MAP(sound_portmap) + MCFG_I8085A_CLK_OUT_DEVICE("audio8155") - MCFG_DEVICE_ADD("audio8155", I8155, XTAL_6_144MHz/2) + MCFG_DEVICE_ADD("audio8155", I8155, 0) MCFG_I8155_OUT_PORTA_CB(WRITE8(equites_state, equites_8155_porta_w)) MCFG_I8155_OUT_PORTB_CB(WRITE8(equites_state, equites_8155_portb_w)) MCFG_I8155_OUT_PORTC_CB(WRITE8(equites_state, equites_8155_portc_w)) diff --git a/src/mame/drivers/nes.cpp b/src/mame/drivers/nes.cpp index faa9b12732f..3c5989f5f8e 100644 --- a/src/mame/drivers/nes.cpp +++ b/src/mame/drivers/nes.cpp @@ -98,10 +98,8 @@ MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( nespal, nes ) /* basic machine hardware */ -// MCFG_CPU_MODIFY("maincpu") -// MCFG_CPU_CLOCK(PAL_APU_CLOCK) // this doesn't get inherited by the APU with DERIVED_CLOCK! - - MCFG_CPU_REPLACE("maincpu", N2A03, PAL_APU_CLOCK) + MCFG_CPU_MODIFY("maincpu") + MCFG_CPU_CLOCK(PAL_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(nes_map) MCFG_DEVICE_REMOVE("ppu") @@ -130,10 +128,8 @@ static MACHINE_CONFIG_DERIVED( famicom, nes ) MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( nespalc, nespal ) -// MCFG_CPU_MODIFY( "maincpu" ) -// MCFG_CPU_CLOCK(PALC_APU_CLOCK) // this doesn't get inherited by the APU with DERIVED_CLOCK! - - MCFG_CPU_REPLACE("maincpu", N2A03, PALC_APU_CLOCK) + MCFG_CPU_MODIFY( "maincpu" ) + MCFG_CPU_CLOCK(PALC_APU_CLOCK) MCFG_CPU_PROGRAM_MAP(nes_map) /* UMC 6538 and friends -- extends time for rendering dummy scanlines */ |