diff options
author | Danny Holman <dholman@gymli.xyz> | 2021-01-28 00:05:00 -0600 |
---|---|---|
committer | Danny Holman <dholman@gymli.xyz> | 2021-01-28 00:05:00 -0600 |
commit | 12c900f24ebd717c0de79dec804f39b6235d4cfa (patch) | |
tree | 5d57a6cf2f587b3333762e46074a218e480a36cd /arch/i386 | |
parent | dce1e97e7503e90e1d2fcfc0ab11b8d2c7ad1dfb (diff) |
i386: create terminal_scroll function
Add support for scrolling the terminal at the end of the VGA buffer.
Signed-off-by: Danny Holman <dholman@gymli.xyz>
Diffstat (limited to 'arch/i386')
-rw-r--r-- | arch/i386/boot/tty.c | 35 |
1 files 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; } } |