summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/natkeyboard.cpp
diff options
context:
space:
mode:
author hap <happppp@users.noreply.github.com>2025-04-22 02:56:58 +0200
committer hap <happppp@users.noreply.github.com>2025-04-22 03:00:14 +0200
commit6d9f657e95147024f2eee57b0b076f77c98d9c3a (patch)
tree80f326705a05c99859986145dcdd81637e0794bc /src/emu/natkeyboard.cpp
parent976f36a5f9e057cc185c61d60f4574fb9d14326a (diff)
natkeyboard: fix issue with dynamic buffer resizing
Diffstat (limited to 'src/emu/natkeyboard.cpp')
-rw-r--r--src/emu/natkeyboard.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/emu/natkeyboard.cpp b/src/emu/natkeyboard.cpp
index d250f4c3b82..4933de13b38 100644
--- a/src/emu/natkeyboard.cpp
+++ b/src/emu/natkeyboard.cpp
@@ -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();
}