mirror of https://github.com/mgba-emu/mgba.git
GBA Context: Move logging and option parsing into GBAContext
This commit is contained in:
parent
f25486eca3
commit
8452e880c2
|
@ -10,10 +10,14 @@
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/vfs.h"
|
#include "util/vfs.h"
|
||||||
|
|
||||||
|
static struct VFile* _logFile = 0;
|
||||||
|
static void _GBAContextLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args);
|
||||||
|
|
||||||
bool GBAContextInit(struct GBAContext* context, const char* port) {
|
bool GBAContextInit(struct GBAContext* context, const char* port) {
|
||||||
context->gba = anonymousMemoryMap(sizeof(struct GBA));
|
context->gba = anonymousMemoryMap(sizeof(struct GBA));
|
||||||
context->cpu = anonymousMemoryMap(sizeof(struct ARMCore));
|
context->cpu = anonymousMemoryMap(sizeof(struct ARMCore));
|
||||||
context->rom = 0;
|
context->rom = 0;
|
||||||
|
context->bios = 0;
|
||||||
context->fname = 0;
|
context->fname = 0;
|
||||||
context->save = 0;
|
context->save = 0;
|
||||||
context->renderer = 0;
|
context->renderer = 0;
|
||||||
|
@ -28,16 +32,34 @@ bool GBAContextInit(struct GBAContext* context, const char* port) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBAConfigInit(&context->config, port);
|
|
||||||
if (port) {
|
|
||||||
GBAConfigLoad(&context->config);
|
|
||||||
}
|
|
||||||
|
|
||||||
GBACreate(context->gba);
|
GBACreate(context->gba);
|
||||||
ARMSetComponents(context->cpu, &context->gba->d, 0, context->components);
|
ARMSetComponents(context->cpu, &context->gba->d, 0, context->components);
|
||||||
ARMInit(context->cpu);
|
ARMInit(context->cpu);
|
||||||
|
|
||||||
|
GBAConfigInit(&context->config, port);
|
||||||
|
if (port) {
|
||||||
|
if (!_logFile) {
|
||||||
|
char logPath[PATH_MAX];
|
||||||
|
GBAConfigDirectory(logPath, PATH_MAX);
|
||||||
|
strncat(logPath, PATH_SEP "log", PATH_MAX - strlen(logPath));
|
||||||
|
_logFile = VFileOpen(logPath, O_WRONLY | O_CREAT | O_TRUNC);
|
||||||
|
}
|
||||||
|
context->gba->logHandler = _GBAContextLog;
|
||||||
|
|
||||||
|
char biosPath[PATH_MAX];
|
||||||
|
GBAConfigDirectory(biosPath, PATH_MAX);
|
||||||
|
strncat(biosPath, PATH_SEP "gba_bios.bin", PATH_MAX - strlen(biosPath));
|
||||||
|
|
||||||
|
struct GBAOptions opts = {
|
||||||
|
.bios = biosPath,
|
||||||
|
.useBios = true,
|
||||||
|
.idleOptimization = IDLE_LOOP_DETECT,
|
||||||
|
.logLevel = GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS
|
||||||
|
};
|
||||||
|
GBAConfigLoadDefaults(&context->config, &opts);
|
||||||
|
GBAConfigLoad(&context->config);
|
||||||
|
}
|
||||||
|
|
||||||
context->gba->sync = 0;
|
context->gba->sync = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -130,6 +152,10 @@ bool GBAContextStart(struct GBAContext* context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GBAConfigMap(&context->config, &opts);
|
GBAConfigMap(&context->config, &opts);
|
||||||
|
|
||||||
|
if (!context->bios && opts.bios) {
|
||||||
|
GBAContextLoadBIOS(context, opts.bios);
|
||||||
|
}
|
||||||
if (opts.useBios && context->bios) {
|
if (opts.useBios && context->bios) {
|
||||||
GBALoadBIOS(context->gba, context->bios);
|
GBALoadBIOS(context->gba, context->bios);
|
||||||
}
|
}
|
||||||
|
@ -166,3 +192,19 @@ void GBAContextFrame(struct GBAContext* context, uint16_t keys) {
|
||||||
ARMRunLoop(context->cpu);
|
ARMRunLoop(context->cpu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _GBAContextLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args) {
|
||||||
|
UNUSED(thread);
|
||||||
|
UNUSED(level);
|
||||||
|
// TODO: Make this local
|
||||||
|
if (!_logFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char out[256];
|
||||||
|
size_t len = vsnprintf(out, sizeof(out), format, args);
|
||||||
|
if (len >= sizeof(out)) {
|
||||||
|
len = sizeof(out) - 1;
|
||||||
|
}
|
||||||
|
out[len] = '\n';
|
||||||
|
_logFile->write(_logFile, out, len + 1);
|
||||||
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ static struct GBA3DSRotationSource {
|
||||||
angularRate gyro;
|
angularRate gyro;
|
||||||
} rotation;
|
} rotation;
|
||||||
|
|
||||||
static struct VFile* logFile;
|
|
||||||
static bool hasSound;
|
static bool hasSound;
|
||||||
// TODO: Move into context
|
// TODO: Move into context
|
||||||
static struct GBAVideoSoftwareRenderer renderer;
|
static struct GBAVideoSoftwareRenderer renderer;
|
||||||
|
@ -50,7 +49,6 @@ static size_t audioPos = 0;
|
||||||
static sf2d_texture* tex;
|
static sf2d_texture* tex;
|
||||||
|
|
||||||
extern bool allocateRomBuffer(void);
|
extern bool allocateRomBuffer(void);
|
||||||
static void GBA3DSLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args);
|
|
||||||
|
|
||||||
static void _postAudioBuffer(struct GBAAVStream* stream, struct GBAAudio* audio);
|
static void _postAudioBuffer(struct GBAAVStream* stream, struct GBAAudio* audio);
|
||||||
|
|
||||||
|
@ -68,13 +66,6 @@ static void _drawEnd(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _setup(struct GBAGUIRunner* runner) {
|
static void _setup(struct GBAGUIRunner* runner) {
|
||||||
struct GBAOptions opts = {
|
|
||||||
.useBios = true,
|
|
||||||
.logLevel = 0,
|
|
||||||
.idleOptimization = IDLE_LOOP_DETECT
|
|
||||||
};
|
|
||||||
GBAConfigLoadDefaults(&runner->context.config, &opts);
|
|
||||||
runner->context.gba->logHandler = GBA3DSLog;
|
|
||||||
runner->context.gba->rotationSource = &rotation.d;
|
runner->context.gba->rotationSource = &rotation.d;
|
||||||
if (hasSound) {
|
if (hasSound) {
|
||||||
runner->context.gba->stream = &stream;
|
runner->context.gba->stream = &stream;
|
||||||
|
@ -323,7 +314,6 @@ int main() {
|
||||||
};
|
};
|
||||||
FSUSER_OpenArchive(0, &sdmcArchive);
|
FSUSER_OpenArchive(0, &sdmcArchive);
|
||||||
|
|
||||||
logFile = VFileOpen("/mgba.log", O_WRONLY | O_CREAT | O_TRUNC);
|
|
||||||
struct GUIFont* font = GUIFontCreate();
|
struct GUIFont* font = GUIFontCreate();
|
||||||
|
|
||||||
if (!font) {
|
if (!font) {
|
||||||
|
@ -352,17 +342,14 @@ int main() {
|
||||||
.incrementScreenMode = _incrementScreenMode,
|
.incrementScreenMode = _incrementScreenMode,
|
||||||
.pollGameInput = _pollGameInput
|
.pollGameInput = _pollGameInput
|
||||||
};
|
};
|
||||||
GBAGUIInit(&runner, 0);
|
|
||||||
|
GBAGUIInit(&runner, "3ds");
|
||||||
GBAGUIRunloop(&runner);
|
GBAGUIRunloop(&runner);
|
||||||
GBAGUIDeinit(&runner);
|
GBAGUIDeinit(&runner);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
linearFree(renderer.outputBuffer);
|
linearFree(renderer.outputBuffer);
|
||||||
|
|
||||||
if (logFile) {
|
|
||||||
logFile->close(logFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
sf2d_free_texture(tex);
|
sf2d_free_texture(tex);
|
||||||
sf2d_fini();
|
sf2d_fini();
|
||||||
|
|
||||||
|
@ -373,18 +360,3 @@ cleanup:
|
||||||
csndExit();
|
csndExit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GBA3DSLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args) {
|
|
||||||
UNUSED(thread);
|
|
||||||
UNUSED(level);
|
|
||||||
if (!logFile) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
char out[256];
|
|
||||||
size_t len = vsnprintf(out, sizeof(out), format, args);
|
|
||||||
if (len >= sizeof(out)) {
|
|
||||||
len = sizeof(out) - 1;
|
|
||||||
}
|
|
||||||
out[len] = '\n';
|
|
||||||
logFile->write(logFile, out, len + 1);
|
|
||||||
}
|
|
||||||
|
|
|
@ -158,7 +158,6 @@ void retro_init(void) {
|
||||||
GBAContextInit(&context, 0);
|
GBAContextInit(&context, 0);
|
||||||
struct GBAOptions opts = {
|
struct GBAOptions opts = {
|
||||||
.useBios = true,
|
.useBios = true,
|
||||||
.logLevel = 0,
|
|
||||||
.idleOptimization = IDLE_LOOP_REMOVE
|
.idleOptimization = IDLE_LOOP_REMOVE
|
||||||
};
|
};
|
||||||
GBAConfigLoadDefaults(&context.config, &opts);
|
GBAConfigLoadDefaults(&context.config, &opts);
|
||||||
|
|
|
@ -100,7 +100,7 @@ int main() {
|
||||||
.pollGameInput = GBAPSP2PollInput
|
.pollGameInput = GBAPSP2PollInput
|
||||||
};
|
};
|
||||||
|
|
||||||
GBAGUIInit(&runner, 0);
|
GBAGUIInit(&runner, "psvita");
|
||||||
GBAGUIRunloop(&runner);
|
GBAGUIRunloop(&runner);
|
||||||
GBAGUIDeinit(&runner);
|
GBAGUIDeinit(&runner);
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,6 @@ void GBAPSP2Setup(struct GBAGUIRunner* runner) {
|
||||||
scePowerSetArmClockFrequency(80);
|
scePowerSetArmClockFrequency(80);
|
||||||
struct GBAOptions opts = {
|
struct GBAOptions opts = {
|
||||||
.useBios = true,
|
.useBios = true,
|
||||||
.logLevel = 0,
|
|
||||||
.idleOptimization = IDLE_LOOP_DETECT
|
.idleOptimization = IDLE_LOOP_DETECT
|
||||||
};
|
};
|
||||||
GBAConfigLoadDefaults(&runner->context.config, &opts);
|
GBAConfigLoadDefaults(&runner->context.config, &opts);
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
#define SAMPLES 1024
|
#define SAMPLES 1024
|
||||||
|
|
||||||
static void GBAWiiLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args);
|
|
||||||
|
|
||||||
static void _audioDMA(void);
|
static void _audioDMA(void);
|
||||||
static void _setRumble(struct GBARumble* rumble, int enable);
|
static void _setRumble(struct GBARumble* rumble, int enable);
|
||||||
static void _sampleRotation(struct GBARotationSource* source);
|
static void _sampleRotation(struct GBARotationSource* source);
|
||||||
|
@ -47,7 +45,6 @@ static uint16_t _pollGameInput(struct GBAGUIRunner* runner);
|
||||||
static struct GBAVideoSoftwareRenderer renderer;
|
static struct GBAVideoSoftwareRenderer renderer;
|
||||||
static struct GBARumble rumble;
|
static struct GBARumble rumble;
|
||||||
static struct GBARotationSource rotation;
|
static struct GBARotationSource rotation;
|
||||||
static FILE* logfile;
|
|
||||||
static GXRModeObj* mode;
|
static GXRModeObj* mode;
|
||||||
static Mtx model, view, modelview;
|
static Mtx model, view, modelview;
|
||||||
static uint16_t* texmem;
|
static uint16_t* texmem;
|
||||||
|
@ -148,8 +145,6 @@ int main() {
|
||||||
|
|
||||||
fatInitDefault();
|
fatInitDefault();
|
||||||
|
|
||||||
logfile = fopen("/mgba.log", "w");
|
|
||||||
|
|
||||||
rumble.setRumble = _setRumble;
|
rumble.setRumble = _setRumble;
|
||||||
|
|
||||||
rotation.sample = _sampleRotation;
|
rotation.sample = _sampleRotation;
|
||||||
|
@ -177,11 +172,10 @@ int main() {
|
||||||
.unpaused = 0,
|
.unpaused = 0,
|
||||||
.pollGameInput = _pollGameInput
|
.pollGameInput = _pollGameInput
|
||||||
};
|
};
|
||||||
GBAGUIInit(&runner, 0);
|
GBAGUIInit(&runner, "wii");
|
||||||
GBAGUIRunloop(&runner);
|
GBAGUIRunloop(&runner);
|
||||||
GBAGUIDeinit(&runner);
|
GBAGUIDeinit(&runner);
|
||||||
|
|
||||||
fclose(logfile);
|
|
||||||
free(fifo);
|
free(fifo);
|
||||||
|
|
||||||
free(renderer.outputBuffer);
|
free(renderer.outputBuffer);
|
||||||
|
@ -190,17 +184,6 @@ int main() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAWiiLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args) {
|
|
||||||
UNUSED(thread);
|
|
||||||
UNUSED(level);
|
|
||||||
if (!logfile) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
vfprintf(logfile, format, args);
|
|
||||||
fprintf(logfile, "\n");
|
|
||||||
fflush(logfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _audioDMA(void) {
|
static void _audioDMA(void) {
|
||||||
if (!audioBufferSize) {
|
if (!audioBufferSize) {
|
||||||
return;
|
return;
|
||||||
|
@ -313,13 +296,6 @@ void _guiFinish(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setup(struct GBAGUIRunner* runner) {
|
void _setup(struct GBAGUIRunner* runner) {
|
||||||
struct GBAOptions opts = {
|
|
||||||
.useBios = true,
|
|
||||||
.logLevel = 0,
|
|
||||||
.idleOptimization = IDLE_LOOP_DETECT
|
|
||||||
};
|
|
||||||
GBAConfigLoadDefaults(&runner->context.config, &opts);
|
|
||||||
runner->context.gba->logHandler = GBAWiiLog;
|
|
||||||
runner->context.gba->rumble = &rumble;
|
runner->context.gba->rumble = &rumble;
|
||||||
runner->context.gba->rotationSource = &rotation;
|
runner->context.gba->rotationSource = &rotation;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue