mirror of
https://github.com/holub/mame
synced 2025-05-28 16:43:04 +03:00
natkeyboard: fix issue with dynamic buffer resizing
This commit is contained in:
parent
976f36a5f9
commit
6d9f657e95
@ -34,7 +34,7 @@
|
||||
// CONSTANTS
|
||||
//**************************************************************************
|
||||
|
||||
const int KEY_BUFFER_SIZE = 4096;
|
||||
const u32 KEY_BUFFER_CHUNK_SIZE = 0x1000;
|
||||
const char32_t INVALID_CHAR = '?';
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ const char32_t INVALID_CHAR = '?';
|
||||
struct char_info
|
||||
{
|
||||
char32_t ch;
|
||||
const char *alternate; // alternative string, in UTF-8
|
||||
const char *alternate; // alternative string, in UTF-8
|
||||
|
||||
static const char_info *find(char32_t target);
|
||||
};
|
||||
@ -344,7 +344,7 @@ natural_keyboard::natural_keyboard(running_machine &machine)
|
||||
build_codes();
|
||||
if (!m_keyboards.empty())
|
||||
{
|
||||
m_buffer.resize(KEY_BUFFER_SIZE);
|
||||
m_buffer.resize(KEY_BUFFER_CHUNK_SIZE);
|
||||
m_timer = machine.scheduler().timer_alloc(timer_expired_delegate(FUNC(natural_keyboard::timer), this));
|
||||
}
|
||||
|
||||
@ -460,15 +460,9 @@ void natural_keyboard::post(std::u32string_view text, const attotime &rate)
|
||||
// set the fixed rate
|
||||
m_current_rate = rate;
|
||||
|
||||
// iterate over characters or until the buffer is full up
|
||||
// iterate over characters
|
||||
for (char32_t ch : text)
|
||||
{
|
||||
if (full())
|
||||
break;
|
||||
|
||||
// fetch next character
|
||||
post_char(ch, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -832,10 +826,14 @@ void natural_keyboard::internal_post(char32_t ch)
|
||||
}
|
||||
|
||||
// add to the buffer, resizing if necessary
|
||||
m_buffer[m_bufend++] = ch;
|
||||
m_buffer[m_bufend] = ch;
|
||||
if ((m_bufend + 1) % m_buffer.size() == m_bufbegin)
|
||||
m_buffer.resize(m_buffer.size() + KEY_BUFFER_SIZE);
|
||||
m_bufend %= m_buffer.size();
|
||||
{
|
||||
m_buffer.insert(m_buffer.begin() + m_bufbegin, KEY_BUFFER_CHUNK_SIZE, INVALID_CHAR);
|
||||
m_bufbegin += KEY_BUFFER_CHUNK_SIZE;
|
||||
}
|
||||
|
||||
m_bufend = (m_bufend + 1) % m_buffer.size();
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,7 +45,6 @@ public:
|
||||
// getters and queries
|
||||
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_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; }
|
||||
|
@ -208,7 +208,6 @@ void lua_engine::initialize_input(sol::table &emu)
|
||||
natkeyboard_type["paste"] = &natural_keyboard::paste;
|
||||
natkeyboard_type["dump"] = static_cast<std::string (natural_keyboard::*)() const>(&natural_keyboard::dump);
|
||||
natkeyboard_type["empty"] = sol::property(&natural_keyboard::empty);
|
||||
natkeyboard_type["full"] = sol::property(&natural_keyboard::full);
|
||||
natkeyboard_type["can_post"] = sol::property(&natural_keyboard::can_post);
|
||||
natkeyboard_type["is_posting"] = sol::property(&natural_keyboard::is_posting);
|
||||
natkeyboard_type["in_use"] = sol::property(&natural_keyboard::in_use, &natural_keyboard::set_in_use);
|
||||
|
@ -232,10 +232,10 @@ INPUT_PORTS_START(msxjp)
|
||||
PORT_MODIFY("KEY2")
|
||||
PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR(':') PORT_CHAR('*')
|
||||
PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH) PORT_CHAR(']') PORT_CHAR('}')
|
||||
PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("_") PORT_CODE(KEYCODE_TILDE) PORT_CHAR('_')
|
||||
PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("_") PORT_CODE(KEYCODE_TILDE) PORT_CHAR() PORT_CHAR('_')
|
||||
|
||||
PORT_MODIFY("KEY6")
|
||||
PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("KANA") PORT_CODE(KEYCODE_PGDN) PORT_CHAR(UCHAR_MAMEKEY(F7))
|
||||
PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("KANA") PORT_CODE(KEYCODE_PGDN) PORT_CHAR(UCHAR_MAMEKEY(F7))
|
||||
INPUT_PORTS_END
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user