Mode 7 perspective with an HDMA split screen (F-Zero style). More...
#include <snes.h>#include <snes/mode7.h>#include <snes/hdma.h>#include "res/ground.inc"#include "res/sky.inc"Macros | |
| #define | SKYLINE 96 |
| The scanline where the sky ends and the ground begins. | |
Functions | |
| int | main (void) |
| Entry point – F-Zero-style Mode 7 perspective with an HDMA split screen. | |
| static void | setCamera (void) |
| Place the camera: Mode 7 scroll and center, and the sky's scroll. | |
Variables | |
| static const u8 | layer_table [] |
| TM (main screen layers) per line: OBJ + BG2 for the sky, OBJ + BG1 for the ground. | |
| static const u8 | mode_table [] |
| BGMODE per line: Mode 1 for the sky ($09: Mode 1 with the BG3 priority bit), Mode 7 for the ground. An entry writes once and holds. | |
| u16 | pad0 |
| static const u8 | perspective_x [] |
| M7A per ground line: 512 / zoom, the zoom growing by 0.025 a line (8.8 fixed point, low byte first; the first line is the horizon). | |
| static const u8 | perspective_y [] |
| M7D per ground line: 4096 / zoom, the zoom growing by 0.05 a line (8.8 fixed point, low byte first; the first line is the horizon). | |
| u16 | sx |
| u16 | sy |
Mode 7 perspective with an HDMA split screen (F-Zero style).
Creates an F-Zero-style pseudo-3D ground plane by combining two BG modes on one screen. HDMA changes registers between scanlines: the top 96 lines show a sky in Mode 1 (BG2), the lines below a Mode 7 ground whose scale changes on every line, so that distant rows are compressed. Four HDMA channels share the work: one writes BGMODE at the split line, one the main screen layers (BG2 for the sky, BG1 for the ground), and two write M7A and M7D on every ground line.
This is the first step: the two diagonal terms of the matrix give depth without rotation. mode7/perspective_rotate drives all four terms per line and turns the world.
Based on PVSnesLib's Mode7Perspective (mills32 / alekmaul); the city and its sky are ours (devtools/art_assets/mode7.py writes them).
| #define SKYLINE 96 |
The scanline where the sky ends and the ground begins.
| int main | ( | void | ) |
Entry point – F-Zero-style Mode 7 perspective with an HDMA split screen.
Loads the ground and the sky, sets up the four HDMA channels once, then scrolls the ground with the D-pad.
|
static |
Place the camera: Mode 7 scroll and center, and the sky's scroll.
mode7SetScroll() and mode7SetCenter() write the registers at once, so this runs in VBlank or force blank. The sky follows the ground horizontally (bgSetScroll, written by the NMI handler).
|
static |
TM (main screen layers) per line: OBJ + BG2 for the sky, OBJ + BG1 for the ground.
|
static |
BGMODE per line: Mode 1 for the sky ($09: Mode 1 with the BG3 priority bit), Mode 7 for the ground. An entry writes once and holds.
| u16 pad0 |
Current joypad button state
|
static |
M7A per ground line: 512 / zoom, the zoom growing by 0.025 a line (8.8 fixed point, low byte first; the first line is the horizon).
|
static |
M7D per ground line: 4096 / zoom, the zoom growing by 0.05 a line (8.8 fixed point, low byte first; the first line is the horizon).
| u16 sx |
Mode 7 ground horizontal scroll offset (camera X)
| u16 sy |
Mode 7 ground vertical scroll offset (camera Y)