OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Family 1 (Text) · rung 1.4 — move a message across the screen. More...

#include <snes.h>

Functions

int main (void)
 Entry point — print one line, then scroll BG1 forever.

Detailed Description

Family 1 (Text) · rung 1.4 — move a message across the screen.

The Text ladder's "make it move" rung. It prints one line, then scrolls the whole text background horizontally every frame, so the message marches across the screen like a marquee and wraps around the 32x32 (256-pixel) tilemap seamlessly. The lesson: text lives on a BG layer, so you move it exactly like any other background — with bgSetScroll().

SNES Concepts
  • Text is just a BG layer: bgSetScroll(0, x, 0) scrolls BG1 (the text layer)
  • Scroll writes are buffered — bgSetScroll() stores a value and marks it dirty; the NMI handler pushes it to the PPU scroll registers during VBlank, so the scroll never tears
  • A 32x32 tilemap is exactly one screen wide, so incrementing X wraps the message around for a continuous marquee, for free
What to Observe
  • "OPENSNES -- TEXT THAT MOVES!" scrolling right-to-left, looping forever
Modules Used
console, dma, text, background, sprite
See also
background.h, text.h, tutorial_scrolling

Function Documentation

◆ main()

int main ( void )

Entry point — print one line, then scroll BG1 forever.

The message is written to the text tilemap once. From then on the frame loop only changes BG1's horizontal scroll offset; the PPU re-reads the same tilemap from a shifted origin, so the text appears to travel without a single extra VRAM write.

Returns
Never returns (infinite loop).