RetroDev Delve #1 - Redux

25 April 2025

Since my dive into some 8-bit development, some interesting facts have been brought to my attention by 'bbbbbr', the main developer of GBDK-2020.

RetroDev Delve #1

One of my common pain points was debugging. I was of the opinion that host-side printf-style debugging support would be a handy thing to have in various retro-emulators and, turns out, that some already have it! Both BGB and Emulicious support what's known as 'ld d,d' debug traps and formatted strings, and both are supported in GBDK-2020 (and therefore also CrossZGB).

A printf debug block might look something like this in the source code. The 'ld d,d' instruction and following tag bytes are a signal to the emulator that a debug block has been encountered and it should output a formatted string based on the data pointed to by the HL and DE registers, referencing the format string and format parameters respectively.

ld d,d
jr @end
dw $6464
dw $0200
@end

There are other forms to output fixed strings as well, and a separate 'ld b,b' instruction to trigger an emulator breakpoint.

All very useful.

This style of debugging has it's place. It allows you to output data and code flow with context and watch how they change over time, something that can be difficult with emulators' built-in monitors and debuggers, more so if you are not working in assembly language. Remote step-debuggers are powerful too, but don't always work very well for C code in my experience and generally tie you to Visual Studio Code as an editor.

ld d,d seems to be a standard of sorts and, as far as I can tell, first showed up in the No$GMB (No Cash GameBoy) emulator in the late 1990s. However, there does not seem to be any open source implementation, which is a shame as it would be very useful to incorporate into other emulators.

Perhaps that's a project for the next rainy weekend.

Related Links

No$GMB Emulator
Emulicious Emulator
BGB Emulator
BGB Emulator debugging documentation
GBDK-2020 debugging support header

Tags

amstrad
atari
gameboy
gamedev
nes
retro
spectrum
vic20