Loading...
Searching...
No Matches
main.c File Reference

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 []
 

Detailed Description

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.

SNES Concepts
  • LZSS/LZ77 decompression: LzssDecodeVram() streams compressed data to VRAM word-by-word
  • gfx4snes -z flag enables LZ77 compression for tile data at build time
  • Mode 1 BG1 at 4bpp (16 colors) with tilemap at $0000, tiles at $4000
  • Force blank via REG_INIDISP during decompression (slower than DMA, needs full blanking)
  • Palette loaded uncompressed via dmaCopyCGram(); only tile data benefits from compression
What to Observe
  • A static full-screen image identical in appearance to the uncompressed Mode 1 example
  • The ROM is smaller due to LZ77-compressed tile data
  • Startup may be slightly slower than DMA (decompression is CPU-driven, not DMA)
Modules Used
console, lzss, background, sprite
See also
lzss.h, background.h, dma.h, video.h

Function Documentation

◆ main()

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.

Returns
Never returns (infinite loop).

Variable Documentation

◆ map

u8 map[]
extern

◆ map_end

u8 map_end[]

Uncompressed 32x32 tilemap entries

◆ palette

u8 palette[]
extern

◆ palette_end

u8 palette_end[]

Uncompressed 16-color BGR555 palette

◆ patterns

u8 patterns[]
extern

LZ77-compressed 4bpp tile data (decompressed to VRAM by LzssDecodeVram)