From d3eecba525738c97e7172317ef5dfd7350b64361 Mon Sep 17 00:00:00 2001 From: AJR Date: Sat, 30 Jan 2016 22:49:08 -0500 Subject: [PATCH] Software list entries can now supply slot option defaults This feature is enabled when executing 'mame driver software'. After the specified software is found in the software list and attached to an appropriate image device, the software part's feature list is examined for any feature whose name is that of a slot device with _default appended. The feature's value field becomes the slot's default option, which overrides any driver-specified default and can be overridden by user-specified options. No software lists have been updated to use this feature at the moment. --- src/emu/clifront.cpp | 2 +- src/emu/emuopts.cpp | 59 ++++++++++++++++++++++++------------------ src/emu/emuopts.h | 11 +++++--- src/emu/ui/slotopt.cpp | 2 +- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/emu/clifront.cpp b/src/emu/clifront.cpp index 05b0ace6116..50e8464a14c 100644 --- a/src/emu/clifront.cpp +++ b/src/emu/clifront.cpp @@ -148,7 +148,7 @@ int cli_frontend::execute(int argc, char **argv) strprintf(val, "%s:%s:%s", swlistdev->list_name(), m_options.software_name(), swpart->name()); // call this in order to set slot devices according to mounting - m_options.parse_slot_devices(argc, argv, option_errors, image->instance_name(), val.c_str()); + m_options.parse_slot_devices(argc, argv, option_errors, image->instance_name(), val.c_str(), swpart); break; } } diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp index aa1b0482edc..725f002aa00 100644 --- a/src/emu/emuopts.cpp +++ b/src/emu/emuopts.cpp @@ -11,6 +11,7 @@ #include "emu.h" #include "emuopts.h" #include "drivenum.h" +#include "softlist.h" #include @@ -205,6 +206,8 @@ emu_options::emu_options() , m_joystick_contradictory(false) , m_sleep(true) , m_refresh_speed(false) +, m_slot_options(0) +, m_device_options(0) { add_entries(emu_options::s_option_entries); } @@ -215,18 +218,17 @@ emu_options::emu_options() // options for the configured system //------------------------------------------------- -bool emu_options::add_slot_options(bool isfirstpass) +bool emu_options::add_slot_options(const software_part *swpart) { // look up the system configured by name; if no match, do nothing const game_driver *cursystem = system(); if (cursystem == nullptr) return false; + + // create the configuration machine_config config(*cursystem, *this); // iterate through all slot devices - bool first = true; - - // create the configuration int starting_count = options_count(); slot_interface_iterator iter(config.root_device()); for (const device_slot_interface *slot = iter.first(); slot != nullptr; slot = iter.next()) @@ -236,9 +238,8 @@ bool emu_options::add_slot_options(bool isfirstpass) continue; // first device? add the header as to be pretty - if (isfirstpass && first) + if (m_slot_options++ == 0) add_entry(nullptr, "SLOT DEVICES", OPTION_HEADER | OPTION_FLAG_DEVICE); - first = false; // retrieve info about the device instance const char *name = slot->device().tag() + 1; @@ -255,6 +256,15 @@ bool emu_options::add_slot_options(bool isfirstpass) } add_entry(name, nullptr, flags, defvalue, true); } + + // allow software lists to supply their own defaults + if (swpart != nullptr) + { + std::string featurename = std::string(name).append("_default"); + const char *value = swpart->feature(featurename.c_str()); + if (value != nullptr) + set_default_value(name, value); + } } return (options_count() != starting_count); } @@ -265,7 +275,7 @@ bool emu_options::add_slot_options(bool isfirstpass) // depending of image mounted //------------------------------------------------- -void emu_options::update_slot_options() +void emu_options::update_slot_options(const software_part *swpart) { // look up the system configured by name; if no match, do nothing const game_driver *cursystem = system(); @@ -290,8 +300,8 @@ void emu_options::update_slot_options() } } } - while (add_slot_options(false)) { } - add_device_options(false); + while (add_slot_options(swpart)) { } + add_device_options(); } @@ -300,7 +310,7 @@ void emu_options::update_slot_options() // options for the configured system //------------------------------------------------- -void emu_options::add_device_options(bool isfirstpass) +void emu_options::add_device_options() { // look up the system configured by name; if no match, do nothing const game_driver *cursystem = system(); @@ -309,14 +319,12 @@ void emu_options::add_device_options(bool isfirstpass) machine_config config(*cursystem, *this); // iterate through all image devices - bool first = true; image_interface_iterator iter(config.root_device()); for (const device_image_interface *image = iter.first(); image != nullptr; image = iter.next()) { // first device? add the header as to be pretty - if (first && isfirstpass) + if (m_device_options++ == 0) add_entry(nullptr, "IMAGE DEVICES", OPTION_HEADER | OPTION_FLAG_DEVICE); - first = false; // retrieve info about the device instance std::string option_name; @@ -348,6 +356,10 @@ void emu_options::remove_device_options() if ((curentry->flags() & OPTION_FLAG_DEVICE) != 0) remove_entry(*curentry); } + + // reset counters + m_slot_options = 0; + m_device_options = 0; } @@ -356,7 +368,7 @@ void emu_options::remove_device_options() // and update slot and image devices //------------------------------------------------- -bool emu_options::parse_slot_devices(int argc, char *argv[], std::string &error_string, const char *name, const char *value) +bool emu_options::parse_slot_devices(int argc, char *argv[], std::string &error_string, const char *name, const char *value, const software_part *swpart) { // an initial parse to capture the initial set of values bool result; @@ -364,15 +376,13 @@ bool emu_options::parse_slot_devices(int argc, char *argv[], std::string &error_ core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); // keep adding slot options until we stop seeing new stuff - bool isfirstpass = true; - while (add_slot_options(isfirstpass)) - { + m_slot_options = 0; + while (add_slot_options(swpart)) core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); - isfirstpass = false; - } // add device options and reparse - add_device_options(true); + m_device_options = 0; + add_device_options(); if (name != nullptr && exists(name)) set_value(name, value, OPTION_PRIORITY_CMDLINE, error_string); core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); @@ -380,7 +390,7 @@ bool emu_options::parse_slot_devices(int argc, char *argv[], std::string &error_ int num; do { num = options_count(); - update_slot_options(); + update_slot_options(swpart); result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); } while (num != options_count()); @@ -399,7 +409,7 @@ bool emu_options::parse_command_line(int argc, char *argv[], std::string &error_ { // parse as normal core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string); - bool result = parse_slot_devices(argc, argv, error_string, nullptr, nullptr); + bool result = parse_slot_devices(argc, argv, error_string); update_cached_options(); return result; } @@ -523,11 +533,10 @@ void emu_options::set_system_name(const char *name) // remove any existing device options and then add them afresh remove_device_options(); - if (add_slot_options(true)) - while (add_slot_options(false)) { } + while (add_slot_options()) { } // then add the options - add_device_options(true); + add_device_options(); int num; do { num = options_count(); diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h index 14597d0e67d..ea279ca3982 100644 --- a/src/emu/emuopts.h +++ b/src/emu/emuopts.h @@ -197,6 +197,7 @@ enum // forward references struct game_driver; +class software_part; class emu_options : public core_options @@ -210,7 +211,7 @@ public: // parsing wrappers bool parse_command_line(int argc, char *argv[], std::string &error_string); void parse_standard_inis(std::string &error_string); - bool parse_slot_devices(int argc, char *argv[], std::string &error_string, const char *name, const char *value); + bool parse_slot_devices(int argc, char *argv[], std::string &error_string, const char *name = nullptr, const char *value = nullptr, const software_part *swpart = nullptr); // core options const char *system_name() const { return value(OPTION_SYSTEMNAME); } @@ -370,12 +371,12 @@ public: std::string main_value(const char *option) const; std::string sub_value(const char *name, const char *subname) const; - bool add_slot_options(bool isfirst); + bool add_slot_options(const software_part *swpart = nullptr); private: // device-specific option handling - void add_device_options(bool isfirst); - void update_slot_options(); + void add_device_options(); + void update_slot_options(const software_part *swpart = nullptr); // INI parsing helper bool parse_one_ini(const char *basename, int priority, std::string *error_string = nullptr); @@ -390,6 +391,8 @@ private: bool m_joystick_contradictory; bool m_sleep; bool m_refresh_speed; + int m_slot_options; + int m_device_options; }; diff --git a/src/emu/ui/slotopt.cpp b/src/emu/ui/slotopt.cpp index a3b6352ac2b..959fef74adc 100644 --- a/src/emu/ui/slotopt.cpp +++ b/src/emu/ui/slotopt.cpp @@ -189,7 +189,7 @@ void ui_menu_slot_devices::handle() { if ((FPTR)menu_event->itemref == 1 && menu_event->iptkey == IPT_UI_SELECT) { - machine().options().add_slot_options(false); + machine().options().add_slot_options(); machine().schedule_hard_reset(); } else if (menu_event->iptkey == IPT_UI_LEFT || menu_event->iptkey == IPT_UI_RIGHT)