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

Mosaic and fade screen transition effects. More...

#include <snes.h>

Functions

void doFadeIn (void)
 Fade the screen from black to full brightness over ~32 frames.
 
void doFadeOut (void)
 Fade the screen from full brightness to black over ~30 frames.
 
void doMosaicIn (void)
 Animate the mosaic filter shrinking back to normal, then disable it.
 
void doMosaicOut (void)
 Activate the hardware mosaic filter and animate pixel blocks growing.
 
int main (void)
 Entry point: set up a background and cycle through transition effects.
 
void WaitForKey (void)
 Block until a button is pressed, debouncing any currently held buttons.
 

Variables

u8 palette []
 16-color palette for the background tiles
 
u8 palette_end []
 
u8 tilemap []
 Background tilemap data mapping tiles to the 32x32 grid.
 
u8 tilemap_end []
 
u8 tiles []
 4bpp background tile data (defined in data.asm, stored in ROM)
 
u8 tiles_end []
 

Detailed Description

Mosaic and fade screen transition effects.

Demonstrates two SNES screen transition techniques: brightness fading and the hardware mosaic filter. Brightness fading uses register $2100 (INIDISP) to ramp the master brightness from 0 (black) to 15 (full) over multiple frames. The mosaic effect uses register $2106 (MOSAIC) to progressively enlarge the pixel blocks on selected BG layers, creating a pixelation effect commonly used in RPG battle transitions.

SNES Concepts
What to Observe
  • Press any button to cycle through 4 effects: fade out, fade in, mosaic out (pixels enlarge), mosaic in (pixels shrink back)
  • The cycle repeats indefinitely
Modules Used
console, dma, background, sprite, input, mosaic
See also
video.h, mosaic.h, background.h

Function Documentation

◆ doFadeIn()

void doFadeIn ( void  )

Fade the screen from black to full brightness over ~32 frames.

Increments INIDISP brightness from 0 to 15. Two WaitForVBlank() calls per step create a 2-frame hold at each level, matching doFadeOut() timing for a symmetrical fade cycle.

◆ doFadeOut()

void doFadeOut ( void  )

Fade the screen from full brightness to black over ~30 frames.

Decrements the SNES master brightness register (INIDISP, $2100) from 15 (full) to 0 (black). Each brightness step lasts 2 frames (~33ms), producing a smooth ~500ms fade-out. The PPU multiplies all pixel colors by (brightness / 15), so brightness 0 = completely black.

◆ doMosaicIn()

void doMosaicIn ( void  )

Animate the mosaic filter shrinking back to normal, then disable it.

mosaicFadeIn() decreases the mosaic block size from 16 back to 1, restoring the original image. mosaicDisable() then clears the mosaic register so the PPU no longer applies the filter, saving a tiny bit of processing.

◆ doMosaicOut()

void doMosaicOut ( void  )

Activate the hardware mosaic filter and animate pixel blocks growing.

The SNES mosaic register ($2106) groups NxN pixel blocks and fills each block with the color of its top-left pixel. mosaicFadeOut() increases N from 1 to 16 over time, making the image progressively more pixelated. The speed parameter (3) controls how many frames each mosaic level is held.

This effect is commonly used in RPG battle transitions (e.g., Final Fantasy).

◆ main()

int main ( void  )

Entry point: set up a background and cycle through transition effects.

Initializes Mode 1 with a single 4bpp background layer, then enters an infinite loop cycling through four effects on each button press: fade out -> fade in -> mosaic out -> mosaic in.

Returns
Never returns (infinite loop).

◆ WaitForKey()

void WaitForKey ( void  )

Block until a button is pressed, debouncing any currently held buttons.

First waits for all buttons to be released (debounce), then waits for any new button press. Each iteration calls WaitForVBlank() to yield to the NMI handler so the system stays synchronized to the 60Hz refresh rate.

Variable Documentation

◆ palette

u8 palette[]
extern

16-color palette for the background tiles

◆ palette_end

u8 palette_end[]

◆ tilemap

u8 tilemap[]
extern

Background tilemap data mapping tiles to the 32x32 grid.

◆ tilemap_end

u8 tilemap_end[]

◆ tiles

u8 tiles[]
extern

4bpp background tile data (defined in data.asm, stored in ROM)

◆ tiles_end

u8 tiles_end[]