Wireframe 3-D Solid
Physics & Simulation
A spinning polyhedron drawn live on the Super Nintendo — tetrahedron, cube, octahedron,
icosahedron. Each frame builds a 3×3 rotation matrix (three Q8.8 matrix multiplies),
projects every vertex through a perspective divide, and connects the edges with integer
Bresenham lines into a 2bpp bitmap canvas. Written in C and compiled to a real
.sfc ROM with the
llvm-mos-based 65816 toolchain
(+mos-a16 16-bit accumulator). Demo #16 of the compiler stress-test battery.
↑/↓ spin Y · ←/→ spin X · Q/W dolly · X/A solid · S palette · Shift trail · Enter reset
Click the screen, then play. Switch solids with X/A; toggle trail mode with Shift.
Controls
| Keys | Action |
|---|---|
| ↑ / ↓ | Speed Y-axis + / − |
| ← / → | Speed X-axis + / − |
| Q / W | Dolly distance − / + |
| A / X | Previous / next solid (tetra → cube → octa → icosa) |
| S | Cycle palette |
| Shift | Toggle trail / crisp |
| Enter | Reset |
The four solids
Cycle them with A (previous) / X (next). Each has its own vertex count and edge table — the icosahedron has 30 edges to draw per frame.
| Solid | What it is |
|---|---|
| TETRA | 4 faces, 4 vertices, 6 edges — the simplest solid |
| CUBE | 6 faces, 8 vertices, 12 edges — a plain box in 3-D |
| OCTA | 8 faces, 6 vertices, 12 edges — two square pyramids joined |
| ICOSA | 20 faces, 12 vertices, 30 edges — the most complex |
Rendering modes
Shift toggles between two modes shown in the top-right HUD:
- TRAIL — phosphor accumulate: lines are never erased, leaving a luminous ghost. Try spinning fast then slow — the solid unpeels itself from its own trail.
- CRISP — canvas clears each frame before redrawing: a clean, sharp rotation.
Tips
- Set spin to zero with ↑/↓ and ←/→ to freeze the solid — then step it slowly.
- Dolly in (Q) until the camera is almost inside the solid; the perspective distortion becomes extreme on the icosahedron.
- It's a compiler stress-test. The mat3_mul loop calls
__mulsi3(32-bit software multiply) nine times per matrix element; the perspective divide calls__divsi3. Under+mos-a16the 65816 runs in native 16-bit-accumulator mode, so the mode-switchrep/seppairs bracket every multiply.
Written in C with an LLVM/65816 SNES toolchain. The 3-D math — matrix
multiply + perspective divide — runs identically on the host oracle and all three compiler
modes, verified against MAME and bsnes-jg. Hit Verify fidelity to reproduce the
build gate's WRAM assert (3-D math hash 0xEF8E) live in this tab. No far
pointers, so the same program is checked five ways: host == default == +mos-a16
== +mos-xy16.