greatbridf 4 жил өмнө
parent
commit
a55ce6a3d1

+ 2 - 0
include/kernel/vga.h

@@ -10,6 +10,8 @@ struct vga_char {
 };
 
 #define VGA_MEM ((struct vga_char*)0xb8000)
+#define VGA_SCREEN_WIDTH_IN_CHARS (80U)
+#define VGA_SCREEN_HEIGHT_IN_CHARS (25U)
 
 void vga_put_char(struct vga_char* c);
 void vga_printk(const int8_t* str, uint8_t color);

+ 13 - 1
src/kernel/vga.c

@@ -1,6 +1,7 @@
 #define _KERNEL_VGA_C_
 #include <types/stdint.h>
 
+#include <kernel/stdio.h>
 #include <kernel/vga.h>
 
 static struct vga_char* p_vga_head = VGA_MEM;
@@ -11,11 +12,22 @@ void vga_put_char(struct vga_char* c)
     ++p_vga_head;
 }
 
+void vga_new_line()
+{
+    int32_t offset = p_vga_head - VGA_MEM;
+    offset %= VGA_SCREEN_WIDTH_IN_CHARS;
+    p_vga_head += (VGA_SCREEN_WIDTH_IN_CHARS - offset);
+}
+
 void vga_printk(const int8_t* str, uint8_t color)
 {
     struct vga_char s_c;
     s_c.color = color;
     while ((s_c.c = *(str++)) != 0x00) {
-        vga_put_char(&s_c);
+        if (s_c.c == '\n') {
+            vga_new_line();
+        } else {
+            vga_put_char(&s_c);
+        }
     }
 }

+ 3 - 3
src/kernel_main.c

@@ -11,12 +11,12 @@ void kernel_main(void)
     result = check_a20_on();
 
     if (result) {
-        vga_printk((const int8_t*)"ON", 0x0fU);
+        vga_printk((const int8_t*)"A20 is ON\n", 0x0fU);
     } else {
-        vga_printk((const int8_t*)"NOT ON", 0x0fU);
+        vga_printk((const int8_t*)"A20 is NOT ON\n", 0x0fU);
     }
 
-    vga_printk((const int8_t*)"No work to do, halting...", 0x0fU);
+    vga_printk((const int8_t*)"No work to do, halting...\n", 0x0fU);
 
 _loop:
     asm("hlt");