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

Colour — shadow & tint: recolour a whole scene at once. More...

#include <snes.h>
#include <snes/colormath.h>
#include <snes/input.h>
#include "res/street.inc"

Functions

static void apply_effect (void)
 Apply the effect for the current fx_state (call after VBlank).
int main (void)

Variables

u8 fx_state
 Probe oracle: current effect (0 none, 1 blackout, 2 green rain, 3 red alert).

Detailed Description

Colour — shadow & tint: recolour a whole scene at once.

Colour math against a fixed colour is how a game changes mood without touching a single tile or palette entry. Subtract a grey and the scene darkens — dusk, a dungeon, nightfall. Add a colour and the scene takes that cast — the blue of being underwater, the orange of a sunset or lava glow, the red flash of taking a hit. One register pair does it to every pixel of a layer, every frame, for free.

The scene here is a street of the city at night — apartment blocks and a noodle sign (res/street.png) — so you can watch the effect land on a picture. Press A to cycle:

none -> blackout (darken) -> green rain (tint) -> red alert (tint) -> none

ROM mode: LoROM (project default).

SNES Concepts
  • Colour math with the FIXED-colour source (COLDATA $2132): result is main-screen ± a constant, applied per enabled layer
  • colorMathShadow() = subtract grey (darken); colorMathTint() = add a colour (cast) — the two share the fixed-colour register and the add/subtract bit, so only one is active at a time
  • The effect is a PPU pass over the final image: no VRAM, CGRAM or OAM traffic, so it costs nothing per frame and scales to the whole screen
What to Observe
Boot: the plain street. Press A to darken it (a blackout), then wash it green (a toxic rain), then red (the alarm), then back to plain. Every pixel shifts together. fx_state is the probe oracle (0..3).
Modules Used
console, dma, background, colormath, input
See also
lib/include/snes/colormath.h — colorMathShadow(), colorMathTint()

Function Documentation

◆ apply_effect()

void apply_effect ( void )
static

Apply the effect for the current fx_state (call after VBlank).

◆ main()

int main ( void )

Variable Documentation

◆ fx_state

u8 fx_state

Probe oracle: current effect (0 none, 1 blackout, 2 green rain, 3 red alert).