Leanpub Header

Skip to main content

6502 Construction Set

Write the machine that ran the eighties - A systems-programming apprenticeship in Rust.

6502 Construction Set
This book is 100% completeLast updated on 2026-11-16

Write the processor that powered the BBC Micro, the Commodore 64, the NES and the Apple II. Thirty builds take you from LDA #$48 to a cycle-accurate 6502 emulator in Rust that passes all three standard conformance suites and finishes by running a complete 6502 chess program. Written for developers.

Minimum price

$39.95

$45.00

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

Buying multiple copies for your team? See below for a discount!

PDF
EPUB
About

About

About the Book

Write a 6502 emulator. Learn Rust. Learn 6502.

This book guides you through writing a 6502 emulator in Rust, one working 6502 program at a time — learning the processor, learning the language, and revisiting the machines of the eighties along the way. Thirty builds take it from Hello, world to an emulator that passes all three standard conformance suites, and finish with a complete chess program running on Windows, Linux, macOS or a Raspberry Pi.

You will write the processor that powered the BBC Micro, the Commodore 64, the NES and the Apple II.

Foreword by Peter Jennings

Microchess, written by Peter Jennings in 1976, was the first commercially available chess program. It is what this book finishes by running, and he has written the foreword:

As this book beautifully demonstrates, learning to balance registers, manage explicit wrapping arithmetic and account for precise execution cycles is not digital archaeology. It is a foundational apprenticeship in systems programming.

— Peter Jennings, author of Microchess (1976)

Who it is for

Written for developers with a year or two of professional experience in a mainstream language — C#, Java, Python or C++ — who are comfortable reading code they did not write and following a compiler error to its cause. You do not need assembly, and you do not need emulator experience; both are introduced here as they are needed.

On Rust: you do not need to know it. Install the toolchain and read the official tutorial as far as its chapter on enums and pattern matching; Chapter 4 teaches the subset this project uses, and any later build that brings in new Rust opens with a short Rust Primer box saying what is new and where to read about it.

What it asks of you: each build is a specification — a goal, the behavior that proves it, and tests you can run. Five of the thirty are markedly bigger than the rest, and the book names them in advance and says how to approach each.

What you learn

The patterns the old machines forced on everyone — multiplication by shift-and-add because the chip cannot multiply, jump-table dispatch, linear-feedback shift registers, binary-coded decimal and the flags it quietly breaks, interrupt handling, and why crossing a page boundary costs a clock cycle.

And modern Rust, taught through a problem that genuinely needs it: ownership on a real data structure rather than a toy, 151 opcodes decoded with enums and pattern matching, deliberate wrapping arithmetic that models 8-bit overflow without undefined behaviour, and a debugger with breakpoints and live disassembly.

Then the part almost nobody teaches: how you know it is right. Anyone can write an emulator that boots. Proving one behaves like the machine it imitates is a different discipline. The instructions in this book have been tested the hard way — the emulator has been rebuilt from the text alone, eight times independently, and all eight reached all 151 documented opcodes and passed all three conformance suites.

What you get

  • DRM-free PDF and EPUB
  • The reference code — the complete working emulator, build by build
  • The tools you build along the way — a disassembler, and a debugger with breakpoints and live disassembly
  • Deployment guidance, including a step-by-step install for the Raspberry Pi 5
  • Updates for life — every future version of this edition, free

Every listing in the book is spliced in from a working repository at build time, so the code on the page is the code that compiles.

Read it before you buy

Four chapters, the first build and a live episode are free and in full — the episode runs a real program in your browser one instruction at a time, showing the registers, flags and memory as they change:

What is in it

30 builds, 7 chapters and 7 appendices. Every build is a real 6502 program — it prints, counts, multiplies, parses — and the emulator work is whatever that program forces. It is why the order looks nothing like an opcode table.

Introduction
  • Chapter 0 — Preface
  • Chapter 1 — Introduction — free to read
  • Chapter 2 — The 6502 Processor for Developers
  • Chapter 3 — The 6502 Itself
  • Chapter 4 — Rust and System Programming — free to read
  • Chapter 5 — The Method and the Map — free to read
  • Chapter 6 — The Method with an AI Assistant — free to read
Implementing Standard 6502 Programming Patterns
  • Build 1 — Hello, world — free to read
  • Build 2 — Count 0 to 9 with subroutines
  • Build 3 — Interlude: The Disassembler
  • Build 4 — Print via zero-page indirect pointer
  • Build 5 — Hex byte output
  • Build 6 — Memory dump
  • Build 7 — Interlude: A Filing System for the Match
  • Build 8 — Print 99 down to 0 in decimal
  • Build 9 — Pseudo-random number generator (LFSR)
  • Build 10 — Multiplication via shift-and-add
  • Build 11 — Jump-table dispatch (with the famous JMP indirect bug)
  • Build 12 — 16-bit decimal output (0–65535)
  • Build 13 — Multi-byte arithmetic demo (16-bit add and subtract)
  • Build 14 — Division via shift-and-subtract
  • Build 15 — Bit-field / status-byte manipulation
  • Build 16 — String operations (strlen, strcmp)
  • Build 17 — Memory copy (memcpy)
  • Build 18 — Lookup tables (advanced indexed addressing)
  • Build 19 — Run-length decoder
  • Build 20 — State machine / parser
  • Build 21 — Tiny interactive monitor
  • Build 22 — Interlude: Completing the Instruction Set
  • Build 23 — Interlude: Interrupts (BRK, IRQ, NMI)
  • Build 24 — Interrupts (BRK round-trip)
  • Build 25 — BCD mode (decimal-mode ADC/SBC)
  • Build 26 — Conformance: finding and fixing compatibility bugs
  • Build 27 — Cycle counting
  • Build 28 — Error Handling: Making the Core's Failure Model Explicit
  • Build 29 — The Emulator Application
  • Build 30 — Case Study: Microchess
  • Afterword
Appendices
  • Appendix A — The Scorecard
  • Appendix B — Notation and the Machine
  • Appendix C — 6502 Instruction Reference
  • Appendix D — Addressing Modes
  • Appendix E — The Opcode Matrix
  • Appendix F — The egui Primer
  • Appendix G — Credits and References

Status

Book 1 is complete — 457 pages, thirty builds, all thirty written. A paperback edition is available separately. Book 2, which builds a machine compatible with the BBC Model B on top of this emulator, is in progress and sold separately.

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 5 members

    Minimum price
    $150
    Suggested price
    $180
  • Up to 10 members

    Minimum price
    $280
    Suggested price
    $315
  • Up to 25 members

    Minimum price
    $600
    Suggested price
    $675

Author

About the Author

Jason Hogg

I’m Jason Hogg. I’ve spent a career building software and services, leading engineering teams, and helping developers learn how to think about systems. I learned to program on the ZX Spectrum and BBC Micro, machines I’ve wanted to rebuild and properly understand ever since.

After retiring from Microsoft, I finally had the chance. What began as a personal project to build a 6502 emulator grew into a deeper exploration of how computers work, how we learn complex systems, and how to teach those ideas through hands-on construction rather than theory alone.

Over the years I’ve written and contributed to books on software design and engineering, and that is how the 6502 is taught here: as patterns rather than as a reference manual, with each opcode introduced when a pattern calls for it rather than in the order a datasheet lists them. Silicon Arcade brings those interests together: building real software, and developing the kind of understanding that stays valuable even as tools continue to change.

When you’re finished, you’ll have built a complete emulator in Rust. More importantly, you’ll understand why it works.

See: https://www.linkedin.com/in/jahogg/

Contents

Table of Contents

Write a 6502 emulator. Learn Rust. Learn 6502.

Understand computers well enough to build one.

This book has you write a 6502 emulator in Rust, one working program at a time. Thirty builds take it from Hello, world to an emulator that passes all three standard conformance suites, and finish with a complete chess program running on Windows, Linux, macOS or a Raspberry Pi.

You will write the processor that powered the BBC Micro, the Commodore 64, the NES and the Apple II.

Who it is for

Written for developers with a year or two of professional experience in a mainstream language — C#, Java, Python, TypeScript or C++ — who are comfortable reading code they did not write and following a compiler error to its cause. You do not need assembly, and you do not need emulator experience; both are introduced here as they are needed.

On Rust: you do not need to know it. Install the toolchain and read the official tutorial as far as its chapter on enums and pattern matching; Chapter 4 teaches the subset this project uses, and any later build that brings in new Rust opens with a short Rust Primer box saying what is new and where to read about it.

What it asks of you: each build is a specification — a goal, the behavior that proves it, and tests you can run. Five of the thirty are markedly bigger than the rest, and the book names them in advance and says how to approach each.

What you learn

The patterns the old machines forced on everyone — multiplication by shift-and-add because the chip cannot multiply, jump-table dispatch, linear-feedback shift registers, binary-coded decimal and the flags it quietly breaks, interrupt handling, and why crossing a page boundary costs a clock cycle.

And modern Rust, taught through a problem that genuinely needs it: ownership on a real data structure rather than a toy, 151 opcodes decoded with enums and pattern matching, deliberate wrapping arithmetic that models 8-bit overflow without undefined behaviour, and a debugger with breakpoints and live disassembly.

Then the part almost nobody teaches: how you know it is right. Anyone can write an emulator that boots. Proving one behaves like the machine it imitates is a different discipline.

What you get

  • DRM-free PDF and EPUB
  • The reference code — the complete working emulator, build by build
  • Updates for life — every future version of this edition, free

Every listing in the book is spliced in from a working repository at build time, so the code on the page is the code that compiles.

Read it before you buy

Three chapters, the first build and a live episode are free and in full — the episode runs a real program in your browser one instruction at a time, showing the registers, flags and memory as they change:

  • Chapter 1 - Introduction
  • Chapter 4 - Rust and System Programming
  • Chapter 5 - The Method and the Map
  • Build 1 - Hello, world
  • Episode: Random numbers - a sequence that only looks random
  • The full contents

What is in it

30 builds, 7 chapters and 7 appendices. Every build is a real 6502 program — it prints, counts, multiplies, parses — and the emulator work is whatever that program forces. It is why the order looks nothing like an opcode table.

Introduction
  • Chapter 0 — Preface
  • Chapter 1 — Introduction — free to read
  • Chapter 2 — The 6502 Processor for Developers
  • Chapter 3 — The 6502 Itself
  • Chapter 4 — Rust and System Programming — free to read
  • Chapter 5 — The Method and the Map — free to read
  • Chapter 6 — The Method with an AI Assistant — free to read
Implementing Standard 6502 Programming Patterns
  • Build 1 — Hello, world — free to read
  • Build 2 — Count 0 to 9 with subroutines
  • Build 3 — Interlude: The Disassembler
  • Build 4 — Print via zero-page indirect pointer
  • Build 5 — Hex byte output
  • Build 6 — Memory dump
  • Build 7 — Interlude: A Filing System for the Match
  • Build 8 — Print 99 down to 0 in decimal
  • Build 9 — Pseudo-random number generator (LFSR)
  • Build 10 — Multiplication via shift-and-add
  • Build 11 — Jump-table dispatch (with the famous JMP indirect bug)
  • Build 12 — 16-bit decimal output (0–65535)
  • Build 13 — Multi-byte arithmetic demo (16-bit add and subtract)
  • Build 14 — Division via shift-and-subtract
  • Build 15 — Bit-field / status-byte manipulation
  • Build 16 — String operations (strlen, strcmp)
  • Build 17 — Memory copy (memcpy)
  • Build 18 — Lookup tables (advanced indexed addressing)
  • Build 19 — Run-length decoder
  • Build 20 — State machine / parser
  • Build 21 — Tiny interactive monitor
  • Build 22 — Interlude: Completing the Instruction Set
  • Build 23 — Interlude: Interrupts (BRK, IRQ, NMI)
  • Build 24 — Interrupts (BRK round-trip)
  • Build 25 — BCD mode (decimal-mode ADC/SBC)
  • Build 26 — Conformance: finding and fixing compatibility bugs
  • Build 27 — Cycle counting
  • Build 28 — Error Handling: Making the Core's Failure Model Explicit
  • Build 29 — The Emulator Application
  • Build 30 — Case Study: MicroChess
  • Afterword
Appendices
  • Appendix A — The Scorecard
  • Appendix B — Notation and the Machine
  • Appendix C — 6502 Instruction Reference
  • Appendix D — Addressing Modes
  • Appendix E — The Opcode Matrix
  • Appendix F — The egui Primer
  • Appendix G — Credits and References

Status

Book 1 is complete — 437 pages, thirty builds, all thirty written. Book 2, which builds a machine compatible with the BBC Model B on top of this emulator, is in progress and sold separately.

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub