From b318c27a3e3f9b50f165508b99108dd9415d398d Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 28 Sep 2026 20:36:27 +0200 Subject: [PATCH 1/8] zaparoo: add analog H-size word2 packing, live apply and TOML mirror Interim control extension: word2 (bytes 0x08-0x0B) carries magic 0x5A52 and a signed h_size (-8..+2) written only by Main; the frontend never touches bytes >= 8. Persisted as crt_h_size in frontend.toml [settings], which the frontend's toml_edit writer preserves. Test pattern publishes word2 too. Co-Authored-By: Claude Fable 5.1 --- support/zaparoo/crt_settings.cpp | 49 ++++++++++++++++++++++++++++++-- support/zaparoo/crt_settings.h | 22 ++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/support/zaparoo/crt_settings.cpp b/support/zaparoo/crt_settings.cpp index d185b4cfc..8b31ac6f6 100644 --- a/support/zaparoo/crt_settings.cpp +++ b/support/zaparoo/crt_settings.cpp @@ -11,6 +11,7 @@ static const uint32_t s_native_addr = 0x3A000000u; static const uint32_t s_native_size = 0x00300000u; static const uint32_t s_slot0_off = 0x1000u; static const uint32_t s_word1_magic = 0x5A50u; +static const uint32_t s_word2_magic = 0x5A52u; static const size_t s_toml_max = 65536; static bool s_pattern_active = false; @@ -213,6 +214,20 @@ bool crt_toml_set_standard(uint8_t mode) return toml_set("crt_video_standard", v); } +void crt_toml_get_hsize(int *s) +{ + int sv = 0; + toml_get_int("crt_h_size", &sv); + *s = clamp_int(sv, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); +} + +bool crt_toml_set_hsize(int s) +{ + char buf[16]; + snprintf(buf, sizeof(buf), "%d", clamp_int(s, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX)); + return toml_set("crt_h_size", buf); +} + void crt_toml_get_offsets(int *h, int *v) { int hv = 0, vv = 0; @@ -251,6 +266,31 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode) shmem_unmap(p, 0x1000); } +// word2: [31:16] magic 0x5A52, [15:8] reserved 0, [7:0] h size as int8. +// See the interim contract note in crt_settings.h. +static uint32_t pack_word2(int s) +{ + uint32_t sb = (uint8_t)(int8_t)clamp_int(s, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); + return (s_word2_magic << 16) | sb; +} + +void crt_hsize_apply_live(int s) +{ + void *p = shmem_map(s_native_addr, 0x1000); + if (!p) return; + volatile uint32_t *w = (volatile uint32_t *)p; + w[2] = pack_word2(s); + __sync_synchronize(); + shmem_unmap(p, 0x1000); +} + +void crt_hsize_republish(void) +{ + int s = 0; + crt_toml_get_hsize(&s); + crt_hsize_apply_live(s); +} + static void mode_dims(uint8_t mode, int *w, int *h) { switch (mode) @@ -305,9 +345,14 @@ bool crt_test_pattern_publish(uint8_t mode, int h, int v) hline(px, w, ht, ht / 2, w / 2 - 16, w / 2 + 16, white); vline(px, w, ht, w / 2, ht / 2 - 12, ht / 2 + 12, white); - // word1 before word0: the core latches both per vblank and a non-zero - // word0 publishes the frame. + // word1/word2 before word0: the core latches them per vblank and a + // non-zero word0 publishes the frame. words[1] = pack_word1(h, v, mode); + { + int hs = 0; + crt_toml_get_hsize(&hs); + words[2] = pack_word2(hs); + } __sync_synchronize(); words[0] = (1u << 2) | 0u; __sync_synchronize(); diff --git a/support/zaparoo/crt_settings.h b/support/zaparoo/crt_settings.h index 0d8490bab..4ec96d0e4 100644 --- a/support/zaparoo/crt_settings.h +++ b/support/zaparoo/crt_settings.h @@ -23,6 +23,12 @@ #define CRT_V_OFFSET_MIN -8 #define CRT_V_OFFSET_MAX 2 +// Analog H size (width stretch), steps of 1/64 pixel period. 0 = unity +// (retimer bypassed). Positive limit +2: the retimer drains each line +// before the incoming HSYNC and NTSC's 12 px front porch caps the growth. +#define CRT_H_SIZE_MIN -8 +#define CRT_H_SIZE_MAX 2 + const char *crt_standard_name(uint8_t mode); uint8_t crt_standard_next(uint8_t mode); @@ -31,12 +37,28 @@ uint8_t crt_standard_next(uint8_t mode); bool crt_toml_set_standard(uint8_t mode); void crt_toml_get_offsets(int *h, int *v); bool crt_toml_set_offsets(int h, int v); +void crt_toml_get_hsize(int *s); +bool crt_toml_set_hsize(int s); // Live centering: rewrites DDR control word1. Only meaningful while the // menu core is scanning a published frame (frontend --crt or the test // pattern below). void crt_offsets_apply_live(int h, int v, uint8_t mode); +// Interim word2 contract (analog H size). The core's per-vblank control +// poll reads two 64-bit beats at 0x3A000000: beat 1 is the unchanged v2 +// word0/word1 (magics 0x5A50/0x5A51); beat 2's low word ("word2", bytes +// 0x08-0x0B) is [31:16] magic 0x5A52, [15:8] reserved 0, [7:0] signed +// h_size (core-clamped to -8..+2; anything without the magic reads as 0). +// Word2 is written ONLY by Main (this page's live apply, the test pattern, +// and a republish after alt_launcher's pre-spawn 3 MB blank); the frontend +// never writes bytes >= 8, so the value survives its word0/word1 publishes. +// h_size applies only while word1's magic is valid. The deferred v3 plan +// (plans/menu-crt-video-plan.md sec. 7) repurposes byte 0x08 and moves +// 0x5A52 into word1; matched releases will replace this layout wholesale. +void crt_hsize_apply_live(int s); +void crt_hsize_republish(void); + // Main-drawn alignment pattern published into DDR slot 0 so centering can // be adjusted without a running frontend. unpublish returns the core to // its default pattern. From 3eb4ba33810c4ad7ee5c2f0e203a4e4848c65081 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 28 Sep 2026 20:36:27 +0200 Subject: [PATCH 2/8] zaparoo: add H size row to the OSD Position page Live-applies via word2 while a picture is up; saves crt_h_size on leave. Size-only changes skip the frontend respawn: the frontend never caches or rewrites this key. Co-Authored-By: Claude Fable 5.1 --- support/zaparoo/launcher_pages.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/support/zaparoo/launcher_pages.cpp b/support/zaparoo/launcher_pages.cpp index 5bc921fb2..bb182da71 100644 --- a/support/zaparoo/launcher_pages.cpp +++ b/support/zaparoo/launcher_pages.cpp @@ -156,6 +156,7 @@ bool kiosk_page_confirm(int menusub) } static int s_h, s_v, s_h0, s_v0; +static int s_size, s_size0; static bool s_pattern; static bool position_live(void) @@ -171,8 +172,10 @@ static int clamp_int(int v, int lo, int hi) void position_page_enter(void) { crt_toml_get_offsets(&s_h, &s_v); + crt_toml_get_hsize(&s_size); s_h0 = s_h; s_v0 = s_v; + s_size0 = s_size; s_pattern = false; if (alt_launcher_native_crt_persisted() && !alt_launcher_active()) s_pattern = crt_test_pattern_publish(alt_launcher_native_crt_mode(), s_h, s_v); @@ -182,7 +185,7 @@ void position_page_render(int menusub, uint64_t *menumask) { OsdSetSize(16); OsdSetTitle("Position", 0); - *menumask = 0x7; + *menumask = 0xF; char s[64]; int m = 0; @@ -191,23 +194,32 @@ void position_page_render(int menusub, uint64_t *menumask) OsdWrite(m++, s, menusub == 0); sprintf(s, " V offset: %+3d", s_v); OsdWrite(m++, s, menusub == 1); + sprintf(s, " H size: %+3d", s_size); + OsdWrite(m++, s, menusub == 2); OsdWrite(m++, ""); - OsdWrite(m++, position_live() ? " Left/Right: move picture" : " No CRT picture to adjust"); + OsdWrite(m++, position_live() ? " Left/Right: adjust picture" : " No CRT picture to adjust"); + OsdWrite(m++, " (+2 size narrows position)"); while (m < OsdGetSize() - 1) OsdWrite(m++, ""); - OsdWrite(15, PAGE_STD_BACK, menusub == 2); + OsdWrite(15, PAGE_STD_BACK, menusub == 3); } void position_page_adjust(int menusub, int dir) { if (menusub == 0) s_h = clamp_int(s_h + dir, CRT_H_OFFSET_MIN, CRT_H_OFFSET_MAX); else if (menusub == 1) s_v = clamp_int(s_v + dir, CRT_V_OFFSET_MIN, CRT_V_OFFSET_MAX); + else if (menusub == 2) + { + s_size = clamp_int(s_size + dir, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); + if (position_live()) crt_hsize_apply_live(s_size); + return; + } else return; if (position_live()) crt_offsets_apply_live(s_h, s_v, alt_launcher_native_crt_mode()); } bool position_page_is_exit(int menusub) { - return menusub == 2; + return menusub == 3; } void position_page_leave(void) @@ -217,6 +229,14 @@ void position_page_leave(void) crt_test_pattern_unpublish(); s_pattern = crt_test_pattern_active(); } + if (s_size != s_size0) + { + // Size needs no respawn: the frontend never reads, caches, or writes + // crt_h_size (or DDR bytes >= 8), so the live word2 write plus this + // TOML save is already complete. + if (crt_toml_set_hsize(s_size)) s_size0 = s_size; + else printf("launcher_pages: h size not saved\n"); + } if (s_h == s_h0 && s_v == s_v0) return; if (!crt_toml_set_offsets(s_h, s_v)) { From 6443a1303ec1724d3a6b241ae5b7247cf28652c3 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 28 Sep 2026 20:36:27 +0200 Subject: [PATCH 3/8] zaparoo: republish H-size word2 after the pre-spawn DDR blank blank_native_crt_fb() wipes the whole 3 MB region including word2; the frontend only republishes words 0/1. Co-Authored-By: Claude Fable 5.1 --- support/zaparoo/alt_launcher.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/support/zaparoo/alt_launcher.cpp b/support/zaparoo/alt_launcher.cpp index d91eb05f0..874c0158a 100644 --- a/support/zaparoo/alt_launcher.cpp +++ b/support/zaparoo/alt_launcher.cpp @@ -502,6 +502,10 @@ static void finish_native_crt_path(void) blank_native_crt_fb(); + // The 3 MB blank wiped control word2 (analog H size); the frontend only + // ever republishes words 0/1, so restore the persisted size here. + crt_hsize_republish(); + s_native_fb_mode_timer = GetTimer(1000); if (!s_native_fb_mode_timer) s_native_fb_mode_timer = 1; } From 6bd073194bc1cf5d5d9ffcd13b7b544f8f4dc87a Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 28 Sep 2026 20:36:27 +0200 Subject: [PATCH 4/8] yc.txt: drop stale MENU PHASE_INC overrides The four MENU_* entries encode colorburst increments for the stock menu core's 20/27.027 MHz clocks and override video.cpp's measured-clock computation. The Zaparoo menu core's video master moves to 54 MHz, where any match makes the chroma carrier wrong; the computed path self-adapts. Co-Authored-By: Claude Fable 5.1 --- yc.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/yc.txt b/yc.txt index a5affca4b..b0e8b91d3 100644 --- a/yc.txt +++ b/yc.txt @@ -253,10 +253,6 @@ JTTORA_59.6=81995078596 JTTROJAN_56.0=81994363707 JTVIGIL_56.3=80073162204 JTVULGUS_59.6=81995078596 -MENU_59.8=196786767482 -MENU_50.2=243746729900 -MENU_60.0=145620875904 -MENU_59.9i=145622662586 VECTOR06_50.1=50779326758 COCO2_58.7=91625969068 RX78_60.1=70281324000 From fc4643c1f96188bddd29bffc1ab4779b87d178b8 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Thu, 1 Oct 2026 23:48:30 +0200 Subject: [PATCH 5/8] zaparoo: add V size (vertical shrink) to the OSD Position page Word2 bits 15:8 now carry a signed v_size (-32..0): -N adds N blank lines per progressive frame, shrinking the picture by lowering the frame rate (262+N / 312+N lines) while the line rate and active lines stay fixed. Shrink only, no grow. Persisted as crt_v_size in frontend.toml; the republish-after-blank hook and the test pattern carry both sizes. 480i forces N=0 in the core's timing latch. Known tradeoff carried from the plan: with the live frontend publishing on a fixed 60 Hz sleep while the CRT consumes slower, moving content can tear at deep shrink; the static test pattern is unaffected. The deferred v3 protocol addresses pacing properly. Co-Authored-By: Claude Fable 5.1 --- support/zaparoo/alt_launcher.cpp | 6 ++--- support/zaparoo/crt_settings.cpp | 41 +++++++++++++++++++++--------- support/zaparoo/crt_settings.h | 14 +++++++--- support/zaparoo/launcher_pages.cpp | 27 +++++++++++++++++--- 4 files changed, 66 insertions(+), 22 deletions(-) diff --git a/support/zaparoo/alt_launcher.cpp b/support/zaparoo/alt_launcher.cpp index 874c0158a..c0a670461 100644 --- a/support/zaparoo/alt_launcher.cpp +++ b/support/zaparoo/alt_launcher.cpp @@ -502,9 +502,9 @@ static void finish_native_crt_path(void) blank_native_crt_fb(); - // The 3 MB blank wiped control word2 (analog H size); the frontend only - // ever republishes words 0/1, so restore the persisted size here. - crt_hsize_republish(); + // The 3 MB blank wiped control word2 (analog H/V size); the frontend + // only ever republishes words 0/1, so restore the persisted sizes here. + crt_size_republish(); s_native_fb_mode_timer = GetTimer(1000); if (!s_native_fb_mode_timer) s_native_fb_mode_timer = 1; diff --git a/support/zaparoo/crt_settings.cpp b/support/zaparoo/crt_settings.cpp index 8b31ac6f6..393626388 100644 --- a/support/zaparoo/crt_settings.cpp +++ b/support/zaparoo/crt_settings.cpp @@ -228,6 +228,20 @@ bool crt_toml_set_hsize(int s) return toml_set("crt_h_size", buf); } +void crt_toml_get_vsize(int *s) +{ + int sv = 0; + toml_get_int("crt_v_size", &sv); + *s = clamp_int(sv, CRT_V_SIZE_MIN, CRT_V_SIZE_MAX); +} + +bool crt_toml_set_vsize(int s) +{ + char buf[16]; + snprintf(buf, sizeof(buf), "%d", clamp_int(s, CRT_V_SIZE_MIN, CRT_V_SIZE_MAX)); + return toml_set("crt_v_size", buf); +} + void crt_toml_get_offsets(int *h, int *v) { int hv = 0, vv = 0; @@ -266,29 +280,31 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode) shmem_unmap(p, 0x1000); } -// word2: [31:16] magic 0x5A52, [15:8] reserved 0, [7:0] h size as int8. +// word2: [31:16] magic 0x5A52, [15:8] v size as int8, [7:0] h size as int8. // See the interim contract note in crt_settings.h. -static uint32_t pack_word2(int s) +static uint32_t pack_word2(int h, int v) { - uint32_t sb = (uint8_t)(int8_t)clamp_int(s, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); - return (s_word2_magic << 16) | sb; + uint32_t hb = (uint8_t)(int8_t)clamp_int(h, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); + uint32_t vb = (uint8_t)(int8_t)clamp_int(v, CRT_V_SIZE_MIN, CRT_V_SIZE_MAX); + return (s_word2_magic << 16) | (vb << 8) | hb; } -void crt_hsize_apply_live(int s) +void crt_size_apply_live(int h_size, int v_size) { void *p = shmem_map(s_native_addr, 0x1000); if (!p) return; volatile uint32_t *w = (volatile uint32_t *)p; - w[2] = pack_word2(s); + w[2] = pack_word2(h_size, v_size); __sync_synchronize(); shmem_unmap(p, 0x1000); } -void crt_hsize_republish(void) +void crt_size_republish(void) { - int s = 0; - crt_toml_get_hsize(&s); - crt_hsize_apply_live(s); + int h = 0, v = 0; + crt_toml_get_hsize(&h); + crt_toml_get_vsize(&v); + crt_size_apply_live(h, v); } static void mode_dims(uint8_t mode, int *w, int *h) @@ -349,9 +365,10 @@ bool crt_test_pattern_publish(uint8_t mode, int h, int v) // non-zero word0 publishes the frame. words[1] = pack_word1(h, v, mode); { - int hs = 0; + int hs = 0, vs = 0; crt_toml_get_hsize(&hs); - words[2] = pack_word2(hs); + crt_toml_get_vsize(&vs); + words[2] = pack_word2(hs, vs); } __sync_synchronize(); words[0] = (1u << 2) | 0u; diff --git a/support/zaparoo/crt_settings.h b/support/zaparoo/crt_settings.h index 4ec96d0e4..61418fbf3 100644 --- a/support/zaparoo/crt_settings.h +++ b/support/zaparoo/crt_settings.h @@ -29,6 +29,11 @@ #define CRT_H_SIZE_MIN -8 #define CRT_H_SIZE_MAX 2 +// Vertical size (shrink only): -N adds N blank lines per progressive frame, +// lowering the frame rate (262+N / 312+N lines). 480i forces 0 in RTL. +#define CRT_V_SIZE_MIN -32 +#define CRT_V_SIZE_MAX 0 + const char *crt_standard_name(uint8_t mode); uint8_t crt_standard_next(uint8_t mode); @@ -39,6 +44,8 @@ void crt_toml_get_offsets(int *h, int *v); bool crt_toml_set_offsets(int h, int v); void crt_toml_get_hsize(int *s); bool crt_toml_set_hsize(int s); +void crt_toml_get_vsize(int *s); +bool crt_toml_set_vsize(int s); // Live centering: rewrites DDR control word1. Only meaningful while the // menu core is scanning a published frame (frontend --crt or the test @@ -48,7 +55,8 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode); // Interim word2 contract (analog H size). The core's per-vblank control // poll reads two 64-bit beats at 0x3A000000: beat 1 is the unchanged v2 // word0/word1 (magics 0x5A50/0x5A51); beat 2's low word ("word2", bytes -// 0x08-0x0B) is [31:16] magic 0x5A52, [15:8] reserved 0, [7:0] signed +// 0x08-0x0B) is [31:16] magic 0x5A52, [15:8] signed v_size (-32..0, -N +// adds N blank lines per progressive frame, 480i forces 0), [7:0] signed // h_size (core-clamped to -8..+2; anything without the magic reads as 0). // Word2 is written ONLY by Main (this page's live apply, the test pattern, // and a republish after alt_launcher's pre-spawn 3 MB blank); the frontend @@ -56,8 +64,8 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode); // h_size applies only while word1's magic is valid. The deferred v3 plan // (plans/menu-crt-video-plan.md sec. 7) repurposes byte 0x08 and moves // 0x5A52 into word1; matched releases will replace this layout wholesale. -void crt_hsize_apply_live(int s); -void crt_hsize_republish(void); +void crt_size_apply_live(int h_size, int v_size); +void crt_size_republish(void); // Main-drawn alignment pattern published into DDR slot 0 so centering can // be adjusted without a running frontend. unpublish returns the core to diff --git a/support/zaparoo/launcher_pages.cpp b/support/zaparoo/launcher_pages.cpp index bb182da71..bb06ce31d 100644 --- a/support/zaparoo/launcher_pages.cpp +++ b/support/zaparoo/launcher_pages.cpp @@ -157,6 +157,7 @@ bool kiosk_page_confirm(int menusub) static int s_h, s_v, s_h0, s_v0; static int s_size, s_size0; +static int s_vsize, s_vsize0; static bool s_pattern; static bool position_live(void) @@ -173,9 +174,11 @@ void position_page_enter(void) { crt_toml_get_offsets(&s_h, &s_v); crt_toml_get_hsize(&s_size); + crt_toml_get_vsize(&s_vsize); s_h0 = s_h; s_v0 = s_v; s_size0 = s_size; + s_vsize0 = s_vsize; s_pattern = false; if (alt_launcher_native_crt_persisted() && !alt_launcher_active()) s_pattern = crt_test_pattern_publish(alt_launcher_native_crt_mode(), s_h, s_v); @@ -185,7 +188,7 @@ void position_page_render(int menusub, uint64_t *menumask) { OsdSetSize(16); OsdSetTitle("Position", 0); - *menumask = 0xF; + *menumask = 0x1F; char s[64]; int m = 0; @@ -196,11 +199,13 @@ void position_page_render(int menusub, uint64_t *menumask) OsdWrite(m++, s, menusub == 1); sprintf(s, " H size: %+3d", s_size); OsdWrite(m++, s, menusub == 2); + sprintf(s, " V size: %+3d", s_vsize); + OsdWrite(m++, s, menusub == 3); OsdWrite(m++, ""); OsdWrite(m++, position_live() ? " Left/Right: adjust picture" : " No CRT picture to adjust"); OsdWrite(m++, " (+2 size narrows position)"); while (m < OsdGetSize() - 1) OsdWrite(m++, ""); - OsdWrite(15, PAGE_STD_BACK, menusub == 3); + OsdWrite(15, PAGE_STD_BACK, menusub == 4); } void position_page_adjust(int menusub, int dir) @@ -210,7 +215,15 @@ void position_page_adjust(int menusub, int dir) else if (menusub == 2) { s_size = clamp_int(s_size + dir, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); - if (position_live()) crt_hsize_apply_live(s_size); + if (position_live()) crt_size_apply_live(s_size, s_vsize); + return; + } + else if (menusub == 3) + { + // Shrink only: blank lines lower the frame rate, they can't add + // active lines. + s_vsize = clamp_int(s_vsize + dir, CRT_V_SIZE_MIN, CRT_V_SIZE_MAX); + if (position_live()) crt_size_apply_live(s_size, s_vsize); return; } else return; @@ -219,7 +232,7 @@ void position_page_adjust(int menusub, int dir) bool position_page_is_exit(int menusub) { - return menusub == 3; + return menusub == 4; } void position_page_leave(void) @@ -237,6 +250,12 @@ void position_page_leave(void) if (crt_toml_set_hsize(s_size)) s_size0 = s_size; else printf("launcher_pages: h size not saved\n"); } + if (s_vsize != s_vsize0) + { + // Same contract as crt_h_size: Main-owned, no respawn needed. + if (crt_toml_set_vsize(s_vsize)) s_vsize0 = s_vsize; + else printf("launcher_pages: v size not saved\n"); + } if (s_h == s_h0 && s_v == s_v0) return; if (!crt_toml_set_offsets(s_h, s_v)) { From 869d572b40199e11b5fc67ec9dea30f77f672c8e Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Fri, 2 Oct 2026 08:52:58 +0200 Subject: [PATCH 6/8] Revert "zaparoo: add V size (vertical shrink) to the OSD Position page" This reverts commit fc4643c. The blank-line vertical shrink turned out to be all-or-nothing on real TVs (vertical countdown lock window), so the control is dropped; H size is enough. Word2 v byte is written as 0 again. Co-Authored-By: Claude Fable 5.1 --- support/zaparoo/alt_launcher.cpp | 6 ++--- support/zaparoo/crt_settings.cpp | 41 +++++++++--------------------- support/zaparoo/crt_settings.h | 14 +++------- support/zaparoo/launcher_pages.cpp | 27 +++----------------- 4 files changed, 22 insertions(+), 66 deletions(-) diff --git a/support/zaparoo/alt_launcher.cpp b/support/zaparoo/alt_launcher.cpp index c0a670461..874c0158a 100644 --- a/support/zaparoo/alt_launcher.cpp +++ b/support/zaparoo/alt_launcher.cpp @@ -502,9 +502,9 @@ static void finish_native_crt_path(void) blank_native_crt_fb(); - // The 3 MB blank wiped control word2 (analog H/V size); the frontend - // only ever republishes words 0/1, so restore the persisted sizes here. - crt_size_republish(); + // The 3 MB blank wiped control word2 (analog H size); the frontend only + // ever republishes words 0/1, so restore the persisted size here. + crt_hsize_republish(); s_native_fb_mode_timer = GetTimer(1000); if (!s_native_fb_mode_timer) s_native_fb_mode_timer = 1; diff --git a/support/zaparoo/crt_settings.cpp b/support/zaparoo/crt_settings.cpp index 393626388..8b31ac6f6 100644 --- a/support/zaparoo/crt_settings.cpp +++ b/support/zaparoo/crt_settings.cpp @@ -228,20 +228,6 @@ bool crt_toml_set_hsize(int s) return toml_set("crt_h_size", buf); } -void crt_toml_get_vsize(int *s) -{ - int sv = 0; - toml_get_int("crt_v_size", &sv); - *s = clamp_int(sv, CRT_V_SIZE_MIN, CRT_V_SIZE_MAX); -} - -bool crt_toml_set_vsize(int s) -{ - char buf[16]; - snprintf(buf, sizeof(buf), "%d", clamp_int(s, CRT_V_SIZE_MIN, CRT_V_SIZE_MAX)); - return toml_set("crt_v_size", buf); -} - void crt_toml_get_offsets(int *h, int *v) { int hv = 0, vv = 0; @@ -280,31 +266,29 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode) shmem_unmap(p, 0x1000); } -// word2: [31:16] magic 0x5A52, [15:8] v size as int8, [7:0] h size as int8. +// word2: [31:16] magic 0x5A52, [15:8] reserved 0, [7:0] h size as int8. // See the interim contract note in crt_settings.h. -static uint32_t pack_word2(int h, int v) +static uint32_t pack_word2(int s) { - uint32_t hb = (uint8_t)(int8_t)clamp_int(h, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); - uint32_t vb = (uint8_t)(int8_t)clamp_int(v, CRT_V_SIZE_MIN, CRT_V_SIZE_MAX); - return (s_word2_magic << 16) | (vb << 8) | hb; + uint32_t sb = (uint8_t)(int8_t)clamp_int(s, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); + return (s_word2_magic << 16) | sb; } -void crt_size_apply_live(int h_size, int v_size) +void crt_hsize_apply_live(int s) { void *p = shmem_map(s_native_addr, 0x1000); if (!p) return; volatile uint32_t *w = (volatile uint32_t *)p; - w[2] = pack_word2(h_size, v_size); + w[2] = pack_word2(s); __sync_synchronize(); shmem_unmap(p, 0x1000); } -void crt_size_republish(void) +void crt_hsize_republish(void) { - int h = 0, v = 0; - crt_toml_get_hsize(&h); - crt_toml_get_vsize(&v); - crt_size_apply_live(h, v); + int s = 0; + crt_toml_get_hsize(&s); + crt_hsize_apply_live(s); } static void mode_dims(uint8_t mode, int *w, int *h) @@ -365,10 +349,9 @@ bool crt_test_pattern_publish(uint8_t mode, int h, int v) // non-zero word0 publishes the frame. words[1] = pack_word1(h, v, mode); { - int hs = 0, vs = 0; + int hs = 0; crt_toml_get_hsize(&hs); - crt_toml_get_vsize(&vs); - words[2] = pack_word2(hs, vs); + words[2] = pack_word2(hs); } __sync_synchronize(); words[0] = (1u << 2) | 0u; diff --git a/support/zaparoo/crt_settings.h b/support/zaparoo/crt_settings.h index 61418fbf3..4ec96d0e4 100644 --- a/support/zaparoo/crt_settings.h +++ b/support/zaparoo/crt_settings.h @@ -29,11 +29,6 @@ #define CRT_H_SIZE_MIN -8 #define CRT_H_SIZE_MAX 2 -// Vertical size (shrink only): -N adds N blank lines per progressive frame, -// lowering the frame rate (262+N / 312+N lines). 480i forces 0 in RTL. -#define CRT_V_SIZE_MIN -32 -#define CRT_V_SIZE_MAX 0 - const char *crt_standard_name(uint8_t mode); uint8_t crt_standard_next(uint8_t mode); @@ -44,8 +39,6 @@ void crt_toml_get_offsets(int *h, int *v); bool crt_toml_set_offsets(int h, int v); void crt_toml_get_hsize(int *s); bool crt_toml_set_hsize(int s); -void crt_toml_get_vsize(int *s); -bool crt_toml_set_vsize(int s); // Live centering: rewrites DDR control word1. Only meaningful while the // menu core is scanning a published frame (frontend --crt or the test @@ -55,8 +48,7 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode); // Interim word2 contract (analog H size). The core's per-vblank control // poll reads two 64-bit beats at 0x3A000000: beat 1 is the unchanged v2 // word0/word1 (magics 0x5A50/0x5A51); beat 2's low word ("word2", bytes -// 0x08-0x0B) is [31:16] magic 0x5A52, [15:8] signed v_size (-32..0, -N -// adds N blank lines per progressive frame, 480i forces 0), [7:0] signed +// 0x08-0x0B) is [31:16] magic 0x5A52, [15:8] reserved 0, [7:0] signed // h_size (core-clamped to -8..+2; anything without the magic reads as 0). // Word2 is written ONLY by Main (this page's live apply, the test pattern, // and a republish after alt_launcher's pre-spawn 3 MB blank); the frontend @@ -64,8 +56,8 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode); // h_size applies only while word1's magic is valid. The deferred v3 plan // (plans/menu-crt-video-plan.md sec. 7) repurposes byte 0x08 and moves // 0x5A52 into word1; matched releases will replace this layout wholesale. -void crt_size_apply_live(int h_size, int v_size); -void crt_size_republish(void); +void crt_hsize_apply_live(int s); +void crt_hsize_republish(void); // Main-drawn alignment pattern published into DDR slot 0 so centering can // be adjusted without a running frontend. unpublish returns the core to diff --git a/support/zaparoo/launcher_pages.cpp b/support/zaparoo/launcher_pages.cpp index bb06ce31d..bb182da71 100644 --- a/support/zaparoo/launcher_pages.cpp +++ b/support/zaparoo/launcher_pages.cpp @@ -157,7 +157,6 @@ bool kiosk_page_confirm(int menusub) static int s_h, s_v, s_h0, s_v0; static int s_size, s_size0; -static int s_vsize, s_vsize0; static bool s_pattern; static bool position_live(void) @@ -174,11 +173,9 @@ void position_page_enter(void) { crt_toml_get_offsets(&s_h, &s_v); crt_toml_get_hsize(&s_size); - crt_toml_get_vsize(&s_vsize); s_h0 = s_h; s_v0 = s_v; s_size0 = s_size; - s_vsize0 = s_vsize; s_pattern = false; if (alt_launcher_native_crt_persisted() && !alt_launcher_active()) s_pattern = crt_test_pattern_publish(alt_launcher_native_crt_mode(), s_h, s_v); @@ -188,7 +185,7 @@ void position_page_render(int menusub, uint64_t *menumask) { OsdSetSize(16); OsdSetTitle("Position", 0); - *menumask = 0x1F; + *menumask = 0xF; char s[64]; int m = 0; @@ -199,13 +196,11 @@ void position_page_render(int menusub, uint64_t *menumask) OsdWrite(m++, s, menusub == 1); sprintf(s, " H size: %+3d", s_size); OsdWrite(m++, s, menusub == 2); - sprintf(s, " V size: %+3d", s_vsize); - OsdWrite(m++, s, menusub == 3); OsdWrite(m++, ""); OsdWrite(m++, position_live() ? " Left/Right: adjust picture" : " No CRT picture to adjust"); OsdWrite(m++, " (+2 size narrows position)"); while (m < OsdGetSize() - 1) OsdWrite(m++, ""); - OsdWrite(15, PAGE_STD_BACK, menusub == 4); + OsdWrite(15, PAGE_STD_BACK, menusub == 3); } void position_page_adjust(int menusub, int dir) @@ -215,15 +210,7 @@ void position_page_adjust(int menusub, int dir) else if (menusub == 2) { s_size = clamp_int(s_size + dir, CRT_H_SIZE_MIN, CRT_H_SIZE_MAX); - if (position_live()) crt_size_apply_live(s_size, s_vsize); - return; - } - else if (menusub == 3) - { - // Shrink only: blank lines lower the frame rate, they can't add - // active lines. - s_vsize = clamp_int(s_vsize + dir, CRT_V_SIZE_MIN, CRT_V_SIZE_MAX); - if (position_live()) crt_size_apply_live(s_size, s_vsize); + if (position_live()) crt_hsize_apply_live(s_size); return; } else return; @@ -232,7 +219,7 @@ void position_page_adjust(int menusub, int dir) bool position_page_is_exit(int menusub) { - return menusub == 4; + return menusub == 3; } void position_page_leave(void) @@ -250,12 +237,6 @@ void position_page_leave(void) if (crt_toml_set_hsize(s_size)) s_size0 = s_size; else printf("launcher_pages: h size not saved\n"); } - if (s_vsize != s_vsize0) - { - // Same contract as crt_h_size: Main-owned, no respawn needed. - if (crt_toml_set_vsize(s_vsize)) s_vsize0 = s_vsize; - else printf("launcher_pages: v size not saved\n"); - } if (s_h == s_h0 && s_v == s_v0) return; if (!crt_toml_set_offsets(s_h, s_v)) { From 0eb8e577eacc5b744db995f9bef9fd8759c62faf Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 3 Oct 2026 00:59:26 +0200 Subject: [PATCH 7/8] zaparoo: respawn frontend when the OSD H size row saves The frontend now owns crt_h_size the way it owns the offsets: it caches the value at start and writes word2 live. A size saved from Main's OSD page must therefore respawn a running frontend, or it would write the old size back on its next settings save. Contract comment updated to the shared-ownership wording. Co-Authored-By: Claude Fable 5.1 --- support/zaparoo/crt_settings.h | 8 +++++--- support/zaparoo/launcher_pages.cpp | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/support/zaparoo/crt_settings.h b/support/zaparoo/crt_settings.h index 4ec96d0e4..16ec024a2 100644 --- a/support/zaparoo/crt_settings.h +++ b/support/zaparoo/crt_settings.h @@ -50,9 +50,11 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode); // word0/word1 (magics 0x5A50/0x5A51); beat 2's low word ("word2", bytes // 0x08-0x0B) is [31:16] magic 0x5A52, [15:8] reserved 0, [7:0] signed // h_size (core-clamped to -8..+2; anything without the magic reads as 0). -// Word2 is written ONLY by Main (this page's live apply, the test pattern, -// and a republish after alt_launcher's pre-spawn 3 MB blank); the frontend -// never writes bytes >= 8, so the value survives its word0/word1 publishes. +// Word2 ownership matches word1's offsets: a running frontend owns it (it +// writes the saved h_size at arm and on live calibration nudges, v byte 0), +// and Main writes it from this page's live apply, the test pattern, and a +// republish after alt_launcher's pre-spawn 3 MB blank. Main's OSD save +// respawns the frontend so the two writers never run stale side by side. // h_size applies only while word1's magic is valid. The deferred v3 plan // (plans/menu-crt-video-plan.md sec. 7) repurposes byte 0x08 and moves // 0x5A52 into word1; matched releases will replace this layout wholesale. diff --git a/support/zaparoo/launcher_pages.cpp b/support/zaparoo/launcher_pages.cpp index bb182da71..165ff3f86 100644 --- a/support/zaparoo/launcher_pages.cpp +++ b/support/zaparoo/launcher_pages.cpp @@ -229,15 +229,25 @@ void position_page_leave(void) crt_test_pattern_unpublish(); s_pattern = crt_test_pattern_active(); } + bool size_changed = false; if (s_size != s_size0) { - // Size needs no respawn: the frontend never reads, caches, or writes - // crt_h_size (or DDR bytes >= 8), so the live word2 write plus this - // TOML save is already complete. - if (crt_toml_set_hsize(s_size)) s_size0 = s_size; + // The frontend owns crt_h_size the same way it owns the offsets + // (it caches the value at start and writes word2 live), so a + // save here must respawn it below or the frontend would write + // the old size back on its next settings save. + if (crt_toml_set_hsize(s_size)) + { + s_size0 = s_size; + size_changed = true; + } else printf("launcher_pages: h size not saved\n"); } - if (s_h == s_h0 && s_v == s_v0) return; + if (s_h == s_h0 && s_v == s_v0) + { + if (size_changed && alt_launcher_active()) alt_launcher_respawn(); + return; + } if (!crt_toml_set_offsets(s_h, s_v)) { printf("launcher_pages: offsets not saved, frontend left running\n"); From ac71c619ddba493b2dfb0267240d0df7776046c4 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 12 Oct 2026 21:34:02 +0200 Subject: [PATCH 8/8] zaparoo: drop H-size republish, the frontend heals word2 itself finish_native_crt_path's 3 MB blank wiped the control words, and word2 (analog H size) was the only one Main restored afterward because the frontend rewrote word0 every frame but word2 only on change. The frontend now re-asserts word1 and word2 every frame alongside word0, so word2 self-heals on its next frame like the offsets and the frame counter do. Remove crt_hsize_republish() (call, definition, declaration) and align the word2 ownership comment: the frontend owns the heal; Main only authors word2 from the Position page's live apply and the test pattern when no frontend is writing. Co-Authored-By: Claude Opus 5.5 (1M context) --- support/zaparoo/alt_launcher.cpp | 8 +++++--- support/zaparoo/crt_settings.cpp | 7 ------- support/zaparoo/crt_settings.h | 11 ++++++----- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/support/zaparoo/alt_launcher.cpp b/support/zaparoo/alt_launcher.cpp index e80e38259..d3bc247ac 100644 --- a/support/zaparoo/alt_launcher.cpp +++ b/support/zaparoo/alt_launcher.cpp @@ -506,9 +506,11 @@ static void finish_native_crt_path(void) blank_native_crt_fb(); - // The 3 MB blank wiped control word2 (analog H size); the frontend only - // ever republishes words 0/1, so restore the persisted size here. - crt_hsize_republish(); + // The blank wiped all three control words, but the frontend re-asserts + // word1 (offsets) and word2 (H size) on every frame, the same way word0's + // counter heals, so both come back on its next frame. Nothing to restore + // here. (Older frontends only healed word0/word1 and needed an H-size + // republish; that is no longer the contract.) s_native_fb_mode_timer = GetTimer(1000); if (!s_native_fb_mode_timer) s_native_fb_mode_timer = 1; diff --git a/support/zaparoo/crt_settings.cpp b/support/zaparoo/crt_settings.cpp index 8b31ac6f6..ec8babb0a 100644 --- a/support/zaparoo/crt_settings.cpp +++ b/support/zaparoo/crt_settings.cpp @@ -284,13 +284,6 @@ void crt_hsize_apply_live(int s) shmem_unmap(p, 0x1000); } -void crt_hsize_republish(void) -{ - int s = 0; - crt_toml_get_hsize(&s); - crt_hsize_apply_live(s); -} - static void mode_dims(uint8_t mode, int *w, int *h) { switch (mode) diff --git a/support/zaparoo/crt_settings.h b/support/zaparoo/crt_settings.h index 16ec024a2..6466efff6 100644 --- a/support/zaparoo/crt_settings.h +++ b/support/zaparoo/crt_settings.h @@ -50,16 +50,17 @@ void crt_offsets_apply_live(int h, int v, uint8_t mode); // word0/word1 (magics 0x5A50/0x5A51); beat 2's low word ("word2", bytes // 0x08-0x0B) is [31:16] magic 0x5A52, [15:8] reserved 0, [7:0] signed // h_size (core-clamped to -8..+2; anything without the magic reads as 0). -// Word2 ownership matches word1's offsets: a running frontend owns it (it -// writes the saved h_size at arm and on live calibration nudges, v byte 0), -// and Main writes it from this page's live apply, the test pattern, and a -// republish after alt_launcher's pre-spawn 3 MB blank. Main's OSD save +// Word2 ownership matches word1's offsets exactly: a running frontend owns it +// and re-asserts both words on every frame (saved h_size at arm, live +// calibration nudges, v byte 0), so word2 self-heals after alt_launcher's +// pre-spawn 3 MB blank the same way word0's counter does -- Main does not +// restore it. Main only authors word2 from this page's live apply and the +// test pattern (while the frontend is not the writer). Main's OSD save // respawns the frontend so the two writers never run stale side by side. // h_size applies only while word1's magic is valid. The deferred v3 plan // (plans/menu-crt-video-plan.md sec. 7) repurposes byte 0x08 and moves // 0x5A52 into word1; matched releases will replace this layout wholesale. void crt_hsize_apply_live(int s); -void crt_hsize_republish(void); // Main-drawn alignment pattern published into DDR slot 0 so centering can // be adjusted without a running frontend. unpublish returns the core to