HDMA brightness gradient on an 8bpp Mode 3 background. More...
#include <snes.h>#include <snes/console.h>#include <snes/video.h>#include <snes/background.h>#include <snes/input.h>#include <snes/hdma.h>Functions | |
| void | loadGraphics (void) |
| Assembly DMA loader for the 8bpp Mode 3 background (defined in data.asm). | |
| int | main (void) |
| Entry point – HDMA brightness gradient on a Mode 3 background. | |
HDMA brightness gradient on an 8bpp Mode 3 background.
Demonstrates a vertical brightness gradient using HDMA writes to the INIDISP register ($2100). Each scanline group receives a different brightness level (0-15), creating a smooth fade from full brightness at the top to darkness at the bottom. The hdmaBrightnessGradient() library helper builds the HDMA table at runtime, interpolating between a top brightness and a bottom brightness across 224 scanlines. The background is an 8bpp Mode 3 image loaded via an assembly DMA helper (required because the 32KB tile data spans multiple ROM banks, and the C-level dmaCopyVram() hardcodes bank $00).
|
extern |
Assembly DMA loader for the 8bpp Mode 3 background (defined in data.asm).
Handles DMA transfers with correct bank bytes for SUPERFREE data sections. The 8bpp tile data is ~32KB, which exceeds bank $00's ROM space and spills into bank $01. The C-level dmaCopyVram() hardcodes bank $00 in its DMA source address, so it would read garbage for data in bank $01+. This assembly routine uses the linker-resolved :label bank byte to set the correct DMA source bank.
Transfers: tiles to VRAM $1000, tilemap to VRAM $0000, palette to CGRAM slot 0. Must be called during forced blank.
| int main | ( | void | ) |
Entry point – HDMA brightness gradient on a Mode 3 background.
Loads a 256-color (8bpp) background image via the assembly DMA loader, then enters an interactive loop where button A cycles through brightness gradient levels (top stays bright, bottom darkens progressively), and button B restores uniform full brightness. The gradient is implemented via hdmaBrightnessGradient(), which builds an HDMA table that writes per-scanline values to INIDISP ($2100).
Current bottom brightness for the gradient (15=full, 0=black).
Each press of A decrements this value, making the bottom of the screen darker. When it drops below 2, it wraps back to 15. The top brightness is always 15 (full).