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

Rotating Mode 7 perspective — full matrix driven by 4 HDMA channels. More...

#include <snes.h>

Macros

#define ANGLES   48u
 48 rotation steps of 7.5 degrees
#define TABLE_STRIDE   673u
 One angle table: 224 x 3-byte HDMA entries + terminator.

Functions

int main (void)
static void repointTables (void)
 Point all four matrix channels at the current angle's tables.

Variables

static u16 angle
 Rotation step index, 0..47.
u8 ground_mp7 []
u8 ground_mp7_end []
u8 ground_pal []
u8 ground_pal_end []
u8 ground_pc7 []
 Mode 7 ground: 9-tile prefab track (original art).
u8 ground_pc7_end []
u8 m7cos []
 krom's tables, verbatim: 48 x [1][val16]x224 + terminator
u8 m7nsin []
u8 m7sin []
static u16 pos_x
 Mode 7 pivot shadows (krom init: 512, 1152).
static u16 pos_y
static u16 scr_x
 BG1 scroll shadows (krom init: 384, 768).
static u16 scr_y

Detailed Description

Rotating Mode 7 perspective — full matrix driven by 4 HDMA channels.

Port of krom (Peter Lemon)'s Mode7 Perspective demo (PeterLemon/SNES, PPU/Mode7/Perspective). Four HDMA channels each feed one Mode 7 matrix register per scanline (M7A/M7B/M7C/M7D from cos, sin, -sin, cos tables), so the ground plane is BOTH perspective-projected (each line scaled by 20480/y) AND rotated (48 angle steps) — the full affine matrix per line, where graphics/backgrounds/mode7_perspective drives only the two diagonal terms (no rotation).

Rotating means the whole matrix changes per angle: the demo precomputes 48 tables per trig function (krom's exact tables, extracted verbatim; entry(a,y) = trig(2*PI*a/48) * 20480 / y in 8.8 fixed point) and repoints all four HDMA channels each frame.

SNES Concepts
  • Per-scanline Mode 7 matrix writes (perspective + rotation combined)
  • 4-channel HDMA coordination on one register family
  • HDMA table repointing as a zero-copy animation primitive
  • Mode 7 interleaved VRAM (dmaCopyVramMode7)
What to Observe
A kart-style track receding to the horizon. D-pad moves over the plane, L/R rotate the world in 7.5-degree steps, Y/A nudge the pivot on X, X/B nudge it on Y (krom's control map).
Modules Used
console, dma, background, hdma, input, mode7
See also
https://github.com/PeterLemon/SNES — original demo & tables
devtools/m7ptables.py — table extraction + math verification

Macro Definition Documentation

◆ ANGLES

#define ANGLES   48u

48 rotation steps of 7.5 degrees

◆ TABLE_STRIDE

#define TABLE_STRIDE   673u

One angle table: 224 x 3-byte HDMA entries + terminator.

Function Documentation

◆ main()

int main ( void )

◆ repointTables()

void repointTables ( void )
static

Point all four matrix channels at the current angle's tables.

cos feeds both diagonal terms (M7A, M7D), sin/-sin the off-diagonal pair (M7B, M7C) — a standard rotation matrix, perspective-scaled per line inside the tables themselves. hdmaSetup() re-arms the channel and reads the bank from the far pointer, so repointing is just four calls.

Variable Documentation

◆ angle

u16 angle
static

Rotation step index, 0..47.

◆ ground_mp7

u8 ground_mp7[]
extern

◆ ground_mp7_end

u8 ground_mp7_end[]

◆ ground_pal

u8 ground_pal[]
extern

◆ ground_pal_end

u8 ground_pal_end[]

◆ ground_pc7

u8 ground_pc7[]
extern

Mode 7 ground: 9-tile prefab track (original art).

◆ ground_pc7_end

u8 ground_pc7_end[]

◆ m7cos

u8 m7cos[]
extern

krom's tables, verbatim: 48 x [1][val16]x224 + terminator

◆ m7nsin

u8 m7nsin[]

◆ m7sin

u8 m7sin[]

◆ pos_x

u16 pos_x
static

Mode 7 pivot shadows (krom init: 512, 1152).

◆ pos_y

u16 pos_y
static

◆ scr_x

u16 scr_x
static

BG1 scroll shadows (krom init: 384, 768).

◆ scr_y

u16 scr_y
static