Keyboard processing optimization.

This commit is contained in:
andreili 2024-10-02 22:40:33 +02:00
parent 08a7f5e3f2
commit 15cff12e04
2 changed files with 35 additions and 20 deletions

View File

@ -66,6 +66,10 @@ SIM_TOP::SIM_TOP(int argc, const char** argv, thread_cb_t cb_to_draw, thread_cb_
m_rom2_size = 0;
m_rom_disk_size = 0;
p_thr = new std::thread(&SIM_TOP::thread_main, this);
for (int i=0 ; i<20 ; ++i)
{
m_keys_matrix[i] = 0;
}
// TODO
p_cfg_sw->bt = 0b00001011;
@ -134,12 +138,34 @@ void SIM_TOP::load_rom_disk(std::string fn)
void SIM_TOP::key_press(uint32_t key)
{
m_key_pressed.insert(key);
for (int j=0 ; j<11 ; ++j)
{
uint32_t line = 0;
for (int i=0 ; i<8 ; ++i)
{
if (key_matrix[i][j] == key)
{
line |= (1 << i);
}
}
m_keys_matrix[j] = line;
}
}
void SIM_TOP::key_release(uint32_t key)
{
m_key_pressed.erase(key);
for (int j=0 ; j<11 ; ++j)
{
uint32_t line = 0;
for (int i=0 ; i<8 ; ++i)
{
if (key_matrix[i][j] == key)
{
line |= (1 << i);
}
}
m_keys_matrix[j] &= ~line;
}
}
void SIM_TOP::thread_main()
@ -349,28 +375,18 @@ void SIM_TOP::screen_proc()
void SIM_TOP::kbd_proc()
{
uint32_t scancode_msk = ((p_kbd_output->bt.PC & 0x7) << 8) | p_kbd_output->bt.PB;
static uint32_t scancode_prev;
if (scancode_msk == scancode_prev)
if (scancode_msk != 0b11111111111)
{
return;
}
uint32_t result = 0xff;
uint32_t result = 0;
for (int j=0 ; j<11 ; ++j)
{
if ((scancode_msk & (1 << j)) == 0)
if (((scancode_msk & (1 << j)) == 0) && (m_keys_matrix[j] != 0))
{
for (int i=0 ; i<8 ; ++i)
{
int key = key_matrix[i][j];
if (m_key_pressed.count(key) != 0)
{
result &= ~(1 << i);
result |= m_keys_matrix[j];
}
}
p_kbd_input->bt.PA = ~result;
}
}
p_kbd_input->bt.PA = result;
scancode_prev = scancode_msk;
}
void SIM_TOP::rom_proc()

View File

@ -2,7 +2,6 @@
#include <thread>
#include <functional>
#include <mutex>
#include <set>
typedef union
{
@ -106,7 +105,7 @@ private:
thread_cb_t m_cb_resize;
SIM_STATE m_state;
std::mutex m_mtx;
std::set<uint32_t> m_key_pressed;
uint32_t m_keys_matrix[20];
uint8_t* p_rom1;
uint32_t* p_rom1_raddr;