From 1727b6d56fd4bb20f33f5f356132598c48899d0d Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 4 Apr 2026 12:38:51 +0300 Subject: [PATCH] Mouse sync positioning updates --- custom.cpp | 62 +++++++++------------------ drawing.cpp | 107 +++++++++++++--------------------------------- include/drawing.h | 1 - inputdevice.cpp | 5 +++ 4 files changed, 55 insertions(+), 120 deletions(-) diff --git a/custom.cpp b/custom.cpp index 1f04f227..ff233641 100644 --- a/custom.cpp +++ b/custom.cpp @@ -75,8 +75,6 @@ #define SPRBORDER 0 -#define EXTRAHEIGHT_EXTREME 28 - #define LORES_TO_SHRES_SHIFT 2 #ifdef SERIAL_PORT @@ -393,7 +391,6 @@ static int next_lineno; int linear_vpos, linear_vpos_vb_start, linear_vpos_vb_end, linear_hpos, linear_vpos_prev[3], linear_hpos_prev[3]; static int linear_vb_offset; static int linear_vpos_vsync; -int vsync_start_offset; int linear_display_vpos; int current_linear_vpos, current_linear_hpos; static int current_linear_hblen, current_linear_hblen_temp; @@ -613,8 +610,8 @@ int hdisplay_left_border; int denisehtotal; static int maxvpos_total = 511; -int minfirstline = VBLANK_ENDLINE_PAL; -int minfirstline_linear = VBLANK_ENDLINE_PAL; +int minfirstline; +int minfirstline_linear; float vblank_hz = VBLANK_HZ_PAL, fake_vblank_hz, vblank_hz_stored, vblank_hz_nom; float hblank_hz; static float vblank_hz_lof, vblank_hz_shf, vblank_hz_lace; @@ -1691,6 +1688,8 @@ void compute_framesync(void) int hiddenbottomv = display_vblankend_skip; int maxv = current_linear_vpos - (hiddentopv + hiddenbottomv) + 1; linear_vpos_vb_end = current_linear_vpos_vb_end - display_vblankstart_skip - 1; + minfirstline = vblines - (display_vblankstart_skip > 0 ? display_vblankstart_skip : 0) - 1; + minfirstline_linear = minfirstline - LINES_AFTER_VSYNC; if (currprefs.gfx_overscanmode >= OVERSCANMODE_ULTRA) { maxv = current_linear_vpos; linear_vpos_vb_end = 0; @@ -1842,12 +1841,12 @@ static void init_beamcon0(void) if (!isntsc) { maxvpos = MAXVPOS_PAL; maxhpos = MAXHPOS_PAL; - minfirstline = VBLANK_STOP_PAL; + //minfirstline = VBLANK_STOP_PAL; vblank_hz_nom = vblank_hz = CHIPSET_CLOCK_PAL / ((float)display_maxvpos * display_maxhpos); } else { maxvpos = MAXVPOS_NTSC; maxhpos = MAXHPOS_NTSC; - minfirstline = VBLANK_STOP_NTSC; + //minfirstline = VBLANK_STOP_NTSC; vblank_hz_nom = vblank_hz = CHIPSET_CLOCK_NTSC / ((float)display_maxvpos * display_maxhpos); halfhpos = (beamcon0 & BEAMCON0_LOLDIS) ? 0 : 0.5f; } @@ -1965,7 +1964,7 @@ static void init_beamcon0(void) maxhpos_display = hsync_ccks * 2; display_hstart_cyclewait_start = 0; display_hstart_cyclewait_end = 0; - minfirstline = 0; + //minfirstline = 0; } if (display_hstart_cyclewait_start < 0) { @@ -2110,37 +2109,23 @@ static void init_beamcon0(void) maxhpos_display += currprefs.gfx_extrawidth; } - //if (hsstop_detect < 0) { - // hsstop_detect = 0; - //} - if (minfirstline < 0) { - minfirstline = 0; - } - int vbstart = linear_vpos_vblank_end; if (currprefs.cs_hvcsync >= HVSYNC_SYNCPOS) { vbstart = LINES_AFTER_VSYNC; - minfirstline = vbstart; } - minfirstline_linear = vbstart; maxvpos_display_vsync = 0; display_vblankstart_skip = 0; display_vblankend_skip = 0; if (currprefs.gfx_overscanmode >= OVERSCANMODE_ULTRA) { vsync_startline = LINES_AFTER_VSYNC; - minfirstline = 0; - minfirstline_linear = 0; maxvpos_display_vsync = vsync_startline; display_vblankstart_skip = -3000; } else if (currprefs.gfx_overscanmode == OVERSCANMODE_EXTREME) { - minfirstline_linear -= EXTRAHEIGHT_EXTREME / 2; - minfirstline -= EXTRAHEIGHT_EXTREME / 2; display_vblankstart_skip = vbstart; display_vblankend_skip = 3; maxvpos_display_vsync += 2; } else if (currprefs.gfx_overscanmode == OVERSCANMODE_BROADCAST) { - minfirstline_linear -= 0; maxvpos_display_vsync++; display_vblankstart_skip = -1; display_vblankend_skip = 2; @@ -2150,10 +2135,8 @@ static void init_beamcon0(void) display_vblankstart_skip = -1; display_vblankend_skip = 2; } - if (minfirstline_linear < 0) { - minfirstline_linear += current_linear_vpos_nom; - } +#if 0 if ((beamcon0 & BEAMCON0_VARVBEN) && (beamcon0 & bemcon0_vsync_mask)) { if (minfirstline < vsync_startline) { minfirstline = vsync_startline; @@ -2171,6 +2154,7 @@ static void init_beamcon0(void) } } } +#endif if (beamcon0 & (BEAMCON0_VARVBEN | bemcon0_vsync_mask)) { programmedmode = 2; } @@ -2188,19 +2172,17 @@ static void init_beamcon0(void) display_hstart_cyclewait_end = 0; } - if (minfirstline < vsync_startline) { - minfirstline = vsync_startline; - } - - if (minfirstline >= vsync_lines) { - minfirstline = vsync_lines - 1; - } - - if (beamcon0 & bemcon0_vsync_mask) { - if (minfirstline < vsync_startline) { - minfirstline = vsync_startline; - } - } +// if (minfirstline < vsync_startline) { +// minfirstline = vsync_startline; +// } +// if (minfirstline >= vsync_lines) { +// minfirstline = vsync_lines - 1; +// } +// if (beamcon0 & bemcon0_vsync_mask) { +// if (minfirstline < vsync_startline) { +// minfirstline = vsync_startline; +// } +// } if (beamcon0 & BEAMCON0_VARBEAMEN) { float half = (beamcon0 & BEAMCON0_PAL) ? 0: ((beamcon0 & BEAMCON0_LOLDIS) ? 0 : 0.5f); @@ -10103,10 +10085,8 @@ static void vsync_mark(void) } vb_end_detect = false; linear_vpos = 0; - int off = currprefs.cs_hvcsync >= HVSYNC_SYNCPOS ? LINES_AFTER_VSYNC : linear_vb_offset; - vsync_start_offset = -off; - + minfirstline_linear = off; } } diff --git a/drawing.cpp b/drawing.cpp index 34512c7a..84eec99b 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -74,8 +74,6 @@ static uae_u8 *xlinebuffer_start, *xlinebuffer_end; static uae_u8 *xlinebuffer2_start, *xlinebuffer2_end; static uae_u8 *xlinebuffer_genlock_start, *xlinebuffer_genlock_end; -static int *amiga2aspect_line_map, *native2amiga_line_map; -static int native2amiga_line_map_height; static uae_u8 *row_map_genlock_buffer; static uae_u8 row_tmp8[MAX_PIXELS_PER_LINE * 32 / 8]; static uae_u8 row_tmp8g[MAX_PIXELS_PER_LINE * 32 / 8]; @@ -306,7 +304,7 @@ bool denisea1000; bool direct_rgb; -static int linedbl, linedbld; +static int linedbl; int interlace_seen; int detected_screen_resolution; @@ -447,6 +445,7 @@ static int linear_denise_frame_hbstrt_tmp, linear_denise_frame_hbstop_tmp; static int linear_denise_frame_hbstrt_sel, linear_denise_frame_hbstop_sel; static bool denise_blanking_changed; static int linear_denise_strobe_offset; +static int denise_strobe_offset, horizontalzerooffset; static int denise_visible_lines, denise_visible_lines_counted; static uae_u16 hbstrt_denise_reg, hbstop_denise_reg; static uae_u16 fmode_denise, denise_bplfmode, denise_sprfmode; @@ -603,19 +602,15 @@ STATIC_INLINE int xshift(int x, int shift) int coord_native_to_amiga_x(int x) { - x += visible_left_border; + x += horizontalzerooffset / 2; return x; } int coord_native_to_amiga_y(int y) { - if (!native2amiga_line_map || y < 0) { - return 0; - } - if (y >= native2amiga_line_map_height) { - y = native2amiga_line_map_height - 1; - } - return native2amiga_line_map[y]; + y += min_ypos_for_screen; + y >>= linedbl; + return y; } void notice_screen_contents_lost(int monid) @@ -1115,11 +1110,11 @@ void get_custom_mouse_limits (int *pw, int *ph, int *pdx, int *pdy, int dbl) y2 = plflastline_total + 1; y1 = plffirstline_total; - if (minfirstline > y1) - y1 = minfirstline; + if (minfirstline_linear > y1) + y1 = minfirstline_linear; h = y2 - y1; - dy = y1 - minfirstline; + dy = y1 - minfirstline_linear; if (*pw > 0) w = *pw; @@ -1265,67 +1260,6 @@ static void gen_pfield_tables(void) } } -static void init_aspect_maps(void) -{ - struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo; - struct vidbuffer *vb = vidinfo->inbuffer; - int i, maxl, h; - - linedbld = linedbl = currprefs.gfx_vresolution; - if (doublescan > 0 && interlace_seen <= 0) { - linedbl = 0; - linedbld = 1; - } - maxl = (MAXVPOS + 1) << linedbld; - min_ypos_for_screen = minfirstline << linedbl; - max_drawn_amiga_line = -1; - - vidinfo->xchange = 1 << (RES_MAX - currprefs.gfx_resolution); - vidinfo->ychange = linedbl ? 1 : 2; - - visible_left_start = 0; - visible_right_stop = MAX_STOP; - visible_top_start = 0; - visible_bottom_stop = MAX_STOP; - - h = vb->height_allocated; - if (h == 0) - /* Do nothing if the gfx driver hasn't initialized the screen yet */ - return; - - if (native2amiga_line_map) - xfree (native2amiga_line_map); - if (amiga2aspect_line_map) - xfree (amiga2aspect_line_map); - - /* At least for this array the +1 is necessary. */ - native2amiga_line_map_height = h; - amiga2aspect_line_map = xmalloc (int, (MAXVPOS + 1) * 2 + 1); - native2amiga_line_map = xmalloc (int, native2amiga_line_map_height); - - for (i = 0; i < maxl; i++) { - int v = i - min_ypos_for_screen; - if (v >= h && max_drawn_amiga_line < 0) - max_drawn_amiga_line = v; - if (i < min_ypos_for_screen || v >= native2amiga_line_map_height) - v = -1; - amiga2aspect_line_map[i] = v; - } - if (max_drawn_amiga_line < 0) - max_drawn_amiga_line = maxl - min_ypos_for_screen; - - for (i = 0; i < native2amiga_line_map_height; i++) - native2amiga_line_map[i] = -1; - - for (i = maxl - 1; i >= min_ypos_for_screen; i--) { - int j; - if (amiga2aspect_line_map[i] == -1) - continue; - for (j = amiga2aspect_line_map[i]; j < native2amiga_line_map_height && native2amiga_line_map[j] == -1; j++) - native2amiga_line_map[j] = i >> linedbl; - } -} - void init_row_map(void) { struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo; @@ -1362,7 +1296,21 @@ void init_row_map(void) oldgenlock = init_genlock_data; oldburst = row_map_color_burst_buffer ? 1 : 0; - init_aspect_maps(); + int linedbld = currprefs.gfx_vresolution; + linedbl = linedbld; + if (doublescan > 0 && interlace_seen > 0) { + linedbl *= 2; + } + int maxl = (MAXVPOS + 1) << linedbld; + max_drawn_amiga_line = -1; + + vidinfo->xchange = 1 << (RES_MAX - currprefs.gfx_resolution); + vidinfo->ychange = linedbl ? 1 : 2; + + visible_left_start = 0; + visible_right_stop = MAX_STOP; + visible_top_start = 0; + visible_bottom_stop = MAX_STOP; } static bool cancenter(void) @@ -1529,7 +1477,7 @@ static void center_image(void) } vidinfo->inbuffer->xoffset = visible_left_border << (RES_MAX - currprefs.gfx_resolution); - vidinfo->inbuffer->yoffset = (-vsync_start_offset) << VRES_MAX; + vidinfo->inbuffer->yoffset = minfirstline_linear << VRES_MAX; int linedbl = currprefs.gfx_vresolution; if (doublescan > 0 && interlace_seen <= 0) { @@ -2245,7 +2193,7 @@ void full_redraw_all(void) bool redraw = false; struct amigadisplay *ad = &adisplays[monid]; struct vidbuf_description *vidinfo = &adisplays[monid].gfxvidinfo; - if (vidinfo->inbuffer && vidinfo->inbuffer->height_allocated && amiga2aspect_line_map) { + if (vidinfo->inbuffer && vidinfo->inbuffer->height_allocated) { notice_screen_contents_lost(monid); if (!ad->picasso_on) { redraw_frame(); @@ -4030,6 +3978,7 @@ static void handle_strobes(struct denise_rga *rd) } previous_strobe = rd->rga; linear_denise_strobe_offset = rd->v * 8; + denise_strobe_offset = internal_pixel_cnt; reset_strlong(); spr_nearest(); } @@ -6167,6 +6116,8 @@ static void draw_denise_line(int gfx_ypos, enum nln_how how, uae_u32 linecnt, in } frame_internal_pixel_cnt = internal_pixel_cnt; + horizontalzerooffset = internal_pixel_cnt - denise_strobe_offset; + horizontalzerooffset += internal_pixel_start_cnt; // detect horizontal blanking if (!denise_vblank_active) { diff --git a/include/drawing.h b/include/drawing.h index 4ba9dfb1..2bd86d68 100644 --- a/include/drawing.h +++ b/include/drawing.h @@ -25,7 +25,6 @@ extern int detected_screen_resolution; extern int hdisplay_left_border, denisehtotal; extern int vsync_startline; extern int video_recording_active; -extern int vsync_start_offset; #define AMIGA_WIDTH_MAX (754 / 2) #define AMIGA_HEIGHT_MAX_PAL (576 / 2) diff --git a/inputdevice.cpp b/inputdevice.cpp index e166df9f..6c43527c 100644 --- a/inputdevice.cpp +++ b/inputdevice.cpp @@ -2691,6 +2691,11 @@ static bool get_mouse_position(int *xp, int *yp, int inx, int iny) ob = true; y = vidinfo->outbuffer->outheight - 1; } + if (currprefs.gfx_resolution == RES_LORES) { + x *= 2; + } else if (currprefs.gfx_resolution == RES_SUPERHIRES) { + x /= 2; + } x = coord_native_to_amiga_x(x); if (y >= 0) { y = coord_native_to_amiga_y(y) * 2; -- 2.47.3