diff --git a/support/zaparoo/alt_launcher.cpp b/support/zaparoo/alt_launcher.cpp index cc8989e55..d3bc247ac 100644 --- a/support/zaparoo/alt_launcher.cpp +++ b/support/zaparoo/alt_launcher.cpp @@ -506,6 +506,12 @@ static void finish_native_crt_path(void) blank_native_crt_fb(); + // 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 d185b4cfc..ec8babb0a 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,24 @@ 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); +} + static void mode_dims(uint8_t mode, int *w, int *h) { switch (mode) @@ -305,9 +338,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..6466efff6 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,31 @@ 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 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); + // 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. diff --git a/support/zaparoo/launcher_pages.cpp b/support/zaparoo/launcher_pages.cpp index 5bc921fb2..165ff3f86 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,7 +229,25 @@ void position_page_leave(void) crt_test_pattern_unpublish(); s_pattern = crt_test_pattern_active(); } - if (s_h == s_h0 && s_v == s_v0) return; + bool size_changed = false; + if (s_size != s_size0) + { + // 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) + { + 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"); 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