From 64aa82592c6c2b043d8c62100d4ce110bf616c1e Mon Sep 17 00:00:00 2001 From: James Barnett Date: Sun, 6 Oct 2019 12:56:26 +0100 Subject: Add os statusbar. Start stdlib --- Makefile | 3 +- kernel/gpu/text_mode/display.c | 60 ++++++++++++++++++++++++++------------ kernel/gpu/text_mode/display.h | 9 ++++-- os/main.c | 65 ++++++++++++++++++++++++++++++++++++++---- os/stdlib/sdtlib.h | 1 + os/stdlib/stdlib.c | 21 ++++++++++++++ 6 files changed, 133 insertions(+), 26 deletions(-) create mode 100644 os/stdlib/sdtlib.h create mode 100644 os/stdlib/stdlib.c diff --git a/Makefile b/Makefile index d2c3019..a5d0449 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ build: setup kernel/kernel.c kernel/global_descriptor_table.c kernel/gpu/text_mo $(CC) $(CFLAGS) -c kernel/io/keyboard/keyboard_handler.c -o bin/keyboard_handler.o $(CC) $(CFLAGS) -c os/main.c -o bin/main.o $(CC) $(CFLAGS) -c os/shell/shell.c -o bin/shell.o + $(CC) $(CFLAGS) -c os/stdlib/stdlib.c -o bin/stdlib.o ld -m elf_i386 -T link.ld -o bin/kernel.bin bin/*.o clean: @@ -23,7 +24,7 @@ clean: rm -f tinyOS.iso run: - qemu-system-i386 -kernel bin/kernel.bin + cpulimit -l 20 qemu-system-i386 -kernel bin/kernel.bin build-and-run: build run diff --git a/kernel/gpu/text_mode/display.c b/kernel/gpu/text_mode/display.c index bacd9df..3758c71 100644 --- a/kernel/gpu/text_mode/display.c +++ b/kernel/gpu/text_mode/display.c @@ -39,32 +39,22 @@ void scrn_clear() cursor_pos = 0; } -void scrn_print(char *msg) +void scrn_set_text_colour(int foreground, int background) { - int j = 0; - while (msg[j] != '\0') - { - video_ram[cursor_pos++] = msg[j]; - video_ram[cursor_pos++] = char_attribute_byte; - ++j; - } + char_attribute_byte = (background << 4) | foreground; } -void scrn_println(char *msg) -{ - scrn_print(msg); - int current_line = cursor_pos / COLS; - cursor_pos = (current_line + 1) * COLS; +int scrn_get_char_attr_byte() { + return char_attribute_byte; } -void scrn_set_text_colour(int foreground, int background) -{ - char_attribute_byte = (background << 4) | foreground; +void scrn_set_char_attr_byte(int byte) { + char_attribute_byte = byte; } -void scrn_putchar(unsigned char byte) +void scrn_putchar(unsigned char c) { - video_ram[cursor_pos++] = byte; + video_ram[cursor_pos++] = c; video_ram[cursor_pos++] = char_attribute_byte; scrn_update_csr(); } @@ -87,3 +77,37 @@ void scrn_newline() scrn_update_csr(); } +void scrn_print(char *msg) +{ + int j = 0; + while (msg[j] != '\0') + { + video_ram[cursor_pos++] = msg[j]; + video_ram[cursor_pos++] = char_attribute_byte; + ++j; + } + scrn_update_csr(); +} + +void scrn_println(char *msg) +{ + scrn_print(msg); + scrn_newline(); +} + +void scrn_set_cursor_pos(unsigned int row, unsigned int col) +{ + cursor_pos = (row * COLS) + (col * 2); + scrn_update_csr(); +} + +int scrn_get_cursor_row() +{ + // 0 index + return cursor_pos / COLS; +} + +int scrn_get_cursor_col() +{ + return (cursor_pos % COLS)/2; +} \ No newline at end of file diff --git a/kernel/gpu/text_mode/display.h b/kernel/gpu/text_mode/display.h index fec3314..9c76499 100644 --- a/kernel/gpu/text_mode/display.h +++ b/kernel/gpu/text_mode/display.h @@ -3,6 +3,11 @@ void scrn_clear(); void scrn_print(char *msg); void scrn_println(char *msg); void scrn_set_text_colour(int foreground, int background); -void scrn_putchar(unsigned char byte); +int scrn_get_char_attr_byte(); +void scrn_set_char_attr_byte(int byte); +void scrn_putchar(unsigned char c); void scrn_backspace(); -void scrn_newline(); \ No newline at end of file +void scrn_newline(); +void scrn_set_cursor_pos(unsigned int row, unsigned int col); +int scrn_get_cursor_row(); +int scrn_get_cursor_col(); \ No newline at end of file diff --git a/os/main.c b/os/main.c index 905b0f7..b04ee62 100644 --- a/os/main.c +++ b/os/main.c @@ -2,13 +2,12 @@ #include "../kernel/gpu/text_mode/colours.h" #include "main.h" #include "./shell/shell.h" +#include "./stdlib/sdtlib.h" Program_t focused_program; void os_show_splash() { - scrn_enable_cursor(10, 12); - scrn_clear(); scrn_set_text_colour(COLOUR_LIGHT_GREEN, COLOUR_BLACK); scrn_println(" _ _ ____ _____ "); @@ -24,19 +23,75 @@ void os_show_splash() scrn_newline(); } -void os_start() +void line_pad(unsigned int width) { - os_show_splash(); + for(int i = 0; i < width; i++) + { + scrn_putchar(' '); + } +} + +void os_update_infobar_rc() +{ + + int curr_attr_byte = scrn_get_char_attr_byte(); + int curr_r = scrn_get_cursor_row(); + int curr_c = scrn_get_cursor_col(); + + scrn_set_text_colour(COLOUR_WHITE, COLOUR_BLUE); + scrn_set_cursor_pos(0, 64); + scrn_print("row "); + + if (curr_r < 9) { + scrn_print("0"); + } + scrn_print(int_to_str(curr_r +1)); + + scrn_print(", col "); + if (curr_c < 9) { + scrn_print("0"); + } + scrn_print(int_to_str(curr_c+1)); + + scrn_set_char_attr_byte(curr_attr_byte); + scrn_set_cursor_pos(curr_r, curr_c); +} + +void os_init_infobar() +{ + scrn_clear(); + scrn_set_cursor_pos(0, 0); + scrn_set_text_colour(COLOUR_WHITE, COLOUR_BLUE); + line_pad(80); // fill line + scrn_set_cursor_pos(0, 2); + scrn_print("tinyOS"); + scrn_set_cursor_pos(0, 30); + scrn_print("running: "); + scrn_print(focused_program.name); + + os_update_infobar_rc(); + scrn_set_text_colour(COLOUR_WHITE, COLOUR_BLACK); + scrn_set_cursor_pos(1, 0); } // TODO keep a stack of running programs void os_update_focused_program(Program_t program) { - focused_program = shell_run(); + focused_program = program; } // Send keypress from kernel to the currently focused programs keypress handler void os_proxy_keypress(unsigned char key) { (focused_program.keypress_handler)(key); + os_update_infobar_rc(); +} + +void os_start() +{ + os_update_focused_program(shell_run()); + scrn_enable_cursor(10, 12); + os_init_infobar(); + os_show_splash(); + os_update_infobar_rc(); } // TODO display handling \ No newline at end of file diff --git a/os/stdlib/sdtlib.h b/os/stdlib/sdtlib.h new file mode 100644 index 0000000..a0b3402 --- /dev/null +++ b/os/stdlib/sdtlib.h @@ -0,0 +1 @@ +char* int_to_str(int i); \ No newline at end of file diff --git a/os/stdlib/stdlib.c b/os/stdlib/stdlib.c new file mode 100644 index 0000000..465e978 --- /dev/null +++ b/os/stdlib/stdlib.c @@ -0,0 +1,21 @@ +char* int_to_str(int i) +{ + // Room for 4 byte int, -ve sign and null terminator + static char buf[12]; + char *p = buf + 11; // points to null terminator + if (i >= 0) { + do { + *--p = '0' + (i % 10); + i /= 10; + } while (i != 0); + return p; + } + else { + do { + *--p = '0' - (i % 10); + i /= 10; + } while (i != 0); + *--p = '-'; + } + return p; +} \ No newline at end of file -- cgit v1.2.3