all repos — mgba @ 2495b650a4dbf12c4955e187f8b3551b67f76297

mGBA Game Boy Advance Emulator

Wii: List devices at root
Jeffrey Pfau jeffrey@endrift.com
Fri, 18 Dec 2015 22:18:52 -0800
commit

2495b650a4dbf12c4955e187f8b3551b67f76297

parent

7d9a89770007203bfa70d6921d0e30fa42afbf3a

M src/gba/context/config.csrc/gba/context/config.c

@@ -209,7 +209,7 @@ snprintf(out, outLength, "cache0:/%s", projectName);

sceIoMkdir(out, 0777); #elif defined(GEKKO) UNUSED(portable); - snprintf(out, outLength, "/%s", projectName); + snprintf(out, outLength, "sd:/%s", projectName); mkdir(out, 0777); #elif defined(_3DS) snprintf(out, outLength, "/%s", projectName);
M src/platform/wii/CMakeLists.txtsrc/platform/wii/CMakeLists.txt

@@ -4,7 +4,7 @@ find_program(RAW2C raw2c)

find_program(WIILOAD wiiload) set(OS_DEFINES COLOR_16_BIT COLOR_5_6_5 USE_VFS_FILE) -list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-file.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c) +list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-file.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-devlist.c) include_directories(${CMAKE_CURRENT_BINARY_DIR})
M src/platform/wii/main.csrc/platform/wii/main.c

@@ -185,7 +185,7 @@ VIDEO_SetPostRetraceCallback(_retraceCallback);

font = GUIFontCreate(); - fatInitDefault(); + fatInit(4, false); rumble.setRumble = _setRumble;

@@ -197,7 +197,7 @@

struct GBAGUIRunner runner = { .params = { vmode->fbWidth * 0.9, vmode->efbHeight * 0.9, - font, "/", + font, "", _drawStart, _drawEnd, _pollInput, _pollCursor, 0,
M src/util/gui/file-select.csrc/util/gui/file-select.c

@@ -32,6 +32,7 @@

static void _upDirectory(char* currentPath) { char* end = strrchr(currentPath, '/'); if (!end) { + currentPath[0] = '\0'; return; } if (end == currentPath) {

@@ -163,7 +164,7 @@ }

} else { size_t len = strlen(params->currentPath); const char* sep = PATH_SEP; - if (params->currentPath[len - 1] == *sep) { + if (!len || params->currentPath[len - 1] == *sep) { sep = ""; } snprintf(outPath, outLen, "%s%s%s", params->currentPath, sep, item->title);
M src/util/vfs.hsrc/util/vfs.h

@@ -80,6 +80,8 @@ #ifdef USE_LZMA

struct VDir* VDirOpen7z(const char* path, int flags); #endif +struct VDir* VDeviceList(void); + struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode); struct VFile* VDirOptionalOpenIncrementFile(struct VDir* dir, const char* realPath, const char* prefix,
A src/util/vfs/vfs-devlist.c

@@ -0,0 +1,111 @@

+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * 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 "util/vfs.h" + +#include <fat.h> + +static bool _vdlClose(struct VDir* vd); +static void _vdlRewind(struct VDir* vd); +static struct VDirEntry* _vdlListNext(struct VDir* vd); +static struct VFile* _vdlOpenFile(struct VDir* vd, const char* path, int mode); +static struct VDir* _vdlOpenDir(struct VDir* vd, const char* path); + +static const char* _vdleName(struct VDirEntry* vde); +static enum VFSType _vdleType(struct VDirEntry* vde); + +extern const struct { + const char* name; + const DISC_INTERFACE* (*getInterface)(void); +} _FAT_disc_interfaces[]; + +struct VDirEntryDevList { + struct VDirEntry d; + size_t index; + char* name; +}; + +struct VDirDevList { + struct VDir d; + struct VDirEntryDevList vde; +}; + +struct VDir* VDeviceList() { + struct VDirDevList* vd = malloc(sizeof(struct VDirDevList)); + if (!vd) { + return 0; + } + + vd->d.close = _vdlClose; + vd->d.rewind = _vdlRewind; + vd->d.listNext = _vdlListNext; + vd->d.openFile = _vdlOpenFile; + vd->d.openDir = _vdlOpenDir; + + vd->vde.d.name = _vdleName; + vd->vde.d.type = _vdleType; + vd->vde.index = 0; + vd->vde.name = 0; + + return &vd->d; +} + +static bool _vdlClose(struct VDir* vd) { + struct VDirDevList* vdl = (struct VDirDevList*) vd; + free(vdl->vde.name); + free(vdl); + return true; +} + +static void _vdlRewind(struct VDir* vd) { + struct VDirDevList* vdl = (struct VDirDevList*) vd; + free(vdl->vde.name); + vdl->vde.name = 0; + vdl->vde.index = 0; +} + +static struct VDirEntry* _vdlListNext(struct VDir* vd) { + struct VDirDevList* vdl = (struct VDirDevList*) vd; + if (vdl->vde.name) { + ++vdl->vde.index; + free(vdl->vde.name); + vdl->vde.name = 0; + } + while (true) { + if (!_FAT_disc_interfaces[vdl->vde.index].name || !_FAT_disc_interfaces[vdl->vde.index].getInterface) { + return 0; + } + const DISC_INTERFACE* iface = _FAT_disc_interfaces[vdl->vde.index].getInterface(); + if (iface && iface->isInserted()) { + vdl->vde.name = malloc(strlen(_FAT_disc_interfaces[vdl->vde.index].name) + 3); + sprintf(vdl->vde.name, "%s:", _FAT_disc_interfaces[vdl->vde.index].name); + return &vdl->vde.d; + } + + ++vdl->vde.index; + } +} + +static struct VFile* _vdlOpenFile(struct VDir* vd, const char* path, int mode) { + UNUSED(vd); + UNUSED(path); + UNUSED(mode); + return 0; +} + +static struct VDir* _vdlOpenDir(struct VDir* vd, const char* path) { + UNUSED(vd); + return VDirOpen(path); +} + +static const char* _vdleName(struct VDirEntry* vde) { + struct VDirEntryDevList* vdle = (struct VDirEntryDevList*) vde; + return vdle->name; +} + +static enum VFSType _vdleType(struct VDirEntry* vde) { + UNUSED(vde); + return VFS_DIRECTORY; +}
M src/util/vfs/vfs-dirent.csrc/util/vfs/vfs-dirent.c

@@ -34,6 +34,11 @@ char* path;

}; struct VDir* VDirOpen(const char* path) { +#ifdef __wii__ + if (!path || !path[0]) { + return VDeviceList(); + } +#endif DIR* de = opendir(path); if (!de) { return 0;