all repos — mgba @ 2c7926ef66d3c4a8703abd60f619109a15f56f23

mGBA Game Boy Advance Emulator

3DS: Adapt VFileOpen for 3DS
Jeffrey Pfau jeffrey@endrift.com
Sat, 22 Aug 2015 17:21:35 -0700
commit

2c7926ef66d3c4a8703abd60f619109a15f56f23

parent

7fa535380165fdb517433a65f1adec435a941950

3 files changed, 38 insertions(+), 3 deletions(-)

jump to
M src/platform/3ds/3ds-vfs.hsrc/platform/3ds/3ds-vfs.h

@@ -12,6 +12,8 @@ #define asm __asm__

#include <3ds.h> +extern FS_archive sdmcArchive; + struct VFile* VFileOpen3DS(FS_archive* archive, const char* path, int flags); #endif
M src/platform/3ds/main.csrc/platform/3ds/main.c

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

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

@@ -22,10 +24,9 @@ aptInit();

hidInit(0); gfxInit(GSP_RGB565_OES, GSP_RGB565_OES, false); fsInit(); - - FS_archive sdmcArchive = (FS_archive) { + sdmcArchive = (FS_archive) { ARCH_SDMC, - (FS_path) { PATH_EMPTY, 1, (u8*)"" }, + (FS_path) { PATH_EMPTY, 1, (const u8*)"" }, 0, 0 }; FSUSER_OpenArchive(0, &sdmcArchive);
M src/util/vfs.csrc/util/vfs.c

@@ -5,6 +5,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "vfs.h" +#ifdef _3DS +#include "platform/3ds/3ds-vfs.h" +#endif + struct VFile* VFileOpen(const char* path, int flags) { #ifdef USE_VFS_FILE const char* chflags;

@@ -30,6 +34,34 @@ chflags = "rb";

break; } return VFileFOpen(path, chflags); +#elif defined(_3DS) + int ctrFlags = FS_OPEN_READ; + switch (flags & O_ACCMODE) { + case O_WRONLY: + ctrFlags = FS_OPEN_WRITE; + break; + case O_RDWR: + ctrFlags = FS_OPEN_READ | FS_OPEN_WRITE; + break; + case O_RDONLY: + ctrFlags = FS_OPEN_READ; + break; + } + + if (flags & O_CREAT) { + ctrFlags |= FS_OPEN_CREATE; + } + struct VFile* vf = VFileOpen3DS(&sdmcArchive, path, ctrFlags); + if (!vf) { + return 0; + } + if (flags & O_TRUNC) { + vf->truncate(vf, 0); + } + if (flags & O_APPEND) { + vf->seek(vf, vf->size(vf), SEEK_SET); + } + return vf; #else return VFileOpenFD(path, flags); #endif