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 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 m_maincpu; @@ -28,6 +30,7 @@ public: required_device m_k007420; required_device m_upd7759; required_device m_gfxdecode; + required_ioport_array<4> m_trackball; /* memory pointers */ required_memory_bank m_rombank;