Files
dusk/src/dusksaturn/log/log.c
T
2026-06-21 11:40:46 -05:00

51 lines
1.1 KiB
C

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "log/log.h"
#include <dbgio.h>
#include <stdarg.h>
#include <stdio.h>
/*
* Yaul's bare-metal stdio (stdout/stderr) has uninitialised function pointers
* and will crash if called via vprintf/vfprintf. Use Yaul's dbgio subsystem
* instead: DBGIO_DEV_MEDNAFEN_DEBUG outputs to Mednafen's debug console;
* the same code works with USB cart or serial on hardware by changing the
* device constant.
*/
static int _dbgioReady = 0;
static void _ensureDbgio(void) {
if (!_dbgioReady) {
dbgio_dev_default_init(DBGIO_DEV_MEDNAFEN_DEBUG);
_dbgioReady = 1;
}
}
static void _logWrite(const char_t *message, va_list args) {
char buf[256];
vsnprintf(buf, sizeof(buf), message, args);
dbgio_puts(buf);
}
void logDebug(const char_t *message, ...) {
_ensureDbgio();
va_list args;
va_start(args, message);
_logWrite(message, args);
va_end(args);
}
void logError(const char_t *message, ...) {
_ensureDbgio();
va_list args;
va_start(args, message);
_logWrite(message, args);
va_end(args);
}