Reaction-Diffusion

Cellular Automata

Gray-Scott reaction-diffusion running live on a Super Nintendo. Two chemical species — activator U and inhibitor V — evolve on a 32×28 toroidal grid via the equation ∂U/∂t = DU∇²U − UV² + F(1−U), seeded from a 2×2 spot. Turing instability spontaneously grows organic worm and coral patterns. Written in C and compiled with the llvm-mos-based 65816 toolchain (+mos-a16, 16-bit accumulator). Runs automatically.

loading core…

Self-running demo — patterns grow automatically from a 2×2 seed.

Click the screen to focus, then watch. Tab away and it pauses.

What it is

The Gray-Scott model (1984) is a pair of reaction-diffusion PDEs that replicate biological pattern formation. Two chemical species compete on a grid:

∂U/∂t = DU·∇²U − U·V² + F·(1 − U)
∂V/∂t = DV·∇²V + U·V² − (F+k)·V

U is the activator (fast diffuser), V is the inhibitor (slow diffuser). The nonlinear U·V² term creates Turing instability: a uniform field is unstable, so tiny fluctuations amplify into spots, stripes, worms, or coral depending on the feed (F) and kill (k) rates. This demo uses F=14, k=16 — a "worm" regime — seeded from a 2×2 central block of V=128 on a background of U=255.

Fixed-point arithmetic on 8-bit hardware

All values are scaled by 256 (S ≡ 1.0) and stored as uint8_t with 16-bit intermediates. Each cell per step requires three 32-bit multiplications (__mulsi3): U×V for the reaction product, then UV×V for the cubic term, then DU×Laplacian for diffusion. The hot path runs 64 cells × 2 steps per frame = 128 × 3 = 384 32-bit multiplies per frame.

Compiler stress-test

ItemWhat it exercises
ActivatorU (activator) diffuses fast (DU=102), grows where both U and V are present
InhibitorV (inhibitor) diffuses slowly (DV=10), suppresses U via the U×V² reaction term
ParametersFeed F=14, kill K=16 — a "worm/coral" morphology region of the Gray-Scott parameter space
Compiler stress3 × __mulsi3 per grid cell per step (U×V, UV×V, DU×Laplacian); rep/sep mode-switch brackets mark 16-bit sections

A separate 8×8 gate grid runs 8 steps and folds V into a rotating-XOR CRC. The gate asserts corpus_result (0x8484) is identical on host, default 8-bit SNES, +mos-a16, and +mos-xy16 — five-way differential. The Verify fidelity button above reproduces that gate live in this tab via the same cycle-accurate bsnes-jg core used in CI.

Written in C with the llvm-mos 65816 toolchain and verified against two emulators (MAME + bsnes-jg). Hit Verify fidelity to reproduce the build gate's WRAM assert (corpus_result = 0x8484) live in this tab. No far pointers — same binary checked five ways: host == default == +mos-a16 == +mos-xy16 == bsnes-jg.