mirror of https://github.com/mgba-emu/mgba.git
3DS: Add log handler
This commit is contained in:
parent
2cb0480943
commit
7a3c7c1488
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
|
|
||||||
|
static void GBA3DSLog(struct GBAThread* thread, enum GBALogLevel level, const char* format, va_list args);
|
||||||
|
static Handle logFile;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
srvInit();
|
srvInit();
|
||||||
aptInit();
|
aptInit();
|
||||||
|
@ -20,6 +23,14 @@ int main() {
|
||||||
gfxInit(GSP_RGB565_OES, GSP_RGB565_OES, false);
|
gfxInit(GSP_RGB565_OES, GSP_RGB565_OES, false);
|
||||||
fsInit();
|
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;
|
struct GBAVideoSoftwareRenderer renderer;
|
||||||
GBAVideoSoftwareRendererCreate(&renderer);
|
GBAVideoSoftwareRendererCreate(&renderer);
|
||||||
|
|
||||||
|
@ -32,13 +43,6 @@ int main() {
|
||||||
renderer.outputBuffer = videoBuffer;
|
renderer.outputBuffer = videoBuffer;
|
||||||
renderer.outputBufferStride = VIDEO_HORIZONTAL_PIXELS;
|
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* rom = VFileOpen3DS(&sdmcArchive, "/rom.gba", FS_OPEN_READ);
|
||||||
|
|
||||||
struct VFile* save = VFileOpen3DS(&sdmcArchive, "/rom.sav", FS_OPEN_WRITE | FS_OPEN_CREATE);
|
struct VFile* save = VFileOpen3DS(&sdmcArchive, "/rom.sav", FS_OPEN_WRITE | FS_OPEN_CREATE);
|
||||||
|
@ -54,6 +58,8 @@ int main() {
|
||||||
|
|
||||||
GBALoadROM(gba, rom, save, 0);
|
GBALoadROM(gba, rom, save, 0);
|
||||||
|
|
||||||
|
gba->logHandler = GBA3DSLog;
|
||||||
|
|
||||||
ARMReset(cpu);
|
ARMReset(cpu);
|
||||||
|
|
||||||
int frameCounter = 0;
|
int frameCounter = 0;
|
||||||
|
@ -94,6 +100,8 @@ int main() {
|
||||||
|
|
||||||
mappedMemoryFree(videoBuffer, 0);
|
mappedMemoryFree(videoBuffer, 0);
|
||||||
|
|
||||||
|
FSFILE_Close(logFile);
|
||||||
|
|
||||||
fsExit();
|
fsExit();
|
||||||
gfxExit();
|
gfxExit();
|
||||||
hidExit();
|
hidExit();
|
||||||
|
@ -101,3 +109,18 @@ int main() {
|
||||||
srvExit();
|
srvExit();
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue