This tutorial covers SNES graphics fundamentals including video modes, backgrounds, and tilemaps.
SNES Video Modes
The SNES has 8 video modes (0-7). OpenSNES primarily uses:
| Mode | BG1 | BG2 | BG3 | BG4 | Best For |
| 0 | 4 colors | 4 colors | 4 colors | 4 colors | Text, simple UI |
| 1 | 16 colors | 16 colors | 4 colors | - | Most games |
| 7 | 256 colors (rotatable) | - | - | - | Racing, rotation effects |
Setting Up Graphics
Initialize Display
while (1) {
}
return 0;
}
int main(void)
Entry point — initialize audio, display controls, run transport loop.
Definition main.c:37
void consoleInit(void)
Initialize SNES hardware.
void WaitForVBlank(void)
Wait for next VBlank period.
void setScreenOn(void)
Enable screen display.
#define REG_TM
Main screen designation (W)
Definition registers.h:181
#define TM_BG1
Definition registers.h:439
#define BGMODE_MODE1
Definition registers.h:429
void setMode(u8 mode, u8 flags)
Set background mode.
Loading Tiles to VRAM
Tiles are 8x8 pixel graphics stored in VRAM. For 4bpp (16 color) tiles:
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
}
static u8 i
Definition main.c:156
static u16 bx
Definition main.c:159
#define REG_VMADDH
VRAM address high (W)
Definition registers.h:118
#define REG_VMAIN
VRAM address increment mode (W)
Definition registers.h:112
#define REG_VMADDL
VRAM address low (W)
Definition registers.h:115
#define REG_VMDATAL
VRAM data write low (W)
Definition registers.h:121
#define REG_VMDATAH
VRAM data write high (W)
Definition registers.h:124
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:52
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:46
Setting Up Tilemaps
Tilemaps define which tiles appear where on screen. Each entry is 2 bytes:
Bits: vhopppcc cccccccc
v = vertical flip
h = horizontal flip
o = priority
ppp = palette (0-7)
cccccccccc = tile number (0-1023)
for (y = 0; y < 32; y++) {
for (x = 0; x < 32; x++) {
}
}
}
Setting Palettes
SNES uses 15-bit color (RGB555):
}
#define REG_CGADD
CGRAM address (W)
Definition registers.h:148
#define REG_CGDATA
CGRAM data write (W)
Definition registers.h:151
Background Scrolling
}
#define REG_BG1VOFS
BG1 vertical scroll (W, 2x write)
Definition registers.h:91
#define REG_BG1HOFS
BG1 horizontal scroll (W, 2x write)
Definition registers.h:88
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:49
Parallax Scrolling
For depth effect, scroll backgrounds at different speeds:
#define REG_BG2HOFS
BG2 horizontal scroll (W, 2x write)
Definition registers.h:94
Using gfx4snes
Convert PNG images to SNES format using gfx4snes (based on PVSnesLib):
# Convert 8x8 tiles with palette output
gfx4snes -s 8 -p -i tiles.png
# Output: tiles.pic (tile data), tiles.pal (palette)
# Convert 16x16 sprites with palette
gfx4snes -s 16 -p -i sprites.png
# Convert with metasprite definition (for animation)
gfx4snes -s 16 -p -T -X 32 -Y 48 -i character.png
# Output: character.pic, character.pal, character_meta.inc
Include the generated data in your assembly file:
sprite_tiles:
.incbin "res/sprites.pic"
sprite_tiles_end:
sprite_pal:
.incbin "res/sprites.pal"
sprite_pal_end:
Example: Complete Background Setup
See examples/graphics/effects/parallax_scrolling/ for a complete parallax scrolling example.
Next Steps