Previous 199869 Revisions Next

r18134 Tuesday 25th September, 2012 at 07:30:11 UTC by Miodrag Milanović
Made timer_device use delegates (no whatsnew)
[src/emu]timer.c timer.h
[src/mame/drivers]midvunit.c segas24.c viper.c
[src/mame/machine]balsente.c megacd.c

trunk/src/emu/timer.c
r18133r18134
6464timer_device::timer_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
6565   : device_t(mconfig, TIMER, "Timer", tag, owner, clock),
6666     m_type(TIMER_TYPE_GENERIC),
67     m_callback(NULL),
67     m_callback(timer_device_expired_delegate()),
6868     m_ptr(NULL),
6969     m_start_delay(attotime::zero),
7070     m_period(attotime::zero),
r18133r18134
8484//  helper to set up a generic timer
8585//-------------------------------------------------
8686
87void timer_device::static_configure_generic(device_t &device, timer_device_fired_func callback)
87void timer_device::static_configure_generic(device_t &device, timer_device_expired_delegate callback)
8888{
8989   timer_device &timer = downcast<timer_device &>(device);
9090   timer.m_type = TIMER_TYPE_GENERIC;
r18133r18134
9797//  helper to set up a periodic timer
9898//-------------------------------------------------
9999
100void timer_device::static_configure_periodic(device_t &device, timer_device_fired_func callback, attotime period)
100void timer_device::static_configure_periodic(device_t &device, timer_device_expired_delegate callback, attotime period)
101101{
102102   timer_device &timer = downcast<timer_device &>(device);
103103   timer.m_type = TIMER_TYPE_PERIODIC;
r18133r18134
111111//  helper to set up a scanline timer
112112//-------------------------------------------------
113113
114void timer_device::static_configure_scanline(device_t &device, timer_device_fired_func callback, const char *screen, int first_vpos, int increment)
114void timer_device::static_configure_scanline(device_t &device, timer_device_expired_delegate callback, const char *screen, int first_vpos, int increment)
115115{
116116   timer_device &timer = downcast<timer_device &>(device);
117117   timer.m_type = TIMER_TYPE_SCANLINE;
r18133r18134
127127//  to set the callback
128128//-------------------------------------------------
129129
130void timer_device::static_set_callback(device_t &device, timer_device_fired_func callback)
130void timer_device::static_set_callback(device_t &device, timer_device_expired_delegate callback)
131131{
132132   timer_device &timer = downcast<timer_device &>(device);
133133   timer.m_callback = callback;
r18133r18134
283283      // general periodic timers just call through
284284      case TIMER_TYPE_GENERIC:
285285      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);
288288         break;
289289
290290
r18133r18134
299299         {
300300            // call the real callback
301301            int vpos = m_screen->vpos();
302            (*m_callback)(*this, m_ptr, vpos);
302            (m_callback)(*this, m_ptr, vpos);
303303
304304            // advance by the increment only if we will still be within the screen bounds
305305              if (m_increment != 0 && (vpos + m_increment) < m_screen->height())
trunk/src/emu/timer.h
r18133r18134
5353//**************************************************************************
5454
5555// 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)
5758
58
59
60
6159//**************************************************************************
6260//  TIMER DEVICE CONFIGURATION MACROS
6361//**************************************************************************
6462
6563#define MCFG_TIMER_ADD(_tag, _callback) \
6664   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)); \
6866
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
6971#define MCFG_TIMER_ADD_PERIODIC(_tag, _callback, _period) \
7072   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); \
7274
7375#define MCFG_TIMER_ADD_SCANLINE(_tag, _callback, _screen, _first_vpos, _increment) \
7476   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); \
7678
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
7791#define MCFG_TIMER_MODIFY(_tag) \
7892   MCFG_DEVICE_MODIFY(_tag)
7993
8094#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)); \
8296
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
83100#define MCFG_TIMER_START_DELAY(_start_delay) \
84101   timer_device::static_set_start_delay(*device, _start_delay); \
85102
r18133r18134
99116class emu_timer;
100117class timer_device;
101118
102// a timer callback looks like this
103typedef void (*timer_device_fired_func)(timer_device &timer, void *ptr, INT32 param);
119// a timer callbacks look like this
120typedef device_delegate<void (timer_device &, void *, INT32)> timer_device_expired_delegate;
104121
105
106122// ======================> timer_device
107123
108124class timer_device : public device_t
r18133r18134
112128   timer_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
113129
114130   // 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);
119135   static void static_set_start_delay(device_t &device, attotime delay);
120136   static void static_set_param(device_t &device, int param);
121137   static void static_set_ptr(device_t &device, void *ptr);
r18133r18134
157173
158174   // configuration data
159175   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
161177   void *               m_ptr;            // the pointer parameter passed to the timer callback
162178
163179   // periodic timers only
trunk/src/mame/machine/megacd.c
r18133r18134
4848
4949   MCFG_DEVICE_ADD("cdc", LC89510, 0) // cd controller
5050
51   MCFG_TIMER_ADD("sw_timer", NULL) //stopwatch timer
51   MCFG_TIMER_ADD_NONE("sw_timer") //stopwatch timer
5252
5353   MCFG_DEFAULT_LAYOUT( layout_megacd )
5454
trunk/src/mame/machine/balsente.c
r18133r18134
867867      {
868868         state->m_counter[0].count--;
869869         if (state->m_counter[0].count == 0)
870            balsente_counter_callback(timer, NULL, 0);
870            balsente_counter_callback(state, timer, NULL, 0);
871871      }
872872   }
873873
trunk/src/mame/drivers/midvunit.c
r18133r18134
10181018
10191019   MCFG_NVRAM_ADD_1FILL("nvram")
10201020
1021   MCFG_TIMER_ADD("timer0", NULL)
1022   MCFG_TIMER_ADD("timer1", NULL)
1021   MCFG_TIMER_ADD_NONE("timer0")
1022   MCFG_TIMER_ADD_NONE("timer1")
10231023
10241024   /* video hardware */
10251025   MCFG_PALETTE_LENGTH(32768)
trunk/src/mame/drivers/segas24.c
r18133r18134
19561956
19571957   MCFG_TIMER_ADD("irq_timer", irq_timer_cb)
19581958   MCFG_TIMER_ADD("irq_timer_clear", irq_timer_clear_cb)
1959   MCFG_TIMER_ADD("frc_timer", NULL)
1959   MCFG_TIMER_ADD_NONE("frc_timer")
19601960   MCFG_TIMER_ADD_PERIODIC("irq_frc", irq_frc_cb, attotime::from_hz(FRC_CLOCK_MODE1))
19611961
19621962   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_AFTER_VBLANK)
trunk/src/mame/drivers/viper.c
r18133r18134
20392039
20402040   MCFG_SCREEN_UPDATE_DRIVER(viper_state, screen_update_viper)
20412041
2042   MCFG_TIMER_ADD("ds2430_timer2", NULL)
2042   MCFG_TIMER_ADD_NONE("ds2430_timer2")
20432043
20442044   /* sound hardware */
20452045   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")

Previous 199869 Revisions Next


© 1997-2024 The MAME Team