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

Minimal "Hello World" text display using hand-coded 2bpp font tiles. More...

#include <snes.h>

Functions

int main (void)
 Entry point – set up PPU, load font, build tilemap, display text.
 

Variables

static const u8 bg_palette []
 Background palette in BGR555 format (2 colors, 4 bytes total)
 
static const u8 font_tiles []
 Hand-coded 2bpp bitmap font tiles (9 glyphs, 16 bytes each)
 
static const u8 message []
 "HELLO WORLD!" encoded as tile indices into font_tiles[]
 

Detailed Description

Minimal "Hello World" text display using hand-coded 2bpp font tiles.

The simplest possible SNES program: writes a hand-coded 2bpp bitmap font into VRAM, builds a tilemap row to spell "HELLO WORLD!", and displays it on BG1 in Mode 0. No external assets or font library are used – every tile is defined as raw bitplane data in a C array, making this example a good starting point for understanding how the SNES PPU interprets tile graphics and tilemaps.

SNES Concepts
  • 2bpp tile format: each 8x8 tile is 16 bytes (two bitplanes interleaved)
  • VRAM tilemap structure: 32x32 entries, each a 16-bit word (tile index + attributes)
  • CGRAM palette: two BGR555 colors loaded at palette index 0
  • Mode 0: four BG layers, each limited to 4 colors (2bpp)
  • DMA transfers for tile data and palette via dmaCopyVram / dmaCopyCGram
What to Observe
  • "HELLO WORLD!" rendered in white text on a dark blue background
  • The text appears centered at row 14, column 10 of the 32x32 tilemap
  • The screen is otherwise blank (tilemap filled with tile 0, the space glyph)
Modules Used
console, sprite, dma, background
See also
background.h, dma.h, video.h

Function Documentation

◆ main()

int main ( void  )

Entry point – set up PPU, load font, build tilemap, display text.

Initializes the SNES hardware via consoleInit(), loads a hand-coded 2bpp font into VRAM, fills the 32x32 tilemap with blank tiles, writes the "HELLO WORLD!" message at a specific tilemap row/column, and enters an infinite VBlank loop. All VRAM writes happen during forced blank (screen off) to satisfy the PPU timing constraint.

Returns
Never returns (infinite loop).

< VRAM word address for tilemap cursor position

< Current tile index read from message[]

< Loop counter for tilemap fill and message write

Variable Documentation

◆ bg_palette

const u8 bg_palette[]
static
Initial value:
= {
0x00, 0x28,
0xFF, 0x7F,
}

Background palette in BGR555 format (2 colors, 4 bytes total)

SNES CGRAM stores colors as 15-bit BGR555: bbbbbgggggrrrrr in two bytes (little-endian). Color 0 is the background fill, color 1 is the text. Only 2 of the 4 available Mode 0 palette entries are used.

◆ font_tiles

const u8 font_tiles[]
static

Hand-coded 2bpp bitmap font tiles (9 glyphs, 16 bytes each)

Each 8x8 tile occupies 16 bytes in SNES 2bpp format: two interleaved bitplanes per pixel row. Bitplane 0 selects palette color 1, bitplane 1 selects color 2, and both together select color 3. All bitplane-1 bytes are zero here, so every lit pixel maps to palette color 1 (white).

Tile index map: 0=Space, 1=H, 2=E, 3=L, 4=O, 5=W, 6=R, 7=D, 8=!

◆ message

const u8 message[]
static
Initial value:
= {
1, 2, 3, 3, 4,
0,
5, 4, 6, 3, 7,
8,
0xFF
}

"HELLO WORLD!" encoded as tile indices into font_tiles[]

Each byte is an index into the font tile array. The string is terminated by 0xFF, which acts as an end-of-message sentinel (not a valid tile index).