Save Point
README.md
snes.asm — 65C816 assembler
A two-pass 65C816 assembler in Luau, for Super Nintendo homebrew built inside the engine (also fine for any 65816 / 6502-family target).
local Asm = require("snes.asm")
local bin, symbols = Asm.assemble(source, { map = "lorom", size = 0x40000, fill = 0xFF, blobs = { tiles = "..." } })
- Addresses are 24-bit.
org $808000sets the full address; the file offset comes from the map:lorom= (bank & $7F) * $8000 + (addr & $7FFF), running past $FFFF continues at the next bank's $8000;hirom= addr & $3FFFFF;flat= addr - org of the firstorg. - Immediate widths:
.a8 .a16 .i8 .i16(also.smart-style tracking:rep #$20/$10/$30andsepwith a constant switch the widths for the lines after them), or a.b/.wsuffix on the mnemonic. - Operand sizes are decided in pass 1 so the layout never moves:
<exprdirect page,!expror|exprabsolute,>exprlong; a mnemonic suffix.b .w .ldoes the same. Without a prefix: a value known in pass 1 that is <= $FF is direct page, a plain number literal > $FFFF is long, everything else is absolute (labels are absolute: their bank comes from DBR/PBR).jsl/jmlare always long. - Every 65816 addressing mode:
#, dp, dp,x, dp,y, (dp), (dp,x), (dp),y, [dp], [dp],y, abs, abs,x, abs,y, long, long,x, sr,s, (sr,s),y, (abs) / (abs,x) for jmp/jsr, [abs] for jml, rel8, rel16 (brl,per),mvn src,dst/mvp src,dst(bank numbers or#bank, written in WLA/ca65 source order: source first). - Directives:
org,db/byte,dw/word,dl/long(24-bit),ds n[,fill],align n,assert expr,incbin name(bytes fromopts.blobs[name]),name equ expr/name = expr. - Expressions:
$FF,0xFF,%0101,'c',*(here),+ - * / % << >> & | ^ ~ ( ),lo() hi() bank()and^label(bank byte). - Labels
name:, local.xscoped to the last global label. Errors name the line.