Skip to content

feat(functional): port C for hand-written assembly, checked against retail in an EE emulator - #104

Merged
Lynder063 merged 7 commits into
mainfrom
claude/wonderful-keller-iuaf17
Oct 19, 2026
Merged

Lynder063 merged 7 commits into
mainfrom
claude/wonderful-keller-iuaf17

Conversation

@Lynder063

@Lynder063 Lynder063 commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Hand-written assembly counts as finished for matching, but the native port still needs C for it. This adds behaviour-equivalent C for 45 hand-written functions that had none. The files are in nonmatching/functional/, each with a row in nonmatching/functional.tsv.

Checked against retail (35):

  • Small helpers: bit length (func_001F9968); quadword copy and clear, and word fill (func_001F9A98, func_001F99D8, func_001F99B0); countdown timer tick (func_001F9938); set vector length in 3D and 2D (func_001F9DC0, func_001F9E10).
  • Hardware and tables: DMA reset (func_0020C268); record-table fill (func_00212508); VIF1 interrupt handler (func_00235118).
  • Matrix math: rotation about Z, X and Y (func_001253F8, func_001254A0, func_00125548).
  • Draw and quad: func_001FA8F0, func_001F7C60, func_001F91B8, func_001F8B6C.
  • Sky: triangle packet, vertex transform, tile visibility, sprites and tiles (func_0022D3F8, func_0022D2AC, func_0022D7E0, func_0022CEB8, func_0022D520).
  • Tfrag and tie: texture usage, tfrag and tie lighting (func_00235EF0, func_002362B0, func_00238688).
  • Moby: joint pose (func_00211808).
  • Shadow volumes: func_00228D20, func_00229098, func_002291E8, func_00229838, func_002298B0.
  • Level code: func_L00_001F34F0, func_L00_002963D8, func_L02_00250A58.

Written from the asm (10): these read COP0 or drive VU0 microcode, so they were not run.

  • DI and EI (func_0011D960, func_0011D9A8), sharing a host-side enable flag.
  • Four interrupt-guarded syscall wrappers (func_00119328, func_00119390, func_001193F8, func_00119460).
  • The fatal trap (func_001F9978) and a busy-wait delay (func_001F9988).
  • The moby skin/light job runner (func_00212578).

How the checks were done

Retail and the C ran side by side in a MIPS64 emulator (unicorn). A small instruction model emulates the R5900-only instructions: MMI, lq/sq, VU0 macro mode, the EE COP1 extras and ei/di. The C was compiled with the real SN compiler and loaded next to retail, with its references resolved to retail addresses; level functions run with their overlay dump loaded.

Each test case starts both runs from the same RAM. It then compares the return values, all of RAM outside the stack, the scratchpad, and the DMA/GS/VIF register pages. Each file's header gives its case count, and any float tolerance used for VU0-versus-FPU rounding (at most 1e-5). All files also build with host gcc, using the same short type names the existing port files use. The harness is not part of this PR.

Not included

  • Kernel syscall stubs: the 85 stubs of the form li $3, n; syscall get no C, because the port supplies the kernel.
  • Custom-ABI helpers: five helpers take inputs in non-ABI registers and are only called from other hand-written code. They belong inside their callers' C.
  • Unfinished: the following were not done when work stopped: func_0020FC38, func_00228A58, func_L00_001F2BE8, func_L00_00252D20, func_L00_002539C8, and the remaining large VU0/MMI routines.

🤖 Generated with Claude Code

https://claude.ai/code/session_017Lr3jLwpQ8QBWgz9eA4WNx

claude and others added 7 commits October 19, 2026 15:38
func_001F9968 (bit length via plzcw), func_001F9A98 (quadword copy),
func_001F9938 (countdown timer tick), func_001F9DC0 and func_001F9E10
(set a 3D/2D vector's length, VU0 rsqrt). Each was checked against the
retail code run in an EE emulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Lynder063 <krystofmalinda@protonmail.com>
Fill/clear loops (func_001F99B0, func_001F99D8), the DMA reset
(func_0020C268) and the record-table fill (func_00212508), checked
against retail in an EE emulator; DI/EI (func_0011D960, func_0011D9A8)
with a host-side enable flag, the four interrupt-guarded syscall
wrappers, the fatal trap and the busy-wait delay, written from the asm.
The two vector-length helpers now use __builtin_sqrtf so they build on
the host without math.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Lynder063 <krystofmalinda@protonmail.com>
Both checked against retail in an EE emulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Lynder063 <krystofmalinda@protonmail.com>
Written from the asm: walks the job chain through the port's
func_0020EF30 and func_001EE9F8, then waits for fromSPR DMA to idle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Lynder063 <krystofmalinda@protonmail.com>
Matrix rotation about Z, X and Y (func_001253F8, func_001254A0,
func_00125548), the screen test func_001FA8F0, the sky vertex transform
and tile visibility (func_0022D2AC, func_0022D7E0) and the tfrag texture
usage pass (func_00235EF0). Each agrees with retail on every test case
in the EE emulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Lynder063 <krystofmalinda@protonmail.com>
…transform update

Both agree with retail on every test case in the EE emulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Lynder063 <krystofmalinda@protonmail.com>
Draw/quad (func_001F7C60, func_001F91B8), moby joint pose
(func_00211808), shadow volumes (func_00228D20, func_00229098,
func_002291E8, func_00229838, func_002298B0), sky sprites and tiles
(func_0022CEB8, func_0022D520), tfrag and tie lighting (func_002362B0,
func_00238688) and three level routines (func_L00_001F34F0,
func_L00_002963D8, func_L02_00250A58). Every one agrees with retail on
all its test cases in the EE emulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Lynder063 <krystofmalinda@protonmail.com>
@Lynder063
Lynder063 marked this pull request as ready for review October 19, 2026 16:04
@Lynder063
Lynder063 merged commit d1cdc15 into main Oct 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants