screen: implement terminal scrolling

This commit is contained in:
2025-03-26 20:35:47 +03:00
parent 12ae4fd814
commit dd865fe89d
+19 -2
View File
@@ -42,6 +42,23 @@ void terminal_putentryat(char c, uint8_t color, size_t x, size_t y)
terminal_buffer[index] = vga_entry(c, color);
}
void terminal_scroll(void)
{
for (size_t y = 0; y < VGA_HEIGHT - 1; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index_from = (y + 1) * VGA_WIDTH + x;
const size_t index_to = y * VGA_WIDTH + x;
terminal_buffer[index_to] = terminal_buffer[index_from];
}
}
for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH + x;
terminal_buffer[index] = vga_entry(' ', terminal_color);
}
terminal_row = VGA_HEIGHT - 1;
terminal_column = 0;
}
void terminal_putchar(char c)
{
if(c != '\n')
@@ -51,10 +68,10 @@ void terminal_putchar(char c)
terminal_column = 0;
terminal_initialize();
if (++terminal_row >= VGA_HEIGHT)
terminal_row = 0;
terminal_scroll();
}
if(terminal_row >= VGA_HEIGHT){
terminal_row = 0;
terminal_scroll();
}
if(c == '\n')