54 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #include <stdint.h>
 | |
| #include <terminal.h>
 | |
| #include <mittos/graphics.h>
 | |
| #include <memory.h>
 | |
| 
 | |
| gfx_context kernel_fb;
 | |
| gfx_context *term_fb;
 | |
| static int setup = 0;
 | |
| 
 | |
| void fbterm_movecursor(unsigned int cursor) {
 | |
|     (void) cursor;
 | |
| }
 | |
| 
 | |
| void fbterm_flush(struct vga_cell *buffer) {
 | |
|     if(!setup) return;
 | |
|     int i = 0;
 | |
|     for(int row = 0; row < VGA_ROWS; row++) {
 | |
|         for(int col=0; col < VGA_COLS; col++) {
 | |
|             putCharacter(term_fb, col*8, row*16, 0xebdbb2, 0x282828, (char)buffer[i++].c);
 | |
|         }
 | |
|     }
 | |
|     flip(term_fb);
 | |
| }
 | |
| 
 | |
| void fbterm_init(struct fbinfo *fbinfo) {
 | |
|     kernel_fb.width = fbinfo->framebuffer_width;
 | |
|     kernel_fb.height = fbinfo->framebuffer_height;
 | |
|     kernel_fb.bpp = fbinfo->framebuffer_bpp/8;
 | |
|     kernel_fb.pitch = fbinfo->framebuffer_pitch/kernel_fb.bpp;
 | |
|     kernel_fb.addr = P2V(fbinfo->framebuffer_addr);
 | |
|     kernel_fb.size = fbinfo->framebuffer_pitch * (kernel_fb.height);
 | |
|     kernel_fb.buffer = calloc(1, kernel_fb.size);
 | |
| 
 | |
|     for(
 | |
|         uintptr_t p = (uintptr_t)kernel_fb.addr;
 | |
|         p < ((uintptr_t)kernel_fb.addr + kernel_fb.size);
 | |
|         p += PAGE_SIZE
 | |
|     ) {
 | |
|         vmm_set_page(kernel_P4, p, V2P(p), PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT);
 | |
|     }
 | |
| 
 | |
|     draw_rect(&kernel_fb, 20, 20, 8*VGA_COLS+8, 16*VGA_ROWS+8, RGB(255, 0, 0));
 | |
|     flip(&kernel_fb);
 | |
|     term_fb = framebuffer_make_subcontext(&kernel_fb, 24, 24, 8*VGA_COLS, 16*VGA_ROWS);
 | |
|     flip(term_fb);
 | |
|     setup = 1;
 | |
| 
 | |
|     draw_line(&kernel_fb, 750, 850, 120, 120, RGB(255,0,0));
 | |
|     draw_line(&kernel_fb, 750, 750, 120, 220, RGB(0,255,0));
 | |
|     draw_line(&kernel_fb, 750, 850, 120, 220, RGB(0,0,255));
 | |
|     draw_line(&kernel_fb, 750, 800, 120, 220, RGB(255,0,255));
 | |
|     draw_line(&kernel_fb, 750, 850, 120, 170, RGB(255,255,0));
 | |
|     flip(&kernel_fb);
 | |
| } |