At a glance

Question
Given the same hands on the pad, where do the port and retail spend a different number of frames, stand in a different place, or draw a different number of random values?
Engine side
One line a session tick from LEGAIA_DIAG_TICK_DIGEST (crates/engine-session/src/host_trace.rs), taken from a full-game ladder segment's pad pass
Retail side
scripts/pcsx-redux/autorun_gate_replay.lua under PCSX-Redux, started from a retail save state
Report
scripts/ci/gate-replay.py cuts the beats, runs the probe and prints the table. It gates nothing, like the walk film
Output
captures/gate-replay/. It is read from retail RAM and stays out of the repository
LEGAIA_FGL_ONLY=tetsu_spar LEGAIA_FGL_TRACE=1 LEGAIA_FGL_PIN_RETAIL=1 \
LEGAIA_FGL_RNG_SEED=0x1a1193df LEGAIA_DIAG_TICK_DIGEST=/path/digest.txt \
XMODIFIERS=@im=none cargo test -p legaia-engine-shell --profile release-test \
  --test integration full_game_ladder::part_b_ -- --nocapture --test-threads 1

scripts/ci/gate-replay.py s3_rimelm_freeroam --digest /path/digest.txt --until 3700

Beats and gates

A gate is a change of state both sides can see in their own memory: a script taking hold of the player, a battle opening, a dialogue page finishing its typing. A beat runs from one gate to the next. The engine's run is cut into beats first; retail then plays each beat's pad and the probe waits for the same gate before the next beat starts.

engine: the recorded pad, cut wherever a gate changes beat 1: walk beat 2: talk, page 1 beat 3: page 2 beat 4: battle prompt engaged=1 page=1 battle=1 retail: the same pad beat 1 beat 2 beat 3 beat 4 late: the walk's last direction stays held early: the beat ends, its last rows are dropped still waiting: a synthetic Cross, logged and counted as a finding each beat's pad is timed from its own opening gate, so a gap in one beat is not carried into the next
The engine's session above, retail's replay below. The marked slivers are what the table measures: retail's extra vsyncs, and the input the engine's log did not supply.
GateOn the engineOn retail
engaged=0/1A script context holds the playerBit 0x80000 of the player record's flags at +0x10
battle=0/1The world's mode is battleThe mode byte 0x8007B83C reads 0x15. The battle context pointer outlives the fight, so it says nothing
scene=NAMEThe active scene labelThe scene name at 0x8007050C
warpThe player moved over 300 units in one tickThe same, between two vsyncs
page=NThe open box's window reaches state 0x19The pager state _DAT_801F2734 reaches 0x19; pages are counted, not timed
pos=X/ZA turn in a walk: the d-pad changes to another held direction, settled for 8 ticks, at least 96 units from the last turnThe player comes within 24 units of the spot, passes it, or is engaged first
flow=XX:N, act=XX:NThe Nth entry into a battle command surface, or the action startThe same bytes, ctx[+0x06] and ctx[+0x07]

Replaying a beat

Each beat's pad rows are timed from its opening gate. A press is held at least two ticks (--min-press), because a one-vsync press can fall between two of retail's game passes and be lost, and a widened press keeps one released tick after it so a run of pulses stays separate edges. What happens at the closing gate depends on who got there first:

CaseWhat the probe doesWhere it shows
Retail reaches the gate firstEnds the beat and drops its remaining rowsdrop counts the Cross presses among them
Retail is lateWaits. A walking player keeps the beat's last direction held; an engaged player and a battle hold nothingwait
A walk closed by a door or a talk comes up shortSteers to where the engine stood when the gate fired, then keeps pressing the last directionsynthetic_seek and synthetic_push rows; synth
Retail is still waiting on an engaged beat or a battle prompt after --synth-after vsyncsGives a two-vsync Cross every 30 vsyncs until the gate comes. The usual cause is a page the replay's presses did not closesynthetic_cross rows; synth. A finding, not a repair
A battle press did not takeRepeats the beat's last logged press while the command flow sits on a byte that waits for input, at most --repulse-max timessynthetic_repulse rows; synth
The gate never comesStops after --max-wait vsyncsStatus timeout; everything after is unmeasured

Synthetic input is input the engine's log did not supply. Every one is a row in gate_events.csv with the press and what it found, so a run that needed help says where. Nothing is pressed while the action state machine owns the frame, or on a flow byte no surface reads the pad on.

Reading the table

ColumnMeaning
E, R, gapThe beat's length in engine ticks, in retail vsyncs, and R - E
wait, drop, synthVsyncs retail waited past the pad, Cross presses dropped, synthetic inputs
pos diffRetail minus engine player x,z at the closing gate; - in a battle
E rng, R rngDraws of the rand() generator over the beat. A +Nj suffix counts values the generator cannot reach from the last one, which is a reseed or a stomp

A beat with a small gap and a matching position says the two sides agree there, whatever came before it. That is what the resynchronisation buys. A second table, page waits, has a row per page gate: when each side's pager finished the page, their difference (which carries the drift of the beats before it) and the part this page added.

What the Rim Elm run shows

The first run replays the walk to Tetsu, the talk and the sparring fight from a Rim Elm free-roam state. With every surface gated, the fight replays to its end.

Surface enteredEngine ticks to the next surfaceRetail vsyncs to the next surface
0x1E round prompt, 0x28 ring17, 1820, 20
0x78, 0x5A, 0x6E18, 18, 1820, 20, 20
0x3C window, 0x64 target confirm18, 1820 to 22, 20
0x50 arts entry1820
0xFE armed, to the action start1820

See also

Tooling Full-game ladder Field walk film Retail comparison corpus PCSX-Redux automation The verification ladder Game Battle command flow Battle HUD