diff options
author | AJR <ajrhacker@users.noreply.github.com> | 2018-05-25 17:41:00 -0400 |
---|---|---|
committer | AJR <ajrhacker@users.noreply.github.com> | 2018-05-25 17:43:38 -0400 |
commit | 52c93bdc1de797080d57f092315ec6b873ed4edb (patch) | |
tree | cc5e4a4fd355e1540ad82d178a5400f5c6a892cc /src/mame/machine | |
parent | 66153a3df51aa7bac8debb326891f19041ca7d9a (diff) |
sega_315_5250: Interrupt callback modernization (nw)
Diffstat (limited to 'src/mame/machine')
-rw-r--r-- | src/mame/machine/segaic16.cpp | 76 | ||||
-rw-r--r-- | src/mame/machine/segaic16.h | 29 |
2 files changed, 77 insertions, 28 deletions
diff --git a/src/mame/machine/segaic16.cpp b/src/mame/machine/segaic16.cpp index 1e6431cb0a3..b3690fd06cc 100644 --- a/src/mame/machine/segaic16.cpp +++ b/src/mame/machine/segaic16.cpp @@ -974,30 +974,50 @@ void sega_315_5249_divider_device::execute(int mode) sega_315_5250_compare_timer_device::sega_315_5250_compare_timer_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, SEGA_315_5250_COMPARE_TIMER, tag, owner, clock) - , m_sound_write(*this) + , m_68kint_callback(*this) + , m_zint_callback(*this) + , m_exck(false) { } //------------------------------------------------- -// clock - clock the timer +// exck_w - clock the timer //------------------------------------------------- -bool sega_315_5250_compare_timer_device::clock() +WRITE_LINE_MEMBER(sega_315_5250_compare_timer_device::exck_w) { + if (m_exck == bool(state)) + return; + + // update on rising edge + m_exck = bool(state); + if (!m_exck) + return; + // if we're enabled, clock the upcounter int old_counter = m_counter; if (m_regs[10] & 1) m_counter++; // regardless of the enable, a value of 0xfff will generate the IRQ - bool result = false; if (old_counter == 0xfff) { - result = true; + if (!m_68kint_callback.isnull()) + m_68kint_callback(ASSERT_LINE); m_counter = m_regs[8] & 0xfff; } - return result; +} + + +//------------------------------------------------- +// interrupt_ack - acknowledge timer interrupt +//------------------------------------------------- + +void sega_315_5250_compare_timer_device::interrupt_ack() +{ + if (!m_68kint_callback.isnull()) + m_68kint_callback(CLEAR_LINE); } @@ -1005,7 +1025,7 @@ bool sega_315_5250_compare_timer_device::clock() // read - read the registers //------------------------------------------------- -READ16_MEMBER( sega_315_5250_compare_timer_device::read ) +READ16_MEMBER(sega_315_5250_compare_timer_device::read) { if (LOG_COMPARE) logerror("compare_r(%X) = %04X\n", offset, m_regs[offset]); switch (offset & 15) @@ -1019,7 +1039,7 @@ READ16_MEMBER( sega_315_5250_compare_timer_device::read ) case 0x6: return m_regs[2]; case 0x7: return m_regs[7]; case 0x9: - case 0xd: interrupt_ack(); break; + case 0xd: if (!machine().side_effects_disabled()) interrupt_ack(); break; } return 0xffff; } @@ -1029,7 +1049,7 @@ READ16_MEMBER( sega_315_5250_compare_timer_device::read ) // write - write to the registers //------------------------------------------------- -WRITE16_MEMBER( sega_315_5250_compare_timer_device::write ) +WRITE16_MEMBER(sega_315_5250_compare_timer_device::write) { if (LOG_COMPARE) logerror("compare_w(%X) = %04X\n", offset, data); switch (offset & 15) @@ -1047,9 +1067,7 @@ WRITE16_MEMBER( sega_315_5250_compare_timer_device::write ) case 0xe: COMBINE_DATA(&m_regs[10]); break; case 0xb: case 0xf: - COMBINE_DATA(&m_regs[11]); - if (!m_sound_write.isnull()) - m_sound_write(m_regs[11]); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(sega_315_5250_compare_timer_device::write_to_sound), this), data & 0xff); break; } } @@ -1062,13 +1080,14 @@ WRITE16_MEMBER( sega_315_5250_compare_timer_device::write ) void sega_315_5250_compare_timer_device::device_start() { // bind our handlers - m_timer_ack.bind_relative_to(*owner()); - m_sound_write.resolve(); + m_68kint_callback.resolve(); + m_zint_callback.resolve(); // save states save_item(NAME(m_regs)); save_item(NAME(m_counter)); save_item(NAME(m_bit)); + save_item(NAME(m_exck)); } @@ -1081,6 +1100,35 @@ void sega_315_5250_compare_timer_device::device_reset() memset(m_regs, 0, sizeof(m_regs)); m_counter = 0; m_bit = 0; + + interrupt_ack(); + if (!m_zint_callback.isnull()) + m_zint_callback(CLEAR_LINE); +} + + +//------------------------------------------------- +// write_to_sound - write data for the sound CPU +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(sega_315_5250_compare_timer_device::write_to_sound) +{ + m_regs[11] = param; + if (!m_zint_callback.isnull()) + m_zint_callback(ASSERT_LINE); +} + + +//------------------------------------------------- +// zread - read data from sound CPU bus +//------------------------------------------------- + +READ8_MEMBER(sega_315_5250_compare_timer_device::zread) +{ + if (!m_zint_callback.isnull() && !machine().side_effects_disabled()) + m_zint_callback(CLEAR_LINE); + + return m_regs[11]; } diff --git a/src/mame/machine/segaic16.h b/src/mame/machine/segaic16.h index 9a6a5027045..90216fa1ef9 100644 --- a/src/mame/machine/segaic16.h +++ b/src/mame/machine/segaic16.h @@ -38,10 +38,10 @@ #define MCFG_SEGA_315_5250_COMPARE_TIMER_ADD(_tag) \ MCFG_DEVICE_ADD(_tag, SEGA_315_5250_COMPARE_TIMER, 0) -#define MCFG_SEGA_315_5250_TIMER_ACK(_class, _func) \ - downcast<sega_315_5250_compare_timer_device &>(*device).set_timer_ack(sega_315_5250_compare_timer_device::timer_ack_delegate(&_class::_func, #_class "::" #_func, nullptr, (_class *)nullptr)); -#define MCFG_SEGA_315_5250_SOUND_WRITE_CALLBACK(_devcb) \ - devcb = &downcast<sega_315_5250_compare_timer_device &>(*device).set_sound_write(DEVCB_##_devcb); +#define MCFG_SEGA_315_5250_68KINT_CALLBACK(_devcb) \ + devcb = &downcast<sega_315_5250_compare_timer_device &>(*device).set_68kint_callback(DEVCB_##_devcb); +#define MCFG_SEGA_315_5250_ZINT_CALLBACK(_devcb) \ + devcb = &downcast<sega_315_5250_compare_timer_device &>(*device).set_zint_callback(DEVCB_##_devcb); //************************************************************************** @@ -247,19 +247,18 @@ private: class sega_315_5250_compare_timer_device : public device_t { public: - typedef device_delegate<void ()> timer_ack_delegate; - // construction/destruction sega_315_5250_compare_timer_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); // configuration helpers - void set_timer_ack(timer_ack_delegate callback) { m_timer_ack = callback; } - template<class Object> devcb_base &set_sound_write(Object &&object) { return m_sound_write.set_callback(std::forward<Object>(object)); } + template<class Object> devcb_base &set_68kint_callback(Object &&object) { return m_68kint_callback.set_callback(std::forward<Object>(object)); } + template<class Object> devcb_base &set_zint_callback(Object &&object) { return m_zint_callback.set_callback(std::forward<Object>(object)); } // public interface - bool clock(); - DECLARE_READ16_MEMBER( read ); - DECLARE_WRITE16_MEMBER( write ); + DECLARE_WRITE_LINE_MEMBER(exck_w); + DECLARE_READ16_MEMBER(read); + DECLARE_WRITE16_MEMBER(write); + DECLARE_READ8_MEMBER(zread); protected: // device-level overrides @@ -269,16 +268,18 @@ protected: private: // internal helpers void execute(bool update_history = false); - void interrupt_ack() { if (!m_timer_ack.isnull()) m_timer_ack(); } + void interrupt_ack(); + TIMER_CALLBACK_MEMBER(write_to_sound); // configuration - timer_ack_delegate m_timer_ack; - devcb_write8 m_sound_write; + devcb_write_line m_68kint_callback; + devcb_write_line m_zint_callback; // internal state uint16_t m_regs[16]; uint16_t m_counter; uint8_t m_bit; + bool m_exck; }; |