Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Johannes Theiner 2019-12-05 11:46:27 +01:00
commit 300cf1ac28
6 changed files with 62 additions and 20 deletions

View File

@ -50,18 +50,21 @@ namespace vkvm {
lockSharedMemory(); lockSharedMemory();
getRegisters()->layout_version = newValue; getRegisters()->layout_version = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto setCharactersPerColumn(int newValue) -> void { auto setCharactersPerColumn(int newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->characters_per_column = newValue; getRegisters()->characters_per_column = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto setCharactersPerRow(int newValue) -> void { auto setCharactersPerRow(int newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->characters_per_row = newValue; getRegisters()->characters_per_row = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto setMousePosition(int x, int y) -> void { auto setMousePosition(int x, int y) -> void {
@ -69,16 +72,29 @@ namespace vkvm {
getRegisters()->mouse_pos_x = x; getRegisters()->mouse_pos_x = x;
getRegisters()->mouse_pos_y = y; getRegisters()->mouse_pos_y = y;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto buttonPressed(KeyCode keyCode) -> void { auto buttonPressed(KeyCode keyCode) -> void {
lockSharedMemory(); lockSharedMemory();
auto reg = getRegisters(); 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_index_write = 0;
} }
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode;
unlockSharedMemory(); unlockSharedMemory();
} }
auto getRegisteredProcesses(EventType eventType) -> std::vector<int> {
std::vector<int> 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;
}
} }

View File

@ -126,6 +126,12 @@ constexpr int keyboardBufferSize = 16;
*/ */
auto buttonPressed(KeyCode keyCode) -> void; auto buttonPressed(KeyCode keyCode) -> void;
/**
* get registered Prosesses for a given event type.
* @param eventType.
*/
auto getRegisteredProcesses(EventType eventType) -> std::vector<int>;
// Shared Memory Layout // Shared Memory Layout
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// struct ControlRegisters // struct ControlRegisters

View File

@ -18,7 +18,6 @@ namespace vkvm {
auto setDefaultValues() -> void { auto setDefaultValues() -> void {
impl.localMemoryWarn = false; impl.localMemoryWarn = false;
if (getSharedMemory() != nullptr) { if (getSharedMemory() != nullptr) {
//set default values
setMode(GraphicMode::RGB); setMode(GraphicMode::RGB);
setCharactersPerRow(60); setCharactersPerRow(60);
setCharactersPerColumn(20); setCharactersPerColumn(20);
@ -64,6 +63,9 @@ namespace vkvm {
} }
auto setPixel(int x, int y, Color color) -> bool { auto setPixel(int x, int y, Color color) -> bool {
if(x < 0 || y < 0){
return false;
}
if (x > getWidth() || y > getHeight()) { if (x > getWidth() || y > getHeight()) {
return false; return false;
} }
@ -116,6 +118,9 @@ namespace vkvm {
} }
auto getPixel(int x, int y) -> Color { auto getPixel(int x, int y) -> Color {
if(x < 0 || y < 0) {
return getBackgroundColor();
}
if (x > getWidth() || y > getHeight()) { if (x > getWidth() || y > getHeight()) {
return getBackgroundColor(); return getBackgroundColor();
} }
@ -164,7 +169,7 @@ namespace vkvm {
auto setText(std::string text) -> bool { auto setText(std::string text) -> bool {
lockSharedMemory(); lockSharedMemory();
char *ptr = getTextArea(); char *ptr = getTextArea();
for (int i = 0; i < text.size(); i++) { for (int i = 0; i < static_cast<int>(text.size()); i++) {
if (i < getCharactersPerColumn() * getCharactersPerRow()) { if (i < getCharactersPerColumn() * getCharactersPerRow()) {
ptr[i] = text[i]; ptr[i] = text[i];
} }
@ -178,7 +183,9 @@ namespace vkvm {
} }
auto getText() -> std::string { auto getText() -> std::string {
return std::string(getTextArea()); std::string text = getTextArea();
return text.substr(0, getCharactersPerColumn() * getCharactersPerRow());
} }
auto clearText() -> bool { auto clearText() -> bool {
@ -209,6 +216,7 @@ namespace vkvm {
lockSharedMemory(); lockSharedMemory();
getRegisters()->width_pixels = newValue; getRegisters()->width_pixels = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto getHeight() -> int { auto getHeight() -> int {
@ -219,6 +227,7 @@ namespace vkvm {
lockSharedMemory(); lockSharedMemory();
getRegisters()->height_pixels = newValue; getRegisters()->height_pixels = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto getMode() -> GraphicMode { auto getMode() -> GraphicMode {
@ -254,6 +263,7 @@ namespace vkvm {
reg->graphicMode = newValue; reg->graphicMode = newValue;
} }
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto getRedrawInterval() -> int { auto getRedrawInterval() -> int {
@ -264,6 +274,7 @@ namespace vkvm {
lockSharedMemory(); lockSharedMemory();
getRegisters()->autoRedrawInterval = newValue; getRegisters()->autoRedrawInterval = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto getTimerInterruptInterval() -> int { auto getTimerInterruptInterval() -> int {
@ -274,6 +285,7 @@ namespace vkvm {
lockSharedMemory(); lockSharedMemory();
getRegisters()->timerInterruptInterval = newValue; getRegisters()->timerInterruptInterval = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto getBackgroundColor() -> Color { auto getBackgroundColor() -> Color {
@ -284,6 +296,7 @@ namespace vkvm {
lockSharedMemory(); lockSharedMemory();
getRegisters()->background_color = newValue; getRegisters()->background_color = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto getForegroundColor() -> Color { auto getForegroundColor() -> Color {
@ -294,6 +307,7 @@ namespace vkvm {
lockSharedMemory(); lockSharedMemory();
getRegisters()->foreground_color = newValue; getRegisters()->foreground_color = newValue;
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto getCharactersPerRow() -> int { auto getCharactersPerRow() -> int {
@ -314,6 +328,7 @@ namespace vkvm {
lockSharedMemory(); lockSharedMemory();
getRegisters()->textMode_font = newValue.getId(); getRegisters()->textMode_font = newValue.getId();
unlockSharedMemory(); unlockSharedMemory();
callEvent(EventType::UpdateControlRegisters);
} }
auto getMousePosition() -> Coordinates { auto getMousePosition() -> Coordinates {
@ -326,7 +341,7 @@ namespace vkvm {
auto reg = getRegisters(); auto reg = getRegisters();
if (reg->keyboardBuffer_index_read != reg->keyboardBuffer_index_write) { if (reg->keyboardBuffer_index_read != reg->keyboardBuffer_index_write) {
keyCode = static_cast<KeyCode>(reg->keyboardBuffer[reg->keyboardBuffer_index_read++]); keyCode = static_cast<KeyCode>(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; reg->keyboardBuffer_index_read = 0;
} }
} }

View File

@ -3,7 +3,6 @@
TEST_CASE("AREA") { TEST_CASE("AREA") {
vkvm::initialize(0); vkvm::initialize(0);
vkvm::setMode(vkvm::RGB);
vkvm::setWidth(200); vkvm::setWidth(200);
vkvm::setHeight(200); vkvm::setHeight(200);
@ -13,10 +12,12 @@ TEST_CASE("AREA") {
} }
SECTION("Out of bounds") { SECTION("Out of bounds") {
REQUIRE_FALSE(vkvm::setPixel(400, 400, vkvm::white)); REQUIRE_FALSE(vkvm::setPixel(400, 400, vkvm::white));
REQUIRE(vkvm::getPixel(400, 400) == vkvm::black); 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); vkvm::setBackgroundColor(vkvm::blue);
REQUIRE(vkvm::getPixel(400, 400) == vkvm::blue); REQUIRE(vkvm::getPixel(400, 400) == vkvm::blue);

View File

@ -7,26 +7,26 @@ TEST_CASE("Event") {
SECTION("Register") { SECTION("Register") {
bool mouseMove = false; bool mouseMove = false;
bool timer = false; bool keyup = false;
bool timer2 = false; bool keyup2 = false;
vkvm::registerEvent(vkvm::MouseMove, [&]() { vkvm::registerEvent(vkvm::MouseMove, [&]() {
mouseMove = true; mouseMove = true;
}); });
vkvm::registerEvent(vkvm::Timer, [&]() { vkvm::registerEvent(vkvm::KeyUp, [&]() {
timer = true; keyup = true;
}); });
vkvm::registerEvent(vkvm::Timer, [&]() { vkvm::registerEvent(vkvm::KeyUp, [&]() {
timer2 = true; keyup2 = true;
}); });
REQUIRE_FALSE(mouseMove); REQUIRE_FALSE(mouseMove);
vkvm::callEvent(vkvm::MouseMove); vkvm::callEvent(vkvm::MouseMove);
REQUIRE(mouseMove); REQUIRE(mouseMove);
REQUIRE_FALSE(timer); REQUIRE_FALSE(keyup);
REQUIRE_FALSE(timer2); REQUIRE_FALSE(keyup2);
vkvm::callEvent(vkvm::Timer); vkvm::callEvent(vkvm::KeyUp);
REQUIRE(timer); REQUIRE(keyup);
REQUIRE(timer2); REQUIRE(keyup2);
} }
} }

View File

@ -20,5 +20,9 @@ TEST_CASE("Text") {
REQUIRE(vkvm::getCharactersPerRow() == 1); REQUIRE(vkvm::getCharactersPerRow() == 1);
REQUIRE(vkvm::setText("Hello World")); REQUIRE(vkvm::setText("Hello World"));
REQUIRE(vkvm::getText() == "Hello World"); REQUIRE(vkvm::getText() == "Hello");
REQUIRE(vkvm::clearText());
REQUIRE(vkvm::getText().empty());
} }