summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
author0x221E <0x221E@0xinfinity.dev>2026-06-11 20:10:31 +0200
committer0x221E <0x221E@0xinfinity.dev>2026-06-11 20:11:56 +0200
commit6d559b7e50dbab428d324b4ddaed9db7a8ced887 (patch)
treec2e807a19d2d0b6054e13a6d3ece16750796198d /lib
downloadtmpbootloader-master.tar.gz
initial commitHEADmaster
Diffstat (limited to 'lib')
-rw-r--r--lib/printk.c36
-rw-r--r--lib/string.c13
-rw-r--r--lib/vga.c23
3 files changed, 72 insertions, 0 deletions
diff --git a/lib/printk.c b/lib/printk.c
new file mode 100644
index 0000000..e2ae612
--- /dev/null
+++ b/lib/printk.c
@@ -0,0 +1,36 @@
+#include <printk.h>
+
+#include <string.h>
+#include <vga.h>
+
+#include <stddef.h>
+
+void write(char *s, uint8_t color)
+{
+ static size_t x BLSEC_DATA = 0;
+ static size_t y BLSEC_DATA = 0;
+
+ size_t len = strlen(s);
+ for (size_t i = 0; i < len; i++) {
+
+ if (s[i] == '\n') {
+ y++;
+ x = 0;
+ continue;
+ }
+
+ vga_put(x, y, s[i], color);
+
+ if (y >= MAX_HEIGHT)
+ return; //TODO: To be implemented.
+
+
+ if (x >= MAX_WIDTH) {
+ y++;
+ x = 0;
+ } else {
+ x++;
+ }
+
+ }
+}
diff --git a/lib/string.c b/lib/string.c
new file mode 100644
index 0000000..b48ffc0
--- /dev/null
+++ b/lib/string.c
@@ -0,0 +1,13 @@
+#include <string.h>
+
+size_t strlen(char* s)
+{
+ int pos=0;
+
+ while (s[pos]) {
+
+ pos++;
+ }
+
+ return pos;
+}
diff --git a/lib/vga.c b/lib/vga.c
new file mode 100644
index 0000000..9727025
--- /dev/null
+++ b/lib/vga.c
@@ -0,0 +1,23 @@
+#include <vga.h>
+#include <stddef.h>
+
+static uint16_t* vga_buffer BLSEC_DATA = VGA_MEMORY_ADDR;
+
+void vga_setup(int xmax, int ymax)
+{
+ for (size_t i = 0; i < MAX_WIDTH; i++) {
+ for (size_t j = 0; j < MAX_HEIGHT; j++) {
+ vga_put(i, j, ' ', 0);
+ }
+ }
+}
+
+uint8_t vga_color(uint8_t fg, uint8_t bg)
+{
+ return (uint8_t) fg | (uint8_t) bg << 4;
+}
+
+void vga_put(uint32_t x, uint32_t y, unsigned char uc, uint8_t color)
+{
+ vga_buffer[y*80+x] = (uint16_t) uc | (uint16_t) color << 8;
+}