From 100564d41225bfd2fa163c0174557ed979285b4e Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Tue, 8 Jun 2010 06:09:57 +0000 Subject: 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(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(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") 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] --- src/emu/sound.h | 249 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 147 insertions(+), 102 deletions(-) (limited to 'src/emu/sound.h') diff --git a/src/emu/sound.h b/src/emu/sound.h index a43c15fd7d9..0fddfc5a286 100644 --- a/src/emu/sound.h +++ b/src/emu/sound.h @@ -19,29 +19,14 @@ #define __SOUND_H__ -/*************************************************************************** - CONSTANTS -***************************************************************************/ - -#define MAX_OUTPUTS 4095 /* maximum number of outputs a sound chip can support */ -#define ALL_OUTPUTS (MAX_OUTPUTS) /* special value indicating all outputs for the current chip */ - - - /*************************************************************************** MACROS ***************************************************************************/ /* these functions are macros primarily due to include file ordering */ /* plus, they are very simple */ -#define sound_count(config) (config)->devicelist.count(SOUND) -#define sound_first(config) (config)->devicelist.first(SOUND) -#define sound_next(previous) (previous)->typenext() - -/* these functions are macros primarily due to include file ordering */ -/* plus, they are very simple */ -#define speaker_output_count(config) (config)->devicelist.count(SPEAKER_OUTPUT) -#define speaker_output_first(config) (config)->devicelist.first(SPEAKER_OUTPUT) +#define speaker_output_count(config) (config)->devicelist.count(SPEAKER) +#define speaker_output_first(config) (config)->devicelist.first(SPEAKER) #define speaker_output_next(previous) (previous)->typenext() @@ -50,86 +35,110 @@ TYPE DEFINITIONS ***************************************************************************/ -/* sound type is just a device type */ -typedef device_type sound_type; - +// ======================> speaker_device_config -/* Sound route for the machine driver */ -typedef struct _sound_route sound_route; -struct _sound_route +class speaker_device_config : public device_config { - sound_route * next; /* pointer to next route */ - UINT32 output; /* output index, or ALL_OUTPUTS */ - const char * target; /* target tag */ - UINT32 input; /* target input index */ - float gain; /* gain */ + friend class speaker_device; + + // construction/destruction + speaker_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 "Speaker"; } + + // indexes to inline data + enum + { + INLINE_X, + INLINE_Y, + INLINE_Z + }; + +protected: + // device_config overrides + virtual void device_config_complete(); + + // internal state + double m_x; + double m_y; + double m_z; }; -/* Sound configuration for the machine driver */ -typedef struct _sound_config sound_config; -struct _sound_config -{ - sound_type type; /* type of sound chip */ - sound_route * routelist; /* list of sound routes */ -}; +// ======================> speaker_device -/* Speaker configuration for the machine driver */ -typedef struct _speaker_config speaker_config; -struct _speaker_config +class speaker_device : public device_t { - float x, y, z; /* positioning vector */ + friend class speaker_device_config; + friend resource_pool_object::~resource_pool_object(); + + // construction/destruction + speaker_device(running_machine &_machine, const speaker_device_config &config); + virtual ~speaker_device(); + +public: + // input properties + int inputs() const { return m_inputs; } + float input_gain(int index = 0) const { return m_input[index].m_gain; } + float input_default_gain(int index = 0) const { return m_input[index].m_default_gain; } + const char *input_name(int index = 0) const { return m_input[index].m_name; } + void set_input_gain(int index, float gain); + + // internally for use by the sound system + void mix(INT32 *leftmix, INT32 *rightmix, int &samples_this_update, bool suppress); + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_post_load(); + + // internal helpers + static STREAM_UPDATE( static_mixer_update ) { downcast(device)->mixer_update(inputs, outputs, samples); } + void mixer_update(stream_sample_t **inputs, stream_sample_t **outputs, int samples); + + // a single input + struct speaker_input + { + float m_gain; // current gain + float m_default_gain; // default gain + astring m_name; // name of this input + }; + + // internal state + const speaker_device_config &m_config; + sound_stream * m_mixer_stream; // mixing stream + int m_inputs; // number of input streams + speaker_input * m_input; // array of input information +#ifdef MAME_DEBUG + INT32 m_max_sample; // largest sample value we've seen + INT32 m_clipped_samples; // total number of clipped samples + INT32 m_total_samples; // total number of samples +#endif }; +// device type definition +const device_type SPEAKER = speaker_device_config::static_alloc_device_config; + + /*************************************************************************** SOUND DEVICE CONFIGURATION MACROS ***************************************************************************/ -#define MDRV_SOUND_ADD(_tag, _type, _clock) \ - MDRV_DEVICE_ADD(_tag, SOUND, _clock) \ - MDRV_DEVICE_CONFIG_DATAPTR(sound_config, type, SOUND_##_type) - -#define MDRV_SOUND_MODIFY(_tag) \ - MDRV_DEVICE_MODIFY(_tag) - -#define MDRV_SOUND_TYPE(_type) \ - MDRV_DEVICE_CONFIG_DATAPTR(sound_config, type, SOUND_##_type) - -#define MDRV_SOUND_CLOCK(_clock) \ - MDRV_DEVICE_CLOCK(_clock) - -#define MDRV_SOUND_REPLACE(_tag, _type, _clock) \ - MDRV_DEVICE_MODIFY(_tag) \ - MDRV_DEVICE_CONFIG_CLEAR() \ - MDRV_DEVICE_CONFIG_DATAPTR(sound_config, type, SOUND_##_type) \ - MDRV_DEVICE_CLOCK(_clock) \ - MDRV_SOUND_ROUTES_RESET() - -#define MDRV_SOUND_CONFIG(_config) \ - MDRV_DEVICE_CONFIG(_config) - - -/* sound routine is too complex for standard decoding, so we use a custom config */ -#define MDRV_SOUND_ROUTE_EX(_output, _target, _gain, _input) \ - TOKEN_UINT64_PACK4(MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_1, 8, _output, 12, _input, 12, ((float)(_gain) * (float)(1 << 24)), 32), \ - TOKEN_PTR(stringptr, _target), - -#define MDRV_SOUND_ROUTE(_output, _target, _gain) \ - MDRV_SOUND_ROUTE_EX(_output, _target, _gain, 0) - -#define MDRV_SOUND_ROUTES_RESET() \ - TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_FREE, 8), - - /* add/remove speakers */ #define MDRV_SPEAKER_ADD(_tag, _x, _y, _z) \ - MDRV_DEVICE_ADD(_tag, SPEAKER_OUTPUT, 0) \ - MDRV_DEVICE_CONFIG_DATAFP32(speaker_config, x, _x, 24) \ - MDRV_DEVICE_CONFIG_DATAFP32(speaker_config, y, _y, 24) \ - MDRV_DEVICE_CONFIG_DATAFP32(speaker_config, z, _z, 24) + MDRV_DEVICE_ADD(_tag, SPEAKER, 0) \ + MDRV_DEVICE_INLINE_DATA32(speaker_device_config::INLINE_X, (_x) * (double)(1 << 24)) \ + MDRV_DEVICE_INLINE_DATA32(speaker_device_config::INLINE_Y, (_y) * (double)(1 << 24)) \ + MDRV_DEVICE_INLINE_DATA32(speaker_device_config::INLINE_Z, (_z) * (double)(1 << 24)) #define MDRV_SPEAKER_STANDARD_MONO(_tag) \ MDRV_SPEAKER_ADD(_tag, 0.0, 0.0, 1.0) @@ -151,12 +160,6 @@ void sound_init(running_machine *machine); /* ----- sound device interface ----- */ -/* device get info callback */ -#define SOUND DEVICE_GET_INFO_NAME(sound) -DEVICE_GET_INFO( sound ); - - - /* global sound controls */ void sound_mute(running_machine *machine, int mute); void sound_set_attenuation(running_machine *machine, int attenuation); @@ -172,35 +175,77 @@ const char *sound_get_user_gain_name(running_machine *machine, int index); /* driver gain controls on chip outputs */ -void sound_set_output_gain(running_device *device, int output, float gain); +void sound_set_output_gain(device_t *device, int output, float gain); -/* ----- sound speaker device interface ----- */ -/* device get info callback */ -#define SPEAKER_OUTPUT DEVICE_GET_INFO_NAME(speaker_output) -DEVICE_GET_INFO( speaker_output ); +//************************************************************************** +// INLINE HELPERS +//************************************************************************** +//------------------------------------------------- +// speaker_count - return the number of speaker +// devices in a machine_config +//------------------------------------------------- +inline int speaker_count(const machine_config &config) +{ + return config.devicelist.count(SPEAKER); +} + + +//------------------------------------------------- +// speaker_first - return the first speaker +// device config in a machine_config +//------------------------------------------------- + +inline const speaker_device_config *speaker_first(const machine_config &config) +{ + return downcast(config.devicelist.first(SPEAKER)); +} -/*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ -/*------------------------------------------------- - sound_get_type - return the type of the - specified sound chip --------------------------------------------------*/ +//------------------------------------------------- +// speaker_next - return the next speaker +// device config in a machine_config +//------------------------------------------------- -INLINE sound_type sound_get_type(const device_config *devconfig) +inline const speaker_device_config *speaker_next(const speaker_device_config *previous) { - const sound_config *config = (const sound_config *)devconfig->inline_config; - return config->type; + return downcast(previous->typenext()); } -INLINE sound_type sound_get_type(running_device *device) + +//------------------------------------------------- +// speaker_count - return the number of speaker +// devices in a machine +//------------------------------------------------- + +inline int speaker_count(running_machine &machine) +{ + return machine.devicelist.count(SPEAKER); +} + + +//------------------------------------------------- +// speaker_first - return the first speaker +// device in a machine +//------------------------------------------------- + +inline speaker_device *speaker_first(running_machine &machine) +{ + return downcast(machine.devicelist.first(SPEAKER)); +} + + +//------------------------------------------------- +// speaker_next - return the next speaker +// device in a machine +//------------------------------------------------- + +inline speaker_device *speaker_next(speaker_device *previous) { - return sound_get_type(&device->baseconfig()); + return downcast(previous->typenext()); } -- cgit v1.2.3-70-g09d2