aboutsummaryrefslogtreecommitdiffstats
path: root/src/ppu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ppu.c')
-rw-r--r--src/ppu.c92
1 files changed, 40 insertions, 52 deletions
diff --git a/src/ppu.c b/src/ppu.c
index dde934e..4da3dd6 100644
--- a/src/ppu.c
+++ b/src/ppu.c
@@ -4,7 +4,7 @@
4 4
5#include <linux/fb.h> 5#include <linux/fb.h>
6#include <sys/ioctl.h> 6#include <sys/ioctl.h>
7// #include <sys/kd.h> 7#include <sys/kd.h>
8#include <sys/mman.h> 8#include <sys/mman.h>
9 9
10#include "ppu.h" 10#include "ppu.h"
@@ -23,16 +23,12 @@
23 */ 23 */
24 24
25// Parameters. 25// Parameters.
26static int zoom = 2; 26static size_t zoom = 4;
27static int frames_per_update = 5;
28static int blits_per_refresh = 60 * 5;
29 27
30static size_t screen_width = 0; 28static size_t screen_width = 0;
31static size_t screen_height = 0; 29static size_t screen_height = 0;
32static size_t bpp = 0; 30static size_t bpp = 0;
33static int fb_file = 0; 31static int fb_file = 0;
34static int refresh_file = 0;
35static frames_refresh = 0;
36 32
37static u8 *framebuffer = 0; 33static u8 *framebuffer = 0;
38 34
@@ -121,51 +117,45 @@ set_tty(bool graphics) {
121 fprintf(stderr,"error: couldn't open tty\n"); 117 fprintf(stderr,"error: couldn't open tty\n");
122 exit(EXIT_FAILURE); 118 exit(EXIT_FAILURE);
123 } 119 }
124 120 if (graphics) {
125 // if (graphics) { 121 if (ioctl(tty, KDSETMODE, KD_GRAPHICS)) {
126 // if (ioctl(tty, KDSETMODE, KD_GRAPHICS)) { 122 fprintf(stderr,"error: setting graphics mode failed\n");
127 // fprintf(stderr,"error: setting graphics mode failed\n"); 123 exit(EXIT_FAILURE);
128 // exit(EXIT_FAILURE); 124 }
129 // } 125 struct termios t;
130 // struct termios t; 126 if (tcgetattr(STDIN_FILENO, &t)) {
131 // if (tcgetattr(STDIN_FILENO, &t)) { 127 fprintf(stderr, "error: couldn't disable terminal echo\n");
132 // fprintf(stderr, "error: couldn't disable terminal echo\n"); 128 exit(EXIT_FAILURE);
133 // exit(EXIT_FAILURE); 129 }
134 // } 130 prev_t = t;
135 // prev_t = t; 131 t.c_lflag &= ~((tcflag_t) ECHO);
136 // t.c_lflag &= ~((tcflag_t) ECHO); 132 if (tcsetattr(STDIN_FILENO, TCSANOW, &t)) {
137 // if (tcsetattr(STDIN_FILENO, TCSANOW, &t)) { 133 fprintf(stderr, "error: couldn't disable terminal echo\n");
138 // fprintf(stderr, "error: couldn't disable terminal echo\n"); 134 exit(EXIT_FAILURE);
139 // exit(EXIT_FAILURE); 135 }
140 // } 136 } else {
141 // } else { 137 if (ioctl(tty, KDSETMODE, KD_TEXT)) {
142 // if (ioctl(tty, KDSETMODE, KD_TEXT)) { 138 fprintf(stderr,"error: setting text mode failed\n");
143 // fprintf(stderr,"error: setting text mode failed\n"); 139 exit(EXIT_FAILURE);
144 // exit(EXIT_FAILURE); 140 }
145 // } 141 if (tcsetattr(STDIN_FILENO, TCSANOW, &prev_t)) {
146 // if (tcsetattr(STDIN_FILENO, TCSANOW, &prev_t)) { 142 fprintf(stderr, "error: couldn't restore terminal attributes\n");
147 // fprintf(stderr, "error: couldn't restore terminal attributes\n"); 143 exit(EXIT_FAILURE);
148 // exit(EXIT_FAILURE); 144 }
149 // } 145 }
150 // }
151 close(tty); 146 close(tty);
152} 147}
153 148
154int 149int
155ppu_init(void) { 150ppu_init(void) {
156 // Open frambuffer and get the size. 151 // Open frambuffer and get the size.
157 fb_file = open("/dev/graphics/fb0", O_RDWR); 152 // TODO: Pass as macro or input parameter
153 fb_file = open("/dev/fb0", O_RDWR);
158 if (fb_file <= 0) { 154 if (fb_file <= 0) {
159 fprintf(stderr, "error: couldn't open the framebuffer\n"); 155 fprintf(stderr, "error: couldn't open the framebuffer\n");
160 exit(EXIT_FAILURE); 156 exit(EXIT_FAILURE);
161 } 157 }
162 158
163 refresh_file = open("/sys/class/graphics/fb0/epd_refresh", O_RDWR);
164 if (refresh_file == 0) {
165 fprintf(stderr, "error: couldn't open the refresh file\n");
166 exit(EXIT_FAILURE);
167 }
168
169 struct fb_var_screeninfo info; 159 struct fb_var_screeninfo info;
170 if (ioctl(fb_file, FBIOGET_VSCREENINFO, &info) != 0) { 160 if (ioctl(fb_file, FBIOGET_VSCREENINFO, &info) != 0) {
171 fprintf(stderr, "error: couldn't get the framebuffer size\n"); 161 fprintf(stderr, "error: couldn't get the framebuffer size\n");
@@ -195,7 +185,7 @@ ppu_init(void) {
195 } 185 }
196 186
197 // Prepare TTY for graphics mode. 187 // Prepare TTY for graphics mode.
198 // set_tty(true); 188 set_tty(true);
199 189
200 // Initialize default palette. 190 // Initialize default palette.
201 palette[0] = 0x444444; 191 palette[0] = 0x444444;
@@ -210,11 +200,11 @@ ppu_init(void) {
210 200
211 // Clear framebuffer. 201 // Clear framebuffer.
212 memset(framebuffer, 0xFF, len); 202 memset(framebuffer, 0xFF, len);
213 write(refresh_file, "1", 1);
214 203
215 // Make sure we perform an initial screen drawing. 204 // Make sure we perform an initial screen drawing.
216 reqdraw = 1; 205 reqdraw = 1;
217 redraw_screen(); 206 redraw_screen();
207 close(fb_file);
218 208
219 return 1; 209 return 1;
220} 210}
@@ -231,7 +221,7 @@ blit_framebuffer(void) {
231 for (size_t i = 0; i < screen_width; i++) { 221 for (size_t i = 0; i < screen_width; i++) {
232 size_t idx = i + j * screen_width; 222 size_t idx = i + j * screen_width;
233 if (bpp == 16) { 223 if (bpp == 16) {
234 u16 *p = framebuffer; 224 u16 *p = (u16*)framebuffer;
235 for (size_t zz = 0; zz < zoom; zz++) { 225 for (size_t zz = 0; zz < zoom; zz++) {
236 size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom); 226 size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom);
237 for (size_t z = 0; z < zoom; z++) { 227 for (size_t z = 0; z < zoom; z++) {
@@ -239,8 +229,13 @@ blit_framebuffer(void) {
239 } 229 }
240 } 230 }
241 } else if (bpp == 32) { 231 } else if (bpp == 32) {
242 u32 *p = framebuffer; 232 u32 *p = (u32*)framebuffer;
243 p[idx] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]]; 233 for (size_t zz = 0; zz < zoom; zz++) {
234 size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom);
235 for (size_t z = 0; z < zoom; z++) {
236 p[fb_idx + z] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]];
237 }
238 }
244 } else { 239 } else {
245 fprintf(stderr, "error: wrong bits per pixel (expected 16 or 32)\n"); 240 fprintf(stderr, "error: wrong bits per pixel (expected 16 or 32)\n");
246 exit(EXIT_FAILURE); 241 exit(EXIT_FAILURE);
@@ -249,12 +244,5 @@ blit_framebuffer(void) {
249 } 244 }
250 dirty_lines[j] = 0; 245 dirty_lines[j] = 0;
251 } 246 }
252 // NOTE: Maybe this should happen on blit_framebuffer depending on
253 // the number of actual updates (uxn applications that don't modify
254 // the framebuffer shouldn't have to blink).
255 if (++frames_refresh > blits_per_refresh) {
256 write(refresh_file, "1", 1);
257 frames_refresh = 0;
258 }
259 reqdraw = 0; 247 reqdraw = 0;
260} 248}