1 #include <klibc/string.h>
2 #include <lunaix/spike.h>
3 #include <lunaix/tty/tty.h>
5 #include <lunaix/owloysius.h>
6 #include <lunaix/mm/pagetable.h>
7 #include <lunaix/mm/mmio.h>
9 #include <asm/x86_pmio.h>
11 vga_attribute* tty_vga_buffer;
13 vga_attribute tty_theme_color = VGA_COLOR_BLACK;
18 asm volatile("rep stosw" ::"D"(tty_vga_buffer),
19 "c"(TTY_HEIGHT * TTY_WIDTH),
25 tty_init(void* vga_buf)
27 tty_vga_buffer = (vga_attribute*)vga_buf;
31 port_wrbyte(0x3D4, 0x0A);
32 port_wrbyte(0x3D5, (port_rdbyte(0x3D5) & 0xC0) | 13);
34 port_wrbyte(0x3D4, 0x0B);
35 port_wrbyte(0x3D5, (port_rdbyte(0x3D5) & 0xE0) | 15);
39 tty_set_cursor(u8_t x, u8_t y)
41 if (x >= TTY_WIDTH || y >= TTY_HEIGHT) {
44 u32_t pos = y * TTY_WIDTH + x;
45 port_wrbyte(0x3D4, 14);
46 port_wrbyte(0x3D5, pos / 256);
47 port_wrbyte(0x3D4, 15);
48 port_wrbyte(0x3D5, pos % 256);
52 tty_set_theme(vga_attribute fg, vga_attribute bg)
54 tty_theme_color = (bg << 4 | fg) << 8;
58 tty_flush_buffer(struct fifo_buf* buf)
66 while (fifo_readone_async(buf, (u8_t*)&chr)) {
78 *(tty_vga_buffer + x + y * TTY_WIDTH) =
79 (tty_theme_color | chr);
88 if (y >= TTY_HEIGHT) {
98 tty_clear_line(int line_num)
100 asm volatile("rep stosw" ::"D"(tty_vga_buffer + line_num * TTY_WIDTH),
107 tty_put_str_at(char* str, int x, int y)
110 while ((c = (*str)) && y < TTY_HEIGHT) {
111 *(tty_vga_buffer + x + y * TTY_WIDTH) = c | tty_theme_color;
113 if (x >= TTY_WIDTH) {
124 // FIXME we should get rid of it at some point
125 tty_init((void*)ioremap(0xB8000, PAGE_SIZE));
126 tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
128 owloysius_fetch_init(vga_rawtty_init, on_earlyboot);