From: Tulio A M Mendes Date: Tue, 10 Feb 2026 04:14:19 +0000 (-0300) Subject: fix: implement VGA text-mode scrolling instead of wrap-to-row-0 X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=127f2ac2fefdb1f4bf1a103013e91db5f29f0529;p=AdrOS.git fix: implement VGA text-mode scrolling instead of wrap-to-row-0 When the cursor reached the bottom of the 25-row VGA text buffer, term_row was reset to 0, overwriting the top of the screen. This made boot output unreadable once it exceeded 25 lines. Add vga_scroll() that shifts all rows up by one and clears the last row. Called from both vga_put_char and vga_print. Passes: make, cppcheck, QEMU smoke test. --- diff --git a/src/drivers/vga_console.c b/src/drivers/vga_console.c index 1890a2c..17770b4 100644 --- a/src/drivers/vga_console.c +++ b/src/drivers/vga_console.c @@ -14,6 +14,18 @@ static uint8_t term_color = 0x0F; // White on Black static spinlock_t vga_lock = {0}; +static void vga_scroll(void) { + for (int y = 1; y < VGA_HEIGHT; y++) { + for (int x = 0; x < VGA_WIDTH; x++) { + VGA_BUFFER[(y - 1) * VGA_WIDTH + x] = VGA_BUFFER[y * VGA_WIDTH + x]; + } + } + for (int x = 0; x < VGA_WIDTH; x++) { + VGA_BUFFER[(VGA_HEIGHT - 1) * VGA_WIDTH + x] = (uint16_t)' ' | (uint16_t)term_color << 8; + } + term_row = VGA_HEIGHT - 1; +} + void vga_init(void) { VGA_BUFFER = (volatile uint16_t*)hal_video_text_buffer(); term_col = 0; @@ -60,8 +72,7 @@ void vga_put_char(char c) { } if (term_row >= VGA_HEIGHT) { - // TODO: Implement scrolling - term_row = 0; + vga_scroll(); } spin_unlock_irqrestore(&vga_lock, flags); @@ -92,7 +103,7 @@ void vga_print(const char* str) { } if (term_row >= VGA_HEIGHT) { - term_row = 0; + vga_scroll(); } }