Interactive Z80 Debugger

Launching the Debugger

To open the debugger, simply click on the debugger icon in the main window toolbar. The debugger window will appear.

Fig. 4: Debugger Window

The debugger window allows access to all the debugger's functions. These are discussed in turn below.

Z80 Code Disassembly

The debugger allows you to display partially disassembled Z80 code for any instructions that the processor has already run. To disassemble a section of memory, press the disassemble button. The following dialogue box will appear:

Fig. 5: Disassembly Range Dialogue Box

To produce the disassembly, simply enter the position in memory you wish to start from, and how many bytes of code should be disassembled, then press OK. The disassembled code appears in the leftmost text box in the debugger window.

Note that the code produced by the disassembler is not complete Z80 source code, it shows only the addresses of the instructions and the instruction type, not the actual operands. This is due to the nature of the processor simulation, as no part of the emulator ever knows enough about an instruction to produce a completely disassembled version.

You can highlight sections of text in the window and use the normal keystrokes for your system to copy them to the clipboard.

Memory Dump

You can use the debugger to view sections of the Spectrum's memory. To dump an area of memory, press the dump button; the following dialogue box appears:

Fig. 6 Dump Range Dialogue Box

To dump the section of memory you are interested in, enter its start location and the number of bytes you wish to view, then click OK. Note that the Spectrum has only 64k of address-space (16k ROM, 16k RAM), so your values must be in this range, or else an error message will occur.

The memory contents is displayed in the rightmost text panel in the debugger window. It is displayed as hex pairs and ASCII (which is the internal character representation scheme of the Spectrum). Again, you may copy and paste this text.

Register Views

The debugger allows you to view the contents of the internal processor registers of the Z80. You may view the contents at any time by pressing the "Get Reg. Values" button. The Z80 has two sets of registers which may be swapped by software; to view the alternate set, check the "View Alternate Registers" check-box.

The registers are displayed in pairs, for example: HL: 0x0123 means that the H register is equal to 01 and the L register is equal to 23. Next to each register pair (except the index registers) is the value pointed to by that pair, so, in our example above, it would be the (16 bit word) contained in memory location 0123.

The register value display is also updated automatically by the interactive-mode controls (see below).

Interactive Mode

This mode allows the user to interactively control the Z80 CPU. To enter interactive mode, check the check-box. The controls to the right of the check-box will become active, and the emulation will freeze.

In this mode, the Z80 CPU does nothing until prompted, nor does the screen update.

There are two buttons which allow stepping through the program. These are the "Step" and "Frame Advance" buttons. Step runs one instruction each time the button is pressed. This allows the user to view the execution of the program and the contents of the registers, in order to find bugs or see how a program works. The frame advance feature runs the processor for 69888 T-States (one frame's worth), generates an interrupt and updates the display. This is useful to jump straight into interrupt handler code, and also to see how the screen changes with each frame.

The other feature available in interactive mode is the setting of break points. If a break point is set, then the "Run to Break" button is active, otherwise press the "Set Break" button to bring up the following dialogue box:

Fig. 7: Set Breakpoint Dialogue Box

The break point field specifies a memory location at which the processor will stop execution. This must be the start address of in instruction, otherwise the processor will not halt.

The other field specifies the maximum number of instructions that can be executed before the processor will halt anyway. This allows a "get-out" in case the break point is never reached. Setting this value to 0 will mean that the processor halts only at the specified break point - if this break point is not reached, then the run to break will never end.

To exit interactive mode, and restart the processor, uncheck the check-box.

Quitting the Debugger

The debugger can run in parallel with the emulator, however, if you want to exit it, simply close the window in the normal way for your platform.