Skip to content

moody-jazz/CPU6502

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPU6502

This is a modular 6502 CPU emulator that can be integrated into emulator projects.
It supports full instruction execution, cycle tracking, and pluggable memory mapping.
A JSON-based test suite is also included to verify correctness.

Features

  • Full 6502 instruction set
  • Cycle accurate execution
  • Opcode argument mapping via opcodedata.txt
  • Abstract memory interface (BaseMemory)
  • JSON-based automated test suite

Integration Steps

1. Add Files

Copy all the files from include and src directory along with opcodedata.txt

2. Implement Memory

#include "basememory.h"

class MyMemory : public BaseMemory {
public:
    MyMemory(uint32_t size) : BaseMemory(size) {}

    uint8_t read(uint16_t addr) override {
        return mainRam_[addr];  // or custom mapping
    }

    void write(uint16_t addr, uint8_t value) override {
        mainRam_[addr] = value; // with mirroring / IO logic
    }
};

3. Initialize CPU

#include "cpu.h"
#include <memory>

int main() {
    std::unique_ptr<BaseMemory> memory = std::make_unique<MyMemory>(0x10000);
    Cpu cpu(std::move(memory));

    cpu.reset();
    cpu.executeInstruction();
    cpu.printInfo();
    return 0;
}

4. Emulation Loop

while (running) {
    cpu.executeInstruction();
    // integrate with graphics, audio, timers, etc.
}

5. Opcode Data

opcodedata.txt defines addressing modes for each opcode:

0x00 implied NA
0x01 indirect X
0x05 zeroPage NA
0x06 zeroPage NA
0x08 implied NA

This is neccessary and used during CPU construction.

6. Testing

  1. Install tests:

    python install_cputests.py

    Creates cpu_test_suit/ and install all the files from SingleStepTests. There are 10,000 test cases for each individual instruction.

  2. Run tests:

    python testcpu.py

    Each test sets CPU state, executes one instruction, and verifies result.

About

6502 CPU emulator

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors