From c6205b3df45273af953ec7318834b558a30ed930 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 20 May 2020 14:22:41 -0400 Subject: [PATCH] Document math_util.c --- include/math_util.h | 18 +++++++-------- src/battle_anim_effects_2.c | 14 +++++------ src/berry_crush.c | 46 ++++++++++++++++++------------------- src/frontier_pass.c | 16 ++++++------- src/math_util.c | 18 +++++++-------- 5 files changed, 56 insertions(+), 56 deletions(-) diff --git a/include/math_util.h b/include/math_util.h index 6b0d42460b..04013fc03f 100755 --- a/include/math_util.h +++ b/include/math_util.h @@ -1,14 +1,14 @@ #ifndef GUARD_MATH_UTIL_H #define GUARD_MATH_UTIL_H -s16 sub_8151534(s16 x, s16 y); -s16 sub_8151550(u8 s, s16 x, s16 y); -s32 sub_8151574(s32 x, s32 y); -s16 sub_81515B0(s16 x, s16 y); -s16 sub_81515D4(u8 s, s16 x, s16 y); -s32 sub_81515FC(s32 x, s32 y); -s16 sub_8151624(s16 y); -s16 sub_815163C(u8 s, s16 y); -s32 sub_815165C(s32 y); +s16 MathUtil_Mul16(s16 x, s16 y); +s16 MathUtil_Mul16Shift(u8 s, s16 x, s16 y); +s32 MathUtil_Mul32(s32 x, s32 y); +s16 MathUtil_Div16(s16 x, s16 y); +s16 MathUtil_Div16Shift(u8 s, s16 x, s16 y); +s32 MathUtil_Div32(s32 x, s32 y); +s16 MathUtil_Inv16(s16 y); +s16 MathUtil_Inv16Shift(u8 s, s16 y); +s32 MathUtil_Inv32(s32 y); #endif // GUARD_MATH_UTIL_H diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index 1337424467..f98b65913d 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -1578,7 +1578,7 @@ static void AnimAirWaveProjectile(struct Sprite *sprite) { sprite->data[0] = 8; task->data[5] = 4; - a = sub_8151624(0x1000); + a = MathUtil_Inv16(0x1000); sprite->pos1.x += sprite->pos2.x; sprite->pos1.y += sprite->pos2.y; sprite->pos2.y = 0; @@ -1597,8 +1597,8 @@ static void AnimAirWaveProjectile(struct Sprite *sprite) sprite->data[1] = 0; sprite->data[6] = 0; sprite->data[5] = 0; - sprite->data[3] = sub_8151534(sub_8151534(b, a), sub_8151624(0x1C0)); - sprite->data[4] = sub_8151534(sub_8151534(c, a), sub_8151624(0x1C0)); + sprite->data[3] = MathUtil_Mul16(MathUtil_Mul16(b, a), MathUtil_Inv16(0x1C0)); + sprite->data[4] = MathUtil_Mul16(MathUtil_Mul16(c, a), MathUtil_Inv16(0x1C0)); sprite->callback = AnimAirWaveProjectile_Step1; } } @@ -1689,18 +1689,18 @@ void AnimTask_AirCutterProjectile(u8 taskId) else xDiff = attackerX - targetX; - gTasks[taskId].data[5] = sub_8151534(xDiff, sub_8151624(gBattleAnimArgs[2] & ~1)); - gTasks[taskId].data[6] = sub_8151534(gTasks[taskId].data[5], 0x80); + gTasks[taskId].data[5] = MathUtil_Mul16(xDiff, MathUtil_Inv16(gBattleAnimArgs[2] & ~1)); + gTasks[taskId].data[6] = MathUtil_Mul16(gTasks[taskId].data[5], 0x80); gTasks[taskId].data[7] = gBattleAnimArgs[2]; if (targetY >= attackerY) { yDiff = targetY - attackerY; - gTasks[taskId].data[8] = sub_8151534(yDiff, sub_8151624(gTasks[taskId].data[5])) & ~1; + gTasks[taskId].data[8] = MathUtil_Mul16(yDiff, MathUtil_Inv16(gTasks[taskId].data[5])) & ~1; } else { yDiff = attackerY - targetY; - gTasks[taskId].data[8] = sub_8151534(yDiff, sub_8151624(gTasks[taskId].data[5])) | 1; + gTasks[taskId].data[8] = MathUtil_Mul16(yDiff, MathUtil_Inv16(gTasks[taskId].data[5])) | 1; } gTasks[taskId].data[3] = gBattleAnimArgs[3]; diff --git a/src/berry_crush.c b/src/berry_crush.c index 0593f53ebc..721fa47295 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -919,10 +919,10 @@ void sub_8020E58(void) var0 = gUnknown_02022C90->unk68.as_four_players.unk00.unk04; var0 <<= 8; - var0 = sub_81515FC(var0, 60 << 8); + var0 = MathUtil_Div32(var0, 60 << 8); var1 = gUnknown_02022C90->unk68.as_four_players.unk00.unk0A; var1 <<= 8; - var1 = sub_81515FC(var1, var0) & 0xFFFF; + var1 = MathUtil_Div32(var1, var0) & 0xFFFF; gUnknown_02022C90->unk16 = var1; switch (gUnknown_02022C90->unk9) { @@ -1232,12 +1232,12 @@ void sub_80214A8(struct BerryCrushGame *arg0, struct BerryCrushGame_138 *arg1) var0 *= 128; var6 = var5 + 32; var6 = var6 / 2; - var1 = sub_81515D4(7, 0x3F80, var6); + var1 = MathUtil_Div16Shift(7, 0x3F80, var6); data[0] = (u16)arg1->unk38[i]->pos1.x * 128; - data[3] = sub_81515D4(7, var0, var1); - var1 = sub_8151550(7, var1, 85); + data[3] = MathUtil_Div16Shift(7, var0, var1); + var1 = MathUtil_Mul16Shift(7, var1, 85); data[4] = 0; - data[5] = sub_81515D4(7, 0x3F80, var1); + data[5] = MathUtil_Div16Shift(7, 0x3F80, var1); data[7] |= 0x8000; if (arg1->unkC[i]->unk8 < 0) StartSpriteAffineAnim(arg1->unk38[i], 1); @@ -1383,7 +1383,7 @@ void sub_8021944(struct BerryCrushGame_138 *arg0, u16 arg1) arg0->unk4 = arg1 / 3600; arg0->unk6 = (arg1 % 3600) / 60; - r3 = sub_8151534((arg1 % 60) << 8, 4); + r3 = MathUtil_Mul16((arg1 % 60) << 8, 4); for (i = 0; i < 8; i++) { @@ -1939,12 +1939,12 @@ void sub_8022B28(struct Sprite *sprite) r7[2] = 32; r7[7] = 168; r4 = sprite->pos2.x * 128; - r5 = sub_81515D4(7, (168 - sprite->pos1.y) << 7, (r2 + 32) >> 1); + r5 = MathUtil_Div16Shift(7, (168 - sprite->pos1.y) << 7, (r2 + 32) >> 1); sprite->data[0] = sprite->pos1.x << 7; - r7[3] = sub_81515D4(7, r4, r5); - r2 = sub_8151550(7, r5, 85); + r7[3] = MathUtil_Div16Shift(7, r4, r5); + r2 = MathUtil_Mul16Shift(7, r5, 85); r7[4] = r8; - r7[5] = sub_81515D4(7, 0x3F80, r2); + r7[5] = MathUtil_Div16Shift(7, 0x3F80, r2); r7[6] = sprite->pos2.x / 4; r7[7] |= 0x8000; sprite->pos2.y = r8; @@ -2194,7 +2194,7 @@ static u32 sub_8022F1C(struct BerryCrushGame *r5, u8 *r2) } r5->unk10 = 0; ResetBlockReceivedFlags(); - r5->unk20 = sub_81515FC(r5->unk18 << 8, 0x2000); + r5->unk20 = MathUtil_Div32(r5->unk18 << 8, 0x2000); break; case 5: ClearDialogWindowAndFrame(0, 1); @@ -2412,7 +2412,7 @@ void sub_802339C(struct BerryCrushGame *r4) if (r0 - r2_ > 0) { r2_ <<= 8; - r2_ = sub_81515FC(r2_, r4->unk20); + r2_ = MathUtil_Div32(r2_, r4->unk20); r2_ >>= 8; r4->unk24 = r2_; } @@ -2800,14 +2800,14 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 ); r7->unk68.as_four_players.unk00.unk04 = r7->unk28; r7->unk68.as_four_players.unk00.unk06 = r7->unk18 / (r7->unk28 / 60); - r2 = sub_8151574(r7->unk30 << 8, 0x3200); - r2 = sub_81515FC(r2, r7->unk32 << 8) + 0x3200; + r2 = MathUtil_Mul32(r7->unk30 << 8, 0x3200); + r2 = MathUtil_Div32(r2, r7->unk32 << 8) + 0x3200; r2 >>= 8; r7->unk68.as_four_players.unk00.unk08 = r2 & 0x7F; r2 <<= 8; - r2 = sub_81515FC(r2, 0x6400); + r2 = MathUtil_Div32(r2, 0x6400); r4 = (r7->unk1C * r7->unk9) << 8; - r4 = sub_8151574(r4, r2); + r4 = MathUtil_Mul32(r4, r2); r7->unk68.as_four_players.unk00.unk00 = r4 >> 8; r7->unk68.as_five_players.unk1C[0].unk4.as_2d_bytes[0][7] = Random() % 3; for (r6 = 0, r8 = 0; r8 < r7->unk9; ++r8) @@ -2823,10 +2823,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[2]; r2 <<= 8; - r2 = sub_8151574(r2, 0x6400); + r2 = MathUtil_Mul32(r2, 0x6400); r4 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[3]; r4 <<= 8; - r4 = sub_81515FC(r2, r4); + r4 = MathUtil_Div32(r2, r4); } else { @@ -2838,10 +2838,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[4]; r2 <<= 8; - r2 = sub_8151574(r2, 0x6400); + r2 = MathUtil_Mul32(r2, 0x6400); r4 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[3]; r4 <<= 8; - r4 = sub_81515FC(r2, r4); + r4 = MathUtil_Div32(r2, r4); } else { @@ -2861,10 +2861,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[5]; r2 <<= 8; - r2 = sub_8151574(r2, 0x6400); + r2 = MathUtil_Mul32(r2, 0x6400); r4 = r7->unk28; r4 <<= 8; - r4 = sub_81515FC(r2, r4); + r4 = MathUtil_Div32(r2, r4); } break; } diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 42a518ed66..75893322ff 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -1038,15 +1038,15 @@ static void Task_DoFadeEffect(u8 taskId) BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_WHITE); } sPassGfx->setAffine = TRUE; - sPassGfx->unk2E = sub_8151624(data[1]); - sPassGfx->unk30 = sub_8151624(data[2]); + sPassGfx->unk2E = MathUtil_Inv16(data[1]); + sPassGfx->unk30 = MathUtil_Inv16(data[2]); break; case 1: UpdatePaletteFade(); data[1] += data[3]; data[2] += data[4]; - sPassGfx->unk2E = sub_8151624(data[1]); - sPassGfx->unk30 = sub_8151624(data[2]); + sPassGfx->unk2E = MathUtil_Inv16(data[1]); + sPassGfx->unk30 = MathUtil_Inv16(data[2]); if (!data[0]) { if (data[1] <= 0x1FC) @@ -1154,8 +1154,8 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) gUnknown_085713E0[sPassData->unkE - 1][1] << 8, gUnknown_085713E0[sPassData->unkE - 1][0], gUnknown_085713E0[sPassData->unkE - 1][1], - sub_8151624(0x1FC), - sub_8151624(0x1FC), + MathUtil_Inv16(0x1FC), + MathUtil_Inv16(0x1FC), 0); } else @@ -1165,8 +1165,8 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) gUnknown_085713E0[sPassData->unkE - 1][1] << 8, gUnknown_085713E0[sPassData->unkE - 1][0], gUnknown_085713E0[sPassData->unkE - 1][1], - sub_8151624(0x100), - sub_8151624(0x100), + MathUtil_Inv16(0x100), + MathUtil_Inv16(0x100), 0); } } diff --git a/src/math_util.c b/src/math_util.c index 83935454a4..f77c82608a 100644 --- a/src/math_util.c +++ b/src/math_util.c @@ -1,6 +1,6 @@ #include "global.h" -s16 sub_8151534(s16 x, s16 y) +s16 MathUtil_Mul16(s16 x, s16 y) { s32 result; @@ -10,7 +10,7 @@ s16 sub_8151534(s16 x, s16 y) return result; } -s16 sub_8151550(u8 s, s16 x, s16 y) +s16 MathUtil_Mul16Shift(u8 s, s16 x, s16 y) { s32 result; @@ -20,7 +20,7 @@ s16 sub_8151550(u8 s, s16 x, s16 y) return result; } -s32 sub_8151574(s32 x, s32 y) +s32 MathUtil_Mul32(s32 x, s32 y) { s64 result; @@ -30,7 +30,7 @@ s32 sub_8151574(s32 x, s32 y) return result; } -s16 sub_81515B0(s16 x, s16 y) +s16 MathUtil_Div16(s16 x, s16 y) { if (y == 0) { @@ -39,7 +39,7 @@ s16 sub_81515B0(s16 x, s16 y) return (x << 8) / y; } -s16 sub_81515D4(u8 s, s16 x, s16 y) +s16 MathUtil_Div16Shift(u8 s, s16 x, s16 y) { if (y == 0) { @@ -48,7 +48,7 @@ s16 sub_81515D4(u8 s, s16 x, s16 y) return (x << s) / y; } -s32 sub_81515FC(s32 x, s32 y) +s32 MathUtil_Div32(s32 x, s32 y) { s64 _x; @@ -61,7 +61,7 @@ s32 sub_81515FC(s32 x, s32 y) return _x / y; } -s16 sub_8151624(s16 y) +s16 MathUtil_Inv16(s16 y) { s32 x; @@ -69,7 +69,7 @@ s16 sub_8151624(s16 y) return x / y; } -s16 sub_815163C(u8 s, s16 y) +s16 MathUtil_Inv16Shift(u8 s, s16 y) { s32 x; @@ -77,7 +77,7 @@ s16 sub_815163C(u8 s, s16 y) return x / y; } -s32 sub_815165C(s32 y) +s32 MathUtil_Inv32(s32 y) { s64 x;