From cc7e3e09ade62540b1c37d42e268c741d64f707c Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 26 Nov 2019 13:22:53 +0100 Subject: [PATCH] + translate pixel colors on change GraphicMode --- src/Color.cpp | 8 ++++++-- src/Color.hpp | 4 ++++ src/SharedMemoryAccess.cpp | 7 ++++++- src/internal.hpp | 1 + src/vkvm.cpp | 31 +++++++++++++++++++++++++++++-- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Color.cpp b/src/Color.cpp index f554401..8531c15 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -2,9 +2,13 @@ namespace vkvm { + Color::Color() noexcept + : red(0), green(0), blue(0) {} + Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept - : red(red), green(green), blue(blue) { - } + : red(red), green(green), blue(blue) {} + + Color::Color(const Color &color) noexcept = default; Color::Color(unsigned int hex) noexcept { red = (unsigned char) ((hex >> 16 & 0xFF));//NOLINT diff --git a/src/Color.hpp b/src/Color.hpp index b622d3d..d9b6040 100644 --- a/src/Color.hpp +++ b/src/Color.hpp @@ -16,8 +16,12 @@ namespace vkvm { unsigned char blue; public: + Color() noexcept; + Color(unsigned char red, unsigned char green, unsigned char blue) noexcept; + Color(const Color &color) noexcept; + explicit Color(unsigned int hex) noexcept; auto getRed() -> unsigned char; diff --git a/src/SharedMemoryAccess.cpp b/src/SharedMemoryAccess.cpp index 6147181..7bd1013 100644 --- a/src/SharedMemoryAccess.cpp +++ b/src/SharedMemoryAccess.cpp @@ -62,9 +62,14 @@ namespace vkvm { } char *getLocalMemory(){ + static bool givenWarning {false}; + if(!givenWarning && impl.localMemoryWarn){ + givenWarning = true; + log(LogLevel::WARNING, "no shared memory found, using local memory instead!"); + } if (localSharedMemory.empty()) { constexpr int kilo = 1024; - localSharedMemory.resize(impl.sharedMemorySize); + localSharedMemory.resize(impl.sharedMemorySize * kilo); } return &localSharedMemory[0]; } diff --git a/src/internal.hpp b/src/internal.hpp index c29e932..7f57add 100644 --- a/src/internal.hpp +++ b/src/internal.hpp @@ -58,6 +58,7 @@ constexpr int keyboardBufferSize = 16; int interruptEntrysPerEventType = 8; //NOLINT int reservedSize = 1024; //NOLINT std::vector> eventTable; + bool localMemoryWarn = true; }; extern Impl impl; diff --git a/src/vkvm.cpp b/src/vkvm.cpp index 9f52356..f938548 100644 --- a/src/vkvm.cpp +++ b/src/vkvm.cpp @@ -16,8 +16,10 @@ namespace vkvm { } auto setDefaultValues() -> void { + impl.localMemoryWarn = false; if(getSharedMemory() != nullptr) { //set default values + setMode(GraphicMode::RGB); setCharactersPerRow(60);// NOLINT setCharactersPerColumn(20);// NOLINT setHeight(600);// NOLINT @@ -25,10 +27,10 @@ namespace vkvm { setMousePosition(42, 42);// NOLINT setBackgroundColor(black); setForegroundColor(white); - setMode(GraphicMode::RGB); setRedrawInterval(20);// NOLINT setTimerInterruptInterval(10);// NOLINT } + impl.localMemoryWarn = true; } auto registerEvent(EventType type, const std::function &handler) -> bool { @@ -205,7 +207,32 @@ namespace vkvm { auto setMode(GraphicMode newValue) -> void { lockSharedMemory(); - getRegisters()->graphicMode = newValue; + auto reg = getRegisters(); + if(reg->graphicMode != newValue){ + + std::vector pixels; + int height = reg->height_pixels; + int width = reg->width_pixels; + pixels.resize(height * width); + + for(int y = 0; y < height;y++){ + for(int x = 0;x < width;x++){ + pixels[y * width + x] = getPixel(x,y); + } + } + + getRegisters()->graphicMode = newValue; + + unlockSharedMemory(); + for(int y = 0; y < height;y++){ + for(int x = 0;x < width;x++){ + setPixel(x,y, pixels[y * width + x]); + } + } + lockSharedMemory(); + }else{ + reg->graphicMode = newValue; + } unlockSharedMemory(); }