diff --git a/arch/cga.cc b/arch/cga.cc index 13b10a6..159e8aa 100644 --- a/arch/cga.cc +++ b/arch/cga.cc @@ -1,10 +1,21 @@ #include "cga.h" +#include "arch/ioport.h" namespace CGA { + IOPort index_port = IOPort(0x3d4); + IOPort data_port = IOPort(0x3d5); + + void writeCGAReg(int reg, int data){ + index_port.outb(reg); + data_port.outb(data); + } + void setCursor(unsigned abs_x, unsigned abs_y) { - (void)abs_x; - (void)abs_y; + uint16_t pos = abs_y * COLUMNS + abs_x; + + writeCGAReg(RegisterIndex::CURSOR_LOW, pos & 0xFF); + writeCGAReg(RegisterIndex::CURSOR_HIGH, ((pos >> 8) & 0xFF)); } void getCursor(unsigned& abs_x, unsigned& abs_y) { diff --git a/arch/cga.h b/arch/cga.h index 33b61b3..5ab7ab7 100644 --- a/arch/cga.h +++ b/arch/cga.h @@ -18,6 +18,15 @@ namespace CGA { constexpr unsigned ROWS = 25; ///< Visible rows in text mode constexpr unsigned COLUMNS = 80; ///< Visible columns in text mode +enum RegisterIndex { + CURSOR_START = 10, + CURSOR_END = 11, + START_ADDRESS_HIGH = 12, + START_ADDRESS_LOW = 13, + CURSOR_HIGH = 14, + CURSOR_LOW = 15 +}; + /*! \brief CGA color palette * * Colors for the attribute byte. @@ -62,7 +71,9 @@ enum Color { */ union Attribute { struct { - uint8_t todo : 8; + uint8_t foreground : 4; + uint8_t background : 3; + uint8_t blink : 1; } __attribute__((packed)); uint8_t value; ///< combined value @@ -75,11 +86,7 @@ union Attribute { * \param blink Blink if `true` (default: no blinking) */ explicit Attribute(Color foreground = LIGHT_GREY, Color background = BLACK, - bool blink = false) { // NOLINT - (void)foreground; - (void)background; - (void)blink; - } + bool blink = false) : foreground(foreground), background(background), blink(blink) {} } __attribute__((packed)); // prevent padding by the compiler /*! \brief Set the keyboard hardware cursor to absolute screen position diff --git a/main.cc b/main.cc index cba4c88..b20d60e 100644 --- a/main.cc +++ b/main.cc @@ -3,12 +3,16 @@ #include "boot/startup_ap.h" #include "debug/output.h" +#include "arch/cga.h" + // Main function // (the bootstrap processor starts here)} extern "C" int main() { unsigned int numCPUs = Core::count(); DBG_VERBOSE << "Number of CPUs: " << numCPUs << endl; + CGA::setCursor(1, 2); + /* Start application processors * To avoid unexpected behaviour, make sure that interrupts are not * enabled before the APs are booted. Otherwise it might interfere with the