Hi all,
Those of you that know me are aware that I’m always trying to push the boundaries of what Xojo can do and that I can’t resist re-inventing the wheel. With that being said, I’m pleased to announce a cycle-accurate emulator of the MOS Technology 6502 8-bit CPU written entirely in Xojo code.
What is the 6502?
The 6502 is an 8-bit microprocessor (CPU) that was incredibly popular in the 1980s. It formed the heart of loads of systems you probably love (the Apple II, BBC Micro and the Nintendo Entertainment System to name a few).
What does this project do?
This project emulates the 6502. That is, it takes a memory dump (typically a ROM in the form of bytes) and executes the instructions one after another, adjusting its internal registers and manipulating the memory just like a real-life CPU.
It’s not a full system emulator. This means that there is no graphical output, keyboard handling, sound, etc. These components would also need to be emulated. The CPU however is often the most complex component in a system.
I may consider pushing this project further if there is interest and try to emulate an entire system (probably the Apple II as I have read this is the most straightforward system to mimic).
Project contents
The project is a desktop project that contains a comprehensive test suite that you can run. All 151 opcodes are tested 10,000 times each with different register and memory addresses and compared to this project. That’s right, there are over 1.5 million tests and they all pass so I’m confident this is a high quality emulator.
Usage
It’s best to inspect the code in the project for a full explanation as I have painstakingly documented every property and method and deliberately been verbose in my implementation to make it clear what is happening.
// Default to 64K of memory.
// To do anything useful you'll need to populate the memory with an actual program.
Var mem As New MOS6502.Memory
Var cpu As New MOS6502.CPU(mem)
cpu.Reset
cpu.Execute
I welcome any and all feedback. I hope people find this interesting and that it’s proof that Xojo can do anything another language can do.
The repository is hosted on GitHub.
My other projects can be found here.