The most common SNES video mode with two 16-color and one 4-color background.
After this lesson, you will understand:
Displays a static background image using Mode 1, a rainy street at night:
Controls:
| Button | Action |
|---|---|
| A | Show BG1 from the LZ77-decompressed copy of the tiles (VRAM $4000) |
| B | Show it from the plain copy (VRAM $0000) |
The picture does not change: that is the point of the second copy.
res/street_lz.png is the same picture with lz = true in its settings file: the build stores its tiles LZ77-compressed, 18816 bytes in ROM for the 28256 of the plain copy. At boot the example decodes them straight into VRAM, in force blank:
and A / B switch BG1's character base between the two copies (bgSetGfxPtr(0, 0x4000) or 0x0000) — one register, at any time. With lz = true the .inc declares the arrays only, no BgAsset: bgLoad() would copy the compressed bytes. Two thirds of the ROM for one call at load time. A painting compresses less than a flat logo: LZ77 saves on repeats, and almost every tile of this picture is a little different (a 2592-byte logo went to 652 bytes, a quarter).
C with Library Functions
| Component | Type |
|---|---|
| Background setup | Library (bgSetMapPtr, bgInitTileSet) |
| Tilemap loading | Library (dmaCopyVram) |
| Mode setting | Library (setMode) |
| Screen enable | Library (setScreenOn) |
Mode 1 is the most popular SNES video mode:
| Layer | Color Depth | Colors | Typical Use |
|---|---|---|---|
| BG1 | 4bpp | 16 | Main playfield |
| BG2 | 4bpp | 16 | Secondary layer |
| BG3 | 2bpp | 4 | Status bar, text |
| Sprites | 4bpp | 16 per palette | Characters, objects |
This example's layout (word addresses), tight because the picture is there twice:
A character base is a multiple of $1000 words and a tilemap base a multiple of $400, which is what decides these three addresses.
Each tilemap entry is 2 bytes:
Mode 1 uses 4 bits per pixel (16 colors):
Then open mode1.sfc in luna (luna-gui mode1.sfc) or any emulator.
console, sprite, dma, background, asset, lzss, input (LIB_MODULES in the Makefile).
| File | Purpose |
|---|---|
| main.c | Background setup code |
| res/street.png | the picture: a rainy street at night, 256x256 (the last 32 rows are below the screen), 16 colours; generated for OpenSNES, CC0 (assets/neo-lumen/) |
| res/street.png.toml | its import settings (opensnes-tileset, 16 colours); the build converts it and links the result, res/street.inc declares the BgAsset |
| res/street_lz.png.toml | the same picture with lz = true: its tiles are linked LZ77-compressed, res/street_lz.inc declares the arrays |
| Makefile | Build configuration (LIB_MODULES := console sprite dma background asset lzss input) |
| res/ | Source graphics files |
Enable BG2 with a different tileset:
Modify colors by writing to CGRAM:
Modify tilemap entries to flip tiles:
Use BG3 for a status bar that appears over BG1:
Default priority (back to front):
Priority bit in tilemap flips individual tiles to front.
BG3 in Mode 1 is only 2bpp (4 colors) but has special priority behavior. It's commonly used for:
Mode 1 palette organization:
More BG layers: Panel HUD - a HUD on BG3, in front of the scene
Sprites: Simple Sprite - Display a sprite
Effects: Fading - Screen transitions