all repos — mgba @ 70afe23fe4b7609ca85ee080b8dca255ff6d325a

mGBA Game Boy Advance Emulator

Add log handling
Jeffrey Pfau jeffrey@endrift.com
Wed, 29 Jan 2014 22:40:13 -0800
commit

70afe23fe4b7609ca85ee080b8dca255ff6d325a

parent

9d351d4a5835da48fd7a4ed24f7cba27adf0ce74

5 files changed, 33 insertions(+), 15 deletions(-)

jump to
M src/gba/gba-thread.csrc/gba/gba-thread.c

@@ -57,6 +57,7 @@ sigemptyset(&signals);

pthread_sigmask(SIG_SETMASK, &signals, 0); #endif + gba.logHandler = threadContext->logHandler; GBAInit(&gba); threadContext->gba = &gba; gba.sync = &threadContext->sync;
M src/gba/gba-thread.hsrc/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 @@

Mutex stateMutex; Condition stateCond; + GBALogHandler logHandler; ThreadCallback startCallback; ThreadCallback cleanCallback; ThreadCallback frameCallback;
M src/gba/gba.csrc/gba/gba.c

@@ -8,7 +8,6 @@

#include "debugger.h" #include <limits.h> -#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h>

@@ -513,9 +512,19 @@ if (threadContext) {

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);
M src/gba/gba.hsrc/gba/gba.h

@@ -7,6 +7,8 @@ #include "gba-memory.h"

#include "gba-video.h" #include "gba-audio.h" +#include <stdarg.h> + extern const uint32_t GBA_ARM7TDMI_FREQUENCY; enum GBAIRQ {

@@ -55,6 +57,8 @@ GBA_KEY_L = 9

}; 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 GBARumble* rumble;

const char* activeFile; const char* savefile; + int logLevel; + GBALogHandler logHandler; }; struct GBACartridge {
M src/platform/sdl/gl-main.csrc/platform/sdl/gl-main.c

@@ -58,7 +58,6 @@ if (fd < 0) {

return 1; } - struct GBAThread context; struct GLSoftwareRenderer renderer; GBAVideoSoftwareRendererCreate(&renderer.d);

@@ -69,19 +68,20 @@ if (!_GBASDLInit(&renderer)) {

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);