1 #include <klibc/string.h>
2 #include <lunaix/common.h>
3 #include <lunaix/spike.h>
4 #include <lunaix/tty/console.h>
5 #include <lunaix/tty/tty.h>
8 #include <sys/port_io.h>
10 vga_attribute* tty_vga_buffer;
12 vga_attribute tty_theme_color = VGA_COLOR_BLACK;
17 asm volatile("rep stosw" ::"D"(tty_vga_buffer),
18 "c"(TTY_HEIGHT * TTY_WIDTH),
24 tty_init(void* vga_buf)
26 tty_vga_buffer = (vga_attribute*)vga_buf;
30 port_wrbyte(0x3D4, 0x0A);
31 port_wrbyte(0x3D5, (port_rdbyte(0x3D5) & 0xC0) | 13);
33 port_wrbyte(0x3D4, 0x0B);
34 port_wrbyte(0x3D5, (port_rdbyte(0x3D5) & 0xE0) | 15);
38 tty_set_cursor(u8_t x, u8_t y)
40 if (x >= TTY_WIDTH || y >= TTY_HEIGHT) {
43 u32_t pos = y * TTY_WIDTH + x;
44 port_wrbyte(0x3D4, 14);
45 port_wrbyte(0x3D5, pos / 256);
46 port_wrbyte(0x3D4, 15);
47 port_wrbyte(0x3D5, pos % 256);
51 tty_set_theme(vga_attribute fg, vga_attribute bg)
53 tty_theme_color = (bg << 4 | fg) << 8;
57 tty_flush_buffer(struct fifo_buf* buf)
67 vga_attribute current_theme = tty_theme_color;
68 while (fifo_readone_async(buf, (u8_t*)&chr)) {
69 if (state == 0 && chr == '\033') {
71 } else if (state == 1 && chr == '[') {
73 } else if (state > 1) {
74 if ('0' <= chr && chr <= '9') {
75 g[state - 2] = (chr - '0') + g[state - 2] * 10;
76 } else if (chr == ';' && state == 2) {
79 if (g[0] == 39 && g[1] == 49) {
80 current_theme = tty_theme_color;
82 current_theme = (g[1] << 4 | g[0]) << 8;
101 // *(tty_vga_buffer + x + y * TTY_WIDTH) =
102 // (current_theme | 0x20);
105 *(tty_vga_buffer + x + y * TTY_WIDTH) =
106 (current_theme | chr);
111 if (x >= TTY_WIDTH) {
115 if (y >= TTY_HEIGHT) {
121 tty_set_cursor(x, y);
125 tty_clear_line(int line_num)
127 asm volatile("rep stosw" ::"D"(tty_vga_buffer + line_num * TTY_WIDTH),
134 tty_put_str_at(char* str, int x, int y)
137 while ((c = (*str)) && y < TTY_HEIGHT) {
138 *(tty_vga_buffer + x + y * TTY_WIDTH) = c | tty_theme_color;
140 if (x >= TTY_WIDTH) {