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

Screen transitions: brightness fades and the mosaic filter. More...

#include <snes.h>
#include "vram_map.h"
#include "res/moonrise.inc"

Functions

int main (void)
 Entry point – cycles through the fades at three speeds, then the mosaic.
static void wait_for_key (void)

Variables

u16 fade_ticks
 4bpp tile data for the background image.

Detailed Description

Screen transitions: brightness fades and the mosaic filter.

The two transitions the PPU gives for free. A fade steps the master brightness of INIDISP ($2100) from 15 (full) to 0 (black) and back; the mosaic filter (MOSAIC, $2106) fills N x N blocks of a background with the colour of their top-left pixel, from 1 x 1 up to 16 x 16. Three fade speeds are shown, then the mosaic growing and shrinking back. Neither costs CPU time beyond one register write per step.

SNES Concepts
What to Observe
  • Press any button to advance to the next transition
  • Fast fade out and in (1 frame per step), then 3 frames per step, then 6 (the 6-frame fades do not hold the program: the loop counts its frames in fade_ticks while they run)
  • Then the mosaic: the picture breaks into growing blocks, then sharpens again
  • The cycle repeats
Modules Used
console, sprite, dma, input, background, mosaic
See also
video.h, mosaic.h, input.h, background.h

Function Documentation

◆ main()

int main ( void )

Entry point – cycles through the fades at three speeds, then the mosaic.

Loads a background image, then enters an interactive loop where each button press triggers the next transition: fade out and in at 1, 3 and 6 frames per step, then the mosaic growing to 16 x 16 blocks and shrinking back. The cycle repeats indefinitely.

Returns
Does not return (infinite loop).

◆ wait_for_key()

void wait_for_key ( void )
static

Variable Documentation

◆ fade_ticks

u16 fade_ticks

4bpp tile data for the background image.

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

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

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.

Frames the main loop ran during the non-blocking fades (96 a fade at 6 frames per step).