diff options
author | 2010-06-08 06:09:57 +0000 | |
---|---|---|
committer | 2010-06-08 06:09:57 +0000 | |
commit | 100564d41225bfd2fa163c0174557ed979285b4e (patch) | |
tree | 0be83fbde1ddb95633293c9faee60d0f2bc6ace1 /src/emu/timer.h | |
parent | 962dca9f57d61cdea65ee32c6362bf3d0d1e2dae (diff) |
WARNING: There are likely to be regressions in both functionality and
performance as a result of this change. Do not panic; report issues to the
list in the short term and I will look into them. There are probably also
some details I forgot to mention. Please ask questions if anything is not
clear.
NOTE: This is a major internal change to the way devices are handled in
MAME. There is a small impact on drivers, but the bulk of the changes are
to the devices themselves. Full documentation on the new device handling
is in progress at http://mamedev.org/devwiki/index.php/MAME_Device_Basics
Defined two new casting helpers: [Aaron Giles]
downcast<type>(value) should be used for safe and efficient downcasting
from a base class to a derived class. It wraps static_cast<> by adding
an assert that a matching dynamic_cast<> returns the same result in
debug builds.
crosscast<type>(value) should be used for safe casting from one type to
another in multiple inheritance scenarios. It compiles to a
dynamic_cast<> plus an assert on the result. Since it does not optimize
down to static_cast<>, you should prefer downcast<> over crosscast<>
when you can.
Redefined running_device to be a proper C++ class (now called device_t).
Same for device_config (still called device_config). All devices and
device_configs must now be derived from these base classes. This means
each device type now has a pair of its own unique classes that describe
the device. Drivers are encouraged to use the specific device types
instead of the generic running_device or device_t classes. Drivers that
have a state class defined in their header file are encouraged to use
initializers off the constructor to locate devices. [Aaron Giles]
Removed the following fields from the device and device configuration
classes as they never were necessary or provided any use: device class,
device family, source file, version, credits. [Aaron Giles]
Added templatized variant of machine->device() which performs a downcast
as part of the device fetch. Thus machine->device<timer_device>("timer")
will locate a device named "timer", downcast it to a timer_device, and
assert if the downcast fails. [Aaron Giles]
Removed most publically accessible members of running_device/device_t in
favor of inline accessor functions. The only remaining public member is
machine. Thus all references to device->type are now device->type(), etc.
[Aaron Giles]
Created a number of device interface classes which are designed to be mix-
ins for the device classes, providing specific extended functionality and
information. There are standard interface classes for sound, execution,
state, nvram, memory, and disassembly. Devices can opt into 0 or more of
these classes. [Aaron Giles]
Converted the classic CPU device to a standard device that uses the
execution, state, memory, and disassembly interfaces. Used this new class
(cpu_device) to implement the existing CPU device interface. In the future
it will be possible to convert each CPU core to its own device type, but
for now they are still all CPU devices with a cpu_type() that specifies
exactly which kind of CPU. [Aaron Giles]
Created a new header devlegcy.h which wraps the old device interface using
some special template classes. To use these with an existing device,
simply remove from the device header the DEVICE_GET_INFO() declaration and
the #define mapping the ALL_CAPS name to the DEVICE_GET_INFO. In their
place #include "devlegcy.h" and use the DECLARE_LEGACY_DEVICE() macro.
In addition, there is a DECLARE_LEGACY_SOUND_DEVICE() macro for wrapping
existing sound devices into new-style devices, and a
DECLARE_LEGACY_NVRAM_DEVICE() for wrapping NVRAM devices. Also moved the
token and inline_config members to the legacy device class, as these are
not used in modern devices. [Aaron Giles]
Converted the standard base devices (VIDEO_SCREEN, SPEAKER, and TIMER)
from legacy devices to the new C++ style. Also renamed VIDEO_SCREEN to
simply SCREEN. The various global functions that were previously used to
access information or modify the state of these devices are now replaced
by methods on the device classes. Specifically:
video_screen_configure() == screen->configure()
video_screen_set_visarea() == screen->set_visible_area()
video_screen_update_partial() == screen->update_partial()
video_screen_update_now() == screen->update_now()
video_screen_get_vpos() == screen->vpos()
video_screen_get_hpos() == screen->hpos()
video_screen_get_vblank() == screen->vblank()
video_screen_get_hblank() == screen->hblank()
video_screen_get_width() == screen->width()
video_screen_get_height() == screen->height()
video_screen_get_visible_area() == screen->visible_area()
video_screen_get_time_until_pos() == screen->time_until_pos()
video_screen_get_time_until_vblank_start() ==
screen->time_until_vblank_start()
video_screen_get_time_until_vblank_end() ==
screen->time_until_vblank_end()
video_screen_get_time_until_update() == screen->time_until_update()
video_screen_get_scan_period() == screen->scan_period()
video_screen_get_frame_period() == screen->frame_period()
video_screen_get_frame_number() == screen->frame_number()
timer_device_adjust_oneshot() == timer->adjust()
timer_device_adjust_periodic() == timer->adjust()
timer_device_reset() == timer->reset()
timer_device_enable() == timer->enable()
timer_device_enabled() == timer->enabled()
timer_device_get_param() == timer->param()
timer_device_set_param() == timer->set_param()
timer_device_get_ptr() == timer->get_ptr()
timer_device_set_ptr() == timer->set_ptr()
timer_device_timeelapsed() == timer->time_elapsed()
timer_device_timeleft() == timer->time_left()
timer_device_starttime() == timer->start_time()
timer_device_firetime() == timer->fire_time()
Updated all drivers that use the above functions to fetch the specific
device type (timer_device or screen_device) and call the appropriate
method. [Aaron Giles]
Changed machine->primary_screen and the 'screen' parameter to VIDEO_UPDATE
to specifically pass in a screen_device object. [Aaron Giles]
Defined a new custom interface for the Z80 daisy chain. This interface
behaves like the standard interfaces, and can be added to any device that
implements the Z80 daisy chain behavior. Converted all existing Z80 daisy
chain devices to new-style devices that inherit this interface.
[Aaron Giles]
Changed the way CPU state tables are built up. Previously, these were data
structures defined by a CPU core which described all the registers and how
to output them. This functionality is now part of the state interface and
is implemented via the device_state_entry class. Updated all CPU cores
which were using the old data structure to use the new form. The syntax is
currently awkward, but will be cleaner for CPUs that are native new
devices. [Aaron Giles]
Converted the okim6295 and eeprom devices to the new model. These were
necessary because they both require multiple interfaces to operate and it
didn't make sense to create legacy device templates for these single cases.
(okim6295 needs the sound interface and the memory interface, while eeprom
requires both the nvram and memory interfaces). [Aaron Giles]
Changed parameters in a few callback functions from pointers to references
in situations where they are guaranteed to never be NULL. [Aaron Giles]
Removed MDRV_CPU_FLAGS() which was only used for disabling a CPU. Changed
it to MDRV_DEVICE_DISABLE() instead. Updated drivers. [Aaron Giles]
Reorganized the token parsing for machine configurations. The core parsing
code knows how to create/replace/remove devices, but all device token
parsing is now handled in the device_config class, which in turn will make
use of any interface classes or device-specific token handling for custom
token processing. [Aaron Giles]
Moved many validity checks out of validity.c and into the device interface
classes. For example, address space validation is now part of the memory
interface class. [Aaron Giles]
Consolidated address space parameters (bus width, endianness, etc.) into
a single address_space_config class. Updated all code that queried for
address space parameters to use the new mechanism. [Aaron Giles]
Diffstat (limited to 'src/emu/timer.h')
-rw-r--r-- | src/emu/timer.h | 220 |
1 files changed, 143 insertions, 77 deletions
diff --git a/src/emu/timer.h b/src/emu/timer.h index d48540d71bc..af56bf054b4 100644 --- a/src/emu/timer.h +++ b/src/emu/timer.h @@ -19,19 +19,7 @@ #ifndef __TIMER_H__ #define __TIMER_H__ - -/*************************************************************************** - CONSTANTS -***************************************************************************/ - -/* timer types */ -enum -{ - TIMER_TYPE_PERIODIC = 0, - TIMER_TYPE_SCANLINE, - TIMER_TYPE_GENERIC -}; - +#include "devlegcy.h" /*************************************************************************** @@ -57,7 +45,7 @@ enum /* macros for a timer callback functions */ #define TIMER_CALLBACK(name) void name(running_machine *machine, void *ptr, int param) -#define TIMER_DEVICE_CALLBACK(name) void name(running_device *timer, void *ptr, INT32 param) +#define TIMER_DEVICE_CALLBACK(name) void name(timer_device &timer, void *ptr, INT32 param) @@ -65,41 +53,19 @@ enum TYPE DEFINITIONS ***************************************************************************/ -/* a timer callback looks like this */ -typedef void (*timer_fired_func)(running_machine *machine, void *ptr, INT32 param); -typedef void (*timer_device_fired_func)(running_device *timer, void *ptr, INT32 param); - +// forward declarations +class emu_timer; +class timer_device; -/*------------------------------------------------- - timer_config - configuration of a single - timer --------------------------------------------------*/ -typedef struct _timer_config timer_config; -struct _timer_config -{ - int type; /* type of timer */ - timer_device_fired_func callback; /* the timer's callback function */ - void *ptr; /* the pointer parameter passed to the timer callback */ - - /* periodic timers only */ - UINT64 start_delay; /* delay before the timer fires for the first time */ - UINT64 period; /* period of repeated timer firings */ - INT32 param; /* the integer parameter passed to the timer callback */ - - /* scanline timers only */ - const char *screen; /* the name of the screen this timer tracks */ - UINT32 first_vpos; /* the first vertical scanline position the timer fires on */ - UINT32 increment; /* the number of scanlines between firings */ -}; +// a timer callback looks like this +typedef void (*timer_fired_func)(running_machine *machine, void *ptr, INT32 param); +typedef void (*timer_device_fired_func)(timer_device &timer, void *ptr, INT32 param); -/* opaque type for representing a timer */ -typedef struct _emu_timer emu_timer; -typedef struct _timer_execution_state timer_execution_state; -struct _timer_execution_state +struct timer_execution_state { attotime nextfire; /* time that the head of the timer list will fire */ attotime basetime; /* global basetime; everything moves forward from here */ @@ -108,43 +74,43 @@ struct _timer_execution_state -/*************************************************************************** - TIMER DEVICE CONFIGURATION MACROS -***************************************************************************/ +//************************************************************************** +// TIMER DEVICE CONFIGURATION MACROS +//************************************************************************** #define MDRV_TIMER_ADD(_tag, _callback) \ MDRV_DEVICE_ADD(_tag, TIMER, 0) \ - MDRV_DEVICE_CONFIG_DATA32(timer_config, type, TIMER_TYPE_GENERIC) \ - MDRV_DEVICE_CONFIG_DATAPTR(timer_config, callback, _callback) \ + MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_TYPE, timer_device_config::TIMER_TYPE_GENERIC) \ + MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_CALLBACK, _callback) #define MDRV_TIMER_ADD_PERIODIC(_tag, _callback, _period) \ MDRV_DEVICE_ADD(_tag, TIMER, 0) \ - MDRV_DEVICE_CONFIG_DATA32(timer_config, type, TIMER_TYPE_PERIODIC) \ - MDRV_DEVICE_CONFIG_DATAPTR(timer_config, callback, _callback) \ - MDRV_DEVICE_CONFIG_DATA64(timer_config, period, UINT64_ATTOTIME_IN_##_period) + MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_TYPE, timer_device_config::TIMER_TYPE_PERIODIC) \ + MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_CALLBACK, _callback) \ + MDRV_DEVICE_INLINE_DATA64(timer_device_config::INLINE_PERIOD, UINT64_ATTOTIME_IN_##_period) #define MDRV_TIMER_ADD_SCANLINE(_tag, _callback, _screen, _first_vpos, _increment) \ MDRV_DEVICE_ADD(_tag, TIMER, 0) \ - MDRV_DEVICE_CONFIG_DATA32(timer_config, type, TIMER_TYPE_SCANLINE) \ - MDRV_DEVICE_CONFIG_DATAPTR(timer_config, callback, _callback) \ - MDRV_DEVICE_CONFIG_DATAPTR(timer_config, screen, _screen) \ - MDRV_DEVICE_CONFIG_DATA32(timer_config, first_vpos, _first_vpos) \ - MDRV_DEVICE_CONFIG_DATA32(timer_config, increment, _increment) + MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_TYPE, timer_device_config::TIMER_TYPE_SCANLINE) \ + MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_CALLBACK, _callback) \ + MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_SCREEN, _screen) \ + MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_FIRST_VPOS, _first_vpos) \ + MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_INCREMENT, _increment) #define MDRV_TIMER_MODIFY(_tag) \ MDRV_DEVICE_MODIFY(_tag) #define MDRV_TIMER_CALLBACK(_callback) \ - MDRV_DEVICE_CONFIG_DATAPTR(timer_config, callback, _callback) + MDRV_DEVICE_INLINE_DATA32(timer_device_config::INLINE_CALLBACK, _callback) #define MDRV_TIMER_START_DELAY(_start_delay) \ - MDRV_DEVICE_CONFIG_DATA64(timer_config, start_delay, UINT64_ATTOTIME_IN_##_start_delay) + MDRV_DEVICE_INLINE_DATA64(timer_device_config::INLINE_DELAY, UINT64_ATTOTIME_IN_##_start_delay) #define MDRV_TIMER_PARAM(_param) \ - MDRV_DEVICE_CONFIG_DATA32(timer_config, param, _param) + MDRV_DEVICE_INLINE_DATA32(timer_device_config::INLINE_PARAM, _param) #define MDRV_TIMER_PTR(_ptr) \ - MDRV_DEVICE_CONFIG_DATAPTR(timer_config, ptr, _ptr) + MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_PTR, _ptr) @@ -193,11 +159,9 @@ emu_timer *_timer_alloc_internal(running_machine *machine, timer_fired_func call /* adjust the time when this timer will fire and disable any periodic firings */ void timer_adjust_oneshot(emu_timer *which, attotime duration, INT32 param); -void timer_device_adjust_oneshot(running_device *timer, attotime duration, INT32 param); /* adjust the time when this timer will fire and specify a period for subsequent firings */ void timer_adjust_periodic(emu_timer *which, attotime start_delay, INT32 param, attotime period); -void timer_device_adjust_periodic(running_device *timer, attotime start_delay, INT32 param, attotime period); @@ -215,31 +179,24 @@ void _timer_pulse_internal(running_machine *machine, attotime period, void *ptr, /* reset the timing on a timer */ void timer_reset(emu_timer *which, attotime duration); -void timer_device_reset(running_device *timer); /* enable/disable a timer */ int timer_enable(emu_timer *which, int enable); -int timer_device_enable(running_device *timer, int enable); /* determine if a timer is enabled */ int timer_enabled(emu_timer *which); -int timer_device_enabled(running_device *timer); /* returns the callback parameter of a timer */ int timer_get_param(emu_timer *which); -int timer_device_get_param(running_device *timer); /* changes the callback parameter of a timer */ void timer_set_param(emu_timer *which, int param); -void timer_device_set_param(running_device *timer, int param); /* returns the callback pointer of a timer */ void *timer_get_ptr(emu_timer *which); -void *timer_device_get_ptr(running_device *timer); /* changes the callback pointer of a timer */ void timer_set_ptr(emu_timer *which, void *ptr); -void timer_device_set_ptr(running_device *timer, void *ptr); @@ -247,29 +204,138 @@ void timer_device_set_ptr(running_device *timer, void *ptr); /* return the time since the last trigger */ attotime timer_timeelapsed(emu_timer *which); -attotime timer_device_timeelapsed(running_device *timer); /* return the time until the next trigger */ attotime timer_timeleft(emu_timer *which); -attotime timer_device_timeleft(running_device *timer); /* return the current time */ attotime timer_get_time(running_machine *machine); /* return the time when this timer started counting */ attotime timer_starttime(emu_timer *which); -attotime timer_device_starttime(running_device *timer); /* return the time when this timer will fire next */ attotime timer_firetime(emu_timer *which); -attotime timer_device_firetime(running_device *timer); -/* ----- timer device interface ----- */ -/* device get info callback */ -#define TIMER DEVICE_GET_INFO_NAME(timer) -DEVICE_GET_INFO( timer ); +// ======================> timer_device_config + +class timer_device_config : public device_config +{ + friend class timer_device; + + // construction/destruction + timer_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); + +public: + // allocators + static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); + virtual device_t *alloc_device(running_machine &machine) const; + + // basic information getters + virtual const char *name() const { return "Timer"; } + + // indexes to inline data + enum + { + INLINE_TYPE, + INLINE_CALLBACK, + INLINE_PERIOD, + INLINE_SCREEN, + INLINE_FIRST_VPOS, + INLINE_INCREMENT, + INLINE_DELAY, + INLINE_PARAM, + INLINE_PTR + }; + + // timer types + enum timer_type + { + TIMER_TYPE_PERIODIC, + TIMER_TYPE_SCANLINE, + TIMER_TYPE_GENERIC + }; + +private: + // device_config overrides + virtual void device_config_complete(); + virtual bool device_validity_check(const game_driver &driver) const; + + // configuration data + timer_type m_type; // type of timer + timer_device_fired_func m_callback; // the timer's callback function + void * m_ptr; // the pointer parameter passed to the timer callback + + // periodic timers only + UINT64 m_start_delay; // delay before the timer fires for the first time + UINT64 m_period; // period of repeated timer firings + INT32 m_param; // the integer parameter passed to the timer callback + + // scanline timers only + const char * m_screen; // the name of the screen this timer tracks + UINT32 m_first_vpos; // the first vertical scanline position the timer fires on + UINT32 m_increment; // the number of scanlines between firings +}; + + + +// ======================> timer_device + +class timer_device : public device_t +{ + friend class timer_device_config; + + // construction/destruction + timer_device(running_machine &_machine, const timer_device_config &config); + +public: + // property getters + int param() const { return timer_get_param(m_timer); } + void *ptr() const { return m_ptr; } + bool enabled() const { return (timer_enabled(m_timer) != 0); } + + // property setters + void set_param(int param) { assert(m_config.m_type == timer_device_config::TIMER_TYPE_GENERIC); timer_set_param(m_timer, param); } + void set_ptr(void *ptr) { m_ptr = ptr; } + void enable(bool enable = true) { timer_enable(m_timer, enable); } + + // adjustments + void reset() { adjust(attotime_never, 0, attotime_never); } + void adjust(attotime duration, INT32 param = 0, attotime period = attotime_never) { assert(m_config.m_type == timer_device_config::TIMER_TYPE_GENERIC); timer_adjust_periodic(m_timer, duration, param, period); } + + // timing information + attotime time_elapsed() const { return timer_timeelapsed(m_timer); } + attotime time_left() const { return timer_timeleft(m_timer); } + attotime start_time() const { return timer_starttime(m_timer); } + attotime fire_time() const { return timer_firetime(m_timer); } + +private: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + + // internal helpers + static TIMER_CALLBACK( static_periodic_timer_callback ) { reinterpret_cast<timer_device *>(ptr)->periodic_timer_callback(param); } + void periodic_timer_callback(int param); + + static TIMER_CALLBACK( static_scanline_timer_callback ) { reinterpret_cast<timer_device *>(ptr)->scanline_timer_callback(param); } + void scanline_timer_callback(int scanline); + + // internal state + const timer_device_config &m_config; + emu_timer * m_timer; // the backing timer + void * m_ptr; // the pointer parameter passed to the timer callback + + // scanline timers only + screen_device *m_screen; // pointer to the screen + bool m_first_time; // indicates that the system is starting +}; + + +// device type definition +const device_type TIMER = timer_device_config::static_alloc_device_config; #endif /* __TIMER_H__ */ |