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

DSP-1 pseudo-3D: a cube tumbling in 3D, rotated by the coprocessor. More...

#include <snes.h>
#include <snes/dsp1.h>

Functions

int main (void)

Variables

static const s16 cube [8][3]
static const u8 dot_pal [4] = { 0x00, 0x00, 0xFF, 0x7F }
static const u8 dot_tile [32]

Detailed Description

DSP-1 pseudo-3D: a cube tumbling in 3D, rotated by the coprocessor.

Each frame the DSP-1 builds a rotation matrix (dsp1Attitude) and transforms the cube's 8 corners through it (dsp1Objective). The corners are drawn as 8 sprites at their orthographically-projected positions, so the cube visibly tumbles in 3D — all the 3D math runs on the NEC uPD77C25, not the 65816.

SNES Concepts
  • DSP-1 coprocessor command interface (matrix + vector transform)
  • Fixed-point 3D rotation offloaded from the CPU
  • Orthographic projection (x',y' straight to screen)
What to Observe
  • A cube of 8 dots rotating smoothly about two axes
Modules Used
console, dma, sprite, dsp1
Warning
Needs the DSP-1 firmware in luna (dsp1b.rom) — see the README.
See also
snes/dsp1.h, .claude/notes/tech/dsp1_reference.md

Function Documentation

◆ main()

int main ( void )

Variable Documentation

◆ cube

const s16 cube[8][3]
static
Initial value:
= {
{-80,-80,-80}, { 80,-80,-80}, { 80, 80,-80}, {-80, 80,-80},
{-80,-80, 80}, { 80,-80, 80}, { 80, 80, 80}, {-80, 80, 80},
}

The cube's 8 corners in model space (DSP-1 integer coordinates).

◆ dot_pal

const u8 dot_pal[4] = { 0x00, 0x00, 0xFF, 0x7F }
static

Two colours: index 0 transparent, index 1 white ($7FFF).

◆ dot_tile

const u8 dot_tile[32]
static
Initial value:
= {
0xFF,0x00, 0xFF,0x00, 0xFF,0x00, 0xFF,0x00,
0xFF,0x00, 0xFF,0x00, 0xFF,0x00, 0xFF,0x00,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0
}

8x8 4bpp tile, colour index 1 everywhere. In the SNES 4bpp layout planes 0/1 interleave per row, so plane 0 all-set is the ODD bytes 0,2,…,14.