User Tools

Site Tools


development:csdk:2.0:debugging

Debugging your Program

The GameTank emulator contains a few tools to debug your program:

  • The VRAM Viewer allows to check what is actually loaded in VRAM
  • The Memory Browser allows to look at the RAM. Its Variables tab allows to see the value of any global variable defined in C
  • The Code Stepper allows to set breakpoints and execute your program instruction by instruction
  • The Profiler allows to see how much time is being spent by the blitter and the CPU for each screen refresh. In order to keep a 60 FPS animation, the bar shown in the screen should stay well below 1

Setting Breakpoints

Setting breakpoints in Code Stepper isn't always easy when the program was written in C. Here is a tip to create breakpoints:

  • Define an empty breakpoint() function
  • Call that function in the areas of your code that need debugging
  void breakpoint() {}
  
  int main () {
     ...
     breakpoint();
     // Doing some stuff that needs to be debugged
     ...
  }
  • In the Code Stepper, set a breakpoint on _breakpoint (don't forget to enable breakpoints)
  • Step out of the breakpoint() function
  • Step out of the interrupt handler function
  • You should now be right where you want to be

Assembly to C

In order to better understand how the assembly code shown in the Code Stepper relates to the original C code:

  • Update the makefile and add –add-source to the CFLAGS value
  • Run make build/main.si
  • Open build/main.si. The original C lines will be inserted as comments, e.g.
;
; if (tile_val & 0x20) {
;
L000D:	lda     _tile_val
	and     #$20
	beq     L000E
;
; tmp = 1;
;
	lda     #$01
	sta     _tmp
development/csdk/2.0/debugging.txt · Last modified: 2024/11/20 22:03 by clyde