aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-03-03 09:04:58 +0000
committerBad Diode <bd@badd10de.dev>2022-03-03 09:04:58 +0000
commit1d4759d8c04f18dc2e4f3ce45c4656f85f7301a7 (patch)
treea0e71f803875e9c8c98cdf59b76b4f040b6c8972
parentd0b2e6376f03ac86087f355c56b5d98262deda6b (diff)
downloaduxnfb-1d4759d8c04f18dc2e4f3ce45c4656f85f7301a7.tar.gz
uxnfb-1d4759d8c04f18dc2e4f3ce45c4656f85f7301a7.zip
Add main loop with framebuffer color change
-rw-r--r--src/main.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index e08dc19..e3e8b77 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,7 +1,43 @@
1#include<stdio.h> 1#include<stdio.h>
2#include<stdlib.h>
3#include<stdint.h>
4#include<stdbool.h>
5#include<fcntl.h>
6#include<linux/fb.h>
7#include<sys/ioctl.h>
8#include<sys/mman.h>
2 9
3int 10int
4main(void) { 11main(void) {
5 printf("hello world\n"); 12 // Open frambuffer and get the size.
13 int fb = open("/dev/fb0", O_RDWR);
14 if (fb <= 0) {
15 fprintf(stderr, "couldn't open the framebuffer\n");
16 exit(EXIT_FAILURE);
17 }
18 struct fb_var_screeninfo info;
19 if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) {
20 fprintf(stderr, "couldn't get the framebuffer size\n");
21 exit(EXIT_FAILURE);
22 }
23
24 // Mmap the framebuffer to a buffer object.
25 size_t width = info.xres;
26 size_t height = info.yres;
27 size_t len = 4 * width * height;
28 uint32_t *buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
29 if (buf == MAP_FAILED) {
30 fprintf(stderr, "couldn't mmap the framebuffer\n");
31 exit(EXIT_FAILURE);
32 }
33 uint8_t shade = 0;
34 while (true) {
35 for (size_t j = 0; j < height; j++) {
36 for (size_t i = 0; i < width; i++) {
37 buf[j * width + i] = shade;
38 }
39 }
40 shade++;
41 }
6 return 0; 42 return 0;
7} 43}