DSP-1 ground: the Super Mario Kart floor — per-scanline Mode 7 matrices streamed by the coprocessor's Raster command. More...
Macros | |
| #define | CAM_AZS (0x4000 - 655) |
| Zenith angle of the view line: 0x4000 is horizontal (horizon at the screen centre); 0x4000 - 655 tilts down 3.6 degrees so the horizon lands 16 lines above centre (line 96) and the ground below fits one 126-line HDMA repeat block. | |
| #define | CAM_HEIGHT 80 |
| Camera height above the ground plane (DSP-1 integer units). Lower = more dramatic near-row magnification; SMK sits low like this. | |
| #define | CAM_LES 256 |
| Viewpoint → screen distance: 256 gives the 50-degree horizontal FOV of a 256-pixel screen, and it is the vertical focal length that turns the tilt into a horizon raster (Vva = -256*tan(tilt)). | |
| #define | CAM_LFE 96 |
| Base point → viewpoint distance; the viewer sits this far behind the camera point along the view line. | |
| #define | CH_AB HDMA_CHANNEL_3 |
| #define | CH_CD HDMA_CHANNEL_4 |
| #define | CH_MODE HDMA_CHANNEL_1 |
| HDMA channels: BGMODE switch, TM switch, M7A/M7B, M7C/M7D. 1-4 like mode7/perspective (0 is the general-DMA channel, 7 the NMI handler's). | |
| #define | CH_TM HDMA_CHANNEL_2 |
| #define | CUBE_HALF 20 |
| #define | CUBE_X 512 |
| The cube: world position of its centre and its half-size. | |
| #define | CUBE_Y 352 |
| #define | CUBE_Z 40 |
| #define | GROUND_MAX 127 |
| Largest HDMA repeat block (7-bit count). The ground uses one. | |
| #define | MOVE_STEP 4 |
| Forward speed in ground units per frame. | |
| #define | NUM_BEACONS 4 |
| Sprites: 8 cube corners (0-7), then the beacons (8-11). | |
| #define | OBJ_VRAM 0x6000 |
| VRAM word address of the sprite tile (the Mode 7 ground takes $0000-$3FFF, the sky $4000-$5FFF). | |
| #define | TABLE_HDR 6 |
| Payload offset in a matrix table: [sky count][4 sky bytes][repeat header]. | |
| #define | TABLE_SIZE (TABLE_HDR + GROUND_MAX * 4 + 1) |
| One matrix table: sky entry, repeat block of GROUND_MAX rasters, terminator. | |
| #define | TURN_STEP 0x0100 |
| Heading change per frame while turning (16-bit angle, 2^16 = 360). | |
Functions | |
| static void | cameraUpdate (void) |
| Re-run the projection for the current camera and cache what the rest of the frame needs (horizon raster, ground centre). | |
| int | main (void) |
| static void | placeObjects (void) |
| Project the cube's corners and the beacons with the current camera. | |
| static void | placePoint (u8 id, s16 x, s16 y, s16 z, u8 pal) |
Place sprite id at world point (x, y, z), or hide it. | |
| static void | tableInit (u8 FAR *t, u8 sky, u8 lines, u16 diag) |
| Build one matrix table skeleton: a sky entry holding the identity matrix, then the repeat-block header the DSP-1 payload sits under. | |
Variables | |
| static u8 | back |
| Table set being filled this frame (the other one is on screen). | |
| static const s16 | beacon [4][2] |
| The beacons: four points on the ground around the cube. | |
| static Dsp1Camera | cam |
| The camera: position on the ground plane (x, y wrap with the 1024-unit texture), height, lens, heading (aas: 0 looks up the map, -Y; 0x4000 looks to +X) and tilt. The luna manifest reads x, y and aas. | |
| static const s16 | cube [8][3] |
| The cube's corners around its centre (model space). | |
| static u16 | cube_ay |
| static u16 | cube_az |
| The cube's two rotation angles (16-bit, 2^16 = 360 degrees). | |
| static s16 | cx |
| Ground point under the imaginary centre (last dsp1SetCamera). | |
| static s16 | cy |
| static const u8 | dot_pal [64] |
| OBJ palettes 0 and 1: colour 1 = neon cyan (the cube), then magenta (the beacons). The ground uses CGRAM 0-15 only, so 128 and up are free. | |
| static const u8 | dot_tile [32] |
| 8x8 4bpp tile, colour 1 everywhere (planes 0/1 interleave per row: plane 0 = even bytes). | |
| volatile u16 | dsp1_ok = 0 |
| 1 when the DSP-1 answered the known-answer probe (luna manifest asserts it). | |
| static u8 | ground_lines |
| volatile u16 | raster_lines = 0 |
| Rasters streamed in the last dsp1Raster call (luna manifest asserts it). | |
| u16 | shown |
| Sprites on screen after the last placement pass (luna manifest asserts it). | |
| static u8 | sky_lines |
| Screen line of the first ground raster and the block length. | |
| static FAR u8 | tab_ab [2][(6+127 *4+1)] |
| Double-buffered M7A/M7B tables: HDMA reads one while the DSP-1 fills the other. | |
| static FAR u8 | tab_cd [2][(6+127 *4+1)] |
| Double-buffered M7C/M7D tables. | |
| static u8 | tab_mode [5] |
| BGMODE table: Mode 3 for the sky lines, then Mode 7 for the rest. | |
| static u8 | tab_tm [5] |
| TM table: BG2 (sky) for the sky lines, then BG1 (ground). | |
| static s16 | vof |
| Geometry from the last dsp1SetCamera: imaginary-centre raster, horizon raster. | |
| static s16 | vva |
DSP-1 ground: the Super Mario Kart floor — per-scanline Mode 7 matrices streamed by the coprocessor's Raster command.
mode7/perspective fakes a receding floor with a precomputed M7A/M7D table; this example asks the DSP-1 for the real thing. Each frame the CPU sends the camera (position, height, heading, tilt) with dsp1SetCamera, then dsp1Raster streams one 2x2 matrix per screen line — A, B, C and D, so the floor rotates with the heading for free — straight into two HDMA payloads. The HDMA channels replay them next frame while the CPU already computes the frame after (double buffering). Above the horizon the same HDMA split as mode7/perspective shows a Mode 3 sky.
The three numbers dsp1SetCamera hands back beside the matrices are the whole geometry: Vva says on which raster the horizon sits, Cx/Cy say which ground point is under the screen centre (they go to M7X/M7Y), and the Mode 7 scroll registers just pin that centre to the middle of the screen.
Objects in that world are the other half of the chip: four beacons stand on the esplanade and a wireframe cube (its eight corners) tumbles above it. dsp1Attitude + dsp1Objective rotate the cube's corners, and dsp1Project, with the same camera, turns every world point into a screen position — so the sprites stay glued to the ground as it turns and slides past. (The cube was the chips/dsp1_cube example.)
| #define CAM_AZS (0x4000 - 655) |
Zenith angle of the view line: 0x4000 is horizontal (horizon at the screen centre); 0x4000 - 655 tilts down 3.6 degrees so the horizon lands 16 lines above centre (line 96) and the ground below fits one 126-line HDMA repeat block.
| #define CAM_HEIGHT 80 |
Camera height above the ground plane (DSP-1 integer units). Lower = more dramatic near-row magnification; SMK sits low like this.
| #define CAM_LES 256 |
Viewpoint → screen distance: 256 gives the 50-degree horizontal FOV of a 256-pixel screen, and it is the vertical focal length that turns the tilt into a horizon raster (Vva = -256*tan(tilt)).
| #define CAM_LFE 96 |
Base point → viewpoint distance; the viewer sits this far behind the camera point along the view line.
| #define CH_AB HDMA_CHANNEL_3 |
| #define CH_CD HDMA_CHANNEL_4 |
| #define CH_MODE HDMA_CHANNEL_1 |
HDMA channels: BGMODE switch, TM switch, M7A/M7B, M7C/M7D. 1-4 like mode7/perspective (0 is the general-DMA channel, 7 the NMI handler's).
| #define CH_TM HDMA_CHANNEL_2 |
| #define CUBE_HALF 20 |
| #define CUBE_X 512 |
The cube: world position of its centre and its half-size.
| #define CUBE_Y 352 |
| #define CUBE_Z 40 |
| #define GROUND_MAX 127 |
Largest HDMA repeat block (7-bit count). The ground uses one.
| #define MOVE_STEP 4 |
Forward speed in ground units per frame.
| #define NUM_BEACONS 4 |
Sprites: 8 cube corners (0-7), then the beacons (8-11).
| #define OBJ_VRAM 0x6000 |
VRAM word address of the sprite tile (the Mode 7 ground takes $0000-$3FFF, the sky $4000-$5FFF).
| #define TABLE_HDR 6 |
Payload offset in a matrix table: [sky count][4 sky bytes][repeat header].
| #define TABLE_SIZE (TABLE_HDR + GROUND_MAX * 4 + 1) |
One matrix table: sky entry, repeat block of GROUND_MAX rasters, terminator.
| #define TURN_STEP 0x0100 |
Heading change per frame while turning (16-bit angle, 2^16 = 360).
|
static |
Re-run the projection for the current camera and cache what the rest of the frame needs (horizon raster, ground centre).
| int main | ( | void | ) |
|
static |
Project the cube's corners and the beacons with the current camera.
Place sprite id at world point (x, y, z), or hide it.
dsp1Project gives H and V relative to the screen centre, H to the right and V downward, and M, the scale (here only its sign: a point behind the eye comes back with M <= 0). A point that lands above the horizon line, where the sky is drawn, or off screen, is hidden.
Build one matrix table skeleton: a sky entry holding the identity matrix, then the repeat-block header the DSP-1 payload sits under.
| t | table to initialise |
| sky | scanlines above the ground (non-repeat entry, written once) |
| lines | ground rasters (repeat entry: 4 bytes written every line) |
| diag | value of the diagonal term in the sky entry (A or D) |
|
static |
Table set being filled this frame (the other one is on screen).
|
static |
The beacons: four points on the ground around the cube.
|
static |
The camera: position on the ground plane (x, y wrap with the 1024-unit texture), height, lens, heading (aas: 0 looks up the map, -Y; 0x4000 looks to +X) and tilt. The luna manifest reads x, y and aas.
|
static |
The cube's corners around its centre (model space).
|
static |
|
static |
The cube's two rotation angles (16-bit, 2^16 = 360 degrees).
|
static |
Ground point under the imaginary centre (last dsp1SetCamera).
|
static |
|
static |
OBJ palettes 0 and 1: colour 1 = neon cyan (the cube), then magenta (the beacons). The ground uses CGRAM 0-15 only, so 128 and up are free.
|
static |
8x8 4bpp tile, colour 1 everywhere (planes 0/1 interleave per row: plane 0 = even bytes).
| volatile u16 dsp1_ok = 0 |
1 when the DSP-1 answered the known-answer probe (luna manifest asserts it).
|
static |
| volatile u16 raster_lines = 0 |
Rasters streamed in the last dsp1Raster call (luna manifest asserts it).
| u16 shown |
Sprites on screen after the last placement pass (luna manifest asserts it).
|
static |
Screen line of the first ground raster and the block length.
Double-buffered M7A/M7B tables: HDMA reads one while the DSP-1 fills the other.
|
static |
BGMODE table: Mode 3 for the sky lines, then Mode 7 for the rest.
|
static |
TM table: BG2 (sky) for the sky lines, then BG1 (ground).
|
static |
Geometry from the last dsp1SetCamera: imaginary-centre raster, horizon raster.
|
static |