diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2010-06-16 13:22:10 +0000 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2010-06-16 13:22:10 +0000 |
commit | 488fbb0f0f96a1cfcf2c206144b6cf6bc87d33e7 (patch) | |
tree | 6e37d0a18c7a1e5bc787c4c28ec8c4a7e978680d /src/emu | |
parent | 16e4f383facef9b7d8d1c0c5e1bd6f8f92ec1935 (diff) |
emuopts - added support for image devices parameters [Miodrag Milanovic]
Diffstat (limited to 'src/emu')
-rw-r--r-- | src/emu/emuopts.c | 90 | ||||
-rw-r--r-- | src/emu/emuopts.h | 15 |
2 files changed, 105 insertions, 0 deletions
diff --git a/src/emu/emuopts.c b/src/emu/emuopts.c index 363913f27e1..d68c1d25215 100644 --- a/src/emu/emuopts.c +++ b/src/emu/emuopts.c @@ -159,6 +159,8 @@ const options_entry mame_core_options[] = { "cheat;c", "0", OPTION_BOOLEAN, "enable cheat subsystem" }, { "skip_gameinfo", "0", OPTION_BOOLEAN, "skip displaying the information screen at startup" }, + /* image device options */ + { OPTION_ADDED_DEVICE_OPTIONS, "0", OPTION_BOOLEAN | OPTION_INTERNAL, "image device-specific options have been added" }, { NULL } }; @@ -199,7 +201,92 @@ static void mame_puts_error(const char *s) { mame_printf_error("%s", s); } + +/*------------------------------------------------- + image_get_device_option - accesses a device + option +-------------------------------------------------*/ + +const char *image_get_device_option(device_t *image) +{ + const char *result = NULL; + + if (options_get_bool(mame_options(), OPTION_ADDED_DEVICE_OPTIONS)) + { + /* access the option */ + result = options_get_string(mame_options(), downcast<const legacy_image_device_config_base *>(&image->baseconfig())->instance_name()); + } + return result; +} + +/*------------------------------------------------- + image_add_device_options - add all of the device + options for a specified device +-------------------------------------------------*/ +void image_add_device_options(core_options *opts, const game_driver *driver) +{ + int index = 0; + machine_config *config; + const device_config_image_interface *image; + + /* create the configuration */ + config = machine_config_alloc(driver->machine_config); + + /* enumerate our callback for every device */ + /* loop on each device instance */ + for (bool gotone = config->devicelist.first(image); gotone; gotone = image->next(image)) + { + options_entry entry[2]; + astring dev_full_name; + + /* first device? add the header as to be pretty */ + if (index == 0) + { + memset(entry, 0, sizeof(entry)); + entry[0].description = "IMAGE DEVICES"; + entry[0].flags = OPTION_HEADER; + options_add_entries(opts, entry); + } + + /* retrieve info about the device instance */ + dev_full_name.printf("%s;%s", image->instance_name(), image->brief_instance_name()); + + /* add the option */ + memset(entry, 0, sizeof(entry)); + entry[0].name = dev_full_name; + options_add_entries(opts, entry); + + index++; + } + + /* record that we've added device options */ + options_set_bool(opts, OPTION_ADDED_DEVICE_OPTIONS, TRUE, OPTION_PRIORITY_CMDLINE); + + /* free the configuration */ + machine_config_free(config); +} + +/*------------------------------------------------- + image_driver_name_callback - called when we + parse the driver name, so we can add options + specific to that driver +-------------------------------------------------*/ + +static void image_driver_name_callback(core_options *opts, const char *arg) +{ + const game_driver *driver; + + /* only add these options if we have not yet added them */ + if (!options_get_bool(opts, OPTION_ADDED_DEVICE_OPTIONS)) + { + driver = driver_get_name(arg); + if (driver != NULL) + { + image_add_device_options(opts, driver); + } + } +} /*------------------------------------------------- @@ -220,6 +307,9 @@ core_options *mame_options_init(const options_entry *entries) if (entries != NULL) options_add_entries(opts, entries); + /* we need to dynamically add options when the device name is parsed */ + options_set_option_callback(opts, OPTION_GAMENAME, image_driver_name_callback); + #ifdef MESS mess_options_init(opts); #endif /* MESS */ diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h index 9738b579006..b2cb0373447 100644 --- a/src/emu/emuopts.h +++ b/src/emu/emuopts.h @@ -153,6 +153,8 @@ #define OPTION_CHEAT "cheat" #define OPTION_SKIP_GAMEINFO "skip_gameinfo" +/* image device options */ +#define OPTION_ADDED_DEVICE_OPTIONS "added_device_options" /*************************************************************************** @@ -164,9 +166,22 @@ extern const options_entry mame_core_options[]; /*************************************************************************** + TYPE DEFINITIONS +***************************************************************************/ + +/* referenced types from other classes */ +struct game_driver; + + +/*************************************************************************** FUNCTION PROTOTYPES ***************************************************************************/ core_options *mame_options_init(const options_entry *entries); +/* add the device options for a specified device */ +void image_add_device_options(core_options *opts, const game_driver *driver); +/* accesses a device option, by device and index */ +const char *image_get_device_option(device_t *image); + #endif /* __EMUOPTS_H__ */ |