10

What techniques were used for implementing breakpoints on the ZX81? Traditionally for the 8086 int 3h is used, for the 8080 on CP/M with DDT RST 7 as single byte replacements, 6502 has the BRK instruction.

I can't figure out what would be used for the ZX81 (or Spectrum) as it's barely possible to hook any of the interrupt vectors.

Obviously this could be done by physical hardware or by single stepping each instruction and intercepting call / jr / jp etc but this would run much slower (but would also allow debugging ROM routines)

Sadly none of the online documentation I can find for the various debuggers / monitors explains how exactly they work. (I suspect from the ZXDB documentation it's using the single step instruction approach)

  • I don't think people used real debuggers natively on those platforms. You either used more primitive techniques or you developed on a more powerful system. Eager to find out otherwise though. Perhaps the CP/M world had real debuggers for Z80? – hippietrail May 10 at 23:40
  • 1
    GENS and MONS existed for the ZX81. They most probably needed a full 16K system. I didn't use them in ZX81 (I didn't own one at the time), but did used them in my Spectrum. – mcleod_ideafix May 11 at 1:12
  • Remember back in those days there were also hardware chip emulators. I used one in a 6809 system. Basically they had a chip shaped module that plugged into the processor socket and all the pins ended up in a rack unit that controlled the emulation. It allowed not only single stepping but full speed emulation and hardware breakpoints. It was also capable of reverse execution as it had gathered all the register state changed on the previous X instructions. – Neil May 11 at 15:11
  • 1
    Man! I sure could use a big old hardware ICE right now... This JTAG ***t is for the birds. – Solomon Slow May 11 at 16:26
10

MONS 3 in the ZX Spectrum, for example, changes the instruction at the break address by a CALL to an entry point in MONS. As MONS is executed, it replaces back the changed instruction with the original one (and of course store in memory the current state of all Z80 registers), so when the disassembler is invoked to give you a assembly listing, you see the original instruction. This can be read from the instruction mannual of MONS 4, availabel at World Of Spectrum https://worldofspectrum.org/pub/sinclair/games-info/h/HiSoftDevpacV4.0.pdf

set a breakpoint in MONS 4

When you opt to execute that instruction and return to MONS (i.e. "trace" that instruction), the CALL is placed at the beginning of the next instruction past the one you broke. Registers are restored and a jump (or a return from subroutine) is made to the former broken instruction, which executes normally, and the next one is again a CALL to MONS, repeating all the process.

Obviously, there is a catch with this method: you cannot trace a program in ROM. AFAIK, MONS3 cannot trace programs in ROM. For that, the debugger should implement a complete Z80 emulator. I don't know of any Z80 debugger that does that.

| improve this answer | |
  • 1
    "I don't know of any Z80 debugger that does that." - the debugger in CHAMP does it by copying the instruction to RAM and single-stepping it, except for certain instructions such as JR and JP which are emulated. I reversed the code and ported it to the Amstrad CPC and Mattel Aquarius (debugger only). – Bruce Abbott May 11 at 11:29
  • And how do you set a breakpoint in ROM with it? (breakpoint, not trace) – mcleod_ideafix May 11 at 23:30
  • 3
    You said "you cannot trace a program in ROM". CHAMP does. It copies the instruction to a buffer, followed by a breakpoint, then executes it. Instructions that might bypass the breakpoint are emulated. This works in RAM and ROM. – Bruce Abbott May 12 at 5:27
  • 1
    Oxford Computer Publishing's "Machine Code Test Tool" was another debugger for the ZX81 and Spectrum that allowed setting breakpoints (again, by inserting a CALL to the debugger at the required location). – john_e May 12 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.