summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
author npwoods <npwoods@alumni.carnegiemellon.edu>2017-04-15 16:32:12 -0400
committer Olivier Galibert <galibert@pobox.com>2017-04-15 22:32:12 +0200
commit02ea4fd43cb42ffdbba6f87a93c03b697c426269 (patch)
treef04a48f239f0686fe711fbda5dc7e69a97d2b281 /src/emu
parentc4b2aa746602b5896400bef928cf76c5d5c72e83 (diff)
Fixes issues specifying image/slot options fron INI files (reported by Robbbert) (#2231)
This fix really doesn't go far enough. I added hooks so that options specified at the command line can also be responded to when parsed from INI files, but in the long run much of the logic that is currently in mame_options should go into emu_options so that when an option is specified, all of the wacko logic around slot/image specification "just works" because it is encapsulated within emu_options. We have a release 11 days away; I want to be in stabilization mode.
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/emuopts.cpp73
-rw-r--r--src/emu/emuopts.h16
2 files changed, 86 insertions, 3 deletions
diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp
index b78c64cf598..00065030373 100644
--- a/src/emu/emuopts.cpp
+++ b/src/emu/emuopts.cpp
@@ -2,7 +2,7 @@
// copyright-holders:Aaron Giles
/***************************************************************************
- emuopts.c
+ emuopts.cpp
Options file and command line management.
@@ -11,6 +11,7 @@
#include "emu.h"
#include "emuopts.h"
+
//**************************************************************************
// CORE EMULATOR OPTIONS
//**************************************************************************
@@ -263,3 +264,73 @@ void emu_options::value_changed(const std::string &name, const std::string &valu
m_ui = UI_CABINET;
}
}
+
+
+//-------------------------------------------------
+// override_get_value - when saving to an INI, we
+// need to hook into that process so we can write
+// out image/slot options
+//-------------------------------------------------
+
+bool emu_options::override_get_value(const char *name, std::string &value) const
+{
+ auto slotiter = m_slot_options.find(name);
+ if (slotiter != m_slot_options.end() && slotiter->second.is_selectable())
+ {
+ value = slotiter->second.value();
+ return true;
+ }
+
+ auto imageiter = m_image_options.find(name);
+ if (imageiter != m_image_options.end())
+ {
+ value = imageiter->second;
+ return true;
+ }
+
+ return false;
+}
+
+
+//-------------------------------------------------
+// override_set_value - when parsing an INI, we
+// need to hook into into it so we can do the same
+// crazy slot logic done in mameopt
+//-------------------------------------------------
+
+bool emu_options::override_set_value(const char *name, const std::string &value)
+{
+ auto slotiter = m_slot_options.find(name);
+ if (slotiter != m_slot_options.end())
+ {
+ slotiter->second = parse_slot_option(std::string(value), true);
+ return true;
+ }
+
+ auto imageiter = m_image_options.find(name);
+ if (imageiter != m_image_options.end())
+ {
+ imageiter->second = value;
+ return true;
+ }
+
+ return false;
+}
+
+
+//-------------------------------------------------
+// parse_slot_option - parses a slot option (the
+// ',bios=XYZ' syntax)
+//-------------------------------------------------
+
+slot_option emu_options::parse_slot_option(std::string &&text, bool selectable)
+{
+ slot_option result;
+ const char *bios_arg = ",bios=";
+
+ size_t pos = text.find(bios_arg);
+ return pos != std::string::npos
+ ? slot_option(text.substr(0, pos), text.substr(pos + strlen(bios_arg)), selectable)
+ : slot_option(std::move(text), "", selectable);
+}
+
diff --git a/src/emu/emuopts.h b/src/emu/emuopts.h
index 31c49210e50..0de3d158ff2 100644
--- a/src/emu/emuopts.h
+++ b/src/emu/emuopts.h
@@ -198,8 +198,13 @@
class slot_option
{
public:
- slot_option(std::string &&value = "", std::string &&bios = "")
- : m_value(std::move(value)), m_bios(std::move(bios))
+ slot_option()
+ : slot_option("", "", true)
+ {
+ }
+
+ slot_option(std::string &&value, std::string &&bios, bool selectable)
+ : m_value(std::move(value)), m_bios(std::move(bios)), m_selectable(selectable)
{
}
slot_option(const slot_option &that) = default;
@@ -219,15 +224,18 @@ public:
const std::string &bios() const { return m_bios; }
const std::string &default_card_software() const { return m_default_card_software; }
bool is_default() const { return m_value.empty(); }
+ bool is_selectable() const { return m_selectable; }
// seters
void set_bios(std::string &&s) { m_bios = std::move(s); }
void set_default_card_software(std::string &&s) { m_default_card_software = std::move(s); }
+ void set_is_selectable(bool selectable) { m_selectable = selectable; }
private:
std::string m_value;
std::string m_bios;
std::string m_default_card_software;
+ bool m_selectable;
};
@@ -427,8 +435,12 @@ public:
std::map<std::string, std::string> &image_options() { return m_image_options; }
const std::map<std::string, std::string> &image_options() const { return m_image_options; }
+ static slot_option parse_slot_option(std::string &&text, bool selectable);
+
protected:
virtual void value_changed(const std::string &name, const std::string &value) override;
+ virtual bool override_get_value(const char *name, std::string &value) const override;
+ virtual bool override_set_value(const char *name, const std::string &value) override;
private:
static const options_entry s_option_entries[];