Timer re-worked!
[lunaix-os.git] / lunaix-os / kernel / tty / tty.c
index cb4e13a1d21954182363b280b2ca84c1d6bf6487..cc70087992a14ed4c9167ec3d29de89a15f667d7 100644 (file)
@@ -1,17 +1,17 @@
-#include <libc/string.h>
+#include <klibc/string.h>
 #include <lunaix/tty/tty.h>
-#include <lunaix/constants.h>
+#include <lunaix/common.h>
 #include <stdint.h>
 
 #define TTY_WIDTH 80
 #define TTY_HEIGHT 25
 
-vga_attribute* tty_vga_buffer = (vga_attribute*)VGA_BUFFER_PADDR;
+static vga_attribute* tty_vga_buffer = (vga_attribute*)VGA_BUFFER_PADDR;
 
-vga_attribute tty_theme_color = VGA_COLOR_BLACK;
+static vga_attribute tty_theme_color = VGA_COLOR_BLACK;
 
-uint32_t tty_x = 0;
-uint16_t tty_y = 0;
+static uint32_t tty_x = 0;
+static uint16_t tty_y = 0;
 
 void tty_init(void* vga_buf) {
     tty_vga_buffer = (vga_attribute*)vga_buf;
@@ -69,11 +69,11 @@ void
 tty_scroll_up()
 {
     size_t last_line = TTY_WIDTH * (TTY_HEIGHT - 1);
-    memcpy(tty_vga_buffer, tty_vga_buffer + TTY_WIDTH, last_line);
+    memcpy(tty_vga_buffer, tty_vga_buffer + TTY_WIDTH, last_line * 2);
     for (size_t i = 0; i < TTY_WIDTH; i++) {
         *(tty_vga_buffer + i + last_line) = tty_theme_color;
     }
-    tty_y = tty_y == 0 ? 0 : tty_y - 1;
+    tty_y = tty_y == 0 ? 0 : TTY_HEIGHT - 1;
 }
 
 void
@@ -84,4 +84,29 @@ tty_clear()
     }
     tty_x = 0;
     tty_y = 0;
+}
+
+void
+tty_clear_line(unsigned int y) {
+    for (size_t i = 0; i < TTY_WIDTH; i++)
+    {
+        *(tty_vga_buffer + i + y * TTY_WIDTH) = tty_theme_color;
+    }
+}
+
+void
+tty_set_cpos(unsigned int x, unsigned int y) {
+    tty_x = x % TTY_WIDTH;
+    tty_y = y % TTY_HEIGHT;
+}
+
+void
+tty_get_cpos(unsigned int* x, unsigned int* y) {
+    *x = tty_x;
+    *y = tty_y;
+}
+
+vga_attribute
+tty_get_theme() {
+    return tty_theme_color;
 }
\ No newline at end of file