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

Mixed scrolling, a title screen: three layers, three scrolls — the rain, a fixed logo, a moving message. More...

#include <snes.h>
#include <snes/text.h>
#include "vram_map.h"
#include "res/logo.inc"
#include "res/rain.inc"

Functions

int main (void)
 Entry point – mixed scrolling with auto-scrolling BG1 and fixed BG2.

Variables

u16 msgX = 0
 The message's horizontal scroll (BG3).
s16 scrX = 0
 BG1 tile data – the rain, a repeating picture (4bpp, tiles at VRAM $4000).
s16 scrY = 0
 BG1 vertical scroll offset (auto-incremented each frame).

Detailed Description

Mixed scrolling, a title screen: three layers, three scrolls — the rain, a fixed logo, a moving message.

The title screen of the Néo-Lumen examples. Layers two Mode 1 backgrounds: BG1 displays the night behind the title — rain and far lights, a picture that repeats — and auto-scrolls diagonally each frame, one pixel left and two down, the slope of the rain; BG2 shows the logo, which remains fixed. Each layer uses its own tile set and palette slot in VRAM and CGRAM (BG1 tiles at $4000 with palette slot 1, BG2 tiles at $5000 with palette slot 0). The tilemaps are placed at non-overlapping VRAM addresses ($1800 for BG1, $1400 for BG2). This demonstrates how the SNES PPU composites multiple BG layers with independent scroll offsets, making it straightforward to combine static UI elements with animated backgrounds.

A third layer, BG3 (2bpp), carries a line of text from the text module, scrolled horizontally at its own pace: a scrolling message is a scrolled background like any other (it was the scroll_message example).

SNES Concepts
  • Independent per-layer scroll registers (BG1 scrolls, BG2 stays fixed)
  • Multiple tile sets sharing VRAM without overlap
  • Separate palette slots per layer (palette-entry in a picture's settings file)
  • Mode 1 layer order: BG1 is in front of BG2 at the same priority, so the logo's tiles carry the priority bit (priority = true in its settings)
  • BG3 in Mode 1: 2bpp, its palettes in CGRAM 0-31 (shared with the 4bpp layers' — the text takes 2bpp slot 7, colours 28-31, which BG1's thirteen colours (CGRAM 16-28) leave free but for 28, the transparent one of the slot), above the others with BG3_MODE1_PRIORITY_HIGH and the tile priority bit
  • The text module on a layer of your choice: textLoadFont / textInit
What to Observe
  • The rain (BG1) falls diagonally and wraps seamlessly
  • The logo (BG2), Kit and the wordmark, remains stationary in the center
  • Both layers composite together with proper priority ordering
  • The message (BG3) slides left one pixel a frame, in front of both
Modules Used
console, sprite, dma, background, text
See also
background.h, dma.h, video.h

Function Documentation

◆ main()

int main ( void )

Entry point – mixed scrolling with auto-scrolling BG1 and fixed BG2.

Loads two Mode 1 background layers into non-overlapping VRAM regions:

  • BG1: the rain (tiles at $4000, tilemap at $1800, palette slot 1)
  • BG2: static logo (tiles at $5000, tilemap at $1400, palette slot 0)

Each frame, BG1's scroll position moves one pixel right and two up, so the rain falls one pixel left and two down, continuously. BG2 has no scroll updates, so it remains fixed on screen. The SNES PPU composites both layers together, with BG2 (the logo) on top of BG1 because its tiles carry the priority bit.

Note
The tile, map and palette symbols come from the generated res/logo.inc and res/rain.inc (opensnes-tileset writes them from the settings files beside the pictures).
Returns
Does not return (infinite loop).

Variable Documentation

◆ msgX

u16 msgX = 0

The message's horizontal scroll (BG3).

◆ scrX

s16 scrX = 0

BG1 tile data – the rain, a repeating picture (4bpp, tiles at VRAM $4000).

BG1 palette (16 colors loaded to CGRAM slot 1, offset 16).

BG1 tilemap (32x32 tile grid loaded to VRAM $1800).

BG2 tile data – static logo (4bpp, tiles at VRAM $5000).

BG2 palette (16 colors loaded to CGRAM slot 0, offset 0).

BG2 tilemap (32x32 tile grid loaded to VRAM $1400).

BG1 horizontal scroll offset (auto-incremented each frame).

◆ scrY

s16 scrY = 0

BG1 vertical scroll offset (auto-incremented each frame).