From 8ff84bc0c9c402a459a48935433fcfa96cc50b48 Mon Sep 17 00:00:00 2001 From: Frank Palazzolo Date: Wed, 6 May 2020 11:28:42 -0400 Subject: [PATCH] Fix for UI Paste with the Default Serial Terminal (#6648) * This fixes the ability for one to use UI Paste with the Default Serial Terminal. Without this fix, 8 characters @^&()\:" cannot be pasted from the UI. --- src/devices/bus/amiga/keyboard/matrix.cpp | 1 - src/emu/natkeyboard.cpp | 68 +++++++++++++---------- src/emu/natkeyboard.h | 4 +- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/devices/bus/amiga/keyboard/matrix.cpp b/src/devices/bus/amiga/keyboard/matrix.cpp index 6ff33666fcb..fa588052cd7 100644 --- a/src/devices/bus/amiga/keyboard/matrix.cpp +++ b/src/devices/bus/amiga/keyboard/matrix.cpp @@ -661,7 +661,6 @@ INPUT_PORTS_START(matrix_dk) INPUT_PORTS_END INPUT_PORTS_START(matrix_ch) - // FIXME: natural keyboard doesn't play nicely with PORT_CONDITION, but it's an issue with natural keyboard itself PORT_INCLUDE(matrix_common) PORT_START("CFG") diff --git a/src/emu/natkeyboard.cpp b/src/emu/natkeyboard.cpp index 29c05730c2f..ce7391c67cd 100644 --- a/src/emu/natkeyboard.cpp +++ b/src/emu/natkeyboard.cpp @@ -644,32 +644,33 @@ void natural_keyboard::build_codes(ioport_manager &manager) { if (((code < UCHAR_SHIFT_BEGIN) || (code > UCHAR_SHIFT_END)) && (code != 0)) { - // prefer lowest shift state keycode_map::iterator const found(m_keycode_map.find(code)); - if ((m_keycode_map.end() == found) || (found->second.shift > curshift)) + keycode_map_entry newcode; + std::fill(std::begin(newcode.field), std::end(newcode.field), nullptr); + newcode.shift = curshift; + newcode.condition = field.condition(); + + unsigned fieldnum = 0; + for (unsigned i = 0, bits = curshift; (i < SHIFT_COUNT) && bits; ++i, bits >>= 1) { - keycode_map_entry newcode; - std::fill(std::begin(newcode.field), std::end(newcode.field), nullptr); - newcode.shift = curshift; + if (BIT(bits, 0)) + newcode.field[fieldnum++] = shift[i]; + } - unsigned fieldnum = 0; - for (unsigned i = 0, bits = curshift; (i < SHIFT_COUNT) && bits; ++i, bits >>= 1) - { - if (BIT(bits, 0)) - newcode.field[fieldnum++] = shift[i]; - } + newcode.field[fieldnum] = &field; + if (m_keycode_map.end() == found) + { + keycode_map_list map_list; + map_list.emplace_back(newcode); + m_keycode_map.emplace(code, map_list); + } + else + found->second.emplace_back(newcode); - newcode.field[fieldnum] = &field; - if (m_keycode_map.end() == found) - m_keycode_map.emplace(code, newcode); - else - found->second = newcode; - - if (LOG_NATURAL_KEYBOARD) - { - machine().logerror("natural_keyboard: code=%u (%s) port=%p field.name='%s'\n", - code, unicode_to_string(code), (void *)&port, field.name()); - } + if (LOG_NATURAL_KEYBOARD) + { + machine().logerror("natural_keyboard: code=%u (%s) port=%p field.name='%s'\n", + code, unicode_to_string(code), (void *)&port, field.name()); } } } @@ -879,7 +880,13 @@ std::string natural_keyboard::unicode_to_string(char32_t ch) const const natural_keyboard::keycode_map_entry *natural_keyboard::find_code(char32_t ch) const { keycode_map::const_iterator const found(m_keycode_map.find(ch)); - return (m_keycode_map.end() != found) ? &found->second : nullptr; + if (m_keycode_map.end() == found) return nullptr; + for(const keycode_map_entry &entry : found->second) + { + if (entry.condition.eval()) + return &entry; + } + return nullptr; } @@ -901,13 +908,16 @@ void natural_keyboard::dump(std::ostream &str) const // pad with spaces util::stream_format(str, "%-*s", left_column_width, description); - // identify the keys used - for (std::size_t field = 0; (code.second.field.size() > field) && code.second.field[field]; ++field) - util::stream_format(str, "%s'%s'", first ? "" : ", ", code.second.field[field]->name()); + for (auto &entry : code.second) + { + // identify the keys used + for (std::size_t field = 0; (entry.field.size() > field) && entry.field[field]; ++field) + util::stream_format(str, "%s'%s'", first ? "" : ", ", entry.field[field]->name()); - // carriage return - str << '\n'; - first = false; + // carriage return + str << '\n'; + first = false; + } } } diff --git a/src/emu/natkeyboard.h b/src/emu/natkeyboard.h index 23abd9ac437..d99e0cdf009 100644 --- a/src/emu/natkeyboard.h +++ b/src/emu/natkeyboard.h @@ -74,8 +74,10 @@ private: { std::array field; unsigned shift; + ioport_condition condition; }; - typedef std::unordered_map keycode_map; + typedef std::list keycode_map_list; + typedef std::unordered_map keycode_map; // internal helpers void build_codes(ioport_manager &manager);