Moved some Kernel Terminal stuff to a seperate header file(s)

This commit is contained in:
nigel 2021-05-02 13:38:18 -04:00
parent 28288545db
commit 5bd25a3737
3 changed files with 74 additions and 42 deletions

View File

@ -1,16 +1,37 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "vga_colors.h"
#include "string.h"
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
#include "kernel.h"
#include "kterm.h"
size_t kterm_row;
size_t kterm_column;
uint8_t kterm_color;
uint16_t* kterm_buffer;
/**
* 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 */
kterm_init();
/** Wrtite stuff to the screen to test the terminal**/
kterm_writestring("Hello world!\n");
kterm_writestring("We got newline support!\n");
for(;;){
delay(500);
kterm_writestring("We have implemented terminal scrolling!\n");
}
}
/**
* KTerm stuff
**/
static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) {
return fg | bg << 4;
@ -20,7 +41,7 @@ static inline uint16_t vga_entry (unsigned char uc, uint8_t color) {
return (uint16_t) uc | (uint16_t) color << 8;
}
void init_kterm () {
void kterm_init () {
kterm_row = 0;
kterm_column = 0;
kterm_color = vga_entry_color ( VGA_COLOR_LIGHT_GREY , VGA_COLOR_BLACK);
@ -35,6 +56,10 @@ void init_kterm () {
}
void kterm_resetcolor(){
kterm_color = vga_entry_color ( VGA_COLOR_LIGHT_GREY , VGA_COLOR_BLACK);
}
void kterm_setcolor(uint8_t color){
kterm_color = color;
}
@ -87,34 +112,6 @@ void kterm_write(const char* data, size_t size) {
void kterm_writestring(const char* data ){
//#define KernelTag "[Kernel]: "
//kterm_write(KernelTag, strlen(KernelTag));
AS_KERNEL();
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();
/** 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!");
}
}
}

24
src/kernel.h Normal file
View File

@ -0,0 +1,24 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "string.h"
#define KernelTag "[Kernel]: "
#define AS_KERNEL() ( kterm_setcolor(VGA_COLOR_LIGHT_BLUE),\
kterm_write(KernelTag, strlen(KernelTag)), \
kterm_resetcolor())
void kterm_init();
void kterm_resetcolor();
void kterm_setcolor(uint8_t);
void kterm_putat(char, uint8_t, size_t, size_t);
void kterm_put(char);
void kterm_write(const char*, size_t);
void kterm_writestring(const char*);
void kterm_scrollup();

11
src/kterm.h Normal file
View File

@ -0,0 +1,11 @@
#include <stdint.h>
#include <stddef.h>
#include "vga_colors.h"
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
size_t kterm_row;
size_t kterm_column;
uint8_t kterm_color;
uint16_t* kterm_buffer;