Ever wondered how a video game console actually works inside? In this book, you'll find out the best way possible: by building one.
We'll write a NES (Nintendo Entertainment System) emulator from scratch, in Crystal, without using emulation libraries or third-party code. We start with a processor that can't do anything and end up playing Super Mario Bros.
Along the way, we'll implement all 151 instructions of the 6502 CPU, parse real cartridges, render graphics pixel by pixel with the PPU, connect controllers, and generate audio with the APU. Everything explained step by step, with code first and theory after.
This isn't a reference book or an academic guide. It's a hands-on project written in a casual tone, meant for programmers who learn by doing. You don't need to know anything about emulation or retro hardware to get started - just some experience programming in any language.
What you'll learn:
- How a real processor works: registers, flags, addressing modes, interrupts
- How an 80s console draws graphics with just 2KB of RAM and 20,000 transistors
- How CPU, PPU, APU, and cartridges connect through a memory bus
- How to parse real binary files (iNES format)
- How to generate real-time audio with square, triangle, and noise waves
- Why the hardware is designed the way it is, not just how it works
By the end of the book, you'll have an emulator that runs Super Mario Bros, The Legend of Zelda, Contra, and dozens of classics. But more importantly: you'll understand how they work under the hood.
There's no magic. Just patience and a desire to understand how things work.