<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/emulating-6502-73lxi4alv" -->

---
title: Emulating 6502 | daily.dev
description: A step-by-step walkthrough builds a MOS 6502 CPU emulator in Python from scratch, covering registers, memory layout, addressing modes, and all 151 opcodes. The...
canonical: https://daily.dev/posts/emulating-6502-73lxi4alv
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Emulating 6502 | daily.dev
og:description: A step-by-step walkthrough builds a MOS 6502 CPU emulator in Python from scratch, covering registers, memory layout, addressing modes, and all 151 opcodes. The...
og:url: https://daily.dev/posts/emulating-6502-73lxi4alv
og:image: https://api.daily.dev/og/posts/73lXi4ALV.png
og:image:alt: Emulating 6502
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Emulating 6502

**[zserge's blog](https://daily.dev/sources/zserge)** · 30 min read · 0 upvotes · 0 comments

## Summary

A step-by-step walkthrough builds a MOS 6502 CPU emulator in Python from scratch, covering registers, memory layout, addressing modes, and all 151 opcodes. The emulator is tested against a real Apple I ROM (WozMon), progressively implementing instruction groups (load/store, branches, stack, shifts, bitwise, arithmetic including BCD mode) until it boots WozMon, accepts keyboard input, runs a hand-typed assembly program, and finally loads Integer BASIC. Full source code is shared as a gist, plus a C port supporting Apple I and KIM-1 emulation.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://zserge.com/posts/6502>

## Questions this post answers

### How many opcodes do I need to implement to fully emulate the MOS 6502 CPU?

A complete MOS 6502 emulator requires implementing 151 individual opcode values, even though the instruction set itself has only 56 distinct instructions. The discrepancy comes from the CPU's multiple addressing modes: the same instruction, like LDA, can be encoded as up to 8 different byte values depending on whether it uses immediate, zero-page, absolute, indexed, or indirect addressing.

_Developers building retro CPU emulators can find deep-dive walkthroughs like this one on daily.dev._

### What is the memory map layout of an Apple I computer for emulation purposes?

The Apple I uses 4KB or 8KB of RAM, memory-mapped I/O at addresses like 0xD010 (keyboard input), 0xD011 (key-pressed flag), and 0xD012 (screen output), plus a 256-byte WozMon monitor ROM loaded at 0xFF00-0xFFFF. Interrupt vectors for reset, IRQ, and NMI sit at the very top of the 16-bit address space, near 0xFFFA-0xFFFF.

_Anyone recreating vintage hardware memory maps can track detailed technical walkthroughs via daily.dev._

### How do you implement BCD (binary-coded decimal) arithmetic for the 6502's ADC and SBC instructions?

BCD mode treats each byte's two nibbles as separate decimal digits rather than a straight binary value, so adding 0x43 and 0x28 yields 0x71 instead of the binary result 0x6B. Implementing it requires splitting the accumulator and operand into high/low nibbles, adding them with carry, adjusting each nibble if it exceeds 9, and updating the carry flag accordingly, with separate logic paths for addition and subtraction.

_Developers wrestling with CPU emulation edge cases like BCD mode can find similar deep technical guides on daily.dev._

## Similar posts on daily.dev

- [Old Vintage Computing Research: 6o6 v1.1: Faster 6502-on-6502 virtualization for a C64/Apple II Apple-1 emulator](https://daily.dev/posts/old-vintage-computing-research-6o6-v1-1-faster-6502-on-6502-virtualization-for-a-c64-apple-ii-appl-poi3fwxyw) · Two Stop Bits · 1 upvotes · 0 comments
- [Welcome to the machine: emulating a CPU — Bitfield Consulting](https://daily.dev/posts/welcome-to-the-machine-emulating-a-cpu-bitfield-consulting-rggljiotl) · Bitfield Consulting · 20 upvotes · 1 comments
- [Building My Own CPU - Part 3: Just Like the Simulations \(It Was Not Just Like The Simulations\)](https://daily.dev/posts/building-my-own-cpu---part-3-just-like-the-simulations-it-was-not-just-like-the-simulations--us6vslbqv) · Hacker News · 0 upvotes · 0 comments
- [zajo/appler: Apple \]\[ emulator for MS-DOS, written in 8088 assembly](https://daily.dev/posts/zajo-appler-apple-emulator-for-ms-dos-written-in-8088-assembly-xoe8n5s8m) · Two Stop Bits · 0 upvotes · 0 comments
- [Computer-generated dream world](https://daily.dev/posts/computer-generated-dream-world-hspk8igob) · Hacker News · 1 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#retrocomputing](https://daily.dev/tags/retrocomputing)

[View this post on daily.dev](https://daily.dev/posts/emulating-6502-73lxi4alv)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Emulating 6502","url":"https://daily.dev/posts/emulating-6502-73lxi4alv","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/emulating-6502-73lxi4alv"},"datePublished":"2026-08-23T10:20:24.250Z","dateModified":"2026-08-23T10:21:49.566Z","description":"A step-by-step walkthrough builds a MOS 6502 CPU emulator in Python from scratch, covering registers, memory layout, addressing modes, and all 151 opcodes. The...","image":"https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001","thumbnailUrl":"https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001","isAccessibleForFree":true,"articleSection":"zserge's blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"zserge's blog","logo":"https://media.daily.dev/image/upload/s--KQnFBOIT--/f_auto,q_auto/v1787480407/logos/zserge","url":"https://daily.dev/sources/zserge"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/emulating-6502-73lxi4alv","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,retrocomputing","timeRequired":"PT30M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"zserge's blog","item":"https://daily.dev/sources/zserge"},{"@type":"ListItem","position":3,"name":"Emulating 6502"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/emulating-6502-73lxi4alv#faq","mainEntity":[{"@type":"Question","name":"How many opcodes do I need to implement to fully emulate the MOS 6502 CPU?","acceptedAnswer":{"@type":"Answer","text":"A complete MOS 6502 emulator requires implementing 151 individual opcode values, even though the instruction set itself has only 56 distinct instructions. The discrepancy comes from the CPU's multiple addressing modes: the same instruction, like LDA, can be encoded as up to 8 different byte values depending on whether it uses immediate, zero-page, absolute, indexed, or indirect addressing. Developers building retro CPU emulators can find deep-dive walkthroughs like this one on daily.dev."}},{"@type":"Question","name":"What is the memory map layout of an Apple I computer for emulation purposes?","acceptedAnswer":{"@type":"Answer","text":"The Apple I uses 4KB or 8KB of RAM, memory-mapped I/O at addresses like 0xD010 (keyboard input), 0xD011 (key-pressed flag), and 0xD012 (screen output), plus a 256-byte WozMon monitor ROM loaded at 0xFF00-0xFFFF. Interrupt vectors for reset, IRQ, and NMI sit at the very top of the 16-bit address space, near 0xFFFA-0xFFFF. Anyone recreating vintage hardware memory maps can track detailed technical walkthroughs via daily.dev."}},{"@type":"Question","name":"How do you implement BCD (binary-coded decimal) arithmetic for the 6502's ADC and SBC instructions?","acceptedAnswer":{"@type":"Answer","text":"BCD mode treats each byte's two nibbles as separate decimal digits rather than a straight binary value, so adding 0x43 and 0x28 yields 0x71 instead of the binary result 0x6B. Implementing it requires splitting the accumulator and operand into high/low nibbles, adding them with carry, adjusting each nibble if it exceeds 9, and updating the carry flag accordingly, with separate logic paths for addition and subtraction. Developers wrestling with CPU emulation edge cases like BCD mode can find similar deep technical guides on daily.dev."}}]}
```

