diff options
| author | Random <28494085+Random06457@users.noreply.github.com> | 2020-10-03 17:22:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-03 11:22:44 -0400 |
| commit | 174af7384d1cfcbf15da02d9069bf02bdc433c20 (patch) | |
| tree | e4fb18346f71047c123ec4d34a80ae7e4d8ab9ea /src/libultra_code_O2/pfsinitpak.c | |
| parent | 6136ee6debd570a63fc695a6f4664553303f2324 (diff) | |
libultra cleanup (#215)
* cleanup libultra
* fixes
- use quotes instead of <> for includes
- add macros for zelda specific thread priorities
- fix Makefile
- properly format the remaining pfs structs
* fix button macros + add CHECK_BTN_ANY/CHECK_BTN_ALL
* remove ULTRA_ABS
* fix includes
* update z_player.c/z_lib.c + run format.sh
* merge upstream/master
* fix include in En_Goroiwa
* fix includes
Diffstat (limited to 'src/libultra_code_O2/pfsinitpak.c')
| -rw-r--r-- | src/libultra_code_O2/pfsinitpak.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/libultra_code_O2/pfsinitpak.c b/src/libultra_code_O2/pfsinitpak.c new file mode 100644 index 000000000..377c4f6a5 --- /dev/null +++ b/src/libultra_code_O2/pfsinitpak.c @@ -0,0 +1,112 @@ +#include "ultra64.h" +#include "global.h" + +s32 osPfsInitPak(OSMesgQueue* queue, OSPfs* pfs, s32 channel) { + s32 ret; + u16 sum; + u16 isum; + u8 temp[BLOCKSIZE]; + __OSPackId* id; + __OSPackId newid; + + __osSiGetAccess(); + + ret = __osPfsGetStatus(queue, channel); + + __osSiRelAccess(); + + if (ret != 0) { + return ret; + } + + pfs->queue = queue; + pfs->channel = channel; + pfs->status = 0; + + if ((ret = __osPfsCheckRamArea(pfs)) != 0) { + return ret; + } + + if ((ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; + } + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, temp)) != 0) { + return (ret); + } + + __osIdCheckSum((u16*)temp, &sum, &isum); + id = (__OSPackId*)temp; + if ((id->checksum != sum) || (id->invertedChecksum != isum)) { + if ((ret = __osCheckPackId(pfs, id)) != 0) { + pfs->status |= PFS_ID_BROKEN; + return ret; + } + } + + if ((id->deviceid & 0x01) == 0) { + ret = __osRepairPackId(pfs, id, &newid); + if (ret) { + if (ret == PFS_ERR_ID_FATAL) { + pfs->status |= PFS_ID_BROKEN; + } + return ret; + } + id = &newid; + if ((id->deviceid & 0x01) == 0) { + return PFS_ERR_DEVICE; + } + } + + bcopy(id, pfs->id, BLOCKSIZE); + + if (0) {} + + pfs->version = id->version; + pfs->banks = id->banks; + pfs->inodeStartPage = 1 + DEF_DIR_PAGES + (2 * pfs->banks); + pfs->dir_size = DEF_DIR_PAGES * PFS_ONE_PAGE; + pfs->inode_table = 1 * PFS_ONE_PAGE; + pfs->minode_table = (1 + pfs->banks) * PFS_ONE_PAGE; + pfs->dir_table = pfs->minode_table + (pfs->banks * PFS_ONE_PAGE); + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label)) != 0) { + return ret; + } + + ret = osPfsChecker(pfs); + pfs->status |= PFS_INITIALIZED; + + return ret; +} + +s32 __osPfsCheckRamArea(OSPfs* pfs) { + s32 i = 0; + s32 ret = 0; + u8 temp1[BLOCKSIZE]; + u8 temp2[BLOCKSIZE]; + u8 saveReg[BLOCKSIZE]; + + if ((ret = __osPfsSelectBank(pfs, PFS_ID_BANK_256K)) != 0) { + return ret; + } + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, saveReg)) != 0) { + return (ret); + } + for (i = 0; i < BLOCKSIZE; i++) { + temp1[i] = i; + } + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, 0, temp1, 0)) != 0) { + return ret; + } + if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, temp2)) != 0) { + return ret; + } + if (bcmp(temp1, temp2, BLOCKSIZE) != 0) { + return PFS_ERR_DEVICE; + } + ret = __osContRamWrite(pfs->queue, pfs->channel, 0, saveReg, 0); + + return ret; +} |
