Matches, near-matches, and fixed warnings in code_800B45E0 (#498)

This commit is contained in:
Matthew
2023-11-25 19:01:58 -05:00
committed by GitHub
parent 8b2bca8268
commit f4658efbba
5 changed files with 115 additions and 494 deletions
+108 -228
View File
@@ -45,7 +45,7 @@ void write_save_data_grand_prix_points_and_sound_mode(void) {
Stuff *main = &gSaveData.main;
main->checksum[1] = compute_save_data_checksum_1();
main->checksum[2] = compute_save_data_checksum_2();
osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(main), main, sizeof(Stuff));
osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(main), (u8 *) main, sizeof(Stuff));
}
void func_800B46D0(void) {
@@ -120,7 +120,7 @@ u8 checksum_time_trial_records(s32 courseIdx) {
u8 compute_save_data_checksum_1(void) {
u8 *grandPrixPoints = &gSaveData.main.grandPrixPoints;
u8 *grandPrixPoints = (u8 *) &gSaveData.main.grandPrixPoints;
s32 i;
s32 crc = 0;
@@ -218,7 +218,7 @@ void validate_save_data(void) {
main->soundMode = backup->soundMode;
main->checksum[1] = compute_save_data_checksum_backup_1();
main->checksum[2] = compute_save_data_checksum_backup_2();
osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(main), main, sizeof(Stuff));
osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(main), (u8 *) main, sizeof(Stuff));
}
update_save_data_backup();
return;
@@ -294,7 +294,7 @@ s32 func_800B4FB0(s32 courseIndex) {
}
s32 func_800B5020(u32 time, s32 charId) {
s32 stackPadding[3];
UNUSED s32 stackPadding[3];
s32 course; // sp30
s32 i;
s32 j;
@@ -333,58 +333,41 @@ s32 func_800B5020(u32 time, s32 charId) {
return i;
}
#ifdef MIPS_TO_C
//generated by m2c commit eefca95b040d7ee0c617bc58f9ac6cd1cf7bce87 on Aug-23-2023
extern ? D_8018CA74;
#ifdef NON_MATCHING
s32 func_800B5218(void) {
s32 sp38;
s32 sp28;
s32 sp24;
u8 *sp20;
struct_8018CA70_entry *sp18;
? *var_a1;
s32 temp_v1;
s32 var_a3;
s32 var_v0;
s32 var_v0_2;
struct_8018CA70_entry *var_a2;
u32 temp_a0;
u32 temp_a1;
u8 *temp_v0;
sp38 = (gCupSelection * 4) + gCupCourseSelection;
var_a3 = 1;
var_a2 = D_8018CA70;
var_a1 = &D_8018CA74;
var_v0_2 = 1;
sp28 = (s32) *gCharacterSelections;
do {
temp_v1 = var_a1->unk20;
temp_a0 = var_a2->lapDurations[0];
if (temp_v1 < (s32) temp_a0) {
var_a3 = 1 << var_v0_2;
var_a2 = (var_v0_2 * 4) + D_8018CA70;
} else if (temp_a0 == temp_v1) {
var_a3 |= 1 << var_v0_2;
u8 *recordPointer;
s32 prevLapTime;
s32 fastestLapIndex;
s32 recordIndex;
UNUSED s32 padding;
s32 thisLapTime;
s32 checkLapIndex;
s32 character;
s32 lapBitmask;
recordIndex = (gCupSelection * 4) + gCupCourseSelection;
recordPointer = &gSaveData.allCourseTimeTrialRecords.cupRecords[recordIndex / 4].courseRecords[recordIndex % 4].records[0][0];
lapBitmask = 1;
fastestLapIndex = 0;
character = *gCharacterSelections;
for (checkLapIndex = 1; checkLapIndex != 3; checkLapIndex++) {
prevLapTime = D_8018CA70->lapDurations[checkLapIndex];
thisLapTime = D_8018CA70->lapDurations[fastestLapIndex];
if (prevLapTime < thisLapTime) {
lapBitmask = 1 << checkLapIndex;
fastestLapIndex = checkLapIndex;
} else if (thisLapTime == prevLapTime) {
lapBitmask |= 1 << checkLapIndex;
}
var_v0_2 += 1;
var_a1 += 4;
} while (var_v0_2 != 3);
sp18 = var_a2;
sp24 = var_a3;
temp_a1 = var_a2->lapDurations[0];
var_v0 = 0;
if (temp_a1 < (u32) (func_800B4F2C((s32) temp_a0, var_a1, var_a2, var_a3) & 0xFFFFF)) {
temp_v0 = &gSaveData.allCourseTimeTrialRecords.cupRecords[0].courseRecords[0].records[0][((sp38 / 4) * 0x60) + ((sp38 % 4) * 0x18)];
sp20 = temp_v0;
sp24 = var_a3;
populate_time_trial_record(temp_v0 + 0xF, temp_a1, sp28);
temp_v0->unk12 = 1;
func_800B45E0(sp38);
var_v0 = sp24;
}
return var_v0;
if (D_8018CA70->lapDurations[fastestLapIndex] < (func_800B4F2C() & 0xFFFFF)) {
populate_time_trial_record(recordPointer + 0xF, D_8018CA70->lapDurations[fastestLapIndex], character);
recordPointer[0x12] = 1;
func_800B45E0(recordIndex);
return lapBitmask;
} else {
return 0;
}
}
#else
GLOBAL_ASM("asm/non_matchings/code_800B45E0/func_800B5218.s")
@@ -477,102 +460,49 @@ s32 func_800B557C(void) {
return func_800B5530(CC_EXTRA);
}
#ifdef MIPS_TO_C
//generated by m2c commit eefca95b040d7ee0c617bc58f9ac6cd1cf7bce87 on Aug-23-2023
void func_800B559C(s32 course) {
CourseTimeTrialRecords *temp_a2;
OnlyBestTimeTrialRecords *temp_s2;
OnlyBestTimeTrialRecords *temp_s2_2;
s32 temp_s6;
s32 var_s1;
s32 var_v0;
s32 var_v0_2;
u8 *temp_a0;
u8 *var_a0;
u8 temp_t3;
u8 temp_t9;
void *temp_v1;
void *temp_v1_2;
temp_s6 = course / 8;
var_s1 = temp_s6 * 8;
if (var_s1 < (var_s1 + 8)) {
temp_s2 = &gSaveData.onlyBestTimeTrialRecords[temp_s6];
do {
var_a0 = D_800F2E60;
temp_a2 = &gSaveData.allCourseTimeTrialRecords.cupRecords[var_s1 / 4].courseRecords[var_s1 % 4];
var_v0 = 0;
if (temp_a2->checksum != checksum_time_trial_records(var_s1)) {
do {
temp_v1 = temp_s2 + ((var_s1 % 8) * 3) + var_v0;
var_v0 += 1;
temp_v1->unk0 = (u8) *var_a0;
temp_t9 = *var_a0;
var_a0 += 1;
temp_v1->unk18 = temp_t9;
} while (var_v0 != 3);
} else {
var_v0_2 = 0;
do {
temp_a0 = &temp_a2->records[0][var_v0_2];
temp_t3 = temp_a0->unk0;
temp_v1_2 = temp_s2 + ((var_s1 % 8) * 3) + var_v0_2;
var_v0_2 += 1;
temp_v1_2->unk0 = temp_t3;
temp_v1_2->unk18 = (u8) temp_a0->unkF;
} while (var_v0_2 != 3);
void func_800B559C(s32 arg0) {
CourseTimeTrialRecords *courseRecord;
OnlyBestTimeTrialRecords *bestRecord;
s32 x = arg0 / 8;
s32 i;
s32 j;
for (i = x * 8; i < ((x * 8) + 8); i++) {
bestRecord = &gSaveData.onlyBestTimeTrialRecords[x];
courseRecord = &gSaveData.allCourseTimeTrialRecords.cupRecords[i / 4].courseRecords[i % 4];
if (courseRecord->checksum != checksum_time_trial_records(i)) {
for (j = 0; j < 3; j++) {
bestRecord->bestThreelaps[i % 8][j] = D_800F2E60[j];
bestRecord->bestSinglelaps[i % 8][j] = D_800F2E60[j];
}
var_s1 += 1;
} while (var_s1 < ((temp_s6 * 8) + 8));
} else {
for (j = 0; j < 3; j++) {
bestRecord->bestThreelaps[i % 8][j] = courseRecord->records[0][j];
bestRecord->bestSinglelaps[i % 8][j] = courseRecord->records[0][j + 0x0f];
}
}
}
temp_s2_2 = &gSaveData.onlyBestTimeTrialRecords[temp_s6];
temp_s2_2->unknownBytes[6] = func_800B578C(temp_s6);
temp_s2_2->unknownBytes[7] = func_800B5888(temp_s6);
osEepromLongWrite(&gSIEventMesgQueue, ((u32) (temp_s2_2 - &gSaveData) >> 3) & 0xFF, temp_s2_2->bestThreelaps[0], 0x00000038);
bestRecord = &gSaveData.onlyBestTimeTrialRecords[x];
bestRecord->unknownBytes[6] = func_800B578C(x);
bestRecord->unknownBytes[7] = func_800B5888(x);
osEepromLongWrite(&gSIEventMesgQueue, ((u32) (((u8 *) bestRecord) - ((u8 *) (&gSaveData)))) >> 3, bestRecord->bestThreelaps[0], 0x38);
}
#else
GLOBAL_ASM("asm/non_matchings/code_800B45E0/func_800B559C.s")
#endif
#ifdef MIPS_TO_C
//generated by m2c commit eefca95b040d7ee0c617bc58f9ac6cd1cf7bce87 on Aug-23-2023
#ifdef NON_MATCHING
s32 func_800B578C(s32 arg0) {
OnlyBestTimeTrialRecords *var_a2;
OnlyBestTimeTrialRecords *var_t0;
s32 temp_a1;
s32 temp_lo;
s32 temp_v1;
u8 *var_a2;
s32 var_a0;
s32 var_v0;
s32 var_v1;
u8 *var_a3;
u8 temp_t5;
u8 temp_t9;
var_a2 = &gSaveData.onlyBestTimeTrialRecords[arg0];
var_a2 = &gSaveData.onlyBestTimeTrialRecords[arg0].bestThreelaps[0][0];
var_v1 = 0;
var_t0 = var_a2;
var_v0 = 0;
do {
temp_a1 = var_v0 + 1;
var_a3 = &var_a2->bestThreelaps[0][1];
temp_lo = (var_t0->bestThreelaps[0][0] + 1) * temp_a1;
var_a2 += 0x11;
var_v0 = temp_a1;
var_a0 = 1;
var_v1 += temp_lo;
loop_2:
temp_t5 = var_a3->unk0;
temp_t9 = var_a3->unk1;
var_a3 += 4;
temp_v1 = var_v1 + ((temp_t5 + 1) * temp_a1) + var_a0 + ((temp_t9 + 1) * temp_a1) + var_a0 + 1 + ((var_a3->unk-2 + 1) * temp_a1) + var_a0 + 2 + ((var_a3->unk-1 + 1) * temp_a1) + var_a0;
var_a0 += 4;
var_v1 = temp_v1 + 3;
if (var_a0 != 0x11) {
goto loop_2;
for (var_v0 = 0; var_v0 < 3;) {
++var_v0;
for (var_a0 = 0; var_a0 != 0x11; var_a0++) {
if (var_a0) { }
var_v1 += (((*var_a2++) + 1) * var_v0) + var_a0;
}
var_t0 += 0x11;
} while (temp_a1 != 3);
var_a2 += 0x11;
}
return (var_v1 % 256) & 0xFF;
}
#else
@@ -610,7 +540,7 @@ void update_save_data_backup(void) {
backup->soundMode = main->soundMode;
backup->checksum[1] = compute_save_data_checksum_backup_1();
backup->checksum[2] = compute_save_data_checksum_backup_2();
osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(backup), backup, sizeof(Stuff));
osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(backup), (u8 *) backup, sizeof(Stuff));
}
u8 compute_save_data_checksum_backup_1(void) {
@@ -662,7 +592,7 @@ s32 check_for_controller_pak(s32 controller) {
// gives status info about controller pak insterted in controller 1
s32 controller_pak_1_status(void) {
if (gControllerPak1State) {
switch (osPfsFindFile(&gControllerPak1FileHandle, gCompanyCode, gGameCode, gGameName, gExtCode, &gControllerPak1FileNote)) {
switch (osPfsFindFile(&gControllerPak1FileHandle, gCompanyCode, gGameCode, (u8 *) gGameName, (u8 *) gExtCode, &gControllerPak1FileNote)) {
case PFS_NO_ERROR:
return PFS_NO_ERROR;
case PFS_ERR_INVALID:
@@ -697,7 +627,7 @@ s32 controller_pak_1_status(void) {
}
gControllerPak1State = OK;
if (osPfsFindFile(&gControllerPak1FileHandle, gCompanyCode, gGameCode, gGameName, gExtCode, &gControllerPak1FileNote) == PFS_NO_ERROR) {
if (osPfsFindFile(&gControllerPak1FileHandle, gCompanyCode, gGameCode, (u8 *) gGameName, (u8 *) gExtCode, &gControllerPak1FileNote) == PFS_NO_ERROR) {
return PFS_NO_ERROR;
}
if (osPfsNumFiles(&gControllerPak1FileHandle, &gControllerPak1NumFilesUsed, &gControllerPak1MaxWriteableFiles) != PFS_NO_ERROR) {
@@ -723,7 +653,7 @@ s32 controller_pak_2_status(void) {
s32 stateBorrow = sControllerPak2State;
if (stateBorrow) {
switch (osPfsFindFile(&gControllerPak2FileHandle, gCompanyCode, gGameCode, gGameName, gExtCode, &gControllerPak2FileNote)) {
switch (osPfsFindFile(&gControllerPak2FileHandle, gCompanyCode, gGameCode, (u8 *) gGameName, (u8 *) gExtCode, &gControllerPak2FileNote)) {
case PFS_NO_ERROR:
return PFS_NO_ERROR;
case PFS_ERR_INVALID:
@@ -756,7 +686,7 @@ s32 controller_pak_2_status(void) {
sControllerPak2State = OK;
switch (osPfsFindFile(&gControllerPak2FileHandle, gCompanyCode, gGameCode, gGameName, gExtCode, &gControllerPak2FileNote)) {
switch (osPfsFindFile(&gControllerPak2FileHandle, gCompanyCode, gGameCode, (u8 *) gGameName, (u8 *) gExtCode, &gControllerPak2FileNote)) {
case PFS_NO_ERROR:
return PFS_NO_ERROR;
case PFS_ERR_INVALID:
@@ -818,24 +748,16 @@ s32 func_800B6088(s32 arg0) {
}
#ifdef NON_MATCHING
struct struct_D_800DC714
{
u8 filler[0x100];
};
u8 func_800B60E8(s32 arg0)
{
u8 *addr = *(s32 *)&D_800DC714 + (arg0 << 8);
s32 checksum = 0, i;
for (i = 0; i < sizeof(struct struct_D_800DC714); i++)
{
checksum = i + ((arg0 + 1) * *addr++) + checksum;
u8 func_800B60E8(s32 page) {
s32 multiplier = page + 1;
s32 checksum = 0;
u8 *addr = &((u8 *) D_800DC714)[page << 8];
s32 i;
for (i = 0; i < 0x100; i++) {
checksum = (*addr++ * multiplier + i) + checksum;
}
return checksum;
return checksum;
}
#else
GLOBAL_ASM("asm/non_matchings/code_800B45E0/func_800B60E8.s")
#endif
@@ -979,15 +901,11 @@ s32 func_800B64EC(s32 arg0) {
return temp_v0;
}
#ifdef NON_MATCHING
// Matching decomp courstesy of Vetri, leaving it as this becasue I'm lazy
// https://decomp.me/scratch/qrC3l
s32 func_800B65F4(s32 arg0, s32 arg1) {
s32 stackPadding;
s32 var_s0;
s32 temp_v0;
UNUSED s32 stackPadding;
s32 i;
s32 writeStatus;
struct_8018EE10_entry *temp_s3;
switch (arg0) {
case 0:
case 1:
@@ -995,11 +913,11 @@ s32 func_800B65F4(s32 arg0, s32 arg1) {
default:
return -1;
}
temp_v0 = osPfsReadWriteFile(&gControllerPak2FileHandle, gControllerPak2FileNote, 0U, (arg0 * 0x3C00) + 0x100, 0x00003C00, (u8 *) D_800DC714);
if (temp_v0 == 0) {
temp_s3 = &D_8018D9C0[arg0];
for (var_s0 = 0; var_s0 < 0x3C; var_s0++) {
if (temp_s3->unk_07[var_s0] != func_800B60E8(var_s0)) {
writeStatus = osPfsReadWriteFile(&gControllerPak2FileHandle, gControllerPak2FileNote, 0U, (arg0 * 0x3C00) + 0x100, 0x00003C00, (u8 *) D_800DC714);
if (writeStatus == 0) {
temp_s3 = &D_8018D9C0->arr[arg0];
for (i = 0; i < 0x3C; i++) {
if (temp_s3->unk_07[i] != func_800B60E8(i)) {
temp_s3->ghostDataSaved = 0;
return -2;
}
@@ -1008,11 +926,8 @@ s32 func_800B65F4(s32 arg0, s32 arg1) {
D_80162DFC = temp_s3->unk_00;
D_8018EE10[arg1].courseIndex = temp_s3->courseIndex;
}
return temp_v0;
return writeStatus;
}
#else
GLOBAL_ASM("asm/non_matchings/code_800B45E0/func_800B65F4.s")
#endif
void func_800B6708(void) {
s32 temp_s0;
@@ -1044,62 +959,27 @@ void func_800B6798(void) {
}
}
#ifdef MIPS_TO_C
//generated by m2c commit 08138748803d75e73e4a94bb0c619a273754ee9c on Oct-08-2023
u8 func_800B6828(s32 arg0) {
s32 temp_a2;
s32 temp_lo;
s32 temp_v1;
s32 var_a1;
s32 var_v1;
struct_8018EE10_entry *temp_v0;
u8 temp_t1;
u8 temp_t4;
u8 temp_t7;
void *var_a3;
temp_v0 = &D_8018EE10[arg0];
temp_a2 = arg0 + 1;
var_a3 = temp_v0 + 3;
var_a1 = 3;
var_v1 = (temp_v0->unk0 * temp_a2) + (temp_v0->unk1 * temp_a2) + 1 + (temp_v0->unk2 * temp_a2) + 2;
do {
temp_t7 = var_a3->unk1;
temp_t1 = var_a3->unk2;
temp_lo = var_a3->unk0 * temp_a2;
temp_t4 = var_a3->unk3;
var_a3 += 4;
temp_v1 = var_v1 + (temp_lo + var_a1) + ((temp_t7 * temp_a2) + var_a1) + 1 + ((temp_t1 * temp_a2) + var_a1) + 2 + ((temp_t4 * temp_a2) + var_a1);
var_a1 += 4;
var_v1 = temp_v1 + 3;
} while (var_a1 != 0x43);
return var_v1 & 0xFF;
u32 checksum = 0;
u8 *addr = (u8 *) &D_8018EE10[arg0];
s32 i;
for (i = 0; i < 0x43; i++) {
checksum += ((addr[i] * (arg0 + 1)) + i);
}
return checksum;
}
#else
GLOBAL_ASM("asm/non_matchings/code_800B45E0/func_800B6828.s")
#endif
#ifdef MIPS_TO_C
//generated by m2c commit 08138748803d75e73e4a94bb0c619a273754ee9c on Oct-08-2023
#ifdef NON_MATCHING
u8 func_800B68F4(s32 arg0) {
s32 temp_a1;
s32 temp_a3;
s32 var_a1;
s32 var_a2;
struct_8018EE10_entry *temp_v1;
void *temp_v0;
temp_a3 = arg0 + 1;
temp_v1 = &D_8018D9C0[arg0];
var_a2 = 3;
var_a1 = (temp_v1->unk0 * temp_a3) + (temp_v1->unk1 * temp_a3) + 1 + (temp_v1->unk2 * temp_a3) + 2;
do {
temp_v0 = temp_v1 + var_a2;
temp_a1 = var_a1 + ((temp_v0->unk0 * temp_a3) + var_a2) + ((temp_v0->unk1 * temp_a3) + var_a2) + 1 + ((temp_v0->unk2 * temp_a3) + var_a2) + 2 + ((temp_v0->unk3 * temp_a3) + var_a2);
var_a2 += 4;
var_a1 = temp_a1 + 3;
} while (var_a2 != 0x43);
return var_a1 & 0xFF;
s32 multiplier = arg0 + 1;
u32 checksum;
s32 i;
checksum = 0;
for (i = 0; i < 0x43; i++) {
u8 *addr = (u8 *) (&D_8018D9C0[arg0]);
checksum += addr[i] * multiplier + i;
}
return checksum;
}
#else
GLOBAL_ASM("asm/non_matchings/code_800B45E0/func_800B68F4.s")
+7 -1
View File
@@ -87,12 +87,18 @@ s32 func_800B6A68(void);
/* data */
// these might not be in this file, but for now...
typedef struct struct_8018EE10_entry_cont
{
struct_8018EE10_entry arr[1];
} struct_8018EE10_entry_cont;
extern u32* D_800DC714;
extern u16 gCompanyCode;
extern u32 gGameCode; // osPfs gamecode
extern s8 gControllerPak1State; // Current state of Controller Pak 1
extern struct_8018EE10_entry *D_8018D9C0;
extern struct_8018EE10_entry_cont *D_8018D9C0;
extern s8 sControllerPak2State; // Current state of the Controller Pak 2
extern const u8 D_800F2E60[];