Path tracing Z80 disassembler
There are plenty of Z80 disassemblers available online but every one i've tried just blindly disassembles the file from start to end which is fine if your file contains only program code but usually it will also contain data tables, strings etc so when the disassembler hits one of these data areas it will mistakenly decode the data as program instructions and generate garbage program code. The usual process is to manually look through the output and try to figure out which parts should'nt be code and then mark these sections as data and try disassembling again. This is a real pain and can take multiple attempts to get a garbage free output.
To make this task a little easier I have decided to write a smarter disassembler that will trace through the code following conditional branches, jumps and subroutine calls to automatically map out what is real code and what is data. There are some programming tricks like calculating a jump address at run time that will be impossible to trace and will still need some manual input but I would think that at least 99% of the hard work will be done automatically.
2021-01-22 - v1.04 minor change - improved assembler and trace output generation so hopefully it should be possible to take the generated assembler output file and reassemble it back into code with a Z80 assembler which will be handy if I ever need to make some modifications to original z80 programs.
2021-01-15 - Fixed the issue with linux, it turned out to be a very small thing. The map file parser checks for comment and blank lines and ignores them, the blank line check was only checking for newline '\n' character which was fine for windows but not for linux so I also added a check for return '\r' character and now the program works correctly in both linux and windows. The latest revision can be downloaded here
2021-01-14 - Something odd is happening in linux. If I compile the disassembler in windows using code::blocks it functions correctly but I just tried compiling it in linux with gcc and although it compiles without any warnings or errors it does'nt function correctly when tracing and fails to complete the trace. I need to investigate this.
2021-01-13 - Success at last. I have finished and tripple checked the opcode decoding, its working correctly and although the output is'nt pretty it does prove its all ok. I disassembled my lady bug eprom dump as a test and it looks right, you can view the map input file / trace and asm output files if you like here. I've also included the current source code and a compiled exe for windows command line but I still need to work on tidying the output files and a little tweaking here and there. More updates coming soon.
2021-01-11 - I've put another 5 hours of work into the opcode decoder and all but the extended DD CB XX and FD CB XX opcodes are complete and fully tested, i should have the extended CB XX opcodes ready within a day. The program is fully functional but I have had some ideas to improve the assembler output but thats not important right now. I will be uploading a fully working version of the source code very soon if anybody wants it.
2021-01-07 - OOPS! - I probably wasted around 8 hours in total writing code / making register tables nested within instruction decoding tables with crazy bit masks and ... well it was just overly complex lol, I can see patterns in the Z80 instruction set and have simplified everything by completely throwing out the tables and code and replacing it all with just simple if statements / bit masks. I have'nt completed the full instruction set decoding yet but I have tested the disassembler with what I have so far and it looks like its working, its following conditional branches and call instructions correctly, pushing and popping addresses on the stack. More to do.
2020-12-31 - I put in 2 hours today and have the main framework in place, map file parsing, program counter and stack simulation. I've tested the main program with a dummy disassembler function and everything is working correctly. Everything is now in place and ready for the actual disassembler, I will start with the tables of mnemonics, instruction length, addressing modes, register and flow control and go on from there. I'll update again soon.
2020-12-30 - Started, just sketching out ideas. Bare minimum code written.