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

Mode 5 hi-resolution background display. More...

#include <snes.h>

Functions

int main (void)
 Entry point – sets up Mode 5 hi-res display and loops forever.
 

Variables

u8 palette []
 15-bit BGR palette for the Mode 5 background (up to 16 colors).
 
u8 palette_end []
 
u8 tilemap []
 Tilemap data mapping tile indices to BG1's 32x32 grid.
 
u8 tilemap_end []
 
u8 tiles []
 Mode 5 interleaved 4bpp tile data (converted with gfx4snes -M 5).
 
u8 tiles_end []
 

Detailed Description

Mode 5 hi-resolution background display.

Demonstrates SNES BG Mode 5 (512x256, 4bpp, 16 colors). Mode 5 doubles the horizontal resolution from 256 to 512 pixels by using interlaced tile data and requiring BG1 on both the main and sub screens. The PPU alternates even/odd pixel columns between the two screens each frame, producing a true 512-pixel-wide output on compatible displays. Tile data must be converted with the special -M 5 interleaving flag.

SNES Concepts
  • BG Mode 5 hi-res rendering (512px horizontal)
  • Main screen + sub screen cooperation for interlaced output
  • Mode 5 tile data interleaving (gfx4snes -M 5)
  • DMA tilemap transfer to VRAM
What to Observe
  • A single full-screen image rendered at 512-pixel horizontal resolution
  • Text and fine detail should appear sharper than standard 256px modes
Modules Used
console, dma, background
See also
background.h, dma.h, video.h

Function Documentation

◆ main()

int main ( void  )

Entry point – sets up Mode 5 hi-res display and loops forever.

The setup sequence is:

  1. Load interleaved tile data and palette via bgInitTileSet (tiles at VRAM $0000, palette at CGRAM slot 0).
  2. DMA the tilemap to VRAM $6000 (chosen to avoid overlap with tile data).
  3. Enable BG Mode 5 and put BG1 on both the main AND sub screens – this is the critical step that makes 512px hi-res work. The PPU interleaves even columns from the main screen with odd columns from the sub screen.
Returns
Does not return (infinite loop).

Variable Documentation

◆ palette

u8 palette[]
extern

15-bit BGR palette for the Mode 5 background (up to 16 colors).

◆ palette_end

u8 palette_end[]

◆ tilemap

u8 tilemap[]
extern

Tilemap data mapping tile indices to BG1's 32x32 grid.

Each tilemap entry is 2 bytes: low byte = tile index, high byte = attributes (palette, priority, flip). Loaded to VRAM $6000 to avoid overlapping the tile data region at $0000.

◆ tilemap_end

u8 tilemap_end[]

◆ tiles

u8 tiles[]
extern

Mode 5 interleaved 4bpp tile data (converted with gfx4snes -M 5).

Mode 5 tile data is interleaved: even pixel columns go to the main screen and odd pixel columns go to the sub screen. The PPU composites both screens each frame to produce the 512-pixel-wide output. Standard (non-interleaved) tile data would display incorrectly in Mode 5.

◆ tiles_end

u8 tiles_end[]