Skip to content

Debugging

Zal0 edited this page Sep 13, 2021 · 4 revisions

The printf function that comes with the gbdk is ok for small projects but as your code grows you won't be able to use it (actually if you use ZGB you can't use it because it takes a big part of bank 0 that is also required by printf)

Instead you can use the print functions available on Print.h

  • INIT_CONSOLE will activate the Window and place it so that n number of lines ara available for printing (obviously this won't let you use the Window for other things)
  • print_x and print_y will let you set the position where you want to write (take into account that after writing, these vars are automatically updated so you should reset then manually if you want to constantly print a value on the same position). You can update both using DPRINT_POS
  • you will need a font. I have included one that can be used as a placeholder (and stored on bank 3). This font will take the last 45 tiles so if your vram is full you will have a conflict here too.
  • These are the functions available:
    • INIT_CONSOLE: inits the console
    • DPrintf: similar to printf
    • DPRINT_POS: places the printing position
    • DPRINT: places the printing position and prints the string passed as parameter

If you want to debug the position of the SpritePlayer here is what you should do:

  • On StateGame.c:
#include "Print.h"
IMPORT_TILES(font);

...

void START() {
	...
	INIT_CONSOLE(font, 3, 2);
}
  • On SpritePlayer.c
#include "Print.h"

...

void UPDATE() {
	...
	DPRINT_POS(0, 0);
	DPrintf("x:%d y:%d  ", THIS->x, THIS->y);
}

Leaving at least one space at the end of your text is recommented because the Window is never cleaned so previous values might overlap the current ones making it a bit confusing.

One last thing: If you are using build.bat (or your current target in Visual Studio is Release) you won't see anything. You need to compile using build_Debug.bat (or change the Target to Debug on VS). This will create a new rom ending in _Debug.gb. This will ensure none of this code will end in your final rom.

Clone this wiki locally