From d51dc308fb58879d6e42c02dca2034bf5ecc66da Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 16:28:00 -0800 Subject: [PATCH 01/18] Start eepmgr --- src/main/eepmgr.c | 30 ++++++++++++++++++++++++++++++ yamls/us/main.yaml | 5 ++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/main/eepmgr.c diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c new file mode 100644 index 0000000..f8b1513 --- /dev/null +++ b/src/main/eepmgr.c @@ -0,0 +1,30 @@ +#include "global.h" + + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDA0.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDCC.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDFC.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CF50.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CFB0.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D0B0.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D1EC.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D2C4.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D380.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D488.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D508.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D540.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D590.s") + +#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/D_800B2AE0.s") diff --git a/yamls/us/main.yaml b/yamls/us/main.yaml index 4fce75b..ec2eede 100644 --- a/yamls/us/main.yaml +++ b/yamls/us/main.yaml @@ -81,8 +81,7 @@ - [0x7CC30, asm] - [0x7D140, asm] - [0x7D270, asm] - - [0x7D9A0, asm] - - [0x7E140, asm] + - [0x7D9A0, c, eepmgr] - [0x7E1E0, asm] - [0x7E760, c, dmamgr] - [0x7EC30, asm] @@ -495,7 +494,7 @@ - [0xB3640, rodata, 7CA70] - [0xB3690, rodata, 7CC30] - [0xB36A0, rodata, 7D140] - - [0xB36E0, rodata, 7D9A0] + - [0xB36E0, .rodata, eepmgr] - [0xB39F0, .rodata, dmamgr] - [0xB3AA0, rodata, 7EC30] - [0xB3B10, rodata, 7EE00] From 4c91418f4c60f3893220e6b97ac9dba50ffb08d2 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 17:03:44 -0800 Subject: [PATCH 02/18] Data + func_8007CF50 --- include/eepmgr.h | 17 +++++++++++++++++ src/main/eepmgr.c | 12 +++++++++++- yamls/us/main.yaml | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 include/eepmgr.h diff --git a/include/eepmgr.h b/include/eepmgr.h new file mode 100644 index 0000000..122fd8e --- /dev/null +++ b/include/eepmgr.h @@ -0,0 +1,17 @@ +#ifndef EEPMGR_H +#define EEPMGR_H + +#include "ultra64.h" + + +typedef struct EepMgr { + /* 0x000 */ char unk_000[0x218]; + /* 0x218 */ s32 unk218; + /* 0x21C */ u8 unk21C; + /* 0x21D */ char unk_21D[0x1]; + /* 0x21E */ u16 unk21E; + /* 0x220 */ s32 unk220; + /* 0x224 */ char unk_224[0x4]; +} EepMgr; // size = 0x228 + +#endif diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index f8b1513..a67a47e 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -1,5 +1,9 @@ +#include "eepmgr.h" + #include "global.h" +s32 D_800A9A20 = 1; +u16 D_800A9A24[] = { 0, 0x40, 0x100 }; #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDA0.s") @@ -7,7 +11,13 @@ #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDFC.s") -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CF50.s") +void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3) { + bzero(eepmgr, sizeof(EepMgr)); + eepmgr->unk218 = arg1; + eepmgr->unk220 = arg3; + eepmgr->unk21C = arg2; + eepmgr->unk21E = D_800A9A24[eepmgr->unk21C]; +} #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CFB0.s") diff --git a/yamls/us/main.yaml b/yamls/us/main.yaml index ec2eede..d96f425 100644 --- a/yamls/us/main.yaml +++ b/yamls/us/main.yaml @@ -372,6 +372,8 @@ - [0xA8C0C, font, fault/sFaultFont] - [0xA900C] - [0xA9080, data] + - [0xAA620, .data, eepmgr] + - [0xAA630, data] - [0xAA650, .data, 7EFD0] - [0xAA660, data, O2/gfxprint] - [0xAAF10, .data, O2/808F0] From 3a4864d2c53fd306c090f35bbf250281275454cf Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 17:15:08 -0800 Subject: [PATCH 03/18] func_8007D488 --- include/eepmgr.h | 7 ++++++- src/main/eepmgr.c | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index 122fd8e..c776f36 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -5,7 +5,12 @@ typedef struct EepMgr { - /* 0x000 */ char unk_000[0x218]; + /* 0x000 */ OSMesg unk000[4]; + /* 0x010 */ OSMesg unk004[1]; + /* 0x014 */ OSMesgQueue unk014; + /* 0x02C */ OSMesgQueue unk02C; + /* 0x044 */ char unk_044[0x68 - 0x44]; + /* 0x068 */ OSThread thread; /* 0x218 */ s32 unk218; /* 0x21C */ u8 unk21C; /* 0x21D */ char unk_21D[0x1]; diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index a67a47e..876f0bd 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -27,9 +27,16 @@ void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3) { #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D2C4.s") +void func_8007D380(void* arg); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D380.s") -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D488.s") +void func_8007D488(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3, s32 id, s32 priority, void* stack) { + func_8007CF50(eepmgr, arg1, arg2, arg3); + osCreateMesgQueue(&eepmgr->unk014, eepmgr->unk000, ARRAY_COUNT(eepmgr->unk000)); + osCreateMesgQueue(&eepmgr->unk02C, eepmgr->unk004, ARRAY_COUNT(eepmgr->unk004)); + osCreateThread(&eepmgr->thread, id, func_8007D380, eepmgr, stack, priority); + osStartThread(&eepmgr->thread); +} #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D508.s") From 9ab056eb51ab581e5cbfb064d5c3ee06ea852685 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 18:01:00 -0800 Subject: [PATCH 04/18] func_8007D380 --- include/eepmgr.h | 4 ++++ src/main/eepmgr.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index c776f36..8d4b929 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -3,6 +3,10 @@ #include "ultra64.h" +typedef struct EepRequest { + /* 0x0 */ s16 unk0; + /* 0x4 */ void* unk4; +} EepRequest; typedef struct EepMgr { /* 0x000 */ OSMesg unk000[4]; diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 876f0bd..5fb0083 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -9,6 +9,7 @@ u16 D_800A9A24[] = { 0, 0x40, 0x100 }; #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDCC.s") +void func_8007CDFC(EepMgr* eepmgr); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDFC.s") void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3) { @@ -23,12 +24,38 @@ void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3) { #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D0B0.s") +OSMesg func_8007D1EC(EepMgr* eepmgr, void* arg1); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D1EC.s") +OSMesg func_8007D2C4(EepMgr* eepmgr, void* arg1); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D2C4.s") -void func_8007D380(void* arg); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D380.s") +void func_8007D380(void* arg) { + EepRequest* req = NULL; + EepMgr* eepmgr = (EepMgr*)arg; + void* tmp; + + func_8007CDFC(eepmgr); + do { + osRecvMesg(&eepmgr->unk014, (OSMesg*)&req, OS_MESG_BLOCK); + switch (req->unk0) { + case 8: + if (1) {} + osSendMesg(&eepmgr->unk02C, func_8007D2C4(eepmgr, req->unk4), OS_MESG_BLOCK); + break; + + case 9: + if (1) {} + osSendMesg(&eepmgr->unk02C, func_8007D1EC(eepmgr, req->unk4), OS_MESG_BLOCK); + break; + + //! FAKE: + tmp = req->unk4; + default: + if (tmp != NULL) {} + } + } while (req->unk0 != 4); +} void func_8007D488(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3, s32 id, s32 priority, void* stack) { func_8007CF50(eepmgr, arg1, arg2, arg3); @@ -38,10 +65,13 @@ void func_8007D488(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3, s32 id, s32 pri osStartThread(&eepmgr->thread); } +void func_8007D508(EepMgr* eepmgr); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D508.s") +void func_8007D540(EepMgr* eepmgr, s32 arg1); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D540.s") +void func_8007D590(EepMgr* eepmgr, s32 arg1); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D590.s") #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/D_800B2AE0.s") From 5cbf8987ebe4bd4d5c162524c8748765973850c4 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 18:26:40 -0800 Subject: [PATCH 05/18] func_8007D2C4 --- include/eepmgr.h | 5 ++--- src/main/eepmgr.c | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index 8d4b929..2816fad 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -17,10 +17,9 @@ typedef struct EepMgr { /* 0x068 */ OSThread thread; /* 0x218 */ s32 unk218; /* 0x21C */ u8 unk21C; - /* 0x21D */ char unk_21D[0x1]; /* 0x21E */ u16 unk21E; - /* 0x220 */ s32 unk220; - /* 0x224 */ char unk_224[0x4]; + /* 0x220 */ EepRequest* unk220; + /* 0x224 */ u8 unk224; } EepMgr; // size = 0x228 #endif diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 5fb0083..765bf8f 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -3,7 +3,7 @@ #include "global.h" s32 D_800A9A20 = 1; -u16 D_800A9A24[] = { 0, 0x40, 0x100 }; +u16 D_800A9A24[] = { 0, 0x200 / 8, 0x800 / 8 }; #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDA0.s") @@ -12,7 +12,7 @@ u16 D_800A9A24[] = { 0, 0x40, 0x100 }; void func_8007CDFC(EepMgr* eepmgr); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDFC.s") -void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3) { +void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3) { bzero(eepmgr, sizeof(EepMgr)); eepmgr->unk218 = arg1; eepmgr->unk220 = arg3; @@ -20,15 +20,36 @@ void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3) { eepmgr->unk21E = D_800A9A24[eepmgr->unk21C]; } +s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest* arg2); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CFB0.s") #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D0B0.s") -OSMesg func_8007D1EC(EepMgr* eepmgr, void* arg1); +s32 func_8007D1EC(EepMgr* eepmgr, void* arg1); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D1EC.s") -OSMesg func_8007D2C4(EepMgr* eepmgr, void* arg1); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D2C4.s") +s32 func_8007D2C4(EepMgr* eepmgr, void* arg1) { + s32 var_s0; + EepRequest* req; + + if (eepmgr->unk21C == 0) { + return -1; + } + + if (eepmgr->unk224 == 0) { + req = eepmgr->unk220; + for (var_s0 = 0; var_s0 < eepmgr->unk21E; var_s0++) { + if (func_8007CFB0(eepmgr, var_s0, req)) { + return -1; + } + req++; + } + eepmgr->unk224 = 1; + } + + bcopy(eepmgr->unk220, arg1, eepmgr->unk21E * 8); + return 0; +} void func_8007D380(void* arg) { EepRequest* req = NULL; @@ -41,12 +62,12 @@ void func_8007D380(void* arg) { switch (req->unk0) { case 8: if (1) {} - osSendMesg(&eepmgr->unk02C, func_8007D2C4(eepmgr, req->unk4), OS_MESG_BLOCK); + osSendMesg(&eepmgr->unk02C, (OSMesg)func_8007D2C4(eepmgr, req->unk4), OS_MESG_BLOCK); break; case 9: if (1) {} - osSendMesg(&eepmgr->unk02C, func_8007D1EC(eepmgr, req->unk4), OS_MESG_BLOCK); + osSendMesg(&eepmgr->unk02C, (OSMesg)func_8007D1EC(eepmgr, req->unk4), OS_MESG_BLOCK); break; //! FAKE: @@ -57,7 +78,7 @@ void func_8007D380(void* arg) { } while (req->unk0 != 4); } -void func_8007D488(EepMgr* eepmgr, s32 arg1, s32 arg2, s32 arg3, s32 id, s32 priority, void* stack) { +void func_8007D488(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3, s32 id, s32 priority, void* stack) { func_8007CF50(eepmgr, arg1, arg2, arg3); osCreateMesgQueue(&eepmgr->unk014, eepmgr->unk000, ARRAY_COUNT(eepmgr->unk000)); osCreateMesgQueue(&eepmgr->unk02C, eepmgr->unk004, ARRAY_COUNT(eepmgr->unk004)); From 118a4e97337f5b90226984be2cc5b20cca07bf89 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 21:07:05 -0800 Subject: [PATCH 06/18] func_8007D1EC WIP --- include/eepmgr.h | 7 ++++++- src/main/eepmgr.c | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index 2816fad..df3af9c 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -8,6 +8,11 @@ typedef struct EepRequest { /* 0x4 */ void* unk4; } EepRequest; +typedef struct EepRequest2 { + /* 0x0 */ s32 unk0; + /* 0x4 */ s32 unk4; +} EepRequest2; + typedef struct EepMgr { /* 0x000 */ OSMesg unk000[4]; /* 0x010 */ OSMesg unk004[1]; @@ -18,7 +23,7 @@ typedef struct EepMgr { /* 0x218 */ s32 unk218; /* 0x21C */ u8 unk21C; /* 0x21E */ u16 unk21E; - /* 0x220 */ EepRequest* unk220; + /* 0x220 */ EepRequest2* unk220; /* 0x224 */ u8 unk224; } EepMgr; // size = 0x228 diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 765bf8f..4ee91cb 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -20,29 +20,57 @@ void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3) { eepmgr->unk21E = D_800A9A24[eepmgr->unk21C]; } -s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest* arg2); +s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CFB0.s") +s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D0B0.s") -s32 func_8007D1EC(EepMgr* eepmgr, void* arg1); +#ifdef NON_MATCHING +s32 func_8007D1EC(EepMgr* eepmgr, EepRequest2* arg1) { + EepRequest2* var_s0; + EepRequest2* var_s1; + s32 var_s2; + + if (eepmgr->unk21C == 0) { + return -1; + } + if (eepmgr->unk224 == 0) { + return -1; + } + + for (var_s1 = eepmgr->unk220, var_s0 = arg1, var_s2 = 0; var_s2 < eepmgr->unk21E; var_s1++, var_s0++, var_s2++) { + if ((var_s1->unk0 == var_s0->unk0) && (var_s1->unk4 == var_s0->unk4)) { + continue; + } + + if (func_8007D0B0(eepmgr, var_s2, var_s0)) { + return -1; + } + var_s1->unk0 = var_s0->unk0; + var_s1->unk4 = var_s0->unk4; + } + + return 0; +} +#else +s32 func_8007D1EC(EepMgr* eepmgr, EepRequest2* arg1); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D1EC.s") +#endif -s32 func_8007D2C4(EepMgr* eepmgr, void* arg1) { +s32 func_8007D2C4(EepMgr* eepmgr, EepRequest2* arg1) { s32 var_s0; - EepRequest* req; + EepRequest2* req; if (eepmgr->unk21C == 0) { return -1; } if (eepmgr->unk224 == 0) { - req = eepmgr->unk220; - for (var_s0 = 0; var_s0 < eepmgr->unk21E; var_s0++) { + for (req = eepmgr->unk220, var_s0 = 0; var_s0 < eepmgr->unk21E; req++, var_s0++) { if (func_8007CFB0(eepmgr, var_s0, req)) { return -1; } - req++; } eepmgr->unk224 = 1; } From d1f14069dec42da28735419f64a1501ac674b6af Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 21:40:15 -0800 Subject: [PATCH 07/18] func_8007D0B0 --- Makefile | 2 +- include/eepmgr.h | 4 +++- src/main/eepmgr.c | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1215144..31fc30e 100644 --- a/Makefile +++ b/Makefile @@ -178,7 +178,7 @@ endif SPLAT_FLAGS ?= ifneq ($(FULL_DISASM), 0) - SPLAT_FLAGS += --disassemble-all + SPLAT_FLAGS += --disassemble-all endif #### Files #### diff --git a/include/eepmgr.h b/include/eepmgr.h index df3af9c..d57212e 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -18,13 +18,15 @@ typedef struct EepMgr { /* 0x010 */ OSMesg unk004[1]; /* 0x014 */ OSMesgQueue unk014; /* 0x02C */ OSMesgQueue unk02C; - /* 0x044 */ char unk_044[0x68 - 0x44]; + /* 0x044 */ OSMesgQueue* unk044; + /* 0x048 */ char unk_048[0x68 - 0x48]; /* 0x068 */ OSThread thread; /* 0x218 */ s32 unk218; /* 0x21C */ u8 unk21C; /* 0x21E */ u16 unk21E; /* 0x220 */ EepRequest2* unk220; /* 0x224 */ u8 unk224; + /* 0x225 */ u8 unk225; } EepMgr; // size = 0x228 #endif diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 4ee91cb..dc658c3 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -1,12 +1,15 @@ #include "eepmgr.h" #include "global.h" +#include "sleep.h" s32 D_800A9A20 = 1; u16 D_800A9A24[] = { 0, 0x200 / 8, 0x800 / 8 }; +void func_8007CDA0(EepMgr* eepmgr); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDA0.s") +void func_8007CDCC(EepMgr* eepmgr); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDCC.s") void func_8007CDFC(EepMgr* eepmgr); @@ -20,11 +23,39 @@ void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3) { eepmgr->unk21E = D_800A9A24[eepmgr->unk21C]; } +#define OS_CYCLES_TO_USEC_ALT(c) (((u64)(c) * (1000000LL / 15625LL)) / (osClockRate / 15625LL)) + s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CFB0.s") -s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D0B0.s") +s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { + s32 write; + OSTime before; + OSTime after; + + func_8007CDA0(eepmgr); + + eepmgr->unk225 = 2; + before = osGetTime(); + write = osEepromWrite(eepmgr->unk044, arg1, (u8*)arg2); + after = osGetTime(); + eepmgr->unk225 = 0; + + func_8007CDCC(eepmgr); + + if (D_800A9A20 >= 2) { + (void)OS_CYCLES_TO_USEC_ALT(after - before); + } + + if (write != 0) { + return -1; + } + + if(D_800A9A20) {} + + csleep((15 * osClockRate) / 1000ULL); + return 0; +} #ifdef NON_MATCHING s32 func_8007D1EC(EepMgr* eepmgr, EepRequest2* arg1) { From be3c7582a1cfbbbea239cdc589f01e9fc211c4ec Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 21:43:35 -0800 Subject: [PATCH 08/18] func_8007CFB0 --- src/main/eepmgr.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index dc658c3..0931d20 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -25,11 +25,36 @@ void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3) { #define OS_CYCLES_TO_USEC_ALT(c) (((u64)(c) * (1000000LL / 15625LL)) / (osClockRate / 15625LL)) -s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CFB0.s") +s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { + s32 status; + OSTime before; + OSTime after; + + func_8007CDA0(eepmgr); + + eepmgr->unk225 = 1; + before = osGetTime(); + status = osEepromRead(eepmgr->unk044, arg1, (u8*)arg2); + after = osGetTime(); + eepmgr->unk225 = 0; + + func_8007CDCC(eepmgr); + + if (D_800A9A20 >= 2) { + (void)OS_CYCLES_TO_USEC_ALT(after - before); + } + + if (status != 0) { + return -1; + } + + if (D_800A9A20) {} + + return 0; +} s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { - s32 write; + s32 status; OSTime before; OSTime after; @@ -37,7 +62,7 @@ s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { eepmgr->unk225 = 2; before = osGetTime(); - write = osEepromWrite(eepmgr->unk044, arg1, (u8*)arg2); + status = osEepromWrite(eepmgr->unk044, arg1, (u8*)arg2); after = osGetTime(); eepmgr->unk225 = 0; @@ -47,11 +72,11 @@ s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { (void)OS_CYCLES_TO_USEC_ALT(after - before); } - if (write != 0) { + if (status != 0) { return -1; } - if(D_800A9A20) {} + if (D_800A9A20) {} csleep((15 * osClockRate) / 1000ULL); return 0; From ec4a06b241b0ab3b0f130f4adf44d7e8be0b4523 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 21:55:53 -0800 Subject: [PATCH 09/18] func_8007CDFC --- src/main/eepmgr.c | 48 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 0931d20..c380093 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -3,17 +3,55 @@ #include "global.h" #include "sleep.h" +#define LOOP() \ + while (true) \ + (void)0 + s32 D_800A9A20 = 1; u16 D_800A9A24[] = { 0, 0x200 / 8, 0x800 / 8 }; +#define OS_CYCLES_TO_USEC_ALT(c) (((u64)(c) * (1000000LL / 15625LL)) / (osClockRate / 15625LL)) + void func_8007CDA0(EepMgr* eepmgr); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDA0.s") void func_8007CDCC(EepMgr* eepmgr); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDCC.s") -void func_8007CDFC(EepMgr* eepmgr); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDFC.s") +void func_8007CDFC(EepMgr* eepmgr) { + s32 status; + OSTime before; + OSTime after; + + func_8007CDA0(eepmgr); + + eepmgr->unk225 = 1; + before = osGetTime(); + status = osEepromProbe(eepmgr->unk044); + after = osGetTime(); + eepmgr->unk225 = 0; + + func_8007CDCC(eepmgr); + + if (D_800A9A20 >= 3) { + (void)OS_CYCLES_TO_USEC_ALT(after - before); + } + if (status == 0) { + if (D_800A9A20 != 0) {} + } else if (status == 1) { + if (D_800A9A20 != 0) {} + } else if (status == 2) { + if (D_800A9A20 != 0) {} + } else { + LOOP(); + } + + if (D_800A9A20 != 0) {} + + if (eepmgr->unk21C != status) { + LOOP(); + } +} void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3) { bzero(eepmgr, sizeof(EepMgr)); @@ -23,8 +61,6 @@ void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3) { eepmgr->unk21E = D_800A9A24[eepmgr->unk21C]; } -#define OS_CYCLES_TO_USEC_ALT(c) (((u64)(c) * (1000000LL / 15625LL)) / (osClockRate / 15625LL)) - s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { s32 status; OSTime before; @@ -48,7 +84,7 @@ s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { return -1; } - if (D_800A9A20) {} + if (D_800A9A20 != 0) {} return 0; } @@ -76,7 +112,7 @@ s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { return -1; } - if (D_800A9A20) {} + if (D_800A9A20 != 0) {} csleep((15 * osClockRate) / 1000ULL); return 0; From c46d4f6630944340265085fcf166e20601122398 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 22:00:34 -0800 Subject: [PATCH 10/18] func_8007CDCC --- include/global.h | 4 ++++ src/main/eepmgr.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/global.h b/include/global.h index 258469e..933bec2 100644 --- a/include/global.h +++ b/include/global.h @@ -8,6 +8,7 @@ #include "libc/stdint.h" #include "attributes.h" +#include "eepmgr.h" #include "macros.h" #include "unk.h" #include "ys64math.h" @@ -58,6 +59,9 @@ void func_8006F560(Y65430UnkStruct*, Y65430UnkStruct*); // dma void DmaMgr_RequestSync(void* ram, u32 vrom, u32 size); +// 740F0 +void func_8007451C(s32 arg0, OSMesgQueue* arg1, void*); + // 80C50 void func_800800CC(MtxF* mfA, MtxF* mfB); void func_80080914(MtxF* mf, f32, f32, f32, f32); diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index c380093..9f1ef78 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -15,8 +15,10 @@ u16 D_800A9A24[] = { 0, 0x200 / 8, 0x800 / 8 }; void func_8007CDA0(EepMgr* eepmgr); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDA0.s") -void func_8007CDCC(EepMgr* eepmgr); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDCC.s") +void func_8007CDCC(EepMgr* eepmgr) { + func_8007451C(eepmgr->unk218, eepmgr->unk044, eepmgr); + eepmgr->unk044 = NULL; +} void func_8007CDFC(EepMgr* eepmgr) { s32 status; From 503dc61ad176504e4dd917e6f8dc230d66d1b09b Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 22:02:17 -0800 Subject: [PATCH 11/18] func_8007CDA0 --- include/global.h | 3 ++- src/main/eepmgr.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/global.h b/include/global.h index 933bec2..3c2758e 100644 --- a/include/global.h +++ b/include/global.h @@ -60,7 +60,8 @@ void func_8006F560(Y65430UnkStruct*, Y65430UnkStruct*); void DmaMgr_RequestSync(void* ram, u32 vrom, u32 size); // 740F0 -void func_8007451C(s32 arg0, OSMesgQueue* arg1, void*); +OSMesgQueue* func_800744B0(s32 arg0); +void func_8007451C(s32 arg0, OSMesgQueue* arg1); // 80C50 void func_800800CC(MtxF* mfA, MtxF* mfB); diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 9f1ef78..6224d14 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -12,11 +12,12 @@ u16 D_800A9A24[] = { 0, 0x200 / 8, 0x800 / 8 }; #define OS_CYCLES_TO_USEC_ALT(c) (((u64)(c) * (1000000LL / 15625LL)) / (osClockRate / 15625LL)) -void func_8007CDA0(EepMgr* eepmgr); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007CDA0.s") +void func_8007CDA0(EepMgr* eepmgr) { + eepmgr->unk044 = func_800744B0(eepmgr->unk218); +} void func_8007CDCC(EepMgr* eepmgr) { - func_8007451C(eepmgr->unk218, eepmgr->unk044, eepmgr); + func_8007451C(eepmgr->unk218, eepmgr->unk044); eepmgr->unk044 = NULL; } From 1c911283f260afeacc5d60fa75878649599f7a81 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 22:06:25 -0800 Subject: [PATCH 12/18] func_8007D508 --- include/eepmgr.h | 3 ++- src/main/eepmgr.c | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index d57212e..a9e5489 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -19,7 +19,8 @@ typedef struct EepMgr { /* 0x014 */ OSMesgQueue unk014; /* 0x02C */ OSMesgQueue unk02C; /* 0x044 */ OSMesgQueue* unk044; - /* 0x048 */ char unk_048[0x68 - 0x48]; + /* 0x048 */ s16 unk048; + /* 0x04C */ char unk_04C[0x68 - 0x4C]; /* 0x068 */ OSThread thread; /* 0x218 */ s32 unk218; /* 0x21C */ u8 unk21C; diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 6224d14..df56609 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -209,8 +209,13 @@ void func_8007D488(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3, s32 id, s32 p osStartThread(&eepmgr->thread); } -void func_8007D508(EepMgr* eepmgr); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D508.s") +s32 func_8007D508(EepMgr* eepmgr) { + s32 msg; + + osRecvMesg(&eepmgr->unk02C, (OSMesg*)&msg, OS_MESG_BLOCK); + eepmgr->unk048 = 0; + return msg; +} void func_8007D540(EepMgr* eepmgr, s32 arg1); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D540.s") From ee3f94900a38d063620ee29ee5ae1b380ecb972a Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 22:11:40 -0800 Subject: [PATCH 13/18] func_8007D540 --- include/eepmgr.h | 4 ++-- src/main/eepmgr.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index a9e5489..cc55ca9 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -19,8 +19,8 @@ typedef struct EepMgr { /* 0x014 */ OSMesgQueue unk014; /* 0x02C */ OSMesgQueue unk02C; /* 0x044 */ OSMesgQueue* unk044; - /* 0x048 */ s16 unk048; - /* 0x04C */ char unk_04C[0x68 - 0x4C]; + /* 0x048 */ EepRequest unk048; + /* 0x050 */ char unk_04C[0x68 - 0x50]; /* 0x068 */ OSThread thread; /* 0x218 */ s32 unk218; /* 0x21C */ u8 unk21C; diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index df56609..31d5847 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -213,12 +213,21 @@ s32 func_8007D508(EepMgr* eepmgr) { s32 msg; osRecvMesg(&eepmgr->unk02C, (OSMesg*)&msg, OS_MESG_BLOCK); - eepmgr->unk048 = 0; + eepmgr->unk048.unk0 = 0; return msg; } -void func_8007D540(EepMgr* eepmgr, s32 arg1); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D540.s") +void func_8007D540(EepMgr* eepmgr, void* arg1) { + EepRequest* req = &eepmgr->unk048; + + if (req->unk0 != 0) { + LOOP(); + } + + req->unk0 = 8; + req->unk4 = arg1; + osSendMesg(&eepmgr->unk014, &eepmgr->unk048, OS_MESG_BLOCK); +} void func_8007D590(EepMgr* eepmgr, s32 arg1); #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D590.s") From f83b4b31ff1991a30b9bbc6f4c719cac582dd54e Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 16 Feb 2024 22:13:07 -0800 Subject: [PATCH 14/18] func_8007D590 --- src/main/eepmgr.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 31d5847..ff42fea 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -229,7 +229,16 @@ void func_8007D540(EepMgr* eepmgr, void* arg1) { osSendMesg(&eepmgr->unk014, &eepmgr->unk048, OS_MESG_BLOCK); } -void func_8007D590(EepMgr* eepmgr, s32 arg1); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D590.s") +void func_8007D590(EepMgr* eepmgr, void* arg1) { + EepRequest* req = &eepmgr->unk048; + + if (req->unk0 != 0) { + LOOP(); + } + + req->unk0 = 9; + req->unk4 = arg1; + osSendMesg(&eepmgr->unk014, &eepmgr->unk048, OS_MESG_BLOCK); +} #pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/D_800B2AE0.s") From d80c01200af23f3ff3264dbf6867358ae0f3b033 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sun, 18 Feb 2024 19:49:37 -0800 Subject: [PATCH 15/18] eepmgr_HandleWrite + docs --- include/eepmgr.h | 20 +++--- src/main/eepmgr.c | 168 ++++++++++++++++++++++++---------------------- 2 files changed, 95 insertions(+), 93 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index cc55ca9..4632d4c 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -3,16 +3,12 @@ #include "ultra64.h" + typedef struct EepRequest { - /* 0x0 */ s16 unk0; - /* 0x4 */ void* unk4; + /* 0x0 */ s16 type; + /* 0x4 */ u64* buffer; } EepRequest; -typedef struct EepRequest2 { - /* 0x0 */ s32 unk0; - /* 0x4 */ s32 unk4; -} EepRequest2; - typedef struct EepMgr { /* 0x000 */ OSMesg unk000[4]; /* 0x010 */ OSMesg unk004[1]; @@ -23,11 +19,11 @@ typedef struct EepMgr { /* 0x050 */ char unk_04C[0x68 - 0x50]; /* 0x068 */ OSThread thread; /* 0x218 */ s32 unk218; - /* 0x21C */ u8 unk21C; - /* 0x21E */ u16 unk21E; - /* 0x220 */ EepRequest2* unk220; - /* 0x224 */ u8 unk224; - /* 0x225 */ u8 unk225; + /* 0x21C */ u8 type; + /* 0x21E */ u16 numBlocks; + /* 0x220 */ u64* buffer; + /* 0x224 */ u8 hasData; + /* 0x225 */ u8 operation; } EepMgr; // size = 0x228 #endif diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index ff42fea..b860c69 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -7,9 +7,13 @@ while (true) \ (void)0 -s32 D_800A9A20 = 1; -u16 D_800A9A24[] = { 0, 0x200 / 8, 0x800 / 8 }; +s32 gEepmgrLogSeverity = 1; +static u16 sMaxBlocks[] = { 0, EEPROM_MAXBLOCKS, EEP16K_MAXBLOCKS }; +#define EEP_READ_MSG 8 +#define EEP_WRITE_MSG 9 + +//! TODO: Probably a libultra macro #define OS_CYCLES_TO_USEC_ALT(c) (((u64)(c) * (1000000LL / 15625LL)) / (osClockRate / 15625LL)) void func_8007CDA0(EepMgr* eepmgr) { @@ -21,65 +25,65 @@ void func_8007CDCC(EepMgr* eepmgr) { eepmgr->unk044 = NULL; } -void func_8007CDFC(EepMgr* eepmgr) { - s32 status; +void eepmgr_Probe(EepMgr* eepmgr) { + s32 type; OSTime before; OSTime after; func_8007CDA0(eepmgr); - eepmgr->unk225 = 1; + eepmgr->operation = 1; before = osGetTime(); - status = osEepromProbe(eepmgr->unk044); + type = osEepromProbe(eepmgr->unk044); after = osGetTime(); - eepmgr->unk225 = 0; + eepmgr->operation = 0; func_8007CDCC(eepmgr); - if (D_800A9A20 >= 3) { + if (gEepmgrLogSeverity >= 3) { (void)OS_CYCLES_TO_USEC_ALT(after - before); } - if (status == 0) { - if (D_800A9A20 != 0) {} - } else if (status == 1) { - if (D_800A9A20 != 0) {} - } else if (status == 2) { - if (D_800A9A20 != 0) {} + if (type == 0) { + if (gEepmgrLogSeverity != 0) {} + } else if (type == EEPROM_TYPE_4K) { + if (gEepmgrLogSeverity != 0) {} + } else if (type == EEPROM_TYPE_16K) { + if (gEepmgrLogSeverity != 0) {} } else { LOOP(); } - if (D_800A9A20 != 0) {} + if (gEepmgrLogSeverity != 0) {} - if (eepmgr->unk21C != status) { + if (eepmgr->type != type) { LOOP(); } } -void func_8007CF50(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3) { +void eepmgr_Setup(EepMgr* eepmgr, s32 arg1, s32 type, u64* buffer) { bzero(eepmgr, sizeof(EepMgr)); eepmgr->unk218 = arg1; - eepmgr->unk220 = arg3; - eepmgr->unk21C = arg2; - eepmgr->unk21E = D_800A9A24[eepmgr->unk21C]; + eepmgr->buffer = buffer; + eepmgr->type = type; + eepmgr->numBlocks = sMaxBlocks[eepmgr->type]; } -s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { +s32 eepmgr_Read(EepMgr* eepmgr, u8 arg1, u64* buffer) { s32 status; OSTime before; OSTime after; func_8007CDA0(eepmgr); - eepmgr->unk225 = 1; + eepmgr->operation = 1; before = osGetTime(); - status = osEepromRead(eepmgr->unk044, arg1, (u8*)arg2); + status = osEepromRead(eepmgr->unk044, arg1, (u8*)buffer); after = osGetTime(); - eepmgr->unk225 = 0; + eepmgr->operation = 0; func_8007CDCC(eepmgr); - if (D_800A9A20 >= 2) { + if (gEepmgrLogSeverity >= 2) { (void)OS_CYCLES_TO_USEC_ALT(after - before); } @@ -87,27 +91,27 @@ s32 func_8007CFB0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { return -1; } - if (D_800A9A20 != 0) {} + if (gEepmgrLogSeverity != 0) {} return 0; } -s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { +s32 eepmgr_Write(EepMgr* eepmgr, u8 addr, u64* buffer) { s32 status; OSTime before; OSTime after; func_8007CDA0(eepmgr); - eepmgr->unk225 = 2; + eepmgr->operation = 2; before = osGetTime(); - status = osEepromWrite(eepmgr->unk044, arg1, (u8*)arg2); + status = osEepromWrite(eepmgr->unk044, addr, (u8*)buffer); after = osGetTime(); - eepmgr->unk225 = 0; + eepmgr->operation = 0; func_8007CDCC(eepmgr); - if (D_800A9A20 >= 2) { + if (gEepmgrLogSeverity >= 2) { (void)OS_CYCLES_TO_USEC_ALT(after - before); } @@ -115,97 +119,99 @@ s32 func_8007D0B0(EepMgr* eepmgr, u8 arg1, EepRequest2* arg2) { return -1; } - if (D_800A9A20 != 0) {} + if (gEepmgrLogSeverity != 0) {} + // Sleep 15ms csleep((15 * osClockRate) / 1000ULL); return 0; } -#ifdef NON_MATCHING -s32 func_8007D1EC(EepMgr* eepmgr, EepRequest2* arg1) { - EepRequest2* var_s0; - EepRequest2* var_s1; - s32 var_s2; +s32 eepmgr_HandleWrite(EepMgr* eepmgr, u64* buffer) { + u64* readBuffer; + u64* iter; + s32 i; - if (eepmgr->unk21C == 0) { + if (eepmgr->type == 0) { return -1; } - if (eepmgr->unk224 == 0) { + + if (!eepmgr->hasData) { return -1; } - for (var_s1 = eepmgr->unk220, var_s0 = arg1, var_s2 = 0; var_s2 < eepmgr->unk21E; var_s1++, var_s0++, var_s2++) { - if ((var_s1->unk0 == var_s0->unk0) && (var_s1->unk4 == var_s0->unk4)) { - continue; - } + iter = eepmgr->buffer; + readBuffer = buffer; + for (i = 0; i < eepmgr->numBlocks; i++) { + if (*readBuffer != *iter) { + if (eepmgr_Write(eepmgr, i, readBuffer) != 0) { + return -1; + } - if (func_8007D0B0(eepmgr, var_s2, var_s0)) { - return -1; + *iter = *readBuffer; } - var_s1->unk0 = var_s0->unk0; - var_s1->unk4 = var_s0->unk4; + + iter++; + readBuffer++; } return 0; } -#else -s32 func_8007D1EC(EepMgr* eepmgr, EepRequest2* arg1); -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/func_8007D1EC.s") -#endif -s32 func_8007D2C4(EepMgr* eepmgr, EepRequest2* arg1) { - s32 var_s0; - EepRequest2* req; +s32 eepmgr_HandleRead(EepMgr* eepmgr, u64* arg1) { + u64* iter; + s32 i; - if (eepmgr->unk21C == 0) { + if (eepmgr->type == 0) { return -1; } - if (eepmgr->unk224 == 0) { - for (req = eepmgr->unk220, var_s0 = 0; var_s0 < eepmgr->unk21E; req++, var_s0++) { - if (func_8007CFB0(eepmgr, var_s0, req)) { + if (!eepmgr->hasData) { + iter = eepmgr->buffer; + for (i = 0; i < eepmgr->numBlocks; i++) { + if (eepmgr_Read(eepmgr, i, iter) != 0) { return -1; } + iter++; } - eepmgr->unk224 = 1; + eepmgr->hasData = true; } - bcopy(eepmgr->unk220, arg1, eepmgr->unk21E * 8); + bcopy(eepmgr->buffer, arg1, eepmgr->numBlocks * EEPROM_BLOCK_SIZE); return 0; } -void func_8007D380(void* arg) { +void eepmgr_ThreadEntry(void* arg) { EepRequest* req = NULL; EepMgr* eepmgr = (EepMgr*)arg; void* tmp; - func_8007CDFC(eepmgr); + eepmgr_Probe(eepmgr); do { osRecvMesg(&eepmgr->unk014, (OSMesg*)&req, OS_MESG_BLOCK); - switch (req->unk0) { - case 8: + switch (req->type) { + case EEP_READ_MSG: if (1) {} - osSendMesg(&eepmgr->unk02C, (OSMesg)func_8007D2C4(eepmgr, req->unk4), OS_MESG_BLOCK); + osSendMesg(&eepmgr->unk02C, (OSMesg)eepmgr_HandleRead(eepmgr, req->buffer), OS_MESG_BLOCK); break; - case 9: + case EEP_WRITE_MSG: if (1) {} - osSendMesg(&eepmgr->unk02C, (OSMesg)func_8007D1EC(eepmgr, req->unk4), OS_MESG_BLOCK); + osSendMesg(&eepmgr->unk02C, (OSMesg)eepmgr_HandleWrite(eepmgr, req->buffer), OS_MESG_BLOCK); break; //! FAKE: - tmp = req->unk4; + tmp = req->buffer; default: if (tmp != NULL) {} } - } while (req->unk0 != 4); + } while (req->type != 4); } -void func_8007D488(EepMgr* eepmgr, s32 arg1, s32 arg2, void* arg3, s32 id, s32 priority, void* stack) { - func_8007CF50(eepmgr, arg1, arg2, arg3); +void eepmgr_Create(EepMgr* eepmgr, s32 arg1, s32 type, u64* buffer, s32 id, s32 priority, void* stack) { + eepmgr_Setup(eepmgr, arg1, type, buffer); osCreateMesgQueue(&eepmgr->unk014, eepmgr->unk000, ARRAY_COUNT(eepmgr->unk000)); osCreateMesgQueue(&eepmgr->unk02C, eepmgr->unk004, ARRAY_COUNT(eepmgr->unk004)); - osCreateThread(&eepmgr->thread, id, func_8007D380, eepmgr, stack, priority); + osCreateThread(&eepmgr->thread, id, eepmgr_ThreadEntry, eepmgr, stack, priority); osStartThread(&eepmgr->thread); } @@ -213,31 +219,31 @@ s32 func_8007D508(EepMgr* eepmgr) { s32 msg; osRecvMesg(&eepmgr->unk02C, (OSMesg*)&msg, OS_MESG_BLOCK); - eepmgr->unk048.unk0 = 0; + eepmgr->unk048.type = 0; return msg; } -void func_8007D540(EepMgr* eepmgr, void* arg1) { +void eepmgr_SendRead(EepMgr* eepmgr, void* buffer) { EepRequest* req = &eepmgr->unk048; - if (req->unk0 != 0) { + if (req->type != 0) { LOOP(); } - req->unk0 = 8; - req->unk4 = arg1; + req->type = EEP_READ_MSG; + req->buffer = buffer; osSendMesg(&eepmgr->unk014, &eepmgr->unk048, OS_MESG_BLOCK); } -void func_8007D590(EepMgr* eepmgr, void* arg1) { +void eepmgr_SendWrite(EepMgr* eepmgr, void* buffer) { EepRequest* req = &eepmgr->unk048; - if (req->unk0 != 0) { + if (req->type != 0) { LOOP(); } - req->unk0 = 9; - req->unk4 = arg1; + req->type = EEP_WRITE_MSG; + req->buffer = buffer; osSendMesg(&eepmgr->unk014, &eepmgr->unk048, OS_MESG_BLOCK); } From 9bd903fc37a6800f4c0f15ae3b6e074f0cae5c9a Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sun, 18 Feb 2024 20:15:58 -0800 Subject: [PATCH 16/18] strings --- include/eepmgr.h | 2 +- linker_scripts/us/symbol_addrs.txt | 4 ++ src/main/eepmgr.c | 81 +++++++++++++++++++++++------- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index 4632d4c..da0b8a1 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -22,7 +22,7 @@ typedef struct EepMgr { /* 0x21C */ u8 type; /* 0x21E */ u16 numBlocks; /* 0x220 */ u64* buffer; - /* 0x224 */ u8 hasData; + /* 0x224 */ u8 cached; /* 0x225 */ u8 operation; } EepMgr; // size = 0x228 diff --git a/linker_scripts/us/symbol_addrs.txt b/linker_scripts/us/symbol_addrs.txt index 2435010..7a94aba 100644 --- a/linker_scripts/us/symbol_addrs.txt +++ b/linker_scripts/us/symbol_addrs.txt @@ -6,6 +6,10 @@ Fault_SetFramebuffer = 0x80071250; // type:func Fault_Init = 0x8007127C; // type:func Fault_HungUp = 0x80071380; // type:func +eepmgr_Create = 0x8007D488; // type:func +eepmgr_SendRead = 0x8007D540; // type:func +eepmgr_SendWrite = 0x8007D590; // type:func + DmaMgr_RequestSync = 0x8007DF0C; // type:func DmaMgr_Init = 0x8007DF74; // type:func diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index b860c69..64dae40 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -13,7 +13,7 @@ static u16 sMaxBlocks[] = { 0, EEPROM_MAXBLOCKS, EEP16K_MAXBLOCKS }; #define EEP_READ_MSG 8 #define EEP_WRITE_MSG 9 -//! TODO: Probably a libultra macro +//! TODO: Probably a libultra macro #define OS_CYCLES_TO_USEC_ALT(c) (((u64)(c) * (1000000LL / 15625LL)) / (osClockRate / 15625LL)) void func_8007CDA0(EepMgr* eepmgr) { @@ -41,14 +41,25 @@ void eepmgr_Probe(EepMgr* eepmgr) { func_8007CDCC(eepmgr); if (gEepmgrLogSeverity >= 3) { + // osEepromProbe execution time=%d us + (void)"osEepromProbe 実行時間=%d us\n"; (void)OS_CYCLES_TO_USEC_ALT(after - before); } if (type == 0) { - if (gEepmgrLogSeverity != 0) {} + if (gEepmgrLogSeverity != 0) { + // No EEPROM + (void)"EEPROM が ありません\n"; + } } else if (type == EEPROM_TYPE_4K) { - if (gEepmgrLogSeverity != 0) {} + if (gEepmgrLogSeverity != 0) { + // 4K bit EEPROM detected + (void)"4KビットEEPROMを検出\n"; + } } else if (type == EEPROM_TYPE_16K) { - if (gEepmgrLogSeverity != 0) {} + if (gEepmgrLogSeverity != 0) { + // 16K bit EEPROM detected + (void)"16KビットEEPROMを検出\n"; + } } else { LOOP(); } @@ -84,14 +95,20 @@ s32 eepmgr_Read(EepMgr* eepmgr, u8 arg1, u64* buffer) { func_8007CDCC(eepmgr); if (gEepmgrLogSeverity >= 2) { + // osEepromRead execution time=%d us + (void)"osEepromRead 実行時間=%d us\n"; (void)OS_CYCLES_TO_USEC_ALT(after - before); } if (status != 0) { + // EEPROM interface circuit unresponsive (READ) + (void)"EEPROM インターフェース回路反応なし (READ)\n"; return -1; } - if (gEepmgrLogSeverity != 0) {} + if (gEepmgrLogSeverity != 0) { + (void)"EEPROM READ %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n"; + } return 0; } @@ -112,14 +129,20 @@ s32 eepmgr_Write(EepMgr* eepmgr, u8 addr, u64* buffer) { func_8007CDCC(eepmgr); if (gEepmgrLogSeverity >= 2) { + // osEepromWrite execution time=%d us + (void)"osEepromWrite 実行時間=%d us\n"; (void)OS_CYCLES_TO_USEC_ALT(after - before); } if (status != 0) { + // EEPROM interface circuit unresponsive (WRITE) + (void)"EEPROM インターフェース回路反応なし (WRITE)\n"; return -1; } - if (gEepmgrLogSeverity != 0) {} + if (gEepmgrLogSeverity != 0) { + (void)"EEPROM WRITE %02X: %02X %02X %02X %02X %02X %02X %02X %02X\n"; + } // Sleep 15ms csleep((15 * osClockRate) / 1000ULL); @@ -132,10 +155,16 @@ s32 eepmgr_HandleWrite(EepMgr* eepmgr, u64* buffer) { s32 i; if (eepmgr->type == 0) { + // No EEPROM + (void)"EEPROM が ありません\n"; return -1; } - if (!eepmgr->hasData) { + if (!eepmgr->cached) { + // EEPROM not cached + (void)"EEPROM が キャッシュされていません\n"; + // Please read it once and then write it. + (void)"一度読み込んでから、書くようにしてください\n"; return -1; } @@ -162,10 +191,12 @@ s32 eepmgr_HandleRead(EepMgr* eepmgr, u64* arg1) { s32 i; if (eepmgr->type == 0) { + // No EEPROM + (void)"EEPROM が ありません\n"; return -1; } - if (!eepmgr->hasData) { + if (!eepmgr->cached) { iter = eepmgr->buffer; for (i = 0; i < eepmgr->numBlocks; i++) { if (eepmgr_Read(eepmgr, i, iter) != 0) { @@ -173,7 +204,7 @@ s32 eepmgr_HandleRead(EepMgr* eepmgr, u64* arg1) { } iter++; } - eepmgr->hasData = true; + eepmgr->cached = true; } bcopy(eepmgr->buffer, arg1, eepmgr->numBlocks * EEPROM_BLOCK_SIZE); @@ -183,31 +214,49 @@ s32 eepmgr_HandleRead(EepMgr* eepmgr, u64* arg1) { void eepmgr_ThreadEntry(void* arg) { EepRequest* req = NULL; EepMgr* eepmgr = (EepMgr*)arg; - void* tmp; + if (gEepmgrLogSeverity != 0) { + // EEPROM manager thread execution starts + (void)"EEPROMマネージャスレッド実行開始\n"; + } eepmgr_Probe(eepmgr); do { + if (gEepmgrLogSeverity != 0) { + // eepmgr: Waiting for command message + (void)"eepmgr:コマンドメッセージ待ち\n"; + } + osRecvMesg(&eepmgr->unk014, (OSMesg*)&req, OS_MESG_BLOCK); switch (req->type) { case EEP_READ_MSG: - if (1) {} + if (gEepmgrLogSeverity != 0) { + // eepmgr: Load command received + (void)"eepmgr:ロードコマンド受信\n"; + } osSendMesg(&eepmgr->unk02C, (OSMesg)eepmgr_HandleRead(eepmgr, req->buffer), OS_MESG_BLOCK); break; case EEP_WRITE_MSG: - if (1) {} + if (gEepmgrLogSeverity != 0) { + // eepmgr:Receive save command + (void)"eepmgr:セーブコマンド受信\n"; + } osSendMesg(&eepmgr->unk02C, (OSMesg)eepmgr_HandleWrite(eepmgr, req->buffer), OS_MESG_BLOCK); break; - //! FAKE: - tmp = req->buffer; default: - if (tmp != NULL) {} + break; } } while (req->type != 4); + + if (gEepmgrLogSeverity != 0) { + // EEPROM manager thread execution ends + (void)"EEPROMマネージャスレッド実行終了\n"; + } } void eepmgr_Create(EepMgr* eepmgr, s32 arg1, s32 type, u64* buffer, s32 id, s32 priority, void* stack) { + (void)"eepmgr_Create(%08x, %08x, %d, %08x, %d, %d, %08x)\n"; eepmgr_Setup(eepmgr, arg1, type, buffer); osCreateMesgQueue(&eepmgr->unk014, eepmgr->unk000, ARRAY_COUNT(eepmgr->unk000)); osCreateMesgQueue(&eepmgr->unk02C, eepmgr->unk004, ARRAY_COUNT(eepmgr->unk004)); @@ -246,5 +295,3 @@ void eepmgr_SendWrite(EepMgr* eepmgr, void* buffer) { req->buffer = buffer; osSendMesg(&eepmgr->unk014, &eepmgr->unk048, OS_MESG_BLOCK); } - -#pragma GLOBAL_ASM("asm/us/nonmatchings/main/eepmgr/D_800B2AE0.s") From e7d9d5f287346c9e496433b194409ea6eed14a69 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Mon, 19 Feb 2024 09:24:15 -0800 Subject: [PATCH 17/18] cache --- include/eepmgr.h | 2 +- src/main/eepmgr.c | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/eepmgr.h b/include/eepmgr.h index da0b8a1..af4528f 100644 --- a/include/eepmgr.h +++ b/include/eepmgr.h @@ -21,7 +21,7 @@ typedef struct EepMgr { /* 0x218 */ s32 unk218; /* 0x21C */ u8 type; /* 0x21E */ u16 numBlocks; - /* 0x220 */ u64* buffer; + /* 0x220 */ u64* cache; /* 0x224 */ u8 cached; /* 0x225 */ u8 operation; } EepMgr; // size = 0x228 diff --git a/src/main/eepmgr.c b/src/main/eepmgr.c index 64dae40..ba5eb58 100644 --- a/src/main/eepmgr.c +++ b/src/main/eepmgr.c @@ -74,7 +74,7 @@ void eepmgr_Probe(EepMgr* eepmgr) { void eepmgr_Setup(EepMgr* eepmgr, s32 arg1, s32 type, u64* buffer) { bzero(eepmgr, sizeof(EepMgr)); eepmgr->unk218 = arg1; - eepmgr->buffer = buffer; + eepmgr->cache = buffer; eepmgr->type = type; eepmgr->numBlocks = sMaxBlocks[eepmgr->type]; } @@ -150,8 +150,8 @@ s32 eepmgr_Write(EepMgr* eepmgr, u8 addr, u64* buffer) { } s32 eepmgr_HandleWrite(EepMgr* eepmgr, u64* buffer) { - u64* readBuffer; - u64* iter; + u64* bufferIter; + u64* cacheIter; s32 i; if (eepmgr->type == 0) { @@ -168,26 +168,26 @@ s32 eepmgr_HandleWrite(EepMgr* eepmgr, u64* buffer) { return -1; } - iter = eepmgr->buffer; - readBuffer = buffer; + cacheIter = eepmgr->cache; + bufferIter = buffer; for (i = 0; i < eepmgr->numBlocks; i++) { - if (*readBuffer != *iter) { - if (eepmgr_Write(eepmgr, i, readBuffer) != 0) { + if (*bufferIter != *cacheIter) { + if (eepmgr_Write(eepmgr, i, bufferIter) != 0) { return -1; } - *iter = *readBuffer; + *cacheIter = *bufferIter; } - iter++; - readBuffer++; + cacheIter++; + bufferIter++; } return 0; } s32 eepmgr_HandleRead(EepMgr* eepmgr, u64* arg1) { - u64* iter; + u64* cacheIter; s32 i; if (eepmgr->type == 0) { @@ -197,17 +197,17 @@ s32 eepmgr_HandleRead(EepMgr* eepmgr, u64* arg1) { } if (!eepmgr->cached) { - iter = eepmgr->buffer; + cacheIter = eepmgr->cache; for (i = 0; i < eepmgr->numBlocks; i++) { - if (eepmgr_Read(eepmgr, i, iter) != 0) { + if (eepmgr_Read(eepmgr, i, cacheIter) != 0) { return -1; } - iter++; + cacheIter++; } eepmgr->cached = true; } - bcopy(eepmgr->buffer, arg1, eepmgr->numBlocks * EEPROM_BLOCK_SIZE); + bcopy(eepmgr->cache, arg1, eepmgr->numBlocks * EEPROM_BLOCK_SIZE); return 0; } @@ -238,7 +238,7 @@ void eepmgr_ThreadEntry(void* arg) { case EEP_WRITE_MSG: if (gEepmgrLogSeverity != 0) { - // eepmgr:Receive save command + // eepmgr: Receive save command (void)"eepmgr:セーブコマンド受信\n"; } osSendMesg(&eepmgr->unk02C, (OSMesg)eepmgr_HandleWrite(eepmgr, req->buffer), OS_MESG_BLOCK); From b1d7d62c1dda079a5dd31edf52847fbc84e49841 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Mon, 19 Feb 2024 10:39:55 -0800 Subject: [PATCH 18/18] Global already had a 740F0 section --- include/global.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/global.h b/include/global.h index 3c2758e..0a85fec 100644 --- a/include/global.h +++ b/include/global.h @@ -45,6 +45,8 @@ typedef struct Y511F0UnkStruct { extern Y511F0UnkStruct D_800DA840[]; // 740F0 +OSMesgQueue* func_800744B0(s32 arg0); +void func_8007451C(s32 arg0, OSMesgQueue* arg1); void func_80074C88(UNK_PTR, struct Input*, s32); // malloc @@ -59,10 +61,6 @@ void func_8006F560(Y65430UnkStruct*, Y65430UnkStruct*); // dma void DmaMgr_RequestSync(void* ram, u32 vrom, u32 size); -// 740F0 -OSMesgQueue* func_800744B0(s32 arg0); -void func_8007451C(s32 arg0, OSMesgQueue* arg1); - // 80C50 void func_800800CC(MtxF* mfA, MtxF* mfB); void func_80080914(MtxF* mf, f32, f32, f32, f32);