HDMA-driven parallax scrolling with three speed zones. More...
Functions | |
| int | main (void) |
| Entry point: set up parallax scrolling with three speed zones. | |
Variables | |
| u8 | scroll_table [10] |
| 4bpp background tile data (converted by the build from res/) | |
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.
The picture is the city at night in three bands: the far towers, the mid-distance blocks, the roofs and the street close by. Each band is a 256-pixel half and its mirror, so it wraps at 512 without a seam, and the converter stores the mirrored half as flip bits, not as new tiles.
This began as the 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 (far towers): 72 scanlines
< Initial horizontal scroll = 1 pixel
< Zone 2 (mid-distance): 88 scanlines
< Initial horizontal scroll = 2 pixels
< Zone 3 (roofs close by): 64 scanlines
< Initial horizontal scroll = 4 pixels
< End-of-table marker
< Far towers: +1 pixel/frame (slow)
< Mid-distance: +2 pixels/frame (medium)
< Roofs close by: +4 pixels/frame (fast)
| u8 scroll_table[10] |
4bpp background tile data (converted by the build from res/)
HDMA scroll table in RAM — a plain C global, so it sits in $00:0000-$1FFF like every non-FAR variable; hdmaSetup() reads the bank from the pointer and would take a const table too.
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.