gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit e8c732dfe0caa9fa3d8f3651c68e5bef78712e29 parent bd99d4ce69dcbab46586e1d8f3b055ff5426df07 Author: Toxa <untoxa@mail.ru> Date: Mon, 24 Feb 2025 23:02:47 +0300 Merge branch 'develop' of https://github.com/gbdk-2020/gbdk-2020 into develop Diffstat:
| M | gbdk-lib/examples/cross-platform/emu_debug/src/emu_debug.c | 31 | ++++++++++++++++++++++++++++--- |
| M | gbdk-lib/include/gbdk/emu_debug.h | 19 | ++++++++++++++----- |
2 files changed, 42 insertions(+), 8 deletions(-)
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 @@ -153,9 +153,34 @@ int main(void) EMU_MESSAGE("PROFILE,%(SP+$0)%,%(SP+$1)%,%A%,%TOTALCLKS%,%ROMBANK%,%WRAMBANK%"); #endif - uint8_t var0 = 16; - int16_t var1 = -10; - EMU_printf("var0: %hd; var1: %d; var0*var1=%d\n", (uint8_t)var0, var1, var0 * var1); + int16_t var_s16 = -1234; + uint16_t var_u16 = 31002; + uint16_t var_u16h = 0xA50Fu; + int8_t var_s8 = -56; + uint8_t var_u8 = 224; + uint8_t var_u8h = 0xF8; + char var_chr = 'A'; + char * var_string = "Hello Emu Printf"; + + // For EMU_printf: + // Note how all the 8 bit arguments must be explicitly cast EXCEPT for %c + // In partifcular, %c MUST NOT be cast or the output will be incorrect + EMU_printf("signed int: %d\n" + "unsigned int: %u\n" + "hex int: 0x%X\n" + "signed byte: %hd\n" + "unsigned byte: %hu\n" + "hex byte: 0x%hX\n" + "Character: %c\n" + "String: %s\n", + (int16_t) var_s16, + (uint16_t) var_u16, + (uint16_t) var_u16h, + (int8_t)var_s8, + (uint8_t)var_u8, + (uint8_t)var_u8h, + var_chr, // Do not explicitly cast %c vars for EMU_printf, it expects them auto-promoted to 2 bytes (casting would prevent that) + var_string); // The EMU_TEXT() macro will accept a non-quoted string EMU_TEXT("The End"); diff --git a/gbdk-lib/include/gbdk/emu_debug.h b/gbdk-lib/include/gbdk/emu_debug.h @@ -149,17 +149,26 @@ void EMU_profiler_message(void); \li \%hx (char as hex) \li \%hu (unsigned char) \li \%hd (signed char) - \li \%c (character) + \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. - Currently supported in the Emulicious emulator + @note + Variables for the following 8-bit formats __MUST__ be cast to their type when passed to EMU_printf() + \li \%hx (char) + \li \%hu (unsigned char) + \li \%hd (signed char) + + However variables for the following 8-bit format __MUST NOT__ be cast to their type when passed to EMU_printf() + \li \%c (char) + + This behavior is __different__ than for @ref sprintf(), which does require \%c format char variables to be explicitly cast. + + + Currently supported in the Emulicious emulator, may be supported by bgb */ void EMU_printf(const char *format, ...) PRESERVES_REGS(a, b, c); #define BGB_printf(...) EMU_printf(__VA_ARGS__)
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.