summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/devfind.h
diff options
context:
space:
mode:
author Alex W. Jackson <alex.w.jackson@gmail.com>2014-04-22 08:05:17 +0000
committer Alex W. Jackson <alex.w.jackson@gmail.com>2014-04-22 08:05:17 +0000
commitae27a1935b9b53f31fd341d625c30120e8a9a2b6 (patch)
tree533b2344c9f86dd8d0bcf900e4f4302efb3952c3 /src/emu/devfind.h
parent815f894a625c6d96ca23f014f5ff3ad8821c0a72 (diff)
ioport_array_finder: [Alex Jackson]
Clean build probably needed since this touches a core header file. ioport_array_finder is a new device finder template for finding, unsurprisingly, an array of ioports. It is mainly intended to help handle multiplexed ioports without runtime tagmap lookups in a more elegant way than was previously possible. It is similar in principle to shared_ptr_array_finder; however, rather than passing a single tag that gets automatically decorated with numeric suffixes, you need to pass an array of tags (this is so ioports can continue to have human-meaningful tags rather than the tags being forced by how the hardware multiplexing happens to work). Because C++ doesn't have array literals, and because most driver state class constructors are defined in header files, the semantics are a little different from other device finders (and possibly awkward/suboptimal, this is the best I could think of). You have to declare the array of tags as a static class member and define it somewhere in a source file (defining it near the function that actually reads the multiplexed ports seems like the most logical place to me). Updated bladestl.c to use ioport_array_finder; will wait for Micko to pass judgement on the semantics before updating more drivers.
Diffstat (limited to 'src/emu/devfind.h')
-rw-r--r--src/emu/devfind.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/emu/devfind.h b/src/emu/devfind.h
index 10e99be643d..f095cb13baa 100644
--- a/src/emu/devfind.h
+++ b/src/emu/devfind.h
@@ -240,6 +240,48 @@ public:
};
+// ======================> ioport_array_finder
+
+// ioport array finder template
+template<int _Count, bool _Required>
+class ioport_array_finder
+{
+ typedef ioport_finder<_Required> ioport_finder_type;
+
+public:
+ // construction/destruction
+ ioport_array_finder(device_t &base, const char * const *tags)
+ {
+ for (int index = 0; index < _Count; index++)
+ m_array[index].reset(global_alloc(ioport_finder_type(base, tags[index])));
+ }
+
+ // array accessors
+ const ioport_finder_type &operator[](int index) const { assert(index < _Count); return *m_array[index]; }
+ ioport_finder_type &operator[](int index) { assert(index < _Count); return *m_array[index]; }
+
+protected:
+ // internal state
+ auto_pointer<ioport_finder_type> m_array[_Count];
+};
+
+// optional ioport array finder
+template<int _Count>
+class optional_ioport_array: public ioport_array_finder<_Count, false>
+{
+public:
+ optional_ioport_array(device_t &base, const char * const *tags) : ioport_array_finder<_Count, false>(base, tags) { }
+};
+
+// required ioport array finder
+template<int _Count>
+class required_ioport_array: public ioport_array_finder<_Count, true>
+{
+public:
+ required_ioport_array(device_t &base, const char * const *tags) : ioport_array_finder<_Count, true>(base, tags) { }
+};
+
+
// ======================> shared_ptr_finder
// shared pointer finder template