diff options
author | 2020-10-11 02:58:46 +1100 | |
---|---|---|
committer | 2020-10-11 02:58:46 +1100 | |
commit | c751a5348a89f2cd9d6b84938551e341ec7f8450 (patch) | |
tree | 6de05430e61f273376943b79ee61a5b83de3552d /src/emu/natkeyboard.h | |
parent | 9e971ab36e2752d554239f9eb92397f87679deb5 (diff) |
-emu/natkeyboard.cpp: Allow keyboard devices to be enabled/disabled.
This fixes the "typing on all keyboards at once" issue. You can now
enable and disable keyboard/keypad inputs per device in the Keyboard
Mode menu. Default is to enable the first device with keyboard inputs,
and all device with keypad inputs but no keyboard inputs. The settings
are saved in the CFG file for the machine.
Typing in natural keyboard mode only ever types on one keyboard at a
time, but now you can control which keyboard it types on, as it will be
the first enabled keyboard.
You can easily try this out with something like:
mame64d zorba -rs232 terminal cpm
-ui/inputmap.cpp: Show device descriptions as well as tag paths.
-mac128.cpp: Fixed mouse axis wrap compensation, cleaned up mouse code,
eliminated static variables for mouse input state.
You could see the issue with wrap detection easily enough just by
running mac128k/mac512k/macplus and tapping the arrow keys to move the
mouse one pixel at a time. As you moved past the point where the axis
count wrapped, it would move one pixel in the opposite direction.
There were two function static variables related to mouse input state,
probably still lurking from when the code was initially made to use a
driver state class. This obviously messes with save states and prevents
multiple instances.
- bus/a2bus/mouse.cpp: Fixed mouse axis wrap compensation.
This device had the same bug with wrap compensation as mac128k.cpp.
Diffstat (limited to 'src/emu/natkeyboard.h')
-rw-r--r-- | src/emu/natkeyboard.h | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/src/emu/natkeyboard.h b/src/emu/natkeyboard.h index d411eb74173..e324205a088 100644 --- a/src/emu/natkeyboard.h +++ b/src/emu/natkeyboard.h @@ -1,5 +1,5 @@ // license:BSD-3-Clause -// copyright-holders:Aaron Giles +// copyright-holders:Aaron Giles,Vas Crabb /*************************************************************************** natkeyboard.h @@ -12,8 +12,12 @@ #pragma once +#include <array> +#include <functional> #include <iosfwd> +#include <string> #include <unordered_map> +#include <vector> //************************************************************************** @@ -21,9 +25,9 @@ //************************************************************************** // keyboard helper function delegates -typedef delegate<int (const char32_t *, size_t)> ioport_queue_chars_delegate; -typedef delegate<bool (char32_t)> ioport_accept_char_delegate; -typedef delegate<bool ()> ioport_charqueue_empty_delegate; +using ioport_queue_chars_delegate = delegate<int (const char32_t *, size_t)>; +using ioport_accept_char_delegate = delegate<bool (char32_t)>; +using ioport_charqueue_empty_delegate = delegate<bool ()>; // ======================> natural_keyboard @@ -41,13 +45,18 @@ public: running_machine &machine() const { return m_machine; } bool empty() const { return (m_bufbegin == m_bufend); } bool full() const { return ((m_bufend + 1) % m_buffer.size()) == m_bufbegin; } - bool can_post() const { return (!m_queue_chars.isnull() || !m_keycode_map.empty()); } + bool can_post() const { return m_have_charkeys || !m_queue_chars.isnull(); } bool is_posting() const { return (!empty() || (!m_charqueue_empty.isnull() && !m_charqueue_empty())); } bool in_use() const { return m_in_use; } // configuration void configure(ioport_queue_chars_delegate queue_chars, ioport_accept_char_delegate accept_char, ioport_charqueue_empty_delegate charqueue_empty); void set_in_use(bool usage); + size_t keyboard_count() const { return m_keyboards.size(); } + device_t &keyboard_device(size_t n) { return m_keyboards[n].device; } + bool keyboard_enabled(size_t n) { return m_keyboards[n].enabled; } + void enable_keyboard(size_t n) { set_keyboard_enabled(n, true); } + void disable_keyboard(size_t n) { set_keyboard_enabled(n, false); } // posting void post_char(char32_t ch, bool normalize_crlf = false); @@ -74,13 +83,27 @@ private: { std::array<ioport_field *, SHIFT_COUNT + 1> field; unsigned shift; - ioport_condition condition; + ioport_condition condition; }; typedef std::vector<keycode_map_entry> keycode_map_entries; typedef std::unordered_map<char32_t, keycode_map_entries> keycode_map; + // per-device character-to-key mapping + struct kbd_dev_info + { + kbd_dev_info(device_t &dev) : device(dev) { } + + std::reference_wrapper<device_t> device; + std::vector<std::reference_wrapper<ioport_field> > keyfields; + keycode_map codemap; + bool keyboard = false; + bool keypad = false; + bool enabled = false; + }; + // internal helpers - void build_codes(ioport_manager &manager); + void build_codes(); + void set_keyboard_enabled(size_t n, bool enable); bool can_post_directly(char32_t ch); bool can_post_alternate(char32_t ch); attotime choose_delay(char32_t ch); @@ -90,11 +113,14 @@ private: const keycode_map_entry *find_code(char32_t ch) const; // internal state + std::vector<kbd_dev_info> m_keyboards; // info on keyboard devices in system running_machine & m_machine; // reference to our machine + bool m_have_charkeys; // are there keys with character? bool m_in_use; // is natural keyboard in use? u32 m_bufbegin; // index of starting character u32 m_bufend; // index of ending character std::vector<char32_t> m_buffer; // actual buffer + keycode_map_entry const * m_current_code; // current code being typed unsigned m_fieldnum; // current step in multi-key sequence bool m_status_keydown; // current keydown status bool m_last_cr; // was the last char a CR? @@ -103,7 +129,6 @@ private: ioport_queue_chars_delegate m_queue_chars; // queue characters callback ioport_accept_char_delegate m_accept_char; // accept character callback ioport_charqueue_empty_delegate m_charqueue_empty; // character queue empty callback - keycode_map m_keycode_map; // keycode map }; |