git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 9715970cc68e14a292af738ad595416b494258ef
parent 37488731bae42837d41a38adae571e05b0ff96e7
Author: bbbbbr <bbbbbr@users.noreply.github.com>
Date:   Sat,  5 Mar 2022 23:05:17 -0800

Merge pull request #328 from bbbbbr/feature_sms_gg_emudebug

Emu Debug: Move header into common gbdk folder
Diffstat:
Mdocs/pages/08_faq.md4++++
Mgbdk-lib/examples/cross-platform/emu_debug/src/emu_debug.c10++++++++--
Mgbdk-lib/include/gb/bgb_emu.h2+-
Mgbdk-lib/include/gb/emu_debug.h165++-----------------------------------------------------------------------------
Mgbdk-lib/include/gbdk/emu_debug.h169++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 185 insertions(+), 165 deletions(-)

diff --git a/docs/pages/08_faq.md b/docs/pages/08_faq.md @@ -49,6 +49,10 @@ See the section @ref setting_mbc_and_rom_ram_banks for more details. <!-- --> + - What do the following kinds of warnings / errors mean? + `info 218: z80instructionSize() failed to parse line node, assuming 999 bytes` + - This is a known issue with SDCC, it should not cause actual problems and you can ignore the warning. <!-- --> + - Why is the compiler so slow, or why did it suddenly get much slower? - This may happen if you have large initialized arrays declared without the `const` keyword. It's important to use the const keyword for read-only data. See @ref const_gbtd_gbmb and @ref const_array_data <!-- --> diff --git a/gbdk-lib/examples/cross-platform/emu_debug/src/emu_debug.c b/gbdk-lib/examples/cross-platform/emu_debug/src/emu_debug.c @@ -18,6 +18,11 @@ // ("expressions, breakpoint conditions, and debug messages") // https://bgb.bircd.org/manual.html#expressions +// If you see a message like the following, it is safe to ignore. It is a known +// issue with SDCC and should not cause problems. +// +// " src/emu_debug.c:156: info 218: z80instructionSize() failed to parse line node, assuming 999 bytes ' llbl:' + int main(void) { SHOW_BKG; @@ -82,6 +87,8 @@ int main(void) // Return the CGB to normal speed cpu_slow(); } + #endif // NINTENDO + __critical { // Temporarily turn off interrupts for more accurate measurements @@ -97,7 +104,6 @@ int main(void) // Remember to divide by 2 for the result (Normal Speed) EMU_PROFILE_END("LOOP TIME:"); } - #endif // NINTENDO // ==== Some other things you can print ==== @@ -144,7 +150,7 @@ int main(void) EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); #elif defined(SEGA) - EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%ROMBANK%,%WRAMBANK%"); + EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); #endif uint8_t var0 = 16; diff --git a/gbdk-lib/include/gb/bgb_emu.h b/gbdk-lib/include/gb/bgb_emu.h @@ -8,6 +8,6 @@ #ifndef __BGB_EMU_INCLUDE #define __BGB_EMU_INCLUDE -#include <gb/emu_debug.h> +#include <gbdk/emu_debug.h> #endif diff --git a/gbdk-lib/include/gb/emu_debug.h b/gbdk-lib/include/gb/emu_debug.h @@ -1,170 +1,13 @@ /** @file gb/emu_debug.h - Debug window logging and profiling support for emulators (BGB, Emulicious, etc). - - Also see the `emu_debug` example project included with gbdk. - - See the BGB Manual for more information - ("expressions, breakpoint conditions, and debug messages") - http://bgb.bircd.org/manual.html#expressions + Shim for legacy use of @ref gb/emu_debug.h which has been + migrated to @ref gbdk/emu_debug.h + See the `emu_debug` example project included with gbdk. */ #ifndef __EMU_DEBUG_INCLUDE #define __EMU_DEBUG_INCLUDE -#include <types.h> - -/** Macro to display a message in the emulator debug message window - - @param message_text Quoted text string to display in the debug message window - - The following special parameters can be - used when bracketed with "%" characters. - \li CPU registers: AF, BC, DE, HL, SP, PC, B, C, D, - E, H, L, A, ZERO, ZF, Z, CARRY, CY, IME, ALLREGS - \li Other state values: ROMBANK, XRAMBANK, SRAMBANK, - WRAMBANK, VRAMBANK, TOTALCLKS, LASTCLKS, CLKS2VBLANK - - Example: print a message along with the currently active ROM bank. - \code{.c} - EMU_MESSAGE("Current ROM Bank is: %ROMBANK%"); - \endcode - - - See the BGB Manual for more information - ("expressions, breakpoint conditions, and debug messages") - http://bgb.bircd.org/manual.html#expressions - - @see EMU_PROFILE_BEGIN(), EMU_PROFILE_END() - */ -#define EMU_MESSAGE(message_text) EMU_MESSAGE1(EMU_MACRONAME(__LINE__), message_text) -#define BGB_MESSAGE(message_text) EMU_MESSAGE(message_text) - -/// \cond DOXYGEN_DO_NOT_DOCUMENT -#define EMU_MACRONAME(A) EMU_MACRONAME1(A) -#define EMU_MACRONAME1(A) EMULOG##A - -#define EMU_MESSAGE1(name, message_text) \ -__asm \ -.MACRO name msg_t, ?llbl\ - ld d, d \ - jr llbl \ - .dw 0x6464 \ - .dw 0x0000 \ - .ascii msg_t \ -llbl: \ -.ENDM \ -name ^/message_text/ \ -__endasm - -#define EMU_MESSAGE_SUFFIX(message_text, message_suffix) EMU_MESSAGE3(EMU_MACRONAME(__LINE__), message_text, message_suffix) -#define EMU_MESSAGE3(name, message_text, message_suffix) \ -__asm \ -.MACRO name msg_t, msg_s, ?llbl\ - ld d, d \ - jr llbl \ - .dw 0x6464 \ - .dw 0x0000 \ - .ascii msg_t \ - .ascii msg_s \ -llbl: \ -.ENDM \ -name ^/message_text/, ^/message_suffix/ \ -__endasm -/// \endcond DOXYGEN_DO_NOT_DOCUMENT - -/** Macro to __Start__ a profiling block for the emulator (BGB, Emulicious, etc) - - @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 EMU_PROFILE_END. - - @see EMU_PROFILE_END(), EMU_MESSAGE() - */ -#define EMU_PROFILE_BEGIN(MSG) EMU_MESSAGE_SUFFIX(MSG, "%ZEROCLKS%"); -#define BGB_PROFILE_BEGIN(MSG) EMU_PROFILE_BEGIN(MSG) -/** Macro to __End__ a profiling block and print the results in the emulator debug message window - - @param MSG Quoted text string to display in the - debug message window along with the result - - This should only be called after a previous call - to @ref EMU_PROFILE_BEGIN() - - The results are in Emulator clock units, which are - "1 nop in [CGB] doublespeed mode". - - So when running in Normal Speed mode (i.e. non-CGB doublespeed) - the printed result should be __divided by 2__ to get the actual - ellapsed cycle count. - - If running in CB Double Speed mode use the below call instead, - it correctly compensates for the speed difference. In this - scenario, the result does __not need to be divided by 2__ to - get the ellapsed cycle count. - \code{.c} - EMU_MESSAGE("NOP TIME: %-4+LASTCLKS%"); - \endcode - - @see EMU_PROFILE_BEGIN(), EMU_MESSAGE() - */ -#if defined(NINTENDO) -#define EMU_PROFILE_END(MSG) EMU_MESSAGE_SUFFIX(MSG,"%-8+LASTCLKS%"); -#define BGB_PROFILE_END(MSG) EMU_PROFILE_END(MSG) -#elif defined(SEGA) -#define EMU_PROFILE_END(MSG) EMU_MESSAGE_SUFFIX(MSG,"%-16+LASTCLKS%"); -#define BGB_PROFILE_END(MSG) EMU_PROFILE_END(MSG) -#endif - -#define EMU_TEXT(MSG) EMU_MESSAGE(MSG) -#define BGB_TEXT(MSG) EMU_TEXT(MSG) - -/** Display preset debug information in the Emulator debug messages window. - - This function is equivalent to: - \code{.c} - EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); - \endcode - -*/ -#if defined(NINTENDO) -void EMU_profiler_message(); -#define BGB_profiler_message() EMU_profiler_message() -#endif // NINTENDO - -/** Print the string and arguments given by format to the emulator debug message window - - @param format The format string as per printf - - Does not return the number of characters printed. - Result string MUST BE LESS OR EQUAL THAN 128 BYTES LONG, INCLUDING THE TRAILIG ZERO BYTE! - - Currently supported: - \li \%hx (char as hex) - \li \%hu (unsigned char) - \li \%hd (signed char) - \li \%c (character) - \li \%u (unsigned int) - \li \%d (signed int) - \li \%x (unsigned int as hex) - \li \%s (string) - - Warning: to correctly pass chars for printing as chars, they *must* - be explicitly re-cast as such when calling the function. - See @ref docs_chars_varargs for more details. - */ -void EMU_printf(const char *format, ...) OLDCALL; -#define BGB_printf(...) EMU_printf(__VA_ARGS__) - -#ifdef NINTENDO -static void * __EMU_PROFILER_INIT = &EMU_profiler_message; -#endif // NINTENDO - -/** The Emulator will break into debugger when encounters this line - */ -#define EMU_BREAKPOINT __asm__("ld b, b"); -#define BGB_BREAKPOINT EMU_BREAKPOINT +#include <gbdk/emu_debug.h> #endif diff --git a/gbdk-lib/include/gbdk/emu_debug.h b/gbdk-lib/include/gbdk/emu_debug.h @@ -1,8 +1,175 @@ +/** @file gbdk/emu_debug.h + + Debug window logging and profiling support for emulators (BGB, Emulicious, etc). + + Also see the `emu_debug` example project included with gbdk. + + See the BGB Manual for more information + ("expressions, breakpoint conditions, and debug messages") + http://bgb.bircd.org/manual.html#expressions + +*/ + #ifndef __GBDK_EMU_DEBUG_H_INCLUDE #define __GBDK_EMU_DEBUG_H_INCLUDE +#include <types.h> + #if defined(__TARGET_gb) || defined(__TARGET_ap) || defined(__TARGET_sms) || defined(__TARGET_gg) - #include <gb/emu_debug.h> + +/** Macro to display a message in the emulator debug message window + + @param message_text Quoted text string to display in the debug message window + + The following special parameters can be + used when bracketed with "%" characters. + \li CPU registers: AF, BC, DE, HL, SP, PC, B, C, D, + E, H, L, A, ZERO, ZF, Z, CARRY, CY, IME, ALLREGS + \li Other state values: ROMBANK, XRAMBANK, SRAMBANK, + WRAMBANK, VRAMBANK, TOTALCLKS, LASTCLKS, CLKS2VBLANK + + Example: print a message along with the currently active ROM bank. + \code{.c} + EMU_MESSAGE("Current ROM Bank is: %ROMBANK%"); + \endcode + + + See the BGB Manual for more information + ("expressions, breakpoint conditions, and debug messages") + http://bgb.bircd.org/manual.html#expressions + + @see EMU_PROFILE_BEGIN(), EMU_PROFILE_END() + */ +#define EMU_MESSAGE(message_text) EMU_MESSAGE1(EMU_MACRONAME(__LINE__), message_text) +#define BGB_MESSAGE(message_text) EMU_MESSAGE(message_text) + +/// \cond DOXYGEN_DO_NOT_DOCUMENT +#define EMU_MACRONAME(A) EMU_MACRONAME1(A) +#define EMU_MACRONAME1(A) EMULOG##A + +#define EMU_MESSAGE1(name, message_text) \ +__asm \ +.MACRO name msg_t, ?llbl\ + ld d, d \ + jr llbl \ + .dw 0x6464 \ + .dw 0x0000 \ + .ascii msg_t \ +llbl: \ +.ENDM \ +name ^/message_text/ \ +__endasm + +#define EMU_MESSAGE_SUFFIX(message_text, message_suffix) EMU_MESSAGE3(EMU_MACRONAME(__LINE__), message_text, message_suffix) +#define EMU_MESSAGE3(name, message_text, message_suffix) \ +__asm \ +.MACRO name msg_t, msg_s, ?llbl\ + ld d, d \ + jr llbl \ + .dw 0x6464 \ + .dw 0x0000 \ + .ascii msg_t \ + .ascii msg_s \ +llbl: \ +.ENDM \ +name ^/message_text/, ^/message_suffix/ \ +__endasm +/// \endcond DOXYGEN_DO_NOT_DOCUMENT + +/** Macro to __Start__ a profiling block for the emulator (BGB, Emulicious, etc) + + @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 EMU_PROFILE_END. + + @see EMU_PROFILE_END(), EMU_MESSAGE() + */ +#define EMU_PROFILE_BEGIN(MSG) EMU_MESSAGE_SUFFIX(MSG, "%ZEROCLKS%"); +#define BGB_PROFILE_BEGIN(MSG) EMU_PROFILE_BEGIN(MSG) +/** Macro to __End__ a profiling block and print the results in the emulator debug message window + + @param MSG Quoted text string to display in the + debug message window along with the result + + This should only be called after a previous call + to @ref EMU_PROFILE_BEGIN() + + The results are in Emulator clock units, which are + "1 nop in [CGB] doublespeed mode". + + So when running in Normal Speed mode (i.e. non-CGB doublespeed) + the printed result should be __divided by 2__ to get the actual + ellapsed cycle count. + + If running in CB Double Speed mode use the below call instead, + it correctly compensates for the speed difference. In this + scenario, the result does __not need to be divided by 2__ to + get the ellapsed cycle count. + \code{.c} + EMU_MESSAGE("NOP TIME: %-4+LASTCLKS%"); + \endcode + + @see EMU_PROFILE_BEGIN(), EMU_MESSAGE() + */ +#if defined(NINTENDO) +#define EMU_PROFILE_END(MSG) EMU_MESSAGE_SUFFIX(MSG,"%-8+LASTCLKS%"); +#define BGB_PROFILE_END(MSG) EMU_PROFILE_END(MSG) +#elif defined(SEGA) +#define EMU_PROFILE_END(MSG) EMU_MESSAGE_SUFFIX(MSG,"%-16+LASTCLKS%"); +#define BGB_PROFILE_END(MSG) EMU_PROFILE_END(MSG) +#endif + +#define EMU_TEXT(MSG) EMU_MESSAGE(MSG) +#define BGB_TEXT(MSG) EMU_TEXT(MSG) + +/** Display preset debug information in the Emulator debug messages window. + + This function is equivalent to: + \code{.c} + EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); + \endcode + +*/ +#if defined(NINTENDO) +void EMU_profiler_message(); +#define BGB_profiler_message() EMU_profiler_message() +#endif // NINTENDO + +/** Print the string and arguments given by format to the emulator debug message window + + @param format The format string as per printf + + Does not return the number of characters printed. + Result string MUST BE LESS OR EQUAL THAN 128 BYTES LONG, INCLUDING THE TRAILIG ZERO BYTE! + + Currently supported: + \li \%hx (char as hex) + \li \%hu (unsigned char) + \li \%hd (signed char) + \li \%c (character) + \li \%u (unsigned int) + \li \%d (signed int) + \li \%x (unsigned int as hex) + \li \%s (string) + + Warning: to correctly pass chars for printing as chars, they *must* + be explicitly re-cast as such when calling the function. + See @ref docs_chars_varargs for more details. + */ +void EMU_printf(const char *format, ...) OLDCALL; +#define BGB_printf(...) EMU_printf(__VA_ARGS__) + +#ifdef NINTENDO +static void * __EMU_PROFILER_INIT = &EMU_profiler_message; +#endif // NINTENDO + +/** The Emulator will break into debugger when encounters this line + */ +#define EMU_BREAKPOINT __asm__("ld b, b"); +#define BGB_BREAKPOINT EMU_BREAKPOINT + #elif defined(__TARGET_duck) #error Not implemented yet #else

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.