diff --git a/kernel.c b/kernel.c index d9a6b6efbfa7224b9de2540c1b4dfb0193ed1fb7..1ab188bc1700eb6a6abf421d12da5627924fe065 100644 --- a/kernel.c +++ b/kernel.c @@ -80,42 +80,41 @@ void terminal_setcolor(uint8_t color) { } void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) { - if (y == VGA_HEIGHT) { - // Scroll the screen up one row - for (size_t i = 1; i < VGA_HEIGHT; i++) { - for (size_t j = 0; j < VGA_WIDTH; j++) { - terminal_buffer[(i - 1) * VGA_WIDTH + j] = terminal_buffer[i * VGA_WIDTH + j]; - } - } - // Clear the last row - for (size_t x = 0; x < VGA_WIDTH; x++) { - terminal_buffer[(VGA_HEIGHT - 1) * VGA_WIDTH + x] = make_vgaentry(' ', color); - } - // Move the cursor to the next row - y = y + 1; - } - - const size_t index = y * VGA_WIDTH + x; - terminal_buffer[index] = make_vgaentry(c, color); + const size_t index = y * VGA_WIDTH + x; + terminal_buffer[index] = make_vgaentry(c, color); } void terminal_putchar(char c) { - if (c == '\n') { - terminal_column = 0; - if (++terminal_row == VGA_HEIGHT) { - terminal_row = 0; + if (c == '\n') { + terminal_column = 0; + if (++terminal_row == VGA_HEIGHT) { + for (size_t y = 1; y < VGA_HEIGHT; y++) { + for (size_t x = 0; x < VGA_WIDTH; x++) { + terminal_buffer[(y - 1) * VGA_WIDTH + x] = terminal_buffer[y * VGA_WIDTH + x]; } - } else if (c == '\r') { - terminal_column = 0; - } else { - terminal_putentryat(c, terminal_color, terminal_column, terminal_row); - if (++terminal_column == VGA_WIDTH) { - terminal_column = 0; - if (++terminal_row == VGA_HEIGHT) { - terminal_row = 0; - } + } + for (size_t x = 0; x < VGA_WIDTH; x++) { + terminal_buffer[(VGA_HEIGHT - 1) * VGA_WIDTH + x] = make_vgaentry(' ', terminal_color); + } + terminal_row = VGA_HEIGHT - 1; + } + } else { + terminal_putentryat(c, terminal_color, terminal_column, terminal_row); + if (++terminal_column == VGA_WIDTH) { + terminal_column = 0; + if (++terminal_row == VGA_HEIGHT) { + for (size_t y = 1; y < VGA_HEIGHT; y++) { + for (size_t x = 0; x < VGA_WIDTH; x++) { + terminal_buffer[(y - 1) * VGA_WIDTH + x] = terminal_buffer[y * VGA_WIDTH + x]; + } } + for (size_t x = 0; x < VGA_WIDTH; x++) { + terminal_buffer[(VGA_HEIGHT - 1) * VGA_WIDTH + x] = make_vgaentry(' ', terminal_color); + } + terminal_row = VGA_HEIGHT - 1; + } } + } } void terminal_writestring(const char* data) {