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

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

#include <snes.h>

Functions

static void fade_in (u8 speed)
 Fade the screen from black to full brightness.
 
static void fade_out (u8 speed)
 Fade the screen from full brightness to black.
 
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

◆ fade_in()

static void fade_in ( u8  speed)
static

Fade the screen from black to full brightness.

Steps the INIDISP register ($2100) brightness field from 0 (black) up to 15 (full). Symmetric counterpart to fade_out().

Parameters
speedNumber of VBlank frames to wait between each brightness step. 1 = fastest, 6 = slowest.
See also
fade_out() for timing details.

◆ fade_out()

static void fade_out ( u8  speed)
static

Fade the screen from full brightness to black.

Steps the INIDISP register ($2100) brightness field from 15 (full) down to 0 (black). The speed parameter controls how many VBlank frames to wait between each brightness step – higher values produce slower fades.

At 60 fps (NTSC):

  • speed=1: 16 frames = ~0.27 seconds (fast/snappy)
  • speed=3: 48 frames = ~0.80 seconds (cinematic)
  • speed=6: 96 frames = ~1.60 seconds (dramatic)
Parameters
speedNumber of VBlank frames to wait between each brightness step. 1 = fastest (1 frame/step), 6 = slowest (6 frames/step).

◆ 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()

static 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[]