A fully playable Breakout clone — ball, paddle, bricks, levels, score, and shadows. This is the "put it all together" example. If you can follow this one, you can make a game. Dressed as Neon Breaker, the arcade cabinet of a bar in Daveo, the city of the examples.
| Button | Action |
|---|---|
| D-Pad Left/Right | Move paddle |
| A (hold) | Move faster |
| Start | Begin; pause during play; after GAME OVER, a new game |
| Any button | Continue after losing a ball |
Then open breakout.sfc in luna (or any SNES emulator).
The very first thing the game does is kill the display:
Why force blank? Outside of VBlank, the PPU owns the VRAM bus for rendering. Writes during active display are silently ignored — not queued, not buffered, just gone. Setting bit 7 of INIDISP shuts off the renderer entirely. Now you can DMA as much as you want without racing the clock.
Here's where it gets interesting. This game's VRAM layout has an intentional overlap:
BG1's tilemap is 32x32 entries but the game only uses the top 16 rows. Rows 16-31 (addresses $0400-$07FF) sit there unused — so we slide BG3's tilemap right into that gap. Free 1 KB of VRAM, no catch.
Well... one catch:
The pink flash incident. During the port, level transitions showed a single frame of garbled colors. The culprit? BG1 and BG3 tilemaps were uploaded in separate VBlanks. The frame between them had BG3 half-overwritten by BG1. Fix: both transfers in the same VBlank, always.
That's ~4 KB in one VBlank. Tight, but PVSnesLib routinely does 4.5 KB+. It works.
Bricks get destroyed. Score changes. Colors cycle each level. You can't modify ROM, so you copy everything to RAM and work on the copies:
Why FAR? They're big — 4.6 KB with the brick state. Plain C RAM lives in the first 8 KB of bank $00, which they would crowd; FAR puts them in bank $7E above it, and every access carries its bank (docs/tutorials/far_ram.md). data.asm reserves them in a RAMSECTION of bank $7E.
The SNES gives you 128 sprites. A full brick wall has 100 bricks. You could use sprites, but you'd blow most of your budget on rectangles that don't even move.
The much better approach: bricks are background tiles. Each brick is 2 tiles wide (16 pixels), and the palette number encodes its color:
Destroying a brick? Write zeroes (transparent tile), DMA the tilemap, done:
One frame later the brick is gone. No sprite management, no flicker, no limits.
Instead of checking every brick against the ball, convert the ball's pixel position to grid coordinates and look up the single cell it's in:
65816 trick: by * 10 is written as (by << 3) + (by << 1) — that's by*8 + by*2. A shift is 2 cycles. A software multiply is ~50. On this CPU, you learn to love bit shifts real fast.
If blocks[b] != 8, there's a brick there. One array lookup instead of 100 comparisons.
Where the ball hits the paddle determines the bounce angle. Four zones, 7 pixels each:
This is what makes Breakout feel like Breakout. Without it, the ball just bounces at the same angle every time and the game plays itself.
Every visible sprite has a shadow twin: same shape, darker palette, offset a few pixels down-right, drawn at a lower priority. Sprites are positioned via direct oamMemory[] writes — the escape hatch next to oamSet(), shown here on purpose (either is fine at 10 sprites):
It costs 5 extra sprites (one per visible piece), but the result looks surprisingly polished for something so simple.
What's tile | 256? With OBJSEL's name base at $0000 and a gap of 0, the sprites' second name table starts at word $1000 — exactly where BG1's tiles are. So the paddle and the ball are tiles 15-21 of the same sheet as the bricks, and bit 8 of the tile number (the attribute's low bit) picks that table. Without it, the PPU looks for tiles at $0000 — which is your tilemap. You'll get garbage sprites and spend an hour debugging before you remember this bit.
Each new level swaps CGRAM colors 16-23 — BG3's palette 4 (the board) and 5 (its shadow) — with one of 7 pre-made color sets:
Same tiles, same tilemap, completely different look. This is why the SNES palette system is so powerful — recoloring is essentially free.
One iteration per frame, clean and predictable:
Note that we read pad_keys[0] directly — not through padPressed(). This is the raw buffer that the NMI handler fills every frame. Sometimes the simple way is the right way.
data.asm serves two purposes in Breakout:
1. ROM data the converters do not make — the two tilemaps and the level colours are binaries, included via .INCBIN in an asset section (the linker places it in any bank but $00):
2. The RAM buffers — the writable tilemap copies, the palette and the brick state (4.6 KB) in a RAMSECTION of bank $7E. C declares them FAR, so they sit above the 8 KB plain C band and every access carries its bank (docs/tutorials/far_ram.md).
res/tiles.png and res/back.png are converted by the build, from the settings file beside each:
no-reduce keeps every tile where it is in the sheet: the game addresses its tiles by number (a brick is tiles 13-14, the font is ASCII − 10, the sprites are 15-21). The sheet's PNG palette is the whole CGRAM image, written as tiles.pal: one BG palette per brick colour (colours 13-15), the font in 10-12, the sprites' palette at 128. BG3's sheet takes bpp = 2 and no palette, since its colours come from backpal.bin.
All of res/ — the two sheets, the two maps and the level colours — is drawn by devtools/art_assets/breakout.py (make art-assets), in the game's tile numbering.
| Module | Why it's here |
|---|---|
| console | PPU init, NMI handler, WaitForVBlank() |
| sprite | OAM buffer for ball, paddle, and drop shadows (10 sprites total) |
| dma | dmaCopyVram() for tilemap uploads, dmaCopyCGram() for palette, OAM DMA |
| background | bgSetMapPtr() for configuring BG1/BG3 tilemap addresses |
| input | Joypad buffers — though Breakout reads pad_keys[0] directly |
console, sprite, dma, background, input (LIB_MODULES in the Makefile).
| Register | Address | Role in this example |
|---|---|---|
| INIDISP | $2100 | Force blank during initial load |
| BGMODE | $2105 | Mode 1 (BG1 4bpp, BG3 2bpp) |
| BG1SC | $2107 | BG1 tilemap at $0000 |
| BG3SC | $2109 | BG3 tilemap at $0400 |
| BG12NBA | $210B | BG1 tile data at $1000 |
| BG34NBA | $210C | BG3 tile data at $2000 |
| TM | $212C | Enable OBJ + BG3 + BG1 (0x15) |
| OBJSEL | $2101 | 8x8 sprites, name base $0000, second table at word $1000 (BG1's tiles) |
| File | What's in it |
|---|---|
| main.c | All game logic |
| data.asm | The far RAM buffers, string constants, the map and colour binaries |
| res/tiles.png | BG1 and sprite tiles (cabinet, bricks, paddle, ball, shadows, font, lives icon); its palette is the whole CGRAM. All of it is drawn by devtools/art_assets/breakout.py |
| res/back.png | BG3's circuit board (2bpp) |
| res/bg1map.bin | The cabinet and the HUD labels |
| res/bg2map.bin | The board under the playfield |
| res/backpal.bin | 7 color sets for level cycling |
| Makefile | LIB_MODULES := console sprite dma background input |