aboutsummaryrefslogtreecommitdiff
path: root/devices/vga.c
diff options
context:
space:
mode:
Diffstat (limited to 'devices/vga.c')
-rw-r--r--devices/vga.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/devices/vga.c b/devices/vga.c
new file mode 100644
index 0000000..983e630
--- /dev/null
+++ b/devices/vga.c
@@ -0,0 +1,35 @@
+#include "vga.h"
+#include <stddef.h>
+#include <stdint.h>
+
+struct __attribute__((packed)) VGAEntry {
+ unsigned char text;
+ uint8_t foreground : 4;
+ uint8_t background : 4;
+};
+
+_Static_assert(sizeof(struct VGAEntry) == 2);
+
+const size_t width = 80;
+const size_t height = 25;
+
+struct VGAEntry *buffer;
+
+void
+vga_init()
+{
+ buffer = (struct VGAEntry *)0xc03ff000;
+ vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY);
+}
+
+void
+vga_clear(enum vga_color foreground, enum vga_color background)
+{
+ for (size_t y = 0; y < height; ++y)
+ for (size_t x = 0; x < width; ++x) {
+ const size_t index = y * width + x;
+ buffer[index].text = ' ';
+ buffer[index].foreground = foreground;
+ buffer[index].background = background;
+ }
+}