LZ77-compressed tile loading with LZSS decompression to VRAM. More...
#include <snes.h>#include "vram_map.h"#include <snes/console.h>#include <snes/video.h>#include <snes/dma.h>#include <snes/background.h>#include <snes/lzss.h>#include "res/opensnes.inc"Functions | |
| int | main (void) |
| Entry point – decompress LZ77 tiles to VRAM and display Mode 1 image. | |
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(). Measured on this example's own asset: the compressed .pic is 652 bytes and its LZ77 header declares 2592 bytes of tile data — the same 2592 bytes examples/backgrounds/mode1 stores uncompressed for the same image, so the ROM footprint is a quarter of the original. (An earlier version of this comment claimed ~8.5 KB expanding to ~12.5 KB for a 31% saving; both figures were wrong.) 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.