LZ77-compressed tile loading with LZSS decompression to VRAM. More...
#include <snes.h>#include <snes/console.h>#include <snes/video.h>#include <snes/dma.h>#include <snes/background.h>#include <snes/lzss.h>Functions | |
| int | main (void) |
| Entry point – decompress LZ77 tiles to VRAM and display Mode 1 image. | |
Variables | |
Graphics data pointers (defined in data.asm via .incbin) | |
| u8 | map [] |
| u8 | map_end [] |
| u8 | palette [] |
| u8 | palette_end [] |
| u8 | patterns [] |
LZ77-compressed tile loading with LZSS decompression to VRAM.
Demonstrates ROM space savings by storing tile data in LZ77-compressed form and decompressing directly into VRAM at load time using LzssDecodeVram(). The compressed .pic file occupies ~8.5 KB in ROM but expands to ~12.5 KB of 4bpp tile data in VRAM, achieving a 31% size reduction. The tilemap and palette are stored uncompressed and loaded via standard DMA.
The gfx4snes tool produces LZ77-compressed output when invoked with the -z flag. LzssDecodeVram() handles the VRAM write timing internally.
Based on the PVSnesLib "Mode1LZ77" example by Alekmaul.
| int main | ( | void | ) |
Entry point – decompress LZ77 tiles to VRAM and display Mode 1 image.
Initializes the console, forces blank, then uses LzssDecodeVram() to stream LZ77-compressed tile data directly into VRAM at $4000. Unlike DMA (which copies raw data at ~1 byte per CPU cycle), LZSS decompression is CPU-driven and slower, so the screen must remain in forced blank for the entire decode. Palette and tilemap are loaded uncompressed via standard DMA calls.
The benefit is ROM space savings: compressed tiles occupy ~30% less ROM than raw tile data, which matters when ROM banks are limited to 32KB.
|
extern |
| u8 map_end[] |
Uncompressed 32x32 tilemap entries
|
extern |
| u8 palette_end[] |
Uncompressed 16-color BGR555 palette
|
extern |
LZ77-compressed 4bpp tile data (decompressed to VRAM by LzssDecodeVram)