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

Colour, rung 6c.2 — shadow & tint: recolour a whole scene at once. More...

#include <snes.h>
#include <snes/colormath.h>
#include <snes/input.h>

Functions

static void apply_effect (void)
 Apply the effect for the current fx_state (call after VBlank).
static void build_scene_palette (void)
 Fill scene_pal[] with a believable slice of a game world.
static void build_solid_tile (u8 v)
 Fill tilebuf with a solid 4bpp tile of palette index v.
int main (void)

Variables

u8 fx_state
 Probe oracle: current effect (0 none, 1 shadow, 2 underwater, 3 sunset).
static u16 rowbuf [32]
 One tilemap row (32 entries).
static u16 scene_pal [16]
 16 game-world colours, filled at init (RAM — no ROM const)
static u8 tilebuf [32]
 One solid 4bpp tile (two interleaved bitplane pairs, 32 bytes).

Detailed Description

Colour, rung 6c.2 — 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 4x4 chart of sixteen game-world colours (sky, water, foliage, earth, stone, accents) built procedurally — zero assets — so you can watch the effect land on every hue at once. Press A to cycle:

none -> shadow (darken) -> underwater tint -> sunset 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 colour chart. Press A to darken it (shadow), then wash it blue (underwater), then warm it (sunset), then back to plain. Every swatch shifts together. fx_state is the probe oracle (0..3).
Modules Used
console, dma, background, colormath, input
See also
lib/include/snes/colormath.hcolorMathShadow(), colorMathTint()

Function Documentation

◆ apply_effect()

void apply_effect ( void )
static

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

◆ build_scene_palette()

void build_scene_palette ( void )
static

Fill scene_pal[] with a believable slice of a game world.

Four rows of four: sky/water, foliage, earth/stone, accents. Vivid enough that both a darken and a colour cast read clearly on every one.

◆ build_solid_tile()

void build_solid_tile ( u8 v)
static

Fill tilebuf with a solid 4bpp tile of palette index v.

4bpp planar: rows 0-7 store bitplane pair (0,1) as 16 bytes, then pair (2,3). Each plane byte is $FF or $00 per the matching bit of v.

◆ main()

int main ( void )

Variable Documentation

◆ fx_state

u8 fx_state

Probe oracle: current effect (0 none, 1 shadow, 2 underwater, 3 sunset).

◆ rowbuf

u16 rowbuf[32]
static

One tilemap row (32 entries).

◆ scene_pal

u16 scene_pal[16]
static

16 game-world colours, filled at init (RAM — no ROM const)

◆ tilebuf

u8 tilebuf[32]
static

One solid 4bpp tile (two interleaved bitplane pairs, 32 bytes).