SNES Mode 7 Support. More...
#include <snes/types.h>Go to the source code of this file.
Macros | |
| #define | MODE7_FLIP_H 0x01 |
| Flip Mode 7 plane horizontally. | |
| #define | MODE7_FLIP_V 0x02 |
| Flip Mode 7 plane vertically. | |
| #define | MODE7_TILE0 0xC0 |
| Show tile 0 when out of bounds. | |
| #define | MODE7_TRANSPARENT 0x80 |
| Show transparent when out of bounds. | |
| #define | MODE7_WRAP 0x00 |
| Wrap around when out of bounds (default). | |
Functions | |
| void | mode7Init (void) |
| Initialize Mode 7. | |
| void | mode7Rotate (u16 degrees) |
| Set rotation in degrees (0-359). | |
| void | mode7SetAngle (u8 angle) |
| Set Mode 7 rotation angle. | |
| void | mode7SetCenter (s16 x, s16 y) |
| Set Mode 7 center point. | |
| void | mode7SetExtBg (u8 on) |
| Enable/disable Mode 7 EXTBG (SETINI bit 6): a second, split layer. | |
| void | mode7SetMatrix (s16 a, s16 b, s16 c, s16 d) |
| Set Mode 7 matrix directly. | |
| void | mode7SetScale (u16 scale_x, u16 scale_y) |
| Set Mode 7 scale factors. | |
| void | mode7SetScroll (s16 x, s16 y) |
| Set Mode 7 scroll position. | |
| void | mode7SetSettings (u8 settings) |
| Set Mode 7 settings register. | |
| void | mode7Transform (u16 degrees, u16 scalePercent) |
| Set rotation and scale together. | |
SNES Mode 7 Support.
Functions for Mode 7 rotation and scaling effects. Mode 7 is the SNES's hardware rotation/scaling mode, famously used in F-Zero, Super Mario Kart, and Pilotwings.
Mode 7 uses a special interleaved VRAM format:
Use dmaCopyVramMode7() (two DMAs: tilemap to the low bytes, tiles to the high bytes, from any bank) or set up DMA manually with interleaved data.
| #define MODE7_FLIP_H 0x01 |
Flip Mode 7 plane horizontally.
| #define MODE7_FLIP_V 0x02 |
Flip Mode 7 plane vertically.
| #define MODE7_TILE0 0xC0 |
Show tile 0 when out of bounds.
| #define MODE7_TRANSPARENT 0x80 |
Show transparent when out of bounds.
| #define MODE7_WRAP 0x00 |
Wrap around when out of bounds (default).
| void mode7Init | ( | void | ) |
Initialize Mode 7.
Writes the identity matrix (A = D = $0100, 1:1), the center point (128,128), M7HOFS = 0 and M7VOFS = $17F (texel row $180 on the first line: the view starts in the middle of the 1024-texel plane, not at its top — call mode7SetScroll(0, 0) to see row 0 first), and the scale mode7SetAngle() uses to 0x0100 (1:1). Call this before using other Mode 7 functions.
| void mode7Rotate | ( | u16 | degrees | ) |
Set rotation in degrees (0-359).
Convenience function that converts degrees to the internal 0-255 format.
| degrees | Rotation angle in degrees (0-359) |
| void mode7SetAngle | ( | u8 | angle | ) |
Set Mode 7 rotation angle.
Sets the rotation angle and recalculates the transformation matrix. The angle is 0-255 where 256 would equal 360 degrees (wraps at 256).
| angle | Rotation angle (0-255) |
This function:
Set Mode 7 center point.
Sets the center of rotation/scaling, a point of the plane. Default is (128, 128). It shows on screen at (center - scroll): for a rotation around the middle of the screen, the center is (scrollX + 128, scrollY + 112).
| x | Center X coordinate (13-bit signed, -4096 to 4095) |
| y | Center Y coordinate (13-bit signed, -4096 to 4095) |
| void mode7SetExtBg | ( | u8 | on | ) |
Enable/disable Mode 7 EXTBG (SETINI bit 6): a second, split layer.
| on | 1 to enable, 0 to disable |
With EXTBG on, BG2 shows the same Mode 7 plane as BG1 (same tilemap, same pixels, same transform), but reads each pixel's bit 7 as a priority bit and bits 0-6 as its colour (128 colours). Front to back, Mode 7 EXTBG draws: sprites of priority 3, sprites 2, BG2 pixels with bit 7 set, sprites 1, BG1, sprites 0, BG2 pixels with bit 7 clear (anomie's register doc, Mode 7; snesdev-wiki, Backgrounds). So a sprite of priority 1 passes in front of the bit-7-clear pixels and behind the bit-7-set ones: put BG2, not BG1, on the screen (BG1 would cover the low pixels), e.g. setMainScreen(LAYER_BG2 | LAYER_OBJ). BG1 still reads all 8 bits, so a pixel 0x83 is colour 3 on BG2 and colour 131 on BG1. Direct colour does not apply to BG2.
SETINI is write-only: this goes through the same software copy as videoSetInterlace(), videoSetOverscan() and videoSetPseudoHires(), so it does not clear their bits.
Set Mode 7 matrix directly.
For advanced users who need direct control over the transformation matrix. Bypasses the angle/scale system.
The matrix maps screen (x,y) to Mode 7 plane (X,Y): X = A*(x-cx) + B*(y-cy) + sx + cx Y = C*(x-cx) + D*(y-cy) + sy + cy
Set Mode 7 scale factors.
Sets the X and Y scale for Mode 7 transformation, 8.8 fixed point (texels per screen pixel):
| scale_x | Horizontal scale (8.8 fixed point) |
| scale_y | Vertical scale (8.8 fixed point) |
Set Mode 7 scroll position.
Sets the scroll offset for the Mode 7 plane.
| x | Horizontal scroll (13-bit signed) |
| y | Vertical scroll (13-bit signed); written as y - 1 to M7VOFS, the same scanline-0 convention as bgSetScroll() |
| void mode7SetSettings | ( | u8 | settings | ) |
Set Mode 7 settings register.
Controls flipping and out-of-bounds behavior.
| settings | M7SEL value: Bit 1: Flip vertically Bit 0: Flip horizontally Bits 7-6: Out of bounds behavior (0=wrap, 0x80=transparent, 0xC0=tile 0) |
Set rotation and scale together.
Combined transformation with rotation in degrees and percentage-based scaling.
| degrees | Rotation angle in degrees (0-359) |
| scalePercent | Scale as a percentage (100 = 1:1, 50 = magnified twice, 200 = shrunk twice; computed as percent x 2.5, so 100 is 0x00FA, within 3 % of 0x0100) |