Skip to content

About

A C++ emulator of the MOS 6502 8-bit microprocessor, exploring CPU instruction execution, memory addressing, hardware devices and computer architecture.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

MOS 6502 Emulator

A C++ implementation of an emulator for the MOS 6502, the 8-bit microprocessor used in systems such as the Apple II, Commodore 64 and Nintendo Entertainment System.

The project explores CPU architecture, instruction execution, memory addressing and hardware emulation by implementing the processor and the components around it.

Current implementation

The emulator is a work in progress. The current implementation includes:

  • CPU: Processor registers, status flags, instruction decoding and execution.
  • Instruction set: A subset of 6502 instructions covering register operations, memory access, stack operations, jumps, subroutine calls and interrupts.
  • Memory bus: Address-based device mapping, allowing the CPU to communicate with attached hardware.
  • RAM and ROM: Memory device abstractions connected through the bus.
  • Peripheral structure: Initial PPU device implementation.

The CPU currently supports instructions including LDA, LDX, LDY, STA, STX, STY, TAX, TAY, PHA, PLA, JMP, JSR, RTS, BRK, RTI and NOP.

This is not yet a complete or cycle-accurate 6502 implementation.

Architecture

The emulator separates processor execution from memory and device access.

              ┌──────────────┐
              │     CPU      │
              │              │
              │ Registers    │
              │ Instructions │
              │ Execution    │
              └──────┬───────┘
                     │
              ┌──────▼───────┐
              │     Bus      │
              │              │
              │ Address map  │
              │ Read / Write │
              └──────┬───────┘
                     │
          ┌──────────┼──────────┐
          │          │          │
     ┌────▼───┐ ┌────▼───┐ ┌────▼───┐
     │  RAM   │ │  ROM   │ │  PPU   │
     └────────┘ └────────┘ └────────┘

The bus maps address ranges to devices. The CPU interacts with memory and peripherals through the same read and write interface, keeping device access separate from instruction execution.

Building

Requirements

  • C++17-compatible compiler
  • CMake 3.31 or later
  • Make or another supported CMake build tool

Compile

Clone the repository:

git clone https://github.com/brandon-kyle-bailey/mos-6502-emulator.git
cd mos-6502-emulator

Configure and build:

cmake -S . -B build
cmake --build build

Run

./build/app

The current executable runs a small demonstration program that executes 6502 instructions and writes a string into emulated memory.

Project structure

.
├── include/
│   ├── bus/          # Memory bus interfaces
│   ├── cpu/          # CPU and ALU interfaces
│   └── devices/      # RAM, ROM and PPU interfaces
├── src/
│   ├── bus/          # Memory bus implementation
│   ├── cpu/          # Instruction execution
│   ├── devices/      # Hardware device implementations
│   └── main.cpp      # Emulator entry point
├── CMakeLists.txt
└── README.md

Resources

About

A C++ emulator of the MOS 6502 8-bit microprocessor, exploring CPU instruction execution, memory addressing, hardware devices and computer architecture.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages