Interactive showcase of all four HDMA library helper effects. More...
#include <snes.h>#include <snes/console.h>#include <snes/input.h>#include <snes/hdma.h>#include "res/bg.inc"Classes | |
| struct | EffectState |
| Tracks which HDMA effect is currently active and its parameters. More... | |
Functions | |
| int | main (void) |
| Entry point – interactive showcase of four HDMA helper effects. | |
| static void | stopCurrentEffect (void) |
| Stop whichever HDMA effect is currently running and restore defaults. | |
Variables | |
| EffectState | fx = {0, 80, 0, 6} |
| Global effect state instance with default values. | |
| u8 | hdma_table_a [] |
| Scratch HDMA table used for channel 6 null-terminator setup. | |
| u8 | hdma_wave_amplitude |
| 4bpp tile data for the background image. | |
Interactive showcase of all four HDMA library helper effects.
Demonstrates the four high-level HDMA helper functions provided by the OpenSNES library: brightness gradient, color gradient, iris wipe, and water ripple. Each effect uses one or two HDMA channels to modify PPU registers per-scanline without CPU intervention. The brightness gradient writes INIDISP ($2100), the color gradient rewrites CGRAM color 0 via CGADD/CGDATA, the iris wipe programs window registers (WH0/WH1) with TMW masking, and the water ripple offsets BG1HOFS per scanline using a sine-based displacement table. Effects can be toggled and their parameters adjusted in real time using the controller.
| int main | ( | void | ) |
Entry point – interactive showcase of four HDMA helper effects.
Loads a background image and enters an interactive loop where each button activates a different HDMA effect:
Before activating a new effect, the previous one is always stopped first to avoid HDMA channel conflicts and stale PPU register values.
< Newly pressed buttons this frame (edge-detected)
|
static |
Stop whichever HDMA effect is currently running and restore defaults.
This function performs a complete cleanup:
| EffectState fx = {0, 80, 0, 6} |
Global effect state instance with default values.
|
extern |
Scratch HDMA table used for channel 6 null-terminator setup.
Defined in the HDMA library module. When an effect is stopped, this table is loaded with a single 0x00 terminator and assigned to channel 6 to keep the channel "alive" for proper HDMA initialization at each VBlank.
|
extern |
4bpp tile data for the background image.
15-bit BGR palette for the background (up to 16 colors).
Tilemap data (32x32 tile grid) for the background.
Current wave amplitude for the water ripple effect (library variable).
This variable is defined in the HDMA library module. Writing to it adjusts the horizontal displacement amplitude of the sine-wave distortion applied per-scanline to BG1HOFS. Valid range: 2-24 pixels. The library reads this value each frame in hdmaWaveUpdate() to scale the sine table entries.