For one of my projects, I need to emulate the WDC 65C02 processor.
In order to ensure everything was working as expected and perform some debugging, I had to develop a small tool to actively disassemble/decompile and display the result (instructions, registers, memory, …).
What is a WDC 65C02?
The WDC 65C02 was made by Western Design Center in 1978 (!).
It is an enhanced version of the MOS 6502, an 8-bit processor designed by Metal Oxide Semiconductor Technology.
The 6502 is a very well know processor used in multiple devices such as the Apple II, Atari 600/800, Atari 2600, Nintendo NES, etc.
The 65C02, at its turn, was used in the Apple IIc/IIe, NEC TurboGrafx-16/PC Engine, Atari Lynx, etc.
It results in a large amount of literature and million of programs and resources. A great playground!
Why write a new one from scratch?
Mainly because I needed to fire test the code I was developing for the main project. And it provides me with a debugger that uses the exact same code.
The resulting shared code between the project and the debugger can then be compiled (debugger) and cross compiled (project).
And more than everything, it was pretty funny to do so.
I miss low-level development sometimes…
I may write a bigger tool later that encompasses all the debugger developments I did for all the various platforms.
A meta debugger, if you wish ^^
How does the tool look like in the end?
What does it do?
Well, using it you can emulate the 65C02, load a program into its memory, run it step by step, put breakpoints, check the resulting state and registers, parse memory bytes, …
It handles auto completion, commands history, working with files (import/export), etc.
And you can even dump the disassembled result into a file:
*$FE00 38 SEC $FE01 80 0A BRA $FE0D $FE03 90 04 BCC $FE09 $FE05 8E 8B FD STX $FD8B $FE08 18 CLC $FE09 E8 INX $FE0A 8E 87 FD STX $FD87 $FE0D A2 02 LDX #$02 $FE0F 8E 87 FD STX $FD87 $FE12 2A ROL A $FE13 9C 8B FD STZ $FD8B $FE16 D0 EB BNE $FE03 $FE18 60 RTS $FE19 64 01 STZ $01 $FE1B A9 00 LDA #$00 $FE1D 91 00 STA ($00),Y $FE1F C8 INY $FE20 D0 FB BNE $FE1D $FE22 E6 01 INC $01 $FE24 D0 F7 BNE $FE1D $FE26 A2 0D LDX #$0D $FE28 BD D8 FF LDA $FFD8,X $FE2B BC CC FF LDY $FFCC,X $FE2E 99 00 FD STA $FD00,Y $FE31 CA DEX $FE32 D0 F4 BNE $FE28 $FE34 BD C1 FE LDA $FEC1,X $FE37 9D 00 50 STA $5000,X $FE3A E8 INX $FE3B D0 F7 BNE $FE34 $FE3D 64 05 STZ $05 [...]
(and a label enabled version is coming soon…)