From df89fa675f636b779bb2c8f96f71ab8dc7cf8cc0 Mon Sep 17 00:00:00 2001 From: Martin Donlon Date: Tue, 24 May 2022 09:49:12 -0700 Subject: [PATCH] Account for aspect ratio in vscale_mode 4/5 (#620) Both modes ensure there is enough horiztonal resolution to fit the core. They do this by reducing the vertical resolution as needed. Mode 5 keeps the horizontal resolution fixed, which uses more bandwidth but reduces the amount of resolution switches that can occur and prevents the OSD from getting to narrow in rotated arcade cores. Initialize the video_info with the current data if the fb_crc changes to ensure it has valid data for the resolution if the resolution has not changed. --- video.cpp | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/video.cpp b/video.cpp index 02b7f88..5a3abff 100644 --- a/video.cpp +++ b/video.cpp @@ -1505,13 +1505,14 @@ int hasAPI1_5() static bool get_video_info(bool force, VideoInfo *video_info) { static uint16_t nres = 0; - bool changed = false; + bool res_changed = false; + bool fb_changed = false; spi_uio_cmd_cont(UIO_GET_VRES); uint16_t res = spi_w(0); if ((nres != res) || force) { - changed = (nres != res); + res_changed = (nres != res); nres = res; video_info->width = spi_w(0) | (spi_w(0) << 16); video_info->height = spi_w(0) | (spi_w(0) << 16); @@ -1526,9 +1527,11 @@ static bool get_video_info(bool force, VideoInfo *video_info) static uint8_t fb_crc = 0; uint8_t crc = spi_uio_cmd_cont(UIO_GET_FB_PAR); - if (fb_crc != crc || force || changed) + if (fb_crc != crc || force || res_changed) { - changed |= (fb_crc != crc); + if (!res_changed) *video_info = current_video_info; + + fb_changed |= (fb_crc != crc); fb_crc = crc; video_info->arx = spi_w(0); video_info->arxy = !!(video_info->arx & 0x1000); @@ -1541,7 +1544,7 @@ static bool get_video_info(bool force, VideoInfo *video_info) } DisableIO(); - return changed; + return res_changed || fb_changed; } static void video_core_description(const VideoInfo *vi, const vmode_custom_t */*vm*/, char *str, size_t len) @@ -1639,25 +1642,28 @@ static void video_resolution_adjust(const VideoInfo *vi, vmode_custom_t *vm) int scale_w = w / core_width; if (!scale_h) return; - int disp_h, disp_w; - if (cfg.vscale_mode == 4) + int disp_h = h; + int disp_w = w; + int ary = vi->ary; + int arx = vi->arx; + if (!ary || !arx) { - int ary = vi->ary; - int arx = vi->arx; - if (!ary || !arx) - { - // full screen - ary = h; - arx = w; - } - - disp_h = core_height * scale_h; - disp_w = (disp_h * arx) / ary; + ary = h; + arx = w; } - else if(cfg.vscale_mode == 5) + + if (cfg.vscale_mode == 4 || cfg.vscale_mode == 5) { - disp_h = core_height * scale_h; - disp_w = w; + int scale; + for (scale = scale_h; scale > 0; scale--) + { + disp_h = core_height * scale; + disp_w = (disp_h * arx) / ary; + if (disp_w <= w) break; + } + if (scale == 0) return; // could not find a scale + + if (cfg.vscale_mode == 5) disp_w = w; } else {