2 #include <klibc/string.h>
3 #include <lunaix/common.h>
4 #include <lunaix/spike.h>
5 #include <lunaix/tty/console.h>
6 #include <lunaix/tty/tty.h>
9 vga_attribute* tty_vga_buffer = (vga_attribute*)VGA_BUFFER_PADDR;
11 vga_attribute tty_theme_color = VGA_COLOR_BLACK;
14 asm volatile("rep stosw" ::"D"(tty_vga_buffer), \
15 "c"(TTY_HEIGHT * TTY_WIDTH), \
16 "a"(tty_theme_color) \
20 tty_init(void* vga_buf)
22 tty_vga_buffer = (vga_attribute*)vga_buf;
27 io_outb(0x3D5, (io_inb(0x3D5) & 0xC0) | 13);
30 io_outb(0x3D5, (io_inb(0x3D5) & 0xE0) | 15);
34 tty_set_theme(vga_attribute fg, vga_attribute bg)
36 tty_theme_color = (bg << 4 | fg) << 8;
40 tty_flush_buffer(char* data, size_t pos, size_t limit, size_t buf_size)
49 vga_attribute current_theme = tty_theme_color;
51 size_t ptr = pos % buf_size;
56 if (state == 0 && chr == '\033') {
58 } else if (state == 1 && chr == '[') {
60 } else if (state > 1) {
61 if ('0' <= chr && chr <= '9') {
62 g[state - 2] = (chr - '0') + g[state - 2] * 10;
63 } else if (chr == ';' && state == 2) {
66 if (g[0] == 39 && g[1] == 49) {
67 current_theme = tty_theme_color;
69 current_theme = (g[1] << 4 | g[0]) << 8;
89 *(tty_vga_buffer + x + y * TTY_WIDTH) =
90 (current_theme | 0x20);
93 *(tty_vga_buffer + x + y * TTY_WIDTH) =
94 (current_theme | chr);
103 if (y >= TTY_HEIGHT) {
110 tty_set_cursor(x, y);
115 tty_set_cursor(uint8_t x, uint8_t y)
117 if (x >= TTY_WIDTH || y >= TTY_HEIGHT) {
120 uint32_t pos = y * TTY_WIDTH + x;
122 io_outb(0x3D5, pos / 256);
124 io_outb(0x3D5, pos % 256);
128 tty_clear_line(int line_num)
130 asm volatile("rep stosw" ::"D"(tty_vga_buffer + line_num * TTY_WIDTH),
137 tty_put_str_at(char* str, int x, int y)
140 while ((c = (*str)) && y < TTY_HEIGHT) {
141 *(tty_vga_buffer + x + y * TTY_WIDTH) = c | tty_theme_color;
143 if (x >= TTY_WIDTH) {