diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index b836185b..0216d2b5 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -1431,6 +1431,15 @@ static void update_variables(void) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { PicoIn.sndFilterRange = (atoi(var.value) * 65536) / 100; } + + var.value = NULL; + var.key = "picodrive_renderer"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { + if (strcmp(var.value, "fast") == 0) + PicoIn.opt |= POPT_ALT_RENDERER; + else + PicoIn.opt &= ~POPT_ALT_RENDERER; + } } void retro_run(void) @@ -1536,6 +1545,25 @@ void retro_run(void) ps2->padding = padding; #else + if (PicoIn.opt & POPT_ALT_RENDERER) { + /* In retro_init, PicoDrawSetOutBuf is called to make sure the output gets written to vout_buf, but this only + * applies to the line renderer (pico/draw.c). The faster tile-based renderer (pico/draw2.c) enabled by + * POPT_ALT_RENDERER writes to Pico.est.Draw2FB, so we need to manually copy that to vout_buf. + */ + /* This section is mostly copied from pemu_finalize_frame in platform/linux/emu.c */ + unsigned short *pd = (unsigned short *)vout_buf; + /* Skip the leftmost 8 columns (it seems to be used as some sort of caching or overscan area) */ + unsigned char *ps = Pico.est.Draw2FB + 8; + unsigned short *pal = Pico.est.HighPal; + int x; + if (Pico.m.dirtyPal) + PicoDrawUpdateHighPal(); + /* Copy up to the max height to include the overscan area, and skip the leftmost 8 columns again */ + for (i = 0; i < VOUT_MAX_HEIGHT; i++, ps += 8) + for (x = 0; x < vout_width; x++) + *pd++ = pal[*ps++]; + } + buff = (char*)vout_buf + vout_offset; #endif diff --git a/platform/libretro/libretro_core_options.h b/platform/libretro/libretro_core_options.h index a9ac83cb..bb69909a 100644 --- a/platform/libretro/libretro_core_options.h +++ b/platform/libretro/libretro_core_options.h @@ -200,6 +200,19 @@ struct retro_core_option_definition option_defs_us[] = { }, "60" }, +#if !defined(RENDER_GSKIT_PS2) + { + "picodrive_renderer", + "Renderer", + "Fast renderer can't render any mid-frame image changes so it is useful only for some games.", + { + { "accurate", NULL }, + { "fast", NULL }, + { NULL, NULL }, + }, + "accurate" + }, +#endif { NULL, NULL, NULL, {{0}}, NULL }, };