diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp index 5fb28cc4ca6..50b27db4779 100644 --- a/src/emu/ioport.cpp +++ b/src/emu/ioport.cpp @@ -744,7 +744,7 @@ digital_joystick::digital_joystick(int player, int number) digital_joystick::direction_t digital_joystick::add_axis(ioport_field &field) { direction_t direction = direction_t((field.type() - (IPT_DIGITAL_JOYSTICK_FIRST + 1)) % 4); - m_field[direction].append(field); + m_field[direction].append(*global_alloc(simple_list_wrapper(&field))); return direction; } @@ -764,10 +764,10 @@ void digital_joystick::frame_update() // read all the associated ports running_machine *machine = NULL; for (direction_t direction = JOYDIR_UP; direction < JOYDIR_COUNT; ++direction) - for (const ioport_field *i = m_field[direction].first(); i != NULL; i = i->next()) + for (const simple_list_wrapper *i = m_field[direction].first(); i != NULL; i = i->next()) { - machine = &i->machine(); - if (machine->input().seq_pressed(i->seq(SEQ_TYPE_STANDARD))) + machine = &i->object()->machine(); + if (machine->input().seq_pressed(i->object()->seq(SEQ_TYPE_STANDARD))) m_current |= 1 << direction; } diff --git a/src/emu/ioport.h b/src/emu/ioport.h index 908e8a0ef2a..5eeedb9a792 100644 --- a/src/emu/ioport.h +++ b/src/emu/ioport.h @@ -792,7 +792,7 @@ private: digital_joystick * m_next; // next joystick in the list int m_player; // player number represented int m_number; // joystick number represented - simple_list m_field[JOYDIR_COUNT]; // potential input fields for each direction + simple_list > m_field[JOYDIR_COUNT]; // potential input fields for each direction UINT8 m_current; // current value UINT8 m_current4way; // current 4-way value UINT8 m_previous; // previous value diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index f312b078a87..60c4e5f059e 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -277,6 +277,40 @@ private: int m_count; // number of objects in the list }; + +// ======================> simple_list_wrapper + +// a simple_list_wrapper wraps an existing object with a next pointer so it +// can live in a simple_list without requiring the object to have a next +// pointer +template +class simple_list_wrapper +{ +public: + template friend class simple_list; + + // construction/destruction + simple_list_wrapper(_ObjectType *object) + : m_next(NULL), + m_object(object) { } + + // operators + operator _ObjectType *() { return m_object; } + operator _ObjectType *() const { return m_object; } + _ObjectType *operator *() { return m_object; } + _ObjectType *operator *() const { return m_object; } + + // getters + simple_list_wrapper *next() const { return m_next; } + _ObjectType *object() const { return m_object; } + +private: + // internal state + simple_list_wrapper * m_next; + _ObjectType * m_object; +}; + + // ======================> fixed_allocator // a fixed_allocator is a simple class that maintains a free pool of objects