diff --git a/src/kernel/drivers/framebuffer.c b/src/kernel/drivers/framebuffer.c index 88bfad4..c3f6b25 100644 --- a/src/kernel/drivers/framebuffer.c +++ b/src/kernel/drivers/framebuffer.c @@ -2,10 +2,9 @@ #include #include #include +#include gfx_context kernel_fb; -gfx_context subcontext; - void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr) { @@ -13,16 +12,24 @@ void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr) uint64_t loc = \ y * ctx->pitch + \ x * ctx->bpp; - uint32_t *fb = incptr(P2V(ctx->addr), loc); - + uint32_t *fb = incptr(ctx->buffer, loc); *fb = clr; } - +void flip(gfx_context *ctx) +{ + for(uint64_t y = 0; y < ctx->height; y++) + { + memcpy( + incptr(ctx->addr, y*ctx->pitch), + incptr(ctx->buffer, y*ctx->pitch), + ctx->width*ctx->bpp); + } +} gfx_context *framebuffer_make_subcontext(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height) { - gfx_context *out = &subcontext; + gfx_context *out = malloc(sizeof(gfx_context)); uint64_t loc = \ y * ctx->pitch + \ x * ctx->bpp; @@ -33,6 +40,7 @@ gfx_context *framebuffer_make_subcontext(gfx_context *ctx, uint64_t x, uint64_t out->pitch = ctx->pitch; out->addr = incptr(ctx->addr, loc); out->size = ctx->pitch * (height); + out->buffer = calloc(1, out->size); return out; } @@ -43,11 +51,12 @@ void framebuffer_init(struct fbinfo *fbinfo) kernel_fb.height = fbinfo->framebuffer_height; kernel_fb.bpp = fbinfo->framebuffer_bpp/8; kernel_fb.pitch = fbinfo->framebuffer_pitch; - kernel_fb.addr = (void *)fbinfo->framebuffer_addr; + kernel_fb.addr = P2V(fbinfo->framebuffer_addr); kernel_fb.size = kernel_fb.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, (uint64_t)P2V(p), p, PAGE_WRITE | PAGE_PRESENT); + vmm_set_page(kernel_P4, p, V2P(p), PAGE_WRITE | PAGE_PRESENT); } } \ No newline at end of file diff --git a/src/kernel/drivers/terminal/fbterm.c b/src/kernel/drivers/terminal/fbterm.c index 9c0b572..b3d41e5 100644 --- a/src/kernel/drivers/terminal/fbterm.c +++ b/src/kernel/drivers/terminal/fbterm.c @@ -113,7 +113,7 @@ static void drawCharacter(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr uint64_t loc = \ y * ctx->pitch + \ x * ctx->bpp; - uint32_t *fb = incptr(P2V(ctx->addr), loc); + uint32_t *fb = incptr(ctx->buffer, loc); for(int row = 0; row < 16; row++) { for(int col = 0; col < 8; col++) @@ -143,6 +143,7 @@ void fbterm_init(gfx_context *ctx) { term_fb = framebuffer_make_subcontext(ctx, 20, 20, 8*VGA_COLS+8, 16*VGA_ROWS+8); draw_border(term_fb, RGB(255, 0, 0)); + flip(term_fb); term_fb = framebuffer_make_subcontext(ctx, 24, 24, 8*VGA_COLS, 16*VGA_ROWS); setup = 1; } @@ -163,4 +164,5 @@ void fbterm_flush(struct vga_cell *buffer) drawCharacter(term_fb, col*8, row*16, 0xFFFFFF, 0, (char)buffer[i++].c); } } + flip(term_fb); } \ No newline at end of file diff --git a/src/kernel/include/framebuffer.h b/src/kernel/include/framebuffer.h index 9e3f424..a8611ea 100644 --- a/src/kernel/include/framebuffer.h +++ b/src/kernel/include/framebuffer.h @@ -13,11 +13,13 @@ typedef struct { size_t size; } gfx_context; +// drivers/framebuffer.c extern gfx_context kernel_fb; #define RGB(r, g, b) (((uint32_t) (r<<16) + (g<<8) + (b))) +// drivers/framebuffer.c void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr); +void flip(gfx_context *ctx); gfx_context *framebuffer_make_subcontext(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height); - void framebuffer_init(struct fbinfo *fbinfo); \ No newline at end of file