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>

Macros

#define VRAM_GFX   0x4000
#define VRAM_MAP   0x0000
 krom's VRAM layout: map at word $0000, tiles at word $4000

Functions

int main (void)

Variables

u8 rings_map []
u8 rings_map_end []
u8 rings_pal []
u8 rings_pal_end []
u8 rings_pic []
 256-color ring artwork (original, procedural)
u8 rings_pic_end []
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 green backdrop (CGRAM color 0) shows wherever the combined window mask disables the layer; the D-pad scrolls the artwork 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
A grid of rectangular portholes over a color-ring artwork; green everywhere else. D-pad scrolls the rings 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   0x4000

◆ VRAM_MAP

#define VRAM_MAP   0x0000

krom's VRAM layout: map at word $0000, tiles at word $4000

Function Documentation

◆ main()

int main ( void )

Variable Documentation

◆ rings_map

u8 rings_map[]
extern

◆ rings_map_end

u8 rings_map_end[]

◆ rings_pal

u8 rings_pal[]
extern

◆ rings_pal_end

u8 rings_pal_end[]

◆ rings_pic

u8 rings_pic[]
extern

256-color ring artwork (original, procedural)

◆ rings_pic_end

u8 rings_pic_end[]

◆ 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.