From 12c900f24ebd717c0de79dec804f39b6235d4cfa Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Thu, 28 Jan 2021 00:05:00 -0600 Subject: i386: create terminal_scroll function Add support for scrolling the terminal at the end of the VGA buffer. Signed-off-by: Danny Holman --- arch/i386/boot/tty.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/arch/i386/boot/tty.c b/arch/i386/boot/tty.c index ed0aaf4..9244415 100644 --- a/arch/i386/boot/tty.c +++ b/arch/i386/boot/tty.c @@ -35,20 +35,35 @@ void tty_putentryat(unsigned 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 i = 0; i < VGA_HEIGHT; i++) { + for (size_t j = 0; j < VGA_WIDTH; j++) + terminal_buffer[i * VGA_WIDTH + j] = terminal_buffer[(i+1) * VGA_WIDTH + j]; + } +} + void tty_putchar(char c) { - unsigned char uc = c; + unsigned char uc; + + uc = c; switch (uc) { case '\n': terminal_column = 0; - terminal_row++; - return; - } - - tty_putentryat(uc, terminal_color, terminal_column, terminal_row); - if (++terminal_column == VGA_WIDTH) { - terminal_column = 0; - if (++terminal_row == VGA_HEIGHT) - terminal_row = 0; + if (++terminal_row == VGA_HEIGHT) { + terminal_row--; + terminal_scroll(); + } + break; + default: + tty_putentryat(uc, terminal_color, terminal_column, terminal_row); + if (++terminal_column == VGA_WIDTH) { + terminal_column = 0; + if (++terminal_row == VGA_HEIGHT) { + terminal_row--; + terminal_scroll(); + } + } + break; } } -- cgit v1.2.3