homebrew.module
README.md
snes.homebrew — original CC0 Super Nintendo carts, built in-engine
Everything here is written for this world and released under CC0 1.0 (public domain): the 65816 runtime, the SPC700 sound driver, the BRR instruments (synthesised in Luau), the music and both games.
- Horizon Kart (
kart.luau, 1 player): a time-trial kart racer on a mode 7 track. HDMA sets the mode 7 matrix on every line from per-angle tables in ROM (perspective + rotation), switches mode 1 → mode 7 at the horizon so a mountain BG scrolls with the heading above a sky gradient (HDMA on colour 0). The kart and the HUD are sprites. Off-road slows you down; three laps with checkpoints; the best total time is kept in battery SRAM. B = accelerate, Y = brake, D-pad = steer, Start = start/pause. - Puck Rush (
puck.luau, 2 players): air hockey in mode 1. Pad 2 plays the right mallet (the CPU plays it until pad 2 presses a button). Shows windows (an HDMA-shaped spotlight on goals), colour math (additive glow on the puck trail, subtractive shadow), BG3 text, sprites, music and sound effects. First to 7.
Luau API:
local H = require("snes.homebrew")
H.build(true) -- assemble every game; write /zero/source/snes_roms/*.sfc
H.buildGame("kart") -- -> rom bytes
H.tile4(pixels) / H.tile2 / H.tile8 -- 64 palette indices -> planar tile bytes
H.rgb(r, g, b) -- 0..31 each -> BGR555
H.brr(samples, loop) -- int16 samples -> BRR blocks
H.track("I0 C4:2 E4:2 G4:4 R:4", ticksPerUnit) -- sequence bytes for the driver
H.driverImage(songs, sfx) -- the sound driver + instruments + songs as one ARAM image from $0200
H.RUNTIME -- 65816 runtime source (reset, NMI with OAM DMA, pads, APU boot, music/SFX commands, sprites, text)
Runtime conventions: the game runs in native mode with 8-bit A / 16-bit X,Y, DBR = $80, D = 0, code in fast ROM bank $80. WRAM $00 is the logic-step counter (advanced once per game step: the logic-rate probe), OAM buffer at $0200, BG text buffer at $7E2000. A game defines Main, VBlank (run inside NMI when a frame is ready) and Irq.