Last active
November 18, 2020 01:09
-
-
Save flozz/ac1cd585d2b3486a6579d936ebe967b6 to your computer and use it in GitHub Desktop.
GameBoy BGB Debug Macros (SDCC)
This file contains 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
// BGB Debug -- Help debugging GameBoy programs in BGB | |
// Copyright (c) 2019 Fabien LOISON <https://flozz.fr/> | |
// ==== LICENSE ============================================================== | |
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
// Version 2, December 2004 | |
// | |
// Copyright (C) 2004 Sam Hocevar <[email protected]> | |
// | |
// Everyone is permitted to copy and distribute verbatim or modified | |
// copies of this license document, and changing it is allowed as long | |
// as the name is changed. | |
// | |
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
// | |
// 0. You just DO WHAT THE FUCK YOU WANT TO. | |
// ==== USAGE ================================================================ | |
// This file defines macros to help debugging a GameBoy program in the BGB | |
// emulator: | |
// | |
// Log a message in the BGB console: | |
// | |
// BGB_LOG("your_message"); | |
// | |
// Define a source code breakpoint: | |
// | |
// BGB_BREAK; | |
// | |
// Your program must be compiled with SDCC using the -DDEBUG flag to allow the | |
// macros to work, else nothing will happen :) | |
#ifdef DEBUG | |
#define CONCAT_(A, B, C) A ## B ## C | |
#define CONCAT(A, B, C) CONCAT_(A, B, C) | |
#define LOG_UNIQUE_LABEL CONCAT(42424200, __COUNTER__, $) | |
// Log a message to the BGB console | |
#define BGB_LOG_(LABEL, MESSAGE) \ | |
__asm \ | |
.db 0x52 \ | |
jr LABEL \ | |
.dw 0x6464 \ | |
.dw 0x0000 \ | |
.str MESSAGE \ | |
LABEL: \ | |
__endasm; | |
#define BGB_LOG(MESSAGE) BGB_LOG_(LOG_UNIQUE_LABEL, MESSAGE) | |
// Break in the BGB debugger | |
#define BGB_BREAK \ | |
__asm \ | |
.db 0x40 \ | |
__endasm; | |
#else | |
#define BGB_LOG(MESSAGE) | |
#define BGB_BREAK | |
#endif |
This file contains 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
#include "./bgb_debug.h" | |
void main(void) { | |
BGB_LOG("Hello World"); | |
BGB_BREAK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment