diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index e37bde16f..0151a0219 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -57,6 +57,7 @@ static THREAD_ENTRY _GBAThreadRun(void* context) { pthread_sigmask(SIG_SETMASK, &signals, 0); #endif + gba.logHandler = threadContext->logHandler; GBAInit(&gba); threadContext->gba = &gba; gba.sync = &threadContext->sync; diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index 1e3844583..16ce72be5 100644 --- a/src/gba/gba-thread.h +++ b/src/gba/gba-thread.h @@ -1,6 +1,7 @@ #ifndef GBA_THREAD_H #define GBA_THREAD_H +#include "gba.h" #include "threading.h" struct GBAThread; @@ -48,6 +49,7 @@ struct GBAThread { Mutex stateMutex; Condition stateCond; + GBALogHandler logHandler; ThreadCallback startCallback; ThreadCallback cleanCallback; ThreadCallback frameCallback; diff --git a/src/gba/gba.c b/src/gba/gba.c index 80c9c26af..ae9151c2d 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -8,7 +8,6 @@ #include "debugger.h" #include -#include #include #include #include @@ -513,9 +512,19 @@ void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) { gba = threadContext->gba; } } + + if (gba && gba->logHandler) { + va_list args; + va_start(args, format); + gba->logHandler(gba, level, format, args); + va_end(args); + return; + } + if (gba && !(level & gba->logLevel)) { return; } + va_list args; va_start(args, format); vprintf(format, args); diff --git a/src/gba/gba.h b/src/gba/gba.h index 6d0fd806a..7153445e6 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -7,6 +7,8 @@ #include "gba-video.h" #include "gba-audio.h" +#include + extern const uint32_t GBA_ARM7TDMI_FREQUENCY; enum GBAIRQ { @@ -55,6 +57,8 @@ enum GBAKey { }; struct GBARotationSource; +struct GBA; +typedef void (*GBALogHandler)(struct GBA*, enum GBALogLevel, const char* format, va_list args); struct GBABoard { struct ARMBoard d; @@ -93,7 +97,9 @@ struct GBA { const char* activeFile; const char* savefile; + int logLevel; + GBALogHandler logHandler; }; struct GBACartridge { diff --git a/src/platform/sdl/gl-main.c b/src/platform/sdl/gl-main.c index 6503f0f73..f9b6ac8b8 100644 --- a/src/platform/sdl/gl-main.c +++ b/src/platform/sdl/gl-main.c @@ -58,7 +58,6 @@ int main(int argc, char** argv) { return 1; } - struct GBAThread context; struct GLSoftwareRenderer renderer; GBAVideoSoftwareRendererCreate(&renderer.d); @@ -69,19 +68,20 @@ int main(int argc, char** argv) { return 1; } - context.fd = fd; - context.fname = fname; - context.useDebugger = 1; - context.renderer = &renderer.d.d; - context.frameskip = 0; - context.sync.videoFrameWait = 0; - context.sync.audioWait = 1; - context.startCallback = _GBASDLStart; - context.cleanCallback = _GBASDLClean; - context.frameCallback = 0; - context.userData = &renderer; - context.rewindBufferCapacity = 10; - context.rewindBufferInterval = 30; + struct GBAThread context = { + .fd = fd, + .fname = fname, + .useDebugger = 1, + .renderer = &renderer.d.d, + .frameskip = 0, + .sync.videoFrameWait = 0, + .sync.audioWait = 1, + .startCallback = _GBASDLStart, + .cleanCallback = _GBASDLClean, + .userData = &renderer, + .rewindBufferCapacity = 10, + .rewindBufferInterval = 30 + }; GBAThreadStart(&context); _GBASDLRunloop(&context, &renderer);