mirror of
https://github.com/holub/mame
synced 2025-10-05 08:41:31 +03:00
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.
This commit is contained in:
parent
815f894a62
commit
ae27a1935b
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user