From db3e15449fd5026fd8c049cb44322285c9298067 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Fri, 18 Apr 2025 17:53:34 +0200 Subject: [PATCH] add getCursor --- arch/cga.cc | 14 +++++++++++--- arch/cga.h | 5 ----- main.cc | 9 +++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/arch/cga.cc b/arch/cga.cc index 159e8aa..e021267 100644 --- a/arch/cga.cc +++ b/arch/cga.cc @@ -8,7 +8,12 @@ namespace CGA { void writeCGAReg(int reg, int data){ index_port.outb(reg); - data_port.outb(data); + data_port.outw(data); + } + + uint16_t readCGAReg(int reg){ + index_port.outb(reg); + return data_port.inb(); } void setCursor(unsigned abs_x, unsigned abs_y) { @@ -19,8 +24,11 @@ void setCursor(unsigned abs_x, unsigned abs_y) { } void getCursor(unsigned& abs_x, unsigned& abs_y) { - (void)abs_x; - (void)abs_y; + uint16_t pos = readCGAReg(RegisterIndex::CURSOR_LOW); + pos |= (readCGAReg(RegisterIndex::CURSOR_HIGH) << 8); + + abs_x = pos / 80; + abs_y = pos % 80; } void show(unsigned abs_x, unsigned abs_y, char character, Attribute attrib) { diff --git a/arch/cga.h b/arch/cga.h index 5ab7ab7..f9c9556 100644 --- a/arch/cga.h +++ b/arch/cga.h @@ -67,7 +67,6 @@ enum Color { * (`-fno-strict-aliasing`). In \StuBS we use this feature extensively due to * the improved code readability. * - * \todo(11) Fill in the bitfield */ union Attribute { struct { @@ -79,8 +78,6 @@ union Attribute { /*! \brief Attribute constructor (with default values) * - * \todo(11) Complete constructor - * * \param foreground Foreground color (Default: \ref LIGHT_GREY) * \param background Background color (Default: \ref BLACK) * \param blink Blink if `true` (default: no blinking) @@ -91,8 +88,6 @@ union Attribute { /*! \brief Set the keyboard hardware cursor to absolute screen position * - * \todo(11) Implement the method using \ref IOPort - * * \param abs_x absolute column of the keyboard hardware cursor * \param abs_y absolute row of the keyboard hardware cursor */ diff --git a/main.cc b/main.cc index a6eb5b7..d800c67 100644 --- a/main.cc +++ b/main.cc @@ -10,8 +10,13 @@ extern "C" int main() { unsigned int numCPUs = Core::count(); DBG_VERBOSE << "Number of CPUs: " << numCPUs << endl; - CGA::setCursor(1, 2); - + CGA::setCursor(0, 0); + + unsigned x,y; + CGA::getCursor(x, y); + + CGA::setCursor(x+1, y+1); + /* 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