diff --git a/src/screen.c b/src/screen.c index f6e05bf..c0d0571 100644 --- a/src/screen.c +++ b/src/screen.c @@ -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')