# Champ: Debug, set breakpoints, monitor registers, step though code

Gilbert Francois Duivesteijn

< Back to main page

This page shows how to use Champ for debugging, stepping through code, inspect registers and more. It is by far the most interesting page about champ on this website :) Let's start with typing in some code. Our test code is absolutely useless and does not do much. But it will help to demonstrate all the goodies that Champ has to offer as a complete development tool.

This code example does the following things:

• Initialize an array of 8 bytes in memory, labeled SMILEY with initial value %11110000 = $F0. This value has been chosen, so we can easily find it in memory when inspecting and debugging. • Copies the smiley character from VRAM to RAM at position SMILEY, using the bios function LDIRMV. • Invert the 8 bytes of SMILEY • Return to Basic The program does not give an output to screen. We can only observe the changes with the Champ Debugger.  Type in the listing or download it from the download section on this page. At the end, a ENDPROG label is added. This will help later when saving the binary to cassette. To save the source, go to  mode and type S DBGSRC. You can also download the source file at the bottom of the page, if you don't feel like typing it in yourself. In go to  mode, compile the program with A, 2. Note that the data array of SMILEY starts at $C01D, as shown in the symbol table.

## Set breakpoint

 Bn=addr Set a breakpoint at given address, where n is a number between 1 and 8. E.g. B1=C00C A breakpoint is set just after the copy command from VRAM to RAM. When running the program from the start, it will stop at the breakpoint and show the register and program counter view.

## List breakpoints

 T Show all breakpoints

## Show all labels

 D E000 Show all labels. Every label uses 8 bytes. The first 2 bytes indicate the memory address, the second 6 bytes are filled with the label name. Note that the labels are stored in human readible order (big endian). In the example on the left, we can see our own defined labels SMILEY (at address \$C01D), AGAIN and PRGEND.

## Clear memory, fill memory

 F saddr faddr value Most of the time, it can be helpful to clear the memory, before running the program again. To do that, you can use the fill command F. E.g. if we want to clear the memory, recompile the program, you can do: F C000 C0FF 00