GBDK 2020 Docs  4.2.0
API Documentation for GBDK 2020
emu_debug.h
Go to the documentation of this file.
1 
13 #ifndef __GBDK_EMU_DEBUG_H_INCLUDE
14 #define __GBDK_EMU_DEBUG_H_INCLUDE
15 
16 #include <types.h>
17 
18 #if defined(__TARGET_gb) || defined(__TARGET_ap) || defined(__TARGET_sms) || defined(__TARGET_gg)
19 
43 #define EMU_MESSAGE(message_text) EMU_MESSAGE1(EMU_MACRONAME(__LINE__), message_text)
44 #define BGB_MESSAGE(message_text) EMU_MESSAGE(message_text)
45 
47 #define EMU_MACRONAME(A) EMU_MACRONAME1(A)
48 #define EMU_MACRONAME1(A) EMULOG##A
49 
50 #define EMU_MESSAGE1(name, message_text) \
51 __asm \
52 .MACRO name msg_t, ?llbl\
53  ld d, d \
54  jr llbl \
55  .dw 0x6464 \
56  .dw 0x0000 \
57  .ascii msg_t \
58 llbl: \
59 .ENDM \
60 name ^/message_text/ \
61 __endasm
62 
63 #define EMU_MESSAGE_SUFFIX(message_text, message_suffix) EMU_MESSAGE3(EMU_MACRONAME(__LINE__), message_text, message_suffix)
64 #define EMU_MESSAGE3(name, message_text, message_suffix) \
65 __asm \
66 .MACRO name msg_t, msg_s, ?llbl\
67  ld d, d \
68  jr llbl \
69  .dw 0x6464 \
70  .dw 0x0000 \
71  .ascii msg_t \
72  .ascii msg_s \
73 llbl: \
74 .ENDM \
75 name ^/message_text/, ^/message_suffix/ \
76 __endasm
78 
89 #define EMU_PROFILE_BEGIN(MSG) EMU_MESSAGE_SUFFIX(MSG, "%ZEROCLKS%");
90 #define BGB_PROFILE_BEGIN(MSG) EMU_PROFILE_BEGIN(MSG)
116 #if defined(NINTENDO)
117 #define EMU_PROFILE_END(MSG) EMU_MESSAGE_SUFFIX(MSG,"%-8+LASTCLKS%");
118 #define BGB_PROFILE_END(MSG) EMU_PROFILE_END(MSG)
119 #elif defined(SEGA)
120 #define EMU_PROFILE_END(MSG) EMU_MESSAGE_SUFFIX(MSG,"%-16+LASTCLKS%");
121 #define BGB_PROFILE_END(MSG) EMU_PROFILE_END(MSG)
122 #endif
123 
124 #define EMU_TEXT(MSG) EMU_MESSAGE(MSG)
125 #define BGB_TEXT(MSG) EMU_TEXT(MSG)
126 
135 #if defined(NINTENDO)
136 void EMU_profiler_message(void);
137 #define BGB_profiler_message EMU_profiler_message()
138 #endif // NINTENDO
139 
161 void EMU_printf(const char *format, ...) OLDCALL;
162 #define BGB_printf(...) EMU_printf(__VA_ARGS__)
163 
164 #ifdef NINTENDO
165 static void * __EMU_PROFILER_INIT = &EMU_profiler_message;
166 #endif // NINTENDO
167 
170 #define EMU_BREAKPOINT __asm__("ld b, b");
171 #define BGB_BREAKPOINT EMU_BREAKPOINT
172 
173 #elif defined(__TARGET_duck)
174  #error Not implemented yet
175 #else
176  #error Unrecognized port
177 #endif
178 
179 #endif
#define OLDCALL
Definition: types.h:21
void EMU_printf(const char *format,...) OLDCALL