#include "type.h" #include "const.h" #include "protect.h" #include "string.h" #include "proc.h" #include "tty.h" #include "console.h" #include "global.h" #include "proto.h" #include "keyboard.h" #include "x86.h" #include "memman.h" #include "stdio.h" #include "serialport.h" #include "bga.h" static int _cursor_x = 0; static int _cursor_y = 0; static int _fbwidth = 0; static int _fbheight = 0; static int _fbpixels_per_row = 0; static int _fbscale = 1; static uint32_t _basecolor = 0x0; static uintptr_t _fb_paddr = 0; volatile uint32_t* _fb = NULL; #include "font8x8.h" static void update_cursor_position(char c) { _cursor_x += 8 * _fbscale; if (c == '\n' || (_cursor_x + 8 * _fbscale) > _fbwidth) { _cursor_y += 8 * _fbscale; _cursor_x = 0; if ((_cursor_y + 8 * _fbscale + 2) > _fbheight) { _cursor_y = 0; } } } static void draw_cursor() { for (int x = 0; x < (8 * _fbscale); x++) { for (int y = 0; y < (8 * _fbscale); y++) { uint32_t ind = (_cursor_x + x) + ((_cursor_y + y) * _fbpixels_per_row); uint32_t clr = _basecolor; if (font8x8_basic[0][y / _fbscale] & (1 << (x / _fbscale))) { clr ^= 0xffffffff; } _fb[ind] = clr; } } } static void draw_char_on_screen(char c) { for (int x = 0; x < (8 * _fbscale); x++) { for (int y = 0; y < (8 * _fbscale); y++) { uint32_t ind = (_cursor_x + x) + ((_cursor_y + y) * _fbpixels_per_row); uint32_t clr = _basecolor; if (font8x8_basic[c & 0x7f][y / _fbscale] & (1 << (x / _fbscale))) { clr ^= 0xffffffff; } _fb[ind] = clr; } } update_cursor_position(c); } int screen_setup() { _cursor_x = 0; _cursor_y = 0; _fb = (uint32_t*)bga_ioctl(BGA_GET_BUFFER, 0); _fb_paddr = bga_ioctl(BGA_GET_BUFFER, 0); _fbwidth = bga_ioctl(BGA_GET_WIDTH, 0); _fbheight = bga_ioctl(BGA_GET_HEIGHT, 0); _fbpixels_per_row = _fbwidth; _fbscale = 2; return 0; } void task_tty() { // main rountine for drawing framebuffered console char text1[] = "hello world\n shit\b idiot\n retard fuckyou\n"; char text2[] = "shabi ni\n ni zhe ge zhi zhangg\b ma de la ji wan yi er\n"; screen_setup(); mmap((u32)_fb, _fb_paddr, _fbwidth * _fbheight * 4 * 2); for (char* p = text1; *p; ++ p){ draw_char_on_screen(*p); } for (char* p = text2; *p; ++ p){ draw_char_on_screen(*p); } draw_cursor(); while (1) { } }