From 0f8b629e20a46e7f9daee8f3d127dbc7075ccc75 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 2 Jun 2026 11:01:54 -0500 Subject: [PATCH] Add logging to Wii --- .github/workflows/build.yml | 2 +- .gitignore | 3 +- assets/testentity.js | 2 +- scripts/build-wii.sh | 3 +- src/duskdolphin/log/log.c | 77 ++++++++++++++++++++++++++++++++----- 5 files changed, 74 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dcb82360..f082b3c0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -144,7 +144,7 @@ jobs: - name: Copy output files. run: | mkdir -p ./git-artifcats/Dusk/apps/Dusk - cp build-wii/Dusk.dol ./git-artifcats/Dusk/apps/Dusk/boot.dol + cp build-wii/boot.dol ./git-artifcats/Dusk/apps/Dusk/boot.dol cp build-wii/dusk.dsk ./git-artifcats/Dusk/apps/Dusk/dusk.dsk cp build-wii/meta.xml ./git-artifcats/Dusk/apps/Dusk/meta.xml - name: Upload Wii binary diff --git a/.gitignore b/.gitignore index 194189d3..2bec2173 100644 --- a/.gitignore +++ b/.gitignore @@ -105,4 +105,5 @@ yarn.lock /build2 /build* /assets/test -/tools_old \ No newline at end of file +/tools_old +/assets/test.png \ No newline at end of file diff --git a/assets/testentity.js b/assets/testentity.js index 399d380a..b0508048 100644 --- a/assets/testentity.js +++ b/assets/testentity.js @@ -1,6 +1,6 @@ // Load rosa. Console.print('Asset time'); -const entry = Asset.lock('rosa.png', Asset.TYPE_TEXTURE, Texture.FORMAT_RGBA); +const entry = Asset.lock('test.png', Asset.TYPE_TEXTURE, Texture.FORMAT_RGBA); Asset.requireLoaded(entry); Console.print('Asset loaded'); diff --git a/scripts/build-wii.sh b/scripts/build-wii.sh index 7fb5ed0b..33f18f66 100755 --- a/scripts/build-wii.sh +++ b/scripts/build-wii.sh @@ -7,4 +7,5 @@ fi mkdir -p build-wii cmake -S. -Bbuild-wii -DDUSK_TARGET_SYSTEM=wii -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake" cd build-wii -make -j$(nproc) VERBOSE=1 \ No newline at end of file +make -j$(nproc) VERBOSE=1 +mv Dusk.dol boot.dol \ No newline at end of file diff --git a/src/duskdolphin/log/log.c b/src/duskdolphin/log/log.c index 3798c8ab..ad35e65c 100644 --- a/src/duskdolphin/log/log.c +++ b/src/duskdolphin/log/log.c @@ -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 +#include +#include +#include + +#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); } \ No newline at end of file