Fundamentals — how a glyph is drawn: 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 (3 colors, 6 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[] | |
Fundamentals — how a glyph is drawn: hand-coded 2bpp font tiles.
The under-the-hood companion to the Text family. Instead of calling the text module, it writes a hand-coded 2bpp bitmap font straight into VRAM, builds a tilemap row to spell "HELLO WORLD!", and shows it on BG1 in Mode 0, in the city's colours: cyan letters with a pink shadow on a terminal's glass. Every tile is raw bitplane data in a C array — no assets, no font library — so you see exactly how the SNES PPU turns bytes into pixels. Read examples/text/print_string first for the easy way; read this to understand what that module hides.
| 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.
< VRAM word address for tilemap cursor position
< Current tile index read from message[]
< Loop counter for tilemap fill and message write
|
static |
Background palette in BGR555 format (3 colors, 6 bytes total).
SNES CGRAM stores colors as 15-bit BGR555: 0bbbbbgggggrrrrr in two bytes (little-endian). Color 0 is the background fill (a terminal's glass), color 1 the letters, color 2 their shadow: the neon of the Rue basse. Color 3 of the 4 Mode 0 palette entries is not used.
|
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, plane 0 first. A pixel's colour is its plane 1 bit times two plus its plane 0 bit. Plane 0 holds the letter, the glyph of the city's font (the text module's, lib/source/text.asm): colour 1, cyan. Plane 1 holds its shadow, the letter moved one pixel right and one down, where the letter is not: colour 2, pink. No pixel has both bits, so colour 3 is never drawn.
Tile index map: 0=Space, 1=H, 2=E, 3=L, 4=O, 5=W, 6=R, 7=D, 8=!
|
static |
"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).