Skip to content

Commit

Permalink
File reading functions
Browse files Browse the repository at this point in the history
  • Loading branch information
meithecatte committed Jan 28, 2024
1 parent af2ac55 commit 2a325ba
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 45 deletions.
6 changes: 3 additions & 3 deletions include/unk_02017728.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ void sub_020177A4(void);
BOOL sub_020177BC(UnkFuncPtr_02017798 param0, void * param1);
void sub_0201789C(void);
void sub_020179E4(void);
void * sub_02017A40(int param0, const char * param1);
void sub_02017A94(const char * param0, void ** param1);
void * ReadFileToHeap(int heapID, const char * filename);
void ReadFileToBuffer(const char * filename, void ** buf);
void sub_02017ACC(void);
void sub_02017AF4(void);
void InitKeypadAndTouchpad(void);
void sub_02017B70(int param0);
void sub_02017B7C(u8 param0);
void sub_02017B8C(u8 param0);
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void NitroMain (void)
{
sub_0201789C();
sub_020179E4();
sub_02017AF4();
InitKeypadAndTouchpad();

sub_02017B70(0);
PM_GetBackLight(&Unk_02101D20, NULL);
Expand Down
4 changes: 2 additions & 2 deletions src/overlay005/ov5_021D2F14.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void ov5_021D2F14 (UnkStruct_ov5_021D30A8 * param0, const UnkStruct_ov7_0224F2EC

for (v4 = 0; v4 < param0->unk_1C4; v4++) {
v0 = sub_02009F38(v1, v4);
v2 = sub_02017A40(param3, param1->val1[v4]);
v2 = ReadFileToHeap(param3, param1->val1[v4]);

sub_02009F40(v2, v0, param3);
Heap_FreeToHeap(v2);
Expand Down Expand Up @@ -78,7 +78,7 @@ void ov5_021D2F14 (UnkStruct_ov5_021D30A8 * param0, const UnkStruct_ov7_0224F2EC
sub_0200A41C(param0->unk_1AC[0]);
sub_0200A684(param0->unk_1AC[1]);

v2 = sub_02017A40(param3, param1->val2.unk_18);
v2 = ReadFileToHeap(param3, param1->val2.unk_18);
param0->unk_190 = sub_02009508(v2, param3, param0->unk_194[0], param0->unk_194[1], param0->unk_194[2], param0->unk_194[3], param0->unk_194[4], param0->unk_194[5]);

Heap_FreeToHeap(v2);
Expand Down
4 changes: 2 additions & 2 deletions src/unk_0200C6E4.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ BOOL sub_0200C8F0 (UnkStruct_0200C6E4 * param0, UnkStruct_0200C704 * param1, con

for (v0 = 0; v0 < v1; v0++) {
v3 = sub_02009F38(param1->unk_08, v0);
v4 = sub_02017A40(param0->unk_00, param2->val1[v0]);
v4 = ReadFileToHeap(param0->unk_00, param2->val1[v0]);

sub_02009F40(v4, v3, param0->unk_00);
Heap_FreeToHeap(v4);
Expand All @@ -283,7 +283,7 @@ BOOL sub_0200C8F0 (UnkStruct_0200C6E4 * param0, UnkStruct_0200C704 * param1, con
sub_0200A368(param1->unk_24[0]);
sub_0200A60C(param1->unk_24[1]);

v4 = sub_02017A40(param0->unk_00, param2->val2.unk_18);
v4 = ReadFileToHeap(param0->unk_00, param2->val2.unk_18);
param1->unk_04 = sub_02009508(v4, param0->unk_00, param1->unk_0C[0], param1->unk_0C[1], param1->unk_0C[2], param1->unk_0C[3], param1->unk_0C[4], param1->unk_0C[5]);

Heap_FreeToHeap(v4);
Expand Down
54 changes: 24 additions & 30 deletions src/unk_02017728.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,55 +202,49 @@ void sub_020179E4 (void)
MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE);
}

void * sub_02017A40 (int param0, const char * param1)
void * ReadFileToHeap (int heapID, const char * filename)
{
FSFile v0;
void * v1;
FSFile file;
void * buf;

FS_InitFile(&v0);
FS_InitFile(&file);

if (FS_OpenFile(&v0, param1)) {
u32 v2 = FS_GetLength(&v0);
if (FS_OpenFile(&file, filename)) {
u32 length = FS_GetLength(&file);

v1 = Heap_AllocFromHeap(param0, v2);
buf = Heap_AllocFromHeap(heapID, length);

if (v1 == NULL) {
(void)0;
} else {
if (FS_ReadFile(&v0, v1, v2) != v2) {
Heap_FreeToHeapExplicit(param0, v1);
v1 = NULL;
if (buf != NULL) {
if (FS_ReadFile(&file, buf, length) != length) {
Heap_FreeToHeapExplicit(heapID, buf);
buf = NULL;
}
}

(void)FS_CloseFile(&v0);
FS_CloseFile(&file);
} else {
v1 = NULL;
buf = NULL;
}

return v1;
return buf;
}

void sub_02017A94 (const char * param0, void ** param1)
void ReadFileToBuffer (const char * filename, void ** buf)
{
FSFile v0;
FSFile file;

FS_InitFile(&v0);
FS_InitFile(&file);

if (FS_OpenFile(&v0, param0)) {
u32 v1 = FS_GetLength(&v0);
if (FS_OpenFile(&file, filename)) {
u32 length = FS_GetLength(&file);

if (*param1 == NULL) {
(void)0;
} else {
if (FS_ReadFile(&v0, *param1, v1) != v1) {
(void)0;
if (*buf != NULL) {
if (FS_ReadFile(&file, *buf, length) != length) {
/* error not handled */
}
}

(void)FS_CloseFile(&v0);
} else {
(void)0;
FS_CloseFile(&file);
}
}

Expand All @@ -270,7 +264,7 @@ void sub_02017ACC (void)
}
}

void sub_02017AF4 (void)
void InitKeypadAndTouchpad (void)
{
TPCalibrateParam v0;

Expand Down
2 changes: 1 addition & 1 deletion src/unk_0201C970.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void sub_0201C970 (const u8 param0, const char * param1, NNSG3dResMdl ** param2,
NNSG3dResTex * v0 = NULL;
BOOL v1;

*param3 = sub_02017A40(param0, param1);
*param3 = ReadFileToHeap(param0, param1);
NNS_G3D_NULL_ASSERT(*param3);

v0 = NNS_G3dGetTex(*param3);
Expand Down
2 changes: 1 addition & 1 deletion src/unk_020218BC.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ UnkStruct_020218BC * sub_020218BC (const UnkStruct_020095C4 * param0)
v0->unk_10.unk_FC = &v0->unk_10;
v0->unk_10.unk_100 = &v0->unk_10;
v0->unk_110 = param0->unk_04;
v0->unk_114 = sub_02017A40(param0->unk_08, "data/clact_default.NANR");
v0->unk_114 = ReadFileToHeap(param0->unk_08, "data/clact_default.NANR");

NNS_G2dGetUnpackedAnimBank(v0->unk_114, &v0->unk_118);
v0->unk_11C = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/unk_0202298C.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ UnkStruct_02022BC0 * sub_02022A58 (UnkStruct_0202298C * param0, const char * par
GF_ASSERT(v0);
GF_ASSERT((sub_020229F8(param0, param2) == 1));

v0->unk_04 = sub_02017A40(param3, param1);
v0->unk_04 = ReadFileToHeap(param3, param1);
GF_ASSERT(v0->unk_04);
v0->unk_00 = param2;

Expand Down
8 changes: 4 additions & 4 deletions src/unk_020393C8.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void * sub_020394A8 (u32 param0)
{
void * v0 = Heap_AllocFromHeapAtEnd(param0, 600);

sub_02017A94("data/pl_wm.NCLR", &v0);
ReadFileToBuffer("data/pl_wm.NCLR", &v0);
DC_FlushRange(v0, 600);

return v0;
Expand All @@ -161,7 +161,7 @@ static void sub_020394D0 (int param0, BOOL param1, u32 param2, u32 param3)
if (v0) {
NNSG2dPaletteData * v1;

sub_02017A94("data/pl_wm.NCLR", &v0);
ReadFileToBuffer("data/pl_wm.NCLR", &v0);
DC_FlushRange(v0, 600);
NNS_G2dGetUnpackedPaletteData(v0, &v1);

Expand All @@ -184,9 +184,9 @@ static void sub_02039530 (int param0, BOOL param1, u32 param2)
int v2, v3, v4;

if (param1) {
sub_02017A94("data/pl_wifi.NCGR", &v0);
ReadFileToBuffer("data/pl_wifi.NCGR", &v0);
} else {
sub_02017A94("data/pl_wm.NCGR", &v0);
ReadFileToBuffer("data/pl_wm.NCGR", &v0);
}

DC_FlushRange(v0, 600);
Expand Down

0 comments on commit 2a325ba

Please sign in to comment.