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

Mode 7 EXTBG: one plane split in two layers, an orb flying between them. More...

#include <snes.h>
#include <snes/mode7.h>
#include "res/plane.inc"
#include "res/orb.inc"

Macros

#define ORB_Y   96
 The orb's height on screen, in pixels.
#define VRAM_OBJ   0x4000
 Sprite tiles in VRAM (words): name base slot 2, past Mode 7's 32 KB.

Functions

static void applyExtBg (void)
 EXTBG on: BG2 (split by bit 7) on screen; off: BG1.
int main (void)

Variables

u8 extbg_on
 Probe oracles: EXTBG on, the orb's x.
u16 orb_x

Detailed Description

Mode 7 EXTBG: one plane split in two layers, an orb flying between them.

Mode 7 has a single layer — unless SETINI bit 6 (EXTBG) is set. Then BG2 shows the same 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. Front to back: sprites 3, sprites 2, BG2 pixels with bit 7 set, sprites 1, BG1, sprites 0, BG2 pixels with bit 7 clear. A priority-1 sprite therefore flies over the pixels whose bit 7 is clear and under those whose bit 7 is set, in one and the same Mode 7 plane.

The plane is the city seen from above with the elevated metro over it: the viaducts and the train are drawn with colours 0x81-0x8D, the streets, roofs and canal below with colours 16 and up. An energy orb crosses the screen on its own, over the roofs and under the viaducts; press A to switch EXTBG off (BG1 shown instead: one layer, the orb in front of everything) and on.

SNES Concepts
  • SETINI ($2133) bit 6 through mode7SetExtBg()
  • Mode 7 EXTBG priority: BG2's high pixels above priority-1 sprites, its low pixels below every sprite and below BG1 (hence BG2 alone on screen)
  • One pixel, two colours: 0x81 is colour 1 on BG2 (7-bit) and colour 129 on BG1 (8-bit), so the palette carries the viaducts' colours twice
  • Mode 7 VRAM interleave (dmaCopyVramMode7)
What to Observe
  • The orb passes over the roofs, the streets and the canal, and under the three viaducts and the train — the same Mode 7 plane, split by bit 7 of its pixels.
  • Press A: EXTBG off, BG1 on screen, the orb now covers the viaducts too.
Modules Used
console, dma, sprite, input, mode7
See also
mode7.h (mode7SetExtBg), docs/tutorials/mode7.md

Macro Definition Documentation

◆ ORB_Y

#define ORB_Y   96

The orb's height on screen, in pixels.

◆ VRAM_OBJ

#define VRAM_OBJ   0x4000

Sprite tiles in VRAM (words): name base slot 2, past Mode 7's 32 KB.

Function Documentation

◆ applyExtBg()

void applyExtBg ( void )
static

EXTBG on: BG2 (split by bit 7) on screen; off: BG1.

◆ main()

int main ( void )

Variable Documentation

◆ extbg_on

u8 extbg_on

Probe oracles: EXTBG on, the orb's x.

◆ orb_x

u16 orb_x