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

"9-bit" gradient — brightness-dithered backdrop, two HDMA channels More...

#include <snes.h>

Functions

int main (void)

Variables

u8 brightness_table []
u8 color_table []
 krom's exact tables: [1][CGADD=0 word][color word] x224 + term, and [1][brightness] x224 + term

Detailed Description

"9-bit" gradient — brightness-dithered backdrop, two HDMA channels

Port of krom (Peter Lemon)'s RedSpace9BitHDMA demo (PeterLemon/SNES, PPU/HDMA/RedSpace9BitHDMA). The SNES has 5 bits per color channel (32 levels); this classic trick fakes more: channel 0 rewrites the backdrop color every scanline (2-register mode into CGADD/CGDATA) while channel 1 rewrites INIDISP brightness (16 levels) on the SAME line. Red level x brightness, plus krom's line-to-line jitter in both tables, dithers the 224-line gradient into far more perceptual steps than 5 bits allow — "9-bit" color.

There is no BG at all (TM = 0): the whole image is the backdrop. INIDISP itself is HDMA-driven — the demo never calls setScreenOn().

SNES Concepts
  • Two HDMA channels cooperating on one visual (color + brightness)
  • HDMA into INIDISP ($2100) — per-scanline master brightness
  • HDMA_MODE_2REG_2X into CGADD: [addr16][data16] = one palette write/line
  • Backdrop-only rendering (TM = 0)
What to Observe
A red-to-black vertical gradient noticeably smoother than 32 bands — compare with hdma/hdma_indirect_gradient (pure 5-bit ramp).
Modules Used
console, dma, hdma
See also
https://github.com/PeterLemon/SNES — original demo & tables

Function Documentation

◆ main()

int main ( void )

Variable Documentation

◆ brightness_table

u8 brightness_table[]

◆ color_table

u8 color_table[]
extern

krom's exact tables: [1][CGADD=0 word][color word] x224 + term, and [1][brightness] x224 + term