6502 Emulator

A cycle-accurate MOS Technology 6502 CPU emulator written entirely in Xojo.

Repository

https://github.com/gkjpettet/6502-Emulator

Background

What do the Apple II, BBC Micro and the Nintendo Entertainment System (NES) all have in common? Apart from stealing a lot of people's childhoods with blissful gaming joy, they were all powered by the 6502 CPU. Having been fascinated by emulation (the concept of mimicking hardware through software) for many years, I decided to write a CPU emulator to better learn about how a microprocessor works on the inside.

Most emulator "experts" advise newcomers to the scene to emulate an 8-bit CPU for their first project and the biggest contenders are the 6502 and the Z80 (of GameBoy and Amstrad CPC fame). I went with the 6502 because it has fewer opcodes (only 151) and an excellent test suite for the instructions is readily available.

About

The repo contains a desktop Xojo project that runs 1.5 million tests on the CPU. The CPU is a single class (CPU) within the MOS6502 module. The CPU expects a Memory class upon instantiation. The Memory class is essentially just a wrapper around an array of bytes. To make the emulator do anything "useful" you'll need to populate its memory with meaningful code (for instance, the contents of a ROM).

Usage

Var mem As New MOS6502.Memory // Defaults to 64K of empty memory.
Var cpu As New MOS6502.CPU(mem)
cpu.Reset
cpu.Execute

Of course to make the CPU do something visually interesting it needs to be part of a system. If there's enough interest I might consider pushing this project further and implementing a system emulator based around this CPU (I hear the Apple II or the BBC Micro are easier to emulate than the NES). For the time being however, I'm just satisfied that I've learned enough about binary maths to get this up and running.