trunk/src/emu/timer.c
| r18133 | r18134 | |
| 64 | 64 | timer_device::timer_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 65 | 65 | : device_t(mconfig, TIMER, "Timer", tag, owner, clock), |
| 66 | 66 | m_type(TIMER_TYPE_GENERIC), |
| 67 | | m_callback(NULL), |
| 67 | m_callback(timer_device_expired_delegate()), |
| 68 | 68 | m_ptr(NULL), |
| 69 | 69 | m_start_delay(attotime::zero), |
| 70 | 70 | m_period(attotime::zero), |
| r18133 | r18134 | |
| 84 | 84 | // helper to set up a generic timer |
| 85 | 85 | //------------------------------------------------- |
| 86 | 86 | |
| 87 | | void timer_device::static_configure_generic(device_t &device, timer_device_fired_func callback) |
| 87 | void timer_device::static_configure_generic(device_t &device, timer_device_expired_delegate callback) |
| 88 | 88 | { |
| 89 | 89 | timer_device &timer = downcast<timer_device &>(device); |
| 90 | 90 | timer.m_type = TIMER_TYPE_GENERIC; |
| r18133 | r18134 | |
| 97 | 97 | // helper to set up a periodic timer |
| 98 | 98 | //------------------------------------------------- |
| 99 | 99 | |
| 100 | | void timer_device::static_configure_periodic(device_t &device, timer_device_fired_func callback, attotime period) |
| 100 | void timer_device::static_configure_periodic(device_t &device, timer_device_expired_delegate callback, attotime period) |
| 101 | 101 | { |
| 102 | 102 | timer_device &timer = downcast<timer_device &>(device); |
| 103 | 103 | timer.m_type = TIMER_TYPE_PERIODIC; |
| r18133 | r18134 | |
| 111 | 111 | // helper to set up a scanline timer |
| 112 | 112 | //------------------------------------------------- |
| 113 | 113 | |
| 114 | | void timer_device::static_configure_scanline(device_t &device, timer_device_fired_func callback, const char *screen, int first_vpos, int increment) |
| 114 | void timer_device::static_configure_scanline(device_t &device, timer_device_expired_delegate callback, const char *screen, int first_vpos, int increment) |
| 115 | 115 | { |
| 116 | 116 | timer_device &timer = downcast<timer_device &>(device); |
| 117 | 117 | timer.m_type = TIMER_TYPE_SCANLINE; |
| r18133 | r18134 | |
| 127 | 127 | // to set the callback |
| 128 | 128 | //------------------------------------------------- |
| 129 | 129 | |
| 130 | | void timer_device::static_set_callback(device_t &device, timer_device_fired_func callback) |
| 130 | void timer_device::static_set_callback(device_t &device, timer_device_expired_delegate callback) |
| 131 | 131 | { |
| 132 | 132 | timer_device &timer = downcast<timer_device &>(device); |
| 133 | 133 | timer.m_callback = callback; |
| r18133 | r18134 | |
| 283 | 283 | // general periodic timers just call through |
| 284 | 284 | case TIMER_TYPE_GENERIC: |
| 285 | 285 | case TIMER_TYPE_PERIODIC: |
| 286 | | if (m_callback != NULL) |
| 287 | | (*m_callback)(*this, m_ptr, param); |
| 286 | if (!m_callback.isnull()) |
| 287 | (m_callback)(*this, m_ptr, param); |
| 288 | 288 | break; |
| 289 | 289 | |
| 290 | 290 | |
| r18133 | r18134 | |
| 299 | 299 | { |
| 300 | 300 | // call the real callback |
| 301 | 301 | int vpos = m_screen->vpos(); |
| 302 | | (*m_callback)(*this, m_ptr, vpos); |
| 302 | (m_callback)(*this, m_ptr, vpos); |
| 303 | 303 | |
| 304 | 304 | // advance by the increment only if we will still be within the screen bounds |
| 305 | 305 | if (m_increment != 0 && (vpos + m_increment) < m_screen->height()) |
trunk/src/emu/timer.h
| r18133 | r18134 | |
| 53 | 53 | //************************************************************************** |
| 54 | 54 | |
| 55 | 55 | // macros for a timer callback functions |
| 56 | | #define TIMER_DEVICE_CALLBACK(name) void name(timer_device &timer, void *ptr, INT32 param) |
| 56 | #define TIMER_DEVICE_CALLBACK(name) void name(device_t *, timer_device &timer, void *ptr, INT32 param) |
| 57 | #define TIMER_DEVICE_CALLBACK_MEMBER(name) void name(timer_device &timer, void *ptr, INT32 param) |
| 57 | 58 | |
| 58 | | |
| 59 | | |
| 60 | | |
| 61 | 59 | //************************************************************************** |
| 62 | 60 | // TIMER DEVICE CONFIGURATION MACROS |
| 63 | 61 | //************************************************************************** |
| 64 | 62 | |
| 65 | 63 | #define MCFG_TIMER_ADD(_tag, _callback) \ |
| 66 | 64 | MCFG_DEVICE_ADD(_tag, TIMER, 0) \ |
| 67 | | timer_device::static_configure_generic(*device, _callback); \ |
| 65 | timer_device::static_configure_generic(*device, timer_device_expired_delegate(&_callback, #_callback)); \ |
| 68 | 66 | |
| 67 | #define MCFG_TIMER_ADD_NONE(_tag) \ |
| 68 | MCFG_DEVICE_ADD(_tag, TIMER, 0) \ |
| 69 | timer_device::static_configure_generic(*device, timer_device_expired_delegate()); \ |
| 70 | |
| 69 | 71 | #define MCFG_TIMER_ADD_PERIODIC(_tag, _callback, _period) \ |
| 70 | 72 | MCFG_DEVICE_ADD(_tag, TIMER, 0) \ |
| 71 | | timer_device::static_configure_periodic(*device, _callback, _period); \ |
| 73 | timer_device::static_configure_periodic(*device, timer_device_expired_delegate(&_callback, #_callback), _period); \ |
| 72 | 74 | |
| 73 | 75 | #define MCFG_TIMER_ADD_SCANLINE(_tag, _callback, _screen, _first_vpos, _increment) \ |
| 74 | 76 | MCFG_DEVICE_ADD(_tag, TIMER, 0) \ |
| 75 | | timer_device::static_configure_scanline(*device, _callback, _screen, _first_vpos, _increment); \ |
| 77 | timer_device::static_configure_scanline(*device, timer_device_expired_delegate(&_callback, #_callback), _screen, _first_vpos, _increment); \ |
| 76 | 78 | |
| 79 | #define MCFG_TIMER_DRIVER_ADD(_tag, _class, _callback) \ |
| 80 | MCFG_DEVICE_ADD(_tag, TIMER, 0) \ |
| 81 | timer_device::static_configure_generic(*device, timer_device_expired_delegate(&_class::_callback, #_class "::" #_callback, NULL)); \ |
| 82 | |
| 83 | #define MCFG_TIMER_DRIVER_ADD_PERIODIC(_tag, _class, _callback, _period) \ |
| 84 | MCFG_DEVICE_ADD(_tag, TIMER, 0) \ |
| 85 | timer_device::static_configure_periodic(*device, timer_device_expired_delegate(&_class::_callback, #_class "::" #_callback, NULL), _period); \ |
| 86 | |
| 87 | #define MCFG_TIMER_DRIVER_ADD_SCANLINE(_tag, _class, _callback, _screen, _first_vpos, _increment) \ |
| 88 | MCFG_DEVICE_ADD(_tag, TIMER, 0) \ |
| 89 | timer_device::static_configure_scanline(*device, timer_device_expired_delegate(&_class::_callback, #_class "::" #_callback, NULL), _screen, _first_vpos, _increment); \ |
| 90 | |
| 77 | 91 | #define MCFG_TIMER_MODIFY(_tag) \ |
| 78 | 92 | MCFG_DEVICE_MODIFY(_tag) |
| 79 | 93 | |
| 80 | 94 | #define MCFG_TIMER_CALLBACK(_callback) \ |
| 81 | | timer_device::static_set_callback(*device, _callback); \ |
| 95 | timer_device::static_set_callback(*device, timer_device_expired_delegate(&_callback, #_callback)); \ |
| 82 | 96 | |
| 97 | #define MCFG_TIMER_DRIVER_CALLBACK(_class, _callback) \ |
| 98 | timer_device::static_set_callback(*device, timer_device_expired_delegate(&_class::_callback, #_class "::" #_callback, NULL)); \ |
| 99 | |
| 83 | 100 | #define MCFG_TIMER_START_DELAY(_start_delay) \ |
| 84 | 101 | timer_device::static_set_start_delay(*device, _start_delay); \ |
| 85 | 102 | |
| r18133 | r18134 | |
| 99 | 116 | class emu_timer; |
| 100 | 117 | class timer_device; |
| 101 | 118 | |
| 102 | | // a timer callback looks like this |
| 103 | | typedef void (*timer_device_fired_func)(timer_device &timer, void *ptr, INT32 param); |
| 119 | // a timer callbacks look like this |
| 120 | typedef device_delegate<void (timer_device &, void *, INT32)> timer_device_expired_delegate; |
| 104 | 121 | |
| 105 | | |
| 106 | 122 | // ======================> timer_device |
| 107 | 123 | |
| 108 | 124 | class timer_device : public device_t |
| r18133 | r18134 | |
| 112 | 128 | timer_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 113 | 129 | |
| 114 | 130 | // inline configuration helpers |
| 115 | | static void static_configure_generic(device_t &device, timer_device_fired_func callback); |
| 116 | | static void static_configure_periodic(device_t &device, timer_device_fired_func callback, attotime period); |
| 117 | | static void static_configure_scanline(device_t &device, timer_device_fired_func callback, const char *screen, int first_vpos, int increment); |
| 118 | | static void static_set_callback(device_t &device, timer_device_fired_func callback); |
| 131 | static void static_configure_generic(device_t &device, timer_device_expired_delegate callback); |
| 132 | static void static_configure_periodic(device_t &device, timer_device_expired_delegate callback, attotime period); |
| 133 | static void static_configure_scanline(device_t &device, timer_device_expired_delegate callback, const char *screen, int first_vpos, int increment); |
| 134 | static void static_set_callback(device_t &device, timer_device_expired_delegate callback); |
| 119 | 135 | static void static_set_start_delay(device_t &device, attotime delay); |
| 120 | 136 | static void static_set_param(device_t &device, int param); |
| 121 | 137 | static void static_set_ptr(device_t &device, void *ptr); |
| r18133 | r18134 | |
| 157 | 173 | |
| 158 | 174 | // configuration data |
| 159 | 175 | timer_type m_type; // type of timer |
| 160 | | timer_device_fired_func m_callback; // the timer's callback function |
| 176 | timer_device_expired_delegate m_callback; // the timer's callback function |
| 161 | 177 | void * m_ptr; // the pointer parameter passed to the timer callback |
| 162 | 178 | |
| 163 | 179 | // periodic timers only |