Added documentation to console.c

This commit is contained in:
Pierre-Emmanuel Gob. 2026-09-17 22:44:16 +02:00
parent 8c46ac48d9
commit 577d28cd2e
2 changed files with 10 additions and 0 deletions

2
.gitignore vendored
View file

@ -13,6 +13,8 @@ compile_commands.json
.vscode/ .vscode/
.idea/ .idea/
*~ *~
.pyc
*.pyc
# QEMU / debug # QEMU / debug
*.log *.log

View file

@ -13,8 +13,13 @@
static uint8_t cursor_row; static uint8_t cursor_row;
static uint8_t cursor_col; static uint8_t cursor_col;
/* Text buffer: one 16-bit cell per character, low byte is the ASCII code,
* high byte is the color attribute. `volatile` so the compiler keeps every
* store in order: this is memory-mapped I/O, and dropped or reordered
* writes would corrupt the screen. */
static volatile uint16_t *const vga = (uint16_t *)VGA_ADDR; static volatile uint16_t *const vga = (uint16_t *)VGA_ADDR;
/* Move every line one row up and blank the last line */
static void scroll(void) static void scroll(void)
{ {
for (uint8_t row = 1; row < VGA_HEIGHT; row++) { for (uint8_t row = 1; row < VGA_HEIGHT; row++) {
@ -47,10 +52,12 @@ void console_putchar(char c)
(uint16_t)((COLOR_DEFAULT << 8) | c); (uint16_t)((COLOR_DEFAULT << 8) | c);
cursor_col++; cursor_col++;
if (cursor_col >= VGA_WIDTH) { if (cursor_col >= VGA_WIDTH) {
/* Past the right edge: wrap to the next line. */
cursor_col = 0; cursor_col = 0;
cursor_row++; cursor_row++;
} }
} }
/* Past the bottom line: scroll and stay on the last line. */
if (cursor_row >= VGA_HEIGHT) { if (cursor_row >= VGA_HEIGHT) {
scroll(); scroll();
cursor_row = VGA_HEIGHT - 1; cursor_row = VGA_HEIGHT - 1;
@ -70,6 +77,7 @@ void console_puthex64(uint64_t value)
static const char digits[] = "0123456789ABCDEF"; static const char digits[] = "0123456789ABCDEF";
console_puts("0x"); console_puts("0x");
/* Print 16 nibbles, most significant first (shifts 60, 56, …, 0). */
for (int shift = 60; shift >= 0; shift -= 4) { for (int shift = 60; shift >= 0; shift -= 4) {
console_putchar(digits[(value >> shift) & 0xFU]); console_putchar(digits[(value >> shift) & 0xFU]);
} }