diff --git a/build_numbers.c b/build_numbers.c index 8382ced..f3f19aa 100644 --- a/build_numbers.c +++ b/build_numbers.c @@ -1,3 +1,3 @@ #ifndef KERNEL_VERSION_NUMBER -#define KERNEL_VERSION_NUMBER "0.0.1-276" +#define KERNEL_VERSION_NUMBER "0.0.1-293" #endif diff --git a/kernel/kmain.c b/kernel/kmain.c index c1a5654..c767f3e 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -11,6 +11,14 @@ void kmain() draw_rect(10, 5, 15, 13, 0x8, 0x6); draw_rect(20, 5, 25, 7, 0xF, 0x1); draw_rect(20, 8, 25, 13, 0x5, 0x3); + set_cursor(0, 14); + move_cursor(0, 14); + move_cursor(0, 15); + draw_s("Test print", 0x8, 0xF); + move_cursor(0, 16); + draw_s("And now the cursor has been moved to y = 16.", 0x1, 0xF); + move_cursor(5, 20); + draw_s("Cursor moved over 5 cells and down 4 cells.", 0xF, 0x0); //draw_rect(20, 5, 50, 7, 0x4, 0xF); //draw_rect(20, 5, 50, 7, 0x4, 0xF); //draw_rect(20, 5, 50, 7, 0x4, 0xF); @@ -30,6 +38,7 @@ void write_screen(unsigned int i, char c, unsigned char fg, unsigned char bg) void move(unsigned short pos) { + outb(0x3D4, 14); outb(0x3D5, ((pos >> 8 ) & 0x00FF)); outb(0x3D4, 15); diff --git a/kernel/screen.c b/kernel/screen.c index 1511193..cd327f2 100644 --- a/kernel/screen.c +++ b/kernel/screen.c @@ -1,9 +1,11 @@ #include "../includes/screen.h" #include "../build_numbers.c" -unsigned char row = 1; -unsigned char column = 0; +unsigned char cursor_x = 0; +unsigned char cursor_y = 0; unsigned char screen_width = 80; +char column = -1; +unsigned char row = 0; void print_banner(){ @@ -55,32 +57,43 @@ void draw_rect(int start_x, int start_y, int end_x, int end_y, unsigned char fg, for(unsigned char i = 0; i < y; i++){ for(unsigned char j = 0; j < x; j++){ unsigned short *where = (unsigned short*) buffer + (i * 80) + j; - *where = 0x23 | (attr << 8); + *where = ' ' | (attr << 8); } } } void draw_s(char* string, unsigned char fg, unsigned char bg) { - char *video_buffer = 0x000B8000; - + unsigned short *video_buffer = 0x000B8000; + int attr = ((bg << 4) | (fg & 0x0F)); for(int i = 0; i < strlen(string); i++) { - char current_char = string[i]; + unsigned char current_char = string[i]; + unsigned short *where = (unsigned short *) video_buffer + (cursor_y * 80) + i + cursor_x; if(current_char == '\n'){ - //row++; - column = row * column; - row++; + cursor_y++; continue; } - video_buffer[i*2 + (row * column)] = string[i]; - video_buffer[i * 2 + 1 + (row * column)] = ((fg & 0x0f) << 4) | (bg & 0x0F); - //column++; + *where = string[i] | attr << 8; } } +void set_cursor(unsigned char x, unsigned char y){ + cursor_x = x; + cursor_y = y; +} + +void move_cursor(unsigned char x, unsigned char y){ + if(column != -1) draw_rect(cursor_x, cursor_y, cursor_x + 1, cursor_y + 1, 0x2, 0x8); + + cursor_x = x; + cursor_y = y; + + draw_rect(x, y, x + 1, y + 1, 0x0, 0xF); +} + void clear_screen(){ char *video_buffer = 0x000B8000;