Debugging is hard. It would easier with breakpoints. But breakpoints need to be implemented. How?
Well, I can use a RST vector. Say RST 20H.
If I’m running from RAM, I can replace the first byte of all instructions at a break location with RST 20H and then start executing. Then when that’s called, go into breakpoint mode. In breakpoint mode, I need to make the following commands available: set break point (addr) reset break point (bp #) run write register (including sp and pc) dump registers dump mem (addr len)
I should also have support in the UART to go into breakpoint mode from inside getchar().
Step is just where you put a breakpoint on either the next assembly instruction or the first assembly instruction of the next C line, then erase it when done. In the case of conditional branches and returns, it’s a little tricker because they require either 2 breakpoints or evaluation of the condition flag to know where to put the next instruction. Also jp (hl) needs to be managed.
I just have to figure out how to use sdgdb….. Either that or make my own source debugger….