diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp index 6f751a28dad..4d106912d7b 100644 --- a/src/emu/ioport.cpp +++ b/src/emu/ioport.cpp @@ -634,6 +634,8 @@ ioport_field::ioport_field(ioport_port &port, ioport_type type, ioport_value def if (device().subtag(def->tag) == fulltag && def->mask == m_mask) m_defvalue = def->defvalue & m_mask; } + + m_flags |= FIELD_FLAG_TOGGLE; } } @@ -706,6 +708,24 @@ const input_seq &ioport_field::defseq(input_seq_type seqtype) const } +//------------------------------------------------- +// set_defseq - dynamically alter the default +// input sequence for the given input field +//------------------------------------------------- + +void ioport_field::set_defseq(input_seq_type seqtype, const input_seq &newseq) +{ + const bool was_changed = seq(seqtype) != defseq(seqtype); + + // set the new sequence + m_seq[seqtype] = newseq; + + // also update live state unless previously customized + if (m_live != nullptr && !was_changed) + m_live->seq[seqtype] = newseq; +} + + //------------------------------------------------- // type_class - return the type class for this // field @@ -3112,13 +3132,6 @@ ioport_configurer& ioport_configurer::onoff_alloc(const char *name, ioport_value // allocate a field normally field_alloc(IPT_DIPSWITCH, defval, mask, name); - // special case service mode - if (name == DEF_STR(Service_Mode)) - { - field_set_toggle(); - m_curfield->m_seq[SEQ_TYPE_STANDARD].set(KEYCODE_F2); - } - // expand the diplocation if (diplocation != nullptr) field_set_diplocation(diplocation); diff --git a/src/emu/ioport.h b/src/emu/ioport.h index a9a4d49b0c4..a5169e08c21 100644 --- a/src/emu/ioport.h +++ b/src/emu/ioport.h @@ -1058,6 +1058,8 @@ public: const input_seq &seq(input_seq_type seqtype = SEQ_TYPE_STANDARD) const; const input_seq &defseq(input_seq_type seqtype = SEQ_TYPE_STANDARD) const; const input_seq &defseq_unresolved(input_seq_type seqtype = SEQ_TYPE_STANDARD) const { return m_seq[seqtype]; } + void set_defseq(const input_seq &newseq) { set_defseq(SEQ_TYPE_STANDARD, newseq); } + void set_defseq(input_seq_type seqtype, const input_seq &newseq); bool has_dynamic_read() const { return !m_read.isnull(); } bool has_dynamic_write() const { return !m_write.isnull(); } diff --git a/src/frontend/mame/ui/info.cpp b/src/frontend/mame/ui/info.cpp index 9de81cef6ec..93583ed85df 100644 --- a/src/frontend/mame/ui/info.cpp +++ b/src/frontend/mame/ui/info.cpp @@ -30,6 +30,7 @@ machine_info::machine_info(running_machine &machine) m_has_dips = false; m_has_bioses = false; m_has_keyboard = false; + m_has_test_switch = false; // scan the input port array to see what options we need to enable for (auto &port : machine.ioport().ports()) @@ -43,6 +44,8 @@ machine_info::machine_info(running_machine &machine) m_has_analog = true; if (field.type() == IPT_KEYBOARD) m_has_keyboard = true; + if (field.type() == IPT_SERVICE) + m_has_test_switch = true; } for (device_t &device : device_iterator(machine.root_device())) @@ -51,6 +54,24 @@ machine_info::machine_info(running_machine &machine) } +//------------------------------------------------- +// find_dipname - look up DIP switch by name +//------------------------------------------------- + +ioport_field *machine_info::find_dipname(const char *name) const +{ + if (!m_has_dips) + return nullptr; + + for (auto &port : m_machine.ioport().ports()) + for (ioport_field &field : port.second->fields()) + if (field.type() == IPT_DIPSWITCH && strcmp(field.name(), name) == 0) + return &field; + + return nullptr; +} + + /*************************************************************************** TEXT GENERATORS ***************************************************************************/ diff --git a/src/frontend/mame/ui/info.h b/src/frontend/mame/ui/info.h index 21d920e4131..b31726ba27f 100644 --- a/src/frontend/mame/ui/info.h +++ b/src/frontend/mame/ui/info.h @@ -29,6 +29,9 @@ public: bool has_dips() const { return m_has_dips; } bool has_bioses() const { return m_has_bioses; } bool has_keyboard() const { return m_has_keyboard; } + bool has_test_switch() const { return m_has_test_switch; } + + ioport_field *find_dipname(const char *name) const; // text generators std::string warnings_string(); @@ -46,6 +49,7 @@ private: bool m_has_dips; bool m_has_bioses; bool m_has_keyboard; + bool m_has_test_switch; }; class menu_game_info : public menu diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index d7bf97a6562..a21b1e82cee 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -256,6 +256,13 @@ void mame_ui_manager::initialize(running_machine &machine) { slider_current = nullptr; } + + if (!m_machine_info->has_test_switch()) + { + ioport_field *service_mode_sw = m_machine_info->find_dipname(ioport_configurer::string_from_token(DEF_STR(Service_Mode))); + if (service_mode_sw != nullptr) + service_mode_sw->set_defseq(machine.ioport().type_seq(IPT_SERVICE)); + } }