diff --git a/include/functions.h b/include/functions.h index 6e8b78e939..747e604c33 100644 --- a/include/functions.h +++ b/include/functions.h @@ -316,7 +316,7 @@ OSId osGetThreadId(OSThread* t); void osSpTaskYield(void); s32 __osPfsGetNextPage(OSPfs* param_1, __OSInode* param_2, u8 param_3, u8 param_4); s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, s32 offset, s32 size_in_bytes, u8* data_buffer); -// void __osPfsGetStatus(void); +s32 __osPfsGetStatus(OSMesgQueue* queue, s32 channel); // void __osPfsRequestOneChannel(void); // void __osPfsGetOneChannelData(void); void guMtxIdentF(float mf[4][4]); @@ -346,7 +346,7 @@ s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank); u32 osGetCount(void); void guMtxL2F(MtxF* m1, Mtx* m2); u32 osGetMemSize(void); -// void osPfsFindFile(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 osPfsFindFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32* fileNo); void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg m); f32 sqrtf(f32 __x); s32 osAfterPreNMI(void); diff --git a/src/libultra/io/pfssearchfile.c b/src/libultra/io/pfssearchfile.c index 572e3d0a78..c5f8bcce46 100644 --- a/src/libultra/io/pfssearchfile.c +++ b/src/libultra/io/pfssearchfile.c @@ -1,3 +1,52 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/pfssearchfile/osPfsFindFile.s") +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, (u8*)&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; +}