diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 60 |
1 files changed, 24 insertions, 36 deletions
@@ -1,45 +1,36 @@ | |||
1 | #include<stdio.h> | 1 | #include <stdio.h> |
2 | #include<stdlib.h> | 2 | #include <stdlib.h> |
3 | #include<stdint.h> | 3 | #include <stdint.h> |
4 | #include<stdbool.h> | 4 | #include <stdbool.h> |
5 | #include<unistd.h> | 5 | #include <unistd.h> |
6 | #include<fcntl.h> | 6 | #include <fcntl.h> |
7 | #include<linux/fb.h> | 7 | #include <linux/fb.h> |
8 | #include<sys/ioctl.h> | 8 | #include <sys/ioctl.h> |
9 | #include<sys/mman.h> | 9 | #include <sys/mman.h> |
10 | |||
11 | #include "shorthand.h" | ||
12 | #include "ppu.c" | ||
13 | #include "uxn-fast.c" | ||
14 | #include "rom.c" | ||
15 | |||
16 | // static Uxn u; | ||
17 | // static Device *devscreen; | ||
18 | // static Device *devctrl; | ||
19 | // static Device *devmouse; | ||
20 | // static Device *devaudio; | ||
10 | 21 | ||
11 | int | 22 | int |
12 | main(void) { | 23 | main(void) { |
13 | // Open frambuffer and get the size. | 24 | ppu_init(); |
14 | int fb = open("/dev/fb0", O_RDWR); | ||
15 | if (fb <= 0) { | ||
16 | fprintf(stderr, "couldn't open the framebuffer\n"); | ||
17 | exit(EXIT_FAILURE); | ||
18 | } | ||
19 | struct fb_var_screeninfo info; | ||
20 | if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) { | ||
21 | fprintf(stderr, "couldn't get the framebuffer size\n"); | ||
22 | exit(EXIT_FAILURE); | ||
23 | } | ||
24 | |||
25 | // Mmap the framebuffer to a buffer object. | ||
26 | size_t width = info.xres; | ||
27 | size_t height = info.yres; | ||
28 | size_t len = 4 * width * height; | ||
29 | uint32_t *buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); | ||
30 | if (buf == MAP_FAILED) { | ||
31 | fprintf(stderr, "couldn't mmap the framebuffer\n"); | ||
32 | exit(EXIT_FAILURE); | ||
33 | } | ||
34 | 25 | ||
35 | // Main loop. | 26 | // Main loop. |
36 | uint8_t shade = 0; | 27 | uint8_t shade = 0; |
37 | size_t counter = 0; | 28 | size_t counter = 0; |
38 | size_t direction = 1; | 29 | size_t direction = 1; |
39 | while (true) { | 30 | while (true) { |
40 | for (size_t j = 0; j < height; j++) { | 31 | for (size_t j = 0; j < screen_height; j++) { |
41 | for (size_t i = 0; i < width; i++) { | 32 | for (size_t i = 0; i < screen_width; i++) { |
42 | buf[j * width + i] = shade; | 33 | framebuffer[j * screen_width + i] = shade; |
43 | } | 34 | } |
44 | } | 35 | } |
45 | counter++; | 36 | counter++; |
@@ -54,8 +45,5 @@ main(void) { | |||
54 | } | 45 | } |
55 | } | 46 | } |
56 | 47 | ||
57 | // Cleanup. | ||
58 | munmap(buf, len); | ||
59 | close(fb); | ||
60 | return 0; | 48 | return 0; |
61 | } | 49 | } |