aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/framebuffer.cpp
blob: 62ffee71a329c3d0586e826147fd30262eb66aca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <framebuffer.h>
#include <stdint.h>
#include <stddef.h>

uint32_t* fb_addr;
uint32_t fb_width;
uint32_t fb_height;

void fb_init(uint32_t* addr, uint32_t width, uint32_t height) {
    fb_addr = addr;
    fb_width = width;
    fb_height = height;
    fb_clear();
}

void fb_clear() {
    for (size_t y = 0; y < fb_height; y++) {
        for (size_t x = 0; x < fb_width; x++) {
            const size_t i = y * fb_width + x;
            fb_addr[i] = 0x000000;
        }
    }
}

void draw_pixel(const uint32_t x, const uint32_t y, const uint32_t color) {
    const size_t pos = y * fb_width + x;
    fb_addr[pos] = color;
}

void draw_bitmap(const uint32_t* bitmap, const uint32_t x_pos, const uint32_t y_pos, const uint32_t width, const uint32_t height) {
    for (size_t y = 0; y < height; y++) {
        for (size_t x = 0; x < width; x++) {
            const size_t i = y * width + x;
            draw_pixel(x_pos + x, y_pos + y, bitmap[i]);
        }
    }    
}