Semi-transparent darkened rectangle via HDMA windows and color math. More...
#include <snes.h>Macros | |
| #define | RECT_HEIGHT 112 |
| Height of the darkened rectangle in scanlines. | |
| #define | RECT_WIDTH 176 |
| Width of the darkened rectangle in pixels. | |
| #define | RECT_X 40 |
| X coordinate of the darkened rectangle's left edge (pixels) | |
| #define | RECT_Y 96 |
| Y coordinate of the darkened rectangle's top edge (scanlines from top) | |
Functions | |
| int | main (void) |
| Entry point: darkened rectangle overlay using HDMA windows and color math. | |
Variables | |
| u8 | hdma_left [128] |
| HDMA table for the left window boundary (WH0, $2126). | |
| u8 | hdma_right [128] |
| HDMA table for the right window boundary (WH1, $2127). | |
| u8 | palette [] |
| 16-color palette for the background | |
| u8 | tilemap [] |
| Background tilemap data for the 32x32 tile grid. | |
| u8 | tilemap_end [] |
| u8 | tiles [] |
| 4bpp background tile data (defined in data.asm, stored in ROM) | |
| u8 | tiles_end [] |
Semi-transparent darkened rectangle via HDMA windows and color math.
Combines two SNES hardware features to render a darkened rectangle over a background image. HDMA drives the window position registers WH0 ($2126) and WH1 ($2127) every scanline to define the rectangle boundaries. The color math unit is configured to subtract a fixed color intensity inside the window region only (CGWSEL bit 5-4 = 01), producing a tinted overlay.
The HDMA tables use repeat mode (bit 7 set in the line count byte) because WH0/WH1 are write-only registers that must be refreshed every scanline, even when the window position is constant across the rectangle height.
Ported from PVSnesLib "TransparentWindow" example by Digifox. Uses bare-metal register writes to match PVSnesLib behavior exactly.
| #define RECT_HEIGHT 112 |
Height of the darkened rectangle in scanlines.
| #define RECT_WIDTH 176 |
Width of the darkened rectangle in pixels.
| #define RECT_X 40 |
X coordinate of the darkened rectangle's left edge (pixels)
| #define RECT_Y 96 |
Y coordinate of the darkened rectangle's top edge (scanlines from top)
| int main | ( | void | ) |
Entry point: darkened rectangle overlay using HDMA windows and color math.
Builds HDMA tables to define a rectangle region, loads a background image, then uses the PPU's color math unit to subtract a fixed color intensity inside the window — creating a semi-transparent darkened overlay. This technique is used in RPGs for dialogue boxes, inventory screens, etc.
| u8 hdma_left[128] |
HDMA table for the left window boundary (WH0, $2126).
Built at startup to define where the darkened rectangle starts horizontally on each scanline. Before and after the rectangle, WH0 is set to 0xFF (disabling the window by placing the left edge beyond the right edge).
| u8 hdma_right[128] |
HDMA table for the right window boundary (WH1, $2127).
Built at startup to define where the darkened rectangle ends horizontally on each scanline. Before the rectangle, WH1 is set to 0x00 (disabling the window by placing the right edge before the left edge).
|
extern |
16-color palette for the background
|
extern |
Background tilemap data for the 32x32 tile grid.
| u8 tilemap_end[] |
|
extern |
4bpp background tile data (defined in data.asm, stored in ROM)
| u8 tiles_end[] |