-
Notifications
You must be signed in to change notification settings - Fork 43
/
fb.c
64 lines (56 loc) · 1.57 KB
/
fb.c
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 "fb.h"
#include <stdlib.h>
#include "mailbox.h"
void *fb_create(uint32_t width, uint32_t height, uint32_t depth)
{
PropertyMessageTag tags[4];
tags[0].tag = FB_SET_PHYSICAL_SIZE;
tags[0].value.fbScreenSize.width = width;
tags[0].value.fbScreenSize.height = height;
tags[1].tag = FB_SET_VIRTUAL_SIZE;
tags[1].value.fbScreenSize.width = width;
tags[1].value.fbScreenSize.height = height;
tags[2].tag = FB_SET_DEPTH;
tags[2].value.fbBitsPerPixel = depth;
tags[3].tag = NULL_TAG;
if (mailbox_send_messages(tags) != 0) {
return NULL;
}
tags[0].tag = FB_ALLOCATE_TAG;
tags[0].value.fbScreenSize.width = 0;
tags[0].value.fbScreenSize.height = 0;
tags[0].value.fbAllocateAlignment = 16;
tags[1].tag = NULL_TAG;
if (mailbox_send_messages(tags) != 0) {
return NULL;
}
return (void *) tags[0].value.fbAllocateRes.base;
}
void fb_putc(uint32_t *fb,
int width,
int height,
const uint8_t *font,
int x,
int y)
{
(void) height;
for (int j = 0; j < 16; ++j) {
for (int i = 0; i < 8; ++i) {
if (font[j] & (1 << i)) {
fb[(y + j) * width + (x + i)] = 0xFFFFFFFF;
}
}
}
}
void fb_puts(uint32_t *fb,
int width,
int height,
const uint8_t (*font)[16],
const char *str,
int x,
int y)
{
for (int i = 0; str[i] != '\0'; ++i) {
fb_putc(fb, width, height, font[(uint8_t) str[i]], x + 8 * i, y);
}
}