Greetings all,
I've been building on a WDC 65C02 simulation in C/C++ for a little while now, and while it definitely needs more work, I think it's in good enough shape to make known. It's available here:
https://github.com/TheTrueForce/simulieren-6502. Questions and comments are welcome.
This passes most of Klaus' NMOS 6502 test suite, with the exception of the decimal mode tests, and the BRK test.
I've determined that the BRK test fails because I've implemented the 'C02 version of BRK, which behaves slightly differently to the NMOS one.
Decimal mode failing is probably because it doesn't handle decimal mode in quite the same way as the actual hardware. Simulieren converts the addends to binary, adds, and then converts back to BCD. I gather that real hardware just adds and then does some sort of adjustment on the result. Decimal-mode SBC is completely out the window, because I've implemented SBC as ADC, but with an inverted input. This works for binary mode, but obviously does not for BCD.
It does not pass many of the 'C02 tests, however, and seems to hang before completing the whole battery, for some reason. Like I said, it needs more work.
My approach with this has been to make it simulate the 'C02 only, and not concern myself with cycle-accuracy. There are two routines that are not implemented in the simulation, and these are to read and write memory. There are calls available to whatever is hosting the sim, to reset the simulated MPU, have it execute the next instruction, and send interrupts. Because this is written in C, the registers can be accessed from other modules using an extern declaration. (Simulieren is written in C, but it's a .cpp file because the Arduino uses C++, and I didn't want to bother having to deal with interfacing C to C++).
I made this because I still haven't given up on trying to make a 65xxx-based handheld, but I've also gotten fed up with trying to design around certain properties of the hardware in question.
The '816s multiplexed data bus, the lack of interfaces of the '265, WinCUPL being ancient, broken and painful are the main ones. The fact that dedicated SPI hardware simply does not exist is also very irritating, because I plan to use that as my main internal and external expansion interface, and bit-banging something that central is just unacceptable to me.
I have an Arduino Due available, which has on it a SAM3X8E. This is an ARM-based microcontroller with 96KB of RAM, 512KB of Flash, and a large suite of very nice peripherals. If I could drop an '816 core into that in place of the ARM, I suspect it would be a very, very nice machine for my purpose. I can't replace the ARM core, but I can program it to simulate a 65C02(probably an '816 as well, but I haven't tried that yet.)
But regardless, I'm going to build Ittiara 4 around an Arduino Due, and this is the core of that but since it's likely to be useful for so much more than just that(especially when I've worked out the kinks), I've made it public so it can at least be inspected. I can't guarantee its usefulness, or that I'll work on it with any sort of regularity(Life takes precedence), but I've got it into a state that I think is somewhat acceptable.
This is my effort. I hope it's useful and acceptable, and I plan for it to become better.
EDIT to add the URL. Many thanks to BigEd for pointing out its absence.