/******************************************************************************\ ** ** This file is part of the Hades GBA Emulator, and is made available under ** the terms of the GNU General Public License version 2. ** ** Copyright (C) 2021-2026 - The Hades Authors ** \******************************************************************************/ #include #include #include "hades.h" /* ** A global variable used to indicate the verbosity of all the different log levels. */ bool g_verbose_global = true; bool g_verbose[HS_END] = { [HS_INFO] = true, [HS_WARN] = true, [HS_ERROR] = true, [HS_DEBUG] = true, [HS_CHEAT] = true, // TODO FIXME: Enabled during the development of the new cheat code feature. }; char const * const module_names[] = { [HS_INFO] = " INFO ", [HS_ERROR] = " ERROR ", [HS_WARN] = " WARN ", [HS_CORE] = " CORE ", [HS_IO] = " IO ", [HS_VIDEO] = " VIDEO ", [HS_DMA] = " DMA ", [HS_IRQ] = " IRQ ", [HS_MEMORY] = " MEM ", [HS_TIMER] = " TIMER ", [HS_DEBUG] = " DEBUG ", [HS_CHEAT] = " CHEAT ", }; /* ** A set of global strings pointing to ANSI control sequences to format the terminal. ** They can also be set to the empty string if coloration is disabled. */ char const *g_reset = "\e[0m"; char const *g_bold = "\e[1m"; char const *g_red = "\e[31m"; char const *g_green = "\e[32m"; char const *g_yellow = "\e[33m"; char const *g_blue = "\e[34m"; char const *g_magenta = "\e[35m"; char const *g_cyan = "\e[36m"; char const *g_light_gray = "\e[37m"; char const *g_dark_gray = "\e[90m"; char const *g_light_red = "\e[91m"; char const *g_light_green = "\e[92m"; char const *g_light_yellow = "\e[93m"; char const *g_light_blue = "\e[94m"; char const *g_light_magenta = "\e[95m"; char const *g_light_cyan = "\e[96m"; char const *g_white = "\e[97m"; void hs_disable_colors( void ) { g_reset = ""; g_bold = ""; g_red = ""; g_green = ""; g_yellow = ""; g_blue = ""; g_magenta = ""; g_cyan = ""; g_light_gray = ""; g_dark_gray = ""; g_light_red = ""; g_light_green = ""; g_light_yellow = ""; g_light_blue = ""; g_light_magenta = ""; g_light_cyan = ""; g_white = ""; } /* ** Log the given formatted string, followed by a `\n`. */ void hs_logln( enum modules module, char const *fmt, ... ) { va_list va; if (g_verbose_global && g_verbose[module]) { va_start(va, fmt); printf("[%s] ", module_names[module]); switch (module) { case HS_ERROR: printf("%s%s", g_bold, g_light_red); break; case HS_WARN: printf("%s%s", g_bold, g_light_yellow); break; default: break; } vprintf(fmt, va); switch (module) { case HS_ERROR: case HS_WARN: printf("%s", g_reset); break; default: break; } printf("\n"); va_end(va); } } /* ** Print the given formatted string to stderr and finally exit(1). */ __hs_noreturn void hs_panic( enum modules module, char const *fmt, ... ) { va_list va; va_start(va, fmt); printf("[%s] Abort: ", module_names[module]); vprintf(fmt, va); printf("\n"); va_end(va); exit(1); } /* ** Print the given formatted string to stderr, followed by a `\n`, and then ** exit(1). */ __hs_noreturn void hs_unimplemented( enum modules module, char const *fmt, ... ) { va_list va; va_start(va, fmt); printf("[%s] Abort: Not Implemented: ", module_names[module]); vprintf(fmt, va); printf("\n"); va_end(va); exit(1); }