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

Static 16-color background display in Mode 1 (4bpp). More...

#include <snes.h>
#include <snes/asset.h>

Functions

int main (void)
 Entry point – load a 4bpp tileset and display a static Mode 1 image.

Variables

static const BgAsset bg = { .gfx = { .tiles = bg_tiles, .tiles_end = bg_tiles_end, .palette = bg_pal, .palette_end = bg_pal_end, .color_mode = (BG_16COLORS), }, .tilemap = bg_map, .tilemap_end = bg_map_end, .map_size = (SC_32x32), }
u8 bg_map []
u8 bg_map_end []
u8 bg_pal []
u8 bg_pal_end []
u8 bg_tiles []
u8 bg_tiles_end []

Detailed Description

Static 16-color background display in Mode 1 (4bpp).

Displays a single full-screen tiled background using Mode 1, the most commonly used SNES video mode. Mode 1 provides two 4bpp layers (BG1 and BG2, each up to 16 colors) plus one 2bpp layer (BG3, 4 colors). This example uses only BG1 with a 16-color tileset and tilemap converted from a PNG by gfx4snes.

This is a direct port of the PVSnesLib "Mode1" example.

SNES Concepts
  • Mode 1: BG1/BG2 are 4bpp (16 colors each), BG3 is 2bpp (4 colors)
  • bgInitTileSet() for combined tile + palette loading with VRAM address configuration
  • dmaCopyVram() for tilemap data transfer to a separate VRAM region
  • VRAM layout: tilemap at $0000, tiles at $4000 (non-overlapping regions)
  • Force blank (setScreenOff) during VRAM setup to avoid mid-frame writes
What to Observe
  • A static full-screen image rendered as 8x8 tiles on BG1
  • Only BG1 is enabled; BG2 and BG3 are unused
  • The image remains stationary (no scrolling)
Modules Used
console, sprite, dma, background, asset
See also
background.h, dma.h, video.h

Function Documentation

◆ main()

int main ( void )

Entry point – load a 4bpp tileset and display a static Mode 1 image.

Demonstrates the typed asset bundle: tileset, palette, tilemap, color depth and map size all travel together in a single BgAsset. A single bgLoad() does the same work as a manual bgSetMapPtr + bgInitTileSet + dmaCopyVram triple, with the color-mode / size pairing locked at declaration time.

The VRAM layout places the tilemap at $0000 and tile graphics at $4000 to avoid overlap (each tilemap is up to 2KB, tile data can be many KB).

Returns
Never returns (infinite loop).

Variable Documentation

◆ bg

const BgAsset bg = { .gfx = { .tiles = bg_tiles, .tiles_end = bg_tiles_end, .palette = bg_pal, .palette_end = bg_pal_end, .color_mode = (BG_16COLORS), }, .tilemap = bg_map, .tilemap_end = bg_map_end, .map_size = (SC_32x32), }
static

◆ bg_map

u8 bg_map[]
extern

◆ bg_map_end

u8 bg_map_end[]

◆ bg_pal

u8 bg_pal[]
extern

◆ bg_pal_end

u8 bg_pal_end[]

◆ bg_tiles

u8 bg_tiles[]
extern

◆ bg_tiles_end

u8 bg_tiles_end[]