summaryrefslogtreecommitdiffstatshomepage
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
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.
-rw-r--r--src/emu/devfind.h42
-rw-r--r--src/mame/drivers/bladestl.c9
-rw-r--r--src/mame/includes/bladestl.h3
3 files changed, 49 insertions, 5 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
diff --git a/src/mame/drivers/bladestl.c b/src/mame/drivers/bladestl.c
index e76508ecbc3..dc9612a007d 100644
--- a/src/mame/drivers/bladestl.c
+++ b/src/mame/drivers/bladestl.c
@@ -50,14 +50,13 @@ TIMER_DEVICE_CALLBACK_MEMBER(bladestl_state::bladestl_scanline)
* Memory handlers
*
*************************************/
+const char * const bladestl_state::trackball_tags[] =
+ { "TRACKBALL_P1_1", "TRACKBALL_P1_2", "TRACKBALL_P2_1", "TRACKBALL_P2_2" };
READ8_MEMBER(bladestl_state::trackball_r)
{
- static const char *const port[] = { "TRACKBALL_P1_1", "TRACKBALL_P1_2", "TRACKBALL_P2_1", "TRACKBALL_P2_2" };
- int curr, delta;
-
- curr = ioport(port[offset])->read();
- delta = (curr - m_last_track[offset]) & 0xff;
+ int curr = m_trackball[offset]->read();
+ int delta = (curr - m_last_track[offset]) & 0xff;
m_last_track[offset] = curr;
return (delta & 0x80) | (curr >> 1);
diff --git a/src/mame/includes/bladestl.h b/src/mame/includes/bladestl.h
index e54a210b1e4..8d29c6bb57e 100644
--- a/src/mame/includes/bladestl.h
+++ b/src/mame/includes/bladestl.h
@@ -10,6 +10,7 @@
class bladestl_state : public driver_device
{
+ static const char * const trackball_tags[];
public:
bladestl_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag),
@@ -20,6 +21,7 @@ public:
m_k007420(*this, "k007420"),
m_upd7759(*this, "upd"),
m_gfxdecode(*this, "gfxdecode"),
+ m_trackball(*this, trackball_tags),
m_rombank(*this, "rombank") { }
required_device<cpu_device> m_maincpu;
@@ -28,6 +30,7 @@ public:
required_device<k007420_device> m_k007420;
required_device<upd7759_device> m_upd7759;
required_device<gfxdecode_device> m_gfxdecode;
+ required_ioport_array<4> m_trackball;
/* memory pointers */
required_memory_bank m_rombank;