ATARI 2600 MASTERY: the book's cover beside two screens of the game it builds
Programming Games in C

ATARI 2600 MASTERY

From an empty folder to a cartridge you can flash — C on the Melody's ARM and 6507 assembly on the line, for the Atari 2600, with every number in the text measured against a ROM that really ran.

// What this book is

Seventy-six cycles, and what you can say in them

The Atari 2600 has no frame buffer: the processor serves the beam, line by line, in 76 cycles each. The Melody cartridge puts an ARM beside it that computes in C. This book is about both halves at once — the game in the ARM, the line in the 6507 — and it tells how one game, an isometric port of Atic Atac, was made that way.

The Line

Every kernel line with its cycles and the windows its writes must land in. The ordinary line at 63, the longest at 72, and what 74 does to the picture.

The ARM's Budget

46 ticks in the blank, 31 in the overscan. The book measures every room of the game against them and finds the floor that never needed redrawing.

Two Sprites, Five Things

Repositioning mid-screen, things sorted by row, a rotation so nothing starves. Zaxxon's way, measured to the colour clock.

C and 6507 Together

The ARM draws a framebuffer and packs it into data streams; the 6507 reads them with one two-cycle instruction a line. Where the work goes, and why.

29 Chapter ROMs

Every chapter from the first picture on ships a ROM built from its own folder, with a desktop simulator that tests the game's rules before Stella runs.

To a Real Cartridge

Three voices from the driver, a sprite HUD, text screens, a game you can lose, and the checklist for the Melody and a television.

// A few things the book measured

Numbers from a ROM that ran

None of these are estimates. Each came out of a build, read from Stella's debugger by the book's own scripts.

76cycles in a line, 22 of them in the blank. The ordinary line spends 63 and has 8 to give away.
15m − 54the colour clock a sprite stands at when RESP is strobed on copy m of the reposition line — measured with a frozen layout, two clocks off the arithmetic.
28 → 1ticks in the overscan for the hall's floor, before and after it was drawn once per room into display RAM and copied back each frame.
16ticks lost to a test that was always false: inlined into the floor scan, it spilled the loop's registers. Found by measuring, not by reading.
15,734samples a second: the driver's three voices mixed in an interrupt and written to the volume register once a line.
4,096bytes of display data RAM, mapped stream by stream; 352 spare at the end, and a buffer that was too small twice.

// Read a sample

The printed edition

The draft as it prints: the cover, the table of contents, and then a complete chapter — Isometric rooms, where the room becomes data and the ARM's budget becomes a number. Turn the pages with the arrows, your keyboard, or by clicking the outer edge of a page.

Left page
Right page
Page 1 – 2 of 8

Cover, contents and pages 76–81 of the draft, shown at reading size. The draft runs to 187 pages.

// The interactive edition

The same book, running

The book also reads in a browser — and there it runs. An Atari 2600 with a Melody cartridge, emulated in JavaScript, sits under each chapter's title with that chapter's ROM: press Run and the picture the chapter describes is on the screen, playable.

The sample below is the real thing: the book's own contents and chapter 16 — Isometric rooms — with its ROM beside the text. The button cycles the three rooms.

Open the interactive sample → Opens in a new tab · one chapter of thirty-eight · nothing to install

// What comes with it

Every line of it, buildable

The book edition of the game is the book's source: one folder per chapter, each with its kernel, its C, its simulator and a three-line Makefile, growing from the one before. The scripts that took every picture and every measurement in the text are in it too.

29 chapter foldersfrom a 4 K 6507-only frame to the finished book edition — about 1,600 lines of C and 660 of assembly at the end, with 2,000 lines of tests along the way.
The gameten isometric rooms: doorways, staircases, trapdoors, wanderers and a guardian, a bag and a locked door, health and lives, a sprite HUD, text screens, three voices.
The toolssnap.sh takes pixel-exact pictures through Stella's debugger, ticks.sh reads the ARM's time from it, and make sim runs the game on the desktop in a second.

Every chapter stands on its own, so you can start anywhere and have something that builds and runs:

cd book/ch16-isometric-rooms
make                              # -> ch16-isometric-rooms.bin
make run                          # Stella, joystick pinned
make sim                          # the rules, tested on the desktop
make ticks ROOM=3                 # the ARM's time, read from the debugger

You need dasm, the arm-none-eabi GCC toolchain and Stella, all covered in chapter 04. Verified with Stella 7.0 and GCC 10.3.

187Pages
45Chapters + appendices
29Chapter ROMs
52kWords

// What is inside

Thirty-eight chapters, in eight parts

Part 0 · Before the first line
  • 00 Why the 2600, and why the Melody
  • 01 What "releasable" means
Part 1 · Foundations
  • 02 The machine, honestly
  • 03 The Melody cartridge and CDFJ
  • 04 A production toolchain
  • 05 The first picture
  • 06 Measuring and debugging
  • 07 C on the ARM, assembly on the 6507
Part 2 · The line
  • 08 How a line is drawn
  • 09 The playfield: 40 pixels, one colour per line
  • 10 The jump stream
  • 11 Sprites: one clock of resolution
  • 12 Repositioning mid-screen
  • 13 Fast Fetch: the trap in LDA #
  • 14 Two colours per line
Part 3 · Engine
  • 15 A framebuffer in the ARM
  • 16 Isometric rooms
  • 17 Ten rooms
  • 18 Characters
  • 19 Trapdoors, and touching
  • 20 States
Part 4 · Sound
  • 21 Three voices
  • 22 Sound effects
  • 23 A tune
Part 5 · From technique to game
  • 24 Sharing a sprite
  • 25 Items, the bag, a key
  • 26 Health, lives, score
  • 27 A sprite HUD
  • 28 Text screens
  • 29 Game feel
Part 6 · Performance and real hardware
  • 30 The line's cycle budget
  • 31 The ARM's budget
  • 32 Display Data RAM and the streams
  • 33 On real hardware
Part 7 · From ROM to product
  • 34 Quality assurance
  • 35 Cartridge production
  • 36 Distribution, community, legal
  • 37 DUSK MANOR, the book edition, complete
Appendices · Reference
  • A TIA and RIOT registers, with write windows
  • B CDFJ: registers, data streams, Fast Fetch, the three entry points
  • C Cycle tables
  • D Every kernel line of the book edition, cycle by cycle
  • E Tools
  • F The error catalogue
  • G The NTSC palette with TIA values

// Get the book

From an empty folder to a cartridge

The draft is complete — 38 chapters, 7 appendices, and the book edition of DUSK MANOR that grows across all of them. Follow the dev log for what comes next.