OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
DSP-1 Ground — the Super Mario Kart floor
Screenshot

mode7/perspective fakes a receding floor with a precomputed M7A/M7D table. This example asks the DSP-1 for the real thing: every frame the coprocessor's Raster command streams one Mode 7 matrix per scanline — A, B, C and D — for the camera you describe with dsp1SetCamera, and two HDMA channels replay them the next frame. Turn with the D-pad and the whole floor rotates in true perspective, because the rotation is inside the matrices the chip computed.

This is the technique Super Mario Kart and Pilotwings shipped with — the reason the DSP-1 was on the cartridge at all.

On that floor stand four beacons, and above them a cube (its eight corners) tumbles: the other half of the chip, the 3D pipeline. dsp1Attitude + dsp1Objective rotate the cube's corners, and dsp1Project, with the same camera, turns every world point into a screen position — so the objects stay on the ground as it turns and slides past.

How it works

  1. dsp1SetCamera(&cam) describes the camera and hands back four numbers: Vof (raster of the "imaginary centre"), Vva (horizon raster, relative to Vof), and Cx/Cy — the ground point under that centre, which goes straight to M7X/M7Y.
  2. dsp1Raster(ab, cd, Vva + 2, lines) streams the per-raster matrices for the ground below the horizon into two buffers laid out as HDMA_MODE_2REG_2X repeat payloads (M7A/M7B on one channel, M7C/M7D on the other). Raster Vva+1 is the singular horizon line, so the ground starts at Vva+2 on screen line 112 + Vof + Vva + 2.
  3. Two more HDMA channels do the F-Zero split above the horizon (BGMODE 3 + BG2 sky, then BGMODE 7 + BG1 ground) exactly like mode7/perspective.
  4. The tables are double-buffered: the DSP-1 fills the back set during active display (≈ 50 µs per raster, 126 rasters ≈ 40 % of the frame), and VBlank swaps them with hdmaSetTable and moves M7X/M7Y and the Mode 7 scroll so the ground under the imaginary centre stays pinned to the middle of the screen.

Moving forward uses the chip too: dsp1Triangle(heading, speed) gives the sin/cos step on the ground plane.

  1. The objects, after the ground in the same frame: for each point, dsp1Project(x, y, z) returns H and V relative to the screen centre — H to the right, V downward (measured on luna) — and M, the scale, positive in front of the eye and negative behind it. A point behind the eye, above the horizon (where the sky is drawn) or off screen is hidden; the others are 8x8 sprites at (128 + H, 112 + V). The TM HDMA keeps OBJ on in both halves of the screen.

Controls

Button Action
D-pad Left / Right Turn the camera (the floor rotates)
D-pad Up / Down Drive forward / backward along the heading

SNES Concepts

  • DSP-1 Raster: an open-ended command that streams until the CPU writes the $8000 sentinel in place of a D read (the lib does this for you)
  • Parameter outputs (Vof, Vva, Cx, Cy) as the whole screen geometry
  • HDMA 2REG_2X repeat blocks feeding two Mode 7 registers per channel
  • Double-buffered HDMA tables swapped in VBlank
  • Mid-frame BG mode switch (sky above, Mode 7 below)
  • dsp1Attitude / dsp1Objective / dsp1Project: rotating and projecting points with the camera that draws the ground; M's sign for points behind the eye

How to Build

make

The ROM needs a DSP-1 on the cartridge (USE_DSP1 := 1 sets the header) and luna needs Sony's dsp1b.rom firmware installed once (luna state --dsp1-rom <path> dsp1_ground.sfc); the luna test manifest is firmware-gated and skips cleanly in CI.

Modules Used

console, dma, background, input, mode7, hdma, sprite, dsp1 (auto-added by USE_DSP1)

Project Structure

File Purpose
main.c Camera, DSP-1 calls, HDMA tables, double buffering
res/ground.png.toml, res/sky.png.toml the import settings of the Mode 7 ground (mode = 7) and the Mode 3 sky (opensnes-tileset); the build converts and links them, res/*.inc declare the symbols
res/ground.png, res/sky.png the city from above and its towers over the horizon, shared with mode7/perspective; written by devtools/art_assets/mode7.py on one palette (the Mode 3 sky reads CGRAM 0-15, the ground's first sixteen colours), CC0, assets/neo-lumen/

Going Further

  • dsp1Target(h, v) is the inverse: which ground point is under a screen pixel — the missile scope of Pilotwings, a cursor on the track.
  • Change CAM_AZS (tilt) and watch Vof/Vva move the horizon; keep the ground under 127 rasters per repeat block, or call dsp1Raster twice for two blocks.
  • Size the sprites with M: a beacon that grows as you drive at it.