diff options
author | Bad Diode <bd@badd10de.dev> | 2022-10-14 15:21:16 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-10-14 15:21:16 +0200 |
commit | 53ff0a9394951be00537b6d23cd19d6efc6a6fbb (patch) | |
tree | 696258e78585e2b40b6b74c0b0f69463ab21d603 | |
parent | c49a985b92c8291278bfcd6ac83e2f8272695e84 (diff) | |
download | uxnnst-53ff0a9394951be00537b6d23cd19d6efc6a6fbb.tar.gz uxnnst-53ff0a9394951be00537b6d23cd19d6efc6a6fbb.zip |
Fix warnings
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/ppu.c | 66 |
2 files changed, 7 insertions, 61 deletions
@@ -28,7 +28,6 @@ typedef struct timespec Time; | |||
28 | void | 28 | void |
29 | halt(int stub) { | 29 | halt(int stub) { |
30 | (void)stub; | 30 | (void)stub; |
31 | set_tty(false); | ||
32 | exit(EXIT_SUCCESS); | 31 | exit(EXIT_SUCCESS); |
33 | } | 32 | } |
34 | 33 | ||
@@ -568,7 +567,6 @@ main(int argc, char *argv[]) { | |||
568 | // Main loop. | 567 | // Main loop. |
569 | Time frame_time = time_now(); | 568 | Time frame_time = time_now(); |
570 | size_t frames_update = 0; | 569 | size_t frames_update = 0; |
571 | size_t frames_refresh = 0; | ||
572 | while (true) { | 570 | while (true) { |
573 | poll_input(); | 571 | poll_input(); |
574 | size_t elapsed = time_elapsed(frame_time); | 572 | size_t elapsed = time_elapsed(frame_time); |
@@ -4,7 +4,6 @@ | |||
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> | ||
8 | #include <sys/mman.h> | 7 | #include <sys/mman.h> |
9 | 8 | ||
10 | #include "ppu.h" | 9 | #include "ppu.h" |
@@ -24,7 +23,7 @@ | |||
24 | 23 | ||
25 | // Parameters. | 24 | // Parameters. |
26 | static int zoom = 2; | 25 | static int zoom = 2; |
27 | static int frames_per_update = 5; | 26 | static size_t frames_per_update = 5; |
28 | static int blits_per_refresh = 60 * 5; | 27 | static int blits_per_refresh = 60 * 5; |
29 | 28 | ||
30 | static size_t screen_width = 0; | 29 | static size_t screen_width = 0; |
@@ -32,7 +31,7 @@ static size_t screen_height = 0; | |||
32 | static size_t bpp = 0; | 31 | static size_t bpp = 0; |
33 | static int fb_file = 0; | 32 | static int fb_file = 0; |
34 | static int refresh_file = 0; | 33 | static int refresh_file = 0; |
35 | static frames_refresh = 0; | 34 | static int frames_refresh = 0; |
36 | 35 | ||
37 | static u8 *framebuffer = 0; | 36 | static u8 *framebuffer = 0; |
38 | 37 | ||
@@ -111,46 +110,6 @@ redraw_screen(void) { | |||
111 | } | 110 | } |
112 | } | 111 | } |
113 | 112 | ||
114 | static struct termios prev_t; | ||
115 | |||
116 | void | ||
117 | set_tty(bool graphics) { | ||
118 | // Disable TTY echo and set graphics mode. | ||
119 | int tty = open("/dev/tty0", O_RDWR); | ||
120 | if (!tty) { | ||
121 | fprintf(stderr,"error: couldn't open tty\n"); | ||
122 | exit(EXIT_FAILURE); | ||
123 | } | ||
124 | |||
125 | // if (graphics) { | ||
126 | // if (ioctl(tty, KDSETMODE, KD_GRAPHICS)) { | ||
127 | // fprintf(stderr,"error: setting graphics mode failed\n"); | ||
128 | // exit(EXIT_FAILURE); | ||
129 | // } | ||
130 | // struct termios t; | ||
131 | // if (tcgetattr(STDIN_FILENO, &t)) { | ||
132 | // fprintf(stderr, "error: couldn't disable terminal echo\n"); | ||
133 | // exit(EXIT_FAILURE); | ||
134 | // } | ||
135 | // prev_t = t; | ||
136 | // t.c_lflag &= ~((tcflag_t) ECHO); | ||
137 | // if (tcsetattr(STDIN_FILENO, TCSANOW, &t)) { | ||
138 | // fprintf(stderr, "error: couldn't disable terminal echo\n"); | ||
139 | // exit(EXIT_FAILURE); | ||
140 | // } | ||
141 | // } else { | ||
142 | // if (ioctl(tty, KDSETMODE, KD_TEXT)) { | ||
143 | // fprintf(stderr,"error: setting text mode failed\n"); | ||
144 | // exit(EXIT_FAILURE); | ||
145 | // } | ||
146 | // if (tcsetattr(STDIN_FILENO, TCSANOW, &prev_t)) { | ||
147 | // fprintf(stderr, "error: couldn't restore terminal attributes\n"); | ||
148 | // exit(EXIT_FAILURE); | ||
149 | // } | ||
150 | // } | ||
151 | close(tty); | ||
152 | } | ||
153 | |||
154 | int | 113 | int |
155 | ppu_init(void) { | 114 | ppu_init(void) { |
156 | // Open frambuffer and get the size. | 115 | // Open frambuffer and get the size. |
@@ -194,9 +153,6 @@ ppu_init(void) { | |||
194 | exit(EXIT_FAILURE); | 153 | exit(EXIT_FAILURE); |
195 | } | 154 | } |
196 | 155 | ||
197 | // Prepare TTY for graphics mode. | ||
198 | // set_tty(true); | ||
199 | |||
200 | // Initialize default palette. | 156 | // Initialize default palette. |
201 | palette[0] = 0x444444; | 157 | palette[0] = 0x444444; |
202 | palette[1] = 0xffffff; | 158 | palette[1] = 0xffffff; |
@@ -230,20 +186,12 @@ blit_framebuffer(void) { | |||
230 | if (dirty_lines[j] != 0) { | 186 | if (dirty_lines[j] != 0) { |
231 | for (size_t i = 0; i < screen_width; i++) { | 187 | for (size_t i = 0; i < screen_width; i++) { |
232 | size_t idx = i + j * screen_width; | 188 | size_t idx = i + j * screen_width; |
233 | if (bpp == 16) { | 189 | u16 *p = (u16*)framebuffer; |
234 | u16 *p = framebuffer; | 190 | for (int zz = 0; zz < zoom; zz++) { |
235 | for (size_t zz = 0; zz < zoom; zz++) { | 191 | size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom); |
236 | size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom); | 192 | for (int z = 0; z < zoom; z++) { |
237 | for (size_t z = 0; z < zoom; z++) { | 193 | p[fb_idx + z] = rgb565(palette[pixels_fg[idx] << 2 | pixels_bg[idx]]); |
238 | p[fb_idx + z] = rgb565(palette[pixels_fg[idx] << 2 | pixels_bg[idx]]); | ||
239 | } | ||
240 | } | 194 | } |
241 | } else if (bpp == 32) { | ||
242 | u32 *p = framebuffer; | ||
243 | p[idx] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]]; | ||
244 | } else { | ||
245 | fprintf(stderr, "error: wrong bits per pixel (expected 16 or 32)\n"); | ||
246 | exit(EXIT_FAILURE); | ||
247 | } | 195 | } |
248 | } | 196 | } |
249 | } | 197 | } |