From 028ea93acf68e98de5cd118b223de29e0d0221fe Mon Sep 17 00:00:00 2001 From: "L. Bradley LaBoon" Date: Wed, 16 Oct 2013 15:55:37 -0400 Subject: [PATCH] Added newline and scroll support to the VGA driver. --- kernel/brados.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/kernel/brados.c b/kernel/brados.c index 86626a5..d78a85f 100644 --- a/kernel/brados.c +++ b/kernel/brados.c @@ -1,4 +1,3 @@ -#include #include #include @@ -80,13 +79,35 @@ void terminalPutEntryAt(char c, uint8_t color, size_t x, size_t y) terminalBuf[index] = makeVGAEntry(c, color); } +void terminalScroll() +{ + for (size_t i = 1; i < VGA_HEIGHT; i++) { + for (size_t j = 0; j < VGA_WIDTH; j++) { + const size_t index = i * VGA_WIDTH + j; + const size_t indexBelow = (i - 1) * VGA_WIDTH + j; + terminalBuf[indexBelow] = terminalBuf[index]; + } + } + + for (size_t i = 0; i < VGA_WIDTH; i++) { + const size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH + i; + terminalBuf[index] = ' '; + } +} + void terminalPutChar(char c) { - terminalPutEntryAt(c, terminalColor, terminalCol, terminalRow); + if (c == '\n') + terminalCol = VGA_WIDTH - 1; + else + terminalPutEntryAt(c, terminalColor, terminalCol, terminalRow); + if (terminalCol++ == VGA_WIDTH) { terminalCol = 0; - if (terminalRow++ == VGA_HEIGHT) - terminalRow = 0; + if (terminalRow++ == VGA_HEIGHT) { + terminalRow--; + terminalScroll(); + } } }