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). | |
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).
| 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:
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.
| 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).
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).
| s16 scrY = 0 |
BG1 vertical scroll offset (auto-incremented each frame).