summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/timer.c
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2010-08-26 15:21:19 +0000
committer Aaron Giles <aaron@aarongiles.com>2010-08-26 15:21:19 +0000
commit47dd9fe5680add9e438e75d71ce476b082382fdf (patch)
tree55f9ab6e9fe1351cbff6992924197ed9a6a33e26 /src/emu/timer.c
parent33e4664bb21d437c5b8fee3c470b00084d0d9d8a (diff)
De-converted MACHINE_DRIVER from tokens back to constructor functions, regaining
type safety. If legacy devices still use inline data, those types are not checked. However, new devices no longer have access to the generic m_inline_data. Instead their MDRV_* macros should map to calls to static functions in the device config class which downcast a generic device_config to the specific device config, and then set the appropriate values. This is not to be done inline in order to prevent further code bloat in the constructors. See eeprom/7474/i2cmem/okim6295 for examples. #ifdef'ed several unused machine driver definitions that weren't referenced.
Diffstat (limited to 'src/emu/timer.c')
-rw-r--r--src/emu/timer.c118
1 files changed, 94 insertions, 24 deletions
diff --git a/src/emu/timer.c b/src/emu/timer.c
index c6b35eb7370..709351a83c1 100644
--- a/src/emu/timer.c
+++ b/src/emu/timer.c
@@ -943,8 +943,8 @@ timer_device_config::timer_device_config(const machine_config &mconfig, const ch
m_type(TIMER_TYPE_GENERIC),
m_callback(NULL),
m_ptr(NULL),
- m_start_delay(0),
- m_period(0),
+ m_start_delay(attotime_zero),
+ m_period(attotime_zero),
m_param(0),
m_screen(NULL),
m_first_vpos(0),
@@ -975,23 +975,93 @@ device_t *timer_device_config::alloc_device(running_machine &machine) const
//-------------------------------------------------
-// device_config_complete - perform any
-// operations now that the configuration is
-// complete
+// static_configure_generic - configuration
+// helper to set up a generic timer
//-------------------------------------------------
-void timer_device_config::device_config_complete()
+void timer_device_config::static_configure_generic(device_config *device, timer_device_fired_func callback)
{
- // move inline data into its final home
- m_type = static_cast<timer_type>(m_inline_data[INLINE_TYPE]);
- m_callback = reinterpret_cast<timer_device_fired_func>(m_inline_data[INLINE_CALLBACK]);
- m_ptr = reinterpret_cast<void *>(m_inline_data[INLINE_PTR]);
- m_start_delay = static_cast<UINT64>(m_inline_data[INLINE_DELAY]);
- m_period = static_cast<UINT64>(m_inline_data[INLINE_PERIOD]);
- m_param = static_cast<UINT32>(m_inline_data[INLINE_PARAM]);
- m_screen = reinterpret_cast<const char *>(m_inline_data[INLINE_SCREEN]);
- m_first_vpos = static_cast<INT16>(m_inline_data[INLINE_FIRST_VPOS]);
- m_increment = static_cast<INT16>(m_inline_data[INLINE_INCREMENT]);
+ timer_device_config *timer = downcast<timer_device_config *>(device);
+ timer->m_type = TIMER_TYPE_GENERIC;
+ timer->m_callback = callback;
+}
+
+
+//-------------------------------------------------
+// static_configure_periodic - configuration
+// helper to set up a periodic timer
+//-------------------------------------------------
+
+void timer_device_config::static_configure_periodic(device_config *device, timer_device_fired_func callback, attotime period)
+{
+ timer_device_config *timer = downcast<timer_device_config *>(device);
+ timer->m_type = TIMER_TYPE_PERIODIC;
+ timer->m_callback = callback;
+ timer->m_period = period;
+}
+
+
+//-------------------------------------------------
+// static_configure_scanline - configuration
+// helper to set up a scanline timer
+//-------------------------------------------------
+
+void timer_device_config::static_configure_scanline(device_config *device, timer_device_fired_func callback, const char *screen, int first_vpos, int increment)
+{
+ timer_device_config *timer = downcast<timer_device_config *>(device);
+ timer->m_type = TIMER_TYPE_SCANLINE;
+ timer->m_callback = callback;
+ timer->m_screen = screen;
+ timer->m_first_vpos = first_vpos;
+ timer->m_increment = increment;
+}
+
+
+//-------------------------------------------------
+// static_set_callback - configuration helper
+// to set the callback
+//-------------------------------------------------
+
+void timer_device_config::static_set_callback(device_config *device, timer_device_fired_func callback)
+{
+ timer_device_config *timer = downcast<timer_device_config *>(device);
+ timer->m_callback = callback;
+}
+
+
+//-------------------------------------------------
+// static_set_start_delay - configuration helper
+// to set the starting delay
+//-------------------------------------------------
+
+void timer_device_config::static_set_start_delay(device_config *device, attotime delay)
+{
+ timer_device_config *timer = downcast<timer_device_config *>(device);
+ timer->m_start_delay = delay;
+}
+
+
+//-------------------------------------------------
+// static_set_param - configuration helper to set
+// the integer parameter
+//-------------------------------------------------
+
+void timer_device_config::static_set_param(device_config *device, int param)
+{
+ timer_device_config *timer = downcast<timer_device_config *>(device);
+ timer->m_param = param;
+}
+
+
+//-------------------------------------------------
+// static_set_ptr - configuration helper to set
+// the pointer parameter
+//-------------------------------------------------
+
+void timer_device_config::static_set_ptr(device_config *device, void *ptr)
+{
+ timer_device_config *timer = downcast<timer_device_config *>(device);
+ timer->m_ptr = ptr;
}
@@ -1008,16 +1078,16 @@ bool timer_device_config::device_validity_check(const game_driver &driver) const
switch (m_type)
{
case TIMER_TYPE_GENERIC:
- if (m_screen != NULL || m_first_vpos != 0 || m_start_delay != 0)
+ if (m_screen != NULL || m_first_vpos != 0 || attotime_compare(m_start_delay, attotime_zero) != 0)
mame_printf_warning("%s: %s generic timer '%s' specified parameters for a scanline timer\n", driver.source_file, driver.name, tag());
- if (m_period != 0 || m_start_delay != 0)
+ if (attotime_compare(m_period, attotime_zero) != 0 || attotime_compare(m_start_delay, attotime_zero) != 0)
mame_printf_warning("%s: %s generic timer '%s' specified parameters for a periodic timer\n", driver.source_file, driver.name, tag());
break;
case TIMER_TYPE_PERIODIC:
if (m_screen != NULL || m_first_vpos != 0)
mame_printf_warning("%s: %s periodic timer '%s' specified parameters for a scanline timer\n", driver.source_file, driver.name, tag());
- if (m_period <= 0)
+ if (attotime_compare(m_period, attotime_zero) <= 0)
{
mame_printf_error("%s: %s periodic timer '%s' specified invalid period\n", driver.source_file, driver.name, tag());
error = true;
@@ -1025,7 +1095,7 @@ bool timer_device_config::device_validity_check(const game_driver &driver) const
break;
case TIMER_TYPE_SCANLINE:
- if (m_period != 0 || m_start_delay != 0)
+ if (attotime_compare(m_period, attotime_zero) != 0 || attotime_compare(m_start_delay, attotime_zero) != 0)
mame_printf_warning("%s: %s scanline timer '%s' specified parameters for a periodic timer\n", driver.source_file, driver.name, tag());
if (m_param != 0)
mame_printf_warning("%s: %s scanline timer '%s' specified parameter which is ignored\n", driver.source_file, driver.name, tag());
@@ -1104,14 +1174,14 @@ void timer_device::device_reset()
{
// convert the period into attotime
attotime period = attotime_never;
- if (m_config.m_period > 0)
+ if (attotime_compare(m_config.m_period, attotime_zero) > 0)
{
- period = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_period);
+ period = m_config.m_period;
// convert the start_delay into attotime
attotime start_delay = attotime_zero;
- if (m_config.m_start_delay > 0)
- start_delay = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_start_delay);
+ if (attotime_compare(m_config.m_start_delay, attotime_zero) > 0)
+ start_delay = m_config.m_start_delay;
// allocate and start the backing timer
timer_adjust_periodic(m_timer, start_delay, m_config.m_param, period);