From fd8bc110675f6f669fb83623bed55928ad1c7119 Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Sat, 5 Sep 2026 21:49:42 +0200 Subject: [PATCH 01/12] bc_object5 cleanup + functions added --- include/battle.h | 27 +- include/battle/bc_object5.h | 4 +- src/battle/bc_object2.c | 22 +- src/battle/bc_object3.c | 14 +- src/battle/bc_object4.c | 4 +- src/battle/bc_object5.c | 771 +++++++++++++----------------------- src/battle/bc_object8.c | 69 ++-- 7 files changed, 347 insertions(+), 564 deletions(-) diff --git a/include/battle.h b/include/battle.h index 3bb86793..7871532c 100644 --- a/include/battle.h +++ b/include/battle.h @@ -494,8 +494,8 @@ typedef struct { /* 0x1292 */ s16 unk1292; /* 0x1294 */ s16 unk1294; /* 0x1296 */ s16 unk1296; - /* 0x1298 */ u8 pad1298[0x12B8 - 0x1298]; - /* 0x12B8 */ u16 array12B8[7]; + /* 0x1298 */ s32 unk1298[8]; + /* 0x12B8 */ u16 unk12B8[7]; /* 0x12C6 */ u8 pad12C7[0x12CC - 0x12C6]; /* 0x12CC */ Struct_12CC array12CC[1]; /* used in func_8009D594 */ /* 0x12CF */ u8 pad12CF[0x12D8 - 0x12CF]; @@ -697,6 +697,14 @@ typedef struct { u8 unk3; } BattleUnkSlot; +typedef struct{ + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; + u8 unk4; +} BattleTestSlot; + /** @brief Battle character render data (g_battleChars, stride 0x1D0 = 464 bytes). */ typedef struct { /* 0x000 */ u8 pad0[0x008 - 0x000]; @@ -708,7 +716,8 @@ typedef struct { /* 0x01C */ u8 unk1C; /* 0x01D */ u8 unk1D; /* 0x01E */ BattleCmdSlot cmdSlots[4]; - /* 0x02E */ u8 pad2E[0x082 - 0x02E]; + /* 0x02E */ u8 pad2E[4]; + /* 0x032 */ BattleTestSlot testSlots[16]; /* 0x082 */ BattleMagicSlot magicSlots[32]; /* 0x122 */ BattleItemSlot itemSlots[16]; /* 0x172 */ s16 unk172; /**< Mirrored HP cap (set with hpRegenCap when battle HP is reduced). */ @@ -916,7 +925,9 @@ typedef struct { */ typedef struct { u16 lookupId; /**< u16 passed to resolveKernelPtr. */ - u8 pad2[6]; + u8 unk2; + u8 unk3; + u8 pad4[4]; } BattleSceneRow8; /* 8 bytes */ typedef struct { @@ -949,12 +960,12 @@ typedef struct { typedef struct { u16 unk0; - u8 unk1; u8 unk2; u8 unk3; u8 unk4; u8 unk5; u8 unk6; + u8 unk7; u8 unk8; u8 unk9; u16 unkA; @@ -991,7 +1002,7 @@ typedef struct { u8 unk2; u8 unk3; u8 unk4; - u8 pad5; + u8 unk5; u8 unk6; u8 unk7; u8 unk8; @@ -1098,8 +1109,7 @@ typedef struct { /* 0x3F63 */ u8 pad3F63[0x4020 - 0x3F63]; /* 0x4020 */ Struct_4020 array4020[1]; /* 0x4030 */ u8 pad4034[0x4484 - 0x4030]; - /* 0x4484 */ Struct_446C array4484[1]; - /* 0x449C */ u8 pad449C[0x44FC - 0x449C]; + /* 0x4484 */ Struct_446C array4484[5]; /* 0x44FC */ Struct_4020 array44FC[1]; /* 0x450C */ u8 pad4510[0x45F8 - 0x450C]; /* 0x45F8 */ Struct_45F8 array45F8[1]; /**< stride 8 */ @@ -1225,6 +1235,7 @@ extern s16 D_8005F11C; extern u8 D_80077E58; extern u8 D_80077E92; extern u8 D_80077E59; +extern u8 D_8007809A; extern u8 D_800786D9; extern u8 D_80078DF8; extern BattleSceneData D_80078E00; diff --git a/include/battle/bc_object5.h b/include/battle/bc_object5.h index c2b826e0..2b5da2c6 100644 --- a/include/battle/bc_object5.h +++ b/include/battle/bc_object5.h @@ -19,7 +19,7 @@ extern void func_800A97D4(void); /** @brief State queries polled by the battle flow controller (bc_object6). */ -extern s32 func_800A980C(void); -extern s32 func_800A9888(void); +extern u16 func_800A980C(void); +extern u16 func_800A9888(void); #endif /* BC_OBJECT5_H */ diff --git a/src/battle/bc_object2.c b/src/battle/bc_object2.c index 25833bb6..943ff1cf 100644 --- a/src/battle/bc_object2.c +++ b/src/battle/bc_object2.c @@ -2437,10 +2437,10 @@ void func_800A09D0(s32 arg0) { break; case 29: - func_8009FCF4(D_80078E00.array4020[D_800EE4C0.statusCode].unk5); - var_s3 = D_80078E00.array4020[D_800EE4C0.statusCode].unk4; - D_800EE4C0.unk4 = D_80078E00.array4020[D_800EE4C0.statusCode].unk2; - var_a0 = D_80078E00.array4020[D_800EE4C0.statusCode].unk3; + func_8009FCF4(D_80078E00.array4020[D_800EE4C0.statusCode].unk6); + var_s3 = D_80078E00.array4020[D_800EE4C0.statusCode].unk5; + D_800EE4C0.unk4 = D_80078E00.array4020[D_800EE4C0.statusCode].unk3; + var_a0 = D_80078E00.array4020[D_800EE4C0.statusCode].unk4; D_800EE4C0.unkC = func_8009F930(var_a0, temp_s4, arg0, var_s3); break; @@ -2512,10 +2512,10 @@ void func_800A09D0(s32 arg0) { break; case 15: - func_8009FCF4(D_80078E00.array44FC[D_800EE4C0.statusCode].unk5); + func_8009FCF4(D_80078E00.array44FC[D_800EE4C0.statusCode].unk6); var_s3 = D_80078E00.array45F8[func_8009FDE0(temp_s4, D_800EE4C0.statusCode)].unk6; - D_800EE4C0.unk4 = D_80078E00.array44FC[D_800EE4C0.statusCode].unk1; - var_a0 = D_80078E00.array44FC[D_800EE4C0.statusCode].unk2; + D_800EE4C0.unk4 = D_80078E00.array44FC[D_800EE4C0.statusCode].unk2; + var_a0 = D_80078E00.array44FC[D_800EE4C0.statusCode].unk3; D_800EE4C0.unkC = func_8009F930(var_a0, temp_s4, arg0, var_s3); break; @@ -2539,10 +2539,10 @@ void func_800A09D0(s32 arg0) { case 32: case 33: case 34: - func_8009FCF4(D_80078E00.array4020[D_800EE4C0.statusCode].unk5); - var_s3 = D_80078E00.array4020[D_800EE4C0.statusCode].unk4; - D_800EE4C0.unk4 = D_80078E00.array4020[D_800EE4C0.statusCode].unk2; - var_a0 = D_80078E00.array4020[D_800EE4C0.statusCode].unk3; + func_8009FCF4(D_80078E00.array4020[D_800EE4C0.statusCode].unk6); + var_s3 = D_80078E00.array4020[D_800EE4C0.statusCode].unk5; + D_800EE4C0.unk4 = D_80078E00.array4020[D_800EE4C0.statusCode].unk3; + var_a0 = D_80078E00.array4020[D_800EE4C0.statusCode].unk4; D_800EE4C0.unkC = func_8009F930(var_a0, temp_s4, arg0, var_s3); break; diff --git a/src/battle/bc_object3.c b/src/battle/bc_object3.c index 3907cad5..6e21e9b5 100644 --- a/src/battle/bc_object3.c +++ b/src/battle/bc_object3.c @@ -851,7 +851,7 @@ s32 func_800A30F8(s32 arg0, u8 arg1, u16 arg2, u8 arg3, u8 arg4, u16 arg5, u8 ar else { arg2 = D_80078E00.unkE8[arg1].unk0; - var_s3 = D_80078E00.array4020[arg2].unk6; + var_s3 = D_80078E00.array4020[arg2].unk7; sp2E = D_80078E00.array4020[arg2].unk0; break; } @@ -1146,7 +1146,7 @@ s32 func_800A30F8(s32 arg0, u8 arg1, u16 arg2, u8 arg3, u8 arg4, u16 arg5, u8 ar break; case 15: - var_s3 = D_80078E00.array44FC[arg2].unk6; + var_s3 = D_80078E00.array44FC[arg2].unk7; sp2E = D_80078E00.array44FC[arg2].unk0; var_s2 = getJuncEffectName(arg2); break; @@ -1261,7 +1261,7 @@ s32 func_800A30F8(s32 arg0, u8 arg1, u16 arg2, u8 arg3, u8 arg4, u16 arg5, u8 ar if (!(D_800ED148.entities[sp2A].status & 4)) { if (func_8009EF64(sp2A) != 0) { arg2 = D_80078E00.unkE8[arg1].unk0; - var_s3 = D_80078E00.array4020[arg2].unk6; + var_s3 = D_80078E00.array4020[arg2].unk7; sp2E = D_80078E00.array4020[arg2].unk0; break; } @@ -1281,7 +1281,7 @@ s32 func_800A30F8(s32 arg0, u8 arg1, u16 arg2, u8 arg3, u8 arg4, u16 arg5, u8 ar case 33: case 34: arg2 = D_80078E00.unkE8[arg1].unk0; - var_s3 = D_80078E00.array4020[arg2].unk6; + var_s3 = D_80078E00.array4020[arg2].unk7; sp2E = D_80078E00.array4020[arg2].unk0; var_s2 = getAbilityEntryName(arg1); break; @@ -1500,7 +1500,7 @@ s32 func_800A4798(u32 arg0, s32 arg1) { // arg0 is always 0-6 u16 mask = 1 << arg0; for (i = 0; i < arg1; i++) { - if (mask & D_800ED148.array12B8[i]) { + if (mask & D_800ED148.unk12B8[i]) { count++; } } @@ -1671,7 +1671,7 @@ void func_800A4B88(u16 arg0, s32 arg1) { var_a1 = func_800A4E08(var_a1, var_s0); } - D_800ED148.array12B8[i] = func_800A4A74(arg1, var_a1); + D_800ED148.unk12B8[i] = func_800A4A74(arg1, var_a1); } D_800ED148.unk130A = var_s0; @@ -1691,7 +1691,7 @@ void func_800A4C84(u16 arg0) { func_800A4B88(arg0, D_800EE4C0.unkB); for (i = 0; i < D_800EE4C0.unkB; i++) { - temp_s1 = func_800A4FC4(D_800ED148.array12B8[i], sp10); + temp_s1 = func_800A4FC4(D_800ED148.unk12B8[i], sp10); var_s5 += temp_s1; if (temp_s1 != 0) { diff --git a/src/battle/bc_object4.c b/src/battle/bc_object4.c index 1aa6d1c5..fa011560 100644 --- a/src/battle/bc_object4.c +++ b/src/battle/bc_object4.c @@ -314,9 +314,6 @@ void func_800A69BC(void) { case 4: func_8009AF3C(getMenuString(0x2F), (D_80077E59 * 8) + 8, 3, 128, 86); break; - - default: - return; } } @@ -600,6 +597,7 @@ s32 func_800A703C(s32 a0) { if (a0 < limit) { return a0; } + return limit; } diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index b153c562..2fa39462 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -5,6 +5,7 @@ #include "battle/bc_object6.h" #include "battle/bc_object7.h" +extern u8 D_800EEBE0[]; // an array containing 1s and 0s extern u8 D_800E3CEC[]; void func_800AB054(void); void func_800AB1AC(void); @@ -18,285 +19,234 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8CA4); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8D7C); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8E90); +void func_800A8E90(BattleCharData* arg0, s32 arg1) { + arg0->testSlots[0].unk0 = arg1; + arg0->testSlots[0].unk2 = D_80078E00.array4484[arg1].unk5; + arg0->testSlots[0].unk3 = D_80078E00.array4484[arg1].unk6; + arg0->testSlots[0].unk4 = 0; + arg0->testSlots[0].unk1 = 1; + + if (D_80078E00.array4484[arg1].unk7 & 0x80) { + arg0->testSlots[0].unk4 |= 1; + } +} INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8EFC); -/** - * @brief Initialize entity ability fields from the ability table. - * - * Writes a1 as the ability ID at offset 0x32 of the entity entry - * (computed as a0 + a2*5). Looks up ability data in D_80078E00 - * (offset 0x4A60, stride 8) and copies two bytes to offsets 0x34-0x35. - * Clears offset 0x36 and sets offset 0x33 to 1. - * - * @param a0 Base entity pointer (as integer). - * @param a1 Ability ID. - * @param a2 Slot index (multiplied by 5 for stride). - */ -void func_800A8F98(s32 a0, s32 a1, s32 a2) { - s32 entry = a0 + a2 * 5; - s32 tbl = (s32)&D_80078E00; - s32 lookup = a1 * 8; - s32 b; - *(u8 *)(entry + 0x32) = a1; - *(u8 *)(entry + 0x34) = *(u8 *)(tbl + lookup + 0x4A60); - b = *(u8 *)(tbl + lookup + 0x4A61); - *(u8 *)(entry + 0x36) = 0; - *(u8 *)(entry + 0x33) = 1; - *(u8 *)(entry + 0x35) = b; +void func_800A8F98(BattleCharData* arg0, s32 arg1, s32 arg2) { + arg0->testSlots[arg2].unk0 = arg1; + arg0->testSlots[arg2].unk2 = D_80078E00.rows8[arg1].unk2; + arg0->testSlots[arg2].unk3 = D_80078E00.rows8[arg1].unk3; + arg0->testSlots[arg2].unk4 = 0; + arg0->testSlots[arg2].unk1 = 1; } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8FDC); +s32 func_800A8FDC(BattleCharData* arg0) { + s32 current; + s32 val = 0; -/** - * @brief Initialize three type bytes in an entity structure. - * - * @param a0 Pointer to entity data. - * @return Always 3. - */ -s32 func_800A9064(u8 *a0) { - a0[0x32] = 0x41; - a0[0x37] = 0x43; - a0[0x3C] = 0x42; + if (!(g_gameState.mainData.partyLockFlag & 0x10)) { + val++; + func_800A8F98(arg0, 0, 0); + } + + current = val; + if (g_gameState.mainData.partyLockFlag & 0x20) { + val++; + func_800A8F98(arg0, 1, current); + } + + return val; +} + +s32 func_800A9064(BattleCharData* arg0) { + arg0->testSlots[0].unk0 = 65; + arg0->testSlots[1].unk0 = 67; + arg0->testSlots[2].unk0 = 66; + return 3; } INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9084); -/** - * @brief Search g_gameState+0xB44 table for entry matching a given byte. - * - * Iterates up to 198 entries (stride 2) in g_gameState at offset 0xB44. - * If byte[0] matches a0, returns byte[1]. Returns 0 if not found. - * - * @param a0 Value to search for. - * @return Unsigned byte at offset 1 of matching entry, or 0 if not found. - */ -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9240); +u8 func_800A9240(s32 arg0) { + s32 i; + + for (i = 0; i < 198; i++) { + if (g_gameState.mainData.itemSlots[i].id == arg0) { + return g_gameState.mainData.itemSlots[i].count; + } + } + + return 0; +} INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9284); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9370); +s32 func_800A9370(s32 arg0) { + BattleCharData* temp_a0; + s32 i; + + temp_a0 = &g_battleChars.chars[arg0]; + + for (i = 0; i < 16; i++) { + temp_a0->testSlots[i].unk4 = 0; + temp_a0->testSlots[i].unk1 = 0; + temp_a0->testSlots[i].unk3 = 0; + temp_a0->testSlots[i].unk2 = 0; + temp_a0->testSlots[i].unk0 = 0; + temp_a0->testSlots[i].unk4 |= 0x10; + } + + switch (temp_a0->characterId) { + case 0: + case 1: + return 0; + + case 2: + return func_800A9284(temp_a0); + + case 3: + return func_800A8EFC(temp_a0); + + case 4: + return func_800A8FDC(temp_a0); + + case 5: + return func_800A9064(temp_a0); + + case 6: + func_800A8E90(temp_a0, 0); + return 1; + + case 7: + func_800A8E90(temp_a0, 1); + return 1; + + case 8: + func_800A8E90(temp_a0, 2); + return 1; + + case 9: + func_800A8E90(temp_a0, 3); + return 1; + + case 10: + func_800A8E90(temp_a0, 4); + return 1; + } +} + INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9490); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A94E0); -/** - * @brief Search D_800EE9E8 table for a matching byte value. - * - * Iterates up to 32 entries (stride 5) in D_800EE9E8, comparing - * the first byte of each entry to a0. - * - * @param a0 Value to search for. - * @return 1 if found, 0 if not found. - * - * @code - * s32 func_800A9568(s32 a0) { - * s32 i = 0; - * u8 *ptr = D_800EE9E8; - * do { - * if (*ptr == a0) return 1; - * i++; - * ptr += 5; - * } while (i < 32); - * return 0; - * } - * @endcode - */ -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9568); +s32 func_800A9568(s32 arg0) { + s32 i; -/** - * @brief Set up entity action with sound and visual effects. - * - * Calls func_800A97FC to get a value, then triggers entity action - * via func_800B0754, sets animation via func_800AF4BC, and - * conditionally calls func_800AE3D4 based on func_800AE390 result. - * - * @param a0 Entity index passed to func_800A97FC and func_800B0754. - * @param a1 Mode parameter for func_800B0754 and subsequent calls. - */ -void func_800A95A0(s32 a0, s32 a1) { - s32 val = func_800A97FC(a0); - func_800B0754(a0, 4, a1, (u16)val); - func_800AF4BC(a1, 1); - if (func_800AE390(a1) == 0) { - func_800AE3D4(a1); + for (i = 0; i < 32; i++) { + if (D_800EE9E8.animSlots[i].id == arg0) { + return 1; + } + } + + return 0; +} + +void func_800A95A0(s32 arg0, s32 arg1) { + func_800B0754(arg0, 4, arg1, func_800A97FC(arg0)); + func_800AF4BC(arg1, 1); + + if (func_800AE390(arg1) == 0) { + func_800AE3D4(arg1); } } INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A960C); -/** - * @brief Compute paired lookup results from entity table and return combined. - * - * Computes D_80078E00 + a0 * 20 as the base address, loads the byte at - * offset 0x3EE7, calls func_800B0F9C and func_800B0F7C with it, and - * returns the bitwise OR of both results masked to 16 bits. - * - * @param a0 Entity index (stride 20 in D_80078E00). - * @return Combined result from both lookups, masked to u16. - */ s32 func_800A972C(s32 arg0) { return func_800B0F9C(D_80078E00.entriesA0[arg0].unk7) | func_800B0F7C(D_80078E00.entriesA0[arg0].unk7); } -/** - * @brief Resolve a 16-bit offset to an address. - * - * If the offset is 0xFFFF (sentinel), returns D_800E3CEC. - * Otherwise returns offset + base. - * - * @param offset 16-bit offset value (0xFFFF = invalid). - * @param base Base address to add offset to. - * @return Resolved address. - */ -s32 func_800A9784(u16 offset, s32 base) { - if ((offset & 0xFFFF) == 0xFFFF) { - return (s32)D_800E3CEC; +u8* func_800A9784(u16 arg0, s32 arg1) { + if (arg0 == 65535) { + return D_800E3CEC; } - return offset + base; + + return arg0 + arg1; // weird } -/** - * @brief Return a random number modulo @p a0. - * - * @param a0 Divisor (also the modulo bound). - * @return Remainder of @c func_8009B15C() / @p a0. - */ -s32 func_800A97A4(s32 a0) { - return func_8009B15C() % a0; +s32 func_800A97A4(s32 arg0) { + return func_8009B15C() % arg0; } -/** - * @brief Clear 8 entity word fields in the battle entity table. - * - * Zeros 8 consecutive words at offset 0x12B4 down to 0x1298 - * relative to D_800ED148. - */ void func_800A97D4(void) { - s32 i = 7; - s32 base = (s32)&D_800ED148; - base += 0x1C; -top: - *(s32 *)(base + 0x1298) = 0; - i--; - base -= 4; - if (i >= 0) goto top; + s32 i; + + for (i = 0; i < 8; i++) { + D_800ED148.unk1298[i] = 0; + } } -/** - * @brief Compute a single-bit mask at the given position. - * - * @param bitPos Bit position (0-15). - * @return 16-bit mask with bit at bitPos set. - */ u16 func_800A97FC(s32 arg0) { - return 1 << arg0; + return (1 << arg0); } -/** - * @brief Find a random available entity (among first 3) and return its bitmask. - * - * Calls func_800AE730 to get entity count. If 0xFF, returns 0. - * Otherwise loops calling func_800A97A4(3) to pick random indices, - * checking entity[0x90] bit 0 (busy flag). Returns (1 << idx) & 0xFFFF - * when an available entity is found. - * - * @return Bitmask of selected entity, or 0 if none available. - */ -s32 func_800A980C(void) { +u16 func_800A980C(void) { s32 idx; - u8 *table; - if (func_800AE730() == 0xFF) { + + if (func_800AE730() == 255) { return 0; } - table = (u8 *)&D_800ED148; + do { idx = func_800A97A4(3); - } while (*(u16 *)(table + idx * 0xD0 + 0x90) & 1); - return (1 << idx) & 0xFFFF; + } while (D_800ED148.entities[idx].status & 1); + + return (1 << idx); } -/** - * @brief Find a random available entity (among 4, offset by 3) and return its bitmask. - * - * Calls func_800AE788 to get entity count. If 0xFF, returns 8. - * Otherwise loops calling func_800A97A4(4), adds 3 to the index, - * checks entity[0x90] bit 0 (busy flag). Returns (1 << (idx+3)) & 0xFFFF - * when an available entity is found. - * - * @return Bitmask of selected entity, or 8 if none available. - */ -s32 func_800A9888(void) { +u16 func_800A9888(void) { s32 idx; - u8 *table; - if (func_800AE788() == 0xFF) { + + if (func_800AE788() == 255) { return 8; } - table = (u8 *)&D_800ED148; + do { idx = func_800A97A4(4) + 3; - } while (*(u16 *)(table + idx * 0xD0 + 0x90) & 1); - return (1 << idx) & 0xFFFF; + } while (D_800ED148.entities[idx].status & 1); + + return (1 << idx); } -/** - * @brief Compute a bitmask from an entity's byte at offset 0x98. - * - * @param a0 Entity index (stride 0xD0). - * @return 16-bit mask with one bit set at the position given by entity[0x98]. - */ -u16 func_800A9904(s32 a0) { - u8 *base = (u8 *)&D_800ED148; - u8 *entity; - asm(""); - entity = base + a0 * 0xD0; - return (1 << entity[0x98]) & 0xFFFF; +u16 func_800A9904(s32 arg0) { + return (1 << D_800ED148.entities[arg0].unk98); } -extern u8 D_800EEBE0[]; - -/** - * @brief Toggle the least significant bit of 7 bytes in D_800EEBE0. - */ void func_800A9938(void) { - s32 i = 0; - u8 *base = D_800EEBE0; - do { - u8 *p = (u8 *)(i + (s32)base); - *p = (~*p) & 1; - i++; - } while (i < 7); + s32 i; + + for (i = 0; i < 7; i++) { + D_800EEBE0[i] = ~D_800EEBE0[i] & 1; + } } -/** - * @brief Populate entity alive flags array from status bits. - * - * Iterates over 7 entities at stride 0xD0 from D_800ED148. For each, - * checks bit 8 (0x100) of the flags word at offset 0x8C. Writes 1 to - * D_800EEBE0[i] if the bit is set, 0 otherwise. If a0 equals 0xC8, - * calls func_800A9938 to toggle the result bits. - * - * @param a0 Trigger value — if 0xC8, post-processes the flags. - */ -void func_800A9970(s32 a0) { - s32 i = 0; - s32 one = 1; - u8 *output = D_800EEBE0; - u8 *entity = (u8 *)&D_800ED148; - do { - if (*(s32 *)(entity + 0x8C) & 0x100) { - *output = one; - } else { - *output = 0; +void func_800A9970(s32 arg0) { + s32 i; + + for (i = 0; i < 7; i++) { + if (D_800ED148.entities[i].controlFlags & 0x100) { + D_800EEBE0[i] = 1; + } + + else { + D_800EEBE0[i] = 0; } - output++; - i++; - entity += 0xD0; - } while (i < 7); - if (a0 == 0xC8) { + } + + if (arg0 == 200) { func_800A9938(); } } @@ -311,42 +261,24 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9C68); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9E08); -/** - * @brief Clear D_800EEBE0 entries for inactive entities. - * - * Loops over 7 entities at D_800ED148 (stride 0xD0). If bit 0 of the - * word at offset 0x8C is not set, clears D_800EEBE0[i] to zero. - */ void func_800A9F98(void) { - s32 i = 0; - s32 arr = (s32)D_800EEBE0; - s32 ptr = (s32)&D_800ED148; - do { - if (!(*(s32 *)(ptr + 0x8C) & 1)) { - *(u8 *)(i + arr) = 0; + s32 i; + + for (i = 0; i < 7; i++) { + if (!(D_800ED148.entities[i].controlFlags & 1)) { + D_800EEBE0[i] = 0; } - i++; - ptr += 0xD0; - } while (i < 7); + } } -/** - * @brief Clear D_800EEBE0 entries for inactive or dead entities. - * - * Iterates 7 entities (stride 0xD0 in D_800ED148). Clears - * D_800EEBE0[i] to zero unless the entity is both active and alive. - */ void func_800A9FDC(void) { - s32 i = 0; - s32 arr = (s32)D_800EEBE0; - s32 ptr = (s32)&D_800ED148; -top: - if (!(*(s32 *)(ptr + 0x8C) & 1) || (*(u16 *)(ptr + 0x90) & 1)) { - *(u8 *)(i + arr) = 0; + s32 i; + + for (i = 0; i < 7; i++) { + if (!(D_800ED148.entities[i].controlFlags & 1) || (D_800ED148.entities[i].status & 1)) { + D_800EEBE0[i] = 0; + } } - i++; - ptr += 0xD0; - if (i < 7) goto top; } INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA034); @@ -355,190 +287,122 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA368); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA44C); -/** @brief Return constant 0x8007. */ s32 func_800AA4E0(void) { - return 0x8007; + return 32775; } -/** @brief Return constant 0x80F8. */ s32 func_800AA4E8(void) { - return 0x80F8; + return 33016; } -/** @brief Return constant 0x80FF. */ s32 func_800AA4F0(void) { - return 0x80FF; + return 33023; } -/** - * @brief Search entity table for a matching byte at offset 0xCB. - * - * @param a0 Value to search for. - * @return Entity index (0-6) if found, or 0xFF if not found. - */ -s32 func_800AA4F8(s32 a0) { - s32 i = 0; - u8 *entity = (u8 *)&D_800ED148; - do { - if (entity[0xCB] == a0) { +s32 func_800AA4F8(s32 arg0) { + s32 i; + + for (i = 0; i < 7; i++) { + if (D_800ED148.entities[i].linkedIdx == arg0) { return i; } - i++; - entity += 0xD0; - } while (i < 7); - return 0xFF; + } + + return 255; } -/** - * @brief Search entity table for active entity linked to index a0. - * - * @param a0 Link index to search for. - * @return Entity index if found, 0xFF otherwise. - */ -s32 func_800AA530(s32 a0) { - s32 i = 0; - s32 base = (s32)&D_800ED148; - s32 ptr = base; - s32 result; -top: - if (!(*(u16 *)(ptr + 0x90) & 1)) { - result = i; - if (*(u8 *)(ptr + 0xCB) == a0) { - return result; +s32 func_800AA530(s32 arg0) { + s32 i; + + for (i = 0; i < 7; i++) { + if (!(D_800ED148.entities[i].status & 1) && ((D_800ED148.entities[i].linkedIdx == arg0))) { + return i; } } - i++; - ptr += 0xD0; - if (i < 7) goto top; - return 0xFF; + + return 255; } INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA57C); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA68C); -/** - * @brief Conditionally search entity table and check for 0xFF result. - * - * If a0 is 0, returns whether func_800AA4F8(a1) is not 0xFF. - * If a0 is 3, returns whether func_800AA4F8(a1) is 0xFF. - * - * @param a0 Mode selector (0 = found check, 3 = not-found check). - * @param a1 Search value passed to func_800AA4F8. - * @return Boolean result based on mode. - */ -s32 func_800AA71C(s32 a0, s32 a1) { - if (a0 == 0) { - return func_800AA4F8(a1) != 0xFF; +s32 func_800AA71C(s32 arg0, s32 arg1) { + if (arg0 == 0) { + return func_800AA4F8(arg1) != 255; } - if (a0 == 3) { - return func_800AA4F8(a1) == 0xFF; + + if (arg0 == 3) { + return func_800AA4F8(arg1) == 255; } } -/** - * @brief Conditionally search via func_800AA530 and check for 0xFF result. - * - * If a0 is 0, returns whether func_800AA530(a1) is not 0xFF. - * If a0 is 3, returns whether func_800AA530(a1) is 0xFF. - * - * @param a0 Mode selector (0 = found check, 3 = not-found check). - * @param a1 Search value passed to func_800AA530. - * @return Boolean result based on mode. - */ -s32 func_800AA768(s32 a0, s32 a1) { - if (a0 == 0) { - return func_800AA530(a1) != 0xFF; +s32 func_800AA768(s32 arg0, s32 arg1) { + if (arg0 == 0) { + return func_800AA530(arg1) != 255; } - if (a0 == 3) { - return func_800AA530(a1) == 0xFF; + + if (arg0 == 3) { + return func_800AA530(arg1) == 255; } } INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA7B4); -/** - * @brief Conditionally search via func_800AA7B4 and check for 0xFF result. - * - * If a0 is 0, returns whether func_800AA7B4(a1) is not 0xFF. - * If a0 is 3, returns whether func_800AA7B4(a1) is 0xFF. - * - * @param a0 Mode selector (0 = found check, 3 = not-found check). - * @param a1 Search value passed to func_800AA7B4. - * @return Boolean result based on mode. - */ -s32 func_800AA840(s32 a0, s32 a1) { - if (a0 == 0) { - return func_800AA7B4(a1) != 0xFF; +s32 func_800AA840(s32 arg0, s32 arg1) { + if (arg0 == 0) { + return func_800AA7B4(arg1) != 255; } - if (a0 == 3) { - return func_800AA7B4(a1) == 0xFF; + + if (arg0 == 3) { + return func_800AA7B4(arg1) == 255; } } INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA88C); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA930); +s32 func_800AA930(s32 arg0) { + drawSlot* var_v1; + s32 i; -/** - * @brief Conditionally call func_800AA930 and optionally invert the result. - * - * If a0 is 0, calls func_800AA930 with a1 and returns its result. - * If a0 is 3, calls func_800AA930 with a1 and returns the inverted - * lowest bit of the result. - * - * @param a0 Mode selector (0 = normal, 3 = inverted). - * @param a1 Parameter passed to func_800AA930. - * @return Result of func_800AA930, possibly with bit 0 inverted. - */ -s32 func_800AA980(s32 a0, s32 a1) { - if (a0 == 0) { - return func_800AA930(a1); + + var_v1 = D_800EE9E8.subEntries[arg0 - 3].array0; + for (i = 0; i < 4; i++) { + if (var_v1[i].unk0 > 63) { + return 1; + } + } + + return 0; +} + +s32 func_800AA980(s32 arg0, s32 arg1) { + if (arg0 == 0) { + return func_800AA930(arg1); } - if (a0 == 3) { - s32 result = func_800AA930(a1); - return (~result) & 1; + + if (arg0 == 3) { + return (~func_800AA930(arg1)) & 1; } } -/** - * @brief Test a specific bit in D_8007809A, optionally inverting. - * - * If a0 is 0, returns bit a1 of D_8007809A. - * If a0 is 3, returns the inverse of bit a1 of D_8007809A. - * Otherwise returns 0 (falls through without setting return value). - * - * @param a0 Mode selector (0 = normal, 3 = inverted). - * @param a1 Bit position to test. - * @return Bit value (0 or 1). - */ -s32 func_800AA9C8(s32 a0, s32 a1) { - if (a0 == 0) { - return (D_8007809A >> a1) & 1; +s32 func_800AA9C8(s32 arg0, s32 arg1) { + if (arg0 == 0) { + return (D_8007809A >> arg1) & 1; } - if (a0 == 3) { - return ((D_8007809A >> a1) & 1) ^ 1; + + if (arg0 == 3) { + return ((D_8007809A >> arg1) & 1) ^ 1; } } -/** - * @brief Test countdownTimer, optionally inverted. - * - * If a0 == 0, returns 1 when countdownTimer is zero (no battle active). - * If a0 == 3, returns 1 when countdownTimer is nonzero (battle active). - * Other values fall through with no explicit return. - * - * @param a0 Query mode (0 = test no-battle, 3 = test in-battle). - * @return 1 or 0 based on the flag value. - */ -s32 func_800AAA10(s32 a0) { - if (a0 == 0) { - volatile GameState *gs = &g_gameState; - return gs->mainData.countdownTimer == 0; +s32 func_800AAA10(s32 arg0) { + if (arg0 == 0) { + return g_gameState.mainData.countdownTimer == 0; } - if (a0 == 3) { - volatile GameState *gs = &g_gameState; - return gs->mainData.countdownTimer != 0; + + if (arg0 == 3) { + return g_gameState.mainData.countdownTimer != 0; } } @@ -558,39 +422,20 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAE10); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAE98); -/** - * @brief Allocate structure via func_800AA57C and copy field +0x1C to +0x18. - * - * @param a0 Second parameter to func_800AA57C (first is 0xC8). - */ -void func_800AAF48(s32 a0) { - u8 *result = func_800AA57C(0xC8, a0); - *(s32 *)(result + 0x18) = *(s32 *)(result + 0x1C); +void func_800AAF48(s32 arg0) { + BattleEntityData* temp_v0; + + temp_v0 = func_800AA57C(200, arg0); + temp_v0->unk18 = temp_v0->unk1C; } -/** - * @brief Allocate entry and add signed offset to its field at 0x18. - * - * Calls func_800AA57C with 0xC8 and a0, then sign-extends a1 to 16 bits - * and adds it to the word at offset 0x18 of the returned entry. - * - * @param a0 Second parameter to func_800AA57C. - * @param a1 Signed 16-bit offset to add. - */ -void func_800AAF70(s32 a0, s32 a1) { - u8 *result = func_800AA57C(0xC8, a0); - *(s32 *)(result + 0x18) += (s16)a1; +void func_800AAF70(s32 arg0, s16 arg1) { + BattleEntityData* temp_v0; + + temp_v0 = func_800AA57C(200, arg0); + temp_v0->unk18 += arg1; } -/** - * @brief Look up entity entry by index, call animation init, set active flag. - * - * Computes D_800EE28C + a0 * 16 to get the entry, calls func_8009AF3C - * with entry[4], duration 0x1E, mode 3, size 0x80, and zero flag. - * Then sets entry[0xF] to 1. - * - * @param a0 Entity index (stride 16). - */ void func_800AAFB8(s32 arg0) { TaskEntry* data; @@ -607,16 +452,6 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB054); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB07C); -/** - * @brief Allocate entry via func_8009B3D0 and store battle data. - * - * Allocates an entry using func_800AB054 as callback, computes the - * entry address from D_800EE28C + index * 16, stores the result of - * func_800B0398(a0) at offset 4, and a1 as halfword at offset 8. - * - * @param a0 Parameter passed to func_800B0398. - * @param a1 Halfword value stored at entry offset 8. - */ void func_800AB0C0(s32 arg0, u16 arg1) { TaskEntry* currentEntry; @@ -625,63 +460,33 @@ void func_800AB0C0(s32 arg0, u16 arg1) { currentEntry->timer = arg1; } -/** - * @brief Clear control flags and reset animation state for a battle entity. - * - * Clears CTRL_FLAG_40, CTRL_FLAG_80, and CTRL_FLAG_02 from the entity's - * controlFlags field, then calls func_800AE6C0 and func_800A59AC to - * reset animation state. - * - * @param idx Entity index (stride 0xD0 in D_800ED148). - */ -void func_800AB11C(s16 idx) { - BattleEntity *base = (BattleEntity *)&D_800ED148; - volatile s32 *flags = &base[idx].controlFlags; - *flags &= ~CTRL_FLAG_40; - *flags &= ~CTRL_FLAG_80; - *flags &= ~CTRL_FLAG_02; +void func_800AB11C(s16 arg0) { + D_800ED148.entities[arg0].controlFlags &= ~0x40; + D_800ED148.entities[arg0].controlFlags &= ~0x80; + D_800ED148.entities[arg0].controlFlags &= ~2; + func_800AE6C0(); - func_800A59AC(idx, 0, 0); + func_800A59AC(arg0, 0, 0); } INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB1AC); -/** - * @brief Allocate entry via func_8009B3D0 and store value at offset 8. - * - * Calls func_8009B3D0 with func_800AB1AC as callback, shifts result - * left by 4 (multiply by 16), adds D_800EE28C as base, then stores a0 - * as halfword at offset 8 of the computed entry. - * - * @param a0 Value to store as halfword. - */ void func_800AB208(u16 arg0) { TaskEntry* currentEntry = &D_800ED148.taskData[func_8009B3D0(func_800AB1AC)]; currentEntry->timer = arg0; } -/** - * @brief Find the first active entity (bit 0 set at offset 0x8C). - * - * Scans entities 3-6 in the D_800ED148 array (offset 0x270, stride 0xD0). - * Returns the index of the first entity whose word at offset 0x8C has bit 0 set. - * Returns 0xFF if no active entity is found. - * - * @return Entity index (3-6), or 0xFF if none active. - */ s32 func_800AB24C(void) { - s32 i = 3; - s32 base = (s32)&D_800ED148; - s32 entry = base + 0x270; - do { - if (!(*(s32 *)(entry + 0x8C) & 1)) { + s32 i; + + for(i = 3; i < 7; i++) { + if (!(D_800ED148.entities[i].controlFlags & 1)) { return i; } - i++; - entry += 0xD0; - } while (i < 7); - return 0xFF; + } + + return 255; } INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB28C); @@ -690,24 +495,16 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB300); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB36C); -/** - * @brief Set battle flag 0x5C2 and clear status bytes 0x12F9 and 0x12FD. - */ void func_800AB3C4(void) { - u8 *base = (u8 *)&D_800ED148; - base[0x5C2] = 1; - base[0x12F9] = 0; - base[0x12FD] = 0; + D_800ED148.unk5C2 = 1; + D_800ED148.unk12F9 = 0; + D_800ED148.unk12FD = 0; } -/** - * @brief Clear battle flag 0x5C2 and set status bytes 0x12F9 and 0x12FD. - */ void func_800AB3E0(void) { - u8 *base = (u8 *)&D_800ED148; - base[0x5C2] = 0; - base[0x12F9] = 1; - base[0x12FD] = 1; + D_800ED148.unk5C2 = 0; + D_800ED148.unk12F9 = 1; + D_800ED148.unk12FD = 1; } /** @@ -735,12 +532,6 @@ void func_800AB3FC(s32 a0, s32 a1, s32 a2) { func_8009AF3C(result, a2, 3, 0xF0, 0); } -/** - * @brief Call func_800AB3FC with a fixed duration of 0x1E. - * - * @param a0 First parameter passed through. - * @param a1 Second parameter passed through. - */ -void func_800AB488(s32 a0, s32 a1) { - func_800AB3FC(a0, a1, 0x1E); +void func_800AB488(s32 arg0, s32 arg1) { + func_800AB3FC(arg0, arg1, 30); } diff --git a/src/battle/bc_object8.c b/src/battle/bc_object8.c index 6907d772..5d79881f 100644 --- a/src/battle/bc_object8.c +++ b/src/battle/bc_object8.c @@ -16,7 +16,6 @@ extern u8 D_800EEEC0[]; extern u8 g_gameState[]; void func_800B3164(void); void func_800B2F3C(void); -extern u8 D_8007809A[]; extern u8 D_800EE45C[]; extern u8 D_800EEDD8[]; extern u8 D_800EEDE8[]; @@ -137,23 +136,19 @@ s32 func_800B1A78(void) { return 1; } -/** - * @brief Check battle conditions and trigger entity action sequence. - * - * Checks bit 1 of D_8007809A. If set, calls func_800B1A78 to validate. - * If valid, calls func_8009B79C(0x20, 0xFF) to test entity availability. - * If available, clears D_800EE45C and calls func_800B1A48 to start action. - */ void func_800B1ACC(void) { - if (!(*(u8 *)D_8007809A & 2)) { + if (!(D_8007809A & 2)) { return; } + if (func_800B1A78() == 0) { return; } - if (func_8009B79C(0x20, 0xFF) == 0) { + + if (func_8009B79C(32, 255) == 0) { return; } + D_800ED148.unk1314 = 0; func_800B1A48(); } @@ -270,20 +265,12 @@ void func_800B2038(void) { } } -/** - * @brief Check battle mode flag and conditionally trigger entity processing. - * - * Checks bit 3 of D_8007809A. If set, calls func_8009B79C(8, 0xFF) to test - * entity availability. If available, calls func_800B1B68 and returns. - * Otherwise (bit not set or entity unavailable), clears D_800EE465. - */ void func_800B2084(void) { - if (*(u8 *)D_8007809A & 8) { - if (func_8009B79C(8, 0xFF) != 0) { - func_800B1B68(); - return; - } + if (D_8007809A & 8 && func_8009B79C(8, 255) != 0) { + func_800B1B68(); + return; } + D_800ED148.unk131D = 0; } @@ -307,34 +294,30 @@ s32 func_800B20D8(void) { return 1; } -/** - * @brief Check if conditions are met to initiate an auto-battle action. - * - * Checks a chain of conditions: whether func_800AE788 returns the sentinel - * 0xFF, whether func_800B20D8 indicates busy, bit 2 of D_8007809A flags, - * whether g_battleConfig matches 0x13D, and whether entity slot 0x40 is - * available via func_8009B79C. If all pass, sets D_800EE45C to 1 and - * calls func_800B1A48 to start the action. - * - * @return 1 if action was initiated, 0 otherwise. - */ s32 func_800B2128(void) { - if (func_800AE788() == 0xFF) { + if (func_800AE788() == 255) { return 0; } + if (func_800B20D8() != 0) { return 0; } - if (*(u8 *)D_8007809A & 4) { - if (*(u16 *)&g_battleConfig != 0x13D) { - if (func_8009B79C(0x40, 0xFF) != 0) { - D_800ED148.unk1314 = 1; - func_800B1A48(); - return 1; - } - } + + if (!(D_8007809A & 4)) { + return 0; } - return 0; + + if (g_battleConfig.battleSceneId == 0x13D) { + return 0; + } + + if (func_8009B79C(64, 255) == 0) { + return 0; + } + + D_800ED148.unk1314 = 1; + func_800B1A48(); + return 1; } /** From 6e1576e84c8f1f68d88cc8f5ae2410dc734c2084 Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Sun, 6 Sep 2026 00:59:13 +0200 Subject: [PATCH 02/12] added func_800AB008, removed fake functions --- config/symbols.battle.txt | 4 ---- src/battle/bc_object5.c | 15 ++++++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/config/symbols.battle.txt b/config/symbols.battle.txt index 194c6d2a..edb7df88 100644 --- a/config/symbols.battle.txt +++ b/config/symbols.battle.txt @@ -248,16 +248,12 @@ func_800AAF48 = 0x800AAF48; // type:func func_800AAF70 = 0x800AAF70; // type:func func_800AAFB8 = 0x800AAFB8; // type:func func_800AB008 = 0x800AB008; // type:func -func_800AB02C = 0x800AB02C; // type:func func_800AB054 = 0x800AB054; // type:func -func_800AB07C = 0x800AB07C; // type:func func_800AB0C0 = 0x800AB0C0; // type:func func_800AB11C = 0x800AB11C; // type:func func_800AB1AC = 0x800AB1AC; // type:func func_800AB208 = 0x800AB208; // type:func func_800AB28C = 0x800AB28C; // type:func -func_800AB300 = 0x800AB300; // type:func -func_800AB36C = 0x800AB36C; // type:func func_800AB3FC = 0x800AB3FC; // type:func func_800AB488 = 0x800AB488; // type:func func_800AB4A8 = 0x800AB4A8; // type:func diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index 2fa39462..7eb42d6a 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -444,14 +444,15 @@ void func_800AAFB8(s32 arg0) { data->done = 1; } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB008); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB02C); +void func_800AB008(s32 arg0) { + s32 idx; + + TaskEntry* task = &D_800ED148.taskData[func_8009B3D0(&func_800AAFB8)]; + task->unk4 = func_800B0398(arg0); +} INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB054); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB07C); - void func_800AB0C0(s32 arg0, u16 arg1) { TaskEntry* currentEntry; @@ -491,10 +492,6 @@ s32 func_800AB24C(void) { INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB28C); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB300); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB36C); - void func_800AB3C4(void) { D_800ED148.unk5C2 = 1; D_800ED148.unk12F9 = 0; From 514bfb3571fdd384f338e8feb4c693b02aef6327 Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Sun, 6 Sep 2026 02:09:35 +0200 Subject: [PATCH 03/12] added func_800AAA50 and func_800A9490 --- include/battle.h | 7 ++++++- src/battle/bc_object5.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/battle.h b/include/battle.h index 7871532c..061dc52f 100644 --- a/include/battle.h +++ b/include/battle.h @@ -766,7 +766,12 @@ typedef struct { /** @brief Complete battle character/GF state block. */ typedef struct { /* 0x000 */ BattleCharData chars[3]; /* 3 party members × 0x1D0 */ - /* 0x570 */ u8 pad570[0x610 - 0x570]; + /* 0x570 */ u8 pad570[4]; + /* 0x574 */ u16 unk574[3]; + /* 0x57A */ u16 unk57A[3]; + /* 0x580 */ u16 unk580[16]; + /* 0x5A0 */ u16 unk5A0[16]; + /* 0x5C0 */ u8 pad5C0[0x610 - 0x5C0]; /* 0x610 */ BattleGfEntry gfEntries[1]; /* hp sub-array (stride 12, 16 entries) */ /* 0x61C */ u8 pad61C[0x620 - 0x61C]; /* 0x620 */ BattleLevelEntry levelEntries[16]; /* 16 × 12 bytes */ diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index 7eb42d6a..fdafe22e 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -138,7 +138,19 @@ s32 func_800A9370(s32 arg0) { } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9490); +void func_800A9490(void) { + s32 i; + + for (i = 0; i < 3; i++) { + g_battleChars.unk57A[i] = 0; + g_battleChars.unk574[i] = 0; + } + + for (i = 0; i < 16; i++) { + g_battleChars.unk5A0[i] = 0; + g_battleChars.unk580[i] = 0; + } +} INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A94E0); @@ -406,7 +418,23 @@ s32 func_800AAA10(s32 arg0) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAA50); +s32 func_800AAA50(s32 arg0, s32 arg1, s32 bit) { + if (arg1 == 0) { + s32 mask = (1 << bit); + if (arg0 & mask) { + return 1; + } + } + + if (arg1 == 3) { + s32 mask = (1 << bit); + if (!(arg0 & mask)) { + return 1; + } + } + + return 0; +} INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAA9C); From 0d02b9af0d3a6544707021b7d1dd720ffe2fa1d6 Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Sun, 6 Sep 2026 04:45:01 +0200 Subject: [PATCH 04/12] added bc_object5 functions --- include/battle.h | 13 ++- src/battle/bc_object5.c | 202 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 197 insertions(+), 18 deletions(-) diff --git a/include/battle.h b/include/battle.h index 061dc52f..80ac0017 100644 --- a/include/battle.h +++ b/include/battle.h @@ -748,7 +748,7 @@ typedef struct { /** @brief GF battle entry (12 bytes, used for GF HP in battle). */ typedef struct { - u8 pad0[8]; + u8 unk0[8]; u16 maxHp; /* max HP cap (used to restore hp on revive) */ s16 hp; /* current HP */ } BattleGfEntry; @@ -763,6 +763,11 @@ typedef struct { u8 pad5[7]; } BattleLevelEntry; +typedef struct{ + u8 unk0; + u8 unk1; +} splitStruct; + /** @brief Complete battle character/GF state block. */ typedef struct { /* 0x000 */ BattleCharData chars[3]; /* 3 party members × 0x1D0 */ @@ -771,14 +776,14 @@ typedef struct { /* 0x57A */ u16 unk57A[3]; /* 0x580 */ u16 unk580[16]; /* 0x5A0 */ u16 unk5A0[16]; - /* 0x5C0 */ u8 pad5C0[0x610 - 0x5C0]; + /* 0x5C0 */ u16 unk5C0[16]; + /* 0x5E0 */ splitStruct unk5E0[24]; /* 0x610 */ BattleGfEntry gfEntries[1]; /* hp sub-array (stride 12, 16 entries) */ /* 0x61C */ u8 pad61C[0x620 - 0x61C]; /* 0x620 */ BattleLevelEntry levelEntries[16]; /* 16 × 12 bytes */ } BattleCharState;/* 0x6E0 */ - /** * @brief Battle/scene context struct pointed to by D_800D244C. * @@ -1276,6 +1281,8 @@ extern u16 D_800EEBC2; extern s32 D_800EEBC4; extern u8 D_800EEBC8; extern u8 D_800EEBD0; +extern s32 D_800EEBD8; +extern s32 D_800EEBDC; /* ---------------------------------------------------------------- * * Battle-overlay function prototypes (battle internals). diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index fdafe22e..e57de8c9 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -5,10 +5,8 @@ #include "battle/bc_object6.h" #include "battle/bc_object7.h" -extern u8 D_800EEBE0[]; // an array containing 1s and 0s +extern u8 D_800EEBE0[]; // an array containing 1s and 0s (size 7) extern u8 D_800E3CEC[]; -void func_800AB054(void); -void func_800AB1AC(void); s32 func_800B0398(s32); void func_800A59AC(s32, s32, s32); s32 func_800A97A4(s32); @@ -31,7 +29,30 @@ void func_800A8E90(BattleCharData* arg0, s32 arg1) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8EFC); +s32 func_800A8EFC(BattleCharData* arg0) { + s32 bit; + s32 i; + s32 val; + + for (val = 0, bit = 1, i = 0; i < 16; bit *= 2, i++) { + if (g_gameState.mainData.limitBreaks.quistisLimits & bit) { + arg0->testSlots[val].unk0 = i; + arg0->testSlots[val].unk2 = D_80078E00.array44FC[i].unk4; + arg0->testSlots[val].unk3 = D_80078E00.array44FC[i].unk5; + arg0->testSlots[val].unk4 = 0; + arg0->testSlots[val].unk1 = 1; + arg0->testSlots[val].unk4 &= 0xEF; + + if (D_80078E00.array44FC[i].unk6 & 0x80) { + arg0->testSlots[val].unk4 |= 1; + } + + val++; + } + } + + return val; +} void func_800A8F98(BattleCharData* arg0, s32 arg1, s32 arg2) { arg0->testSlots[arg2].unk0 = arg1; @@ -152,7 +173,26 @@ void func_800A9490(void) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A94E0); +void func_800A94E0(void) { + s32 i; + + func_800A9490(); + + for (i = 0; i < 16; i++) { + g_battleChars.unk5C0[i] = 0; + } + + for (i = 0; i < 24; i++) { + g_battleChars.unk5E0[i].unk1 = 0; + g_battleChars.unk5E0[i].unk0 = 0; + } + + + + for (i = 0; i < 8; i++) { + g_battleChars.gfEntries[0].unk0[i] = 255; + } +} s32 func_800A9568(s32 arg0) { s32 i; @@ -263,9 +303,51 @@ void func_800A9970(s32 arg0) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A99E8); +void func_800A99E8(s32 arg0) { + s32 i; + + for (i = 0; i < 7; i++) { + if (arg0 < 16) { + if ((D_800ED148.entities[i].status >> arg0) & 1) { + D_800EEBE0[i] = 1; + } + + else { + D_800EEBE0[i] = 0; + } + } + + else { + s32 result = 1 << (arg0 - 16); + if (D_800ED148.entities[i].flags & result) { + D_800EEBE0[i] = 1; + } + + else { + D_800EEBE0[i] = 0; + } + } + } +} -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9A6C); +void func_800A9A6C(s32 arg0) { + switch (arg0) { + case 0xC8: + D_800EEBD8 = 0; + D_800EEBDC = 3; + break; + + case 0xC9: + D_800EEBD8 = 3; + D_800EEBDC = 7; + break; + + default: + D_800EEBD8 = 0; + D_800EEBDC = 7; + break; + } +} INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9AC0); @@ -297,7 +379,21 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA034); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA368); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA44C); +u16 func_800AA44C(s32 arg0) { + s32 bit; + + if (func_800AA368(201) == 1) { + bit = arg0; + } + + else { + do { + bit = func_800A97A4(4) + 3; + } while (bit == arg0 || (D_800ED148.entities[bit].status & 1)); + } + + return (1 << bit); +} s32 func_800AA4E0(void) { return 32775; @@ -359,15 +455,35 @@ s32 func_800AA768(s32 arg0, s32 arg1) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA7B4); +s32 func_800AA7B4(s32 unused, s32 arg1) { + s32 i; + + for (i = 0; i < 3; i++) { + if ((D_800ED148.entities[i].controlFlags & 1) && !(D_800ED148.entities[i].status & 1)) { + if (arg1 == 202) { + if (!(D_800ED148.entities[i].controlFlags & 0x100)) { + return i; + } + } + + else { + if ((D_800ED148.entities[i].controlFlags & 0x100)) { + return i; + } + } + } + } + + return 255; +} s32 func_800AA840(s32 arg0, s32 arg1) { if (arg0 == 0) { - return func_800AA7B4(arg1) != 255; + return func_800AA7B4(arg1, arg1) != 255; } if (arg0 == 3) { - return func_800AA7B4(arg1) == 255; + return func_800AA7B4(arg1, arg1) == 255; } } @@ -446,9 +562,41 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AACD0); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAD5C); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAE10); +s32 func_800AAE10(s32 arg0, s32 arg1, s32 arg2) { + if (D_800ED148.entities[arg2].controlFlags & 1) { + if ((D_800ED148.entities[arg2].status & 1)) { + return arg1; + } + + arg1 += func_800AAA9C(0, arg0, &D_800ED148.entities[arg2].entityData); + } + + + return arg1; +} -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAE98); +s32 func_800AAE98(s32 arg0) { + s32 check1; + s32 check2; + s32 i; + + + check1 = 0; + check2 = 0; + + for (i = 0; i < 3; i++) { + if ((D_800ED148.entities[i].controlFlags & 1) && !(D_800ED148.entities[i].status & 1)) { + check2++; + } + } + + for (i = 0; i < 3; i++) { + check1 = func_800AAE10(arg0, check1, i); + + } + + return check1 == check2; +} void func_800AAF48(s32 arg0) { BattleEntityData* temp_v0; @@ -479,7 +627,16 @@ void func_800AB008(s32 arg0) { task->unk4 = func_800B0398(arg0); } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB054); +void func_800AB054(s32 arg0) { + TaskEntry* td = &D_800ED148.taskData[arg0]; + + if (td->timer == 0) { + func_8009AF3C(td->unk4, 0x1E, 3, 0xF0, 0); + td->done = 1; + } + + td->timer--; +} void func_800AB0C0(s32 arg0, u16 arg1) { TaskEntry* currentEntry; @@ -498,7 +655,22 @@ void func_800AB11C(s16 arg0) { func_800A59AC(arg0, 0, 0); } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB1AC); +void func_800AB1AC(s32 arg0) { + TaskEntry* temp_a0; + + temp_a0 = &D_800ED148.taskData[arg0]; + if (temp_a0->timer == 0) { + D_800ED148.unk5C2 = 1; + D_800ED148.unk12FD = 0; + temp_a0->done = 1; + return; + } + + + D_800ED148.unk5C2 = 0; + D_800ED148.unk12FD = 1; + temp_a0->timer--; +} void func_800AB208(u16 arg0) { TaskEntry* currentEntry = &D_800ED148.taskData[func_8009B3D0(func_800AB1AC)]; From 76c280ec43c9b654109a861e47213f2fcb63bafe Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Mon, 7 Sep 2026 03:06:50 +0200 Subject: [PATCH 05/12] fixed problems with rodata, extended bc_object4 size and reduced bc_object5 size. Added functions --- config/ff8.yaml | 5 +- config/symbols.battle.txt | 1 - include/battle.h | 4 +- src/battle/bc_object4.c | 436 ++++++++++++++++++++++++++++++- src/battle/bc_object5.c | 534 +++++++++----------------------------- 5 files changed, 561 insertions(+), 419 deletions(-) diff --git a/config/ff8.yaml b/config/ff8.yaml index 55e30062..40de66e4 100644 --- a/config/ff8.yaml +++ b/config/ff8.yaml @@ -62,8 +62,7 @@ binaries: - [0x130, .rodata, bc_object2] - [0xA84, .rodata, bc_object3] - [0xECC, .rodata, bc_object4] - - [0xF48, pad] - - [0xF4C, .rodata, bc_object5] + - [0xF78, .rodata, bc_object5] - [0xF90, .rodata, bc_object6] - [0x14C0, .rodata, bc_object7] - [0x14E8, .rodata, bc_object8] @@ -83,7 +82,7 @@ binaries: - [0x3AC4, c, bc_object2] - [0x98E0, c, bc_object3] - [0xE184, c, bc_object4] - - [0x10B7C, c, bc_object5] + - [0x1268C, c, bc_object5] - [0x134A8, c, bc_object6] - [0x17358, c, bc_object7] - [0x19624, c, bc_object8] diff --git a/config/symbols.battle.txt b/config/symbols.battle.txt index edb7df88..3135520e 100644 --- a/config/symbols.battle.txt +++ b/config/symbols.battle.txt @@ -241,7 +241,6 @@ func_800AA980 = 0x800AA980; // type:func func_800AAB50 = 0x800AAB50; // type:func func_800AABEC = 0x800AABEC; // type:func func_800AACD0 = 0x800AACD0; // type:func -func_800AAD5C = 0x800AAD5C; // type:func func_800AAE10 = 0x800AAE10; // type:func func_800AAE98 = 0x800AAE98; // type:func func_800AAF48 = 0x800AAF48; // type:func diff --git a/include/battle.h b/include/battle.h index 80ac0017..3b73fb03 100644 --- a/include/battle.h +++ b/include/battle.h @@ -523,7 +523,9 @@ typedef struct { /* 0x12F7 */ u8 unk12F7; /* 0x12F8 */ u8 unk12F8; /* 0x12F9 */ u8 unk12F9; - /* 0x12FA */ u8 pad12FA[3]; + /* 0x12FA */ u8 pad12FA; + /* 0x12FB */ u8 unk12FB; // used as index for entities (max 7) + /* 0x12FC */ u8 unk12FC; // used as index for unkD54,unkD14 (max 8) /* 0x12FD */ u8 unk12FD; /* 0x12FE */ u8 unk12FE; /* 0x12FF */ u8 unk12FF; diff --git a/src/battle/bc_object4.c b/src/battle/bc_object4.c index fa011560..43a176af 100644 --- a/src/battle/bc_object4.c +++ b/src/battle/bc_object4.c @@ -1436,4 +1436,438 @@ s32 func_800A8AFC(s32 arg0) { func_800A8A48(ptr, 2, 0, 0); return 2; -} \ No newline at end of file +} + +// bc_object5 + +#include "battle/bc_object5.h" +#include "battle/bc_object6.h" +#include "battle/bc_object7.h" + +extern u8 D_800EEBE0[]; // an array containing 1s and 0s (size 7) +extern u8 D_800E3CEC[]; +s32 func_800B0398(s32); +void func_800A59AC(s32, s32, s32); +s32 func_800A97A4(s32); + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A8B7C); + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A8CA4); + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A8D7C); + +void func_800A8E90(BattleCharData* arg0, s32 arg1) { + arg0->testSlots[0].unk0 = arg1; + arg0->testSlots[0].unk2 = D_80078E00.array4484[arg1].unk5; + arg0->testSlots[0].unk3 = D_80078E00.array4484[arg1].unk6; + arg0->testSlots[0].unk4 = 0; + arg0->testSlots[0].unk1 = 1; + + if (D_80078E00.array4484[arg1].unk7 & 0x80) { + arg0->testSlots[0].unk4 |= 1; + } +} + +s32 func_800A8EFC(BattleCharData* arg0) { + s32 bit; + s32 i; + s32 val; + + for (val = 0, bit = 1, i = 0; i < 16; bit *= 2, i++) { + if (g_gameState.mainData.limitBreaks.quistisLimits & bit) { + arg0->testSlots[val].unk0 = i; + arg0->testSlots[val].unk2 = D_80078E00.array44FC[i].unk4; + arg0->testSlots[val].unk3 = D_80078E00.array44FC[i].unk5; + arg0->testSlots[val].unk4 = 0; + arg0->testSlots[val].unk1 = 1; + arg0->testSlots[val].unk4 &= 0xEF; + + if (D_80078E00.array44FC[i].unk6 & 0x80) { + arg0->testSlots[val].unk4 |= 1; + } + + val++; + } + } + + return val; +} + +void func_800A8F98(BattleCharData* arg0, s32 arg1, s32 arg2) { + arg0->testSlots[arg2].unk0 = arg1; + arg0->testSlots[arg2].unk2 = D_80078E00.rows8[arg1].unk2; + arg0->testSlots[arg2].unk3 = D_80078E00.rows8[arg1].unk3; + arg0->testSlots[arg2].unk4 = 0; + arg0->testSlots[arg2].unk1 = 1; +} + +s32 func_800A8FDC(BattleCharData* arg0) { + s32 current; + s32 val = 0; + + if (!(g_gameState.mainData.partyLockFlag & 0x10)) { + val++; + func_800A8F98(arg0, 0, 0); + } + + current = val; + if (g_gameState.mainData.partyLockFlag & 0x20) { + val++; + func_800A8F98(arg0, 1, current); + } + + return val; +} + +s32 func_800A9064(BattleCharData* arg0) { + arg0->testSlots[0].unk0 = 65; + arg0->testSlots[1].unk0 = 67; + arg0->testSlots[2].unk0 = 66; + + return 3; +} + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9084); + +u8 func_800A9240(s32 arg0) { + s32 i; + + for (i = 0; i < 198; i++) { + if (g_gameState.mainData.itemSlots[i].id == arg0) { + return g_gameState.mainData.itemSlots[i].count; + } + } + + return 0; +} + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9284); + +s32 func_800A9370(s32 arg0) { + BattleCharData* temp_a0; + s32 i; + + temp_a0 = &g_battleChars.chars[arg0]; + + for (i = 0; i < 16; i++) { + temp_a0->testSlots[i].unk4 = 0; + temp_a0->testSlots[i].unk1 = 0; + temp_a0->testSlots[i].unk3 = 0; + temp_a0->testSlots[i].unk2 = 0; + temp_a0->testSlots[i].unk0 = 0; + temp_a0->testSlots[i].unk4 |= 0x10; + } + + switch (temp_a0->characterId) { + case 0: + case 1: + return 0; + + case 2: + return func_800A9284(temp_a0); + + case 3: + return func_800A8EFC(temp_a0); + + case 4: + return func_800A8FDC(temp_a0); + + case 5: + return func_800A9064(temp_a0); + + case 6: + func_800A8E90(temp_a0, 0); + return 1; + + case 7: + func_800A8E90(temp_a0, 1); + return 1; + + case 8: + func_800A8E90(temp_a0, 2); + return 1; + + case 9: + func_800A8E90(temp_a0, 3); + return 1; + + case 10: + func_800A8E90(temp_a0, 4); + return 1; + } +} + + +void func_800A9490(void) { + s32 i; + + for (i = 0; i < 3; i++) { + g_battleChars.unk57A[i] = 0; + g_battleChars.unk574[i] = 0; + } + + for (i = 0; i < 16; i++) { + g_battleChars.unk5A0[i] = 0; + g_battleChars.unk580[i] = 0; + } +} + +void func_800A94E0(void) { + s32 i; + + func_800A9490(); + + for (i = 0; i < 16; i++) { + g_battleChars.unk5C0[i] = 0; + } + + for (i = 0; i < 24; i++) { + g_battleChars.unk5E0[i].unk1 = 0; + g_battleChars.unk5E0[i].unk0 = 0; + } + + + + for (i = 0; i < 8; i++) { + g_battleChars.gfEntries[0].unk0[i] = 255; + } +} + +s32 func_800A9568(s32 arg0) { + s32 i; + + for (i = 0; i < 32; i++) { + if (D_800EE9E8.animSlots[i].id == arg0) { + return 1; + } + } + + return 0; +} + +void func_800A95A0(s32 arg0, s32 arg1) { + func_800B0754(arg0, 4, arg1, func_800A97FC(arg0)); + func_800AF4BC(arg1, 1); + + if (func_800AE390(arg1) == 0) { + func_800AE3D4(arg1); + } +} + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A960C); + +s32 func_800A972C(s32 arg0) { + return func_800B0F9C(D_80078E00.entriesA0[arg0].unk7) | func_800B0F7C(D_80078E00.entriesA0[arg0].unk7); +} + +u8* func_800A9784(u16 arg0, s32 arg1) { + if (arg0 == 65535) { + return D_800E3CEC; + } + + return arg0 + arg1; // weird +} + +s32 func_800A97A4(s32 arg0) { + return func_8009B15C() % arg0; +} + +void func_800A97D4(void) { + s32 i; + + for (i = 0; i < 8; i++) { + D_800ED148.unk1298[i] = 0; + } +} + +u16 func_800A97FC(s32 arg0) { + return (1 << arg0); +} + +u16 func_800A980C(void) { + s32 idx; + + if (func_800AE730() == 255) { + return 0; + } + + do { + idx = func_800A97A4(3); + } while (D_800ED148.entities[idx].status & 1); + + return (1 << idx); +} + +u16 func_800A9888(void) { + s32 idx; + + if (func_800AE788() == 255) { + return 8; + } + + do { + idx = func_800A97A4(4) + 3; + } while (D_800ED148.entities[idx].status & 1); + + return (1 << idx); +} + +u16 func_800A9904(s32 arg0) { + return (1 << D_800ED148.entities[arg0].unk98); +} + +void func_800A9938(void) { + s32 i; + + for (i = 0; i < 7; i++) { + D_800EEBE0[i] = ~D_800EEBE0[i] & 1; + } +} + +void func_800A9970(s32 arg0) { + s32 i; + + for (i = 0; i < 7; i++) { + if (D_800ED148.entities[i].controlFlags & 0x100) { + D_800EEBE0[i] = 1; + } + + else { + D_800EEBE0[i] = 0; + } + } + + if (arg0 == 200) { + func_800A9938(); + } +} + +void func_800A99E8(s32 arg0) { + s32 i; + + for (i = 0; i < 7; i++) { + if (arg0 < 16) { + if ((D_800ED148.entities[i].status >> arg0) & 1) { + D_800EEBE0[i] = 1; + } + + else { + D_800EEBE0[i] = 0; + } + } + + else { + s32 result = 1 << (arg0 - 16); + if (D_800ED148.entities[i].flags & result) { + D_800EEBE0[i] = 1; + } + + else { + D_800EEBE0[i] = 0; + } + } + } +} + +void func_800A9A6C(s32 arg0) { + switch (arg0) { + case 0xC8: + D_800EEBD8 = 0; + D_800EEBDC = 3; + break; + + case 0xC9: + D_800EEBD8 = 3; + D_800EEBDC = 7; + break; + + default: + D_800EEBD8 = 0; + D_800EEBDC = 7; + break; + } +} + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9AC0); + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9C68); + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9E08); + +void func_800A9F98(void) { + s32 i; + + for (i = 0; i < 7; i++) { + if (!(D_800ED148.entities[i].controlFlags & 1)) { + D_800EEBE0[i] = 0; + } + } +} + +void func_800A9FDC(void) { + s32 i; + + for (i = 0; i < 7; i++) { + if (!(D_800ED148.entities[i].controlFlags & 1) || (D_800ED148.entities[i].status & 1)) { + D_800EEBE0[i] = 0; + } + } +} + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800AA034); + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800AA368); + +u16 func_800AA44C(s32 arg0) { + s32 bit; + + if (func_800AA368(201) == 1) { + bit = arg0; + } + + else { + do { + bit = func_800A97A4(4) + 3; + } while (bit == arg0 || (D_800ED148.entities[bit].status & 1)); + } + + return (1 << bit); +} + +s32 func_800AA4E0(void) { + return 32775; +} + +s32 func_800AA4E8(void) { + return 33016; +} + +s32 func_800AA4F0(void) { + return 33023; +} + +s32 func_800AA4F8(s32 arg0) { + s32 i; + + for (i = 0; i < 7; i++) { + if (D_800ED148.entities[i].linkedIdx == arg0) { + return i; + } + } + + return 255; +} + +s32 func_800AA530(s32 arg0) { + s32 i; + + for (i = 0; i < 7; i++) { + if (!(D_800ED148.entities[i].status & 1) && ((D_800ED148.entities[i].linkedIdx == arg0))) { + return i; + } + } + + return 255; +} + +INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800AA57C); \ No newline at end of file diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index e57de8c9..a1df86ff 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -11,430 +11,48 @@ s32 func_800B0398(s32); void func_800A59AC(s32, s32, s32); s32 func_800A97A4(s32); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8B7C); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8CA4); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A8D7C); - -void func_800A8E90(BattleCharData* arg0, s32 arg1) { - arg0->testSlots[0].unk0 = arg1; - arg0->testSlots[0].unk2 = D_80078E00.array4484[arg1].unk5; - arg0->testSlots[0].unk3 = D_80078E00.array4484[arg1].unk6; - arg0->testSlots[0].unk4 = 0; - arg0->testSlots[0].unk1 = 1; - - if (D_80078E00.array4484[arg1].unk7 & 0x80) { - arg0->testSlots[0].unk4 |= 1; - } -} - -s32 func_800A8EFC(BattleCharData* arg0) { - s32 bit; - s32 i; - s32 val; - - for (val = 0, bit = 1, i = 0; i < 16; bit *= 2, i++) { - if (g_gameState.mainData.limitBreaks.quistisLimits & bit) { - arg0->testSlots[val].unk0 = i; - arg0->testSlots[val].unk2 = D_80078E00.array44FC[i].unk4; - arg0->testSlots[val].unk3 = D_80078E00.array44FC[i].unk5; - arg0->testSlots[val].unk4 = 0; - arg0->testSlots[val].unk1 = 1; - arg0->testSlots[val].unk4 &= 0xEF; - - if (D_80078E00.array44FC[i].unk6 & 0x80) { - arg0->testSlots[val].unk4 |= 1; +s32 func_800AA68C(s32 arg0, u32 arg1, u32 arg2) { + switch (arg1) { + case 0: + if (arg0 == arg2) { + return 1; } + break; - val++; - } - } - - return val; -} - -void func_800A8F98(BattleCharData* arg0, s32 arg1, s32 arg2) { - arg0->testSlots[arg2].unk0 = arg1; - arg0->testSlots[arg2].unk2 = D_80078E00.rows8[arg1].unk2; - arg0->testSlots[arg2].unk3 = D_80078E00.rows8[arg1].unk3; - arg0->testSlots[arg2].unk4 = 0; - arg0->testSlots[arg2].unk1 = 1; -} - -s32 func_800A8FDC(BattleCharData* arg0) { - s32 current; - s32 val = 0; - - if (!(g_gameState.mainData.partyLockFlag & 0x10)) { - val++; - func_800A8F98(arg0, 0, 0); - } - - current = val; - if (g_gameState.mainData.partyLockFlag & 0x20) { - val++; - func_800A8F98(arg0, 1, current); - } - - return val; -} - -s32 func_800A9064(BattleCharData* arg0) { - arg0->testSlots[0].unk0 = 65; - arg0->testSlots[1].unk0 = 67; - arg0->testSlots[2].unk0 = 66; - - return 3; -} - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9084); - -u8 func_800A9240(s32 arg0) { - s32 i; - - for (i = 0; i < 198; i++) { - if (g_gameState.mainData.itemSlots[i].id == arg0) { - return g_gameState.mainData.itemSlots[i].count; - } - } - - return 0; -} - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9284); - -s32 func_800A9370(s32 arg0) { - BattleCharData* temp_a0; - s32 i; - - temp_a0 = &g_battleChars.chars[arg0]; - - for (i = 0; i < 16; i++) { - temp_a0->testSlots[i].unk4 = 0; - temp_a0->testSlots[i].unk1 = 0; - temp_a0->testSlots[i].unk3 = 0; - temp_a0->testSlots[i].unk2 = 0; - temp_a0->testSlots[i].unk0 = 0; - temp_a0->testSlots[i].unk4 |= 0x10; - } - - switch (temp_a0->characterId) { - case 0: case 1: - return 0; + if (arg0 < arg2) { + return 1; + } + break; case 2: - return func_800A9284(temp_a0); + if (arg2 < arg0) { + return 1; + } + break; case 3: - return func_800A8EFC(temp_a0); + if (arg0 != arg2) { + return 1; + } + break; case 4: - return func_800A8FDC(temp_a0); - - case 5: - return func_800A9064(temp_a0); - - case 6: - func_800A8E90(temp_a0, 0); - return 1; - - case 7: - func_800A8E90(temp_a0, 1); - return 1; - - case 8: - func_800A8E90(temp_a0, 2); - return 1; - - case 9: - func_800A8E90(temp_a0, 3); - return 1; - - case 10: - func_800A8E90(temp_a0, 4); - return 1; - } -} - - -void func_800A9490(void) { - s32 i; - - for (i = 0; i < 3; i++) { - g_battleChars.unk57A[i] = 0; - g_battleChars.unk574[i] = 0; - } - - for (i = 0; i < 16; i++) { - g_battleChars.unk5A0[i] = 0; - g_battleChars.unk580[i] = 0; - } -} - -void func_800A94E0(void) { - s32 i; - - func_800A9490(); - - for (i = 0; i < 16; i++) { - g_battleChars.unk5C0[i] = 0; - } - - for (i = 0; i < 24; i++) { - g_battleChars.unk5E0[i].unk1 = 0; - g_battleChars.unk5E0[i].unk0 = 0; - } - - - - for (i = 0; i < 8; i++) { - g_battleChars.gfEntries[0].unk0[i] = 255; - } -} - -s32 func_800A9568(s32 arg0) { - s32 i; - - for (i = 0; i < 32; i++) { - if (D_800EE9E8.animSlots[i].id == arg0) { - return 1; - } - } - - return 0; -} - -void func_800A95A0(s32 arg0, s32 arg1) { - func_800B0754(arg0, 4, arg1, func_800A97FC(arg0)); - func_800AF4BC(arg1, 1); - - if (func_800AE390(arg1) == 0) { - func_800AE3D4(arg1); - } -} - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A960C); - -s32 func_800A972C(s32 arg0) { - return func_800B0F9C(D_80078E00.entriesA0[arg0].unk7) | func_800B0F7C(D_80078E00.entriesA0[arg0].unk7); -} - -u8* func_800A9784(u16 arg0, s32 arg1) { - if (arg0 == 65535) { - return D_800E3CEC; - } - - return arg0 + arg1; // weird -} - -s32 func_800A97A4(s32 arg0) { - return func_8009B15C() % arg0; -} - -void func_800A97D4(void) { - s32 i; - - for (i = 0; i < 8; i++) { - D_800ED148.unk1298[i] = 0; - } -} - -u16 func_800A97FC(s32 arg0) { - return (1 << arg0); -} - -u16 func_800A980C(void) { - s32 idx; - - if (func_800AE730() == 255) { - return 0; - } - - do { - idx = func_800A97A4(3); - } while (D_800ED148.entities[idx].status & 1); - - return (1 << idx); -} - -u16 func_800A9888(void) { - s32 idx; - - if (func_800AE788() == 255) { - return 8; - } - - do { - idx = func_800A97A4(4) + 3; - } while (D_800ED148.entities[idx].status & 1); - - return (1 << idx); -} - -u16 func_800A9904(s32 arg0) { - return (1 << D_800ED148.entities[arg0].unk98); -} - -void func_800A9938(void) { - s32 i; - - for (i = 0; i < 7; i++) { - D_800EEBE0[i] = ~D_800EEBE0[i] & 1; - } -} - -void func_800A9970(s32 arg0) { - s32 i; - - for (i = 0; i < 7; i++) { - if (D_800ED148.entities[i].controlFlags & 0x100) { - D_800EEBE0[i] = 1; - } - - else { - D_800EEBE0[i] = 0; - } - } - - if (arg0 == 200) { - func_800A9938(); - } -} - -void func_800A99E8(s32 arg0) { - s32 i; - - for (i = 0; i < 7; i++) { - if (arg0 < 16) { - if ((D_800ED148.entities[i].status >> arg0) & 1) { - D_800EEBE0[i] = 1; - } - - else { - D_800EEBE0[i] = 0; + if (arg2 >= arg0) { + return 1; } - } - - else { - s32 result = 1 << (arg0 - 16); - if (D_800ED148.entities[i].flags & result) { - D_800EEBE0[i] = 1; - } + break; - else { - D_800EEBE0[i] = 0; + case 5: + if (arg0 >= arg2) { + return 1; } - } - } -} - -void func_800A9A6C(s32 arg0) { - switch (arg0) { - case 0xC8: - D_800EEBD8 = 0; - D_800EEBDC = 3; - break; - - case 0xC9: - D_800EEBD8 = 3; - D_800EEBDC = 7; - break; - - default: - D_800EEBD8 = 0; - D_800EEBDC = 7; break; } -} - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9AC0); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9C68); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800A9E08); - -void func_800A9F98(void) { - s32 i; - - for (i = 0; i < 7; i++) { - if (!(D_800ED148.entities[i].controlFlags & 1)) { - D_800EEBE0[i] = 0; - } - } -} - -void func_800A9FDC(void) { - s32 i; - - for (i = 0; i < 7; i++) { - if (!(D_800ED148.entities[i].controlFlags & 1) || (D_800ED148.entities[i].status & 1)) { - D_800EEBE0[i] = 0; - } - } -} - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA034); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA368); - -u16 func_800AA44C(s32 arg0) { - s32 bit; - - if (func_800AA368(201) == 1) { - bit = arg0; - } - - else { - do { - bit = func_800A97A4(4) + 3; - } while (bit == arg0 || (D_800ED148.entities[bit].status & 1)); - } - - return (1 << bit); -} - -s32 func_800AA4E0(void) { - return 32775; -} - -s32 func_800AA4E8(void) { - return 33016; -} - -s32 func_800AA4F0(void) { - return 33023; -} -s32 func_800AA4F8(s32 arg0) { - s32 i; - - for (i = 0; i < 7; i++) { - if (D_800ED148.entities[i].linkedIdx == arg0) { - return i; - } - } - - return 255; -} - -s32 func_800AA530(s32 arg0) { - s32 i; - - for (i = 0; i < 7; i++) { - if (!(D_800ED148.entities[i].status & 1) && ((D_800ED148.entities[i].linkedIdx == arg0))) { - return i; - } - } - - return 255; + return 0; } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA57C); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA68C); - s32 func_800AA71C(s32 arg0, s32 arg1) { if (arg0 == 0) { return func_800AA4F8(arg1) != 255; @@ -556,11 +174,75 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAA9C); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAB50); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AABEC); +s32 func_800AABEC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + if (arg4 != 0 && arg1 == 0) { + if (D_800ED148.entities[arg3].controlFlags & 1) { + BattleEntity* var_a2 = (BattleEntity*)&D_800ED148.entities[arg3].entityData; + arg2 += func_800AAA9C(arg0, arg1, var_a2); + } + + return arg2; + } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AACD0); + else if (D_800ED148.entities[arg3].controlFlags & 1) { + if (!(D_800ED148.entities[arg3].status & 1)) { + BattleEntity* var_a2 = (BattleEntity*)&D_800ED148.entities[arg3].entityData; + if (arg4 == 0) { + arg2 += func_800AAB50(arg0, arg1, var_a2); + } + + else { + arg2 += func_800AAA9C(arg0, arg1, var_a2); + } + } + } + + return arg2; +} -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAD5C); +s32 func_800AACD0(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + s32 result; + s32 var_s2; + s32 i; + + var_s2 = 0; + if (arg3 == 0) { + var_s2 = arg1; + } + + result = 0; + switch(arg0) { + case 0xC8: + for (i = 0; i < 3; i++) { + result = func_800AABEC(var_s2, arg2, result, i, arg3); + } + break; + + case 0xC9: + for (i = 3; i < 7; i++) { + result = func_800AABEC(var_s2, arg2, result, i, arg3); + } + break; + + default: + for (i = 0; i < 7; i++) { + if (D_800ED148.entities[i].linkedIdx == arg0) { + result = func_800AABEC(var_s2, arg2, result, i, arg3); + } + } + break; + } + + if (arg3 == 0) { + return result != 0; + } + + if (result == 0) { + return arg1 != 0; + } + + return arg1 == 0; +} s32 func_800AAE10(s32 arg0, s32 arg1, s32 arg2) { if (D_800ED148.entities[arg2].controlFlags & 1) { @@ -579,7 +261,6 @@ s32 func_800AAE98(s32 arg0) { s32 check1; s32 check2; s32 i; - check1 = 0; check2 = 0; @@ -690,7 +371,34 @@ s32 func_800AB24C(void) { return 255; } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AB28C); +void func_800AB28C(void) { + u8 entityIdx; + u8 idx; + + idx = D_800ED148.unk12FC; + entityIdx = D_800ED148.unk12FB; + func_800A7FD0(entityIdx, D_800ED148.unkD54[idx], D_800ED148.unkD14[idx]); + func_800A8430(entityIdx); + + + + if (func_8009A514(D_800ED148.unkCE0, 7 - idx) != 0) { + D_800ED148.entities[entityIdx].controlFlags |= 2; + } + + if (func_8009A514(D_800ED148.unkCE2, 7 - idx) != 0) { + D_800ED148.entities[entityIdx].controlFlags |= 0x40; + } + + if (func_8009A514(D_800ED148.unkCE1, 7 - idx) != 0) { + D_800ED148.entities[entityIdx].controlFlags |= 0x80; + } + + func_800A890C(entityIdx); + func_800A8794(); + func_800D8A94(); + func_8009A528(entityIdx, idx); +} void func_800AB3C4(void) { D_800ED148.unk5C2 = 1; @@ -731,4 +439,4 @@ void func_800AB3FC(s32 a0, s32 a1, s32 a2) { void func_800AB488(s32 arg0, s32 arg1) { func_800AB3FC(arg0, arg1, 30); -} +} \ No newline at end of file From 4f47193ecf149620fc67ab618ebf44c5c1e7ba1b Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Mon, 7 Sep 2026 23:00:05 +0200 Subject: [PATCH 06/12] added functions and general fixes --- include/battle.h | 2 +- src/battle/bc_object2.c | 38 ++++++++++++----------- src/battle/bc_object3.c | 21 ++++++++----- src/battle/bc_object4.c | 68 ++++++++++++++++++++++++++++++++++++----- src/battle/bc_object5.c | 49 +++++++++++++++++++++++++---- 5 files changed, 140 insertions(+), 38 deletions(-) diff --git a/include/battle.h b/include/battle.h index 3b73fb03..b46fdf7f 100644 --- a/include/battle.h +++ b/include/battle.h @@ -1267,7 +1267,7 @@ extern u8 D_800E3CBC[]; extern u8 D_800E3CE8; extern BattleSystem D_800ED148; extern BattleCmdBuf D_800EE4C0; -extern BattleAnimTable D_800EE9E8; +extern BattleAnimTable D_800EE9E8; // (D_800EE9B3 = D_800EE9E8-3) extern u8 D_800EEBA8[]; extern u8 D_800EEBB0; extern u8 D_800EEBB8; diff --git a/src/battle/bc_object2.c b/src/battle/bc_object2.c index 943ff1cf..d2cc1388 100644 --- a/src/battle/bc_object2.c +++ b/src/battle/bc_object2.c @@ -336,8 +336,8 @@ s32 func_8009C300(s32 arg0, s32 arg1) { u8 func_8009C390(s32 arg0, s32 arg1, s32 arg2) { s32 temp_s3; - s32 var_s0; - s32 var_s1; + s32 i; + s32 mask; s32 var_s2; s32 var_s5; s32 sp20; @@ -358,18 +358,22 @@ u8 func_8009C390(s32 arg0, s32 arg1, s32 arg2) { temp_s3 = func_8009C300(arg1, 1); } - var_s1 = 1; - for (var_s0 = 0; var_s0 < 7; var_s0++, var_s1 *= 2) { - if (D_800EEBC2 & var_s1) { - var_s2 += func_8009C104(arg0, arg1, var_s0, var_s1, 0, var_s5, temp_s3, D_800EEBBA); + mask = 1; + for (i = 0; i < 7; i++) { + if (D_800EEBC2 & mask) { + var_s2 += func_8009C104(arg0, arg1, i, mask, 0, var_s5, temp_s3, D_800EEBBA); } + + mask <<= 1; } - var_s1 = 1; - for (var_s0 = 8; var_s0 < 40; var_s0++, var_s1 *= 2) { - if (D_800EEBC4 & var_s1) { - var_s2 += func_8009C104(arg0, arg1, var_s0, var_s1, 1, var_s5, temp_s3, D_800EEBBA); + mask = 1; + for (i = 8; i < 40; i++) { + if (D_800EEBC4 & mask) { + var_s2 += func_8009C104(arg0, arg1, i, mask, 1, var_s5, temp_s3, D_800EEBBA); } + + mask <<= 1; } func_8009BF70(sp20, &D_800ED148.entities[arg1].flags); @@ -1022,7 +1026,7 @@ void func_8009DD2C(s32 arg0, s32 arg1, u16 sp10, s32 arg3) { s32 i; BattleEntity* entities; BattleEntity* entity; - s32 var_s0; + s32 mask; s32 var_s2; @@ -1031,22 +1035,22 @@ void func_8009DD2C(s32 arg0, s32 arg1, u16 sp10, s32 arg3) { func_8009B878(arg0, &sp10, &D_800EEBC4, 0); var_s2 = 0; - var_s0 = 1; + mask = 1; for(i = 0; i < 7; i++) { - if ((sp10 & var_s0) && (entities[arg0].status & var_s0)) { + if ((sp10 & mask) && (entities[arg0].status & mask)) { var_s2 = 1; } - var_s0 *= 2; + mask <<= 1; } - var_s0 = 1; + mask = 1; for(i = 8; i < 40; i++) { - if ((arg3 & var_s0) && (D_800ED148.entities[arg0].flags & var_s0) && (func_800B0668(arg0, var_s0) == 0)) { + if ((arg3 & mask) && (D_800ED148.entities[arg0].flags & mask) && (func_800B0668(arg0, mask) == 0)) { var_s2 = 1; } - var_s0 *= 2; + mask <<= 1; } diff --git a/src/battle/bc_object3.c b/src/battle/bc_object3.c index 6e21e9b5..f75b997f 100644 --- a/src/battle/bc_object3.c +++ b/src/battle/bc_object3.c @@ -225,18 +225,24 @@ s32 func_800A20AC(s32 arg0) { s32 result; temp_a0 = &g_battleChars.chars[arg0]; - result = 0; - for (mask = 1, i = 0; i < 8; i++, mask *= 2) { + + mask = 1; + for (i = 0; i < 8; i++) { if (temp_a0->displayStatus & mask) { result += D_80078E00.unk4CDC[i]; } + + mask <<= 1; } - for (mask = 1, i = 0; i < 24; i++, mask *= 2) { + mask = 1; + for (i = 0; i < 24; i++) { if (temp_a0->unk188 & mask) { result += D_80078E00.unk4CE4[i]; } + + mask <<= 1; } return result; @@ -647,7 +653,7 @@ u16 func_800A2E48(BattleEntityData* arg0, s32 index) { return arg0->unk150[entity[index+1].slot8.byteView.unkA + result]; } -s32 func_800A2EB8(s32 arg0, s32 arg1) { +s32 func_800A2EB8(s32 arg0, s32 flags) { s32 var_a0; s32 mask; s32 i; @@ -658,12 +664,13 @@ s32 func_800A2EB8(s32 arg0, s32 arg1) { } do { - for (i = 0, mask = 1; i < var_a0; i++) { - mask *= 2; + mask = 1; + for (i = 0; i < var_a0; i++) { + mask <<= 1; } var_a0--; - } while (!(mask & arg1)); + } while (!(mask & flags)); return var_a0 + 1; } diff --git a/src/battle/bc_object4.c b/src/battle/bc_object4.c index 43a176af..c63d44ae 100644 --- a/src/battle/bc_object4.c +++ b/src/battle/bc_object4.c @@ -1452,7 +1452,25 @@ s32 func_800A97A4(s32); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A8B7C); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A8CA4); +void func_800A8CA4(s32 characterId, s32 targetId) { + BattleAnimSubEntry* var_s0; + s32 i; + + if (D_800ED148.entities[targetId].controlFlags & 1) { + for (i = 0; i < 4; i++) { + var_s0 = &D_800EE9E8.subEntries[targetId - 3]; + if (var_s0->array0[i].unk0 < 64) { + if (hasJunctionedAbility(characterId, var_s0->array0[i].unk0) != 0) { + var_s0->array0[i].unk1 |= 4; + } + + else { + var_s0->array0[i].unk1 &= 0xFB; + } + } + } + } +} INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A8D7C); @@ -1473,7 +1491,10 @@ s32 func_800A8EFC(BattleCharData* arg0) { s32 i; s32 val; - for (val = 0, bit = 1, i = 0; i < 16; bit *= 2, i++) { + val = 0; + bit = 1; + + for (i = 0; i < 16; i++) { if (g_gameState.mainData.limitBreaks.quistisLimits & bit) { arg0->testSlots[val].unk0 = i; arg0->testSlots[val].unk2 = D_80078E00.array44FC[i].unk4; @@ -1488,6 +1509,8 @@ s32 func_800A8EFC(BattleCharData* arg0) { val++; } + + bit <<= 1; } return val; @@ -1529,7 +1552,7 @@ s32 func_800A9064(BattleCharData* arg0) { INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9084); -u8 func_800A9240(s32 arg0) { +s32 func_800A9240(s32 arg0) { s32 i; for (i = 0; i < 198; i++) { @@ -1597,7 +1620,6 @@ s32 func_800A9370(s32 arg0) { } } - void func_800A9490(void) { s32 i; @@ -1771,12 +1793,12 @@ void func_800A99E8(s32 arg0) { void func_800A9A6C(s32 arg0) { switch (arg0) { - case 0xC8: + case 200: D_800EEBD8 = 0; D_800EEBDC = 3; break; - case 0xC9: + case 201: D_800EEBD8 = 3; D_800EEBDC = 7; break; @@ -1816,7 +1838,39 @@ void func_800A9FDC(void) { INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800AA034); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800AA368); +s32 func_800AA368(s32 arg0) { + s32 i; + s32 val; + + val = 0; + switch(arg0) { + case 200: + for (i = 0; i < 3; i++) { + if (!(D_800ED148.entities[i].status & 1)) { + val++; + } + } + break; + + case 201: + for (i = 3; i < 7; i++) { + if (!(D_800ED148.entities[i].status & 1)) { + val++; + } + } + break; + + default: + for (i = 0; i < 7; i++) { + if ((D_800ED148.entities[i].linkedIdx == arg0) && !(D_800ED148.entities[i].status & 1)) { + val++; + } + } + break; + } + + return val; +} u16 func_800AA44C(s32 arg0) { s32 bit; diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index a1df86ff..0eb63d8c 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -105,7 +105,23 @@ s32 func_800AA840(s32 arg0, s32 arg1) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AA88C); +s32 func_800AA88C(s32 arg0, s32 arg1) { + if (arg0 == 0) { + if ((D_800ED148.entities[arg1].controlFlags & 1) && !(D_800ED148.entities[arg1].status & 1)) { + return 1; + } + + return 0; + } + + if (arg0 == 3) { + if ((D_800ED148.entities[arg1].controlFlags & 1) && !(D_800ED148.entities[arg1].status & 1)) { + return 0; + } + + return 1; + } +} s32 func_800AA930(s32 arg0) { drawSlot* var_v1; @@ -170,14 +186,35 @@ s32 func_800AAA50(s32 arg0, s32 arg1, s32 bit) { return 0; } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAA9C); +s32 func_800AAA9C(s32 arg0, u32 arg1, BattleEntityData* arg2) { + if (arg1 < 16) { + if (arg0 == 0 && ((arg2->unk80 >> arg1) & 1)) { + return 1; + } + + if (arg0 == 3 && !((arg2->unk80 >> arg1) & 1)) { + return 1; + } + } + + else if (arg0 == 0 && (arg2->unk8 & (1 << (arg1 - 16)))) { + return 1; + } + + else if (arg0 == 3 && !(arg2->unk8 & (1 << (arg1 - 16)))) { + return 1; + } + + + return 0; +} INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAB50); s32 func_800AABEC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { if (arg4 != 0 && arg1 == 0) { if (D_800ED148.entities[arg3].controlFlags & 1) { - BattleEntity* var_a2 = (BattleEntity*)&D_800ED148.entities[arg3].entityData; + BattleEntityData* var_a2 = (BattleEntityData*)&D_800ED148.entities[arg3].entityData; arg2 += func_800AAA9C(arg0, arg1, var_a2); } @@ -186,7 +223,7 @@ s32 func_800AABEC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { else if (D_800ED148.entities[arg3].controlFlags & 1) { if (!(D_800ED148.entities[arg3].status & 1)) { - BattleEntity* var_a2 = (BattleEntity*)&D_800ED148.entities[arg3].entityData; + BattleEntityData* var_a2 = (BattleEntityData*)&D_800ED148.entities[arg3].entityData; if (arg4 == 0) { arg2 += func_800AAB50(arg0, arg1, var_a2); } @@ -212,13 +249,13 @@ s32 func_800AACD0(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { result = 0; switch(arg0) { - case 0xC8: + case 200: for (i = 0; i < 3; i++) { result = func_800AABEC(var_s2, arg2, result, i, arg3); } break; - case 0xC9: + case 201: for (i = 3; i < 7; i++) { result = func_800AABEC(var_s2, arg2, result, i, arg3); } From f217efd344c347a65a64942b95420165d4712283 Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Fri, 11 Sep 2026 20:35:59 +0200 Subject: [PATCH 07/12] added functions + fixed prototypes --- include/battle.h | 13 +- src/battle/bc_object1.c | 3 +- src/battle/bc_object4.c | 343 ++++++++++++++++++++++++++++++++++++++-- src/battle/bc_object5.c | 1 - src/battle/bc_object8.c | 2 + 5 files changed, 343 insertions(+), 19 deletions(-) diff --git a/include/battle.h b/include/battle.h index 07a1c1a7..5875d3cd 100644 --- a/include/battle.h +++ b/include/battle.h @@ -728,7 +728,7 @@ typedef struct { /* 0x17C */ s32 xpToNext; /**< XP needed to reach next level. */ /* 0x180 */ u32 unk180; /* 0x184 */ u32 unk184; - /* 0x188 */ s32 unk188; /**< Status/ability mask checked for bit 0x60000. */ + /* 0x188 */ u32 unk188; /**< Status/ability mask checked for bit 0x60000. */ /* 0x18C */ s32 abilityFlags; /* 0x190 */ s32 statusFlags; /* 0x194 */ u16 elemResistances[8];/**< Element resistance values (8 × s16). */ @@ -1094,8 +1094,13 @@ typedef struct { /* 0x00D8 */ u8 pad00D8[0x00DC - 0x00D8]; /* 0x00DC */ s32 unk4C0CArg; /**< resolveKernelPtr arg paired with unk4C0C[]. */ /* 0x00E0 */ u8 pad00E0[0x00E8 - 0x00E0]; - /* 0x00E8 */ structE8 unkE8[36]; - /* 0x0208 */ u8 pad0208[0x0220 - 0x0208]; + /* 0x00E8 */ structE8 unkE8[7]; + /* 0x0120 */ u8 pad00F0[0x0139 - 0x0120]; + /* 0x0139 */ u8 unk0139; + /* 0x013A */ u8 unk013A; + /* 0x013B */ u8 pad013B[0x015A - 0x013B]; + /* 0x015A */ u8 unk015A; + /* 0x015B */ u8 pad015B[0x0220 - 0x015B]; /* 0x0220 */ BattleSpellRow spells[1]; /**< 60-byte stride (size unknown, index past). */ /* 0x025C */ u8 pad025C[0x0F78 - 0x025C]; /* 0x0F78 */ BattleSceneRow rows132[1]; /**< 132-byte stride (size unknown, index past). */ @@ -1285,6 +1290,7 @@ extern u8 D_800EEBC8; extern u8 D_800EEBD0; extern s32 D_800EEBD8; extern s32 D_800EEBDC; +extern u8 D_800EEBE0[7]; /* ---------------------------------------------------------------- * * Battle-overlay function prototypes (battle internals). @@ -1331,7 +1337,6 @@ void func_800D0608(void); /* bc_object17: overlay VSync handler (RENDER_OVERLAY) void func_8002A2C4(u8 *, s32); s32 func_80037ADC(void); -u16 func_800A97FC(s32 arg0); /* ---------------------------------------------------------------- * * Records the effect overlays share with battle.bin diff --git a/src/battle/bc_object1.c b/src/battle/bc_object1.c index 614cd9a9..1516f7fb 100644 --- a/src/battle/bc_object1.c +++ b/src/battle/bc_object1.c @@ -915,8 +915,7 @@ void func_8009B0F8(s32 a0) { * @param entry Caller-supplied context pointer / value. * @return Pointer to the command buffer, or NULL if the queue is full. */ - - // some functions want arg1 to be s32, probably forgot to include the prototype + SoundCmd* func_8009B134(s32 arg0, s32 arg1, void* unused) { return func_800B8564(arg0, arg1); } diff --git a/src/battle/bc_object4.c b/src/battle/bc_object4.c index c63d44ae..578a70d2 100644 --- a/src/battle/bc_object4.c +++ b/src/battle/bc_object4.c @@ -1131,8 +1131,8 @@ void func_800A7FD0(s32 arg0, s32 arg1, s32 arg2) { temp_s3 = *D_800ED148.entities[arg0].entityData; - D_800EE9E8.subEntries[arg0 - 3].unk10 = 0; temp_s1 = (BattleEntityData*)&D_800ED148.entities[arg0].entityData; + D_800EE9E8.subEntries[arg0 - 3].unk10 = 0; temp_s1->unkBC = func_800A7154(arg1); temp_s1->unk7C = 17; if (temp_s3->immunityFlags & 0x10) { @@ -1444,13 +1444,37 @@ s32 func_800A8AFC(s32 arg0) { #include "battle/bc_object6.h" #include "battle/bc_object7.h" -extern u8 D_800EEBE0[]; // an array containing 1s and 0s (size 7) extern u8 D_800E3CEC[]; s32 func_800B0398(s32); void func_800A59AC(s32, s32, s32); -s32 func_800A97A4(s32); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A8B7C); +s32 func_800A8B7C(s32 arg0) { + BattleCharData* temp_s0; + + temp_s0 = &g_battleChars.chars[arg0]; + func_800A8A48(temp_s0, 2, 0, 1); + + switch (temp_s0->unk188 & 0x60000) { + case 0: + return 0; + + case 0x60000: + func_800A8A48(temp_s0, 0, 0x23, 1); + func_800A8A48(temp_s0, 1, 0x24, 1); + func_800A8A48(temp_s0, 2, 0x25, 1); + return 3; + + case 0x20000: + func_800A8A48(temp_s0, 0, 0x23, 1); + func_800A8A48(temp_s0, 1, 0x24, 1); + return 2; + + case 0x40000: + func_800A8A48(temp_s0, 0, 0x23, 1); + func_800A8A48(temp_s0, 1, 0x25, 1); + return 2; + } +} void func_800A8CA4(s32 characterId, s32 targetId) { BattleAnimSubEntry* var_s0; @@ -1472,7 +1496,40 @@ void func_800A8CA4(s32 characterId, s32 targetId) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A8D7C); +void func_800A8D7C(s32 arg0, s32 arg1) { + BattleCharData* temp_s0; + + temp_s0 = &g_battleChars.chars[arg0]; + temp_s0->pad0[0] = 10; + temp_s0->pad0[1] = D_80078E00.unk0139; + temp_s0->pad0[2] = D_80078E00.unk013A; + temp_s0->pad0[3] = 0; + if (arg1 < 64) { + temp_s0->pad0[4] = 9; + temp_s0->pad0[5] = D_80078E00.spells[arg1].unk5; + temp_s0->pad0[6] = D_80078E00.spells[arg1].magicId; + temp_s0->pad0[7] = 0; + + if (D_80078E00.spells[arg1].unk7 & 0x80) { + temp_s0->pad0[7] = 1; + + if (D_80078E00.spells[arg1].unk7 & 0x80) { + temp_s0->pad0[3] |= 1; + } + } + + if (func_800A89B8(arg0, arg1) != 0) { + temp_s0->pad0[3] |= 2; + } + } + + else { + temp_s0->pad0[4] = 9; + temp_s0->pad0[5] = 0; + temp_s0->pad0[6] = 0; + temp_s0->pad0[7] = 2; + } +} void func_800A8E90(BattleCharData* arg0, s32 arg1) { arg0->testSlots[0].unk0 = arg1; @@ -1564,7 +1621,40 @@ s32 func_800A9240(s32 arg0) { return 0; } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9284); +s32 func_800A9284(BattleCharData* arg0) { + s32 i; + u16 mask; + s32 val; + s32 temp_a0; + s32 var_s1; + + val = 0; + mask = 1; + var_s1 = 101; + + for (i = 0; i < 8; i++) { + temp_a0 = func_800A9240(var_s1); + if ((g_gameState.mainData.limitBreaks.irvineLimits & mask) || (temp_a0 != 0)) { + arg0->testSlots[val].unk0 = var_s1; + arg0->testSlots[val].unk2 = 0x80; + arg0->testSlots[val].unk3 = D_80078E00.unk015A; + arg0->testSlots[val].unk4 = 0; + arg0->testSlots[val].unk1 = temp_a0; + arg0->testSlots[val].unk4 &= 0xEF; + + if (temp_a0 == 0) { + arg0->testSlots[val].unk4 |= 2; + } + + val++; + } + + var_s1++; + mask <<= 1; + } + + return val; +} s32 func_800A9370(s32 arg0) { BattleCharData* temp_a0; @@ -1676,7 +1766,49 @@ void func_800A95A0(s32 arg0, s32 arg1) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A960C); +void func_800A960C(s32 arg0) { + s32 result; + + if (D_800ED148.entities[arg0].status & 0x200) { + result = D_800ED148.entities[arg0].unk2C - D_800ED148.entities[arg0].unk28; + if (result <= 200) { + return; + } + + if (result > 1000) { + if (func_800A9568(3) != 0) { + func_800A95A0(arg0, 3); + } + + else if (func_800A9568(1) != 0) { + func_800A95A0(arg0, 1); + } + + else if (func_800A9568(2) != 0) { + func_800A95A0(arg0, 2); + } + + else if (func_800A9568(4) != 0) { + func_800A95A0(arg0, 4); + } + + else if (func_800A9568(5) != 0) { + func_800A95A0(arg0, 5); + } + + else if (func_800A9568(9) != 0) { + func_800A95A0(arg0, 9); + } + } + + else { + if (func_800A9568(1) != 0) { + func_800A95A0(arg0, 1); + } + } + } +} + s32 func_800A972C(s32 arg0) { return func_800B0F9C(D_80078E00.entriesA0[arg0].unk7) | func_800B0F7C(D_80078E00.entriesA0[arg0].unk7); @@ -1702,8 +1834,8 @@ void func_800A97D4(void) { } } -u16 func_800A97FC(s32 arg0) { - return (1 << arg0); +s32 func_800A97FC(s32 arg0) { + return (u16)(1 << arg0); // functions in this folder break with u16 return prototype } u16 func_800A980C(void) { @@ -1812,9 +1944,87 @@ void func_800A9A6C(s32 arg0) { INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9AC0); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9C68); +void func_800A9C68(s32 arg0, s32 arg1) { + s32 i; + u16 val; + s32 idx; + + func_800A9A6C(arg1); + + if (arg0 < 229) { + val = 0; + idx = arg0 - 221; + for (i = D_800EEBD8; i < D_800EEBDC; i++) { + if (!(D_800ED148.entities[i].status & 1)) { + if (val < D_800ED148.entities[i].unk54[idx]) { + val = D_800ED148.entities[i].unk54[idx]; + } + } + } + } + + else { + val = 65535; + idx = arg0 - 229; + for (i = D_800EEBD8; i < D_800EEBDC; i++) { + if (!(D_800ED148.entities[i].status & 1)) { + if (D_800ED148.entities[i].unk54[idx] < val) { + val = D_800ED148.entities[i].unk54[idx]; + } + } + } + } + -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9E08); + for (i = 0; i < 7; i++) { + if (val == D_800ED148.entities[i].unk54[idx]) { + D_800EEBE0[i] = 1; + } + + else { + D_800EEBE0[i] = 0; + } + } +} + +void func_800A9E08(s32 arg0, s32 arg1) { + s32 i; + s32 val; + + func_800A9A6C(arg1); + + if (arg0 == 203) { + val = 0; + for (i = D_800EEBD8; i < D_800EEBDC; i++) { + if (!(D_800ED148.entities[i].status & 1)) { + if (val < D_800ED148.entities[i].unk28) { + val = D_800ED148.entities[i].unk28; + } + } + } + } + + else { + val = 0x7FFFFFFF; + for (i = D_800EEBD8; i < D_800EEBDC; i++) { + if (!(D_800ED148.entities[i].status & 1)) { + if ((D_800ED148.entities[i].unk28 < val) && (D_800ED148.entities[i].unk28 != 0)) { + val = D_800ED148.entities[i].unk28; + } + } + } + } + + for (i = 0; i < 7; i++) { + if (val == D_800ED148.entities[i].unk28) { + D_800EEBE0[i]= 1; + } + + else { + D_800EEBE0[i] = 0; + } + } +} void func_800A9F98(void) { s32 i; @@ -1836,7 +2046,116 @@ void func_800A9FDC(void) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800AA034); +u16 func_800AA034(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + s32 i; + s32 result; + s32 var_s0; + + var_s0 = 0; + + switch (arg3) { + case 200: case 201: + func_800A9970(arg3); + break; + + case 0: + var_s0 = 1; + /* fallthrough */ + case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: + case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: + case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: + case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39: + case 40: case 41: case 42: + case 46: case 47: + func_800A99E8(arg3); + break; + + case 205: case 206: case 207: case 208: case 209: case 210: case 211: case 212: + case 213: case 214: case 215: case 216: case 217: case 218: case 219: case 220: + func_800A9AC0(arg3, arg1); + break; + + case 221: case 222: case 223: case 224: case 225: case 226: case 227: case 228: + case 229: case 230: case 231: case 232: case 233: case 234: case 235: case 236: + func_800A9C68(arg3, arg1); + break; + + case 203: case 204: + func_800A9E08(arg3, arg1); + break; + + default: + break; + } + + if (arg2 == 3) { + func_800A9938(); + } + + if (var_s0 == 0) { + func_800A9FDC(); + } + + else { + func_800A9F98(); + } + + if (arg0 == 0) { + switch (arg1) { + case 200: + do { + i = func_800A97A4(3); + } while (D_800EEBE0[i] == 0); + result = func_800A97FC(i); + break; + + case 201: + do { + i = func_800A97A4(4) + 3; + } while (D_800EEBE0[i] == 0); + result = func_800A97FC(i); + break; + + default: + do { + i = func_800A97A4(7); + } while ((D_800EEBE0[i] == 0) || D_800ED148.entities[i].linkedIdx != arg1); + result = func_800A97FC(i); + break; + } + } + + else { + result = 32768; + switch (arg1) { + case 200: + for (i = 0; i < 3; i++) { + if (D_800EEBE0[i] != 0) { + result |= func_800A97FC(i); + } + } + break; + + case 201: + for (i = 3; i < 7; i++) { + if (D_800EEBE0[i] != 0) { + result |= func_800A97FC(i); + } + } + break; + + default: + for (i = 0; i < 7; i++) { + if ((D_800ED148.entities[i].linkedIdx == arg1) && (D_800EEBE0[i] != 0)) { + result |= func_800A97FC(i); + } + } + break; + } + } + + return result; +} s32 func_800AA368(s32 arg0) { s32 i; diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index 0eb63d8c..7b84dd70 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -5,7 +5,6 @@ #include "battle/bc_object6.h" #include "battle/bc_object7.h" -extern u8 D_800EEBE0[]; // an array containing 1s and 0s (size 7) extern u8 D_800E3CEC[]; s32 func_800B0398(s32); void func_800A59AC(s32, s32, s32); diff --git a/src/battle/bc_object8.c b/src/battle/bc_object8.c index 240d5025..a5378920 100644 --- a/src/battle/bc_object8.c +++ b/src/battle/bc_object8.c @@ -34,6 +34,8 @@ s32 func_800AA4E0(void); extern u8 D_800EEED0[]; extern u8 D_800EEED4[]; +u16 func_800A97FC(s32 arg0); + INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object8", func_800B1624); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object8", func_800B16C0); From 94139770c76f5beb701318745881a546cdc14bb1 Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Fri, 11 Sep 2026 23:54:01 +0200 Subject: [PATCH 08/12] added func_800AAB50, general cleanup --- src/battle/bc_object2.c | 44 +++++------------------------------------ src/battle/bc_object3.c | 26 +++++------------------- src/battle/bc_object4.c | 25 +++++++---------------- src/battle/bc_object5.c | 13 +++++++++++- 4 files changed, 29 insertions(+), 79 deletions(-) diff --git a/src/battle/bc_object2.c b/src/battle/bc_object2.c index d2cc1388..5690e6df 100644 --- a/src/battle/bc_object2.c +++ b/src/battle/bc_object2.c @@ -666,24 +666,7 @@ s32 func_8009CF18(void) { return func_8009B7BC(33) + 239; } -/** - * @brief Compute damage for a battle action based on type and route to dispatcher. - * - * - case 0/19: scale formula using attacker @c unkCD (squared), defense, - * power, and the @c func_8009CF18 modifier. Case 19 forces - * @c defense to 0 first. - * - case 1: if target's @c controlFlags bit 0x10000 is set, mark - * @c D_800EE4C0[6] (bit 2) and report 0; else scale @c unk28. - * - case 3: multiply attacker's @c unk2C by 5. - * - case 16: active party member's kill count (selected via the party - * slot at @c targetIdx) times power. If @c targetIdx >= 3, - * the damage is forced to 0. - * - * @param attackerIdx Battle entity index of the attacker (case 0/3 path). - * @param targetIdx Battle entity index of the target (case 1) or party slot (case 16). - * @param power Damage multiplier. - * @param type Action type, indexes the case dispatch. - */ + s32 func_8009CF38(s32 attackerIdx, s32 targetIdx, s32 power, u32 type) { s32 defense; s32 dmg; @@ -2109,17 +2092,8 @@ void func_8009FE14(s32 arg0) { break; case 7: - case 23: - case 24: - case 25: - case 26: - case 27: - case 29: - case 30: - case 31: - case 32: - case 33: - case 34: + case 23 ... 27: + case 29 ... 34: case 38: D_800EEBB9 = D_80078E00.array4020[D_800EE4C0.statusCode].unk8; D_800EEBBA = D_80078E00.array4020[D_800EE4C0.statusCode].unk9; @@ -2533,16 +2507,8 @@ void func_800A09D0(s32 arg0) { break; case 7: - case 23: - case 24: - case 25: - case 26: - case 27: - case 30: - case 31: - case 32: - case 33: - case 34: + case 23 ... 27: + case 30 ... 34: func_8009FCF4(D_80078E00.array4020[D_800EE4C0.statusCode].unk6); var_s3 = D_80078E00.array4020[D_800EE4C0.statusCode].unk5; D_800EE4C0.unk4 = D_80078E00.array4020[D_800EE4C0.statusCode].unk3; diff --git a/src/battle/bc_object3.c b/src/battle/bc_object3.c index f75b997f..b2df3d76 100644 --- a/src/battle/bc_object3.c +++ b/src/battle/bc_object3.c @@ -1142,11 +1142,8 @@ s32 func_800A30F8(s32 arg0, u8 arg1, u16 arg2, u8 arg3, u8 arg4, u16 arg5, u8 ar var_s2 = getGfSummonData(arg3); break; - case 17: - case 18: - case 20: - case 21: - case 22: + case 17 ... 18: + case 20 ... 22: var_s3 = D_80078E00.array4484[arg2].unk8; sp2E = D_80078E00.array4484[arg2].unk0; var_s2 = getJuncCategoryName(arg2); @@ -1277,16 +1274,8 @@ s32 func_800A30F8(s32 arg0, u8 arg1, u16 arg2, u8 arg3, u8 arg4, u16 arg5, u8 ar func_800A42DC(112, &arg1, &arg6, &sp2E, &arg2); break; - case 23: - case 24: - case 25: - case 26: - case 27: - case 30: - case 31: - case 32: - case 33: - case 34: + case 23 ... 27: + case 30 ... 34: arg2 = D_80078E00.unkE8[arg1].unk0; var_s3 = D_80078E00.array4020[arg2].unk7; sp2E = D_80078E00.array4020[arg2].unk0; @@ -2283,12 +2272,7 @@ void func_800A5C48(InternalStruct* arg0) { case 11: case 14: case 15: - case 17: - case 18: - case 19: - case 20: - case 21: - case 22: + case 17 ... 22: D_800E3CE8 = func_8009B2A4(D_800ED148.unkD64[1], &D_800ED148.unk1100[1], 11); var_s3 = 1; func_800A5AF4(p->unk2); diff --git a/src/battle/bc_object4.c b/src/battle/bc_object4.c index 578a70d2..24cc22ff 100644 --- a/src/battle/bc_object4.c +++ b/src/battle/bc_object4.c @@ -1069,13 +1069,7 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A7D8C); u8 func_800A7EE0(BattleEntityData* arg0, s32 arg1) { switch (arg1) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: + case 0 ... 6: return arg0->unk168[arg1]; case 8: @@ -2061,26 +2055,21 @@ u16 func_800AA034(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { case 0: var_s0 = 1; /* fallthrough */ - case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: - case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: - case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: - case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39: - case 40: case 41: case 42: - case 46: case 47: + case 1 ... 9: + case 16 ... 42: + case 46 ... 47: func_800A99E8(arg3); break; - case 205: case 206: case 207: case 208: case 209: case 210: case 211: case 212: - case 213: case 214: case 215: case 216: case 217: case 218: case 219: case 220: + case 205 ... 220: func_800A9AC0(arg3, arg1); break; - case 221: case 222: case 223: case 224: case 225: case 226: case 227: case 228: - case 229: case 230: case 231: case 232: case 233: case 234: case 235: case 236: + case 221 ... 236: func_800A9C68(arg3, arg1); break; - case 203: case 204: + case 203 ... 204: func_800A9E08(arg3, arg1); break; diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index 7b84dd70..06c9530b 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -208,7 +208,18 @@ s32 func_800AAA9C(s32 arg0, u32 arg1, BattleEntityData* arg2) { return 0; } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object5", func_800AAB50); +s32 func_800AAB50(s32 arg0, u32 arg1, BattleEntityData* arg2) { + switch (arg1) { + case 1 ... 9: + return func_800AA68C(arg2->unk18, arg0, (arg2->unk1C / 10) * arg1); + + case 10: + return func_800AA68C(arg2->unk18, arg0, arg2->unk1C >> 2); + + default: + return func_800AA68C(arg2->unk18, arg0, arg1); + } +} s32 func_800AABEC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { if (arg4 != 0 && arg1 == 0) { From 6170c495e1d0e9b443fd2901ce72437b12689fab Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Sat, 12 Sep 2026 00:21:36 +0200 Subject: [PATCH 09/12] added func_800A9AC0 --- include/battle.h | 2 +- src/battle/bc_object2.c | 8 ++++---- src/battle/bc_object4.c | 45 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/include/battle.h b/include/battle.h index 5875d3cd..d1dd989a 100644 --- a/include/battle.h +++ b/include/battle.h @@ -351,7 +351,7 @@ typedef struct { u8 unkC8[3]; u8 linkedIdx; u8 unkCC; - u8 unkCD; /* 0xCD: stat byte used in case-0 damage formula (squared). */ + u8 unkCD[1]; /* 0xCD: stat byte used in case-0 damage formula (squared). */ u8 unkCE; u8 unkCF; /* 0xCF: stat byte averaged with arg2 in func_8009DEF0 mode-7. */ } BattleEntity; /* 208 bytes */ diff --git a/src/battle/bc_object2.c b/src/battle/bc_object2.c index 5690e6df..beb2318b 100644 --- a/src/battle/bc_object2.c +++ b/src/battle/bc_object2.c @@ -349,7 +349,7 @@ u8 func_8009C390(s32 arg0, s32 arg1, s32 arg2) { sp20 = entities[arg1].flags; if (arg2 == 0) { - var_s5 = entities[arg0].unkCD; + var_s5 = entities[arg0].unkCD[0]; temp_s3 = func_8009C300(arg1, 0); } @@ -680,7 +680,7 @@ s32 func_8009CF38(s32 attackerIdx, s32 targetIdx, s32 power, u32 type) { defense = 0; case 0: mod = func_8009CF18(); - stat = D_800ED148.entities[attackerIdx].unkCD; + stat = D_800ED148.entities[attackerIdx].unkCD[0]; sq = stat * stat / 16 + stat; dmg = sq * (265 - defense) / 256 * power / 16 * mod / 256; break; @@ -766,9 +766,9 @@ s32 func_8009D228(s32 arg0, s32 arg1, s32 arg2) { result1 = func_8009C300(arg1, 0); result2 = func_8009CF18(); - var_v1 = D_800ED148.entities[arg0].unkCD * D_800ED148.entities[arg0].unkCD; + var_v1 = D_800ED148.entities[arg0].unkCD[0] * D_800ED148.entities[arg0].unkCD[0]; - var2 = ((var_v1 / 16) + D_800ED148.entities[arg0].unkCD) * (265 - result1); + var2 = ((var_v1 / 16) + D_800ED148.entities[arg0].unkCD[0]) * (265 - result1); var1 = (var2 / 256) * arg2; diff --git a/src/battle/bc_object4.c b/src/battle/bc_object4.c index 24cc22ff..9417bc80 100644 --- a/src/battle/bc_object4.c +++ b/src/battle/bc_object4.c @@ -1936,7 +1936,50 @@ void func_800A9A6C(s32 arg0) { } } -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9AC0); +void func_800A9AC0(s32 arg0, s32 arg1) { + s32 i; + s32 val; + s32 idx; + + func_800A9A6C(arg1); + + if (arg0 < 213) { + val = 0; + idx = arg0 - 0xCD; + for (i = D_800EEBD8; i < D_800EEBDC; i++) { + if (!(D_800ED148.entities[i].status & 1)) { + u8* cd = D_800ED148.entities[i].unkCD; + if (val < cd[idx]) { + val = cd[idx]; + } + } + } + } + + else { + val = 255; + idx = arg0 - 0xD5; + for (i = D_800EEBD8; i < D_800EEBDC; i++) { + if (!(D_800ED148.entities[i].status & 1)) { + u8* cd = D_800ED148.entities[i].unkCD; + if (cd[idx] < val){ + val = cd[idx]; + } + } + } + } + + for (i = 0; i < 7; i++) { + u8* cd = D_800ED148.entities[i].unkCD; + if (val == cd[idx]) { + D_800EEBE0[i] = 1; + } + + else { + D_800EEBE0[i] = 0; + } + } +} void func_800A9C68(s32 arg0, s32 arg1) { s32 i; From 4c95a3662b8db91242588c3aba881e3fb9f21a76 Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Sat, 12 Sep 2026 01:35:24 +0200 Subject: [PATCH 10/12] headers cleanup --- include/battle.h | 1 + include/battle/bc_object1.h | 2 +- include/battle/bc_object2.h | 4 +- include/battle/bc_object3.h | 2 +- include/battle/bc_object4.h | 93 +++++++++++++++++++++++++++++++++++-- include/battle/bc_object5.h | 82 ++++++++++++++++++++++++-------- src/battle/bc_object2.c | 1 + src/battle/bc_object3.c | 1 + src/battle/bc_object4.c | 10 ---- src/battle/bc_object5.c | 7 --- src/battle/bc_object6.c | 1 - src/menu/menusts/menusts.c | 2 +- 12 files changed, 160 insertions(+), 46 deletions(-) diff --git a/include/battle.h b/include/battle.h index d1dd989a..3159a370 100644 --- a/include/battle.h +++ b/include/battle.h @@ -1270,6 +1270,7 @@ extern u8 D_800E3CC5; extern u8 D_800E3CC6; extern u8 D_800E3CBC[]; extern u8 D_800E3CE8; +extern u8 D_800E3CEC[]; extern BattleSystem D_800ED148; extern BattleCmdBuf D_800EE4C0; extern BattleAnimTable D_800EE9E8; // (D_800EE9B3 = D_800EE9E8-3) diff --git a/include/battle/bc_object1.h b/include/battle/bc_object1.h index d20409b0..99227e01 100644 --- a/include/battle/bc_object1.h +++ b/include/battle/bc_object1.h @@ -142,4 +142,4 @@ void func_8009B924(s32, s32, s32); u16 func_8009BA5C(s32, u16); -#endif \ No newline at end of file +#endif /* BC_OBJECT1_H */ \ No newline at end of file diff --git a/include/battle/bc_object2.h b/include/battle/bc_object2.h index 86b3a181..956af422 100644 --- a/include/battle/bc_object2.h +++ b/include/battle/bc_object2.h @@ -1,8 +1,6 @@ #ifndef BC_OBJECT2_H #define BC_OBJECT2_H -#include "game.h" - #define BATTLE_ENTITY_FLAG_BIT_0 (1 << 0) /* 0x00000000 */ #define BATTLE_ENTITY_FLAG_BIT_10 (1 << 10) /* 0x00000400 */ @@ -195,4 +193,4 @@ void func_800A184C(s32 idx, u16 attr, s32 flags); void func_800A1888(s32 arg0); -#endif \ No newline at end of file +#endif /* BC_OBJECT2_H */ \ No newline at end of file diff --git a/include/battle/bc_object3.h b/include/battle/bc_object3.h index fe8b091c..f2e47ef2 100644 --- a/include/battle/bc_object3.h +++ b/include/battle/bc_object3.h @@ -170,4 +170,4 @@ void func_800A5C48(InternalStruct*); void func_800A5F24(s32, s32, s32, s32, u16); -#endif \ No newline at end of file +#endif /* BC_OBJECT3_H */ \ No newline at end of file diff --git a/include/battle/bc_object4.h b/include/battle/bc_object4.h index d32823c8..a643c742 100644 --- a/include/battle/bc_object4.h +++ b/include/battle/bc_object4.h @@ -1,5 +1,6 @@ -#ifndef BATTLE_BC_OBJECT4_H -#define BATTLE_BC_OBJECT4_H +#ifndef BC_OBJECT4_H +#define BC_OBJECT4_H + void func_800A6184(s32, s32, s32, u16); @@ -147,4 +148,90 @@ void func_800A8A48(BattleCharData*, s32, u8, s32); s32 func_800A8AFC(s32); -#endif /* BATTLE_BC_OBJECT4_H */ \ No newline at end of file +s32 func_800A8B7C(s32); + +void func_800A8CA4(s32, s32); + +void func_800A8D7C(s32, s32); + +void func_800A8E90(BattleCharData*, s32); + +s32 func_800A8EFC(BattleCharData*); + +void func_800A8F98(BattleCharData*, s32, s32); + +s32 func_800A8FDC(BattleCharData*); + +s32 func_800A9064(BattleCharData*); + +// func_800A9084 + +s32 func_800A9240(s32); + +s32 func_800A9284(BattleCharData*); + +s32 func_800A9370(s32); + +void func_800A9490(void); + +void func_800A94E0(void); + +s32 func_800A9568(s32); + +void func_800A95A0(s32, s32); + +void func_800A960C(s32); + +s32 func_800A972C(s32); + +u8* func_800A9784(u16, s32); + +s32 func_800A97A4(s32); + +void func_800A97D4(void); + +s32 func_800A97FC(s32); + +u16 func_800A980C(void); + +u16 func_800A9888(void); + +u16 func_800A9904(s32); + +void func_800A9938(void); + +void func_800A9970(s32); + +void func_800A99E8(s32); + +void func_800A9A6C(s32); + +void func_800A9AC0(s32, s32); + +void func_800A9C68(s32, s32); + +void func_800A9E08(s32, s32); + +void func_800A9F98(void); + +void func_800A9FDC(void); + +u16 func_800AA034(s32, s32, s32, s32); + +s32 func_800AA368(s32); + +u16 func_800AA44C(s32); + +s32 func_800AA4E0(void); + +s32 func_800AA4E8(void); + +s32 func_800AA4F0(void); + +s32 func_800AA4F8(s32); + +s32 func_800AA530(s32); + +// func_800AA57C + +#endif /* BC_OBJECT4_H */ \ No newline at end of file diff --git a/include/battle/bc_object5.h b/include/battle/bc_object5.h index 2b5da2c6..1b1b2adb 100644 --- a/include/battle/bc_object5.h +++ b/include/battle/bc_object5.h @@ -1,25 +1,69 @@ -/** - * @file bc_object5.h - * @brief Public symbols owned by bc_object5 — battle command/state queries. - * - * @note Two of this unit's public functions are deliberately absent. - * @c func_800A97FC is still declared in @c battle.h, where bc_object3 - * and bc_object8 pick it up; moving it here means giving those two - * units their own headers first. @c func_800A9784 is defined here - * taking a @c u16 offset but called from bc_object6 through an - * @c (s32, s32) view -- an inconsistent-ABI pair, so that prototype - * stays file-local to bc_object6 where the narrower parameter cannot - * change its call-site codegen. - */ #ifndef BC_OBJECT5_H #define BC_OBJECT5_H -#include "common.h" -extern void func_800A97D4(void); +s32 func_800AA68C(s32, u32, u32); -/** @brief State queries polled by the battle flow controller (bc_object6). */ -extern u16 func_800A980C(void); -extern u16 func_800A9888(void); +s32 func_800AA71C(s32, s32); -#endif /* BC_OBJECT5_H */ +s32 func_800AA768(s32, s32); + +s32 func_800AA7B4(s32, s32); + +s32 func_800AA840(s32, s32); + +s32 func_800AA88C(s32, s32); + +s32 func_800AA930(s32); + +s32 func_800AA980(s32, s32); + +s32 func_800AA9C8(s32, s32); + +s32 func_800AAA10(s32); + +s32 func_800AAA50(s32, s32, s32); + +s32 func_800AAA9C(s32, u32, BattleEntityData*); + +s32 func_800AAB50(s32, u32, BattleEntityData*); + +s32 func_800AABEC(s32, s32, s32, s32, s32); + +s32 func_800AACD0(s32, s32, s32, s32); + +s32 func_800AAE10(s32, s32, s32); + +s32 func_800AAE98(s32); + +void func_800AAF48(s32); + +void func_800AAF70(s32, s16); + +void func_800AAFB8(s32); + +void func_800AB008(s32); + +void func_800AB054(s32); + +void func_800AB0C0(s32, u16); + +void func_800AB11C(s16); + +void func_800AB1AC(s32); + +void func_800AB208(u16); + +s32 func_800AB24C(void); + +void func_800AB28C(void); + +void func_800AB3C4(void); + +void func_800AB3E0(void); + +void func_800AB3FC(s32, s32, s32); + +void func_800AB488(s32, s32); + +#endif /* BC_OBJECT5_H */ \ No newline at end of file diff --git a/src/battle/bc_object2.c b/src/battle/bc_object2.c index beb2318b..ba752c78 100644 --- a/src/battle/bc_object2.c +++ b/src/battle/bc_object2.c @@ -8,6 +8,7 @@ #include "common.h" #include "battle.h" #include "gamestate.h" +#include "game.h" #include "battle/bc_object2.h" #include "battle/bc_object6.h" #include "battle/bc_object7.h" diff --git a/src/battle/bc_object3.c b/src/battle/bc_object3.c index b2df3d76..df47e1a2 100644 --- a/src/battle/bc_object3.c +++ b/src/battle/bc_object3.c @@ -1,6 +1,7 @@ #include "common.h" #include "gamestate.h" #include "battle.h" +#include "game.h" #include "battle/bc_object2.h" #include "battle/bc_object3.h" #include "battle/bc_object7.h" diff --git a/src/battle/bc_object4.c b/src/battle/bc_object4.c index 9417bc80..882ace5c 100644 --- a/src/battle/bc_object4.c +++ b/src/battle/bc_object4.c @@ -3,11 +3,9 @@ #include "gf.h" #include "gamestate.h" #include "battle/bc_object4.h" - extern void func_800E1850(void); - void func_800A6184(s32 arg0, s32 arg1, s32 arg2, u16 arg3) { func_800A5A7C(arg0, arg1, arg2, 0, arg3, 0, &D_800ED148.unk1244[arg0].unk0); } @@ -1432,16 +1430,8 @@ s32 func_800A8AFC(s32 arg0) { return 2; } -// bc_object5 - -#include "battle/bc_object5.h" -#include "battle/bc_object6.h" #include "battle/bc_object7.h" -extern u8 D_800E3CEC[]; -s32 func_800B0398(s32); -void func_800A59AC(s32, s32, s32); - s32 func_800A8B7C(s32 arg0) { BattleCharData* temp_s0; diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index 06c9530b..46fddc0b 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -2,13 +2,6 @@ #include "battle.h" #include "gamestate.h" #include "battle/bc_object5.h" -#include "battle/bc_object6.h" -#include "battle/bc_object7.h" - -extern u8 D_800E3CEC[]; -s32 func_800B0398(s32); -void func_800A59AC(s32, s32, s32); -s32 func_800A97A4(s32); s32 func_800AA68C(s32 arg0, u32 arg1, u32 arg2) { switch (arg1) { diff --git a/src/battle/bc_object6.c b/src/battle/bc_object6.c index ecea248d..fa8ce1b3 100644 --- a/src/battle/bc_object6.c +++ b/src/battle/bc_object6.c @@ -1,7 +1,6 @@ #include "common.h" #include "battle.h" #include "gamestate.h" -#include "battle/bc_object5.h" #include "battle/bc_object6.h" #include "battle/bc_object1.h" extern u8 D_800EE441[]; diff --git a/src/menu/menusts/menusts.c b/src/menu/menusts/menusts.c index 27e5d3db..1808b04a 100644 --- a/src/menu/menusts/menusts.c +++ b/src/menu/menusts/menusts.c @@ -6,7 +6,7 @@ #include "gamestate.h" #include "btl_color.h" #include "btl_entity.h" -#include "battle/bc_object2.h" +#include "game.h" /* menumain is called at a fixed overlay address, so its prototype stays * file-local here (overlay-conflict rule, as in the other sub-overlays). */ From 1b1ef430855827a2fa1fcbc9a97213986f8c21b0 Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Sun, 13 Sep 2026 02:07:19 +0200 Subject: [PATCH 11/12] bc_object6 fixes --- config/symbols.battle.txt | 11 ----------- src/battle/bc_object6.c | 22 ---------------------- 2 files changed, 33 deletions(-) diff --git a/config/symbols.battle.txt b/config/symbols.battle.txt index 3135520e..b98a7014 100644 --- a/config/symbols.battle.txt +++ b/config/symbols.battle.txt @@ -259,20 +259,9 @@ func_800AB4A8 = 0x800AB4A8; // type:func func_800AB570 = 0x800AB570; // type:func func_800AB668 = 0x800AB668; // type:func func_800AB6F4 = 0x800AB6F4; // type:func -func_800AB744 = 0x800AB744; // type:func func_800AB844 = 0x800AB844; // type:func func_800AB914 = 0x800AB914; // type:func func_800AB9B4 = 0x800AB9B4; // type:func -func_800ABA3C = 0x800ABA3C; // type:func -func_800ABCA4 = 0x800ABCA4; // type:func -func_800AC034 = 0x800AC034; // type:func -func_800AC094 = 0x800AC094; // type:func -func_800AC190 = 0x800AC190; // type:func -func_800AC2E4 = 0x800AC2E4; // type:func -func_800AC348 = 0x800AC348; // type:func -func_800AC368 = 0x800AC368; // type:func -func_800AC400 = 0x800AC400; // type:func -func_800AC4E4 = 0x800AC4E4; // type:func func_800ACF84 = 0x800ACF84; // type:func func_800AD4A4 = 0x800AD4A4; // type:func func_800AD50C = 0x800AD50C; // type:func diff --git a/src/battle/bc_object6.c b/src/battle/bc_object6.c index fa8ce1b3..d71d35e9 100644 --- a/src/battle/bc_object6.c +++ b/src/battle/bc_object6.c @@ -16,8 +16,6 @@ INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AB668); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AB6F4); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AB744); - INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AB844); INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AB914); @@ -36,26 +34,6 @@ s16 func_800AB998(u8 *ptr) { INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AB9B4); -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800ABA3C); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800ABCA4); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AC034); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AC094); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AC190); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AC2E4); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AC348); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AC368); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AC400); - -INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object6", func_800AC4E4); - /** * @brief Check if an entity is available (no blocking status flags). * From fa5d745a1180a40ff6b97e269cb40f40d531ea3c Mon Sep 17 00:00:00 2001 From: Eletonyy Date: Wed, 16 Sep 2026 23:20:05 +0200 Subject: [PATCH 12/12] re added removed comments --- include/battle.h | 6 +- src/battle/bc_object4.c | 166 ++++++++++++++++++++++++++++++++++++++ src/battle/bc_object5.c | 172 +++++++++++++++++++++++++++++++++++++--- src/battle/bc_object8.c | 28 +++++++ 4 files changed, 359 insertions(+), 13 deletions(-) diff --git a/include/battle.h b/include/battle.h index 3159a370..921f24cc 100644 --- a/include/battle.h +++ b/include/battle.h @@ -514,9 +514,9 @@ typedef struct { /* 0x12EE */ u8 volatile unk12EE; /**< Misc state byte. */ /* 0x12EF */ u8 volatile unk12EF; /* 0x12EF */ u8 unk12F0; - /* 0x12EF */ u8 pad12F1; - /* 0x12EF */ u8 unk12F2; - /* 0x12F3 */ u8 unk12F3; /* used as index in func_8009F824 */ + /* 0x12EF */ u8 unk12F1; /* used as index for BattleEntity unkC8 in func_800AE414 */ + /* 0x12EF */ u8 unk12F2; /* used as index for unkD64 and unk1100 in func_800A57E0 */ + /* 0x12F3 */ u8 unk12F3; /* used as index for entities in func_8009F824 */ /* 0x12F4 */ u8 unk12F4; /* 0x12F5 */ u8 unk12F5; /* 0x12F6 */ u8 taskHead; /**< Head index of the task queue linked list. */ diff --git a/src/battle/bc_object4.c b/src/battle/bc_object4.c index 882ace5c..6234c1ab 100644 --- a/src/battle/bc_object4.c +++ b/src/battle/bc_object4.c @@ -1557,6 +1557,19 @@ s32 func_800A8EFC(BattleCharData* arg0) { return val; } +/** +* @brief Initialize entity ability fields from the ability table. +* +* Writes a1 as the ability ID at offset 0x32 of the entity entry +* (computed as a0 + a2*5). Looks up ability data in D_80078E00 +* (offset 0x4A60, stride 8) and copies two bytes to offsets 0x34-0x35. +* Clears offset 0x36 and sets offset 0x33 to 1. +* +* @param a0 Base entity pointer (as integer). +* @param a1 Ability ID. +* @param a2 Slot index (multiplied by 5 for stride). +*/ + void func_800A8F98(BattleCharData* arg0, s32 arg1, s32 arg2) { arg0->testSlots[arg2].unk0 = arg1; arg0->testSlots[arg2].unk2 = D_80078E00.rows8[arg1].unk2; @@ -1583,6 +1596,14 @@ s32 func_800A8FDC(BattleCharData* arg0) { return val; } + +/** +* @brief Initialize three type bytes in an entity structure. +* +* @param a0 Pointer to entity data. +* @return Always 3. +*/ + s32 func_800A9064(BattleCharData* arg0) { arg0->testSlots[0].unk0 = 65; arg0->testSlots[1].unk0 = 67; @@ -1593,6 +1614,16 @@ s32 func_800A9064(BattleCharData* arg0) { INCLUDE_ASM("asm/ovl/battle/nonmatchings/bc_object4", func_800A9084); +/** +* @brief Search g_gameState+0xB44 table for entry matching a given byte. +* +* Iterates up to 198 entries (stride 2) in g_gameState at offset 0xB44. +* If byte[0] matches a0, returns byte[1]. Returns 0 if not found. +* +* @param a0 Value to search for. +* @return Unsigned byte at offset 1 of matching entry, or 0 if not found. +*/ + s32 func_800A9240(s32 arg0) { s32 i; @@ -1729,6 +1760,16 @@ void func_800A94E0(void) { } } +/** +* @brief Search D_800EE9E8 table for a matching byte value. +* +* Iterates up to 32 entries (stride 5) in D_800EE9E8, comparing +* the first byte of each entry to a0. +* +* @param a0 Value to search for. +* @return 1 if found, 0 if not found. +*/ + s32 func_800A9568(s32 arg0) { s32 i; @@ -1741,6 +1782,17 @@ s32 func_800A9568(s32 arg0) { return 0; } +/** +* @brief Set up entity action with sound and visual effects. +* +* Calls func_800A97FC to get a value, then triggers entity action +* via func_800B0754, sets animation via func_800AF4BC, and +* conditionally calls func_800AE3D4 based on func_800AE390 result. +* +* @param a0 Entity index passed to func_800A97FC and func_800B0754. +* @param a1 Mode parameter for func_800B0754 and subsequent calls. +*/ + void func_800A95A0(s32 arg0, s32 arg1) { func_800B0754(arg0, 4, arg1, func_800A97FC(arg0)); func_800AF4BC(arg1, 1); @@ -1793,11 +1845,32 @@ void func_800A960C(s32 arg0) { } } +/** +* @brief Compute paired lookup results from entity table and return combined. +* +* Computes D_80078E00 + a0 * 20 as the base address, loads the byte at +* offset 0x3EE7, calls func_800B0F9C and func_800B0F7C with it, and +* returns the bitwise OR of both results masked to 16 bits. +* +* @param a0 Entity index (stride 20 in D_80078E00). +* @return Combined result from both lookups, masked to u16. +*/ s32 func_800A972C(s32 arg0) { return func_800B0F9C(D_80078E00.entriesA0[arg0].unk7) | func_800B0F7C(D_80078E00.entriesA0[arg0].unk7); } +/** +* @brief Resolve a 16-bit offset to an address. +* +* If the offset is 0xFFFF (sentinel), returns D_800E3CEC. +* Otherwise returns offset + base. +* +* @param offset 16-bit offset value (0xFFFF = invalid). +* @param base Base address to add offset to. +* @return Resolved address. +*/ + u8* func_800A9784(u16 arg0, s32 arg1) { if (arg0 == 65535) { return D_800E3CEC; @@ -1806,10 +1879,24 @@ u8* func_800A9784(u16 arg0, s32 arg1) { return arg0 + arg1; // weird } +/** +* @brief Return a random number modulo @p a0. +* +* @param a0 Divisor (also the modulo bound). +* @return Remainder of @c func_8009B15C() / @p a0. +*/ + s32 func_800A97A4(s32 arg0) { return func_8009B15C() % arg0; } +/** +* @brief Clear 8 entity word fields in the battle entity table. +* +* Zeros 8 consecutive words at offset 0x12B4 down to 0x1298 +* relative to D_800ED148. +*/ + void func_800A97D4(void) { s32 i; @@ -1818,10 +1905,28 @@ void func_800A97D4(void) { } } +/** +* @brief Compute a single-bit mask at the given position. +* +* @param bitPos Bit position (0-15). +* @return 16-bit mask with bit at bitPos set. +*/ + s32 func_800A97FC(s32 arg0) { return (u16)(1 << arg0); // functions in this folder break with u16 return prototype } +/** +* @brief Find a random available entity (among first 3) and return its bitmask. +* +* Calls func_800AE730 to get entity count. If 0xFF, returns 0. +* Otherwise loops calling func_800A97A4(3) to pick random indices, +* checking entity[0x90] bit 0 (busy flag). Returns (1 << idx) & 0xFFFF +* when an available entity is found. +* +* @return Bitmask of selected entity, or 0 if none available. +*/ + u16 func_800A980C(void) { s32 idx; @@ -1836,6 +1941,17 @@ u16 func_800A980C(void) { return (1 << idx); } +/** +* @brief Find a random available entity (among 4, offset by 3) and return its bitmask. +* +* Calls func_800AE788 to get entity count. If 0xFF, returns 8. +* Otherwise loops calling func_800A97A4(4), adds 3 to the index, +* checks entity[0x90] bit 0 (busy flag). Returns (1 << (idx+3)) & 0xFFFF +* when an available entity is found. +* +* @return Bitmask of selected entity, or 8 if none available. +*/ + u16 func_800A9888(void) { s32 idx; @@ -1850,10 +1966,21 @@ u16 func_800A9888(void) { return (1 << idx); } +/** +* @brief Compute a bitmask from an entity's byte at offset 0x98. +* +* @param a0 Entity index (stride 0xD0). +* @return 16-bit mask with one bit set at the position given by entity[0x98]. +*/ + u16 func_800A9904(s32 arg0) { return (1 << D_800ED148.entities[arg0].unk98); } +/** +* @brief Toggle the least significant bit of 7 bytes in D_800EEBE0. +*/ + void func_800A9938(void) { s32 i; @@ -1862,6 +1989,17 @@ void func_800A9938(void) { } } +/** +* @brief Populate entity alive flags array from status bits. +* +* Iterates over 7 entities at stride 0xD0 from D_800ED148. For each, +* checks bit 8 (0x100) of the flags word at offset 0x8C. Writes 1 to +* D_800EEBE0[i] if the bit is set, 0 otherwise. If a0 equals 0xC8, +* calls func_800A9938 to toggle the result bits. +* +* @param a0 Trigger value — if 0xC8, post-processes the flags. +*/ + void func_800A9970(s32 arg0) { s32 i; @@ -2053,6 +2191,13 @@ void func_800A9E08(s32 arg0, s32 arg1) { } } +/** +* @brief Clear D_800EEBE0 entries for inactive entities. +* +* Loops over 7 entities at D_800ED148 (stride 0xD0). If bit 0 of the +* word at offset 0x8C is not set, clears D_800EEBE0[i] to zero. +*/ + void func_800A9F98(void) { s32 i; @@ -2063,6 +2208,13 @@ void func_800A9F98(void) { } } +/** +* @brief Clear D_800EEBE0 entries for inactive or dead entities. +* +* Iterates 7 entities (stride 0xD0 in D_800ED148). Clears +* D_800EEBE0[i] to zero unless the entity is both active and alive. +*/ + void func_800A9FDC(void) { s32 i; @@ -2241,6 +2393,13 @@ s32 func_800AA4F0(void) { return 33023; } +/** +* @brief Search entity table for a matching byte at offset 0xCB. +* +* @param a0 Value to search for. +* @return Entity index (0-6) if found, or 0xFF if not found. +*/ + s32 func_800AA4F8(s32 arg0) { s32 i; @@ -2253,6 +2412,13 @@ s32 func_800AA4F8(s32 arg0) { return 255; } +/** + * @brief Search entity table for active entity linked to index a0. + * + * @param a0 Link index to search for. + * @return Entity index if found, 0xFF otherwise. + */ + s32 func_800AA530(s32 arg0) { s32 i; diff --git a/src/battle/bc_object5.c b/src/battle/bc_object5.c index 46fddc0b..27827461 100644 --- a/src/battle/bc_object5.c +++ b/src/battle/bc_object5.c @@ -45,6 +45,17 @@ s32 func_800AA68C(s32 arg0, u32 arg1, u32 arg2) { return 0; } +/** +* @brief Conditionally search entity table and check for 0xFF result. +* +* If a0 is 0, returns whether func_800AA4F8(a1) is not 0xFF. +* If a0 is 3, returns whether func_800AA4F8(a1) is 0xFF. +* +* @param a0 Mode selector (0 = found check, 3 = not-found check). +* @param a1 Search value passed to func_800AA4F8. +* @return Boolean result based on mode. +*/ + s32 func_800AA71C(s32 arg0, s32 arg1) { if (arg0 == 0) { return func_800AA4F8(arg1) != 255; @@ -55,6 +66,17 @@ s32 func_800AA71C(s32 arg0, s32 arg1) { } } +/** +* @brief Conditionally search via func_800AA530 and check for 0xFF result. +* +* If a0 is 0, returns whether func_800AA530(a1) is not 0xFF. +* If a0 is 3, returns whether func_800AA530(a1) is 0xFF. +* +* @param a0 Mode selector (0 = found check, 3 = not-found check). +* @param a1 Search value passed to func_800AA530. +* @return Boolean result based on mode. +*/ + s32 func_800AA768(s32 arg0, s32 arg1) { if (arg0 == 0) { return func_800AA530(arg1) != 255; @@ -87,6 +109,17 @@ s32 func_800AA7B4(s32 unused, s32 arg1) { return 255; } +/** +* @brief Conditionally search via func_800AA7B4 and check for 0xFF result. +* +* If a0 is 0, returns whether func_800AA7B4(a1) is not 0xFF. +* If a0 is 3, returns whether func_800AA7B4(a1) is 0xFF. +* +* @param a0 Mode selector (0 = found check, 3 = not-found check). +* @param a1 Search value passed to func_800AA7B4. +* @return Boolean result based on mode. +*/ + s32 func_800AA840(s32 arg0, s32 arg1) { if (arg0 == 0) { return func_800AA7B4(arg1, arg1) != 255; @@ -130,6 +163,18 @@ s32 func_800AA930(s32 arg0) { return 0; } +/** +* @brief Conditionally call func_800AA930 and optionally invert the result. +* +* If a0 is 0, calls func_800AA930 with a1 and returns its result. +* If a0 is 3, calls func_800AA930 with a1 and returns the inverted +* lowest bit of the result. +* +* @param a0 Mode selector (0 = normal, 3 = inverted). +* @param a1 Parameter passed to func_800AA930. +* @return Result of func_800AA930, possibly with bit 0 inverted. +*/ + s32 func_800AA980(s32 arg0, s32 arg1) { if (arg0 == 0) { return func_800AA930(arg1); @@ -140,6 +185,18 @@ s32 func_800AA980(s32 arg0, s32 arg1) { } } +/** +* @brief Test a specific bit in D_8007809A, optionally inverting. +* +* If a0 is 0, returns bit a1 of D_8007809A. +* If a0 is 3, returns the inverse of bit a1 of D_8007809A. +* Otherwise returns 0 (falls through without setting return value). +* +* @param a0 Mode selector (0 = normal, 3 = inverted). +* @param a1 Bit position to test. +* @return Bit value (0 or 1). +*/ + s32 func_800AA9C8(s32 arg0, s32 arg1) { if (arg0 == 0) { return (D_8007809A >> arg1) & 1; @@ -150,6 +207,17 @@ s32 func_800AA9C8(s32 arg0, s32 arg1) { } } +/** + * @brief Test countdownTimer, optionally inverted. + * + * If a0 == 0, returns 1 when countdownTimer is zero (no battle active). + * If a0 == 3, returns 1 when countdownTimer is nonzero (battle active). + * Other values fall through with no explicit return. + * + * @param a0 Query mode (0 = test no-battle, 3 = test in-battle). + * @return 1 or 0 based on the flag value. + */ + s32 func_800AAA10(s32 arg0) { if (arg0 == 0) { return g_gameState.mainData.countdownTimer == 0; @@ -319,6 +387,12 @@ s32 func_800AAE98(s32 arg0) { return check1 == check2; } +/** +* @brief Allocate structure via func_800AA57C and copy field +0x1C to +0x18. +* +* @param a0 Second parameter to func_800AA57C (first is 0xC8). +*/ + void func_800AAF48(s32 arg0) { BattleEntityData* temp_v0; @@ -326,6 +400,16 @@ void func_800AAF48(s32 arg0) { temp_v0->unk18 = temp_v0->unk1C; } +/** +* @brief Allocate entry and add signed offset to its field at 0x18. +* +* Calls func_800AA57C with 0xC8 and a0, then sign-extends a1 to 16 bits +* and adds it to the word at offset 0x18 of the returned entry. +* +* @param a0 Second parameter to func_800AA57C. +* @param a1 Signed 16-bit offset to add. +*/ + void func_800AAF70(s32 arg0, s16 arg1) { BattleEntityData* temp_v0; @@ -333,6 +417,16 @@ void func_800AAF70(s32 arg0, s16 arg1) { temp_v0->unk18 += arg1; } +/** +* @brief Look up entity entry by index, call animation init, set active flag. +* +* Computes D_800EE28C + a0 * 16 to get the entry, calls func_8009AF3C +* with entry[4], duration 0x1E, mode 3, size 0x80, and zero flag. +* Then sets entry[0xF] to 1. +* +* @param a0 Entity index (stride 16). +*/ + void func_800AAFB8(s32 arg0) { TaskEntry* data; @@ -359,6 +453,17 @@ void func_800AB054(s32 arg0) { td->timer--; } +/** +* @brief Allocate entry via func_8009B3D0 and store battle data. +* +* Allocates an entry using func_800AB054 as callback, computes the +* entry address from D_800EE28C + index * 16, stores the result of +* func_800B0398(a0) at offset 4, and a1 as halfword at offset 8. +* +* @param a0 Parameter passed to func_800B0398. +* @param a1 Halfword value stored at entry offset 8. +*/ + void func_800AB0C0(s32 arg0, u16 arg1) { TaskEntry* currentEntry; @@ -367,6 +472,17 @@ void func_800AB0C0(s32 arg0, u16 arg1) { currentEntry->timer = arg1; } + +/** +* @brief Clear control flags and reset animation state for a battle entity. +* +* Clears CTRL_FLAG_40, CTRL_FLAG_80, and CTRL_FLAG_02 from the entity's +* controlFlags field, then calls func_800AE6C0 and func_800A59AC to +* reset animation state. +* +* @param idx Entity index (stride 0xD0 in D_800ED148). +*/ + void func_800AB11C(s16 arg0) { D_800ED148.entities[arg0].controlFlags &= ~0x40; D_800ED148.entities[arg0].controlFlags &= ~0x80; @@ -393,12 +509,32 @@ void func_800AB1AC(s32 arg0) { temp_a0->timer--; } +/** +* @brief Allocate entry via func_8009B3D0 and store value at offset 8. +* +* Calls func_8009B3D0 with func_800AB1AC as callback, shifts result +* left by 4 (multiply by 16), adds D_800EE28C as base, then stores a0 +* as halfword at offset 8 of the computed entry. +* +* @param a0 Value to store as halfword. +*/ + void func_800AB208(u16 arg0) { TaskEntry* currentEntry = &D_800ED148.taskData[func_8009B3D0(func_800AB1AC)]; currentEntry->timer = arg0; } +/** +* @brief Find the first active entity (bit 0 set at offset 0x8C). +* +* Scans entities 3-6 in the D_800ED148 array (offset 0x270, stride 0xD0). +* Returns the index of the first entity whose word at offset 0x8C has bit 0 set. +* Returns 0xFF if no active entity is found. +* +* @return Entity index (3-6), or 0xFF if none active. +*/ + s32 func_800AB24C(void) { s32 i; @@ -440,12 +576,20 @@ void func_800AB28C(void) { func_8009A528(entityIdx, idx); } +/** +* @brief Set battle flag 0x5C2 and clear status bytes 0x12F9 and 0x12FD. +*/ + void func_800AB3C4(void) { D_800ED148.unk5C2 = 1; D_800ED148.unk12F9 = 0; D_800ED148.unk12FD = 0; } +/** +* @brief Clear battle flag 0x5C2 and set status bytes 0x12F9 and 0x12FD. +*/ + void func_800AB3E0(void) { D_800ED148.unk5C2 = 0; D_800ED148.unk12F9 = 1; @@ -453,16 +597,17 @@ void func_800AB3E0(void) { } /** - * @brief Resolve animation data and display it with position and timing. - * - * Looks up animation data from the entity's sub-object table at offset 0x14, - * resolves it through func_800A9784 and func_800B0398, then calls - * func_8009AF3C to display with the given Y position, fixed params. - * - * @param a0 Entity index (stride 0xD0 in D_800ED148). - * @param a1 Sub-animation index (multiplied by 2 for table lookup). - * @param a2 Y position for display. - */ +* @brief Resolve animation data and display it with position and timing. +* +* Looks up animation data from the entity's sub-object table at offset 0x14, +* resolves it through func_800A9784 and func_800B0398, then calls +* func_8009AF3C to display with the given Y position, fixed params. +* +* @param a0 Entity index (stride 0xD0 in D_800ED148). +* @param a1 Sub-animation index (multiplied by 2 for table lookup). +* @param a2 Y position for display. +*/ + void func_800AB3FC(s32 a0, s32 a1, s32 a2) { volatile u8 *base = (u8 *)&D_800ED148; u8 *entity = (u8 *)base + a0 * 0xD0; @@ -477,6 +622,13 @@ void func_800AB3FC(s32 a0, s32 a1, s32 a2) { func_8009AF3C(result, a2, 3, 0xF0, 0); } +/** +* @brief Call func_800AB3FC with a fixed duration of 0x1E. +* +* @param a0 First parameter passed through. +* @param a1 Second parameter passed through. +*/ + void func_800AB488(s32 arg0, s32 arg1) { func_800AB3FC(arg0, arg1, 30); } \ No newline at end of file diff --git a/src/battle/bc_object8.c b/src/battle/bc_object8.c index a5378920..4fac4f84 100644 --- a/src/battle/bc_object8.c +++ b/src/battle/bc_object8.c @@ -139,6 +139,14 @@ s32 func_800B1A78(void) { return 1; } +/** +* @brief Check battle conditions and trigger entity action sequence. +* +* Checks bit 1 of D_8007809A. If set, calls func_800B1A78 to validate. +* If valid, calls func_8009B79C(0x20, 0xFF) to test entity availability. +* If available, clears D_800EE45C and calls func_800B1A48 to start action. +*/ + void func_800B1ACC(void) { if (!(D_8007809A & 2)) { return; @@ -268,6 +276,14 @@ void func_800B2038(void) { } } +/** +* @brief Check battle mode flag and conditionally trigger entity processing. +* +* Checks bit 3 of D_8007809A. If set, calls func_8009B79C(8, 0xFF) to test +* entity availability. If available, calls func_800B1B68 and returns. +* Otherwise (bit not set or entity unavailable), clears D_800EE465. +*/ + void func_800B2084(void) { if (D_8007809A & 8 && func_8009B79C(8, 255) != 0) { func_800B1B68(); @@ -297,6 +313,18 @@ s32 func_800B20D8(void) { return 1; } +/** +* @brief Check if conditions are met to initiate an auto-battle action. +* +* Checks a chain of conditions: whether func_800AE788 returns the sentinel +* 0xFF, whether func_800B20D8 indicates busy, bit 2 of D_8007809A flags, +* whether g_battleConfig matches 0x13D, and whether entity slot 0x40 is +* available via func_8009B79C. If all pass, sets D_800EE45C to 1 and +* calls func_800B1A48 to start the action. +* +* @return 1 if action was initiated, 0 otherwise. +*/ + s32 func_800B2128(void) { if (func_800AE788() == 255) { return 0;