From 17db38f44d54a47c6fe0843d1e285313cb585711 Mon Sep 17 00:00:00 2001 From: smf- Date: Tue, 25 Sep 2018 23:50:55 +0100 Subject: [PATCH] simplify clock_device (nw) --- src/devices/machine/clock.cpp | 49 ++++++++++------------------------- src/devices/machine/clock.h | 3 --- 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/src/devices/machine/clock.cpp b/src/devices/machine/clock.cpp index 927a0aecbf5..374dc8a16a8 100644 --- a/src/devices/machine/clock.cpp +++ b/src/devices/machine/clock.cpp @@ -22,48 +22,25 @@ void clock_device::device_start() void clock_device::device_clock_changed() { - update_timer(); -} + if (!m_signal_handler.isnull() && m_clock > 0) + { + if (m_timer == nullptr) + m_timer = timer_alloc(0); -attotime clock_device::period() -{ - if (m_clock > 0) - return attotime::from_hz(m_clock * 2); + const attotime period(attotime::from_hz(m_clock * 2)); - return attotime::never; + attotime next = period - m_timer->elapsed(); + if (next < attotime::zero) + next = attotime::zero; + + m_timer->adjust(next, 0, period); + } + else if (m_timer != nullptr) + m_timer->adjust(attotime::never); } void clock_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) { m_signal = !m_signal; m_signal_handler(m_signal); - - m_timer->adjust(period()); -} - -void clock_device::update_timer() -{ - if (!m_signal_handler.isnull() && m_clock > 0) - { - if (m_timer == nullptr) - { - m_timer = timer_alloc(0); - m_timer->adjust(period()); - } - else - { - attotime next = period() - m_timer->elapsed(); - - if (next < attotime::zero) - { - next = attotime::zero; - } - - m_timer->adjust(next); - } - } - else if (m_timer != nullptr) - { - m_timer->adjust(attotime::never); - } } diff --git a/src/devices/machine/clock.h b/src/devices/machine/clock.h index dbe6cd00bd9..32989a15149 100644 --- a/src/devices/machine/clock.h +++ b/src/devices/machine/clock.h @@ -26,9 +26,6 @@ protected: virtual void device_clock_changed() override; private: - void update_timer(); - attotime period(); - int m_signal; emu_timer *m_timer;