aboutsummaryrefslogtreecommitdiffstats
path: root/src/ppu.c
blob: 2e0404f7d0c0132339776e5144fb1f95b1252f58 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "common.h"

static u32 *framebuffer = 0;

#define SCREEN_WIDTH  800
#define SCREEN_HEIGHT 600

static u32 palette[4];

void
ppu_init(void) {
    // Initialize the framebuffer.
    static MboxFramebufferRequest fb_request = {
        .buf_size = 96,
        .code = MBOX_REQUEST,
        .screen_tag = {
            .header = {
                .id = 0x48003,
                .buf_size = 8,
            },
            .width = SCREEN_WIDTH,
            .height = SCREEN_HEIGHT,
        },
        .virtual_screen_tag = {
            .header = {
                .id = 0x48004,
                .buf_size = 8,
            },
            .width = SCREEN_WIDTH,
            .height = SCREEN_HEIGHT,
        },
        .depth_tag = {
            .header = {
                .id = 0x48005,
                .buf_size = 4,
            },
            .depth = 32,
        },
        .framebuffer_tag = {
            .header = {
                .id = 0x40001,
                .buf_size = 8,
            },
            .fb_addr = 0,
            .fb_size = 0,
        }
    };

    if (mb_call(MBOX_CH_PROP, &fb_request)
            && fb_request.depth_tag.depth == 32
            && fb_request.framebuffer_tag.fb_addr != 0) {
        fb_request.framebuffer_tag.fb_addr &= 0x3FFFFFFF;
        framebuffer = (u32*)((uintptr_t)fb_request.framebuffer_tag.fb_addr);
    } else {
        uart_puts("Unable initialize framebuffer\n");
        return;
    }

    // Initialize default palette.
    palette[0] = 0x00444444;
    palette[1] = 0x00ffffff;
    palette[2] = 0x007777ff;
    palette[3] = 0x00ff7777;
}