maziac / DeZog

Visual Studio Code Debugger for Z80/ZX Spectrum.
MIT License
212 stars 35 forks source link

[Question] Is ROM debugging possible? #35

Closed reostat closed 3 years ago

reostat commented 3 years ago

Let's say I had a stock or a custom ROM file e.g. 48.rom with corresponding list file and I wanted to debug it (set breakpoints etc.); how would I go about it? Preferably with CSpect as I can write plugins for it, too.

A bit of context. I'm thinking of building an FPGA-based Z80 machine with custom peripherals. It would also have custom ROM so for example it can load programs from an SD card. My idea is to emulate peripherals with CSpect plugins and use DeZog to debug the ROM. Would it work?

maziac commented 3 years ago

Yes, you should be able to do that.

Simply add a few lines like this to your launch.json:

            "z80asm": [
                {
                    "path": "rom48.list",
                    "srcDirs": []
                }

            ],

It depends if the list file is in an assembler format that can be read by DeZog. If it e.g. starts like

0000    L0000:  DI                      ; Disable Interrupts.  
0001            XOR     A               ; Signal coming from START.  
0002            LD      DE,$FFFF        ; Set pointer to top of possible physical RAM.  
0005            JP      L11CB           ; Jump forward to common code at START-NEW.  

it will most probably be recognized.

However there is currently a small error. Address 0x0000 is not correctly recognized. I.e. the disassembly is shown instead of the list file for address 0.

But, for your goal: why don't you simply develop at ORG 0x8000. I.e. in RAM. Later when everything is working you could change to ROM.

However, how you would make CSpect use your custom I don't know. I'm sure it is possible as it is also loading the 48k ROM. But I haven't done yet.

reostat commented 3 years ago

Hm. I think my confusion comes from a spot in documentation (don't remember where exactly it was) which says that when you start debugging in DeZog, it will upload your current program into emulator. That got me thinking ROM debugging wouldn't be an option.

As for developing new ROM in RAM address space, that's an interesting idea! Although I suspect it will screw up all absolute jumps etc. but I guess it can be mitigated with some assembly macros dance.

maziac commented 3 years ago

"when you start debugging in DeZog, it will upload your current program into emulator" That's the normal case. You can also start without loading any program. Then the ROM has to be loaded somewhere else, e.g. when starting CSpect. DeZog cannot load code into ROM areas of ZEsarUX or CSpect. Because it's ROM. The emulators do not allow that through the interface to DeZog. You can load your code into zsim though, the internal simulator. There it is possible to load code to address 0. But, of course, simulating peripherals is not possible with zsim (I'm working on this, but it will not come soon).