Add logging to Wii

This commit is contained in:
2026-06-02 11:01:54 -05:00
parent 36f6ac65f2
commit 0f8b629e20
5 changed files with 74 additions and 13 deletions
+68 -9
View File
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2026 Dominic Masters
*
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
@@ -8,19 +8,66 @@
#include "log/log.h"
#include "display/display.h"
#include <debug.h>
#include <fat.h>
#include <stdio.h>
#include <stdlib.h>
#define LOG_DEBUG_PATH "/apps/Dusk/debug.log"
#define LOG_ERROR_PATH "/apps/Dusk/error.log"
static bool_t fatTried = false;
static bool_t fatReady = false;
static void logInitFAT(void) {
if(fatTried) return;
fatTried = true;
fatReady = fatInitDefault();
}
void logDebug(const char_t *message, ...) {
// Print to stdout
va_list args;
va_start(args, message);
vfprintf(stdout, message, args);
va_end(args);
// Print to stdout
va_list copy;
va_copy(copy, args);
vfprintf(stdout, message, copy);
va_end(copy);
fflush(stdout);
// Print to file
logInitFAT();
if(fatReady) {
FILE *file = fopen(LOG_DEBUG_PATH, "a");
if(file) {
va_copy(copy, args);
vfprintf(file, message, copy);
va_end(copy);
fclose(file);
}
}
va_end(args);
}
void logError(const char_t *message, ...) {
va_list args;
va_start(args, message);
// Write to file before displaying on screen
logInitFAT();
if(fatReady) {
FILE *file = fopen(LOG_ERROR_PATH, "a");
if(file) {
va_list copy;
va_copy(copy, args);
vfprintf(file, message, copy);
va_end(copy);
fclose(file);
}
}
// Either create graphics, or hijack the displays' graphics.
void *xfb = NULL;
GXRModeObj *rmode = NULL;
void *framebuffer;
@@ -54,12 +101,24 @@ void logError(const char_t *message, ...) {
}
// Printf
va_list args;
va_start(args, message);
vprintf(message, args);
va_list copy;
va_copy(copy, args);
vprintf(message, copy);
va_end(copy);
va_end(args);
// PAD_Init is idempotent — safe to call even if inputInit already called it,
// and handles the case where the error occurred before inputInit ran.
PAD_Init();
while(SYS_MainLoop()) {
PAD_ScanPads();
// START button matches the RAGEQUIT bind — allows exit on GC controller
// when there is no Wiimote HOME button available.
if(PAD_ButtonsDown(0) & PAD_BUTTON_START) break;
VIDEO_WaitVSync();
}
// Exit cleanly to HBC regardless of engine state. engineDispose() is not
// called here because the engine may be partially initialized.
exit(0);
}