Loading...
Searching...
No Matches
main.c File Reference

Mode 7 rotation and scaling demo. More...

#include <snes.h>

Functions

void asm_loadMode7Data (void)
 Assembly helper to load Mode 7 tile data, tilemap, and palette.
 
int main (void)
 Entry point – interactive Mode 7 rotation and scaling demo.
 

Detailed Description

Mode 7 rotation and scaling demo.

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.

SNES Concepts
  • Mode 7 affine transformation (rotation + scaling via M7A-M7D)
  • Interleaved VRAM format (tilemap in low bytes, pixels in high bytes)
  • 8.8 fixed-point scale representation
  • 8-bit angle for hardware sin/cos lookup
What to Observe
  • Press A to rotate the background clockwise
  • Press B to rotate counter-clockwise
  • Press UP to zoom out (background shrinks, more visible)
  • Press DOWN to zoom in (background magnifies)
Modules Used
console, dma, background, sprite, input, mode7
See also
mode7.h, background.h, input.h

Function Documentation

◆ asm_loadMode7Data()

void asm_loadMode7Data ( void  )
extern

Assembly helper to load Mode 7 tile data, tilemap, and palette.

Mode 7 uses a unique interleaved VRAM format: each VRAM word has the tilemap byte in the low byte and the 8bpp pixel data in the high byte. This requires special DMA sequencing that cannot be done with the standard dmaCopyVram() function. The assembly routine handles the interleaved write and also loads the 256-color palette to CGRAM.

Must be called during forced blank (screen off) since it writes to VRAM.

◆ main()

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.

Returns
Does not return (infinite loop).

< Current joypad button state

< Rotation angle (0-255 maps to 0-360 degrees)

< Zoom level in 8.8 fixed-point (2.0 = default, higher = more zoomed out)