From 4f0ab6f7e462ee740ec29ba484f97836d10ad6b1 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Sat, 6 Jun 2020 03:02:27 +0200 Subject: [PATCH 1/4] Improve experimental/debug.h with many helper macros This is very useful for displaying error/debug messages to the developper. --- include/experimental/debug.h | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/include/experimental/debug.h b/include/experimental/debug.h index b821d3a..6e23e77 100644 --- a/include/experimental/debug.h +++ b/include/experimental/debug.h @@ -3,4 +3,39 @@ #define BREAKPOINT __asm jr $ __endasm; -#endif \ No newline at end of file +#include +#include + +#define __DEBUG_TIMEOUT 100 + +#define debug_hinted(/* SCREEN* */ screen, msg, /* char* */ hint, /* void(SCREEN*, unsigned char, unsigned char, msg) */ draw_func) \ +{ \ + unsigned short i = 0; \ + const unsigned char* bug_msg = hint; \ + const unsigned short bug_msg_len = strlen(bug_msg); \ + const unsigned short space = (bug_msg_len != 0) ? 4 : 0; \ + for(i=0; i<__DEBUG_TIMEOUT;i++){ \ + screen_clear(screen); \ + draw_string(screen, 2, 2, "L. "); \ + draw_short(screen, 2+3*4, 2, __LINE__); \ + draw_string(screen, 2, 8*7, __FILE__); \ + draw_string(screen, 2, 8*1, hint);\ + draw_func(screen, 2+bug_msg_len*4+space, 8*1, msg); \ + draw_short(screen, 2, 8*6, __DEBUG_TIMEOUT-i); \ + screen_draw(screen); \ + } \ +} + +#define debug(screen, msg, draw_func) debug_hinted(screen, msg, "", draw_func) + +#define debug_str(screen, msg) debug(screen, msg, draw_string) +#define debug_short(screen, msg) debug(screen, msg, draw_short) +#define debug_signed(screen, msg) debug(screen, msg, draw_signed) +#define debug_float(screen, msg) debug(screen, msg, draw_float) +#define debug_float_hinted(screen, msg, hint) \ +{ \ + float ___temp___ = msg; /* Trick done because of performance issues */ \ + debug_hinted(screen, ___temp___, hint, draw_float); \ +} + +#endif From d169ecefb51c75f9ea75af39ef9896c044902350 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Mon, 8 Jun 2020 01:02:02 +0200 Subject: [PATCH 2/4] Add timeout option to debug and improve performance greatly --- include/experimental/debug.h | 39 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/include/experimental/debug.h b/include/experimental/debug.h index 6e23e77..6b5bfee 100644 --- a/include/experimental/debug.h +++ b/include/experimental/debug.h @@ -6,36 +6,35 @@ #include #include -#define __DEBUG_TIMEOUT 100 +#define __DEFAULT_DEBUG_TIMEOUT 150 -#define debug_hinted(/* SCREEN* */ screen, msg, /* char* */ hint, /* void(SCREEN*, unsigned char, unsigned char, msg) */ draw_func) \ +#define debug_hinted(/* SCREEN* */ screen, msg, /* char* */ hint, /* int */ timeout, /* void(SCREEN*, unsigned char, unsigned char, msg) */ draw_func) \ { \ unsigned short i = 0; \ const unsigned char* bug_msg = hint; \ const unsigned short bug_msg_len = strlen(bug_msg); \ const unsigned short space = (bug_msg_len != 0) ? 4 : 0; \ - for(i=0; i<__DEBUG_TIMEOUT;i++){ \ - screen_clear(screen); \ - draw_string(screen, 2, 2, "L. "); \ - draw_short(screen, 2+3*4, 2, __LINE__); \ - draw_string(screen, 2, 8*7, __FILE__); \ - draw_string(screen, 2, 8*1, hint);\ - draw_func(screen, 2+bug_msg_len*4+space, 8*1, msg); \ - draw_short(screen, 2, 8*6, __DEBUG_TIMEOUT-i); \ + screen_clear(screen); \ + draw_string(screen, 2, 2, "L. "); \ + draw_short(screen, 2+3*4, 2, __LINE__); \ + draw_string(screen, 2, 8*7, __FILE__); \ + draw_string(screen, 2, 8*1, hint);\ + /* the size of a single character is 4 pixel */ \ + draw_func(screen, 2+bug_msg_len*4+space, 8*1, msg); \ + for(i=0; i Date: Mon, 8 Jun 2020 01:03:40 +0200 Subject: [PATCH 3/4] Fix "debug" not being "debug_hinted" in some macros --- include/experimental/debug.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/experimental/debug.h b/include/experimental/debug.h index 6b5bfee..c16f56e 100644 --- a/include/experimental/debug.h +++ b/include/experimental/debug.h @@ -31,9 +31,9 @@ #define debug(screen, msg, draw_func) debug_hinted(screen, msg, "", __DEFAULT_DEBUG_TIMEOUT, draw_func) -#define debug_str(screen, msg) debug(screen, msg, "str:", __DEFAULT_DEBUG_TIMEOUT, draw_string) -#define debug_short(screen, msg) debug(screen, msg, "short:", __DEFAULT_DEBUG_TIMEOUT, draw_short) -#define debug_signed(screen, msg) debug(screen, msg, "signed:", __DEFAULT_DEBUG_TIMEOUT, draw_signed) +#define debug_str(screen, msg) debug_hinted(screen, msg, "str:", __DEFAULT_DEBUG_TIMEOUT, draw_string) +#define debug_short(screen, msg) debug_hinted(screen, msg, "short:", __DEFAULT_DEBUG_TIMEOUT, draw_short) +#define debug_signed(screen, msg) debug_hinted(screen, msg, "signed:", __DEFAULT_DEBUG_TIMEOUT, draw_signed) #define debug_float(screen, msg) debug_hinted(screen, msg, "float:", __DEFAULT_DEBUG_TIMEOUT, draw_float) #define debug_float_hinted(screen, msg, hint) debug_hinted(screen, msg, hint, __DEFAULT_DEBUG_TIMEOUT, draw_float) From fae3a8db3bbc27ee6669696a9ce0150c94deaf52 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Wed, 10 Jun 2020 01:17:42 +0200 Subject: [PATCH 4/4] Add possibility to easily disable all debug (for releases) --- include/experimental/debug.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/experimental/debug.h b/include/experimental/debug.h index c16f56e..1f551c2 100644 --- a/include/experimental/debug.h +++ b/include/experimental/debug.h @@ -8,6 +8,8 @@ #define __DEFAULT_DEBUG_TIMEOUT 150 +#ifndef KCC_DISABLE_DEBUG + #define debug_hinted(/* SCREEN* */ screen, msg, /* char* */ hint, /* int */ timeout, /* void(SCREEN*, unsigned char, unsigned char, msg) */ draw_func) \ { \ unsigned short i = 0; \ @@ -29,6 +31,12 @@ screen_clear(screen); \ } +#else + +#define debug_hinted(/* SCREEN* */ screen, msg, /* char* */ hint, /* int */ timeout, /* void(SCREEN*, unsigned char, unsigned char, msg) */ draw_func) + +#endif + #define debug(screen, msg, draw_func) debug_hinted(screen, msg, "", __DEFAULT_DEBUG_TIMEOUT, draw_func) #define debug_str(screen, msg) debug_hinted(screen, msg, "str:", __DEFAULT_DEBUG_TIMEOUT, draw_string)