gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit f6432035ca7acd7aa378340c6eeb30b2e022223c parent 545244841712f069677027b960561677dc1eadd5 Author: Toxa <untoxa@mail.ru> Date: Sat, 24 Jul 2021 12:28:18 +0300 reworked bgb_emu.h macros and bgb_debug.c example Diffstat:
| M | gbdk-lib/examples/gb/bgb_debug/Makefile | 2 | +- |
| M | gbdk-lib/examples/gb/bgb_debug/bgb_debug.c | 23 | +++++++++++------------ |
| M | gbdk-lib/include/gb/bgb_emu.h | 56 | +++++++++++++++++++++++++++++++++++++------------------- |
3 files changed, 49 insertions(+), 32 deletions(-)
diff --git a/gbdk-lib/examples/gb/bgb_debug/Makefile b/gbdk-lib/examples/gb/bgb_debug/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -Wa-l -Wl-m -Wl-j -Wm-yc +CC = ../../../bin/lcc -Wl-m -Wl-j -Wm-yS -Wm-yc BINS = bgb_debug.gb diff --git a/gbdk-lib/examples/gb/bgb_debug/bgb_debug.c b/gbdk-lib/examples/gb/bgb_debug/bgb_debug.c @@ -17,7 +17,7 @@ // // See the BGB Manual for more information // ("expressions, breakpoint conditions, and debug messages") -// https://bgb.bircd.org/manual.html#expressions +// http://bgb.bircd.org/manual.html#expressions int main(void) { @@ -31,6 +31,7 @@ int main(void) printf("Message to the \nGameBoy screen\n"); // Log a message to the BGB debug message window + BGB_MESSAGE(""); // new line BGB_MESSAGE("Message to the BGB console"); // ==== Normal Speed Mode ==== @@ -43,12 +44,11 @@ int main(void) // You should see the message "NOP TIME: 2". // // So in this case, divide the printed value by 2 = The NOP took "1" cycle - BGB_MESSAGE("Profile a single NOP instruction at Normal Speed"); - + __critical { // Temporarily turn off interrupts for more accurate measurements - BGB_PROFILE_BEGIN(); + BGB_PROFILE_BEGIN("Profile a single NOP instruction at Normal Speed"); __asm__("nop"); - BGB_PROFILE_END(NOP TIME); + BGB_PROFILE_END("NOP TIME:"); } @@ -73,14 +73,13 @@ int main(void) // divide by 2 to get the cycle count. // // You should see the message "NOP TIME: 1". - BGB_MESSAGE("Profile a single NOP instruction at Double Speed"); __critical { // Temporarily turn off interrupts for more accurate measurements - BGB_MESSAGE("%ZEROCLKS%"); + BGB_PROFILE_BEGIN("Profile a single NOP instruction at Double Speed"); __asm__("nop"); // The "-4+" subtracts 4 clocks to compensate for the ones // used by the debug message itself (Normal speed uses -8) - BGB_MESSAGE("NOP TIME: %-4+LASTCLKS%"); + BGB_MESSAGE("NOP TIME:%-4+LASTCLKS%"); } // Return the CGB to normal speed @@ -88,18 +87,17 @@ int main(void) } - BGB_MESSAGE("Profile code in a loop"); __critical { // Temporarily turn off interrupts for more accurate measurements // Profile code in a loop - BGB_PROFILE_BEGIN(); + BGB_PROFILE_BEGIN("Profile code in a loop"); for(c=0; c<5; c++) { // Do something printf("%d\n", c); } // Elapsed cycle count output is in hex. // Remember to divide by 2 for the result (Normal Speed) - BGB_PROFILE_END(LOOP TIME); + BGB_PROFILE_END("LOOP TIME:"); } @@ -113,6 +111,7 @@ int main(void) // Which Banks are currently active (for MBC based cartridges) BGB_MESSAGE("Current ROM bank: %ROMBANK%"); + BGB_MESSAGE("Current XRAM bank: %XRAMBANK%"); BGB_MESSAGE("Current SRAM bank: %SRAMBANK%"); // These are only banked in the CGB BGB_MESSAGE("Current VRAM bank: %VRAMBANK%"); @@ -138,7 +137,7 @@ int main(void) BGB_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); // The BGB_TEXT() macro will accept a non-quoted string - BGB_TEXT(The End); + BGB_TEXT("The End"); return 0; } diff --git a/gbdk-lib/include/gb/bgb_emu.h b/gbdk-lib/include/gb/bgb_emu.h @@ -12,11 +12,6 @@ #ifndef __BGB_EMU_INCLUDE #define __BGB_EMU_INCLUDE -/// \cond DOXYGEN_DO_NOT_DOCUMENT -#define BGB_ADD_DOLLARD(A) BGB_ADD_DOLLARD1 (A) -#define BGB_ADD_DOLLARD1(A) A##00$ -/// \endcond DOXYGEN_DO_NOT_DOCUMENT - /** Macro to display a message in the BGB emulator debug message window @param message_text Quoted text string to display in the debug message window @@ -40,16 +35,37 @@ @see BGB_PROFILE_BEGIN(), BGB_PROFILE_END() */ -#define BGB_MESSAGE(message_text) BGB_MESSAGE1(BGB_ADD_DOLLARD(__LINE__), message_text) +#define BGB_MESSAGE(message_text) BGB_MESSAGE1(BGB_MACRONAME(__LINE__), message_text) /// \cond DOXYGEN_DO_NOT_DOCUMENT -#define BGB_MESSAGE1(lbl, message_text) \ +#define BGB_MACRONAME(A) BGB_MACRONAME1(A) +#define BGB_MACRONAME1(A) BGBLOG##A + +#define BGB_MESSAGE1(name, message_text) \ +__asm \ +.MACRO name msg_t, msg_s, ?llbl\ + ld d, d \ + jr llbl \ + .dw 0x6464 \ + .dw 0x0000 \ + .ascii msg_t \ +llbl: \ +.ENDM \ +name ^/message_text/ \ +__endasm + +#define BGB_MESSAGE_SUFFIX(message_text, message_suffix) BGB_MESSAGE3(BGB_MACRONAME(__LINE__), message_text, message_suffix) +#define BGB_MESSAGE3(name, message_text, message_suffix) \ __asm \ +.MACRO name msg_t, msg_s, ?llbl\ ld d, d \ - jr lbl \ + jr llbl \ .dw 0x6464 \ .dw 0x0000 \ - .ascii message_text \ -lbl: \ + .ascii msg_t \ + .ascii msg_s \ +llbl: \ +.ENDM \ +name ^/message_text/, ^/message_suffix/ \ __endasm #define BGB_HASH # @@ -74,33 +90,35 @@ __endasm @see BGB_MESSAGE() */ -#define BGB_MESSAGE_FMT(buf, ...) sprintf(buf, __VA_ARGS__);BGB_MESSAGE2(BGB_ADD_DOLLARD(__LINE__), BGB_MAKE_LABEL(_##buf)); +#define BGB_MESSAGE_FMT(buf, ...) sprintf(buf, __VA_ARGS__);BGB_MESSAGE2(BGB_MACRONAME(__LINE__), BGB_MAKE_LABEL(_##buf)); /// \cond DOXYGEN_DO_NOT_DOCUMENT #define BGB_MESSAGE2(lbl, buf) \ __asm \ +.MACRO name buf, ?llbl\ ld d, d \ - jr lbl \ + jr llbl \ .dw 0x6464 \ .dw 0x0001 \ .dw buf \ .dw 0 \ -lbl: \ +llbl: \ +.ENDM \ +name ^/buf/ \ __endasm -#define BGB_STR(A) #A -#define BGB_CONCAT(A,B) BGB_STR(A:B) /// \endcond DOXYGEN_DO_NOT_DOCUMENT /** Macro to __Start__ a profiling block for the BGB emulator - @param MSG Quoted text string to display in the debug message window + @param MSG Quoted text string to display in the + debug message window along with the result To complete the profiling block and print the result call @ref BGB_PROFILE_END. @see BGB_PROFILE_END(), BGB_MESSAGE() */ -#define BGB_PROFILE_BEGIN(MSG) BGB_MESSAGE(BGB_CONCAT(MSG,%ZEROCLKS%)); +#define BGB_PROFILE_BEGIN(MSG) BGB_MESSAGE_SUFFIX(MSG, "%ZEROCLKS%"); /** Macro to __End__ a profiling block and print the results in the BGB emulator debug message window @param MSG Quoted text string to display in the @@ -126,8 +144,8 @@ __endasm @see BGB_PROFILE_BEGIN(), BGB_MESSAGE() */ -#define BGB_PROFILE_END(MSG) BGB_MESSAGE(BGB_CONCAT(MSG,%-8+LASTCLKS%)); -#define BGB_TEXT(MSG) BGB_MESSAGE(BGB_STR(MSG)) +#define BGB_PROFILE_END(MSG) BGB_MESSAGE_SUFFIX(MSG,"%-8+LASTCLKS%"); +#define BGB_TEXT(MSG) BGB_MESSAGE(MSG) /** Display preset debug information in the BGB debug messages window.
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.