HhhOS/arch/x86_64/drivers/framebuffer.c
2021-08-17 12:45:35 +03:00

25 lines
942 B
C

#include <framebuffer.h>
#include <std/stdio.h>
void putpixel(framebuffer_t *framebuffer, u16 x, u16 y, u32 color) {
if (color & 255 == 0) return;
u64 where = x * framebuffer->pixelwidth + y * framebuffer->pitch;
framebuffer->address[where] = (color >> 8) & 255; // BLUE
framebuffer->address[where + 1] = (color >> 16) & 255; // GREEN
framebuffer->address[where + 2] = (color >> 24) & 255; // RED
}
void fillrect(framebuffer_t *framebuffer, u16 x, u16 y, u16 w, u16 h, u32 color) {
if (color & 255 == 0) return;
u8 *where;
u32 pw = framebuffer->pixelwidth;
for (u16 i = y; i < h + y; i++) {
where = (u8*)((u64)framebuffer->address + framebuffer->pitch * i);
for (u16 j = x; j < w + x; j++) {
where[j * pw] = (color >> 8) & 255; // BLUE
where[j * pw + 1] = (color >> 16) & 255; // GREEN
where[j * pw + 2] = (color >> 24) & 255; // RED
}
}
}