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;
16 asm volatile("rep stosw" ::"D"(tty_vga_buffer),
17 "c"(TTY_HEIGHT * TTY_WIDTH),
23 tty_init(void* vga_buf)
25 tty_vga_buffer = (vga_attribute*)vga_buf;
30 io_outb(0x3D5, (io_inb(0x3D5) & 0xC0) | 13);
33 io_outb(0x3D5, (io_inb(0x3D5) & 0xE0) | 15);
37 tty_set_theme(vga_attribute fg, vga_attribute bg)
39 tty_theme_color = (bg << 4 | fg) << 8;
43 tty_flush_buffer(struct fifo_buf* buf)
53 vga_attribute current_theme = tty_theme_color;
54 while (fifo_readone_async(buf, &chr)) {
55 if (state == 0 && chr == '\033') {
57 } else if (state == 1 && chr == '[') {
59 } else if (state > 1) {
60 if ('0' <= chr && chr <= '9') {
61 g[state - 2] = (chr - '0') + g[state - 2] * 10;
62 } else if (chr == ';' && state == 2) {
65 if (g[0] == 39 && g[1] == 49) {
66 current_theme = tty_theme_color;
68 current_theme = (g[1] << 4 | g[0]) << 8;
87 // *(tty_vga_buffer + x + y * TTY_WIDTH) =
88 // (current_theme | 0x20);
91 *(tty_vga_buffer + x + y * TTY_WIDTH) =
92 (current_theme | chr);
101 if (y >= TTY_HEIGHT) {
107 tty_set_cursor(x, y);
111 tty_set_cursor(uint8_t x, uint8_t y)
113 if (x >= TTY_WIDTH || y >= TTY_HEIGHT) {
116 uint32_t pos = y * TTY_WIDTH + x;
118 io_outb(0x3D5, pos / 256);
120 io_outb(0x3D5, pos % 256);
124 tty_clear_line(int line_num)
126 asm volatile("rep stosw" ::"D"(tty_vga_buffer + line_num * TTY_WIDTH),
133 tty_put_str_at(char* str, int x, int y)
136 while ((c = (*str)) && y < TTY_HEIGHT) {
137 *(tty_vga_buffer + x + y * TTY_WIDTH) = c | tty_theme_color;
139 if (x >= TTY_WIDTH) {