From 67e09930e2e5568eba9c61d25e46994dfffb960c Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Fri, 9 Oct 2026 12:19:26 +0800 Subject: [PATCH] fix(zaparoo): keep menu snow visible without a frontend The Zaparoo menu core holds idle video black so a frontend start has no snow flash, and on its own shows snow only behind the OSD. Kiosk mode never opens the OSD, so with the frontend off the screen stayed black. Set menu status[10] whenever no frontend owns or is about to take the screen, which the menu core reads as permission to show snow. --- ZAPAROO_FORK.md | 3 ++- support/zaparoo/alt_launcher.cpp | 5 +++++ support/zaparoo/alt_launcher.h | 3 +++ support/zaparoo/menu_bg.cpp | 30 ++++++++++++++++++++++++++++++ support/zaparoo/menu_bg.h | 15 +++++++++++++++ support/zaparoo/save.cpp | 2 ++ user_io.cpp | 2 ++ 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 support/zaparoo/menu_bg.cpp create mode 100644 support/zaparoo/menu_bg.h diff --git a/ZAPAROO_FORK.md b/ZAPAROO_FORK.md index c1864760c..540d9a297 100644 --- a/ZAPAROO_FORK.md +++ b/ZAPAROO_FORK.md @@ -49,7 +49,7 @@ non-blocking spawn) are intentionally omitted. | 19 | **CI / build infrastructure** | Docker container build; binary named `MiSTer_Zaparoo`; "Z"-suffixed version; release / unstable CI; sync-upstream workflow; deploy script | `docker-build.sh`, `stable-build.sh`, `unstable-build.sh`, `deploy-zaparoo.sh`, `.github/build_*.sh`, `.github/workflows/*.yml` | | 20 | **Direct active-game tracking** | Main writes the selected game's absolute path directly to `/tmp/ACTIVEGAME`, the MiSTer convention consumed by Zaparoo Core and other integrations. MRA/MGL startup writes it and bare-core startup clears it from `user_io_init()`, except a start from `/media/fat/.LASTLAUNCH.mgl`, the temp MGL Zaparoo Core and mrext generate for `load_core` after writing the game path themselves, which leaves the file untouched; in-core file launches update it through the existing `recent_update()` call sites even when recents are disabled. This removes the need to force `RECENTS` or `LOG_FILE_ENTRY`; all upstream behavior behind those user-controlled options, including `/tmp/STARTPATH`, remains unchanged | `support/zaparoo/active_game.cpp/.h`; hooks in `user_io.cpp`, `recent.cpp` | | 25 | **Fork settings store** | `config/zaparoo_settings.bin`, 16-byte blob read into a zeroed buffer so an absent or short file means today's behavior. Byte 0 = frontend **disabled**, byte 1 = kiosk **enabled**, byte 2 = save on core exit, byte 3 = physical-disc autorun, rest reserved and preserved by the read-modify-write setters. Cached (the predicates run per scheduler tick, per gamepad event and inside the OSD render loop) and keyed on the storage root. Deliberately not `MiSTer.ini`: an unknown key breaks non-fork Mains, upstream appends to `ini_vars[]` most releases, and the stable build excludes `MiSTer.ini` | `support/zaparoo/settings.cpp/.h` | -| 26 | **Kiosk mode** | Total OSD lockout for card-only setups. Gates: `menu.cpp` key decode (covers F1/F7/F9/F10/F11/F12/ESC/Backspace, the front-panel tap and the keyrah Fn combo), the front-panel button block (its 3s hold sets `menustate` directly), the menu-core auto-open, and `SelectINI()` at boot. **The MGL clause in the auto-open condition is deliberately not gated**: it is how a card launches core + ROM, and gating it would load the core but never mount the game. Deliberately does **not** touch the menu background: whatever the user chose via `status[3:1]` (default 0 = the core's own snow, or a wallpaper / test pattern) is what shows. The idle screensaver keeps working to whatever `OSD_TIMEOUT` / `VIDEO_OFF` say: its countdown only runs while `menustate` is the file browser, which kiosk never reaches, so kiosk substitutes `MENU_NONE2` as the idle state, and skips the `OsdMenuCtl(1)` on wake because that would turn the overlay on over stale OSD buffer contents. Recovery is deleting the settings file | `support/zaparoo/kiosk.cpp/.h`, `menu.cpp:626,1341,1640`, `user_io.cpp:1472` | +| 26 | **Kiosk mode** | Total OSD lockout for card-only setups. Gates: `menu.cpp` key decode (covers F1/F7/F9/F10/F11/F12/ESC/Backspace, the front-panel tap and the keyrah Fn combo), the front-panel button block (its 3s hold sets `menustate` directly), the menu-core auto-open, and `SelectINI()` at boot. **The MGL clause in the auto-open condition is deliberately not gated**: it is how a card launches core + ROM, and gating it would load the core but never mount the game. Deliberately does **not** touch the menu background: whatever the user chose via `status[3:1]` (default 0 = the core's own snow, or a wallpaper / test pattern) is what shows. The snow only shows with the OSD closed because Main sets the menu status bit in row 46. The idle screensaver keeps working to whatever `OSD_TIMEOUT` / `VIDEO_OFF` say: its countdown only runs while `menustate` is the file browser, which kiosk never reaches, so kiosk substitutes `MENU_NONE2` as the idle state, and skips the `OsdMenuCtl(1)` on wake because that would turn the overlay on over stale OSD buffer contents. Recovery is deleting the settings file | `support/zaparoo/kiosk.cpp/.h`, `menu.cpp:626,1341,1640`, `user_io.cpp:1472` | | 27 | **`zaparoo_` command surface** | `zaparoo_command()` dispatches every `zaparoo_`-prefixed `/dev/MiSTer_cmd` line: `zaparoo_console ...` delegates to `alt_launcher_command()`, plus `zaparoo_kiosk on\|off\|toggle` and `zaparoo_frontend on\|off\|toggle` (both persisted), `zaparoo_osd open\|close\|toggle`, `zaparoo_save`, `zaparoo_mount [path]` and `zaparoo_cheat ...` (row 33). The upstream hook stays one line: the existing `zaparoo_console` prefix test, trailing space included, was widened to `zaparoo_`. `zaparoo_osd` is the everyday admin route under kiosk: a **session-only** bypass that lifts the gates without changing the setting, raising the same `menu_key_set(KEY_F12 \| UPSTROKE)` user_io raises for a real F12 so it works on a game core too. It is deliberately not persisted and dies on the next core load, since that re-execs Main. Cards must be set up before kiosk is switched on | `support/zaparoo/command.cpp/.h`, `support/zaparoo/kiosk.cpp`, `input.cpp` (cmd FIFO dispatch) | | 29 | **How a core is made to save** | **Read this before touching save or the OSD enable path.** Main never initiates a save; the *core's own Verilog* dumps battery RAM over the SD interface, which `user_io_poll` then writes `O_SYNC`. Two triggers exist, and every core that has a save reads them as `bk_save = \| `. **(a) The explicit bit.** Cores expose a menu row labelled "Save Backup RAM", or "Save Memory Cards" on PSX and "Save Memory Card" on NeoGeo. `menu.cpp:2658-2660` fires it with nothing but `user_io_status_set(opt, 1, ex)` then `user_io_status_set(opt, 0, ex)`, so **no OSD is involved and the save can be completely invisible**. Confirmed present in NES, SNES, Game Boy, GBA, MegaDrive, Genesis, MegaCD, N64, PSX, NeoGeo, Saturn, SMS, TurboGrafx16 and WonderSwan. **(b) The `OSD_STATUS` edge**, which is why the F12 trick works. `OsdEnable()` sends one SPI byte the FPGA turns into `OSD_STATUS`; from `sys/osd.v`, `if(!io_din[0]) {osd_status,highres} <= 0; else {osd_status,info} <= {~io_din[2] & ~io_din[3], io_din[2]};` so it rises **only** with bit 0 set and bits 2 and 3 clear. Bit 2 is `OSD_INFO` and bit 3 is `OSD_MSG`, so **`Info()` (0x45) and `InfoMessage()` (0x49) drive it low** and cannot trigger a save. Status and overlay-enable are the same bit, so this path always shows the full panel. `user_io_osd_is_visible()` mirrors it faithfully at every call site except `OsdMenuCtl(1)` | `sys/osd.v` and each core's top-level `.sv`, not here; consumers in `support/zaparoo/save.cpp`, `support/zaparoo/confstr.cpp` | | 29a | **A core saves only when it has something to save** | Every core keeps a pending-change flag (`bk_pending` / `sav_pending` / `anyChangeBuf`), set when the game writes save RAM and cleared once the dump runs. **Which trigger the flag gates differs, and that difference explains every "it did not save" result.** NES, SNES, Game Boy, MegaDrive and PSX gate only path (b), so the explicit bit dumps unconditionally. **N64 and NeoGeo gate both**: `rtl/savemem.vhd:147` reads `elsif (saveLatched = '1') then if (anyChangeBuf = '1')`, and `neogeo.sv:610` reads `bk_save & bk_pending`. On those two a game sitting at its title screen writes nothing, from any trigger, including the core's own menu row. That is correct behaviour, not a fault. Arcade NVRAM is the same story through `UIO_CHK_UPLOAD`: eight cores all report `pending=0` in attract mode and write only after real play, verified by playing Berzerk to a game over and watching the flag flip. **Never diagnose a save as broken without first confirming the game actually changed its save RAM** | each core's top-level `.sv`; `support/zaparoo/save.cpp` | @@ -71,6 +71,7 @@ non-blocking spawn) are intentionally omitted. | 43 | **Core liveness watchdog** | While frontend is active, polls the existing Core PID file every 2 s. A retained PID that no longer exists or does not identify Core's cached service executable/script triggers a memory diagnostic and the idempotent service ensure through a detached helper. Core owns stale-PID cleanup under its start gate; PID-reuse recovery requires matching Core support. Missing PID files are ignored and attempts are throttled to 30 s; this is a liveness heuristic, not proof of OOM or another specific exit cause | `support/zaparoo/core_watchdog.cpp/.h`; called from `support/zaparoo/save.cpp`'s existing `zaparoo_poll()` fork hook | | 44 | **Frontend scanout and black handoff** | Exact-qualified HDMI scanout uses a v2 inherited socket slot lease; Main proxies complete UIO packets and remains the sole bus writer, so OSD/video queries stay live. Mismatched handshakes fall back to fb0. Startup stays black through video probing, with bounded fb0 fallback and no live-owner timeout. Failed child stops abort core loads, re-exec and script handoffs. Native CRT and Direct Video retain their existing paths | `support/zaparoo/scanout.cpp/.h`, `bootstrap.h`, `alt_launcher.cpp/.h`, `SCANOUT.md`; surgical hooks in `fpga_io.cpp`, `menu.cpp`, `user_io.cpp`, `video.cpp` | | 45 | **Frontend input/FIFO liveness** | Noisy controllers cannot drain forever while the launcher is active; proxy mode uses nonblocking input polls. Stock Menu rumble diagnostics exclude the live frontend. Command FIFO parsing preserves fragmented lines and dispatches coalesced lines independently, discarding overlong/NUL-containing lines rather than executing truncations | `support/zaparoo/command_stream.h`, `tests/integration_test.cpp`; surgical `input.cpp` hooks | +| 46 | **Menu snow without a frontend** | The Zaparoo menu core holds its idle video black so a frontend start has no snow flash, and on its own only shows snow behind the OSD. Kiosk mode, the idle screensaver's first stage and a quit frontend all have the OSD closed, so the background went black (zaparoo-frontend#503). Main now sets menu `status[10]` whenever no frontend owns or is about to take the screen: `zaparoo_menu_bg_init()` writes it right after the saved menu status is loaded (F1 saves the whole status word, so a stale bit must not survive into a frontend start), and `zaparoo_menu_bg_poll()` follows `alt_launcher_menu_snow_allowed()`, which is `!alt_launcher_owns_screen()` and not waiting to resume after a script. **Set = snow, clear = black**: the core resets with status 0 before Main has spoken, so clear has to be the black state. Mismatched pairs behave as before the bit existed (black except behind the OSD). Bit 9 is avoided because the retired v1 native CRT contract used it | `support/zaparoo/menu_bg.cpp/.h`, `alt_launcher.cpp` (`alt_launcher_menu_snow_allowed`), `user_io.cpp` (menu init), `zaparoo_poll()`; core side `rtl/zaparoo_snow_enable.sv` in `Menu_MiSTer` | | 28 | **Early service start** | A `__attribute__((constructor))` runs `/media/fat/Scripts/zaparoo.sh -service start` before `main()`, so ahead of the core-1 affinity pin (a child would inherit it) and ahead of `FindStorage()`'s 30s USB wait. Double fork + `setsid()` and **no** `PR_SET_PDEATHSIG`, the inverse of `exec_launcher_child`: the service must survive the `app_restart()` re-exec every core load performs. The detached ensure helper is also reused by the Core liveness watchdog, restoring the saved startup CPU-affinity mask and closing inherited Main descriptors before exec. No marker file, the script is an ensure | `support/zaparoo/service_boot.cpp/.h` (zero upstream hooks) | --- diff --git a/support/zaparoo/alt_launcher.cpp b/support/zaparoo/alt_launcher.cpp index 20252d4b9..5f77cc22f 100644 --- a/support/zaparoo/alt_launcher.cpp +++ b/support/zaparoo/alt_launcher.cpp @@ -863,6 +863,11 @@ bool alt_launcher_owns_screen(void) return s_pid != 0 || s_init_pending || s_respawn_timer != 0; } +bool alt_launcher_menu_snow_allowed(void) +{ + return !alt_launcher_owns_screen() && !s_resume_after_script; +} + bool alt_launcher_console_lease_active(void) { return s_console_lease; diff --git a/support/zaparoo/alt_launcher.h b/support/zaparoo/alt_launcher.h index 40588d255..3795d6b4b 100644 --- a/support/zaparoo/alt_launcher.h +++ b/support/zaparoo/alt_launcher.h @@ -27,6 +27,9 @@ bool alt_launcher_blank_framebuffer(void); // True from the moment a launcher start is queued (or a respawn is pending) // until the child exits: the OSD must not auto-open over that window. bool alt_launcher_owns_screen(void); +// The menu core may show its snow: no frontend owns the screen, and none is +// coming back once a running script ends. +bool alt_launcher_menu_snow_allowed(void); bool alt_launcher_console_lease_active(void); // The frontend should run and own the screen: installed, enabled, not escaped. bool alt_launcher_configured(void); diff --git a/support/zaparoo/menu_bg.cpp b/support/zaparoo/menu_bg.cpp new file mode 100644 index 000000000..bfbaed950 --- /dev/null +++ b/support/zaparoo/menu_bg.cpp @@ -0,0 +1,30 @@ +#include "menu_bg.h" + +#include "alt_launcher.h" + +#include "user_io.h" + +#define MENU_STATUS_SNOW "[10]" + +static int s_snow = -1; + +static void set_snow(bool on) +{ + if (s_snow == (on ? 1 : 0)) return; + s_snow = on ? 1 : 0; + user_io_status_set(MENU_STATUS_SNOW, s_snow); +} + +void zaparoo_menu_bg_init(void) +{ + // The launcher is queued right after this, so ownership is not visible + // yet: a configured frontend starts black. + s_snow = -1; + set_snow(!alt_launcher_configured()); +} + +void zaparoo_menu_bg_poll(void) +{ + if (!is_menu()) return; + set_snow(alt_launcher_menu_snow_allowed()); +} diff --git a/support/zaparoo/menu_bg.h b/support/zaparoo/menu_bg.h new file mode 100644 index 000000000..f0fd4b079 --- /dev/null +++ b/support/zaparoo/menu_bg.h @@ -0,0 +1,15 @@ +#pragma once + +// Tells the Zaparoo menu core when its idle video may show snow. The core +// holds black unless the OSD is up or menu status bit 10 is set, so a frontend +// start has no snow flash. Main sets the bit whenever no frontend owns or is +// about to take the screen, which keeps the background visible with the OSD +// closed (kiosk mode, the idle screensaver, after quitting the frontend). +// A menu core without the bit ignores it. + +// Called once the menu core's saved status has been loaded: the whole status +// word is saved by F1, so a stale bit must not survive into a frontend start. +void zaparoo_menu_bg_init(void); + +// Driven from zaparoo_poll(): follows frontend ownership. +void zaparoo_menu_bg_poll(void); diff --git a/support/zaparoo/save.cpp b/support/zaparoo/save.cpp index b9746d9df..c8ccb8b54 100644 --- a/support/zaparoo/save.cpp +++ b/support/zaparoo/save.cpp @@ -2,6 +2,7 @@ #include "confstr.h" #include "core_watchdog.h" #include "kiosk.h" +#include "menu_bg.h" #include "settings.h" #include @@ -352,6 +353,7 @@ void zaparoo_poll(void) { zaparoo_core_watchdog_poll(); zaparoo_kiosk_poll(); + zaparoo_menu_bg_poll(); switch (s_state) { diff --git a/user_io.cpp b/user_io.cpp index 2f0449a11..1487a81d3 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -44,6 +44,7 @@ #include "support.h" #include "support/zaparoo/active_game.h" #include "support/zaparoo/alt_launcher.h" +#include "support/zaparoo/menu_bg.h" #include "support/zaparoo/menu_rbf.h" static char core_path[1024] = {}; @@ -1632,6 +1633,7 @@ void user_io_init(const char *path, const char *xml) else if (is_menu()) { user_io_status_set("[4]", (cfg.menu_pal) ? 1 : 0); + zaparoo_menu_bg_init(); zaparoo_native_video_release(); if (alt_launcher_configured()) {