From 16828ae0be60e7e6f0ae863ee6c60ea73d12b211 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 3 Mar 2026 19:40:47 +0200 Subject: [PATCH] black level calibration updates --- custom.cpp | 8 ++++---- drawing.cpp | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/custom.cpp b/custom.cpp index 3e239faf..b5d474b0 100644 --- a/custom.cpp +++ b/custom.cpp @@ -577,7 +577,7 @@ static int current_linear_hs_hb_dist; static uae_u32 agnus_hsstrt_cck, agnus_hsstop_cck; static int agnus_hslen_cck, agnus_hslen_cck_prev, agnus_hslen_cck_cnt, current_agnus_hslen_cck; static uae_u32 agnus_phsstrt_cck, agnus_phsstop_cck; -static uae_u32 agnus_pchsstrt_cck, agnus_pchsstop_cck;; +static uae_u32 agnus_pchsstrt_cck, agnus_pchsstop_cck; static bool agnus_pvsync, agnus_pcsync, agnus_csync; static int agnus_vb, agnus_pvb; static bool agnus_vb_active; @@ -10709,11 +10709,11 @@ static void draw_line(int ldvpos, bool finalseg) l = &lines[linear_vpos][lof_display]; } - int cs = 0;// (beamcon0 & BEAMCON0_VARHSYEN) ? agnus_phsync_end - agnus_phsync_start : agnus_hsync_end - agnus_hsync_start; - int cslen = 10; + int calib_start = current_agnus_hslen_cck; + int calib_len = 2; draw_denise_line_queue(dvp, nextline_how, rga_denise_cycle_line, rga_denise_cycle_start, rga_denise_cycle, rga_denise_cycle_count_start, rga_denise_cycle_count_end, display_hstart_cyclewait_skip_start, display_hstart_cyclewait_skip_end, - wclks, cs, cslen, lof_store, lol, display_hstart_fastmode - display_hstart_cyclewait_start, nosignal_status != 0, finalseg, l); + wclks, calib_start, calib_len, lof_store, lol, display_hstart_fastmode - display_hstart_cyclewait_start, nosignal_status != 0, finalseg, l); rga_denise_cycle_count_start = rga_denise_cycle_count_end; } diff --git a/drawing.cpp b/drawing.cpp index 6bfa32e0..49626d8c 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -5453,18 +5453,15 @@ static uae_u8 blc_prev[3]; static void emulate_black_level_calibration(uae_u32 *b1, uae_u32 *b2, uae_u32 *db, int dtotal, int cstart, int clen) { int shift = hresolution + 1; - int off; + int off = cstart << shift; + + off -= denise_pixtotalskip_start << shift; - if (cstart < 0) { - off = dtotal + cstart; - } else { - off = cstart; - } uae_u32 vv[3] = { 0 }; int cnt = 0; - for (int i = 0; i < clen; i++) { - for (int ii = 0; ii < (1 << shift); ii++) { - int j = (off << shift) + (i << shift) + ii; + for (int i = 0; i < (clen << shift); i++) { + int j = off + i; + if (j >= 0) { uae_u32 v = db[j]; uae_u8 vi; vi = (v >> 16) & 0xff; @@ -5476,8 +5473,18 @@ static void emulate_black_level_calibration(uae_u32 *b1, uae_u32 *b2, uae_u32 *d cnt++; } } - db[off << shift] = 0xff0000; - db[(off << shift) + (clen << shift) - 1] = 0xff0000; + if (!cnt) { + return; + + } + +#if 1 + db[off] = 0xff0000; + db[off + (clen << shift) - 1] = 0xff0000; + + b1[off] = 0xff0000; + b1[off + (clen << shift) - 1] = 0xff0000; +#endif int outc[3]; for (int i = 0; i < 3; i++) { @@ -5487,9 +5494,10 @@ static void emulate_black_level_calibration(uae_u32 *b1, uae_u32 *b2, uae_u32 *d // if (outc[0] > 10 || outc[1] > 10 || outc[2] > 10) // write_log("%02x %02x %02x\n", outc[0], outc[1], outc[2]); + bool useb2 = b1 != b2 && b2; if (outc[0] <= 3 && outc[1] <= 3 && outc[2] <= 3) { memcpy(b1, db, (dtotal * sizeof(uae_u32)) << shift); - if (b1 != b2) { + if (useb2) { memcpy(b2, db, (dtotal * sizeof(uae_u32)) << shift); } } else { @@ -5505,14 +5513,20 @@ static void emulate_black_level_calibration(uae_u32 *b1, uae_u32 *b2, uae_u32 *d if (c[j] <= outc[j]) { c[j] = 0; } else { - c[j] = (c[j] - outc[j]) * 256 / outc[j]; + int cc = c[j] + outc[j]; + if (cc >= 256) { + cc = 255; + } + c[j] = cc; } } } v = (c[0] << 16) | (c[1] << 8) | (c[2] << 0); } *b1++ = v; - *b2++ = v; + if (useb2) { + *b2++ = v; + } } } } -- 2.47.3