Loading...
Searching...
No Matches
main.c File Reference

Mode 1 BG3 high-priority overlay for HUD-style layering. More...

#include <snes.h>

Functions

int main (void)
 Entry point – load 3 BG layers and display with BG3 high priority.
 

Variables

BG1 asset labels (4bpp layer, defined in data.asm via .incbin)
u8 bg1_map
 
u8 bg1_map_end
 
u8 bg1_pal
 
u8 bg1_pal_end
 
u8 bg1_tiles
 
u8 bg1_tiles_end
 
BG2 asset labels (4bpp layer, defined in data.asm via .incbin)
u8 bg2_map
 
u8 bg2_map_end
 
u8 bg2_pal
 
u8 bg2_pal_end
 
u8 bg2_tiles
 
u8 bg2_tiles_end
 
BG3 asset labels (2bpp overlay layer, defined in data.asm via .incbin)
u8 bg3_map
 
u8 bg3_map_end
 
u8 bg3_pal
 
u8 bg3_pal_end
 
u8 bg3_tiles
 
u8 bg3_tiles_end
 

Detailed Description

Mode 1 BG3 high-priority overlay for HUD-style layering.

Demonstrates the Mode 1 BG3 priority bit, which promotes the normally lowest-priority 2bpp layer to render above BG1 and BG2. This hardware feature is how most SNES games implement status bars and HUDs that overlay the gameplay scene without using sprites. Three separate backgrounds are loaded: BG1 and BG2 provide the scene (4bpp, 16 colors each with separate palette banks), while BG3 (2bpp, 4 colors) draws on top of everything when BG3_MODE1_PRIORITY_HIGH is set in setMode().

Based on the PVSnesLib example by odelot. Backgrounds inspired by Streets of Rage 2.

SNES Concepts
  • BG3 priority bit (BG3_MODE1_PRIORITY_HIGH): promotes BG3 above BG1+BG2
  • Mode 1 layer depths: normally BG1 > BG2 > BG3, but priority bit inverts BG3
  • Multi-layer VRAM layout with separate tilemap and tile regions per BG
  • Palette banking via bgInitTileSet() palette offset parameter (e.g., 2, 4 for 32/64-byte CGRAM offsets)
  • VRAM layout: tilemaps at $0000/$0400/$0800, tiles at $2000/$3000/$4000
What to Observe
  • Three background layers visible simultaneously
  • BG3 (the HUD/overlay layer) renders on top of BG1 and BG2
  • Each layer uses a different palette bank (no color sharing between layers)
  • The scene is static (no scrolling or animation)
Modules Used
console, sprite, dma, background
See also
background.h, dma.h, video.h

Function Documentation

◆ main()

int main ( void  )

Entry point – load 3 BG layers and display with BG3 high priority.

Sets up a Mode 1 scene with three background layers. BG1 and BG2 are 4bpp (16 colors each) providing the main scene, while BG3 is 2bpp (4 colors) used as an overlay/HUD layer. The key feature is BG3_MODE1_PRIORITY_HIGH passed to setMode(), which promotes BG3 above BG1 and BG2 in the rendering order. Without this flag, BG3 would render behind the other layers (lowest priority by default in Mode 1).

Each layer loads into its own VRAM region and uses a separate CGRAM palette bank (controlled by the palette offset parameter in bgInitTileSet()). The palette offset is in units of 16 colors: offset 2 means CGRAM colors 32-47 (BG1), offset 4 means colors 64-79 (BG2), and offset 0 means colors 0-15 (BG3).

Returns
Never returns (infinite loop).

Variable Documentation

◆ bg1_map

u8 bg1_map
extern

◆ bg1_map_end

u8 bg1_map_end

BG1 tilemap

◆ bg1_pal

u8 bg1_pal
extern

◆ bg1_pal_end

u8 bg1_pal_end

BG1 16-color palette (CGRAM bank 2)

◆ bg1_tiles

u8 bg1_tiles
extern

◆ bg1_tiles_end

u8 bg1_tiles_end

BG1 tile graphics

◆ bg2_map

u8 bg2_map
extern

◆ bg2_map_end

u8 bg2_map_end

BG2 tilemap

◆ bg2_pal

u8 bg2_pal
extern

◆ bg2_pal_end

u8 bg2_pal_end

BG2 16-color palette (CGRAM bank 4)

◆ bg2_tiles

u8 bg2_tiles
extern

◆ bg2_tiles_end

u8 bg2_tiles_end

BG2 tile graphics

◆ bg3_map

u8 bg3_map
extern

◆ bg3_map_end

u8 bg3_map_end

BG3 tilemap (HUD/overlay)

◆ bg3_pal

u8 bg3_pal
extern

◆ bg3_pal_end

u8 bg3_pal_end

BG3 palette (CGRAM bank 0)

◆ bg3_tiles

u8 bg3_tiles
extern

◆ bg3_tiles_end

u8 bg3_tiles_end

BG3 tile graphics