OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Screen fade in/out using INIDISP brightness control. More...

#include <snes.h>
#include "vram_map.h"

Functions

int main (void)
 Entry point – cycles through fade-out/fade-in at three speeds.
static void wait_for_key (void)
 Block until the user presses a button (with debounce).

Variables

u8 palette []
 15-bit BGR palette (up to 16 colors) for the background image.
u8 palette_end []
u8 tilemap []
 Tilemap data (32x32 tile grid) for the background image.
u8 tilemap_end []
u8 tiles []
 4bpp tile data for the background image.
u8 tiles_end []

Detailed Description

Screen fade in/out using INIDISP brightness control.

Demonstrates smooth screen fading by stepping through the 16 brightness levels of the SNES INIDISP register ($2100). Bits 0-3 of INIDISP control master brightness from 0 (black) to 15 (full), while bit 7 is the force blank flag. By writing successive brightness values with timed delays between frames, the display fades smoothly to or from black. Three fade speeds are showcased: fast (1 frame/step), medium (3 frames/step), and slow (6 frames/step). This technique is used in virtually every SNES game for scene transitions, title screens, and game-over sequences.

SNES Concepts
  • INIDISP register ($2100) brightness levels 0-15
  • Frame-counted delay loops for animation timing
  • setBrightness() library wrapper for safe INIDISP writes
  • Force blank (bit 7) vs brightness dimming (bits 0-3)
What to Observe
  • Press any button to advance through fade effects
  • Fast fade out (instant-feeling), then fast fade in
  • Medium fade (noticeable transition), then slow fade (cinematic pace)
  • The cycle repeats: fast, medium, slow, fast, ...
Modules Used
console, sprite, dma, input, background
See also
video.h, input.h, background.h

Function Documentation

◆ main()

int main ( void )

Entry point – cycles through fade-out/fade-in at three speeds.

Loads a background image, then enters an interactive loop where each button press triggers the next fade effect: fast (1 frame/step), medium (3 frames/step), and slow (6 frames/step). The cycle repeats indefinitely. This demonstrates how INIDISP brightness control provides smooth scene transitions without any per-pixel computation.

Returns
Does not return (infinite loop).

◆ wait_for_key()

void wait_for_key ( void )
static

Block until the user presses a button (with debounce).

First waits for all buttons to be released (if any are held), then waits for a new button press. This two-phase approach prevents the same press from being detected twice and ensures clean transition between fade steps. Each iteration calls WaitForVBlank() to yield CPU time and synchronize with the display refresh.

Variable Documentation

◆ palette

u8 palette[]
extern

15-bit BGR palette (up to 16 colors) for the background image.

◆ palette_end

u8 palette_end[]

◆ tilemap

u8 tilemap[]
extern

Tilemap data (32x32 tile grid) for the background image.

◆ tilemap_end

u8 tilemap_end[]

◆ tiles

u8 tiles[]
extern

4bpp tile data for the background image.

◆ tiles_end

u8 tiles_end[]