dromaius816 - a new 65816 emulator
Posted: Thu Feb 06, 2025 3:12 pm
Short story: I have just started working on a half-cycle exact 65816 emulator.
Long story: New year, new project—it seems I did it again.
This is my first post in the Emulation board. In fact, this is my first attempt at emulation. So, once again, the beginning of a long journey, it seems. Some of you may know me from my main project, 74HCT6526, a discrete implementation of the MOS6526. That project is currently on a longer-than-expected break (14 months now, with at least 6 more to go) as my new house (and with it, my new lab) is still under construction.
To keep my mind busy during this time, I started working on a computer based on the 65816. I needed a new challenge, and having no experience with this CPU, it seemed like the perfect choice.
And that brings us to today. With no experience and no lab, I thought having an emulator for my computer would be useful. I’ve seen several people build emulators for their own projects, and given my current situation, a project that requires nothing more than a laptop and coffee is exactly what I need.
After some research, I came across this 6502 emulator called Dromaius. It’s quite low-level and capable of emulating a Commodore PET. I could have looked for an existing 65816 emulator, but if I manage to adapt this project and create a 65816 version, I will gain an incredible amount of knowledge about the CPU.
So far, I’ve managed to extract the core from the original project and create a basic barebones version of my own. I’ve more or less figured out how it works, and it seems quite clever to me.
The core of the emulator is built around chips, signals, and devices. Chips represent, well, chips. Each has a list of pins, some of which trigger an emulation "process," and each has a scheduled next operation time. Take the clock source, for example—it has only an output pin, and when it "ticks," a new process is scheduled for half a cycle later. There’s a thread continuously running that checks all chips' scheduled processes, so when one is due, the chip’s outputs are recalculated.
The 6502 is implemented as a special type of chip called, unsurprisingly, "cpu." Each change on its clock input triggers a process, and to model certain CPU delays (such as the time until the address is valid), its next process is scheduled for the exact delay after the corresponding clock edge.
Signals represent connections between chips. A device is a collection of chips and signals, making it, effectively, an emulated computer. When created, the device spawns a new thread that runs the emulation in an infinite loop. It’s not the fastest emulator ever—it can emulate a PET at about 600–700 kHz on my (three-year-old Ryzen 7) computer.
My project is not yet public on GitHub. It’s only four days old, and right now, it's a mess. It will be public soon enough, as I'm currently cleaning up the code before making an even bigger mess.
As usual, I’m starting this thread to share my progress—and to remind myself that I have work to do.
Cheers!
Long story: New year, new project—it seems I did it again.
This is my first post in the Emulation board. In fact, this is my first attempt at emulation. So, once again, the beginning of a long journey, it seems. Some of you may know me from my main project, 74HCT6526, a discrete implementation of the MOS6526. That project is currently on a longer-than-expected break (14 months now, with at least 6 more to go) as my new house (and with it, my new lab) is still under construction.
To keep my mind busy during this time, I started working on a computer based on the 65816. I needed a new challenge, and having no experience with this CPU, it seemed like the perfect choice.
And that brings us to today. With no experience and no lab, I thought having an emulator for my computer would be useful. I’ve seen several people build emulators for their own projects, and given my current situation, a project that requires nothing more than a laptop and coffee is exactly what I need.
After some research, I came across this 6502 emulator called Dromaius. It’s quite low-level and capable of emulating a Commodore PET. I could have looked for an existing 65816 emulator, but if I manage to adapt this project and create a 65816 version, I will gain an incredible amount of knowledge about the CPU.
So far, I’ve managed to extract the core from the original project and create a basic barebones version of my own. I’ve more or less figured out how it works, and it seems quite clever to me.
The core of the emulator is built around chips, signals, and devices. Chips represent, well, chips. Each has a list of pins, some of which trigger an emulation "process," and each has a scheduled next operation time. Take the clock source, for example—it has only an output pin, and when it "ticks," a new process is scheduled for half a cycle later. There’s a thread continuously running that checks all chips' scheduled processes, so when one is due, the chip’s outputs are recalculated.
The 6502 is implemented as a special type of chip called, unsurprisingly, "cpu." Each change on its clock input triggers a process, and to model certain CPU delays (such as the time until the address is valid), its next process is scheduled for the exact delay after the corresponding clock edge.
Signals represent connections between chips. A device is a collection of chips and signals, making it, effectively, an emulated computer. When created, the device spawns a new thread that runs the emulation in an infinite loop. It’s not the fastest emulator ever—it can emulate a PET at about 600–700 kHz on my (three-year-old Ryzen 7) computer.
My project is not yet public on GitHub. It’s only four days old, and right now, it's a mess. It will be public soon enough, as I'm currently cleaning up the code before making an even bigger mess.
As usual, I’m starting this thread to share my progress—and to remind myself that I have work to do.
Cheers!