+ translate pixel colors on change GraphicMode

This commit is contained in:
Julian Hinxlage 2019-11-26 13:22:53 +01:00
parent 7fa0988413
commit cc7e3e09ad
5 changed files with 46 additions and 5 deletions

View File

@ -2,9 +2,13 @@
namespace vkvm { namespace vkvm {
Color::Color() noexcept
: red(0), green(0), blue(0) {}
Color::Color(unsigned char red, unsigned char green, unsigned char blue) noexcept 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 { Color::Color(unsigned int hex) noexcept {
red = (unsigned char) ((hex >> 16 & 0xFF));//NOLINT red = (unsigned char) ((hex >> 16 & 0xFF));//NOLINT

View File

@ -16,8 +16,12 @@ namespace vkvm {
unsigned char blue; unsigned char blue;
public: public:
Color() noexcept;
Color(unsigned char red, unsigned char green, unsigned char blue) noexcept; Color(unsigned char red, unsigned char green, unsigned char blue) noexcept;
Color(const Color &color) noexcept;
explicit Color(unsigned int hex) noexcept; explicit Color(unsigned int hex) noexcept;
auto getRed() -> unsigned char; auto getRed() -> unsigned char;

View File

@ -62,9 +62,14 @@ namespace vkvm {
} }
char *getLocalMemory(){ 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()) { if (localSharedMemory.empty()) {
constexpr int kilo = 1024; constexpr int kilo = 1024;
localSharedMemory.resize(impl.sharedMemorySize); localSharedMemory.resize(impl.sharedMemorySize * kilo);
} }
return &localSharedMemory[0]; return &localSharedMemory[0];
} }

View File

@ -58,6 +58,7 @@ constexpr int keyboardBufferSize = 16;
int interruptEntrysPerEventType = 8; //NOLINT int interruptEntrysPerEventType = 8; //NOLINT
int reservedSize = 1024; //NOLINT int reservedSize = 1024; //NOLINT
std::vector<std::function<void()>> eventTable; std::vector<std::function<void()>> eventTable;
bool localMemoryWarn = true;
}; };
extern Impl impl; extern Impl impl;

View File

@ -16,8 +16,10 @@ namespace vkvm {
} }
auto setDefaultValues() -> void { auto setDefaultValues() -> void {
impl.localMemoryWarn = false;
if(getSharedMemory() != nullptr) { if(getSharedMemory() != nullptr) {
//set default values //set default values
setMode(GraphicMode::RGB);
setCharactersPerRow(60);// NOLINT setCharactersPerRow(60);// NOLINT
setCharactersPerColumn(20);// NOLINT setCharactersPerColumn(20);// NOLINT
setHeight(600);// NOLINT setHeight(600);// NOLINT
@ -25,10 +27,10 @@ namespace vkvm {
setMousePosition(42, 42);// NOLINT setMousePosition(42, 42);// NOLINT
setBackgroundColor(black); setBackgroundColor(black);
setForegroundColor(white); setForegroundColor(white);
setMode(GraphicMode::RGB);
setRedrawInterval(20);// NOLINT setRedrawInterval(20);// NOLINT
setTimerInterruptInterval(10);// NOLINT setTimerInterruptInterval(10);// NOLINT
} }
impl.localMemoryWarn = true;
} }
auto registerEvent(EventType type, const std::function<void()> &handler) -> bool { auto registerEvent(EventType type, const std::function<void()> &handler) -> bool {
@ -205,7 +207,32 @@ namespace vkvm {
auto setMode(GraphicMode newValue) -> void { auto setMode(GraphicMode newValue) -> void {
lockSharedMemory(); lockSharedMemory();
getRegisters()->graphicMode = newValue; auto reg = getRegisters();
if(reg->graphicMode != newValue){
std::vector<Color> 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(); unlockSharedMemory();
} }