MEGA DRIVE MASTERY, a hardcover book, shown with a Mega Drive console, controller and an open spread
Programming Games in C

MEGA DRIVE MASTERY

From the toolchain to a cartridge you can sell — C with SGDK and 68000 assembly for the Sega Mega Drive, with every number in the text measured against a ROM that really ran.

// What this book is

Every number measured

Most retro programming books assert. This one measures. Every technical claim was verified against a real build before it went into the text, and every screenshot comes from a ROM that was actually built — because a claim you cannot check is a claim you should not make.

The DMA Budget

7,790 bytes per frame in NTSC, 18,245 in PAL. The chapter that decides whether your game holds 60 frames a second.

128,006 Cycles

That is one NTSC frame on the 68000, 152,923 in PAL. Everything the game does has to fit between two of them.

20 Sprites a Line

80 on screen, 20 per scanline, and the twenty-first simply is not drawn. The book makes the limit visible, then works with it.

C and 68000 Together

C with SGDK for the shape of the game, hand-written assembly in the hot paths. The book shows where the line falls, measured.

21 Milestone ROMs

Every chapter ends with a ROM that builds and runs — no dead example code. Jump in anywhere and regressions stay visible.

To a Real Cartridge

It ends where a hobby project usually stops: SRAM saves, PAL and NTSC correctness, cartridge production and distribution.

// A few things the book measured

Numbers from a ROM that ran

None of these are estimates. Each came out of a build, checked with the book's own tooling.

×11more you can write to VRAM during blanking than during display — 205 bytes a line against 18. It shapes every architectural decision.
7,790bytes into the VDP per NTSC frame. PAL gives 18,245 — develop only on PAL and the game collapses in NTSC.
128,00668000 cycles in an NTSC frame, 152,923 in PAL. A quarter of the frame at 30 fps is about 1,067 cycles.
20sprites per scanline in H40, 80 in total. The book makes the limit visible on screen, then shows the flicker rotation that lives with it.
32bytes per tile, so 243 tiles is the whole NTSC budget for a frame. Tile counts are a currency in this book.
13,696bytes measured in one milestone phase — over the NTSC budget, documented in the text rather than quietly tuned away.

// Read a sample

The printed edition

The printed edition, as printed: the cover, the full table of contents, and then a complete chapter — DMA and the VBlank budget, the one that decides whether your game holds 60 frames a second. 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 7

Cover, contents and pages 66–71 of the printed edition, shown at reading size. The full book runs to 234 pages.

// The interactive edition

The same book, running

The book also reads in a browser — and there it runs. A Mega Drive compiled to WebAssembly sits beside the text, and the chapter you are reading picks the ROM: scrolling switches the machine along with the words. Every chapter carries the source of its milestone with it.

The sample below is the real thing, not a mock-up: the book's own contents and chapter 10 — DMA and the VBlank budget — with milestone 07-dma running beside the text, showing the budget live and what happens when you blow through it.

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

// What comes with it

Every line of it, buildable

The book is not a set of listings to retype. It comes with the complete source for all twenty-one milestones, the build and test tooling the whole book runs on, and the converters that turn artwork and levels into something the VDP can use. Nothing is held back for a "pro edition"; there is no such thing.

21 milestonesevery one with its own makefile, sources and resources — about 20,000 lines of commented C that builds to a running ROM.
The gamea run-and-gun platformer that grows across the book: parallax, entities, collision, streaming, bosses, music, SRAM saves.
The toolsmd-build, md-run, md-shot, md-test, md-play — headless screenshots, ten acceptance checks, tile and palette validation.

Every milestone stands on its own, so you can start at any chapter and still have something that builds and runs — and regressions stay visible because the checks are scriptable:

cd milestones/07-dma
make                              # -> out/rom.bin
../../tools/md-run.sh out/rom.bin ntsc      # play it
python3 ../../tools/md-test.py out/rom.bin  # 10 checks, 0 = green

You need SGDK and the free m68k toolchain, both covered in chapter 03. Verified with SGDK 2.12, m68k-elf-gcc 15.2.0 and MAME 0.288.

234Printed pages
45Chapters + appendices
21Milestone ROMs
52kWords

// What is inside

Thirty-eight chapters, in eight parts

Part 0 · Before the first line
  • 00 Why the Mega Drive, and what the market actually buys
  • 01 What “sellable” means technically
Part 1 · Foundation
  • 02 The machine, honestly explained
  • 03 A production-quality toolchain
  • 04 The first ROM, done right
  • 05 Debugging, measuring, automating
  • 06 Mixing C and 68000 assembly
Part 2 · Mastering the VDP
  • 07 Tiles, planes, scrolling
  • 08 Palettes like a professional
  • 09 Sprites
  • 10 DMA and the VBlank budget
  • 11 Raster effects
  • 12 The graphics pipeline
Part 3 · Engine
  • 13 Fixed-point mathematics
  • 14 The entity system
  • 15 Collision
  • 16 Camera and level streaming
  • 17 Game states
  • 18 Level format and converter
Part 4 · Audio
  • 19 Understanding the YM2612 and PSG
  • 20 Sound-Treiber einsetzen
  • 21 Musik und SFX produzieren
Part 5 · From technology to a game
  • 22 Game Feel
  • 23 Gegner-KI ohne CPU-Last
  • 24 Bosse
  • 25 Level-Design und Balancing
  • 26 HUD, Menüs, Lokalisierung
Part 6 · Performance and real hardware
  • 27 Profilieren statt raten
  • 28 68000-Optimierung
  • 29 Assembly-Hotpaths
  • 30 PAL/NTSC, 50/60 Hz, Regionen
  • 31 Auf echter Hardware
Part 7 · From ROM to product
  • 32 Speichern
  • 33 Qualitätssicherung
  • 34 Cartridge-Produktion
  • 35 Vertrieb
  • 36 Marketing und Community
  • 37 Rechtliches
Appendices · Reference
  • A VDP-Registerreferenz
  • B DMA- und VBlank-Budget-Tabelle
  • C 68000-Zyklentabelle
  • D SGDK-API-Spickzettel
  • E Werkzeugliste
  • F Fehlerkatalog: 40 typische Fehler
  • G Weiterführend: Mega CD, 32X, Mapper

// Get the book

From the toolchain to a cartridge

The manuscript is finished — 234 pages, 38 chapters, and a run-and-gun platformer that grows across all of them. The German edition is complete; the English translation is under way. The printed edition and the interactive edition are being prepared for release.