From b82ccebd3a0cce28177b5fac046139e2de7737fa Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Sun, 20 Aug 2023 20:12:36 +0700 Subject: Getting started with print on display + some fixes --- arch/x86/io/VGADisplay.cpp | 119 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 arch/x86/io/VGADisplay.cpp (limited to 'arch/x86/io/VGADisplay.cpp') diff --git a/arch/x86/io/VGADisplay.cpp b/arch/x86/io/VGADisplay.cpp new file mode 100644 index 0000000..b74858b --- /dev/null +++ b/arch/x86/io/VGADisplay.cpp @@ -0,0 +1,119 @@ +#include "VGADisplay.h" + +VGADisplay::VGADisplay() +{ + isBright = isBlink = shift = 0; + xCurr = yCurr = 0; + color = (char)VGADisplayInfo::colorAttr::gray; + videoMem = (dchar *)VGADisplayInfo::videoMemAddr; +}; + +VGADisplay::VGADisplay(uint16 x, uint16 y) +{ + isBright = isBlink = shift = 0; + xCurr = yCurr = 0; + color = (char)VGADisplayInfo::colorAttr::gray; + videoMem = (dchar *)VGADisplayInfo::videoMemAddr; +}; + +VGADisplay& VGADisplay::operator<<(const char &c) +{ + printChar(c); + + return *this; +}; + +VGADisplay& VGADisplay::operator++(int) +{ + if(++xCurr == VGADisplayInfo::width) + { + yCurr++; + xCurr = 0; + } + if(yCurr == VGADisplayInfo::height) + { + if(shift) + { + this->doShift(); + xCurr = 0; + yCurr--; + } + else xCurr = 0, yCurr = 0; + } + videoMem = (dchar *)(VGADisplayInfo::videoMemAddr) + + yCurr * VGADisplayInfo::width + xCurr; + + return *this; +}; + +VGADisplay& VGADisplay::operator<<(const char *c) +{ + for(int i = 0; c[i] != '\0'; i++) + { + (*this) << c[i]; + } + + return *this; +}; + +void VGADisplay::doShift() +{ + for(uint16 i = 0; i < VGADisplayInfo::height; i++) + { + for(uint16 j = 0; j < VGADisplayInfo::width; j++) + { + *((dchar *)(VGADisplayInfo::videoMemAddr) + (i - 1) * VGADisplayInfo::width + j) = *((dchar *)(VGADisplayInfo::videoMemAddr) + i * VGADisplayInfo::width + j); + *((dchar *)(VGADisplayInfo::videoMemAddr) + i * VGADisplayInfo::width + j) = (*((dchar *)(VGADisplayInfo::videoMemAddr) + i * VGADisplayInfo::width + j) & 0x00) | ' '; + } + } +}; + +void VGADisplay::setShift(bool status) +{ + shift = status; +}; + +void VGADisplay::setColor(char colorAttr) +{ + color = colorAttr; +}; + +void VGADisplay::setBlink(bool blinkAttr) +{ + isBlink = blinkAttr; +}; + +void VGADisplay::setBright(bool brigthAttr) +{ + isBright = brigthAttr; +}; + +void VGADisplay::goNewLine() +{ + uint16 yCurrOld = yCurr; + + while(yCurrOld == yCurr) (*this)++; +}; + +void VGADisplay::goHorizontalTab() +{ + while(xCurr % 8 != 0) (*this)++; +}; + +bool VGADisplay::printChar(const char &c) +{ + switch(c) + { + case '\0': return true; + case '\n': this->goNewLine(); return true; + case '\t': this->goHorizontalTab(); return true; + default: + { + char attr = isBlink << 8 | isBright << 4 + | color; + *videoMem = c | attr << 8; + (*this)++; + return false; + } + } +}; -- cgit v1.2.3