mirror of https://github.com/mgba-emu/mgba.git
Add log handling
This commit is contained in:
parent
9d351d4a58
commit
70afe23fe4
|
@ -57,6 +57,7 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
|
||||||
pthread_sigmask(SIG_SETMASK, &signals, 0);
|
pthread_sigmask(SIG_SETMASK, &signals, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
gba.logHandler = threadContext->logHandler;
|
||||||
GBAInit(&gba);
|
GBAInit(&gba);
|
||||||
threadContext->gba = &gba;
|
threadContext->gba = &gba;
|
||||||
gba.sync = &threadContext->sync;
|
gba.sync = &threadContext->sync;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef GBA_THREAD_H
|
#ifndef GBA_THREAD_H
|
||||||
#define GBA_THREAD_H
|
#define GBA_THREAD_H
|
||||||
|
|
||||||
|
#include "gba.h"
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
|
|
||||||
struct GBAThread;
|
struct GBAThread;
|
||||||
|
@ -48,6 +49,7 @@ struct GBAThread {
|
||||||
Mutex stateMutex;
|
Mutex stateMutex;
|
||||||
Condition stateCond;
|
Condition stateCond;
|
||||||
|
|
||||||
|
GBALogHandler logHandler;
|
||||||
ThreadCallback startCallback;
|
ThreadCallback startCallback;
|
||||||
ThreadCallback cleanCallback;
|
ThreadCallback cleanCallback;
|
||||||
ThreadCallback frameCallback;
|
ThreadCallback frameCallback;
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include "debugger.h"
|
#include "debugger.h"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -513,9 +512,19 @@ void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...) {
|
||||||
gba = threadContext->gba;
|
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)) {
|
if (gba && !(level & gba->logLevel)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vprintf(format, args);
|
vprintf(format, args);
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "gba-video.h"
|
#include "gba-video.h"
|
||||||
#include "gba-audio.h"
|
#include "gba-audio.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
extern const uint32_t GBA_ARM7TDMI_FREQUENCY;
|
extern const uint32_t GBA_ARM7TDMI_FREQUENCY;
|
||||||
|
|
||||||
enum GBAIRQ {
|
enum GBAIRQ {
|
||||||
|
@ -55,6 +57,8 @@ enum GBAKey {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GBARotationSource;
|
struct GBARotationSource;
|
||||||
|
struct GBA;
|
||||||
|
typedef void (*GBALogHandler)(struct GBA*, enum GBALogLevel, const char* format, va_list args);
|
||||||
|
|
||||||
struct GBABoard {
|
struct GBABoard {
|
||||||
struct ARMBoard d;
|
struct ARMBoard d;
|
||||||
|
@ -93,7 +97,9 @@ struct GBA {
|
||||||
|
|
||||||
const char* activeFile;
|
const char* activeFile;
|
||||||
const char* savefile;
|
const char* savefile;
|
||||||
|
|
||||||
int logLevel;
|
int logLevel;
|
||||||
|
GBALogHandler logHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GBACartridge {
|
struct GBACartridge {
|
||||||
|
|
|
@ -58,7 +58,6 @@ int main(int argc, char** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GBAThread context;
|
|
||||||
struct GLSoftwareRenderer renderer;
|
struct GLSoftwareRenderer renderer;
|
||||||
GBAVideoSoftwareRendererCreate(&renderer.d);
|
GBAVideoSoftwareRendererCreate(&renderer.d);
|
||||||
|
|
||||||
|
@ -69,19 +68,20 @@ int main(int argc, char** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.fd = fd;
|
struct GBAThread context = {
|
||||||
context.fname = fname;
|
.fd = fd,
|
||||||
context.useDebugger = 1;
|
.fname = fname,
|
||||||
context.renderer = &renderer.d.d;
|
.useDebugger = 1,
|
||||||
context.frameskip = 0;
|
.renderer = &renderer.d.d,
|
||||||
context.sync.videoFrameWait = 0;
|
.frameskip = 0,
|
||||||
context.sync.audioWait = 1;
|
.sync.videoFrameWait = 0,
|
||||||
context.startCallback = _GBASDLStart;
|
.sync.audioWait = 1,
|
||||||
context.cleanCallback = _GBASDLClean;
|
.startCallback = _GBASDLStart,
|
||||||
context.frameCallback = 0;
|
.cleanCallback = _GBASDLClean,
|
||||||
context.userData = &renderer;
|
.userData = &renderer,
|
||||||
context.rewindBufferCapacity = 10;
|
.rewindBufferCapacity = 10,
|
||||||
context.rewindBufferInterval = 30;
|
.rewindBufferInterval = 30
|
||||||
|
};
|
||||||
GBAThreadStart(&context);
|
GBAThreadStart(&context);
|
||||||
|
|
||||||
_GBASDLRunloop(&context, &renderer);
|
_GBASDLRunloop(&context, &renderer);
|
||||||
|
|
Loading…
Reference in New Issue