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

Direct color — the pixel byte IS the color (CGWSEL bit 0). More...

#include <snes.h>
#include <snes/colormath.h>
#include <snes/input.h>

Functions

static void build_solid_tile (u8 v)
 Fill tilebuf with a solid 8bpp tile of pixel value v.
int main (void)

Variables

u8 direct_on
 Probe oracle: 1 while direct color is active.
static u16 graybuf [256]
 Grayscale CGRAM ramp (256 x 15-bit).
static u16 rowbuf [32]
 One tilemap row (32 entries).
static u8 tilebuf [64]
 One 8bpp tile (4 interleaved bitplane pairs, 64 bytes).

Detailed Description

Direct color — the pixel byte IS the color (CGWSEL bit 0).

Effects arc 4/7 (#109). In direct color mode the PPU stops looking 8bpp BG pixels up in CGRAM: each pixel byte is read as BBGGGRRR and expanded straight to 15-bit BGR. This example builds a 16x16 chart of all 256 pixel codes procedurally (zero assets, 256 solid-color tiles generated at init) and loads a deliberately DIFFERENT CGRAM palette — a grayscale ramp — so one button press flips the SAME VRAM bytes between two readings:

  • direct ON (boot state): the BBGGGRRR color cube — red ramps left-to-right within each block row, green down the chart, blue in four broad bands;
  • direct OFF: the CGRAM grayscale ramp of the very same tile data.

ROM mode: LoROM (project default).

SNES Concepts
  • CGWSEL bit 0 via colorMathSetDirectColor() — the colormath module shadows the register, so this composes with any blending setup
  • BBGGGRRR expansion and the tilemap-palette-bits low-bit extension (2048 colors max — this chart uses pal bits 0, the base 256)
  • Mode 3: BG1 is 8bpp; 8bpp tile format = 4 interleaved bitplane pairs (64 bytes/tile), built here byte by byte in C
What to Observe
Boot shows the color cube. Press A to re-read the same VRAM as grayscale (CGRAM mode), press again to return. Nothing is uploaded on toggle — one register bit changes the meaning of every pixel.
Modules Used
console, dma, background, colormath, input
See also
lib/include/snes/colormath.hcolorMathSetDirectColor()

Function Documentation

◆ build_solid_tile()

void build_solid_tile ( u8 v)
static

Fill tilebuf with a solid 8bpp tile of pixel value v.

8bpp planar layout: rows store plane pairs 0-1, then 2-3, 4-5, 6-7 in 16-byte groups. A solid tile makes every row byte of plane p either $FF or $00 depending on bit p of v.

◆ main()

int main ( void )

Variable Documentation

◆ direct_on

u8 direct_on

Probe oracle: 1 while direct color is active.

◆ graybuf

u16 graybuf[256]
static

Grayscale CGRAM ramp (256 x 15-bit).

◆ rowbuf

u16 rowbuf[32]
static

One tilemap row (32 entries).

◆ tilebuf

u8 tilebuf[64]
static

One 8bpp tile (4 interleaved bitplane pairs, 64 bytes).