aboutsummaryrefslogtreecommitdiff
path: root/kernel/gpu/text_mode/display.c
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2019-05-26 15:32:53 +0100
committerJames Barnett <noreply@jamesbarnett.xyz>2019-05-26 15:32:53 +0100
commitc68b5b688db76e00126302bbac669a5639949943 (patch)
tree1260c4fc3c4ea24a5bdfbcc3652670e33a74d71c /kernel/gpu/text_mode/display.c
parentef0c2b2bfe2de7721674521f11c583f943f77461 (diff)
downloadtinyOS-c68b5b688db76e00126302bbac669a5639949943.tar.xz
tinyOS-c68b5b688db76e00126302bbac669a5639949943.zip
Reorganise files
Diffstat (limited to 'kernel/gpu/text_mode/display.c')
-rw-r--r--kernel/gpu/text_mode/display.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/kernel/gpu/text_mode/display.c b/kernel/gpu/text_mode/display.c
new file mode 100644
index 0000000..3659e60
--- /dev/null
+++ b/kernel/gpu/text_mode/display.c
@@ -0,0 +1,64 @@
+#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 scrn_clear()
+{
+ for (int i = 0; i < FRAME_SIZE; i = i + 2)
+ {
+ video_ram[i] = ' ';
+ video_ram[i + 1] = char_attribute_byte;
+ };
+ cursor_pos = 0;
+}
+
+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;
+ }
+}
+
+void scrn_println(char *msg)
+{
+ scrn_print(msg);
+ int current_line = cursor_pos / COLS;
+ cursor_pos = (current_line + 1) * COLS;
+}
+
+void scrn_set_text_colour(int foreground, int background)
+{
+ char_attribute_byte = (background << 4) | foreground;
+}
+
+void scrn_putchar(unsigned char byte)
+{
+ video_ram[cursor_pos++] = byte;
+ video_ram[cursor_pos++] = char_attribute_byte;
+}
+
+// TODO - jump cursor to prev non 0 text char rather than reversing through whole array
+void scrn_backspace()
+{
+ if (cursor_pos != 0)
+ {
+ video_ram[--cursor_pos] = char_attribute_byte;
+ video_ram[--cursor_pos] = 0;
+ }
+}
+
+void scrn_newline()
+{
+ int current_line = cursor_pos / COLS;
+ cursor_pos = (current_line + 1) * COLS;
+} \ No newline at end of file