From b93a5dcb7c09a87d106711fb9dde8d79e64f3fc6 Mon Sep 17 00:00:00 2001 From: fig02 Date: Mon, 21 Apr 2025 11:32:09 -0400 Subject: [PATCH] create printf and translation headers --- include/macros.h | 52 ------------------------------------------- include/printf.h | 52 +++++++++++++++++++++++++++++++++++++++++++ include/translation.h | 11 +++++++++ src/audio/general.c | 1 + src/audio/sfx.c | 1 + 5 files changed, 65 insertions(+), 52 deletions(-) create mode 100644 include/printf.h create mode 100644 include/translation.h diff --git a/include/macros.h b/include/macros.h index 813ceb6f26..0cb1b4285d 100644 --- a/include/macros.h +++ b/include/macros.h @@ -1,7 +1,6 @@ #ifndef MACROS_H #define MACROS_H -#include "terminal.h" #include "versions.h" #define SCREEN_WIDTH 320 @@ -13,13 +12,6 @@ #define BAD_RETURN(type) void #endif -/** - * The T macro holds translations in English for original debug strings written in Japanese. - * The translated strings match the original debug strings, they are only direct translations. - * For example, any original name is left as is rather than being replaced with the name in the codebase. - */ -#define T(jp, en) jp - #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0])) #define ARRAY_COUNT_2D(arr) (s32)(sizeof(arr) / sizeof(arr[0][0])) @@ -45,50 +37,6 @@ #define CHECK_FLAG_ALL(flags, mask) (((flags) & (mask)) == (mask)) -// IDO doesn't support variadic macros, but it merely throws a warning for the -// number of arguments not matching the definition (warning 609) instead of -// throwing an error. We suppress this warning and rely on GCC to catch macro -// argument errors instead. -// Note some tools define __sgi but preprocess with a modern cpp implementation, -// ensure that these do not use the IDO workaround to avoid errors. -#define IDO_PRINTF_WORKAROUND (__sgi && !__GNUC__ && !M2CTX) - -#if DEBUG_FEATURES -#define PRINTF osSyncPrintf -#elif defined(EGCS) -#define PRINTF(format, args...) while (0) osSyncPrintf(format, ##args) -#elif IDO_PRINTF_WORKAROUND -#define PRINTF(args) (void)0 -#else -#define PRINTF(format, ...) (void)0 -#endif - -#if DEBUG_FEATURES -#define PRINTF_COLOR_BLACK() PRINTF(VT_FGCOL(BLACK)) -#define PRINTF_COLOR_RED() PRINTF(VT_FGCOL(RED)) -#define PRINTF_COLOR_GREEN() PRINTF(VT_FGCOL(GREEN)) -#define PRINTF_COLOR_YELLOW() PRINTF(VT_FGCOL(YELLOW)) -#define PRINTF_COLOR_BLUE() PRINTF(VT_FGCOL(BLUE)) -#define PRINTF_COLOR_MAGENTA() PRINTF(VT_FGCOL(MAGENTA)) -#define PRINTF_COLOR_CYAN() PRINTF(VT_FGCOL(CYAN)) -#define PRINTF_COLOR_WHITE() PRINTF(VT_FGCOL(WHITE)) -#define PRINTF_COLOR_WARNING() PRINTF(VT_COL(YELLOW, BLACK)) -#define PRINTF_COLOR_ERROR() PRINTF(VT_COL(RED, WHITE)) -#define PRINTF_RST() PRINTF(VT_RST) -#else -#define PRINTF_COLOR_BLACK() (void)0 -#define PRINTF_COLOR_RED() (void)0 -#define PRINTF_COLOR_GREEN() (void)0 -#define PRINTF_COLOR_YELLOW() (void)0 -#define PRINTF_COLOR_BLUE() (void)0 -#define PRINTF_COLOR_MAGENTA() (void)0 -#define PRINTF_COLOR_CYAN() (void)0 -#define PRINTF_COLOR_WHITE() (void)0 -#define PRINTF_COLOR_WARNING() (void)0 -#define PRINTF_COLOR_ERROR() (void)0 -#define PRINTF_RST() (void)0 -#endif - #if PLATFORM_N64 || DEBUG_FEATURES #define HUNGUP_AND_CRASH(file, line) Fault_AddHungupAndCrash(file, line) #else diff --git a/include/printf.h b/include/printf.h new file mode 100644 index 0000000000..2d33ed6692 --- /dev/null +++ b/include/printf.h @@ -0,0 +1,52 @@ +#ifndef PRINTF_H +#define PRINTF_H + +#include "is_debug.h" +#include "terminal.h" +#include "ultra64.h" + +// IDO doesn't support variadic macros, but it merely throws a warning for the +// number of arguments not matching the definition (warning 609) instead of +// throwing an error. We suppress this warning and rely on GCC to catch macro +// argument errors instead. +// Note some tools define __sgi but preprocess with a modern cpp implementation, +// ensure that these do not use the IDO workaround to avoid errors. +#define IDO_PRINTF_WORKAROUND (__sgi && !__GNUC__ && !M2CTX) + +#if DEBUG_FEATURES +#define PRINTF osSyncPrintf +#elif defined(EGCS) +#define PRINTF(format, args...) while (0) osSyncPrintf(format, ##args) +#elif IDO_PRINTF_WORKAROUND +#define PRINTF(args) (void)0 +#else +#define PRINTF(format, ...) (void)0 +#endif + +#if DEBUG_FEATURES +#define PRINTF_COLOR_BLACK() PRINTF(VT_FGCOL(BLACK)) +#define PRINTF_COLOR_RED() PRINTF(VT_FGCOL(RED)) +#define PRINTF_COLOR_GREEN() PRINTF(VT_FGCOL(GREEN)) +#define PRINTF_COLOR_YELLOW() PRINTF(VT_FGCOL(YELLOW)) +#define PRINTF_COLOR_BLUE() PRINTF(VT_FGCOL(BLUE)) +#define PRINTF_COLOR_MAGENTA() PRINTF(VT_FGCOL(MAGENTA)) +#define PRINTF_COLOR_CYAN() PRINTF(VT_FGCOL(CYAN)) +#define PRINTF_COLOR_WHITE() PRINTF(VT_FGCOL(WHITE)) +#define PRINTF_COLOR_WARNING() PRINTF(VT_COL(YELLOW, BLACK)) +#define PRINTF_COLOR_ERROR() PRINTF(VT_COL(RED, WHITE)) +#define PRINTF_RST() PRINTF(VT_RST) +#else +#define PRINTF_COLOR_BLACK() (void)0 +#define PRINTF_COLOR_RED() (void)0 +#define PRINTF_COLOR_GREEN() (void)0 +#define PRINTF_COLOR_YELLOW() (void)0 +#define PRINTF_COLOR_BLUE() (void)0 +#define PRINTF_COLOR_MAGENTA() (void)0 +#define PRINTF_COLOR_CYAN() (void)0 +#define PRINTF_COLOR_WHITE() (void)0 +#define PRINTF_COLOR_WARNING() (void)0 +#define PRINTF_COLOR_ERROR() (void)0 +#define PRINTF_RST() (void)0 +#endif + +#endif diff --git a/include/translation.h b/include/translation.h new file mode 100644 index 0000000000..d88c0a5bbf --- /dev/null +++ b/include/translation.h @@ -0,0 +1,11 @@ +#ifndef TRANSLATION_H +#define TRANSLATION_H + +/** + * The T macro holds translations in English for original debug strings written in Japanese. + * The translated strings match the original debug strings, they are only direct translations. + * For example, any original name is left as is rather than being replaced with the name in the codebase. + */ +#define T(jp, en) jp + +#endif \ No newline at end of file diff --git a/src/audio/general.c b/src/audio/general.c index 7dce7b54df..c3286554e0 100644 --- a/src/audio/general.c +++ b/src/audio/general.c @@ -4,6 +4,7 @@ #include "audiothread_cmd.h" #include "controller.h" #include "padmgr.h" +#include "printf.h" #include "seqcmd.h" #include "sequence.h" #include "sfx.h" diff --git a/src/audio/sfx.c b/src/audio/sfx.c index 1ed7e6b594..3d837676df 100644 --- a/src/audio/sfx.c +++ b/src/audio/sfx.c @@ -1,5 +1,6 @@ #include "audiothread_cmd.h" #include "macros.h" +#include "printf.h" #include "sfx.h" #include "terminal.h" #include "ultra64.h"