From 128951d856670652a15670279d7aa2ad25bd8a21 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Wed, 4 Dec 2019 12:32:54 +0100 Subject: [PATCH 1/4] ~ fixed keyboard buffer error --- src/internal.cpp | 4 ++-- src/vkvm.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/internal.cpp b/src/internal.cpp index 436c76e..40f6c73 100644 --- a/src/internal.cpp +++ b/src/internal.cpp @@ -74,10 +74,10 @@ namespace vkvm { auto buttonPressed(KeyCode keyCode) -> void { lockSharedMemory(); auto reg = getRegisters(); - if (reg->keyboardBuffer_index_write >= sizeof(reg->keyboardBuffer)) { + reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode; + if (reg->keyboardBuffer_index_write >= keyboardBufferSize) { reg->keyboardBuffer_index_write = 0; } - reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode; unlockSharedMemory(); } diff --git a/src/vkvm.cpp b/src/vkvm.cpp index 6337c99..3d0455d 100644 --- a/src/vkvm.cpp +++ b/src/vkvm.cpp @@ -326,7 +326,7 @@ namespace vkvm { auto reg = getRegisters(); if (reg->keyboardBuffer_index_read != reg->keyboardBuffer_index_write) { keyCode = static_cast(reg->keyboardBuffer[reg->keyboardBuffer_index_read++]); - if (reg->keyboardBuffer_index_read >= sizeof(reg->keyboardBuffer)) { + if (reg->keyboardBuffer_index_read >= keyboardBufferSize) { reg->keyboardBuffer_index_read = 0; } } From 9ced919be41dd8580ca72bef9515256b46e750b7 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Wed, 4 Dec 2019 13:08:21 +0100 Subject: [PATCH 2/4] + calling ControlRegisterUpdated Event ~ fixed setPixel performance --- src/internal.cpp | 4 ++++ src/vkvm.cpp | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/internal.cpp b/src/internal.cpp index 40f6c73..c4dd5ed 100644 --- a/src/internal.cpp +++ b/src/internal.cpp @@ -50,18 +50,21 @@ namespace vkvm { lockSharedMemory(); getRegisters()->layout_version = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto setCharactersPerColumn(int newValue) -> void { lockSharedMemory(); getRegisters()->characters_per_column = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto setCharactersPerRow(int newValue) -> void { lockSharedMemory(); getRegisters()->characters_per_row = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto setMousePosition(int x, int y) -> void { @@ -69,6 +72,7 @@ namespace vkvm { getRegisters()->mouse_pos_x = x; getRegisters()->mouse_pos_y = y; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto buttonPressed(KeyCode keyCode) -> void { diff --git a/src/vkvm.cpp b/src/vkvm.cpp index 3d0455d..331ba6c 100644 --- a/src/vkvm.cpp +++ b/src/vkvm.cpp @@ -18,7 +18,6 @@ namespace vkvm { auto setDefaultValues() -> void { impl.localMemoryWarn = false; if (getSharedMemory() != nullptr) { - //set default values setMode(GraphicMode::RGB); setCharactersPerRow(60); setCharactersPerColumn(20); @@ -67,7 +66,7 @@ namespace vkvm { if (x > getWidth() || y > getHeight()) { return false; } - lockSharedMemory(); + //lockSharedMemory(); auto reg = getRegisters(); const int bitsPerPixel = 8; @@ -111,7 +110,7 @@ namespace vkvm { break; } } - unlockSharedMemory(); + //unlockSharedMemory(); return true; } @@ -164,7 +163,7 @@ namespace vkvm { auto setText(std::string text) -> bool { lockSharedMemory(); char *ptr = getTextArea(); - for (int i = 0; i < text.size(); i++) { + for (int i = 0; i < static_cast(text.size()); i++) { if (i < getCharactersPerColumn() * getCharactersPerRow()) { ptr[i] = text[i]; } @@ -209,6 +208,7 @@ namespace vkvm { lockSharedMemory(); getRegisters()->width_pixels = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto getHeight() -> int { @@ -219,6 +219,7 @@ namespace vkvm { lockSharedMemory(); getRegisters()->height_pixels = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto getMode() -> GraphicMode { @@ -254,6 +255,7 @@ namespace vkvm { reg->graphicMode = newValue; } unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto getRedrawInterval() -> int { @@ -264,6 +266,7 @@ namespace vkvm { lockSharedMemory(); getRegisters()->autoRedrawInterval = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto getTimerInterruptInterval() -> int { @@ -274,6 +277,7 @@ namespace vkvm { lockSharedMemory(); getRegisters()->timerInterruptInterval = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto getBackgroundColor() -> Color { @@ -284,6 +288,7 @@ namespace vkvm { lockSharedMemory(); getRegisters()->background_color = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto getForegroundColor() -> Color { @@ -294,6 +299,7 @@ namespace vkvm { lockSharedMemory(); getRegisters()->foreground_color = newValue; unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto getCharactersPerRow() -> int { @@ -314,6 +320,7 @@ namespace vkvm { lockSharedMemory(); getRegisters()->textMode_font = newValue.getId(); unlockSharedMemory(); + callEvent(EventType::UpdateControlRegisters); } auto getMousePosition() -> Coordinates { From 71bd846c6b42f91bf44443630e904eb2414374e1 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Wed, 4 Dec 2019 13:33:04 +0100 Subject: [PATCH 3/4] + getRegisteredProcesses() --- src/internal.cpp | 12 ++++++++++++ src/internal.hpp | 6 ++++++ src/vkvm.cpp | 3 +++ 3 files changed, 21 insertions(+) diff --git a/src/internal.cpp b/src/internal.cpp index c4dd5ed..e6ff8e8 100644 --- a/src/internal.cpp +++ b/src/internal.cpp @@ -85,4 +85,16 @@ namespace vkvm { unlockSharedMemory(); } + auto getRegisteredProcesses(EventType eventType) -> std::vector { + std::vector result; + auto ivt = getInterruptTable(); + for(int i = 0; i < impl.interruptEntrysPerEventType;i++){ + auto &entry= ivt[eventType * impl.interruptEntrysPerEventType + i]; + if (entry.pid != 0) { + result.push_back(entry.pid); + } + } + return result; + } + } diff --git a/src/internal.hpp b/src/internal.hpp index e1b5ea2..a84676a 100644 --- a/src/internal.hpp +++ b/src/internal.hpp @@ -126,6 +126,12 @@ constexpr int keyboardBufferSize = 16; */ auto buttonPressed(KeyCode keyCode) -> void; +/** + * get registered Prosesses for a given event type. + * @param eventType. + */ + auto getRegisteredProcesses(EventType eventType) -> std::vector; + // Shared Memory Layout // -------------------------------------------------------------------- // struct ControlRegisters diff --git a/src/vkvm.cpp b/src/vkvm.cpp index 331ba6c..d48d36b 100644 --- a/src/vkvm.cpp +++ b/src/vkvm.cpp @@ -63,6 +63,9 @@ namespace vkvm { } auto setPixel(int x, int y, Color color) -> bool { + if(x < 0 || y < 0){ + return false; + } if (x > getWidth() || y > getHeight()) { return false; } From 469ac1479dc4464d87516d1a83de0f1b2b957a6b Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 5 Dec 2019 09:49:54 +0100 Subject: [PATCH 4/4] ~ test if text has been cleared ~ test for negative values for set pixel --- src/vkvm.cpp | 7 ++++++- test/area_test.cpp | 5 +++-- test/event_test.cpp | 22 +++++++++++----------- test/text_test.cpp | 6 +++++- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/vkvm.cpp b/src/vkvm.cpp index d48d36b..9e42e38 100644 --- a/src/vkvm.cpp +++ b/src/vkvm.cpp @@ -118,6 +118,9 @@ namespace vkvm { } auto getPixel(int x, int y) -> Color { + if(x < 0 || y < 0) { + return getBackgroundColor(); + } if (x > getWidth() || y > getHeight()) { return getBackgroundColor(); } @@ -180,7 +183,9 @@ namespace vkvm { } auto getText() -> std::string { - return std::string(getTextArea()); + std::string text = getTextArea(); + + return text.substr(0, getCharactersPerColumn() * getCharactersPerRow()); } auto clearText() -> bool { diff --git a/test/area_test.cpp b/test/area_test.cpp index a91ac75..3306598 100644 --- a/test/area_test.cpp +++ b/test/area_test.cpp @@ -3,7 +3,6 @@ TEST_CASE("AREA") { vkvm::initialize(0); - vkvm::setMode(vkvm::RGB); vkvm::setWidth(200); vkvm::setHeight(200); @@ -13,10 +12,12 @@ TEST_CASE("AREA") { } SECTION("Out of bounds") { - REQUIRE_FALSE(vkvm::setPixel(400, 400, vkvm::white)); REQUIRE(vkvm::getPixel(400, 400) == vkvm::black); + REQUIRE_FALSE(vkvm::setPixel(-5, -5, vkvm::white)); + REQUIRE(vkvm::getPixel(-5, -5) == vkvm::black); + vkvm::setBackgroundColor(vkvm::blue); REQUIRE(vkvm::getPixel(400, 400) == vkvm::blue); diff --git a/test/event_test.cpp b/test/event_test.cpp index eeb9c78..64275c1 100644 --- a/test/event_test.cpp +++ b/test/event_test.cpp @@ -7,26 +7,26 @@ TEST_CASE("Event") { SECTION("Register") { bool mouseMove = false; - bool timer = false; - bool timer2 = false; + bool keyup = false; + bool keyup2 = false; vkvm::registerEvent(vkvm::MouseMove, [&]() { mouseMove = true; }); - vkvm::registerEvent(vkvm::Timer, [&]() { - timer = true; + vkvm::registerEvent(vkvm::KeyUp, [&]() { + keyup = true; }); - vkvm::registerEvent(vkvm::Timer, [&]() { - timer2 = true; + vkvm::registerEvent(vkvm::KeyUp, [&]() { + keyup2 = true; }); REQUIRE_FALSE(mouseMove); vkvm::callEvent(vkvm::MouseMove); REQUIRE(mouseMove); - REQUIRE_FALSE(timer); - REQUIRE_FALSE(timer2); - vkvm::callEvent(vkvm::Timer); - REQUIRE(timer); - REQUIRE(timer2); + REQUIRE_FALSE(keyup); + REQUIRE_FALSE(keyup2); + vkvm::callEvent(vkvm::KeyUp); + REQUIRE(keyup); + REQUIRE(keyup2); } } diff --git a/test/text_test.cpp b/test/text_test.cpp index e26baf0..8996f16 100644 --- a/test/text_test.cpp +++ b/test/text_test.cpp @@ -20,5 +20,9 @@ TEST_CASE("Text") { REQUIRE(vkvm::getCharactersPerRow() == 1); REQUIRE(vkvm::setText("Hello World")); - REQUIRE(vkvm::getText() == "Hello World"); + REQUIRE(vkvm::getText() == "Hello"); + + REQUIRE(vkvm::clearText()); + + REQUIRE(vkvm::getText().empty()); } \ No newline at end of file