summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/mconfig.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2018-05-04 03:01:32 +1000
committer Vas Crabb <vas@vastheman.com>2018-05-04 03:01:32 +1000
commit32a73f450da82c345b0f694bee311af34a5e717d (patch)
treede6259ee4c0120e992f348afcc9078e16bbe49d4 /src/emu/mconfig.cpp
parentaa96f47092f764f089c2ce9e0f26d756197150e8 (diff)
Make MCFG_DEVICE_ADD and callable device types more flexible:
* Allows defaulted clocks (see subtle example with vboy) * Allows additional constructors (see RS232 port in tranz330) * Allows use of device finder in place of tag in MCFG_DEVICE_ADD * Requires out-of-line destructor for devices using incomplete types * Requires XTAL or explicit u32 for clocks for devices with private types Devices must still define the standard constructor. When writing additional constructors, be aware that the constructor runs before device_add_mconfig in the context of the existing device, not the new device. See osborne1, zorba, tranz330, and vboy for examples of this in use. Compilation is a bit slower, but this is temporary while refactoring is in progress. Eliminated the need for MCFG_SOUND_ROUTE_EX. Removed macros from slot option configuration - they just obfuscated code and slowed it down with needless dynamic casts, but didn't actually simplify it.
Diffstat (limited to 'src/emu/mconfig.cpp')
-rw-r--r--src/emu/mconfig.cpp40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/emu/mconfig.cpp b/src/emu/mconfig.cpp
index eef4a143969..546ce1c885f 100644
--- a/src/emu/mconfig.cpp
+++ b/src/emu/mconfig.cpp
@@ -73,7 +73,8 @@ machine_config::machine_config(const game_driver &gamedrv, emu_options &options)
if (selval && *selval)
{
- device_slot_option const *const option = slot.option(selval);
+ // TODO: make this thing more self-contained so it can apply itself - shouldn't need to know all this here
+ device_slot_interface::slot_option const *option = slot.option(selval);
if (option && (is_default || option->selectable()))
{
// create the device
@@ -115,11 +116,11 @@ machine_config::~machine_config()
//-------------------------------------------------
-// device_add - configuration helper to add a
-// new device
+// resolve_owner - get the actual owner and base
+// tag given tag relative to current context
//-------------------------------------------------
-device_t *machine_config::device_add(const char *tag, device_type type, u32 clock)
+std::pair<const char *, device_t *> machine_config::resolve_owner(const char *tag) const
{
assert(bool(m_current_device) == bool(m_root_device));
char const *const orig_tag = tag;
@@ -145,19 +146,30 @@ device_t *machine_config::device_add(const char *tag, device_type type, u32 cloc
}
assert(tag[0] != '\0');
+ return std::make_pair(tag, owner);
+}
+
+
+//-------------------------------------------------
+// add_device - add a new device at the correct
+// point in the hierarchy
+//-------------------------------------------------
+
+device_t *machine_config::add_device(std::unique_ptr<device_t> &&device, device_t *owner)
+{
current_device_stack context(*this);
if (owner)
{
// allocate the new device and append it to the owner's list
- device_t *const device = &owner->subdevices().m_list.append(*type(*this, tag, owner, clock).release());
- device->add_machine_configuration(*this);
- return device;
+ device_t *const result = &owner->subdevices().m_list.append(*device.release());
+ result->add_machine_configuration(*this);
+ return result;
}
else
{
// allocate the root device directly
assert(!m_root_device);
- m_root_device = type(*this, tag, nullptr, clock);
+ m_root_device = std::move(device);
driver_device *driver = dynamic_cast<driver_device *>(m_root_device.get());
if (driver)
driver->set_game_driver(m_gamedrv);
@@ -168,6 +180,18 @@ device_t *machine_config::device_add(const char *tag, device_type type, u32 cloc
//-------------------------------------------------
+// device_add - configuration helper to add a
+// new device
+//-------------------------------------------------
+
+device_t *machine_config::device_add(const char *tag, device_type type, u32 clock)
+{
+ std::pair<const char *, device_t *> const owner(resolve_owner(tag));
+ return add_device(type(*this, owner.first, owner.second, clock), owner.second);
+}
+
+
+//-------------------------------------------------
// device_replace - configuration helper to
// replace one device with a new device
//-------------------------------------------------