fixed keyboard buffer error

This commit is contained in:
Julian Hinxlage 2020-01-07 11:40:47 +01:00
parent 50b24b5644
commit 90948c9edb
4 changed files with 12 additions and 21 deletions

View File

@ -21,7 +21,7 @@ namespace vkvm {
setForegroundColor(white);
setRedrawInterval(500);
setTimerInterruptInterval(1000);
setFont(FontType::FuturisticBlack);
setFont(FontType::ProFontIIX);
}
impl.localMemoryWarn = true;
}
@ -96,10 +96,7 @@ namespace vkvm {
auto buttonPressed(KeyCode keyCode) -> void {
lockSharedMemory();
auto reg = getRegisters();
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode;
if (reg->keyboardBuffer_index_write >= keyboardBufferSize) {
reg->keyboardBuffer_index_write = 0;
}
reg->keyboardBuffer[(reg->keyboardBuffer_index_write) % keyboardBufferSize] = keyCode;
unlockSharedMemory();
}

View File

@ -319,21 +319,15 @@ namespace vkvm {
lockSharedMemory();
auto keyCode = KeyCode(0);
auto reg = getRegisters();
if (reg->keyboardBuffer_index_read != reg->keyboardBuffer_index_write) {
auto code = reg->keyboardBuffer[reg->keyboardBuffer_index_read++];
keyCode = KeyCode(code);
if (reg->keyboardBuffer_index_read >= keyboardBufferSize) {
reg->keyboardBuffer_index_read = 0;
}
}else{
if(reg->keyboardBuffer_index_read == 0){
auto code = reg->keyboardBuffer[keyboardBufferSize - 1];
if(reg->keyboardBuffer_index_read >= reg->keyboardBuffer_index_write) {
auto code = reg->keyboardBuffer[(reg->keyboardBuffer_index_read) % keyboardBufferSize];
keyCode = KeyCode(code);
}else{
auto code = reg->keyboardBuffer[reg->keyboardBuffer_index_read - 1];
auto code = reg->keyboardBuffer[(reg->keyboardBuffer_index_read) % keyboardBufferSize];
keyCode = KeyCode(code);
}
}
unlockSharedMemory();
return keyCode;
}

View File

@ -12,8 +12,8 @@ TEST_CASE("Keyboard Buffer") {
}
SECTION("read") {
CHECK(vkvm::getLastPressedKey() == vkvm::A);
CHECK(vkvm::getLastPressedKey() == vkvm::B);
CHECK(vkvm::getLastPressedKey() == vkvm::C);
CHECK(vkvm::getLastPressedKey() == vkvm::C);
CHECK(vkvm::getLastPressedKey() == vkvm::C);
}
}

View File

@ -17,7 +17,7 @@ TEST_CASE("Default values") {
REQUIRE(vkvm::getForegroundColor() == vkvm::white);
REQUIRE(vkvm::getRedrawInterval() == 500);
REQUIRE(vkvm::getTimerInterruptInterval() == 1000);
REQUIRE(vkvm::getFont() == vkvm::FuturisticBlack);
REQUIRE(vkvm::getFont() == vkvm::ProFontIIX);
}
SECTION("change") {
@ -63,7 +63,7 @@ TEST_CASE("Default values") {
REQUIRE(vkvm::getForegroundColor() == vkvm::white);
REQUIRE(vkvm::getRedrawInterval() == 500);
REQUIRE(vkvm::getTimerInterruptInterval() == 1000);
REQUIRE(vkvm::getFont() == vkvm::FuturisticBlack);
REQUIRE(vkvm::getFont() == vkvm::ProFontIIX);
}