diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2018-08-28 18:02:17 +0100 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2018-08-28 18:02:17 +0100 |
| commit | 326526206eface026e6ec291d75cd037dbec6609 (patch) | |
| tree | 3b7236a4024ba183d9f512b51072343436dbdbfa /kernel/io/vga/text_mode_display.c | |
| parent | d5cf6a9696f6f86bec5652f94ba7485aae4ca1bc (diff) | |
| download | tinyOS-326526206eface026e6ec291d75cd037dbec6609.tar.xz tinyOS-326526206eface026e6ec291d75cd037dbec6609.zip | |
Add text colour manipulation
Diffstat (limited to 'kernel/io/vga/text_mode_display.c')
| -rw-r--r-- | kernel/io/vga/text_mode_display.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/kernel/io/vga/text_mode_display.c b/kernel/io/vga/text_mode_display.c new file mode 100644 index 0000000..958eb87 --- /dev/null +++ b/kernel/io/vga/text_mode_display.c @@ -0,0 +1,42 @@ +#include "colours.h" + +#define COLS (80 * 2) // 2 bytes per char +#define ROWS 25 +#define FRAME_SIZE (ROWS * COLS) + +char *video_ram = (char *)0xB8000; +int cursor_pos = 0; +int char_attribute_byte = 0x07; + +void clear_screen() +{ + for (int i = 0; i < FRAME_SIZE; i = i + 2) + { + video_ram[i] = ' '; + video_ram[i + 1] = char_attribute_byte; + }; + cursor_pos = 0; +} + +void print(char *msg) +{ + int j = 0; + while (msg[j] != '\0') + { + video_ram[cursor_pos++] = msg[j]; + video_ram[cursor_pos++] = char_attribute_byte; + ++j; + } +} + +void print_ln(char *msg) +{ + print(msg); + int current_line = cursor_pos / COLS; + cursor_pos = (current_line + 1) * COLS; +} + +void set_text_colour(int foreground, int background) +{ + char_attribute_byte = (background << 4) | foreground; +}
\ No newline at end of file |