Close

Simulator

A project log for Dodo: 6502 Game System

Handheld Game System featuring the 6502

peter-noyesPeter Noyes 03/13/2016 at 05:511 Comment

With the hardware all working and tested, and a core set of assembly routines written, the time has come to finally write some games. I have actually made some progress on a game but development is quite annoying. I am writing the software on a Mac, but my EEPROM burner only works on my PC. Currently I build on the Mac, upload to dropbox, download on PC, burn chip, and then I can test.

I finally threw in the towel and decided to see what it would take to simulate Dodo for more rapid development. There are a gazillion 6502 emulators out there. I looked over a few of them and found a very simple one written in C that seemed to be a benchmark referenced by other libraries. I ported it to Go, did a quick and dirty simulation of the screen and via chip and I was able to get my software working. I did run into a few hiccups.

1) Typos: I had two bugs related to typos, in one spot I had a copy/paste problem where I missed switching a cpu.X to cpu.Y. I also missed a << 8.

2) 65C02 op codes: I swear that I configured cc65 to output for vanilla 6502, but apparently it is using some newer opcodes that were not in the C emulator I ported, so I needed to add those.

The C Emulator was developed for emulating a Nintendo which used a custom NMOS 6502. Several changes were introduced when they developed the CMOS version.

As I troubleshooted the simulator it was frustrating because it would mostly work, and I had to analyze the generated assembly to try to guess which opcodes had a problem. Eventually I found a test suite written in 6502 assembly that tests all op codes, I was able to find the typo related bugs using the test suite.

Another annoying problem was getting BCD (Binary Coded Decimal) to work. The Nintendo Emulator did not correctly emulate BCD, probably because the Nintendo chip didn't support it at all. The Klaus test suite tests BCD and to be sure I had everything 100% correct I wanted to make sure it was working in case there were other tests I might be failing after the BCD ones. After a bunch of hacking and looking over how other emulators have implemented it, I finally got it working. I doubt I will ever even use it.

The simulator isn't pretty, but for now it gets the job done and writing a game should now be much more painless.

Simulator in Github

Discussions

Ed S wrote 03/25/2016 at 16:28 point

Big cheer for cracking BCD!

  Are you sure? yes | no