#include "cga.h" #include "../debug/output.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); } uint16_t readCGAReg(int reg){ index_port.outb(reg); return data_port.inb(); } void setCursor(unsigned abs_x, unsigned 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) { uint16_t pos = readCGAReg(RegisterIndex::CURSOR_LOW); pos |= (readCGAReg(RegisterIndex::CURSOR_HIGH) << 8); abs_y = pos / COLUMNS; abs_x = pos % COLUMNS; } void show(unsigned abs_x, unsigned abs_y, char character, Attribute attrib) { TEXT_BUFFER_BASE[abs_x + (COLUMNS * abs_y)] = Cell(character, attrib); } }; // namespace CGA