all repos — mgba @ 7a3c7c14888216135c8973d73d3eda537b1a25ab

mGBA Game Boy Advance Emulator

3DS: Add log handler
Jeffrey Pfau jeffrey@endrift.com
Mon, 17 Aug 2015 01:39:23 -0700
commit

7a3c7c14888216135c8973d73d3eda537b1a25ab

parent

2cb04809431f0d0144c741a3a6af9b3309ab1f2c

1 files changed, 30 insertions(+), 7 deletions(-)

jump to
M src/platform/3ds/main.csrc/platform/3ds/main.c

@@ -13,6 +13,9 @@ #include "3ds-vfs.h"

#include <3ds.h> +static void GBA3DSLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args); +static Handle logFile; + int main() { srvInit(); aptInit();

@@ -20,6 +23,14 @@ hidInit(0);

gfxInit(GSP_RGB565_OES, GSP_RGB565_OES, false); fsInit(); + FS_archive sdmcArchive = (FS_archive) { + ARCH_SDMC, + (FS_path) { PATH_EMPTY, 1, (u8*)"" }, + 0, 0 + }; + FSUSER_OpenArchive(0, &sdmcArchive); + FSUSER_OpenFile(0, &logFile, sdmcArchive, FS_makePath(PATH_CHAR, "/mgba.log"), FS_OPEN_WRITE | FS_OPEN_CREATE, FS_ATTRIBUTE_NONE); + struct GBAVideoSoftwareRenderer renderer; GBAVideoSoftwareRendererCreate(&renderer);

@@ -32,13 +43,6 @@

renderer.outputBuffer = videoBuffer; renderer.outputBufferStride = VIDEO_HORIZONTAL_PIXELS; - FS_archive sdmcArchive = (FS_archive) { - ARCH_SDMC, - (FS_path) { PATH_EMPTY, 1, (u8*)"" }, - 0, 0 - }; - FSUSER_OpenArchive(0, &sdmcArchive); - struct VFile* rom = VFileOpen3DS(&sdmcArchive, "/rom.gba", FS_OPEN_READ); struct VFile* save = VFileOpen3DS(&sdmcArchive, "/rom.sav", FS_OPEN_WRITE | FS_OPEN_CREATE);

@@ -54,6 +58,8 @@ GBAVideoAssociateRenderer(&gba->video, &renderer.d);

GBALoadROM(gba, rom, save, 0); + gba->logHandler = GBA3DSLog; + ARMReset(cpu); int frameCounter = 0;

@@ -94,6 +100,8 @@ mappedMemoryFree(cpu, 0);

mappedMemoryFree(videoBuffer, 0); + FSFILE_Close(logFile); + fsExit(); gfxExit(); hidExit();

@@ -101,3 +109,18 @@ aptExit();

srvExit(); return 0; } + +static void GBA3DSLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args) { + UNUSED(thread); + UNUSED(level); + char out[256]; + u64 size; + u32 written; + size_t len = vsnprintf(out, sizeof(out), format, args); + if (len >= 256) { + len = 255; + } + out[len] = '\n'; + FSFILE_GetSize(logFile, &size); + FSFILE_Write(logFile, &written, size, out, len + 1, FS_WRITE_FLUSH); +}