1 #include <klibc/string.h>
2 #include <lunaix/spike.h>
3 #include <lunaix/tty/tty.h>
6 #include <sys/port_io.h>
8 vga_attribute* tty_vga_buffer;
10 vga_attribute tty_theme_color = VGA_COLOR_BLACK;
15 asm volatile("rep stosw" ::"D"(tty_vga_buffer),
16 "c"(TTY_HEIGHT * TTY_WIDTH),
22 tty_init(void* vga_buf)
24 tty_vga_buffer = (vga_attribute*)vga_buf;
28 port_wrbyte(0x3D4, 0x0A);
29 port_wrbyte(0x3D5, (port_rdbyte(0x3D5) & 0xC0) | 13);
31 port_wrbyte(0x3D4, 0x0B);
32 port_wrbyte(0x3D5, (port_rdbyte(0x3D5) & 0xE0) | 15);
36 tty_set_cursor(u8_t x, u8_t y)
38 if (x >= TTY_WIDTH || y >= TTY_HEIGHT) {
41 u32_t pos = y * TTY_WIDTH + x;
42 port_wrbyte(0x3D4, 14);
43 port_wrbyte(0x3D5, pos / 256);
44 port_wrbyte(0x3D4, 15);
45 port_wrbyte(0x3D5, pos % 256);
49 tty_set_theme(vga_attribute fg, vga_attribute bg)
51 tty_theme_color = (bg << 4 | fg) << 8;
55 tty_flush_buffer(struct fifo_buf* buf)
63 while (fifo_readone_async(buf, (u8_t*)&chr)) {
75 *(tty_vga_buffer + x + y * TTY_WIDTH) =
76 (tty_theme_color | chr);
85 if (y >= TTY_HEIGHT) {
95 tty_clear_line(int line_num)
97 asm volatile("rep stosw" ::"D"(tty_vga_buffer + line_num * TTY_WIDTH),
104 tty_put_str_at(char* str, int x, int y)
107 while ((c = (*str)) && y < TTY_HEIGHT) {
108 *(tty_vga_buffer + x + y * TTY_WIDTH) = c | tty_theme_color;
110 if (x >= TTY_WIDTH) {