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

Display a single static 32x32 sprite. More...

#include <snes.h>

Functions

int main (void)
 Entry point: display a single static 32x32 sprite at screen center.
 

Variables

u8 palsprite32 []
 16-color palette for the 32x32 sprite
 
u8 sprite32 []
 4bpp 32x32 sprite tile data (defined in data.asm, stored in ROM)
 
u8 sprite32_end []
 

Detailed Description

Display a single static 32x32 sprite.

Minimal example showing how to load and display one hardware sprite on the SNES. Sprite tile data is DMA'd to VRAM, a 16-color palette is loaded to CGRAM at address 128 (sprite palette 0), and the OBJ size register (OBJSEL, $2101) is configured for small=8x8 / large=32x32 mode.

The sprite is placed at screen center using oamSet(), which writes to the 544-byte OAM buffer that the NMI handler DMAs to the PPU each VBlank. The tile number is calculated from the offset between the OBJSEL name base and the VRAM address where the tile data was loaded.

SNES Concepts
  • OAM (Object Attribute Memory): 128 sprite entries, 544 bytes total
  • OBJSEL register ($2101): sprite size mode and name base address
  • Sprite tile numbering relative to the OBJSEL name base
  • DMA transfer of tile data to VRAM and palette data to CGRAM
What to Observe
  • A single 32x32 sprite displayed at the center of the screen
  • No input required; the sprite is static
Modules Used
console, dma, sprite
See also
sprite.h, dma.h, video.h

Function Documentation

◆ main()

int main ( void  )

Entry point: display a single static 32x32 sprite at screen center.

This is the simplest possible sprite example. It demonstrates the complete pipeline for getting one hardware sprite on screen:

  1. DMA tile data to OBJ VRAM
  2. DMA palette to CGRAM (sprite palettes start at address 128)
  3. Configure OBJSEL for the desired size mode and name base
  4. Set OAM entry with position, tile number, and attributes
  5. Enable OBJ layer on the main screen
Returns
Never returns (infinite loop).

Variable Documentation

◆ palsprite32

u8 palsprite32[]
extern

16-color palette for the 32x32 sprite

◆ sprite32

u8 sprite32[]
extern

4bpp 32x32 sprite tile data (defined in data.asm, stored in ROM)

◆ sprite32_end

u8 sprite32_end[]