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

Multi-window HDMA — both windows' edges driven per scanline. More...

#include <snes.h>
#include "res/city.inc"

Macros

#define VRAM_GFX   0x1000
#define VRAM_MAP   0x0000
 The city behind the portholes, 8bpp (devtools/art_assets/build.py).

Functions

int main (void)

Variables

static const u8 window_table []
 krom's exact HDMA window table: 16-line bands alternating "both windows empty" (edges 1..0 = degenerate = fully masked = green) and "two portholes" (W1 16-112, W2 144-240). 5-byte entries: [count][W1L][W1R][W2L][W2R], terminator 0.

Detailed Description

Multi-window HDMA — both windows' edges driven per scanline.

Port of krom (Peter Lemon)'s WindowMultiHDMA demo (PeterLemon/SNES, PPU/Window/WindowMultiHDMA). One HDMA channel in 4-register mode streams WH0-WH3 ($2126-$2129) — BOTH windows' left/right edges — every scanline band, cutting a grid of portholes into BG1: the four windows of an aerial tram, with the city at dusk behind them. The backdrop (CGRAM color 0, the tram's wall) shows wherever the combined window mask disables the layer; the D-pad scrolls the city underneath the static mask.

Window algebra (krom's exact setup): W1 and W2 both enabled on BG1 and both INVERTED, combined with AND — the layer is masked where (outside W1) AND (outside W2), i.e. visible inside either window.

SNES Concepts
  • HDMA_MODE_4REG: one channel drives 4 consecutive PPU registers/line
  • Two windows animated per scanline (hdmaWindowShape covers only one)
  • W12SEL / WBGLOG / TMW via windowEnable/windowSetInvert/ windowSetLogic/windowSetMainMask
  • Backdrop color as the "outside the windows" fill
What to Observe
Four portholes in the tram's dark wall, the city and its reflection in a canal behind them. D-pad scrolls the city behind the fixed portholes.
Modules Used
console, dma, background, hdma, window, input
See also
https://github.com/PeterLemon/SNES — original demo
window.h, hdma.h (HDMA_MODE_4REG)

Macro Definition Documentation

◆ VRAM_GFX

#define VRAM_GFX   0x1000

◆ VRAM_MAP

#define VRAM_MAP   0x0000

The city behind the portholes, 8bpp (devtools/art_assets/build.py).

VRAM: the map at word $0000, the tiles at $1000 (546 8bpp tiles, 34 KB, up to $543F: krom's $4000 would run past the end of VRAM). A BG's character base moves in steps of $1000 words (BG12NBA), so $1000 is the first one past the map.

Function Documentation

◆ main()

int main ( void )

Variable Documentation

◆ window_table

const u8 window_table[]
static
Initial value:
= {
16, 1, 0, 1, 0,
16, 16, 112, 144, 240,
16, 16, 112, 144, 240,
16, 16, 112, 144, 240,
16, 16, 112, 144, 240,
16, 16, 112, 144, 240,
16, 1, 0, 1, 0,
16, 1, 0, 1, 0,
16, 16, 112, 144, 240,
16, 16, 112, 144, 240,
16, 16, 112, 144, 240,
16, 16, 112, 144, 240,
16, 16, 112, 144, 240,
16, 1, 0, 1, 0,
0,
}

krom's exact HDMA window table: 16-line bands alternating "both windows empty" (edges 1..0 = degenerate = fully masked = green) and "two portholes" (W1 16-112, W2 144-240). 5-byte entries: [count][W1L][W1R][W2L][W2R], terminator 0.