11#define MGBA_REG_DEBUG_ENABLE ((vu16*)0x4FFF780)
12#define MGBA_REG_DEBUG_FLAGS ((vu16*)0x4FFF700)
13#define MGBA_REG_DEBUG_STRING ((char*)0x4FFF600)
15static const u32 MGBA_ENABLE_MAGIC = 0xC0DE;
16static const u32 MGBA_ENABLE_OK = 0x1DEA;
17static const u32 MGBA_LOG_SEND = 0x100;
18static const u32 MGBA_LOG_BUFFER_SIZE = 0x100;
19static const u16 MGBA_LOG_LEVEL_MASK = 0x7;
21static bool s_mgba_logger_available =
false;
25 *MGBA_REG_DEBUG_ENABLE = MGBA_ENABLE_MAGIC;
26 s_mgba_logger_available = (*MGBA_REG_DEBUG_ENABLE == MGBA_ENABLE_OK);
27 return s_mgba_logger_available;
30static void mgba_vprintf(MgbaLogLevel level,
const char* fmt, va_list args)
32 if (!s_mgba_logger_available || fmt == NULL)
35 vsnprintf(MGBA_REG_DEBUG_STRING, MGBA_LOG_BUFFER_SIZE, fmt, args);
37 *MGBA_REG_DEBUG_FLAGS = ((uint16_t)level & MGBA_LOG_LEVEL_MASK) | MGBA_LOG_SEND;
40void mgba_printf(MgbaLogLevel level,
const char* fmt, ...)
44 mgba_vprintf(level, fmt, args);
48void mgba_func_printf(MgbaLogLevel level,
const char* func_name,
const char* fmt, ...)
50 if (!s_mgba_logger_available || func_name == NULL || fmt == NULL)
56 char printed_str_buff[MGBA_LOG_BUFFER_SIZE];
61 vsnprintf(printed_str_buff,
sizeof(printed_str_buff), fmt, args);
63 mgba_printf(level,
"%s(): %s", func_name, printed_str_buff);
Interface to interact with the mgba logger.
bool mgba_logger_init(void)
Initialize mgba logger.
void mgba_func_printf(MgbaLogLevel level, const char *func_name, const char *fmt,...)
Print to mgba log with a format string and function name.
void mgba_printf(MgbaLogLevel level, const char *fmt,...)
Print to mgba log with a format string.