HhhOS/arch/i386/drivers/framebuffer.c

25 lines
1,017 B
C

#include <framebuffer.h>
#include <std/stdio.h>
void putpixel(framebuffer_t *framebuffer, uint16_t x, uint16_t y, uint32_t color) {
if (color & 255 == 0) return;
uint64_t 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, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color) {
if (color & 255 == 0) return;
uint8_t* where;
uint32_t pw = framebuffer->pixelwidth;
for (uint16_t i = y; i < h + y; i++) {
where = (uint8_t*)((uint64_t)framebuffer->address + framebuffer->pitch * i);
for (uint16_t 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
}
}
}