Mode 7 rotation and scaling, flown over: a glider, its shadow and the altitude. More...
Macros | |
| #define | GLIDER_X 112 |
| Mode 7 tile pixel data (256 tiles x 64 bytes, 8bpp), converted by the build from res/. | |
| #define | GLIDER_Y 96 |
Functions | |
| int | main (void) |
| Entry point – interactive Mode 7 rotation and scaling demo. | |
| static void | place_shadow (u16 zscale) |
| Draw the shadow below the glider, further away the higher it flies. | |
Variables | |
| u16 | shadow_dy |
| Probe oracle: the shadow's offset below the glider, in pixels. | |
Mode 7 rotation and scaling, flown over: a glider, its shadow and the altitude.
Demonstrates SNES Mode 7, the hardware affine transformation mode that applies a 2x2 matrix (rotation + scaling) to a single 128x128 tile background layer. Mode 7 uses a unique interleaved VRAM format where tilemap bytes occupy the low bytes and 8bpp tile pixel data occupies the high bytes of each VRAM word. The transformation matrix is controlled via registers M7A-M7D, with the library's mode7SetAngle() and mode7SetScale() computing the sin/cos matrix entries from an 8-bit angle and 8.8 fixed-point scale factors.
A glider flies over the plane at the rotation centre, and the zoom is its altitude: zooming out widens the view as if it climbed, and its shadow — the same sprite in a dark palette, behind it — slides further away. The two together are how a flat Mode 7 plane reads as height. (The glider and its shadow were the games/mode7_flying example.)
| #define GLIDER_X 112 |
Mode 7 tile pixel data (256 tiles x 64 bytes, 8bpp), converted by the build from res/.
Mode 7 tilemap (128x128 tile indices, one byte each), converted by the build from res/
256-colour palette for the Mode 7 plane (512 bytes), converted by the build from res/
Kit's glider seen from above, 32x32, converted by the build from res/glider.png
Where the glider is drawn: its 32x32 box centred on screen (128, 112).
| #define GLIDER_Y 96 |
| int main | ( | void | ) |
Entry point – interactive Mode 7 rotation and scaling demo.
Initializes the Mode 7 plane with an image, then allows the user to rotate (A/B buttons) and zoom (D-pad UP/DOWN) in real time. The transformation matrix is updated each frame via mode7SetAngle() and mode7SetScale(), which compute sin/cos values and write to the M7A-M7D hardware registers.
< Current joypad button state
< Rotation angle (0-255 maps to 0-360 degrees)
< Zoom level in 8.8 fixed-point (1.0 = 1:1, higher = more zoomed out)
|
static |
Draw the shadow below the glider, further away the higher it flies.
| u16 shadow_dy |
Probe oracle: the shadow's offset below the glider, in pixels.