This tutorial covers SNES graphics fundamentals including video modes, backgrounds, and tilemaps.
The SNES has eight background modes (0-7); most games use Mode 1, text and simple UI use Mode 0, rotation uses Mode 7. What each mode gives each layer is tabled in The PPU: background modes.
Tiles are 8x8 pixel graphics stored in VRAM. For 4bpp (16 colour) tiles:
The background module does the same with DMA, and points the layer at the tiles in one call. bgInitTileSetData() loads tiles only (no palette), for a second tile set or a layer that shares a palette:
Like any DMA to VRAM, call it during force blank or VBlank. bgInit(bg) puts a layer's scroll back to (0, 0).
Tilemaps define which tiles appear where on screen. Each entry is 2 bytes — tile number, palette, priority and flips; the bit layout is in The PPU: tilemaps.
Colours are 15-bit BGR555, written low byte first; the format and the split of CGRAM between backgrounds and sprites are in The PPU: CGRAM and colours.
bgSetScroll() records a layer's position; the NMI handler writes it to the PPU during VBlank, and applies the vertical one-line correction the hardware needs (see Scrolling):
For depth, scroll the layers at different speeds:
For a different speed on each band of the screen, see the HDMA parallax in Scrolling.
A background picture becomes tiles, a tilemap and a palette with opensnes-tileset — pictures to tilesets and tilemaps. Put a settings file beside the picture — its first line names the tool — and the build converts it before compiling anything; nothing goes in the Makefile:
The same conversion by hand is opensnes-tileset convert res/opensnes.png --colors 16 (--save writes the settings file for you). It writes opensnes.pic (the unique tiles), opensnes.map (the tilemap), opensnes.pal and opensnes.inc, which declares the arrays and a ready BgAsset:
The arrays behind it (opensnes_tiles, opensnes_map, opensnes_pal, each with _end) work with dmaCopyVram / dmaCopyCGram when you want to place each part yourself. Other keys of [convert] used by the examples: bpp = 2 and colors = 4 for a Mode 0 layer, bpp = 8 for Mode 3, mode = 7 for a Mode 7 plane, priority = true, palette-entry = N for a layer that uses a later palette bank, pages = true for a 64x64 scrolling map. Sprite sheets go through opensnes-sprite — sheets, metasprites and Aseprite clips instead (Sprites & Animation Tutorial).
palette = "master.pal" imposes a committed palette instead of deriving one from the image's own colours. The build fails — naming the offending colour — if the image uses any colour not in that palette. This is the fix for the problem where adding one tile re-derives the whole palette and shifts every existing tile's hue: author the palette once, commit it, and impose it on every conversion so a new tile can only reuse existing entries (examples/demos/rpg/res/tileset.png.toml does this).
Art generated by the game — a dot, a bar, a glyph built from a bitmask — starts as colour indices, one byte per pixel. tileEncode4bpp() (module tile, <snes/tile.h>; 2bpp and 8bpp variants too) turns 64 of them, row by row, into the planar tile the PPU reads:
A tile costs about 47 000 master cycles, an eighth of a frame: build tiles while loading, or a few per frame. backgrounds/mode2 builds its art this way.
Tile data compresses well — it is repetitive by construction — and the SDK can decompress it straight into VRAM, so the ROM carries the small form and the PPU gets the big one. Add lz = true to the picture's settings file and link the module:
With lz = true the .inc declares the arrays only, no BgAsset: bgLoad() would copy the compressed bytes.
The saving is worth measuring rather than assuming. examples/backgrounds/mode1 links its picture twice, plain and with lz = true: the compressed .pic is 652 bytes and its LZ77 header declares 2592 bytes of tile data — the 2592 bytes of the plain copy. A and B show one copy or the other, and the picture does not change. That is a quarter of the ROM footprint for one call at load time.
The format is the familiar GBA-style LZ77: a 0x10 tag byte, a three-byte little-endian decompressed length, then flag bytes whose bits select a literal or a back-reference. Any tool that emits that layout will do.
See examples/scrolling/parallax_scroll/ for a complete parallax scrolling example.
BG Mode 5 renders 512 horizontal pixels (16x8 tiles, stored as 8x8 character pairs N/N+1); adding screen interlace (videoSetInterlace(1), SETINI bit 0 through the lib's write-only shadow) doubles vertical to 448 lines. Three traps, all demonstrated by examples/backgrounds/mode5_hires:
videoSetObjInterlace, videoSetOverscan and videoSetPseudoHires cover the other SETINI bits — overscan shrinks the VBlank DMA budget by ~15 lines, see the header warning.