From 162d024a53e1e31e00ff0b6f47dd4590edebc551 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 9 Aug 2020 16:51:01 +0200 Subject: Heavy restructuring of libc, kernel and apps --- kernel/drivers/vesa.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 kernel/drivers/vesa.c (limited to 'kernel/drivers/vesa.c') diff --git a/kernel/drivers/vesa.c b/kernel/drivers/vesa.c new file mode 100644 index 0000000..9402664 --- /dev/null +++ b/kernel/drivers/vesa.c @@ -0,0 +1,40 @@ +#include +#include + +void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const u32 color[3]) +{ + int pos1 = x1 * vbe_bpl + y1 * vbe_pitch; + u8 *draw = &fb[pos1]; + for (int i = 0; i <= y2 - y1; i++) { + for (int j = 0; j <= x2 - x1; j++) { + draw[vbe_bpl * j] = color[2]; + draw[vbe_bpl * j + 1] = color[1]; + draw[vbe_bpl * j + 2] = color[0]; + } + draw += vbe_pitch; + } +} + +void vesa_set_pixel(u16 x, u16 y, const u32 color[3]) +{ + u8 pos = x * vbe_bpl + y * vbe_pitch; + u8 *draw = &fb[pos]; + draw[pos] = (char)color[2]; + draw[pos + 1] = (char)color[1]; + draw[pos + 2] = (char)color[0]; +} + +void vesa_fill(const u32 color[3]) +{ + vesa_draw_rectangle(0, 0, vbe->width - 1, vbe->height - 1, color); +} + +void vesa_init(struct vbe *info) +{ + vbe = info; + vbe_height = vbe->height; + vbe_width = vbe->width; + vbe_bpl = vbe->bpp >> 3; + vbe_pitch = vbe->pitch; + fb = (u8 *)vbe->framebuffer; +} -- cgit v1.2.3