HDMA-driven parallax scrolling with three speed zones. More...
#include <snes.h>Functions | |
| int | main (void) |
| Entry point: set up parallax scrolling with three speed zones. | |
Variables | |
| u8 | palette [] |
| 16-color palette for the background | |
| u8 | scroll_table [10] |
| HDMA scroll table in RAM (must be in bank $00 WRAM, < $2000). | |
| u8 | tilemap [] |
| 64x32 tilemap data for the parallax background | |
| u8 | tiles [] |
| 4bpp background tile data (defined in data.asm, stored in ROM) | |
| u8 | tiles_end [] |
HDMA-driven parallax scrolling with three speed zones.
Demonstrates parallax scrolling using HDMA (H-Blank DMA) to override the BG1 horizontal scroll register (BG1HOFS, $210D) at different scanline boundaries. The screen is divided into three horizontal zones, each scrolling at a different speed to create the illusion of depth.
HDMA channel 6 writes a 2-byte scroll value (mode: 2-register) to BG1HOFS at each zone boundary. The scroll table lives in RAM so the main loop can increment each zone's offset at different rates every frame.
Ported from PVSnesLib ParallaxScrolling example.
| int main | ( | void | ) |
Entry point: set up parallax scrolling with three speed zones.
Loads a 64x32 tile background, configures HDMA to split the screen into three horizontal bands, and updates each band's scroll offset at a different rate every frame to create a parallax depth illusion.
< Enable only BG1 on the main screen
< Zone 1 (sky): 72 scanlines
< Initial horizontal scroll = 1 pixel
< Zone 2 (hills): 88 scanlines
< Initial horizontal scroll = 2 pixels
< Zone 3 (ground): 64 scanlines
< Initial horizontal scroll = 4 pixels
< End-of-table marker
< Sky: +1 pixel/frame (slow)
< Hills: +2 pixels/frame (medium)
< Ground: +4 pixels/frame (fast)
|
extern |
16-color palette for the background
| u8 scroll_table[10] |
HDMA scroll table in RAM (must be in bank $00 WRAM, < $2000).
This table defines three horizontal screen zones, each with an independent scroll offset. HDMA channel 6 reads this table during HBlank to override the BG1 horizontal scroll register (BG1HOFS, $210D) at zone boundaries.
Table format (mode: 2-register write to $210D/$210E): [line_count] [scroll_lo] [scroll_hi] – zone entry (3 bytes) ...repeated for each zone... [0x00] – end-of-table marker
The table lives in RAM (not ROM) because scroll values are updated every frame by the main loop. HDMA re-reads the table each frame automatically.
Total: 3 zones x 3 bytes + 1 terminator = 10 bytes.
|
extern |
64x32 tilemap data for the parallax background
|
extern |
4bpp background tile data (defined in data.asm, stored in ROM)
| u8 tiles_end[] |