3DS: Adapt VFileOpen for 3DS

This commit is contained in:
Jeffrey Pfau 2015-08-22 17:21:35 -07:00
parent 7fa5353801
commit 2c7926ef66
3 changed files with 38 additions and 3 deletions

View File

@ -12,6 +12,8 @@
#include <3ds.h>
extern FS_archive sdmcArchive;
struct VFile* VFileOpen3DS(FS_archive* archive, const char* path, int flags);
#endif

View File

@ -13,6 +13,8 @@
#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 @@ int main() {
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);

View File

@ -5,6 +5,10 @@
* 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 @@ struct VFile* VFileOpen(const char* path, int flags) {
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