Lots of changes have been pushed into the XGS repository since my last post.
Boot crash fixed
The bug causing the emulation to crash into the system monitor at startup has been fixed. It was not, as I had originally suspected, a CPU emulation bug. Instead it was a bug in the Mega2::buildLanguageCard() method, and a fairly obvious one in retrospect. Turns out it was mapping all sixteen $DnXX logical pages to the same physical page; needless to say this resulted in severe memory corruption!
CPU emulation updates
The latest code makes two major changes to the CPU emulation, though not in any way visible outside the code.
First, there is now a LogicEngineBase class that defines the executeOpcode() method as a virtual method. The LogicEngine template class inherits from this, and so now the emulator just stores a pointer to the current logic engine and calls it directly, instead of using a large set of nested if statements to pick it manually for every opcode. This actually turned out to be just as fast as my original “no virtual functions” implementation, and the code is cleaner too.
Second, the cpuRead and cpuWrite methods now take an extra parameter of type mem_access_t (defined in the M65816/types.h file). This tells the rest of the emulator exactly what a particular memory access is for:
- Instruction fetches
- Opcode fetches
- Stack operations
- Generic data
This was done to facilitate the new debugger, which has been decoupled from the CPU emulation and moved to its own module.
The new debugger
As I mentioned above, the debugger is has been moved out of the M65816 emulation and into its own module. In the new implementation the debugger monitors all calls to cpuRead and cpuWrite, and using the memory access type provided by the CPU it can decode instructions as well as monitor (or even modify!) other memory accesses. I made this change for a couple of reasons:
- Some of the things i want the debugger to eventually do would have required putting a lot of hooks inside M65816. The new debugger design hooks into exactly two places, and since it’s sitting “above” the CPU emulation it has a lot more control.
- I want a graphical UI for the debugger, but I don’t want to make M65816 depend on any GUI libraries.
At the moment the debugger only implements the instruction disassembly from the old version. Additional features will get added once I implement the GUI.