# Supply pad approach, docked state and departure

The mode-1 supply-entry gate installs callback 7D9A and starts the supplementary script as previously described in [supply re-entry](supplementary-scripts.md). Movement and the supply script are separate parts of the update: docking does not itself execute the script instructions.

## Approach and centring

7D9A stabilizes attitude through 8348, constructs its horizontal target from C81E and the patched immediate at 7DA9, then reduces horizontal error through the original vector helper 7CA4. The step is approximately `dt / 8`, with fractional carry accumulated in byte 7D70. Height approaches **328 internal units** through scalar helper 7CDB, using the same step budget.

Once position and height reach this target, heading approaches the direction toward the cell centre. The maximum heading change here is **7 × dt** angular units per update. At alignment, 7E3A exchanges 7DA9 with 8080h:

- On the first alignment, that replaces the entry offset with the cell-centre offset. The approach callback remains active and performs a second movement stage.
- At alignment after the offset was already 8080h, CALL 7EAD changes the callback to **7E49**, the instruction after the CALL.

7EAD is a small assembly control-flow trick: it pops its return address, stores it in object +66 and jumps there. Thus the docked callback is the shared tail of the approach function, not a separate conventional subroutine.

The native fixture starts at (1000h,2000h), height 400, and first targets (1080h,2010h), then (1080h,2080h), at height 328. Original vector/scalar convergence, angle lookup and callback transition execute for dt values 8, 16 and 32. All three reach the same final centre and docked callback. Their tick totals are artificial-fixture results, not predictions of docking duration in the game: the attitude helper is substituted and the starting heading deliberately demands large rotations.

## Docked callback and departure

7E49 converges object word +42 toward the target in 7E4A by at most dt per update. It stores half the resulting value in +3E. The supplementary script's `set_transition_parameter` opcode writes 7E4A; this therefore controls the docked engine/output target rather than an abstract presentation-only parameter.

Departure requires all three checks at 7E5C–7E6B:

1. The high byte of the halved output is nonzero (for the normal positive range, +42 is at least **512**).
2. Supplementary-context flag 7E61 is **zero**, so the supply sequence has returned.
3. The signed high byte of control word D5CA is at least **12** (word threshold 0C00h in the positive range).

D5CA is produced by input processing 7AD6: one keyboard/axis path stores it at 7B04, and the mouse path reads 11DC, negates it and updates it through the input helper. It is also consumed by pitch-related control code. The departure gate is therefore a positive pitch-control request, rather than a timer or automatic script-end departure. Exact physical mouse direction can depend on the input mapping; this fixture tests the processed field, not a mouse gesture.

When the gate passes, native code halves +42, writes **200** to +40, clears object flag +07 bit 10h, and installs **8108**, the ordinary mode-1/Skimma flight callback. It does not run that callback immediately; the current invocation returns and the next object update uses it. The +3E value was calculated before +42 was halved, a sequencing detail to preserve.

The same departure tail is reached during approach as well. The three departure conditions are checked there too; the geometry alignment alone is not the gate. The active supplementary flag normally suppresses departure while the sequence is running.

## Native verification

```
PYTHONPATH=/tmp/darker-python python3 tools/verify_supply_motion.py
```

[Results and transition snapshots](../analysis/missions/supply-motion-verification.json) contain three convergent approach runs and six departure cases. Tests distinguish output 511/512, control high byte 11/12, signed 127/128, and active/inactive supplementary state. Departure callback, output adjustment, +40 value and docking flag are checked.

The original 8348 attitude helper is intercepted; collision, live input production, supply effects and subsequent ordinary flight are not simulated. This is a bounded native movement/control check, not a complete playable docking sequence. The [combined supply cycle](combined-supply-cycle.md) now runs the script, message cursor and motion together with actual English text and explicit departure input.

## Map correspondence

[Native location verification](supply-pad-locations.md) now checks the actual Halon map against the entry gate: exactly its eight type-3 cells are accepted, with heading-adjusted subcell boundaries and stored targets verified.
