+ read and write keyboard buffer

This commit is contained in:
Julian Hinxlage 2019-11-26 11:49:19 +01:00
parent 82bab57e98
commit 32b66cf8bf
2 changed files with 12 additions and 3 deletions

View File

@ -74,7 +74,7 @@ namespace vkvm {
auto buttonPressed(KeyCode keyCode) -> void {
lockSharedMemory();
auto reg = getRegisters();
if (reg->keyboardBuffer_index_write == sizeof(reg->keyboardBuffer)) {
if (reg->keyboardBuffer_index_write >= sizeof(reg->keyboardBuffer)) {
reg->keyboardBuffer_index_write = 0;
}
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode;

View File

@ -210,8 +210,17 @@ namespace vkvm {
}
auto getLastPressedKey() -> KeyCode {
//TODO(julian): get key properly
return KeyCode(0);
lockSharedMemory();
auto reg = getRegisters();
if(reg->keyboardBuffer_index_read == reg->keyboardBuffer_index_write){
return KeyCode(0);
}
KeyCode keyCode = (KeyCode)reg->keyboardBuffer[reg->keyboardBuffer_index_read++];
if(reg->keyboardBuffer_index_read >= sizeof(reg->keyboardBuffer)){
reg->keyboardBuffer_index_read = 0;
}
unlockSharedMemory();
return keyCode;
}
}