[WIP] Add pixel perfect zoom to the PPU

This commit is contained in:
Bad Diode 2022-10-12 14:05:45 +02:00
parent 44acb94e43
commit c7fd12ca4c
2 changed files with 18 additions and 10 deletions

View File

@ -120,10 +120,17 @@ poll_mouse(void) {
printf("MOUSE REL EVENT\n"); printf("MOUSE REL EVENT\n");
if (mouse_event.code == REL_X) { if (mouse_event.code == REL_X) {
in.mouse.x = CLAMP( in.mouse.x = CLAMP(
in.mouse.x + (s32)mouse_event.value, 0, (s32)screen_width); in.mouse.x / zoom + (s32)mouse_event.value, 0, (s32)screen_width);
} else if (mouse_event.code == REL_Y) { } else if (mouse_event.code == REL_Y) {
in.mouse.y = CLAMP( in.mouse.y = CLAMP(
in.mouse.y + (s32)mouse_event.value, 0, (s32)screen_height); in.mouse.y / zoom + (s32)mouse_event.value, 0, (s32)screen_height);
}
} else if (mouse_event.type == EV_ABS) {
printf("MOUSE ABS EVENT\n");
if (mouse_event.code == ABS_X) {
in.mouse.x = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_width);
} else if (mouse_event.code == ABS_Y) {
in.mouse.y = CLAMP((s32)mouse_event.value / zoom, 0, (s32)screen_height);
} }
} else if (mouse_event.type == EV_KEY) { } else if (mouse_event.type == EV_KEY) {
printf("MOUSE KEY EVENT\n"); printf("MOUSE KEY EVENT\n");
@ -144,13 +151,6 @@ poll_mouse(void) {
} break; } break;
default: break; default: break;
} }
} else if (mouse_event.type == EV_ABS) {
printf("MOUSE ABS EVENT\n");
if (mouse_event.code == ABS_X) {
in.mouse.x = CLAMP((s32)mouse_event.value, 0, (s32)screen_width);
} else if (mouse_event.code == ABS_Y) {
in.mouse.y = CLAMP((s32)mouse_event.value, 0, (s32)screen_height);
}
} }
in.mouse.update = true; in.mouse.update = true;
} }

View File

@ -27,6 +27,7 @@ static size_t screen_height = 0;
static size_t bpp = 0; static size_t bpp = 0;
static int fb_file = 0; static int fb_file = 0;
static int refresh_file = 0; static int refresh_file = 0;
static int zoom = 2;
static u8 *framebuffer = 0; static u8 *framebuffer = 0;
@ -175,6 +176,8 @@ ppu_init(void) {
fprintf(stderr, "error: couldn't mmap the framebuffer\n"); fprintf(stderr, "error: couldn't mmap the framebuffer\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
screen_width /= zoom;
screen_height /= zoom;
// Allocate intermediate buffers. // Allocate intermediate buffers.
pixels_fg = malloc(screen_width * screen_height); pixels_fg = malloc(screen_width * screen_height);
@ -222,7 +225,12 @@ blit_framebuffer(void) {
size_t idx = i + j * screen_width; size_t idx = i + j * screen_width;
if (bpp == 16) { if (bpp == 16) {
u16 *p = framebuffer; u16 *p = framebuffer;
p[idx] = rgb565(palette[pixels_fg[idx] << 2 | pixels_bg[idx]]); for (size_t zz = 0; zz < zoom; zz++) {
size_t fb_idx = (i * zoom + j * screen_width * zoom * zoom + zz * screen_width * zoom);
for (size_t z = 0; z < zoom; z++) {
p[fb_idx + z] = rgb565(palette[pixels_fg[idx] << 2 | pixels_bg[idx]]);
}
}
} else if (bpp == 32) { } else if (bpp == 32) {
u32 *p = framebuffer; u32 *p = framebuffer;
p[idx] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]]; p[idx] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]];