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

Color addition transparency between two background layers. More...

#include <snes.h>
#include <snes/console.h>
#include <snes/video.h>
#include <snes/background.h>
#include <snes/colormath.h>

Functions

int main (void)
 Entry point: color math transparency with scrolling clouds over a landscape.

Variables

u8 cloud_map []
u8 cloud_map_end []
u8 cloud_pal []
u8 cloud_pal_end []
u8 cloud_tiles []
u8 cloud_tiles_end []
u8 land_map []
u8 land_map_end []
u8 land_pal []
u8 land_pal_end []
u8 land_tiles []
 Assembly DMA loader for SUPERFREE graphics data.
u8 land_tiles_end []

Detailed Description

Color addition transparency between two background layers.

Demonstrates the SNES color math unit by blending two background layers. BG1 (main screen) shows a 4bpp landscape, while BG3 (sub screen) holds 2bpp semi-transparent clouds that scroll horizontally. The PPU adds the sub screen pixel colors to the main screen via registers CGWSEL ($2130) and CGADSUB ($2131), producing a translucent overlay effect.

Mode 1 is used with BG3 priority high so the 2bpp cloud layer renders above BG1. Color addition is applied to BG1 and the backdrop, meaning the cloud colors are numerically added to whatever is underneath.

Based on PVSnesLib Transparency example by Alekmaul.

SNES Concepts
  • Color math: addition mode via CGWSEL/CGADSUB registers
  • Main screen vs sub screen layer assignment
  • Mode 1 with BG3 priority high for overlay effects
  • 4bpp (BG1) and 2bpp (BG3) tile formats in the same mode
What to Observe
  • A landscape background with semi-transparent clouds scrolling over it
  • The clouds blend additively, brightening the landscape beneath them
  • No input required; clouds scroll automatically
Modules Used
console, sprite, dma, background, colormath
See also
colormath.h, background.h, video.h

Function Documentation

◆ main()

int main ( void )

Entry point: color math transparency with scrolling clouds over a landscape.

Sets up Mode 1 with two background layers:

  • BG1 (main screen): 4bpp landscape, static
  • BG3 (sub screen): 2bpp semi-transparent clouds, scrolling horizontally

The SNES color math unit adds the sub screen pixel colors to the main screen, producing a translucent cloud overlay. BG3 is given priority high so its tiles render above BG1 in Mode 1's layer ordering.

Returns
Never returns (infinite loop).

Horizontal scroll offset for the cloud layer (BG3), incremented each frame

Variable Documentation

◆ cloud_map

u8 cloud_map[]
extern

◆ cloud_map_end

u8 cloud_map_end[]

◆ cloud_pal

u8 cloud_pal[]
extern

◆ cloud_pal_end

u8 cloud_pal_end[]

◆ cloud_tiles

u8 cloud_tiles[]
extern

◆ cloud_tiles_end

u8 cloud_tiles_end[]

◆ land_map

u8 land_map[]
extern

◆ land_map_end

u8 land_map_end[]

◆ land_pal

u8 land_pal[]
extern

◆ land_pal_end

u8 land_pal_end[]

◆ land_tiles

u8 land_tiles[]
extern

Assembly DMA loader for SUPERFREE graphics data.

Asset symbols from data.asm (.incbin sections). Post-A6+A7 (v0.19.0) C pointers carry the bank byte, so dmaCopyVram / dmaCopyCGram resolve the correct source bank automatically — no ASM stub needed.

◆ land_tiles_end

u8 land_tiles_end[]