Implemented terminal scrolling

main
nigel 2021-05-02 13:14:31 -04:00
parent a9ecdbc6a6
commit 28288545db
3 changed files with 53 additions and 15 deletions

View File

@ -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. \

View File

@ -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

View File

@ -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<t;i++)
for(j=0;j<25000;j++)
asm("NOP");
}
void kernel_main (void) {
/** initialize terminal interface */
init_kterm();
kterm_writestring("K: Hello world!\n");
kterm_writestring("K: We got newline support!");
/** Wrtite stuff to the screen to test the terminal**/
kterm_writestring("Hello world!\n");
kterm_writestring("We got newline support!\n");
for(;;){
delay(100);
kterm_writestring("We have implemented terminal scrolling!");
}
}