From 030d46a9999846d63c12c456aa5326eca17cd0d7 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 5 Dec 2022 17:28:42 -0600 Subject: [PATCH] [ox/std] Cleanup mGBA logging --- deps/ox/src/ox/std/tracehook.cpp | 45 +++++++++++++++----------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/deps/ox/src/ox/std/tracehook.cpp b/deps/ox/src/ox/std/tracehook.cpp index a3cb2d5f..749b61e5 100644 --- a/deps/ox/src/ox/std/tracehook.cpp +++ b/deps/ox/src/ox/std/tracehook.cpp @@ -16,37 +16,34 @@ #define REG_MGBA_DEBUG_FLAGS *reinterpret_cast(0x4FFF700) #define REG_MGBA_DEBUG_STRING (reinterpret_cast(0x4FFF600)) -namespace ox::hw { -static void (*infoLog)(ox::CRStringView) = [](ox::CRStringView) {}; -static void (*debugLog)(ox::CRStringView) = [](ox::CRStringView) {}; -static void (*errorLog)(ox::CRStringView) = [](ox::CRStringView) {}; -} +inline void nullLog(ox::CRStringView) {} +inline void (*infoLog)(ox::CRStringView) = nullLog; +inline void (*debugLog)(ox::CRStringView) = nullLog; +inline void (*errorLog)(ox::CRStringView) = nullLog; namespace mgba { enum LogChan { - LOG_FATAL = 0, - LOG_ERROR = 1, - LOG_WARN = 2, - LOG_INFO = 3, - LOG_DEBUG = 4 + Fatal = 0, + Error = 1, + Warn = 2, + Info = 3, + Debug = 4, }; template -static auto mkLogger() { - return [](ox::CRStringView str) { - const auto sz = ox::min(0x100, str.bytes()); - ox_strncpy(REG_MGBA_DEBUG_STRING, str.data(), sz); - REG_MGBA_DEBUG_FLAGS = chan | 0x100; - }; +static void log(ox::CRStringView str) { + const auto sz = ox::min(0x100, str.bytes()); + ox_strncpy(REG_MGBA_DEBUG_STRING, str.data(), sz); + REG_MGBA_DEBUG_FLAGS = chan | 0x100; } void initConsole() { REG_MGBA_DEBUG_ENABLE = 0xC0DE; if (REG_MGBA_DEBUG_ENABLE == 0x1DEA) { - ox::hw::infoLog = mgba::mkLogger(); - ox::hw::debugLog = mgba::mkLogger(); // use INFO because mGBA disables DEBUG on start - ox::hw::errorLog = mgba::mkLogger(); + infoLog = log; + debugLog = log; // use INFO because mGBA disables DEBUG on start + errorLog = log; } } @@ -84,15 +81,15 @@ void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line, } #else if (ox_strcmp(ch, "info") == 0) { - ox::hw::infoLog(msg); + infoLog(msg); } else if (ox_strcmp(ch, "debug") == 0) { - ox::hw::debugLog(msg); + debugLog(msg); } else if (ox_strcmp(ch, "stdout") == 0) { - ox::hw::infoLog(msg); + infoLog(msg); } else if (ox_strcmp(ch, "stderr") == 0) { - ox::hw::errorLog(msg); + errorLog(msg); } else if (ox_strcmp(ch, "error") == 0) { - ox::hw::errorLog(msg); + errorLog(msg); } #endif }