Save Point
README.md
snes.machine
The Super Nintendo (NTSC) machine: the 65C816 (snes.cpu65816) on a 24-bit bus with LoROM/HiROM carts (cart.luau: copier header, zip, header scoring, SRAM), WRAM 128 KB + the WRAM port, the multiplier/divider, auto and manual joypad reads, NMI and H/V timer IRQs, MEMSEL fast ROM, 8 DMA channels (all transfer modes) and HDMA (direct/indirect, repeat, line counters), the S-PPU line renderer (ppu.luau), the APU (apu.luau: SPC700 + S-DSP, caught up on every port access), a 262-line scheduler and save states. Called by the snes emulatorCore and the package tests.
local Snes = require("snes.machine")
local m = Snes.new(cartBytes)
m:runFrame(true) -- one frame; false skips drawing
m.fb -- 512x224 RGBA (256-pixel modes doubled, hi-res 1:1)
m:setPad(p1, p2) -- station words (bit0 R,1 L,2 U,3 D,4 A,5 B,6 C,7 D,8 Start,9 Select,10 L,11 R)
m:drainAudio() -- 44.1 kHz stereo f32
m:snapshot() / m:restore(s) ; m:saveSram() / m:loadSram(s) ; m:watchRam(addr)
PPU: modes 0-7, 8x8/16x16 tiles, 32/64 maps, per-BG scroll, mosaic, offset-per-tile (modes 2/4/6), mode 7 (matrix, flips, wrap/transparent/tile-0, EXTBG), direct colour, 128 OBJ with OBSEL sizes, 32-per-line and 34-sliver limits and flags, priority rotation, two windows with OR/AND/XOR/XNOR per layer and the colour window, main/sub screens with add/sub/half colour math and the fixed colour, brightness and forced blank. Hi-res modes 5/6 draw 512 pixels; pseudo-hires and interlace draw as 256/224.