From 28288545db27127065910908f6335a511a3a5467 Mon Sep 17 00:00:00 2001 From: nigel Date: Sun, 2 May 2021 13:14:31 -0400 Subject: [PATCH] Implemented terminal scrolling --- README.md | 2 +- build.sh | 3 +++ src/kernel.c | 63 ++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1aae946..c07f211 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ I hope to soon have the basic output and booting sequence with multiboot done. ### Planning -[ ] Muliboot to kernel \ +[x] Muliboot to kernel \ [ ] Printing strings and integer numbers (both decimal and hex) on the screen is certainly a must. This is one of most basic ways of debugging, and virtually all of us have gone through a kprint() or kout in version 0.01. \ [ ] Outputting to a serial port will save you a lot of debugging time. You don't have to fear losing information due to scrolling. You will be able to test your OS from a console, filter interesting debug messages, and automatize some tests. \ [ ] Having a working and reliable interrupt/exception handling system that can dump the contents of the registers (and perhaps the address of the fault) will be very useful. \ diff --git a/build.sh b/build.sh index 75f630a..8a15692 100755 --- a/build.sh +++ b/build.sh @@ -9,6 +9,9 @@ SRC_DIR=src BUILD_DIR=build +# clean old build +rm build/* + # Execute build i686-elf-as $SRC_DIR/boot.s -o $BUILD_DIR/boot.o i686-elf-gcc -c $SRC_DIR/kernel.c -o $BUILD_DIR/kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra diff --git a/src/kernel.c b/src/kernel.c index f75f1b4..c06aa3a 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -46,20 +46,36 @@ void kterm_putat (char c, uint8_t color, size_t x, size_t y ) { } -void kterm_put (char c) { - // add newline support - if ( c == '\n'){ - kterm_column = 0; - kterm_row++; - return; - } - kterm_putat ( c, kterm_color, kterm_column, kterm_row); - if(kterm_column++ == VGA_WIDTH ){ +/** + * With the help from: + * https://whiteheadsoftware.dev/operating-systems-development-for-dummies/ + **/ +void kterm_scrollup(){ + size_t i ; + for(i=0; i < (VGA_WIDTH * VGA_HEIGHT - VGA_WIDTH); i++) + kterm_buffer[i] = kterm_buffer[i+VGA_WIDTH]; + + for( i=0; i< VGA_WIDTH; i++) + kterm_buffer[(VGA_HEIGHT -1) * VGA_WIDTH + i ] = vga_entry(' ', kterm_color); + +} + +void kterm_put (char c) { + + if(++kterm_column == VGA_WIDTH || c == '\n' ) { kterm_column = 0; - if(kterm_row++ == VGA_HEIGHT) - kterm_row = 0; + if(kterm_row == VGA_HEIGHT-1) { + kterm_scrollup(); + } else { + kterm_row ++; + } + } + + if(c == '\n') return; + kterm_putat ( c, kterm_color, kterm_column, kterm_row); + } @@ -71,15 +87,34 @@ void kterm_write(const char* data, size_t size) { void kterm_writestring(const char* data ){ + + //#define KernelTag "[Kernel]: " + //kterm_write(KernelTag, strlen(KernelTag)); + kterm_write(data, strlen(data)); } +/** + * simple delay function + **/ +void delay(int t){ + volatile int i,j; + for(i=0;i