summaryrefslogtreecommitdiff
path: root/src/libultra_code/osPfsFindFile.c
diff options
context:
space:
mode:
authorLucas Shaw <49287729+shawlucas@users.noreply.github.com>2020-07-06 17:15:01 -0700
committerGitHub <noreply@github.com>2020-07-06 20:15:01 -0400
commit7e195a35621e629f47be7ebd70f91775a01498da (patch)
treef2f1ef0440bce50131dd18547ee63ab268be42f0 /src/libultra_code/osPfsFindFile.c
parente6ca2dfd70ef4f76af85b8492e67fb17b1e4dc71 (diff)
Matched most remaining libultra files (#221)
* osPfsIsPlug.c and osContSetCh.c OK * update * __osPfsGetStatus.c OK * removed unused asm * Updated all libultra controller files to use new structs instead of the temporary structs. Added os_pfs.h * controller updates * fixed header guard * Made suggested changes * guLookAt.c OK * commit * __osPfsSelectBank.c OK * osPfsDeleteFile.c OK * pfsreadwritefile.c OK * osPfsFreeBlocks.c OK * cleaned up ospfsfreeblocks * started pfsinitpak.c * pfsallocatefile.c OK * contpfs.c decompiled with 1 non matching * osPfsFindFile.c OK * pfsinitpak.c decompiled. one non-matching * Actually fixed merge conflict * sins.c OK * cosf.c sinf.c and sins.c OK * moved osAfterPreNMI to its own file. Renamed code_801031F0 to contquery.c * pfschecker.c OK * final update and rename * Removed makefile testing thing that i accidentally added * Made suggested changes
Diffstat (limited to 'src/libultra_code/osPfsFindFile.c')
-rw-r--r--src/libultra_code/osPfsFindFile.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/libultra_code/osPfsFindFile.c b/src/libultra_code/osPfsFindFile.c
new file mode 100644
index 000000000..4320aca4b
--- /dev/null
+++ b/src/libultra_code/osPfsFindFile.c
@@ -0,0 +1,53 @@
+#include <ultra64.h>
+#include <global.h>
+
+s32 osPfsFindFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32* fileNo) {
+ s32 j;
+ s32 i;
+ __OSDir dir;
+ s32 ret = 0;
+ s32 err;
+
+ if (!(pfs->status & PFS_INITIALIZED)) {
+ return PFS_ERR_INVALID;
+ }
+
+ if ((ret = __osCheckId(pfs)) != 0) {
+ return ret;
+ }
+
+ for (j = 0; j < pfs->dir_size; j++) {
+ if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, &dir)) != 0) {
+ return ret;
+ }
+ if ((ret = __osPfsGetStatus(pfs->queue, pfs->channel)) != 0) {
+ return ret;
+ }
+
+ if ((dir.company_code == companyCode) && (dir.game_code == gameCode)) {
+ err = 0;
+ if (gameName != 0) {
+ for (i = 0; i < PFS_FILE_NAME_LEN; i++) {
+ if (dir.game_name[i] != gameName[i]) {
+ err = 1;
+ break;
+ }
+ }
+ }
+ if ((extName != 0) && (err == 0)) {
+ for (i = 0; i < PFS_FILE_EXT_LEN; i++) {
+ if (dir.ext_name[i] != extName[i]) {
+ err = 1;
+ break;
+ }
+ }
+ }
+ if (err == 0) {
+ *fileNo = j;
+ return ret;
+ }
+ }
+ }
+ *fileNo = -1;
+ return PFS_ERR_INVALID;
+}