On this website each file has .txt added to its name (spsin.ts.txt is spsin.ts) so it opens as plain text. # Apollo 11 SPSIN / SPCOS: modernisation and equivalence test Evidence behind the blog post "ProductSphere and the Apollo 11 Code: A Modernisation Case Study". Run on 22 October 2026. ## What was done 1. **Source.** `chrislgarry/Apollo-11` (commit 911e5c0). 175 `.agc` files: 85 in Comanche055, 90 in Luminary099. 2. **Assembly.** The full Luminary099 program assembled with Virtual AGC's `yaYUL` (virtualagc commit faca381) with 0 fatal errors. The repository's `MAIN.agc` names two files differently from the files on disk (`LAMBERT_AIMPOINT_GUIDANCE.agc`, `TRIM_GIMBAL_CNTROL_SYSTEM.agc`); copies under those names were added in a work directory only. 3. **Binary check.** The assembled rope was compared word for word with Virtual AGC's proofread `Luminary099.binsource` (and `AP11ROPE.binsource`, which is identical to it). 4 words differ, all in banks 21 and 33. Bank 02, which holds SPSIN and SPCOS (05032–05071) and their constants, is identical. The test runs the proofread rope. 4. **Original run.** `run_sp.c` drives Virtual AGC's CPU core (`yaAGC/agc_engine.c`) through SPSIN (05033) and SPCOS (05032) for all 32,768 15-bit inputs, interrupts off, watchdogs reset before each call. 5. **Rewrite.** `spsin.ts`: the same polynomial, flight constants and AGC rounding rules, in TypeScript. 6. **Test.** `equivalence.test.ts` compares each rewrite with every original result. ## Results | Rewrite | Calls | Mismatches | |---|---|---| | `Math.sin` / `Math.cos`, rounded | 65,536 | 43,250 (sin 21,666, cos 21,584), worst 4 LSB | | `spsin.ts` (from intent) | 65,536 | **0** | Planted bugs, each caught: doubling after truncation (32,488 calls), mirror point 32767 (20,850), rounding multiplies (22,976). Facts about the original: it never returns negative zero or overflows; its worst error against true sine is 4.17 LSB (1 LSB = 1/16,384). ## Other source checks used in the post - NOVAC is defined in both `Comanche055/EXECUTIVE.agc:37` and `Luminary099/EXECUTIVE.agc:37`. - KILLTASK is defined only in Luminary099 and called from 11 places (BURN_BABY_BURN 630, 797; P20-P25 952, 997, 1187, 1215, 2706, 3207, 4301, 4379, 4386). - SPSIN/SPCOS are called from 10 places: GPMATRIX (T4RUPT_PROGRAM), QUICTRIG (POWERED_FLIGHT_SUBROUTINES), GOTANGLS (P20-P25). - "TEMPORARY, I HOPE HOPE HOPE": `Luminary099/LUNAR_LANDING_GUIDANCE_EQUATIONS.agc:179`. ## Re-running ```sh git clone https://github.com/chrislgarry/Apollo-11 git clone https://github.com/virtualagc/virtualagc # yaYUL, yaAGC, Tools/oct2bin, Luminary099/*.binsource make -C virtualagc/yaYUL cc=cc cc -O2 '-DNVER="local"' -o oct2bin virtualagc/Tools/oct2bin.c virtualagc/Tools/utils.c ./oct2bin < virtualagc/Luminary099/Luminary099.binsource && mv oct2bin.bin lum099.bin cc -O2 -w -Ivirtualagc/yaAGC -o run_sp run_sp.c stubs.c virtualagc/yaAGC/agc_engine.c virtualagc/yaAGC/agc_engine_init.c virtualagc/yaAGC/NullAPI.c ./run_sp lum099.bin 5033 5032 > sp_original.txt node equivalence.test.ts sp_original.txt ```