summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/timer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/timer.cpp')
-rw-r--r--src/devices/machine/timer.cpp92
1 files changed, 40 insertions, 52 deletions
diff --git a/src/devices/machine/timer.cpp b/src/devices/machine/timer.cpp
index 2461fb4da30..f2dc8464578 100644
--- a/src/devices/machine/timer.cpp
+++ b/src/devices/machine/timer.cpp
@@ -9,7 +9,7 @@
***************************************************************************/
#include "emu.h"
-#include "machine/timer.h"
+#include "timer.h"
/***************************************************************************
@@ -33,19 +33,18 @@ DEFINE_DEVICE_TYPE(TIMER, timer_device, "timer", "Timer")
// timer_device - constructor
//-------------------------------------------------
-timer_device::timer_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
- : device_t(mconfig, TIMER, tag, owner, clock),
- m_type(TIMER_TYPE_GENERIC),
- m_callback(*this),
- m_ptr(nullptr),
- m_start_delay(attotime::zero),
- m_period(attotime::zero),
- m_param(0),
- m_screen(*this, finder_base::DUMMY_TAG),
- m_first_vpos(0),
- m_increment(0),
- m_timer(nullptr),
- m_first_time(true)
+timer_device::timer_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
+ device_t(mconfig, TIMER, tag, owner, clock),
+ m_type(TIMER_TYPE_GENERIC),
+ m_callback(*this),
+ m_start_delay(attotime::zero),
+ m_period(attotime::zero),
+ m_param(0),
+ m_screen(*this, finder_base::DUMMY_TAG),
+ m_first_vpos(0),
+ m_increment(0),
+ m_timer(nullptr),
+ m_first_time(true)
{
}
@@ -103,8 +102,10 @@ void timer_device::device_validity_check(validity_checker &valid) const
void timer_device::device_start()
{
- // allocate the timer
- m_timer = timer_alloc();
+ if (m_type == TIMER_TYPE_SCANLINE)
+ m_timer = timer_alloc(FUNC(timer_device::scanline_tick), this);
+ else
+ m_timer = timer_alloc(FUNC(timer_device::generic_tick), this);
m_callback.resolve();
@@ -154,44 +155,31 @@ void timer_device::device_reset()
}
-//-------------------------------------------------
-// device_timer - handle timer expiration events
-//-------------------------------------------------
-
-void timer_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
+TIMER_CALLBACK_MEMBER(timer_device::generic_tick)
{
- switch (m_type)
- {
- // general periodic timers just call through
- case TIMER_TYPE_GENERIC:
- case TIMER_TYPE_PERIODIC:
- if (!m_callback.isnull())
- (m_callback)(*this, m_ptr, param);
- break;
-
- // scanline timers have to do some additional bookkeeping
- case TIMER_TYPE_SCANLINE:
- {
- // by default, we fire at the first position
- int next_vpos = m_first_vpos;
+ if (!m_callback.isnull())
+ (m_callback)(*this, param);
+}
- // the first time through we just go with the default position
- if (!m_first_time)
- {
- // call the real callback
- int vpos = m_screen->vpos();
- if (!m_callback.isnull())
- (m_callback)(*this, m_ptr, vpos);
-
- // advance by the increment only if we will still be within the screen bounds
- if (m_increment != 0 && (vpos + m_increment) < m_screen->height())
- next_vpos = vpos + m_increment;
- }
- m_first_time = false;
+TIMER_CALLBACK_MEMBER(timer_device::scanline_tick)
+{
+ // by default, we fire at the first position
+ int next_vpos = m_first_vpos;
- // adjust the timer
- m_timer->adjust(m_screen->time_until_pos(next_vpos));
- break;
- }
+ // the first time through we just go with the default position
+ if (!m_first_time)
+ {
+ // call the real callback
+ int vpos = m_screen->vpos();
+ if (!m_callback.isnull())
+ (m_callback)(*this, vpos);
+
+ // advance by the increment only if we will still be within the screen bounds
+ if (m_increment != 0 && (vpos + m_increment) < m_screen->height())
+ next_vpos = vpos + m_increment;
}
+ m_first_time = false;
+
+ // adjust the timer
+ m_timer->adjust(m_screen->time_until_pos(next_vpos));
}