From c2d1eb399c2bbcbb2fc4a85ae7095fe4a5eb8f0b Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Thu, 9 Sep 2021 15:13:22 -0400 Subject: [PATCH] Controller Pak functions fleshed out --- .../controller_pak/func_80073E1C.s | 2 +- .../controller_pak/func_80074018.s | 2 +- .../controller_pak/func_80074B34.s | 2 +- .../controller_pak/func_80075000.s | 2 +- .../controller_pak/func_800753D8.s | 2 +- .../controller_pak/func_800756D4.s | 2 +- .../controller_pak/func_80076388.s | 2 +- include/PR/pfs.h | 18 ++++++++++ src/controller_pak.c | 36 ++++++++++--------- src/controller_pak.h | 1 + src/thread0_epc.c | 13 +++---- 11 files changed, 52 insertions(+), 30 deletions(-) diff --git a/asm/non_matchings/controller_pak/func_80073E1C.s b/asm/non_matchings/controller_pak/func_80073E1C.s index 0c3ab296..b9b89a23 100644 --- a/asm/non_matchings/controller_pak/func_80073E1C.s +++ b/asm/non_matchings/controller_pak/func_80073E1C.s @@ -41,7 +41,7 @@ glabel func_80073E1C /* 074AB0 80073EB0 8FA70020 */ lw $a3, 0x20($sp) /* 074AB4 80073EB4 AFA2002C */ sw $v0, 0x2c($sp) /* 074AB8 80073EB8 02002025 */ move $a0, $s0 -/* 074ABC 80073EBC 0C01D984 */ jal func_80076610 +/* 074ABC 80073EBC 0C01D984 */ jal read_file_from_controller_pak /* 074AC0 80073EC0 00403025 */ move $a2, $v0 /* 074AC4 80073EC4 14400013 */ bnez $v0, .L80073F14 /* 074AC8 80073EC8 00401825 */ move $v1, $v0 diff --git a/asm/non_matchings/controller_pak/func_80074018.s b/asm/non_matchings/controller_pak/func_80074018.s index 62fef754..f53a3d3b 100644 --- a/asm/non_matchings/controller_pak/func_80074018.s +++ b/asm/non_matchings/controller_pak/func_80074018.s @@ -41,7 +41,7 @@ glabel func_80074018 /* 074CAC 800740AC 8FA70020 */ lw $a3, 0x20($sp) /* 074CB0 800740B0 AFA2002C */ sw $v0, 0x2c($sp) /* 074CB4 800740B4 02002025 */ move $a0, $s0 -/* 074CB8 800740B8 0C01D984 */ jal func_80076610 +/* 074CB8 800740B8 0C01D984 */ jal read_file_from_controller_pak /* 074CBC 800740BC 00403025 */ move $a2, $v0 /* 074CC0 800740C0 1440000F */ bnez $v0, .L80074100 /* 074CC4 800740C4 00401825 */ move $v1, $v0 diff --git a/asm/non_matchings/controller_pak/func_80074B34.s b/asm/non_matchings/controller_pak/func_80074B34.s index 2a21a5f0..60a21b0c 100644 --- a/asm/non_matchings/controller_pak/func_80074B34.s +++ b/asm/non_matchings/controller_pak/func_80074B34.s @@ -58,7 +58,7 @@ glabel func_80074B34 /* 075808 80074C08 8FA40058 */ lw $a0, 0x58($sp) /* 07580C 80074C0C 8FA50048 */ lw $a1, 0x48($sp) /* 075810 80074C10 8FA60050 */ lw $a2, 0x50($sp) -/* 075814 80074C14 0C01D984 */ jal func_80076610 +/* 075814 80074C14 0C01D984 */ jal read_file_from_controller_pak /* 075818 80074C18 24070100 */ li $a3, 256 /* 07581C 80074C1C 87A8005E */ lh $t0, 0x5e($sp) /* 075820 80074C20 87A90062 */ lh $t1, 0x62($sp) diff --git a/asm/non_matchings/controller_pak/func_80075000.s b/asm/non_matchings/controller_pak/func_80075000.s index 17cb6037..a369a05c 100644 --- a/asm/non_matchings/controller_pak/func_80075000.s +++ b/asm/non_matchings/controller_pak/func_80075000.s @@ -84,7 +84,7 @@ glabel func_80075000 /* 075D0C 8007510C 8FA5004C */ lw $a1, 0x4c($sp) /* 075D10 80075110 8FA70054 */ lw $a3, 0x54($sp) /* 075D14 80075114 00409025 */ move $s2, $v0 -/* 075D18 80075118 0C01D984 */ jal func_80076610 +/* 075D18 80075118 0C01D984 */ jal read_file_from_controller_pak /* 075D1C 8007511C 00403025 */ move $a2, $v0 /* 075D20 80075120 8FA40078 */ lw $a0, 0x78($sp) /* 075D24 80075124 0C01D6BB */ jal func_80075AEC diff --git a/asm/non_matchings/controller_pak/func_800753D8.s b/asm/non_matchings/controller_pak/func_800753D8.s index 25762857..712b72e7 100644 --- a/asm/non_matchings/controller_pak/func_800753D8.s +++ b/asm/non_matchings/controller_pak/func_800753D8.s @@ -52,7 +52,7 @@ glabel func_800753D8 /* 07606C 8007546C 8FA50034 */ lw $a1, 0x34($sp) /* 076070 80075470 8FA70030 */ lw $a3, 0x30($sp) /* 076074 80075474 AFA20048 */ sw $v0, 0x48($sp) -/* 076078 80075478 0C01D984 */ jal func_80076610 +/* 076078 80075478 0C01D984 */ jal read_file_from_controller_pak /* 07607C 8007547C 00403025 */ move $a2, $v0 /* 076080 80075480 8FA40050 */ lw $a0, 0x50($sp) /* 076084 80075484 0C01D6BB */ jal func_80075AEC diff --git a/asm/non_matchings/controller_pak/func_800756D4.s b/asm/non_matchings/controller_pak/func_800756D4.s index 31195ea5..e1956e88 100644 --- a/asm/non_matchings/controller_pak/func_800756D4.s +++ b/asm/non_matchings/controller_pak/func_800756D4.s @@ -74,7 +74,7 @@ glabel func_800756D4 /* 0763D0 800757D0 8FA5005C */ lw $a1, 0x5c($sp) /* 0763D4 800757D4 8FA70058 */ lw $a3, 0x58($sp) /* 0763D8 800757D8 00409025 */ move $s2, $v0 -/* 0763DC 800757DC 0C01D984 */ jal func_80076610 +/* 0763DC 800757DC 0C01D984 */ jal read_file_from_controller_pak /* 0763E0 800757E0 00403025 */ move $a2, $v0 /* 0763E4 800757E4 1440002A */ bnez $v0, .L80075890 /* 0763E8 800757E8 AFA20064 */ sw $v0, 0x64($sp) diff --git a/asm/non_matchings/controller_pak/func_80076388.s b/asm/non_matchings/controller_pak/func_80076388.s index 08702309..c9209d0d 100644 --- a/asm/non_matchings/controller_pak/func_80076388.s +++ b/asm/non_matchings/controller_pak/func_80076388.s @@ -42,7 +42,7 @@ glabel func_80076388 /* 077020 80076420 8FA70034 */ lw $a3, 0x34($sp) /* 077024 80076424 AFA2002C */ sw $v0, 0x2c($sp) /* 077028 80076428 02002025 */ move $a0, $s0 -/* 07702C 8007642C 0C01D984 */ jal func_80076610 +/* 07702C 8007642C 0C01D984 */ jal read_file_from_controller_pak /* 077030 80076430 00403025 */ move $a2, $v0 /* 077034 80076434 02002025 */ move $a0, $s0 /* 077038 80076438 0C01D6BB */ jal func_80075AEC diff --git a/include/PR/pfs.h b/include/PR/pfs.h index d3d2928a..0e9dc7a2 100644 --- a/include/PR/pfs.h +++ b/include/PR/pfs.h @@ -134,4 +134,22 @@ typedef struct { u8 map[PFS_INODE_DIST_MAP]; } __OSInodeCache; +/* file system interface */ + +extern s32 osPfsInitPak(OSMesgQueue *, OSPfs *, int); +extern s32 osPfsRepairId(OSPfs *); +extern s32 osPfsInit(OSMesgQueue *, OSPfs *, int); +extern s32 osPfsReFormat(OSPfs *, OSMesgQueue *, int); +extern s32 osPfsChecker(OSPfs *); +extern s32 osPfsAllocateFile(OSPfs *, u16, u32, u8 *, u8 *, int, s32 *); +extern s32 osPfsFindFile(OSPfs *, u16, u32, u8 *, u8 *, s32 *); +extern s32 osPfsDeleteFile(OSPfs *, u16, u32, u8 *, u8 *); +extern s32 osPfsReadWriteFile(OSPfs *pfs, s32 file_no, u8 flag, int offset, int nbytes, u8 * data_buffer); +extern s32 osPfsFileState(OSPfs *, s32, OSPfsState *); +extern s32 osPfsGetLabel(OSPfs *, u8 *, int *); +extern s32 osPfsSetLabel(OSPfs *, u8 *); +extern s32 osPfsIsPlug(OSMesgQueue *, u8 *); +extern s32 osPfsFreeBlocks(OSPfs *, s32 *); +extern s32 osPfsNumFiles(OSPfs *, s32 *, s32 *); + #endif diff --git a/src/controller_pak.c b/src/controller_pak.c index aae3e3db..23d841bb 100644 --- a/src/controller_pak.c +++ b/src/controller_pak.c @@ -61,7 +61,7 @@ const char D_800E7750[] = "warning: corrupt ghost\n"; /************ .bss ************/ -s32 D_80124010; //OSMesgQueue +OSMesgQueue *D_80124010; s32 D_80124014; OSPfs pfs[MAXCONTROLLERS]; @@ -365,14 +365,15 @@ s32 func_80076194(s32 controllerIndex, s32 *arg1, s32 *arg2) { #ifdef NON_MATCHING // regalloc & stack issues -s32 func_800762C8(s32 controllerIndex, s32 arg1) { +// Rename delete_file_from_controller_pak? +s32 func_800762C8(s32 controllerIndex, s32 fileNum) { s16 sp3E; s16 sp3A; s32 sp30; s32 sp34; u16 sp38; s32 temp_v0; - void *temp_a0; + OSPfs *temp_a0; temp_v0 = func_800758DC(); if (temp_v0 != 0) { @@ -382,7 +383,7 @@ s32 func_800762C8(s32 controllerIndex, s32 arg1) { temp_v0 = controllerIndex << 0x1E; temp_a0 = &pfs[controllerIndex]; temp_v0 |= 9; - if (osPfsFileState(temp_a0, arg1, &sp30) == 0) { + if (osPfsFileState(temp_a0, fileNum, &sp30) == 0) { if (osPfsDeleteFile(temp_a0, sp38, sp34, &sp3E, &sp3A) == 0) { temp_v0 = 0; } @@ -398,21 +399,22 @@ GLOBAL_ASM("asm/non_matchings/controller_pak/func_800762C8.s") GLOBAL_ASM("asm/non_matchings/controller_pak/func_80076388.s") GLOBAL_ASM("asm/non_matchings/controller_pak/func_800764E8.s") -s32 func_80076610(s32 controllerIndex, s32 arg1, u8 *data, s32 dataLength) { - s32 temp_v0 = osPfsReadWriteFile(&pfs[controllerIndex], arg1, 0, 0, dataLength, data); - if (temp_v0 == 0) { +s32 read_file_from_controller_pak(s32 controllerIndex, s32 fileNum, u8 *data, s32 dataLength) { + s32 readResult = osPfsReadWriteFile(&pfs[controllerIndex], fileNum, PFS_READ, 0, dataLength, data); + //Successful read + if (readResult == 0) { return 0; } - if ((temp_v0 == 1) || (temp_v0 == 0xB)) { + if ((readResult == PFS_ERR_NOPACK) || (readResult == PFS_ERR_DEVICE)) { return 1; } - if (temp_v0 == 3) { + if (readResult == PFS_ERR_INCONSISTENT) { return 2; } - if (temp_v0 == 0xA) { + if (readResult == PFS_ERR_ID_FATAL) { return 3; } - if (temp_v0 == 5) { + if (readResult == PFS_ERR_INVALID) { return 5; } return 9; @@ -440,15 +442,15 @@ GLOBAL_ASM("asm/non_matchings/controller_pak/func_80076924.s") GLOBAL_ASM("asm/non_matchings/controller_pak/func_8007698C.s") GLOBAL_ASM("asm/non_matchings/controller_pak/func_80076A38.s") -s32 func_80076AF4(s32 controllerIndex, s32 arg1) { - s32* temp; +s32 func_80076AF4(s32 controllerIndex, s32 fileNum) { + s32 *data; s32 pad; s32 ret; ret = 6; - temp = allocate_from_main_pool_safe(0x100, COLOR_TAG_BLACK); - if (func_80076610(controllerIndex, arg1, temp, 0x100) == 0) { - switch(*temp) { + data = allocate_from_main_pool_safe(0x100, COLOR_TAG_BLACK); + if (read_file_from_controller_pak(controllerIndex, fileNum, (u8 *)data, 0x100) == 0) { + switch(*data) { case 0x47414D44: // GAMD, Game Data? ret = 3; break; @@ -463,6 +465,6 @@ s32 func_80076AF4(s32 controllerIndex, s32 arg1) { break; } } - free_from_memory_pool(temp); + free_from_memory_pool(data); return ret; } diff --git a/src/controller_pak.h b/src/controller_pak.h index 0a342587..97b483f4 100644 --- a/src/controller_pak.h +++ b/src/controller_pak.h @@ -7,5 +7,6 @@ extern s32 D_800DE440; extern u8 gN64FontCodes[68]; extern s32 D_800DE488; extern s32 D_800DE48C; +s32 read_file_from_controller_pak(s32 controllerIndex, s32 fileNum, u8 *data, s32 dataLength); #endif diff --git a/src/thread0_epc.c b/src/thread0_epc.c index a97dffb2..19805094 100644 --- a/src/thread0_epc.c +++ b/src/thread0_epc.c @@ -5,6 +5,7 @@ #include "macros.h" #include "libultra_internal.h" #include "menu.h" +#include "controller_pak.h" /************ .rodata ************/ @@ -286,27 +287,27 @@ void func_800B76B8(s32 arg0, s32 arg1) { } s32 func_800B76DC(void) { - s32 sp824; + s32 fileNum; u8 sp820[4]; // Unused? s16 sp420[0x200]; u8 sp220[0x200]; u8 sp1D0[0x50]; // Unused? - epcInfo sp20; + epcInfo dataFromControllerPak; if (D_800E3020 != -1) { return D_800E3020; } else { D_800E3020 = 0; - if ((func_800758DC(0) == 0) && (func_800764E8(0, &D_800E8EF4, &D_800E8EFC, &sp824) == 0) - && (func_80076610(0, sp824, &sp20, 0x800) == 0)) { - bcopy(&sp20, &gEpcInfo, 0x1B0); + if ((func_800758DC(0) == 0) && (func_800764E8(0, &D_800E8EF4, &D_800E8EFC, &fileNum) == 0) + && (read_file_from_controller_pak(0, fileNum, &dataFromControllerPak, 0x800) == 0)) { + bcopy(&dataFromControllerPak, &gEpcInfo, 0x1B0); bcopy(&sp220, &D_801299B0, 0x200); bcopy(&sp420, &D_80129BB0, 0x400); D_800E3020 = 1; } func_80075AEC(0); if (D_800E3020 != 0) { - func_800762C8(0, sp824); + func_800762C8(0, fileNum); } return D_800E3020; }