Goal: the payoff lesson. You have a palette (Lesson 4) and a tile (Lesson 5) sitting in memory doing nothing — this lesson builds the tilemap that finally puts them on screen, and turns on the background layer that displays it.
A background layer needs three things, two of which you already have:
BGMODE, $2105) that decides how many background layers exist and how many colors each one gets.The SNES has 8 background modes, selected by the low 3 bits of $2105. Modes trade off “how many layers” against “how many colors per layer” — see the full BG Modes table for all eight. This tutorial uses Mode 1: two 16-color (4bpp) layers plus one 4-color (2bpp) layer. We’ll only turn on the 2bpp layer, BG3, since it matches the tile you already built in Lesson 5.
$2105 wb+++-
DCBAemmm
mmm = 001 -> Mode 1
e = 0 -> BG3 priority bit, default behavior
A/B/C/D = 0 -> all BGs use 8x8 tiles, not 16x16
A tilemap is a grid of 16-bit entries, one per 8×8 (or 16×16) screen cell. Per the background reference:
vhopppcc cccccccc
v/h = vertical/horizontal flip this tile
o = tile priority
ppp = palette number for this tile
cccccccccc = tile number (10 bits)
The default “empty” entry $0000 means: no flip, priority 0, palette 0, tile 0 — which is exactly the tile you built in Lesson 5, in the palette you built in Lesson 4. A tilemap filled entirely with $0000 will show that same striped tile, repeated, across the whole screen. That’s what we’re about to build.
Tilemaps are always 32×32 tiles internally (more on larger maps in Lesson 9), which is exactly 256×256 pixels — bigger than the visible 256×224 screen, so a single 32×32 map already fills the display with room to spare.
This trips up nearly everyone the first time. VMADDL/VMADDH (which you used directly in Lesson 5) always take a word address — VRAM is fundamentally 16-bit-addressed from the CPU’s side. But the base address fields inside BG34NBA (character data location) and BG3SC (tilemap location) describe positions in VRAM’s 64 KB byte address space, pre-shifted:
BG34NBA: aaaa = BG3 character base, as (byte address) >> 12
BG3SC: aaaaaa = BG3 tilemap base, as (byte address) >> 10
The conversion you need to remember: word address = byte address ÷ 2. Since Lesson 5 put the tile at VRAM word address $0000 (byte address $0000 too, conveniently), BG34NBA’s BG3 field is just 0. For the tilemap, we’ll pick byte address $1000 (well clear of the 16-byte tile) — that’s word address $0800 when we write it with VMADDL/VMADDH, but $1000 >> 10 = 4 when we write it into BG3SC. Two different registers, two different units, same physical location. Getting this wrong (writing a word address into BG3SC, or vice versa) produces a classic symptom: your tile data looks fine in a VRAM viewer, but the screen shows garbage or nothing — worth remembering when Lesson 7 covers debugging techniques.
Careful where you paste this. Every lesson so far ended with reset: turning the screen on — lda #$0F / sta $2100 (INIDISP) has been the last thing your reset: routine does since Lesson 1, so simply appending new code to the end of your file, like you did in Lessons 2-5, would tack it on after that line. This lesson is different: insert the block below before your existing INIDISP write, which needs to stay the very last thing reset: does. Getting this order wrong won’t crash anything — it just means the tilemap and BG-register writes below land on VRAM/PPU state the screen is already actively reading from, so they get dropped or corrupted, and you’ll see leftover VRAM garbage instead of stripes.
Add this after the VRAM tile-loading loop from Lesson 5 (and before INIDISP):
; --- Fill a 32x32 tilemap at VRAM byte $1000 (word $0800) with
; zeros: tile 0, palette 0, no flip, priority 0, everywhere. ---
lda #$08
sta $2117 ; VMADDH: word address $0800, high byte
stz $2116 ; VMADDL: word address $0800, low byte
ldx #0
@map_loop:
stz $2118 ; VMDATAL: tile number low byte = 0
stz $2119 ; VMDATAH: rest of the entry = 0
inx
cpx #1024 ; 32*32 = 1024 tilemap entries
bne @map_loop
; --- Point BG3 at that character data and tilemap. ---
lda #$00
sta $210C ; BG34NBA: BG3 character base = byte $0000 (>>12 = 0)
lda #$10
sta $2109 ; BG3SC: BG3 tilemap base = byte $1000 (>>10 = 4), 32x32
; --- Select BG Mode 1. ---
lda #$01
sta $2105 ; BGMODE: mode 1, all BGs 8x8 tiles
; --- Enable BG3 on the main screen. ---
lda #$04
sta $212C ; TM: bit 2 = BG3This all needs to happen before the INIDISP write that turns on the screen (the last few lines of Lesson 1’s reset:) — everything here writes to PPU registers that are only safe to touch during forced blank or V-Blank, and forced blank is exactly the state the CPU is in for this whole reset: routine, right up until that final brightness write.
Assemble and run it. This time the screen changes: instead of a flat backdrop color, you should see the entire visible area filled with horizontal red and green stripes — the Lesson 5 tile, repeated across a 32×32 tilemap, rendered through the Lesson 4 palette. This is the first lesson where every earlier piece of the tutorial visibly comes together.
BG3SC to place the tilemap at a different (still non-overlapping) VRAM location, recomputing both the byte-address shift for BG3SC and the word address for the VMADDL/VMADDH write. Confirm the display is unchanged — the exact address doesn’t matter as long as it’s consistent and doesn’t collide with the tile data.
Byte address $2000 works fine — well clear of both the tile ($0000-$000F) and the original tilemap ($1000-$17FF). Word address for VMADDL/VMADDH is byte÷2 = $1000; BG3SC’s field is byte-address>>10 (with map-size bits below it, both 0 for 32×32), which for a byte address that’s already a multiple of $400 simplifies to byte>>8:
lda #$10
sta $2117 ; VMADDH: word address $1000, high byte
stz $2116 ; VMADDL: word address $1000, low byte
...
lda #$20
sta $2109 ; BG3SC: byte $2000 >> 8 = $20, 32x32
Same red/green stripes as before — the tilemap just lives somewhere else in VRAM now, which the PPU doesn’t care about as long as BG3SC and the actual write address agree.
The horizontal flip bit (h) won’t show anything on this particular tile — its stripes run horizontally, so every pixel in a row already matches its mirror. The vertical flip bit (v, bit 15, entry value $8000) does: it swaps the red top half and green bottom half for just that one cell. Poke it after the fill loop, at tilemap word address $0800 + 5 (base + entry index):
lda #$08
sta $2117
lda #$05
sta $2116 ; word address $0805 = tilemap entry 5
lda #$00
sta $2118 ; low byte
lda #$80
sta $2119 ; high byte -> entry = $8000 (v flip, tile 0, palette 0)
Entry 5 is the 6th cell in row-major order with a 32-wide map, so it lands in row 0 (the top row of the screen), column 5 — the 6th 8×8 square from the left along the very top edge. That one square shows green-on-top/red-on-bottom while every other square around it stays red-on-top/green-on-bottom.
TM ($212C) enables layers on the main screen; TS ($212D) is the identical register for the subscreen, used for color-math effects this tutorial doesn’t cover. Skim its entry in the register reference just enough to confirm it uses the exact same bit layout as TM.
Same five low bits, same meaning, just aimed at the subscreen instead of the main screen: bit 0 = BG1, bit 1 = BG2, bit 2 = BG3, bit 3 = BG4, bit 4 = OBJ (sprites), bits 5-7 unused. So lda #$04 / sta $212D would put BG3 on the subscreen the same way this lesson’s sta $212C put it on the main screen — the register reference lists TS right under TM with an identical bit diagram for exactly this reason.
Home | Previous: Lesson 5 — Tiles & VRAM Next: Lesson 7 — Debugging with Mesen