From ae27a1935b9b53f31fd341d625c30120e8a9a2b6 Mon Sep 17 00:00:00 2001 From: "Alex W. Jackson" Date: Tue, 22 Apr 2014 08:05:17 +0000 Subject: 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. --- src/emu/devfind.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/emu/devfind.h') 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 +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 m_array[_Count]; +}; + +// optional ioport array finder +template +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 +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 -- cgit v1.2.3-70-g09d2