RKb

🇦🇹

6502 Emulator

  • Status: In Progress
  • Started: Wednesday, July 8, 2026
  • Source: GitHub

A software implementation of the MOS 6502 microprocessor written in Rust.


Overview

The goal of this project is to understand how CPUs execute instructions by implementing a 6502 emulator from scratch.

Unlike many simple emulators, this one aims to emulate individual instructions accurately while keeping the implementation clean and easy to understand.


Features


Motivation

I wanted to better understand how processors execute instructions and how machine code interacts with memory.

This project also serves as preparation for building a small operating system and experimenting with computer architecture.


Architecture

           +----------------+
           |      CPU       |
           +-------+--------+
                   |
        +----------+----------+
        |                     |
+-------v------+      +-------v------+
|   Memory     |      |   Registers  |
+--------------+      +--------------+

Instruction Execution

Each instruction follows roughly the same flow:

  1. Fetch opcode.
  2. Decode instruction.
  3. Read operands.
  4. Execute.
  5. Update flags.
  6. Increment program counter.

Example

fn lda(&mut self, value: u8) {
    self.a = value;
    self.update_zero_and_negative_flags(self.a);
}

Current Progress

Component Status
CPU Registers
Memory Bus
Addressing Modes 🚧
Instructions 🚧
Interrupts
Decimal Mode

Problems Encountered

The hardest part wasn't implementing instructions—it was realizing that several instructions behave differently depending on the addressing mode.

Another issue was understanding the processor status flags.


Lessons Learned


Future Improvements


Screenshot

CPU Debugger


Related Lab Entries


References


Source Code

GitHub:

https://github.com/Muhammed-Rajab

Demo:

https://example.com