diff options
Diffstat (limited to 'src/emu/timer.c')
-rw-r--r-- | src/emu/timer.c | 175 |
1 files changed, 64 insertions, 111 deletions
diff --git a/src/emu/timer.c b/src/emu/timer.c index a2b0c781ebd..28ed940c93b 100644 --- a/src/emu/timer.c +++ b/src/emu/timer.c @@ -51,56 +51,32 @@ -/*************************************************************************** -// DEVICE DEFINITIONS -***************************************************************************/ - -const device_type TIMER = timer_device_config::static_alloc_device_config; - - - //************************************************************************** -// TIMER DEVICE CONFIGURATION +// LIVE TIMER DEVICE //************************************************************************** +const device_type TIMER = &device_creator<timer_device>; + //------------------------------------------------- -// timer_device_config - constructor +// timer_device - constructor //------------------------------------------------- -timer_device_config::timer_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) - : device_config(mconfig, static_alloc_device_config, "Timer", tag, owner, clock), +timer_device::timer_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, TIMER, "Timer", tag, owner, clock), m_type(TIMER_TYPE_GENERIC), m_callback(NULL), m_ptr(NULL), m_start_delay(attotime::zero), m_period(attotime::zero), m_param(0), + m_screen_tag(NULL), m_screen(NULL), m_first_vpos(0), - m_increment(0) -{ -} - - -//------------------------------------------------- -// static_alloc_device_config - allocate a new -// configuration object -//------------------------------------------------- - -device_config *timer_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) -{ - return global_alloc(timer_device_config(mconfig, tag, owner, clock)); -} - - -//------------------------------------------------- -// alloc_device - allocate a new device object -//------------------------------------------------- - -device_t *timer_device_config::alloc_device(running_machine &machine) const + m_increment(0), + m_timer(NULL), + m_first_time(true) { - return auto_alloc(machine, timer_device(machine, *this)); } @@ -109,11 +85,11 @@ device_t *timer_device_config::alloc_device(running_machine &machine) const // helper to set up a generic timer //------------------------------------------------- -void timer_device_config::static_configure_generic(device_config *device, timer_device_fired_func callback) +void timer_device::static_configure_generic(device_t &device, timer_device_fired_func callback) { - timer_device_config *timer = downcast<timer_device_config *>(device); - timer->m_type = TIMER_TYPE_GENERIC; - timer->m_callback = callback; + timer_device &timer = downcast<timer_device &>(device); + timer.m_type = TIMER_TYPE_GENERIC; + timer.m_callback = callback; } @@ -122,12 +98,12 @@ void timer_device_config::static_configure_generic(device_config *device, timer_ // helper to set up a periodic timer //------------------------------------------------- -void timer_device_config::static_configure_periodic(device_config *device, timer_device_fired_func callback, attotime period) +void timer_device::static_configure_periodic(device_t &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; + timer_device &timer = downcast<timer_device &>(device); + timer.m_type = TIMER_TYPE_PERIODIC; + timer.m_callback = callback; + timer.m_period = period; } @@ -136,14 +112,14 @@ void timer_device_config::static_configure_periodic(device_config *device, timer // 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) +void timer_device::static_configure_scanline(device_t &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; + timer_device &timer = downcast<timer_device &>(device); + timer.m_type = TIMER_TYPE_SCANLINE; + timer.m_callback = callback; + timer.m_screen_tag = screen; + timer.m_first_vpos = first_vpos; + timer.m_increment = increment; } @@ -152,10 +128,10 @@ void timer_device_config::static_configure_scanline(device_config *device, timer // to set the callback //------------------------------------------------- -void timer_device_config::static_set_callback(device_config *device, timer_device_fired_func callback) +void timer_device::static_set_callback(device_t &device, timer_device_fired_func callback) { - timer_device_config *timer = downcast<timer_device_config *>(device); - timer->m_callback = callback; + timer_device &timer = downcast<timer_device &>(device); + timer.m_callback = callback; } @@ -164,10 +140,10 @@ void timer_device_config::static_set_callback(device_config *device, timer_devic // to set the starting delay //------------------------------------------------- -void timer_device_config::static_set_start_delay(device_config *device, attotime delay) +void timer_device::static_set_start_delay(device_t &device, attotime delay) { - timer_device_config *timer = downcast<timer_device_config *>(device); - timer->m_start_delay = delay; + timer_device &timer = downcast<timer_device &>(device); + timer.m_start_delay = delay; } @@ -176,10 +152,10 @@ void timer_device_config::static_set_start_delay(device_config *device, attotime // the integer parameter //------------------------------------------------- -void timer_device_config::static_set_param(device_config *device, int param) +void timer_device::static_set_param(device_t &device, int param) { - timer_device_config *timer = downcast<timer_device_config *>(device); - timer->m_param = param; + timer_device &timer = downcast<timer_device &>(device); + timer.m_param = param; } @@ -188,10 +164,10 @@ void timer_device_config::static_set_param(device_config *device, int param) // the pointer parameter //------------------------------------------------- -void timer_device_config::static_set_ptr(device_config *device, void *ptr) +void timer_device::static_set_ptr(device_t &device, void *ptr) { - timer_device_config *timer = downcast<timer_device_config *>(device); - timer->m_ptr = ptr; + timer_device &timer = downcast<timer_device &>(device); + timer.m_ptr = ptr; } @@ -200,7 +176,7 @@ void timer_device_config::static_set_ptr(device_config *device, void *ptr) // configuration //------------------------------------------------- -bool timer_device_config::device_validity_check(emu_options &options, const game_driver &driver) const +bool timer_device::device_validity_check(emu_options &options, const game_driver &driver) const { bool error = false; @@ -208,14 +184,14 @@ bool timer_device_config::device_validity_check(emu_options &options, const game switch (m_type) { case TIMER_TYPE_GENERIC: - if (m_screen != NULL || m_first_vpos != 0 || m_start_delay != attotime::zero) + if (m_screen_tag != NULL || m_first_vpos != 0 || m_start_delay != attotime::zero) mame_printf_warning("%s: %s generic timer '%s' specified parameters for a scanline timer\n", driver.source_file, driver.name, tag()); if (m_period != attotime::zero || m_start_delay != attotime::zero) 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) + if (m_screen_tag != 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 <= attotime::zero) { @@ -251,26 +227,6 @@ bool timer_device_config::device_validity_check(emu_options &options, const game } - -//************************************************************************** -// LIVE TIMER DEVICE -//************************************************************************** - -//------------------------------------------------- -// timer_device - constructor -//------------------------------------------------- - -timer_device::timer_device(running_machine &_machine, const timer_device_config &config) - : device_t(_machine, config), - m_config(config), - m_timer(NULL), - m_ptr(m_config.m_ptr), - m_screen(NULL), - m_first_time(true) -{ -} - - //------------------------------------------------- // device_start - perform device-specific // startup @@ -279,8 +235,8 @@ timer_device::timer_device(running_machine &_machine, const timer_device_config void timer_device::device_start() { // fetch the screen - if (m_config.m_screen != NULL) - m_screen = downcast<screen_device *>(machine().device(m_config.m_screen)); + if (m_screen_tag != NULL) + m_screen = machine().device<screen_device>(m_screen_tag); // allocate the timer m_timer = timer_alloc(); @@ -297,35 +253,35 @@ void timer_device::device_start() void timer_device::device_reset() { // type based configuration - switch (m_config.m_type) + switch (m_type) { - case timer_device_config::TIMER_TYPE_GENERIC: - case timer_device_config::TIMER_TYPE_PERIODIC: + case TIMER_TYPE_GENERIC: + case TIMER_TYPE_PERIODIC: { // convert the period into attotime attotime period = attotime::never; - if (m_config.m_period > attotime::zero) + if (m_period > attotime::zero) { - period = m_config.m_period; + period = m_period; // convert the start_delay into attotime attotime start_delay = attotime::zero; - if (m_config.m_start_delay > attotime::zero) - start_delay = m_config.m_start_delay; + if (m_start_delay > attotime::zero) + start_delay = m_start_delay; // allocate and start the backing timer - m_timer->adjust(start_delay, m_config.m_param, period); + m_timer->adjust(start_delay, m_param, period); } break; } - case timer_device_config::TIMER_TYPE_SCANLINE: + case TIMER_TYPE_SCANLINE: if (m_screen == NULL) - fatalerror("timer '%s': unable to find screen '%s'\n", tag(), m_config.m_screen); + fatalerror("timer '%s': unable to find screen '%s'\n", tag(), m_screen_tag); // set the timer to to fire immediately m_first_time = true; - m_timer->adjust(attotime::zero, m_config.m_param); + m_timer->adjust(attotime::zero, m_param); break; } } @@ -337,35 +293,32 @@ void timer_device::device_reset() void timer_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) { - switch (m_config.m_type) + switch (m_type) { // general periodic timers just call through - case timer_device_config::TIMER_TYPE_GENERIC: - case timer_device_config::TIMER_TYPE_PERIODIC: - if (m_config.m_type != timer_device_config::TIMER_TYPE_SCANLINE) - { - if (m_config.m_callback != NULL) - (*m_config.m_callback)(*this, m_ptr, param); - } + case TIMER_TYPE_GENERIC: + case TIMER_TYPE_PERIODIC: + if (m_callback != NULL) + (*m_callback)(*this, m_ptr, param); break; // scanline timers have to do some additiona bookkeeping - case timer_device_config::TIMER_TYPE_SCANLINE: + case TIMER_TYPE_SCANLINE: { // by default, we fire at the first position - int next_vpos = m_config.m_first_vpos; + int next_vpos = m_first_vpos; // the first time through we just go with the default position if (!m_first_time) { // call the real callback int vpos = m_screen->vpos(); - (*m_config.m_callback)(*this, m_ptr, vpos); + (*m_callback)(*this, m_ptr, vpos); // advance by the increment only if we will still be within the screen bounds - if (m_config.m_increment != 0 && (vpos + m_config.m_increment) < m_screen->height()) - next_vpos = vpos + m_config.m_increment; + if (m_increment != 0 && (vpos + m_increment) < m_screen->height()) + next_vpos = vpos + m_increment; } m_first_time = false; |