35 #define CHAR_OFFSET(x, y) ((y) * VGA_WIDTH + (x)) 38 static uint16_t *videoTextMemory = (uint16_t *)0xB8000;
39 static uint8_t *videoFontMemory = (uint8_t *)0xA0000;
41 static UNUSED uint16_t *videoIOPort = (uint16_t *)0x0463;
44 static uint8_t cursorX = 0;
45 static uint8_t cursorY = 0;
54 static uint8_t cursorHardwareX = 0;
55 static uint8_t cursorHardwareY = 0;
58 static const char hexTable[] =
"0123456789ABCDEF";
61 static void __consoleSetMiscOutputRegister(
bool set)
96 videoTextMemory[
CHAR_OFFSET(x, y)] =
' ' | (consoleColor << 8);
115 consoleColor = color;
136 return consoleColor & 15;
145 return (consoleColor >> 4) & 15;
159 if (rawMode || chr !=
'\n')
161 videoTextMemory[
CHAR_OFFSET(cursorX, cursorY)] = (chr & 0xFF) | (consoleColor << 8);
165 if ((chr ==
'\n' && !rawMode) || cursorX >=
VGA_WIDTH)
211 videoTextMemory[
CHAR_OFFSET(cursorX, cursorY)] = chr;
308 for (i = 7; i >= 0; i--)
310 buf[i] = hexTable[value & 0xF];
333 buf[--i] =
'0' + (value % 10);
353 for (i = 3; i >= 0; i--)
355 buf[i] = hexTable[value & 0xF];
390 return (cursorY << 16) | cursorX;
427 videoTextMemory[
CHAR_OFFSET(x, VGA_HEIGHT - 1)] =
' ' | (consoleColor << 8);
466 __consoleSetMiscOutputRegister(
true);
477 uint32_t indexPos =
CHAR_OFFSET(cursorHardwareX, cursorHardwareY);
480 outb(0x3D5, indexPos & 0xFF);
482 outb(0x3D5, (indexPos >> 8) & 0xFF);
515 return (cursorHardwareY << 16) | cursorHardwareX;
531 outw(0x03ce, 0x0406);
532 outw(0x03c4, 0x0402);
533 outw(0x03c4, 0x0604);
540 for (i = 0; i < 256; i++)
541 memcpy(videoFontMemory + i * 32, &vga_latin1[i], 16);
543 outw(0x03c4, 0x0302);
544 outw(0x03c4, 0x0204);
545 outw(0x03ce, 0x1005);
546 outw(0x03ce, 0x0E06);
556 consoleFlags = flags;
617 for (i = 0; i < numArgs; i++, args++)
void consoleScrollUp()
Scroll the console up one line.
void consoleWriteStringMax(const char *str, size_t len)
Write a nullterminated string or a maximum of len characters.
uint32_t consoleGetCursorPosY()
Get Y position of the text cursor.
void consoleWriteRawLen(const uint16_t *data, size_t count)
Write raw data with a fixed size to the console.
uint32_t consoleGetSize()
Returns the packed size of the console.
#define CHAR_OFFSET(x, y)
uint8_t consoleGetColorForeground()
Get current foreground color.
#define MAKE_COLOR(foreground, background)
void consoleShowHardwareCursor(bool changed)
Show / hide blinking hardware cursor.
void consoleWriteInt32(uint32_t value)
Write a 32 bit integer as decimal value on the console.
uint32_t consoleGetHardwareCursor()
Get packed position of the hardware cursor.
void outb(uint16_t port, uint8_t val)
void consoleSetFont()
Load a custom font supporting latin1 characters.
uint32_t stringLength(const char *str)
Returns the length of a nullterminated string.
uint8_t consoleGetWidth()
Returns the width (text cols) of the console.
void physMemProtectBootEntry(uint32_t addr, uint32_t length)
Marks all pages within a memory range as reserved and adds them to the boot map.
uint8_t inb(uint16_t port)
uint8_t vga_latin1[256][16]
void consoleInit()
Initializes the console.
#define RAW_CHAR_CHR(raw)
uint32_t consoleGetCursorPosX()
Get X position of the text cursor.
void consoleSetColor(uint8_t color)
Set the text and background color of the console.
uint8_t consoleGetHeight()
Returns the height (text rows) of the console.
uint8_t consoleGetColorBackground()
Get current background color.
void consolePutCharRaw(uint16_t chr)
Write a raw character and color on the console.
void consoleWriteHex32(uint32_t value)
Write a 32 bit integer as hex value on the console.
void consoleClear()
Clear the screen contents.
uint8_t consoleGetColor()
Get current color.
void * memcpy(void *destination, const void *source, size_t num)
Copies a block of memory from source to destination.
void consoleSetHardwareCursor(uint8_t x, uint8_t y)
Set the position of the hardware cursor.
void consoleSystemFailure(const char **lines, uint32_t numArgs, uint32_t *args, struct taskContext *context)
Print a system failure message and halts the system.
void consoleWriteHex16(uint16_t value)
Write a 16 bit integer as hex value on the console.
void consoleWriteString(const char *str)
Write a C string to the console.
uint32_t consoleGetCursorPos()
Get packed position of the text cursor.
void consoleWriteStringLen(const char *str, size_t len)
Write a string with a fixed size to the console.
bool consoleSetCursorPos(uint8_t x, uint8_t y)
Set the position of the text cursor.
void consoleSetFlags(uint32_t flags)
Set console flags.
void consoleEchoChar(char chr)
Echo keyboard input on the console.
void outw(uint16_t port, uint16_t val)
void consolePutChar(char chr)
Write a character on the console.
uint32_t consoleGetFlags()
Get console flags.