Loading...
Searching...
No Matches
main.c File Reference

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.
 

Detailed Description

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).

SNES Concepts
  • HDMA writing to INIDISP ($2100) for per-scanline brightness control
  • hdmaBrightnessGradient() library helper for runtime table generation
  • Mode 3 (8bpp, 256-color) background rendering
  • Assembly DMA loader for multi-bank ROM data (SUPERFREE sections)
What to Observe
  • Press A repeatedly to cycle through gradient levels (top stays bright, bottom darkens)
  • Press B to stop the gradient and restore full uniform brightness
  • The 8bpp background image displays in full 256-color detail
Modules Used
console, dma, background, sprite, hdma, input, math
See also
hdma.h, video.h, background.h, input.h

Function Documentation

◆ loadGraphics()

void loadGraphics ( void  )
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.

◆ main()

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).

Returns
Does not return (infinite loop).

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).