From 569c1e62b47dd4facfc95a3bc0722b77225561c6 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sun, 4 May 2025 13:14:44 +0300 Subject: [PATCH] Reimplement resolution autoswitch. --- custom.cpp | 7 ++++-- drawing.cpp | 62 ++++++++++++++++++++++++++++++++++++++--------- include/drawing.h | 3 ++- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/custom.cpp b/custom.cpp index 3217b907..c51461ab 100644 --- a/custom.cpp +++ b/custom.cpp @@ -4594,8 +4594,8 @@ static void maybe_process_pull_audio(void) static bool crender_screen(int monid, int mode, bool immediate) { if (currprefs.gfx_vresolution && interlace_seen > 0 && currprefs.gfx_iscanlines == 0) { - // if non-fields interlace mode: render only every other frame - if (vsync_counter & 1) { + // if non-fields interlace mode: render only complete frames + if (!lof_display) { return true; } } @@ -5524,6 +5524,9 @@ static void hsync_handler_pre(bool onvsync) } } + if (GET_PLANES(bplcon0)) { + notice_resolution_seen(GET_RES_AGNUS(bplcon0), interlace_seen != 0); + } } devices_hsync(); diff --git a/drawing.cpp b/drawing.cpp index d57acd72..eeb847cb 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -851,6 +851,8 @@ void store_custom_limits(int w, int h, int x, int y) int get_custom_limits(int *pw, int *ph, int *pdx, int *pdy, int *prealh, int *hres, int *vres) { + static int interlace_count; + static int interlace_lof[2]; struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo; int w, h, dx, dy, y1, y2, dbl1, dbl2; int ret = 0; @@ -882,17 +884,27 @@ int get_custom_limits(int *pw, int *ph, int *pdx, int *pdy, int *prealh, int *hr ret = -1; if (interlace_seen) { - static int interlace_count; - // interlace = only use long frames - if (lof_display && (interlace_count & 1) == 0) - interlace_count++; - if (!lof_display && (interlace_count & 1) != 0) + for (;;) { + // if more than 1 long or short frames only: accept it, we may have double (non field) mode. + if (interlace_lof[0] >= 2 || interlace_lof[1] >= 2) { + break; + } + // wait for long frame + if (interlace_lof[0] && interlace_lof[1]) { + if (!lof_display) { + return ret; + } + } interlace_count++; - if (interlace_count < 3) - return ret; - if (!lof_display) - return ret; + interlace_lof[lof_display]++; + if (interlace_count < 3) { + return ret; + } + } + } else { interlace_count = 0; + interlace_lof[0] = 0; + interlace_lof[1] = 0; } int skip = denise_hdelay << (RES_MAX + 1); @@ -1460,6 +1472,20 @@ static void center_image (void) static int frame_res_cnt; static int autoswitch_old_resolution; + +void notice_resolution_seen(int res, bool lace) +{ + if (res > frame_res) { + frame_res = res; + } + if (res > 0) { + can_use_lores = 0; + } + if (!frame_res_lace && lace) { + frame_res_lace = lace; + } +} + static void init_drawing_frame(void) { struct amigadisplay *ad = &adisplays[0]; @@ -1470,8 +1496,9 @@ static void init_drawing_frame(void) int largest_count = 0; int largest_count_res = 0; for (int i = 0; i <= RES_MAX; i++) { - if (resolution_count[i]) + if (resolution_count[i]) { largest_res = i; + } if (resolution_count[i] >= largest_count) { largest_count = resolution_count[i]; largest_count_res = i; @@ -5703,7 +5730,9 @@ static void draw_denise_line(int gfx_ypos, enum nln_how how, uae_u32 linecnt, in ls->lol = lol; } - resolution_count[denise_res]++; + if (!line_is_blanked && denise_planes > 0) { + resolution_count[denise_res]++; + } lines_count++; } @@ -6557,6 +6586,11 @@ void draw_denise_border_line_fast(int gfx_ypos, enum nln_how how, struct linesta get_line(gfx_ypos, how); + if (!buf1 && !ls->blankedline && denise_planes > 0) { + resolution_count[denise_res]++; + } + lines_count++; + if (!buf1) { return; } @@ -6631,6 +6665,12 @@ void draw_denise_bitplane_line_fast(int gfx_ypos, enum nln_how how, struct lines get_line(gfx_ypos, how); + if (!buf1 && !ls->blankedline && denise_planes > 0) { + resolution_count[denise_res]++; + } + lines_count++; + + if (!buf1) { return; } diff --git a/include/drawing.h b/include/drawing.h index b550c3db..fd884912 100644 --- a/include/drawing.h +++ b/include/drawing.h @@ -124,13 +124,14 @@ extern void set_custom_limits(int w, int h, int dx, int dy, bool blank); extern void check_custom_limits(void); extern void get_custom_topedge(int *x, int *y, bool max); extern void get_custom_raw_limits(int *pw, int *ph, int *pdx, int *pdy); -void get_custom_mouse_limits(int *pw, int *ph, int *pdx, int *pdy, int dbl); +extern void get_custom_mouse_limits(int *pw, int *ph, int *pdx, int *pdy, int dbl); extern void putpixel(uae_u8 *buf, uae_u8 *genlockbuf, int x, xcolnr c8); extern void allocvidbuffer(int monid, struct vidbuffer *buf, int width, int height, int depth); extern void freevidbuffer(int monid, struct vidbuffer *buf); extern void check_prefs_picasso(void); extern int get_vertical_visible_height(bool); extern void get_mode_blanking_limits(int *phbstop, int *phbstrt, int *pvbstop, int *pvbstrt); +extern void notice_resolution_seen(int res, bool lace); /* Finally, stuff that shouldn't really be shared. */ -- 2.47.3