Print text in framebuffer
This commit is contained in:
parent
40999d3da3
commit
a09c160bcb
@ -1,35 +1,25 @@
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
#include <multiboot.h>
|
||||
#include <framebuffer.h>
|
||||
#include <vga.h>
|
||||
|
||||
struct gfx_context {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t bpp;
|
||||
uint32_t pitch;
|
||||
void *addr;
|
||||
void *buffer;
|
||||
size_t size;
|
||||
};
|
||||
gfx_context kernel_fb;
|
||||
gfx_context subcontext;
|
||||
|
||||
struct gfx_context framebuffer;
|
||||
|
||||
struct gfx_context subcontext;
|
||||
|
||||
#define RGB(r, g, b) (((uint32_t) (r<<16) + (g<<8) + (b)))
|
||||
|
||||
void putpixel(struct gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr)
|
||||
void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr)
|
||||
{
|
||||
if(x >= ctr->width || y >= ctx->height) return;
|
||||
if(x >= ctx->width || y >= ctx->height) return;
|
||||
uint64_t loc = \
|
||||
y * ctx->pitch + \
|
||||
x * ctx->bpp/8;
|
||||
x * ctx->bpp;
|
||||
uint32_t *fb = incptr(P2V(ctx->addr), loc);
|
||||
|
||||
*fb = clr;
|
||||
}
|
||||
|
||||
static void draw_border(struct gfx_context *ctx, uint32_t clr)
|
||||
static void draw_border(gfx_context *ctx, uint32_t clr)
|
||||
{
|
||||
for(uint64_t x = 0; x < ctx->width; x++)
|
||||
{
|
||||
@ -43,12 +33,12 @@ static void draw_border(struct gfx_context *ctx, uint32_t clr)
|
||||
}
|
||||
}
|
||||
|
||||
struct gfx_context *make_subarea(struct gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height)
|
||||
gfx_context *make_subcontext(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height)
|
||||
{
|
||||
struct gfx_context *out = &subcontext;
|
||||
gfx_context *out = &subcontext;
|
||||
uint64_t loc = \
|
||||
y * ctx->pitch + \
|
||||
x * ctx->bpp/8;
|
||||
x * ctx->bpp;
|
||||
|
||||
out->width = width;
|
||||
out->height = height;
|
||||
@ -60,22 +50,24 @@ struct gfx_context *make_subarea(struct gfx_context *ctx, uint64_t x, uint64_t y
|
||||
return out;
|
||||
}
|
||||
|
||||
void framebuffer_init(struct fbinfo *fbinfo)
|
||||
gfx_context *framebuffer_init(struct fbinfo *fbinfo)
|
||||
{
|
||||
framebuffer.width = fbinfo->framebuffer_width;
|
||||
framebuffer.height = fbinfo->framebuffer_height;
|
||||
framebuffer.bpp = fbinfo->framebuffer_bpp;
|
||||
framebuffer.pitch = fbinfo->framebuffer_pitch;
|
||||
framebuffer.addr = (void *)fbinfo->framebuffer_addr;
|
||||
framebuffer.size = framebuffer.pitch * (framebuffer.height);
|
||||
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.addr = (void *)fbinfo->framebuffer_addr;
|
||||
kernel_fb.size = kernel_fb.pitch * (kernel_fb.height);
|
||||
|
||||
for(uintptr_t p = (uintptr_t)framebuffer.addr; p < ((uintptr_t)framebuffer.addr + framebuffer.size); p += PAGE_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);
|
||||
}
|
||||
|
||||
draw_border(&framebuffer, RGB(0, 255, 0));
|
||||
struct gfx_context *sub = make_subarea(&framebuffer, 256, 192, 256, 192);
|
||||
draw_border(&kernel_fb, RGB(0, 255, 0));
|
||||
gfx_context *sub = make_subcontext(&kernel_fb, 20, 20, 8*VGA_COLS+8, 16*VGA_ROWS+8);
|
||||
draw_border(sub, RGB(255, 0, 0));
|
||||
sub = make_subcontext(&kernel_fb, 24, 24, 8*VGA_COLS, 16*VGA_ROWS);
|
||||
|
||||
return sub;
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#include <framebuffer.h>
|
||||
#include <vga.h>
|
||||
#include <memory.h>
|
||||
#include <ports.h>
|
||||
@ -5,9 +6,6 @@
|
||||
#include <stddef.h>
|
||||
#include <debug.h>
|
||||
|
||||
#define VGA_COLS 80
|
||||
#define VGA_ROWS 24
|
||||
#define VGA_SIZE (VGA_COLS*VGA_ROWS)
|
||||
|
||||
#define VGA_ROW(pos) ((pos)/VGA_COLS)
|
||||
#define VGA_COL(pos) ((pos)%VGA_COLS)
|
||||
@ -19,10 +17,6 @@
|
||||
#define VGA_REGISTER_CURSOR_POS_HIGH 0xE
|
||||
|
||||
void *vidmem;
|
||||
struct vga_cell{
|
||||
uint8_t c;
|
||||
uint8_t f;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct vga_cell buffer[VGA_SIZE];
|
||||
|
||||
@ -31,6 +25,7 @@ uint8_t format;
|
||||
|
||||
static int vga_setup = 0;
|
||||
static int vga_type;
|
||||
gfx_context *fb_context;
|
||||
|
||||
void vga_init()
|
||||
{
|
||||
@ -39,7 +34,7 @@ void vga_init()
|
||||
switch(vga_type)
|
||||
{
|
||||
case 1:
|
||||
framebuffer_init(fbinfo);
|
||||
fb_context = framebuffer_init(fbinfo);
|
||||
break;
|
||||
case 2:
|
||||
vidmem = VGA_MEMORY;
|
||||
@ -77,9 +72,6 @@ static void scroll()
|
||||
|
||||
void vga_write(char c)
|
||||
{
|
||||
switch(vga_type)
|
||||
{
|
||||
case 2:
|
||||
switch(c)
|
||||
{
|
||||
case '\n':
|
||||
@ -89,6 +81,12 @@ void vga_write(char c)
|
||||
buffer[cursor++] = (struct vga_cell){.c = c, .f = format};
|
||||
}
|
||||
scroll();
|
||||
switch(vga_type)
|
||||
{
|
||||
case 1:
|
||||
vga2fb(buffer, fb_context, VGA_ROWS, VGA_COLS);
|
||||
break;
|
||||
case 2:
|
||||
flush();
|
||||
movecursor();
|
||||
break;
|
||||
|
135
src/kernel/drivers/vga2fb.c
Normal file
135
src/kernel/drivers/vga2fb.c
Normal file
@ -0,0 +1,135 @@
|
||||
#include <stdint.h>
|
||||
#include <vga.h>
|
||||
#include <framebuffer.h>
|
||||
#include <memory.h>
|
||||
|
||||
// Font from https://github.com/atextor/unifont
|
||||
char font[95][16] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0x12, 0x7E, 0x24, 0x24, 0x7E, 0x48, 0x48, 0x48, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x08, 0x3E, 0x49, 0x48, 0x38, 0x0E, 0x09, 0x49, 0x3E, 0x08, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x31, 0x4A, 0x4A, 0x34, 0x08, 0x08, 0x16, 0x29, 0x29, 0x46, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x39, 0x45, 0x42, 0x46, 0x39, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x04, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x49, 0x2A, 0x1C, 0x2A, 0x49, 0x08, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x7F, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x10},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x02, 0x0C, 0x10, 0x20, 0x40, 0x40, 0x7E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x02, 0x1C, 0x02, 0x02, 0x42, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x14, 0x24, 0x44, 0x44, 0x7E, 0x04, 0x04, 0x04, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x40, 0x40, 0x40, 0x7C, 0x02, 0x02, 0x02, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x1C, 0x20, 0x40, 0x40, 0x7C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x02, 0x02, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x3E, 0x02, 0x02, 0x02, 0x04, 0x38, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x10, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x4A, 0x56, 0x52, 0x52, 0x52, 0x4E, 0x20, 0x1E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x42, 0x7C, 0x42, 0x42, 0x42, 0x42, 0x7C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x44, 0x78, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x40, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x40, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x40, 0x40, 0x4E, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x44, 0x38, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x42, 0x44, 0x48, 0x50, 0x60, 0x60, 0x50, 0x48, 0x44, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x66, 0x66, 0x5A, 0x5A, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x42, 0x62, 0x62, 0x52, 0x52, 0x4A, 0x4A, 0x46, 0x46, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x42, 0x7C, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x5A, 0x66, 0x3C, 0x03, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x42, 0x7C, 0x48, 0x44, 0x44, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x40, 0x30, 0x0C, 0x02, 0x42, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x41, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x5A, 0x5A, 0x66, 0x66, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x7E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x0E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0E, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x70, 0x00},
|
||||
{0x00, 0x00, 0x18, 0x24, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00},
|
||||
{0x00, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x02, 0x3E, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x5C, 0x62, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x3A, 0x46, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x7E, 0x40, 0x40, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x0C, 0x10, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3A, 0x44, 0x44, 0x44, 0x38, 0x20, 0x3C, 0x42, 0x42, 0x3C},
|
||||
{0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x5C, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x48, 0x30},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x62, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5C, 0x40, 0x40},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A, 0x46, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3A, 0x02, 0x02},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x62, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x40, 0x30, 0x0C, 0x02, 0x42, 0x3C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0C, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x42, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x26, 0x1A, 0x02, 0x02, 0x3C},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7E, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x0C, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x0C, 0x00},
|
||||
{0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
|
||||
{0x00, 0x00, 0x00, 0x30, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x30, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x31, 0x49, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
};
|
||||
|
||||
void drawCharacter(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr_fg, uint32_t clr_bg, char c)
|
||||
{
|
||||
|
||||
char *chr = c ? font[(int)c-0x20]: font[0];
|
||||
if(x >= ctx->width || y >= ctx->height) return;
|
||||
uint64_t loc = \
|
||||
y * ctx->pitch + \
|
||||
x * ctx->bpp;
|
||||
uint32_t *fb = incptr(P2V(ctx->addr), loc);
|
||||
for(int row = 0; row < 16; row++)
|
||||
{
|
||||
for(int col = 0; col < 8; col++)
|
||||
{
|
||||
fb[col] = ((chr[row]>>(7-col))&0x1) ? clr_fg : clr_bg;
|
||||
}
|
||||
fb = incptr(fb, ctx->pitch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void vga2fb(struct vga_cell *buffer, gfx_context *ctx, int rows, int cols)
|
||||
{
|
||||
int i = 0;
|
||||
for(int row = 0; row < rows; row++)
|
||||
{
|
||||
for(int col = 0; col < cols; col++)
|
||||
{
|
||||
drawCharacter(ctx, col*8, row*16, 0xFFFFFF, 0, (char)buffer[i++].c);
|
||||
}
|
||||
}
|
||||
}
|
20
src/kernel/include/framebuffer.h
Normal file
20
src/kernel/include/framebuffer.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t bpp;
|
||||
uint32_t pitch;
|
||||
void *addr;
|
||||
void *buffer;
|
||||
size_t size;
|
||||
} gfx_context;
|
||||
|
||||
#define RGB(r, g, b) (((uint32_t) (r<<16) + (g<<8) + (b)))
|
||||
|
||||
void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr);
|
||||
gfx_context *make_subarea(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height);
|
||||
|
||||
void drawCharacter(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr_fg, uint32_t clr_bg, char c);
|
@ -1,12 +1,27 @@
|
||||
#pragma once
|
||||
#include <memory.h>
|
||||
#include <multiboot.h>
|
||||
#include <framebuffer.h>
|
||||
|
||||
#define VGA_MEMORY P2V(0xB8000)
|
||||
#define VGA_COLS 80
|
||||
#define VGA_ROWS 24
|
||||
#define VGA_SIZE (VGA_COLS*VGA_ROWS)
|
||||
|
||||
struct vga_cell{
|
||||
uint8_t c;
|
||||
uint8_t f;
|
||||
}__attribute__((packed));
|
||||
|
||||
// drivers/vga.c
|
||||
extern struct vga_cell buffer[];
|
||||
|
||||
// drivers/vga.c
|
||||
void vga_init();
|
||||
void vga_write(char c);
|
||||
|
||||
// drivers/framebuffer.c
|
||||
void framebuffer_init(struct fbinfo *fbinfo);
|
||||
gfx_context *framebuffer_init(struct fbinfo *fbinfo);
|
||||
|
||||
// drivers/vga2fb.c
|
||||
void vga2fb(struct vga_cell *buffer, gfx_context *ctx, int rows, int cols);
|
Loading…
x
Reference in New Issue
Block a user