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

SA-1 Murmuration Demo — 128 neon moths in Lissajous sine patterns. More...

#include <snes.h>
#include <snes/sa1.h>
#include "res/mote.inc"
#include "res/skyline.inc"

Macros

#define NBIRDS   128
#define SA1_STAR_BUF   ((volatile u8*)0x3010)
#define SA1_SYNC   (*(volatile u8*)0x3001)

Functions

int main (void)

Variables

static const u16 pal []

Detailed Description

SA-1 Murmuration Demo — 128 neon moths in Lissajous sine patterns.

The SA-1 computes 128 positions using overlapping Lissajous sine patterns at 10.74 MHz. The main CPU reads them from I-RAM and displays them as a cloud of neon moths over the city's far skyline in the rain.

Each bird's position is the sum of two sine harmonics per axis, with prime-number phase multipliers creating organic flock spread: X = sin[bird*3 + frame]/2 + sin[bird*7 + frame*2]/4 + 32 Y = sin[bird*5 + frame+64]/2 + sin[bird*11 + frame*3]/4 + 16

SNES Concepts
  • The SA-1 computes while the main CPU displays: positions written to shared I-RAM, read by the 65816 each frame
  • A sync byte in I-RAM as the handshake between the two CPUs
  • One tiny sprite (a 4x3 moth in an 8x8 tile) for all 128: the cloud bunches up, and a line shows at most 32 sprites
  • oamMemory[] written directly, the escape hatch beside oamSet(): 128 positions copied from I-RAM each frame in one loop
What to Observe
  • 128 moths moving in smooth, coordinated flock-like patterns over the skyline
  • The pattern resembles a murmuration (starling flock)
  • All math computed by SA-1 coprocessor at 10.74 MHz
Modules Used
console, sprite, dma, background, input, sa1

Macro Definition Documentation

◆ NBIRDS

#define NBIRDS   128

◆ SA1_STAR_BUF

#define SA1_STAR_BUF   ((volatile u8*)0x3010)

◆ SA1_SYNC

#define SA1_SYNC   (*(volatile u8*)0x3001)

Function Documentation

◆ main()

int main ( void )

Variable Documentation

◆ pal

const u16 pal[]
static
Initial value:
= {
0x0000, RGB(14, 28, 30), RGB(29, 31, 31), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0x0000, RGB(10, 22, 26), RGB(22, 28, 30), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0x0000, RGB( 7, 16, 20), RGB(16, 22, 26), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0x0000, RGB( 5, 11, 15), RGB(10, 16, 20), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}
#define RGB(r, g, b)
Create RGB color value.
Definition video.h:92

Sprite palettes: 4 brightness levels for depth illusion — the wings (1) in a cyan that dims with distance, the body (2) a touch brighter