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

void loadGraphics (void)
 Assembly DMA loader for SUPERFREE graphics data.
 
int main (void)
 Entry point: color math transparency with scrolling clouds over a landscape.
 

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

◆ loadGraphics()

void loadGraphics ( void  )
extern

Assembly DMA loader for SUPERFREE graphics data.

Handles DMA transfers with correct bank bytes for tile/tilemap/palette data that may be placed in ROM banks beyond $00 by the linker. C code cannot reliably specify bank bytes for SUPERFREE sections, so an assembly routine uses the :label syntax to get the linker-resolved bank at link time.

Defined in data.asm. Loads BG1 (4bpp landscape) and BG3 (2bpp clouds) tile data, tilemaps, and palettes to their respective VRAM/CGRAM addresses.

◆ 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