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);
|
||||
#endif
|
||||
|
||||
gba.logHandler = threadContext->logHandler;
|
||||
GBAInit(&gba);
|
||||
threadContext->gba = &gba;
|
||||
gba.sync = &threadContext->sync;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 @@ 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);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "gba-video.h"
|
||||
#include "gba-audio.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue