Static 16-color background display in Mode 1 (4bpp). More...
#include <snes.h>#include <snes/asset.h>#include <snes/lzss.h>#include "res/street.inc"#include "res/street_lz.inc"Macros | |
| #define | MAP_ADDR 0x7800 |
| VRAM word address of the tilemap, after both copies of the tiles. | |
| #define | TILES_LZ 0x4000 |
| #define | TILES_PLAIN 0x0000 |
| VRAM word address of the plain tiles (bgLoad) and of the decompressed copy. | |
Functions | |
| int | main (void) |
| Entry point – load a 4bpp tileset and display a static Mode 1 image. | |
Static 16-color background display in Mode 1 (4bpp).
Displays a single full-screen tiled background using Mode 1, the most commonly used SNES video mode. Mode 1 provides two 4bpp layers (BG1 and BG2, each up to 16 colors) plus one 2bpp layer (BG3, 4 colors). This example uses only BG1: a rainy street at night, 16 colours, converted from a PNG by the build (opensnes-tileset and the settings file beside it).
The same picture is also linked a second time, LZ77-compressed by the build (lz = true in res/street_lz.png.toml: 28256 bytes of tiles become 18816), and decompressed at boot straight into VRAM by lzssDecodeVram(). A and B point BG1 at one copy or the other: the screen does not change, and that is the lesson — same tiles, two thirds of the ROM. A detailed picture compresses less than a flat one: LZ77 finds repeats, and every tile of a painting is a little different.
This began as the PVSnesLib "Mode1" and "Mode1LZ77" examples.
| #define MAP_ADDR 0x7800 |
VRAM word address of the tilemap, after both copies of the tiles.
| #define TILES_LZ 0x4000 |
| #define TILES_PLAIN 0x0000 |
VRAM word address of the plain tiles (bgLoad) and of the decompressed copy.
| int main | ( | void | ) |
Entry point – load a 4bpp tileset and display a static Mode 1 image.
Demonstrates the typed asset bundle: tileset, palette, tilemap, color depth and map size all travel together in a single BgAsset. A single bgLoad() does the same work as a manual bgSetMapPtr + bgInitTileSet + dmaCopyVram triple, with the color-mode / size pairing locked at declaration time.
The picture has 883 distinct tiles (28 KB at 4bpp), and the VRAM holds it twice, so the layout is tight: the plain tiles at $0000, the decompressed copy at $4000 (a character base is a multiple of $1000 words), and the tilemap after both at $7800.