aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-10-12 14:05:45 +0200
committerBad Diode <bd@badd10de.dev>2022-10-12 14:05:45 +0200
commitc7fd12ca4cd5b98846bf9635d96de9b04b48a0ee (patch)
treea72d1682e938a69323a490c7fdb3ed210838879a
parent44acb94e4339e240bb9e7f93d14a7757e2db8962 (diff)
downloaduxnfb-c7fd12ca4cd5b98846bf9635d96de9b04b48a0ee.tar.gz
uxnfb-c7fd12ca4cd5b98846bf9635d96de9b04b48a0ee.zip
[WIP] Add pixel perfect zoom to the PPU
-rw-r--r--src/main.c18
-rw-r--r--src/ppu.c10
2 files changed, 18 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index cdc8530..8792a9a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -120,10 +120,17 @@ poll_mouse(void) {
120 printf("MOUSE REL EVENT\n"); 120 printf("MOUSE REL EVENT\n");
121 if (mouse_event.code == REL_X) { 121 if (mouse_event.code == REL_X) {
122 in.mouse.x = CLAMP( 122 in.mouse.x = CLAMP(
123 in.mouse.x + (s32)mouse_event.value, 0, (s32)screen_width); 123 in.mouse.x / zoom + (s32)mouse_event.value, 0, (s32)screen_width);
124 } else if (mouse_event.code == REL_Y) { 124 } else if (mouse_event.code == REL_Y) {
125 in.mouse.y = CLAMP( 125 in.mouse.y = CLAMP(
126 in.mouse.y + (s32)mouse_event.value, 0, (s32)screen_height); 126 in.mouse.y / zoom + (s32)mouse_event.value, 0, (s32)screen_height);
127 }
128 } else if (mouse_event.type == EV_ABS) {
129 printf("MOUSE ABS EVENT\n");
130 if (mouse_event.code == ABS_X) {
131 in.mouse.x = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_width);
132 } else if (mouse_event.code == ABS_Y) {
133 in.mouse.y = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_height);
127 } 134 }
128 } else if (mouse_event.type == EV_KEY) { 135 } else if (mouse_event.type == EV_KEY) {
129 printf("MOUSE KEY EVENT\n"); 136 printf("MOUSE KEY EVENT\n");
@@ -144,13 +151,6 @@ poll_mouse(void) {
144 } break; 151 } break;
145 default: break; 152 default: break;
146 } 153 }
147 } else if (mouse_event.type == EV_ABS) {
148 printf("MOUSE ABS EVENT\n");
149 if (mouse_event.code == ABS_X) {
150 in.mouse.x = CLAMP((s32)mouse_event.value, 0, (s32)screen_width);
151 } else if (mouse_event.code == ABS_Y) {
152 in.mouse.y = CLAMP((s32)mouse_event.value, 0, (s32)screen_height);
153 }
154 } 154 }
155 in.mouse.update = true; 155 in.mouse.update = true;
156 } 156 }
diff --git a/src/ppu.c b/src/ppu.c
index 3afa533..38b27e6 100644
--- a/src/ppu.c
+++ b/src/ppu.c
@@ -27,6 +27,7 @@ static size_t screen_height = 0;
27static size_t bpp = 0; 27static size_t bpp = 0;
28static int fb_file = 0; 28static int fb_file = 0;
29static int refresh_file = 0; 29static int refresh_file = 0;
30static int zoom = 2;
30 31
31static u8 *framebuffer = 0; 32static u8 *framebuffer = 0;
32 33
@@ -175,6 +176,8 @@ ppu_init(void) {
175 fprintf(stderr, "error: couldn't mmap the framebuffer\n"); 176 fprintf(stderr, "error: couldn't mmap the framebuffer\n");
176 exit(EXIT_FAILURE); 177 exit(EXIT_FAILURE);
177 } 178 }
179 screen_width /= zoom;
180 screen_height /= zoom;
178 181
179 // Allocate intermediate buffers. 182 // Allocate intermediate buffers.
180 pixels_fg = malloc(screen_width * screen_height); 183 pixels_fg = malloc(screen_width * screen_height);
@@ -222,7 +225,12 @@ blit_framebuffer(void) {
222 size_t idx = i + j * screen_width; 225 size_t idx = i + j * screen_width;
223 if (bpp == 16) { 226 if (bpp == 16) {
224 u16 *p = framebuffer; 227 u16 *p = framebuffer;
225 p[idx] = rgb565(palette[pixels_fg[idx] << 2 | pixels_bg[idx]]); 228 for (size_t zz = 0; zz < zoom; zz++) {
229 size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom);
230 for (size_t z = 0; z < zoom; z++) {
231 p[fb_idx + z] = rgb565(palette[pixels_fg[idx] << 2 | pixels_bg[idx]]);
232 }
233 }
226 } else if (bpp == 32) { 234 } else if (bpp == 32) {
227 u32 *p = framebuffer; 235 u32 *p = framebuffer;
228 p[idx] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]]; 236 p[idx] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]];