OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
Multi-window HDMA — both windows animated per scanline
Screenshot

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 AND right edges — per scanline band, cutting a 2×2 grid of portholes into BG1: the windows of an aerial tram, the city at dusk behind them. The backdrop (the tram's wall) shows wherever the combined mask disables the layer; the D-pad scrolls the city behind the fixed portholes. hdmaWindowShape covers a single window; this is the two-window composition the arc audit flagged.

Window algebra (krom's exact setup): W1 and W2 both enabled on BG1 and both inverted, combined with AND — masked where (outside W1) AND (outside W2) = visible inside either window.

The table is krom's exact 14-band data (in main.c). The picture is ours: res/city.png, 256x256 so that the scroll wraps both ways, made by devtools/art_assets/build.py (tram_view) — the mid-distance towers of the Néo-Lumen art at half size over a gradient of 168 rows (one colour a row, so each row of tiles is one tile), their reflection in a canal; 546 8bpp tiles and 104 colours. Colour 0 is the tram's wall, never in the picture: it is the backdrop.

SNES Concepts

  • HDMA_MODE_4REG: one channel drives 4 consecutive PPU registers/line
  • Two windows shaped per scanline (W1L/W1R/W2L/W2R in one stream)
  • Window combination logic: windowSetInvert ×2 + windowSetLogic(AND)
  • Degenerate window (left=1, right=0) as the "fully masked" band value

Register fidelity vs the original

Register krom this port
BGMODE $0B (Mode 3, priority) same (setMode(BG_MODE3, 0x08))
BG1 tiles word $4000 word $1000: 546 8bpp tiles (34 KB) do not fit from $4000, and the character base moves in steps of $1000 words
W12SEL $0F (W1+W2 on BG1, inverted) same (windowEnable+windowSetInvert ×2)
WBGLOG $01 (BG1 = AND) same (windowSetLogic(LAYER_BG1, WINDOW_LOGIC_AND))
TMW $01 same (windowSetMainMask(LAYER_BG1))
DMAP0/BBAD0 %100 / $26 same (hdmaSetup(ch0, HDMA_MODE_4REG, HDMA_DEST_WH0, …))
HDMA table 14 bands of 16 lines krom's exact bytes (see main.c)
Backdrop green (CGRAM 0) the tram's wall (CGRAM 0, from the picture's palette)

How to Build

cd examples/windows/window_multi_hdma && make

Modules Used

console, dma, background, hdma, window, input