diff options
author | 2010-06-28 06:40:44 +0000 | |
---|---|---|
committer | 2010-06-28 06:40:44 +0000 | |
commit | 41b9dbb9ace490ee8ab0bd87d35a50e9b693d538 (patch) | |
tree | 945b176affb6ad7958b2016777241736ff6f294d /src/emu/mconfig.c | |
parent | f9a3aaf5c82bae95ba12b517beaf3fe5d4d1a93a (diff) |
Made the machine_config a proper object. Added detokenize method to
this object which can be called multiple times to append new devices
after the initial machine configuration is set up. Updated member
variables to match new naming convention.
Changed the running_machine to take a constructed machine_config
object in the constructor, instead of creating one itself, for
consistency. Also added machine->total_colors() as a shortcut to
machine->config->m_total_colors.
Diffstat (limited to 'src/emu/mconfig.c')
-rw-r--r-- | src/emu/mconfig.c | 223 |
1 files changed, 133 insertions, 90 deletions
diff --git a/src/emu/mconfig.c b/src/emu/mconfig.c index 22a8240faa3..cdae9af9cb3 100644 --- a/src/emu/mconfig.c +++ b/src/emu/mconfig.c @@ -4,8 +4,36 @@ Machine configuration macros and functions. - Copyright Nicola Salmoria and the MAME Team. - Visit http://mamedev.org for licensing and usage restrictions. +**************************************************************************** + + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. ***************************************************************************/ @@ -13,74 +41,65 @@ #include <ctype.h> -/*************************************************************************** - FUNCTION PROTOTYPES -***************************************************************************/ - -static void machine_config_detokenize(machine_config *config, const machine_config_token *tokens, const device_config *owner); - - - -/*************************************************************************** - MACHINE CONFIGURATIONS -***************************************************************************/ - -/*------------------------------------------------- - machine_config_alloc - allocate a new - machine configuration and populate it using - the supplied constructor --------------------------------------------------*/ - -machine_config *machine_config_alloc(const machine_config_token *tokens) +//************************************************************************** +// MACHINE CONFIGURATIONS +//************************************************************************** + +//------------------------------------------------- +// machine_config - constructor +//------------------------------------------------- + +machine_config::machine_config(const machine_config_token *tokens) + : m_driver_data_alloc(NULL), + m_minimum_quantum(attotime_zero), + m_perfect_cpu_quantum(NULL), + m_watchdog_vblank_count(0), + m_watchdog_time(attotime_zero), + m_machine_start(NULL), + m_machine_reset(NULL), + m_nvram_handler(NULL), + m_memcard_handler(NULL), + m_video_attributes(0), + m_gfxdecodeinfo(NULL), + m_total_colors(0), + m_default_layout(NULL), + m_init_palette(NULL), + m_video_start(NULL), + m_video_reset(NULL), + m_video_eof(NULL), + m_video_update(NULL), + m_sound_start(NULL), + m_sound_reset(NULL), + m_parse_level(0) { - machine_config *config; - - /* allocate a new configuration object */ - config = global_alloc_clear(machine_config); - - /* parse tokens into the config */ - machine_config_detokenize(config, tokens, NULL); - - /* process any device-specific machine configurations */ - for (const device_config *device = config->devicelist.first(); device != NULL; device = device->next()) - { - tokens = device->machine_config_tokens(); - if (tokens != NULL) - machine_config_detokenize(config, tokens, device); - } - - // then notify all devices that their configuration is complete - for (device_config *device = config->devicelist.first(); device != NULL; device = device->next()) - device->config_complete(); - - return config; + // parse tokens into the config + detokenize(tokens); } -/*------------------------------------------------- - machine_config_free - release memory allocated - for a machine configuration --------------------------------------------------*/ +//------------------------------------------------- +// ~machine_config - destructor +//------------------------------------------------- -void machine_config_free(machine_config *config) +machine_config::~machine_config() { - /* release the configuration itself */ - global_free(config); } -/*------------------------------------------------- - machine_config_detokenize - detokenize a - machine config --------------------------------------------------*/ +//------------------------------------------------- +// detokenize - detokenize a machine config +//------------------------------------------------- -static void machine_config_detokenize(machine_config *config, const machine_config_token *tokens, const device_config *owner) +void machine_config::detokenize(const machine_config_token *tokens, const device_config *owner) { - UINT32 entrytype = MCONFIG_TOKEN_INVALID; device_config *device = NULL; astring tempstring; + + // increase the parse level + m_parse_level++; - /* loop over tokens until we hit the end */ + // loop over tokens until we hit the end + UINT32 entrytype = MCONFIG_TOKEN_INVALID; while (entrytype != MCONFIG_TOKEN_END) { device_type devtype; @@ -88,26 +107,26 @@ static void machine_config_detokenize(machine_config *config, const machine_conf UINT64 data64; UINT32 clock; - /* unpack the token from the first entry */ + // unpack the token from the first entry TOKEN_GET_UINT32_UNPACK1(tokens, entrytype, 8); switch (entrytype) { - /* end */ + // end case MCONFIG_TOKEN_END: break; - /* including */ + // including case MCONFIG_TOKEN_INCLUDE: - machine_config_detokenize(config, TOKEN_GET_PTR(tokens, tokenptr), owner); + detokenize(TOKEN_GET_PTR(tokens, tokenptr), owner); break; - /* device management */ + // device management case MCONFIG_TOKEN_DEVICE_ADD: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32); devtype = TOKEN_GET_PTR(tokens, devtype); tag = owner->subtag(tempstring, TOKEN_GET_STRING(tokens)); - device = config->devicelist.append(tag, (*devtype)(*config, tag, owner, clock)); + device = m_devicelist.append(tag, (*devtype)(*this, tag, owner, clock)); break; case MCONFIG_TOKEN_DEVICE_REPLACE: @@ -115,18 +134,18 @@ static void machine_config_detokenize(machine_config *config, const machine_conf TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32); devtype = TOKEN_GET_PTR(tokens, devtype); tag = owner->subtag(tempstring, TOKEN_GET_STRING(tokens)); - device = config->devicelist.replace(tag, (*devtype)(*config, tag, owner, clock)); + device = m_devicelist.replace(tag, (*devtype)(*this, tag, owner, clock)); break; case MCONFIG_TOKEN_DEVICE_REMOVE: tag = TOKEN_GET_STRING(tokens); - config->devicelist.remove(owner->subtag(tempstring, tag)); + m_devicelist.remove(owner->subtag(tempstring, tag)); device = NULL; break; case MCONFIG_TOKEN_DEVICE_MODIFY: tag = TOKEN_GET_STRING(tokens); - device = config->devicelist.find(owner->subtag(tempstring, tag)); + device = m_devicelist.find(owner->subtag(tempstring, tag)); if (device == NULL) fatalerror("Unable to find device: tag=%s\n", tempstring.cstr()); break; @@ -164,94 +183,94 @@ static void machine_config_detokenize(machine_config *config, const machine_conf break; - /* core parameters */ + // core parameters case MCONFIG_TOKEN_DRIVER_DATA: - config->driver_data_alloc = TOKEN_GET_PTR(tokens, driver_data_alloc); + m_driver_data_alloc = TOKEN_GET_PTR(tokens, driver_data_alloc); break; case MCONFIG_TOKEN_QUANTUM_TIME: TOKEN_EXTRACT_UINT64(tokens, data64); - config->minimum_quantum = UINT64_ATTOTIME_TO_ATTOTIME(data64); + m_minimum_quantum = UINT64_ATTOTIME_TO_ATTOTIME(data64); break; case MCONFIG_TOKEN_QUANTUM_PERFECT_CPU: - config->perfect_cpu_quantum = TOKEN_GET_STRING(tokens); + m_perfect_cpu_quantum = TOKEN_GET_STRING(tokens); break; case MCONFIG_TOKEN_WATCHDOG_VBLANK: TOKEN_UNGET_UINT32(tokens); - TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, config->watchdog_vblank_count, 24); + TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_watchdog_vblank_count, 24); break; case MCONFIG_TOKEN_WATCHDOG_TIME: TOKEN_EXTRACT_UINT64(tokens, data64); - config->watchdog_time = UINT64_ATTOTIME_TO_ATTOTIME(data64); + m_watchdog_time = UINT64_ATTOTIME_TO_ATTOTIME(data64); break; - /* core functions */ + // core functions case MCONFIG_TOKEN_MACHINE_START: - config->machine_start = TOKEN_GET_PTR(tokens, machine_start); + m_machine_start = TOKEN_GET_PTR(tokens, machine_start); break; case MCONFIG_TOKEN_MACHINE_RESET: - config->machine_reset = TOKEN_GET_PTR(tokens, machine_reset); + m_machine_reset = TOKEN_GET_PTR(tokens, machine_reset); break; case MCONFIG_TOKEN_NVRAM_HANDLER: - config->nvram_handler = TOKEN_GET_PTR(tokens, nvram_handler); + m_nvram_handler = TOKEN_GET_PTR(tokens, nvram_handler); break; case MCONFIG_TOKEN_MEMCARD_HANDLER: - config->memcard_handler = TOKEN_GET_PTR(tokens, memcard_handler); + m_memcard_handler = TOKEN_GET_PTR(tokens, memcard_handler); break; - /* core video parameters */ + // core video parameters case MCONFIG_TOKEN_VIDEO_ATTRIBUTES: TOKEN_UNGET_UINT32(tokens); - TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, config->video_attributes, 24); + TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_video_attributes, 24); break; case MCONFIG_TOKEN_GFXDECODE: - config->gfxdecodeinfo = TOKEN_GET_PTR(tokens, gfxdecode); + m_gfxdecodeinfo = TOKEN_GET_PTR(tokens, gfxdecode); break; case MCONFIG_TOKEN_PALETTE_LENGTH: TOKEN_UNGET_UINT32(tokens); - TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, config->total_colors, 24); + TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_total_colors, 24); break; case MCONFIG_TOKEN_DEFAULT_LAYOUT: - config->default_layout = TOKEN_GET_STRING(tokens); + m_default_layout = TOKEN_GET_STRING(tokens); break; - /* core video functions */ + // core video functions case MCONFIG_TOKEN_PALETTE_INIT: - config->init_palette = TOKEN_GET_PTR(tokens, palette_init); + m_init_palette = TOKEN_GET_PTR(tokens, palette_init); break; case MCONFIG_TOKEN_VIDEO_START: - config->video_start = TOKEN_GET_PTR(tokens, video_start); + m_video_start = TOKEN_GET_PTR(tokens, video_start); break; case MCONFIG_TOKEN_VIDEO_RESET: - config->video_reset = TOKEN_GET_PTR(tokens, video_reset); + m_video_reset = TOKEN_GET_PTR(tokens, video_reset); break; case MCONFIG_TOKEN_VIDEO_EOF: - config->video_eof = TOKEN_GET_PTR(tokens, video_eof); + m_video_eof = TOKEN_GET_PTR(tokens, video_eof); break; case MCONFIG_TOKEN_VIDEO_UPDATE: - config->video_update = TOKEN_GET_PTR(tokens, video_update); + m_video_update = TOKEN_GET_PTR(tokens, video_update); break; - /* core sound functions */ + // core sound functions case MCONFIG_TOKEN_SOUND_START: - config->sound_start = TOKEN_GET_PTR(tokens, sound_start); + m_sound_start = TOKEN_GET_PTR(tokens, sound_start); break; case MCONFIG_TOKEN_SOUND_RESET: - config->sound_reset = TOKEN_GET_PTR(tokens, sound_reset); + m_sound_reset = TOKEN_GET_PTR(tokens, sound_reset); break; default: @@ -259,4 +278,28 @@ static void machine_config_detokenize(machine_config *config, const machine_conf break; } } + + // if we started at parse level 0 (and are thus at level 1), do post-processing + if (m_parse_level == 1) + { + // process any device-specific machine configurations + for (const device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) + if (!devconfig->m_config_complete) + { + tokens = devconfig->machine_config_tokens(); + if (tokens != NULL) + detokenize(tokens, devconfig); + } + + // then notify all devices that their configuration is complete + for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) + if (!devconfig->m_config_complete) + { + devconfig->config_complete(); + devconfig->m_config_complete = true; + } + } + + // bump down the parse level + m_parse_level--; } |