summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/clock.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2015-11-08 12:56:12 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2015-11-08 12:56:12 +0100
commit7c19aac60e12d6f5ea301bdb34d7826a01e0b06f (patch)
treef310d86aa2c6bfc19d115307dedde4eb0cd52dad /src/devices/machine/clock.cpp
parenta57b46ae933badd7441ce1644711dbb851e2b504 (diff)
Rename *.c -> *.cpp in our source (nw)
Diffstat (limited to 'src/devices/machine/clock.cpp')
-rw-r--r--src/devices/machine/clock.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/devices/machine/clock.cpp b/src/devices/machine/clock.cpp
new file mode 100644
index 00000000000..9896bebabcc
--- /dev/null
+++ b/src/devices/machine/clock.cpp
@@ -0,0 +1,68 @@
+// license:BSD-3-Clause
+// copyright-holders:smf
+#include "clock.h"
+
+const device_type CLOCK = &device_creator<clock_device>;
+
+clock_device::clock_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
+ : device_t(mconfig, CLOCK, "Clock", tag, owner, clock, "clock", __FILE__),
+ m_signal(0),
+ m_timer(NULL),
+ m_signal_handler(*this)
+{
+}
+
+void clock_device::device_start()
+{
+ m_signal_handler.resolve();
+
+ save_item(NAME(m_signal));
+}
+
+void clock_device::device_clock_changed()
+{
+ update_timer();
+}
+
+attotime clock_device::period()
+{
+ if (m_clock > 0)
+ return attotime::from_hz(m_clock * 2);
+
+ return 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 == NULL)
+ {
+ 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 != NULL)
+ {
+ m_timer->adjust(attotime::never);
+ }
+}