Project reference snapshot. Recovery notes retain earlier subsystem milestones; use the current feature overview for playable scope.

BSP visibility and ordered wall commands

src/world_visibility.c recovers the original world-list construction stage. It produces actual front-to-back wall commands from the decoded map, camera, live sector heights and side records. It does not draw pixels or submit actors. ssa_world_visibility_build ends at the three original drawing boundaries: 017CC, D2D0, and 01828. Native wall/plane rendering is a separate module.

Original Native behavior
0800B574 Reset visibility bitsets, horizontal clipping, wall queue and plane pool
0800B6B0 Front-first BSP traversal, far-child bounding-box culling, sector reject
0800B220 / 0800B1B0 Signed node-vector projection and original BSP side test
0800B428 / 08000CEC Bounding-box angular frustum and solid-span rejection
0800B7B0 Mark visited sector and traverse leaf segments
0800B818 Segment backface, cached vertex angles, angular clipping and screen endpoints
0800BA04 Plane selection, portal/solid classification, perspective endpoints and wall enqueue
08000AC8 / 08000C10 Inclusive visible ranges; solid insertion/merging versus portal clipping
08000F44 / 08000F78 / 08000FB8 Reset, allocate and append the original wall queue

The isolated helpers use existing native ssa_bsp_side, ssa_sector_reject, ssa_sincos, and ssa_plane_find. The 32-bit vertex-angle calculation follows 093E8 without truncating the difference between two signed 16-bit coordinates. BA04 uses the original tangent and reciprocal tables, signed 64-bit dot product, fixed-point products and 32-bit wrapping texture coordinates. These table copies are data, not executed instructions.

Important original behavior

Ownership and bounds

Zero-initialize SsaWorldVisibility, then initialize it with borrowed decoded map, math tables, visibility tables and a stable-address plane pool. The workspace owns its vertex-angle cache, bitsets and traversal stack. Its wall, range and solid arrays remain stable until free. Map layout and count metadata must stay fixed; sector heights, line flags and side texture IDs are read live. Use one workspace per simultaneous view. Do not modify or release its resources during a build, and do not render through its plane pool concurrently.

Successful operations return 1, except clip returns the number of new ranges and box/segment return 0 when rejected. Invalid input returns -1. Later failures retain earlier effects, clear the update guard and do not silently complete. The original 100-wall limit is enforced: original F78 returns FFFF, which BA04 would use as an unchecked record index. Native code fails instead. Plane, range and solid-array exhaustion likewise return errors. Invalid node cycles, section bounds, leaf/segment/side/sector references and output pointers are guarded. Free before freeing the borrowed map or lookup tables.

Evidence

Run tests/test_world_visibility_rom.py with the test environment. It compiles the native implementation and runs complete original B6B0 list construction on all 16 maps, including original B574/B428/B7B0/B818/BA04, clipping, plane allocation, trig and ARM fixed-point helpers. The only computational hooks are GBA BIOS division/copy and DMA semantics. The subsequent drawing calls are explicitly intercepted and their ordered addresses are checked.

Current results:

Sanitizer binaries use -no-pie and ASAN_OPTIONS=detect_leaks=0. Exact file hashes and metrics are in native-world-visibility-validation.json. Unicorn executes original instructions only in these tests, never in the native port.

The requested decomp.wtf matcher also verified B220 byte-identically on the first manual compile: 42 bytes / 21 instructions. Source is recovered/visibility_side.c; scripts/match_visibility_side.py uses the real engine/agent matcher, and visibility-side-match-attempts.json records the result. The automatically released claim has recovery notes. The rest of this native implementation is behaviorally recovered, not claimed as an exact match.