SMW Sprite Engine — Redundancy & Inefficiency Notes

Analysis of sprite handling across bank_00/01/02/03/05/07.asm of the community disassembly. Addresses are SNES ($BB:AAAA collapsed to $BBAAAA), matching the labels in the bank files.

0. A duplicated region in the community disassembly

Some copies of bank_01.asm contain the same ROM region twice (the sprite init routines from InitGreyLavaPlat/$018311 through the SpriteMainPtr table). Same code and addresses, two different comment revisions — an artifact of the original SMWDisC etherpad dump. The first copy is the stale one (older comments, pre-rename labels like DiagBoospeeds/DATA_0183B3); the second copy is current. Labels and addresses in these notes follow the current copy.

1. Architecture (for orientation)

2. Cross-bank utility clones (the JSR-locality tax)

JSR can't cross banks, so leaf utilities were copy-pasted per bank instead of made JSL-able. Any bug fix or hack hook must be applied 3–4×:

RoutineCopiesAddresses
GetDrawInfo (~130 bytes, the OAM pre-draw setup)3GetDrawInfoBnk1 $01A365, GetDrawInfo2 $02D378, GetDrawInfoBnk3 $03B760 — 80+ call sites total
SubOffscreen (4 entry points each, ~200 bytes)3$01AC21.. , $02D016.. , $03B84F.. — ~95% identical; Bnk1 alone has the MagiKoopa-respawn special case
SubHorizPos (Mario-vs-sprite X compare)3$01AD30, SubHorzPosBnk2 $02848D, SubHorzPosBnk3 $03B817
vertical twin of SubHorizPos2+CODE_01AD42, SubVertPosBnk3 $03B829 — same 9 instructions with Y-axis addresses
IsSprOffScreen (2 instructions!)4$0180CB, $02849F and $02D0C9 (twice in bank 02), $03B8FB

The per-bank DATA_ tables these reference (SpriteOffScreen3/4 vs DATA_02D007/0F vs DATA_03B83F..) are byte-identical too.

Counter-example done right: FindFreeSprSlot/FindFreeSlotLowPri $02A9E4/$02A9DE share one body (FindFreeSlotRt $02A9EF) with two prologues, and are JSL'd cross-bank.

3. Per-sprite GFX routine clone family

4. Dispatch inefficiency

5. Spawn-path waste

6. Per-frame structural costs

7. Data-layout costs

8. Optimization patch candidates (ranked)

  1. Bnk3CallSprMain → ExecutePtr jump table — removes ~30 compares/sprite/frame; mechanical.
  2. Hoist the OAM-index computation to level load — $15EA per-slot values are level-constant.
  3. Drop the 5 dead tweaker STZs in ZeroSpriteTables — free 15 bytes + ~30 cycles/spawn.
  4. Merge the utility clones behind JSL (GetDrawInfo, SubOffscreen, SubHorizPos, IsSprOffScreen) — ~600+ bytes freed, one patch point instead of 3–4. Costs JSL/RTL overhead (+~2 cycles/call); hacks (SA-1 etc.) do exactly this.
  5. Table-driven generic GFX writer replacing the ~35 clones — biggest byte win (est. 1.5–2 KB), but touches every sprite's draw path; highest risk.
  6. Halve CircleCoords with a mirror lookup; dedupe the mask tables.

9. What this means for editors and tools