summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2018-04-30 23:32:41 +1000
committer Vas Crabb <vas@vastheman.com>2018-04-30 23:32:41 +1000
commitb60c852f119db04564731fa86d73e0a986771258 (patch)
treef3f48148a13484a407b7054c78239258708c5a18 /src/emu
parent89b356a0f5d874f2cabe2e0a96ccfb611b735109 (diff)
Set finder tag relative to current device being configured rather than
the finder's owner. This meand you no longer need to care about the your relationship to the object being configured and a lot of ^ and : can disappear. There's a bit reduction in string pasting in macros from this. Yes, I have to make this apply to devcb etc. as well, but that's a job for another day. There's probably at least one thing broken by this where optional objects are involved. Most things can be solved by just getting rid of the now-problematic ^ and : prefixes.
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/devfind.cpp25
-rw-r--r--src/emu/devfind.h32
-rw-r--r--src/emu/divideo.cpp54
-rw-r--r--src/emu/divideo.h8
-rw-r--r--src/emu/emupal.h2
-rw-r--r--src/emu/mconfig.h3
-rw-r--r--src/emu/tilemap.h2
7 files changed, 83 insertions, 43 deletions
diff --git a/src/emu/devfind.cpp b/src/emu/devfind.cpp
index 81071fa891c..ba2d024a7ca 100644
--- a/src/emu/devfind.cpp
+++ b/src/emu/devfind.cpp
@@ -116,14 +116,25 @@ finder_base::~finder_base()
//-------------------------------------------------
+// set_tag - set tag
+//-------------------------------------------------
+
+void finder_base::set_tag(char const *tag)
+{
+ m_base = m_base.get().mconfig().current_device();
+ m_tag = tag;
+}
+
+
+//-------------------------------------------------
// find_memregion - find memory region
//-------------------------------------------------
void *finder_base::find_memregion(u8 width, size_t &length, bool required) const
{
// look up the region and return nullptr if not found
- memory_region *const region = m_base.memregion(m_tag);
- if (region == nullptr)
+ memory_region *const region(m_base.get().memregion(m_tag));
+ if (!region)
{
length = 0;
return nullptr;
@@ -162,10 +173,10 @@ bool finder_base::validate_memregion(size_t bytes, bool required) const
{
// make sure we can resolve the full path to the region
size_t bytes_found = 0;
- std::string region_fulltag = m_base.subtag(m_tag);
+ std::string const region_fulltag(m_base.get().subtag(m_tag));
// look for the region
- for (device_t const &dev : device_iterator(m_base.mconfig().root_device()))
+ for (device_t const &dev : device_iterator(m_base.get().mconfig().root_device()))
{
for (romload::region const &region : romload::entries(dev.rom_region()).get_regions())
{
@@ -197,8 +208,8 @@ bool finder_base::validate_memregion(size_t bytes, bool required) const
void *finder_base::find_memshare(u8 width, size_t &bytes, bool required) const
{
// look up the share and return nullptr if not found
- memory_share *share = m_base.memshare(m_tag);
- if (share == nullptr)
+ memory_share *const share(m_base.get().memshare(m_tag));
+ if (!share)
return nullptr;
// check the width and warn if not correct
@@ -233,7 +244,7 @@ bool finder_base::report_missing(bool found, const char *objname, bool required)
return true;
// otherwise, report
- std::string const region_fulltag = m_base.subtag(m_tag);
+ std::string const region_fulltag(m_base.get().subtag(m_tag));
if (required)
osd_printf_error("Required %s '%s' not found\n", objname, region_fulltag.c_str());
else
diff --git a/src/emu/devfind.h b/src/emu/devfind.h
index 2ba7303239d..90e7e4f3dba 100644
--- a/src/emu/devfind.h
+++ b/src/emu/devfind.h
@@ -17,6 +17,7 @@
#pragma once
+#include <functional>
#include <iterator>
#include <stdexcept>
#include <type_traits>
@@ -259,10 +260,27 @@ public:
/// Allows search tag to be changed after construction. Note that
/// this must be done before resolution time to take effect. Also
/// note that the tag is not copied.
+ /// \param [in] base Updated search base. The tag must be specified
+ /// relative to this device.
/// \param [in] tag Updated search tag. This is not copied, it is
/// the caller's responsibility to ensure this pointer remains
/// valid until resolution time.
- void set_tag(char const *tag) { m_tag = tag; }
+ void set_tag(device_t &base, char const *tag)
+ {
+ m_base = base;
+ m_tag = tag;
+ }
+
+ /// \brief Set search tag
+ ///
+ /// Allows search tag to be changed after construction. Note that
+ /// this must be done before resolution time to take effect. Also
+ /// note that the tag is not copied.
+ /// \param [in] tag Updated search tag relative to the current
+ /// device being configured. This is not copied, it is the
+ /// caller's responsibility to ensure this pointer remains valid
+ /// until resolution time.
+ void set_tag(char const *tag);
/// \brief Is the object to be resolved before memory maps?
///
@@ -375,7 +393,7 @@ protected:
finder_base *const m_next;
/// \brief Base device to search from
- device_t &m_base;
+ std::reference_wrapper<device_t> m_base;
/// \brief Object tag to search for
char const *m_tag;
@@ -494,7 +512,7 @@ private:
/// is found, false otherwise.
virtual bool findit(bool isvalidation) override
{
- device_t *const device = this->m_base.subdevice(this->m_tag);
+ device_t *const device = this->m_base.get().subdevice(this->m_tag);
this->m_target = dynamic_cast<DeviceClass *>(device);
if (device && !this->m_target)
this->printf_warning("Device '%s' found but is of incorrect type (actual type is %s)\n", this->m_tag, device->name());
@@ -560,7 +578,7 @@ private:
virtual bool findit(bool isvalidation) override
{
if (isvalidation) return this->validate_memregion(0, Required);
- this->m_target = this->m_base.memregion(this->m_tag);
+ this->m_target = this->m_base.get().memregion(this->m_tag);
return this->report_missing("memory region");
}
};
@@ -620,7 +638,7 @@ public:
virtual bool findit(bool isvalidation) override
{
if (isvalidation) return true;
- this->m_target = this->m_base.membank(this->m_tag);
+ this->m_target = this->m_base.get().membank(this->m_tag);
return this->report_missing("memory bank");
}
};
@@ -691,7 +709,7 @@ private:
virtual bool findit(bool isvalidation) override
{
if (isvalidation) return true;
- this->m_target = this->m_base.ioport(this->m_tag);
+ this->m_target = this->m_base.get().ioport(this->m_tag);
return this->report_missing("I/O port");
}
};
@@ -863,7 +881,7 @@ public:
m_allocated.resize(entries);
this->m_target = &m_allocated[0];
m_bytes = entries * sizeof(PointerType);
- this->m_base.save_item(m_allocated, this->m_tag);
+ this->m_base.get().save_item(m_allocated, this->m_tag);
}
private:
diff --git a/src/emu/divideo.cpp b/src/emu/divideo.cpp
index 6a06aa3e857..66cbd6105e9 100644
--- a/src/emu/divideo.cpp
+++ b/src/emu/divideo.cpp
@@ -25,10 +25,11 @@ const char device_video_interface::s_unconfigured_screen_tag[] = "!!UNCONFIGURED
//-------------------------------------------------
device_video_interface::device_video_interface(const machine_config &mconfig, device_t &device, bool screen_required)
- : device_interface(device, "video"),
- m_screen_required(screen_required),
- m_screen_tag(s_unconfigured_screen_tag),
- m_screen(nullptr)
+ : device_interface(device, "video")
+ , m_screen_required(screen_required)
+ , m_screen_base(&device)
+ , m_screen_tag(s_unconfigured_screen_tag)
+ , m_screen(nullptr)
{
}
@@ -42,6 +43,13 @@ device_video_interface::~device_video_interface()
}
+void device_video_interface::set_screen(const char *tag)
+{
+ m_screen_base = &device().mconfig().current_device();
+ m_screen_tag = tag;
+}
+
+
//-------------------------------------------------
// interface_validity_check - validation for a
// device after the configuration has been
@@ -52,19 +60,18 @@ void device_video_interface::interface_validity_check(validity_checker &valid) c
{
// only look up screens if we haven't explicitly requested no screen
screen_device *screen = nullptr;
- if (m_screen_tag != nullptr)
+ if (m_screen_tag)
{
- // find the screen device if explicitly configured
if (strcmp(m_screen_tag, s_unconfigured_screen_tag) != 0)
{
- screen = device().siblingdevice<screen_device>(m_screen_tag);
- if (screen == nullptr)
+ // find the screen device if explicitly configured
+ screen = m_screen_base->subdevice<screen_device>(m_screen_tag);
+ if (!screen)
osd_printf_error("Screen '%s' not found, explicitly set for device '%s'\n", m_screen_tag, device().tag());
}
-
- // otherwise, look for a single match
else
{
+ // otherwise, look for a single match
screen_device_iterator iter(device().mconfig().root_device());
screen = iter.first();
if (iter.count() > 1)
@@ -73,7 +80,7 @@ void device_video_interface::interface_validity_check(validity_checker &valid) c
}
// error if no screen is found
- if (screen == nullptr && m_screen_required)
+ if (!screen && m_screen_required)
osd_printf_error("Device '%s' requires a screen\n", device().tag());
}
@@ -86,19 +93,18 @@ void device_video_interface::interface_validity_check(validity_checker &valid) c
void device_video_interface::interface_pre_start()
{
// only look up screens if we haven't explicitly requested no screen
- if (m_screen_tag != nullptr)
+ if (m_screen_tag)
{
- // find the screen device if explicitly configured
if (strcmp(m_screen_tag, s_unconfigured_screen_tag) != 0)
{
- m_screen = device().siblingdevice<screen_device>(m_screen_tag);
- if (m_screen == nullptr)
+ // find the screen device if explicitly configured
+ m_screen = m_screen_base->subdevice<screen_device>(m_screen_tag);
+ if (!m_screen)
throw emu_fatalerror("Screen '%s' not found, explicitly set for device '%s'", m_screen_tag, device().tag());
}
-
- // otherwise, look for a single match
else
{
+ // otherwise, look for a single match
screen_device_iterator iter(device().machine().root_device());
m_screen = iter.first();
if (iter.count() > 1)
@@ -107,21 +113,19 @@ void device_video_interface::interface_pre_start()
}
// fatal error if no screen is found
- if (m_screen == nullptr && m_screen_required)
+ if (!m_screen)
throw emu_fatalerror("Device '%s' requires a screen", device().tag());
// if we have a screen and it's not started, wait for it
device_palette_interface *palintf;
- if (m_screen != nullptr && !m_screen->started())
+ if (m_screen && !m_screen->started())
{
// avoid circular dependency if we are also a palette device
if (!device().interface(palintf))
throw device_missing_dependencies();
- else
- {
- // no other palette may be specified
- if (m_screen->has_palette() && palintf != &m_screen->palette())
- throw emu_fatalerror("Device '%s' cannot control screen '%s' with palette '%s'", device().tag(), m_screen_tag, m_screen->palette().device().tag());
- }
+
+ // no other palette may be specified
+ if (m_screen->has_palette() && palintf != &m_screen->palette())
+ throw emu_fatalerror("Device '%s' cannot control screen '%s' with palette '%s'", device().tag(), m_screen_tag, m_screen->palette().device().tag());
}
}
diff --git a/src/emu/divideo.h b/src/emu/divideo.h
index 5e2c5d1798d..87425f09a9a 100644
--- a/src/emu/divideo.h
+++ b/src/emu/divideo.h
@@ -43,7 +43,12 @@ public:
virtual ~device_video_interface();
// configuration
- void set_screen(const char *tag) { m_screen_tag = tag; }
+ void set_screen(const char *tag);
+ void set_screen(device_t &base, const char *tag)
+ {
+ m_screen_base = &base;
+ m_screen_tag = tag;
+ }
// getters
screen_device &screen() const { return *m_screen; }
@@ -57,6 +62,7 @@ protected:
private:
// configuration state
bool m_screen_required; // is a screen required?
+ device_t * m_screen_base; // base device for resolving target screen
const char * m_screen_tag; // configured tag for the target screen
// internal state
diff --git a/src/emu/emupal.h b/src/emu/emupal.h
index 467cbc2c818..c16960537f0 100644
--- a/src/emu/emupal.h
+++ b/src/emu/emupal.h
@@ -273,7 +273,7 @@
// other standard palettes
#define MCFG_PALETTE_ADD_RRRRGGGGBBBB_PROMS(_tag, _region, _entries) \
MCFG_PALETTE_ADD(_tag, _entries) \
- downcast<palette_device &>(*device).set_prom_region("^" _region); \
+ downcast<palette_device &>(*device).set_prom_region(_region); \
downcast<palette_device &>(*device).set_init(palette_init_delegate(FUNC(palette_device::palette_init_RRRRGGGGBBBB_proms), downcast<palette_device *>(device)));
// not implemented yet
diff --git a/src/emu/mconfig.h b/src/emu/mconfig.h
index 317acc91309..86902c4b525 100644
--- a/src/emu/mconfig.h
+++ b/src/emu/mconfig.h
@@ -82,7 +82,8 @@ public:
// getters
const game_driver &gamedrv() const { return m_gamedrv; }
- device_t &root_device() const { assert(m_root_device != nullptr); return *m_root_device; }
+ device_t &root_device() const { assert(m_root_device); return *m_root_device; }
+ device_t &current_device() const { assert(m_current_device); return *m_current_device; }
emu_options &options() const { return m_options; }
inline device_t *device(const char *tag) const { return root_device().subdevice(tag); }
template <class DeviceClass> inline DeviceClass *device(const char *tag) const { return downcast<DeviceClass *>(device(tag)); }
diff --git a/src/emu/tilemap.h b/src/emu/tilemap.h
index ae62cdc873b..c37cdd66be0 100644
--- a/src/emu/tilemap.h
+++ b/src/emu/tilemap.h
@@ -370,7 +370,7 @@ enum tilemap_standard_mapper
#define MCFG_TILEMAP_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, TILEMAP, 0)
#define MCFG_TILEMAP_GFXDECODE(_gfxtag) \
- downcast<tilemap_device &>(*device).set_gfxdecode_tag("^" _gfxtag);
+ downcast<tilemap_device &>(*device).set_gfxdecode_tag(_gfxtag);
#define MCFG_TILEMAP_BYTES_PER_ENTRY(_bpe) \
downcast<tilemap_device &>(*device).set_bytes_per_entry(_bpe);
#define MCFG_TILEMAP_INFO_CB_DRIVER(_class, _method) \