fix(loader): exit the harness on completion, and add LOADER_END=0 #9

Merged
arti merged 1 commits from opencode.siil.arti.ee/vt1200:fix/issue-3-loader-completion into master 2026-11-13 11:54:56 +02:00
Collaborator

What this fixes

dwt/loader/loader.lua had a completion check that only set done in the
frames >= ENDF branch; the status block was a comment-only no-op. Every run
therefore continued to the fixed LOADER_END (default 2700) and called
machine:exit(), even when the loader result had been final for hundreds of
frames. A slow client had no way to run longer, and a client still in startup
at LOADER_END was cut off with no diagnostic.

This replaces the empty block with a real completion rule and adds
LOADER_END=0 / LOADER_MAX:

  • done is set exactly once, on the frame completion is detected.
  • Completion = RESULT_STATUS has been written (!= 0xFFFFFFFF) and PC
    is outside [LOADER_BASE, LOADER_BASE+0x400) and the result block has
    been unchanged for 10 frames.
  • On completion: LOADER: complete at frame <n> status=<hex>.
  • A fixed LOADER_END still exits at that frame, so the snapshot filename
    and every existing fixed-frame capture are unchanged. Completion is
    informational there and suppresses the startup warning.
  • LOADER_END=0 exits at completion, or at LOADER_MAX (default 6000) with
    LOADER: warning: app still in startup at LOADER_MAX=<n>.
  • A fixed LOADER_END reached before completion prints
    LOADER: warning: app still in startup at LOADER_END=<n>.

LOADER: result, LOADER: snapshot, the loader_frame<frames>.png filename,
and the default ENDF=2700 are unchanged.

Verification

M=/home/arti/code/k-space/mame0289/vt1200, run from the repo root. Every run
used private -cfg_directory / -nvram_directory and a private HOME:

VT1200_SKIP_LEVEL1=1 $M vt1200 -rompath harness/mame/roms \
  -video none -sound none -nothrottle -skip_gameinfo \
  -nvram_directory <private>/nvram -cfg_directory <private>/cfg \
  -debug -debugger none -autoboot_script dwt/loader/loader.lua -autoboot_delay 0

1. Before the change (reproduction)

No env; default LOADER_COFF=dwt/loader/build/marker.coff, default
LOADER_END=2700:

$ grep -c "LOADER: complete" baseline.log
0
$ grep -n "LOADER: result\|LOADER: PC at inspection" baseline.log
225:LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510
229:LOADER: PC at inspection = 018C0260
$ tail -1 baseline.log
Average speed: 122.15% (58 seconds)

No completion line; the result was only inspected at the fixed end frame. The
marker app had already been running for many frames before that (the old log
shows its counter climbing from frame 2500).

2. Default LOADER_END=2700, after the change

Same command plus LOADER_SNAP=1 LOADER_OUT=/tmp/opencode/issue3/evidence
(the snapshot filename is how the exit frame is pinned):

LOADER: complete at frame 2510 status=00000000
LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510
LOADER: PC at inspection = 018C0260
LOADER: snapshot /tmp/opencode/issue3/evidence/loader_frame2700.png ok=true
Average speed: 117.37% (58 seconds)

Completion is detected at frame 2510, but the run still exits at 2700:
loader_frame2700.png, same fixed-frame contract as before.

3. LOADER_END=0

$ HOME=... VT1200_SKIP_LEVEL1=1 LOADER_END=0 LOADER_SNAP=1 \
  LOADER_OUT=/tmp/opencode/issue3/evidence $M vt1200 ...
LOADER: complete at frame 2510 status=00000000
LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510
LOADER: PC at inspection = 018C0260
LOADER: snapshot /tmp/opencode/issue3/evidence/loader_frame2510.png ok=true
Average speed: 121.25% (54 seconds)

Exit at the completion frame (2510), well before LOADER_MAX=6000.

4. Warning paths

Fixed end reached before completion:

$ LOADER_END=2505 LOADER_SNAP=1 ...
LOADER: warning: app still in startup at LOADER_END=2505
LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510
LOADER: snapshot /tmp/opencode/issue3/evidence/loader_frame2505.png ok=true

LOADER_END=0 with a short LOADER_MAX:

$ LOADER_END=0 LOADER_MAX=2505 LOADER_SNAP=1 ...
LOADER: warning: app still in startup at LOADER_MAX=2505
LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510
LOADER: snapshot /tmp/opencode/issue3/evidence/loader_frame2505.png ok=true

5. Deliberately wrong LOADER_COFF

$ LOADER_COFF=/tmp/opencode/issue3/does-not-exist.coff $M vt1200 ... -seconds_to_run 5
Ignoring MAME exception: Error running autoboot script dwt/loader/loader.lua: runtime error
dwt/loader/loader.lua:62: cannot open /tmp/opencode/issue3/does-not-exist.coff: /tmp/opencode/issue3/does-not-exist.coff: No such file or directory

Fatal error: Error running autoboot script dwt/loader/loader.lua: runtime error
dwt/loader/loader.lua:62: cannot open /tmp/opencode/issue3/does-not-exist.coff: /tmp/opencode/issue3/does-not-exist.coff: No such file or directory

The error path still reports the missing file and exits non-zero (exit=3).

Notes

  • The logs above were produced on commit 0e36c3e before rebasing onto
    upstream/master (0b3db19). The rebase did not change either file:
    git rev-parse 0e36c3e:dwt/loader/loader.lua and
    git rev-parse HEAD:dwt/loader/loader.lua are both
    57e8173927cbc08230d2df9a4165475a5a52bcf3, and the README blob is
    ba2b32ae82653f74ca7b8d6b217d85799fe834cb in both.
  • ROM untouched: md5sum vt1200_v22.bin =
    b46a3e442ccb86134d2356bd70d22fd2.
  • The termtris tests carry their own Lua copies and were not modified; their
    fixed LOADER_END behaviour is unchanged.
  • Not verified here: a client whose startup exceeds LOADER_MAX, and the
    actual slow-client retry timing in termtris. The rule was exercised with the
    marker app (completes at frame 2510) and the two warning paths above.

Closes #3

## What this fixes `dwt/loader/loader.lua` had a completion check that only set `done` in the `frames >= ENDF` branch; the status block was a comment-only no-op. Every run therefore continued to the fixed `LOADER_END` (default 2700) and called `machine:exit()`, even when the loader result had been final for hundreds of frames. A slow client had no way to run longer, and a client still in startup at `LOADER_END` was cut off with no diagnostic. This replaces the empty block with a real completion rule and adds `LOADER_END=0` / `LOADER_MAX`: * `done` is set exactly once, on the frame completion is detected. * Completion = `RESULT_STATUS` has been written (`!= 0xFFFFFFFF`) **and** `PC` is outside `[LOADER_BASE, LOADER_BASE+0x400)` **and** the result block has been unchanged for 10 frames. * On completion: `LOADER: complete at frame <n> status=<hex>`. * A **fixed** `LOADER_END` still exits at that frame, so the snapshot filename and every existing fixed-frame capture are unchanged. Completion is informational there and suppresses the startup warning. * `LOADER_END=0` exits at completion, or at `LOADER_MAX` (default 6000) with `LOADER: warning: app still in startup at LOADER_MAX=<n>`. * A fixed `LOADER_END` reached before completion prints `LOADER: warning: app still in startup at LOADER_END=<n>`. `LOADER: result`, `LOADER: snapshot`, the `loader_frame<frames>.png` filename, and the default `ENDF=2700` are unchanged. ## Verification `M=/home/arti/code/k-space/mame0289/vt1200`, run from the repo root. Every run used private `-cfg_directory` / `-nvram_directory` and a private `HOME`: ``` VT1200_SKIP_LEVEL1=1 $M vt1200 -rompath harness/mame/roms \ -video none -sound none -nothrottle -skip_gameinfo \ -nvram_directory <private>/nvram -cfg_directory <private>/cfg \ -debug -debugger none -autoboot_script dwt/loader/loader.lua -autoboot_delay 0 ``` ### 1. Before the change (reproduction) No env; default `LOADER_COFF=dwt/loader/build/marker.coff`, default `LOADER_END=2700`: ``` $ grep -c "LOADER: complete" baseline.log 0 $ grep -n "LOADER: result\|LOADER: PC at inspection" baseline.log 225:LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510 229:LOADER: PC at inspection = 018C0260 $ tail -1 baseline.log Average speed: 122.15% (58 seconds) ``` No completion line; the result was only inspected at the fixed end frame. The marker app had already been running for many frames before that (the old log shows its counter climbing from frame 2500). ### 2. Default `LOADER_END=2700`, after the change Same command plus `LOADER_SNAP=1 LOADER_OUT=/tmp/opencode/issue3/evidence` (the snapshot filename is how the exit frame is pinned): ``` LOADER: complete at frame 2510 status=00000000 LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510 LOADER: PC at inspection = 018C0260 LOADER: snapshot /tmp/opencode/issue3/evidence/loader_frame2700.png ok=true Average speed: 117.37% (58 seconds) ``` Completion is detected at frame 2510, but the run still exits at **2700**: `loader_frame2700.png`, same fixed-frame contract as before. ### 3. `LOADER_END=0` ``` $ HOME=... VT1200_SKIP_LEVEL1=1 LOADER_END=0 LOADER_SNAP=1 \ LOADER_OUT=/tmp/opencode/issue3/evidence $M vt1200 ... LOADER: complete at frame 2510 status=00000000 LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510 LOADER: PC at inspection = 018C0260 LOADER: snapshot /tmp/opencode/issue3/evidence/loader_frame2510.png ok=true Average speed: 121.25% (54 seconds) ``` Exit at the completion frame (2510), well before `LOADER_MAX=6000`. ### 4. Warning paths Fixed end reached before completion: ``` $ LOADER_END=2505 LOADER_SNAP=1 ... LOADER: warning: app still in startup at LOADER_END=2505 LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510 LOADER: snapshot /tmp/opencode/issue3/evidence/loader_frame2505.png ok=true ``` `LOADER_END=0` with a short `LOADER_MAX`: ``` $ LOADER_END=0 LOADER_MAX=2505 LOADER_SNAP=1 ... LOADER: warning: app still in startup at LOADER_MAX=2505 LOADER: result status=0 (OK) entry=018C0000 text=018C0000/656 bits data=018D0000/64 bits bss=018D8000/64 bits relocs=0 pcb=003FEE50 nscns=3 len=510 LOADER: snapshot /tmp/opencode/issue3/evidence/loader_frame2505.png ok=true ``` ### 5. Deliberately wrong `LOADER_COFF` ``` $ LOADER_COFF=/tmp/opencode/issue3/does-not-exist.coff $M vt1200 ... -seconds_to_run 5 Ignoring MAME exception: Error running autoboot script dwt/loader/loader.lua: runtime error dwt/loader/loader.lua:62: cannot open /tmp/opencode/issue3/does-not-exist.coff: /tmp/opencode/issue3/does-not-exist.coff: No such file or directory Fatal error: Error running autoboot script dwt/loader/loader.lua: runtime error dwt/loader/loader.lua:62: cannot open /tmp/opencode/issue3/does-not-exist.coff: /tmp/opencode/issue3/does-not-exist.coff: No such file or directory ``` The error path still reports the missing file and exits non-zero (`exit=3`). ## Notes * The logs above were produced on commit `0e36c3e` before rebasing onto `upstream/master` (`0b3db19`). The rebase did not change either file: `git rev-parse 0e36c3e:dwt/loader/loader.lua` and `git rev-parse HEAD:dwt/loader/loader.lua` are both `57e8173927cbc08230d2df9a4165475a5a52bcf3`, and the README blob is `ba2b32ae82653f74ca7b8d6b217d85799fe834cb` in both. * ROM untouched: `md5sum vt1200_v22.bin` = `b46a3e442ccb86134d2356bd70d22fd2`. * The termtris tests carry their own Lua copies and were not modified; their fixed `LOADER_END` behaviour is unchanged. * Not verified here: a client whose startup exceeds `LOADER_MAX`, and the actual slow-client retry timing in termtris. The rule was exercised with the marker app (completes at frame 2510) and the two warning paths above. Closes #3
opencode.siil.arti.ee added 1 commit 2026-11-13 11:23:10 +02:00
arti merged commit 4554c9274e into master 2026-11-13 11:54:56 +02:00
arti deleted branch fix/issue-3-loader-completion 2026-11-13 11:54:56 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: arti/vt1200#9