aturn
This commit is contained in:
@@ -6,27 +6,45 @@
|
||||
*/
|
||||
|
||||
#include "log/log.h"
|
||||
#include <dbgio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* On Saturn, stdout goes to the debug serial port (via Yaul's dbgio module).
|
||||
* With a comm link or emulator (Mednafen, SSF) this is visible on the host.
|
||||
*
|
||||
* TODO: add dbgio_dev_default_set(DBGIO_DEV_USB_CART, NULL) in
|
||||
* systemSaturnInit() and replace vprintf with dbgio_printf() for
|
||||
* hardware-accurate serial output.
|
||||
* 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);
|
||||
vprintf(message, args);
|
||||
_logWrite(message, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void logError(const char_t *message, ...) {
|
||||
_ensureDbgio();
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
_logWrite(message, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user