Created
March 12, 2016 20:16
-
-
Save Leandros/9eae69ba027b1c83a9a7 to your computer and use it in GitHub Desktop.
Debugging Messages in no$gmb and BGB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IF !DEF(DEBUG_INC) | |
| DEBUG_INC SET 1 | |
| ; Prints a message to the no$gmb / bgb debugger | |
| ; Accepts a string as input, see emulator doc for support | |
| DBGMSG: MACRO | |
| ld d, d | |
| jr .end\@ | |
| DW $6464 | |
| DW $0000 | |
| DB \1 | |
| .end\@: | |
| ENDM | |
| ENDC ; DEBUG_INC |
__asm blocks can accomplish this in C:
#define DEBUG(message) \
__asm \
ld d, d \
jr .end \
.dw 0x6464 \
.dw 0x0000 \
.ascii message \
.end: \
__endasm
For non-constant strings, they must have a fixed address and bank:
#define DYN_DEBUG(address, bank) \
__asm \
ld d, d \
jr .end \
.dw 0x6464 \
.dw 0x0001 \
.dw address \
.dw bank \
.end: \
__endasm
I tried this:
#include <gb/gb.h>
#include <gb/drawing.h>
// this allows you to debug in BGB
#define DEBUG(message)
__asm \
ld d, d \
jr .end \
.dw 0x6464 \
.dw 0x0000 \
.ascii message \
.end: \
__endasm
// do dynamic debugging with a bank
#define DYN_DEBUG(addr, bank) \
__asm \
ld d, d \
jr .end
.dw 0x6464 \
.dw 0x0001 \
.dw address \
.dw bank \
.end: \
__endasm
void main () {
gotogxy(7, 8);
gprintf("O HAI!");
DEBUG("O HAI");
}and go this error:
demo.c:6: syntax error: token -> '__endasm' ; column 13
make: *** [<builtin>: demo.o] Error 1
I am using gbdk-2020.
@konsumer If you're using gbdk-2020 then you can just #include <gb/bgb_emu.h> and use BGB_MESSAGE.
However, I did forget a couple backslashes. That should be fixed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

It shouldn't matter exactly how you have your development environment set up. Most assemblers use very similar syntax.
I found this documentation on mixing assembly with your C code however I couldn't find any documentation on which assembly syntax they use so you'll have to experiment I guess. I also can't see any support for macros so you might have to write a specific function for each debug message you want.
You'll want to write something like this in your .s (assembly) file for each debug message you want:
As I said, I'm not sure on exactly which compiler directives it has so research how to write data like I have with the
dbdirective.