From eb66b60f3813dda5cd6aae92401c10300b4a3515 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 17 Nov 2018 15:30:34 +0100 Subject: [PATCH 1/7] Begin battle pyramid --- asm/battle_frontier_2.s | 3532 ---------------------------------- asm/battle_pyramid.s | 2421 +++++++++++++++++++++++ data/battle_frontier_3.s | 6 +- include/battle_pyramid_bag.h | 1 + include/global.h | 8 +- ld_script.txt | 2 + src/battle_pyramid.c | 425 ++++ src/battle_script_commands.c | 109 +- src/graphics.c | 2 +- 9 files changed, 2913 insertions(+), 3593 deletions(-) create mode 100644 asm/battle_pyramid.s create mode 100644 src/battle_pyramid.c diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index f4dc876ed..34dfb9429 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -4,10 +4,6 @@ .syntax unified .text - - - - thumb_func_start sub_81A8934 @ void sub_81A8934(u8) @@ -702,3532 +698,4 @@ _081A8E76: bx r0 thumb_func_end sub_81A8D94 - thumb_func_start sub_81A8E7C -sub_81A8E7C: @ 81A8E7C - push {lr} - ldr r1, =gUnknown_08613EE0 - ldr r0, =gSpecialVar_0x8004 - ldrh r0, [r0] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - bl _call_via_r0 - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A8E7C - - thumb_func_start sub_81A8E9C -sub_81A8E9C: @ 81A8E9C - push {r4-r6,lr} - ldr r3, =gSaveBlock2Ptr - ldr r1, [r3] - ldr r4, =0x00000ca9 - adds r0, r1, r4 - ldrb r0, [r0] - lsls r0, 30 - lsrs r5, r0, 30 - ldr r0, =0x00000ca8 - adds r1, r0 - movs r2, 0 - strb r2, [r1] - ldr r1, [r3] - ldr r6, =0x00000cb2 - adds r0, r1, r6 - strh r2, [r0] - adds r1, r4 - ldrb r2, [r1] - movs r0, 0x5 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - cmp r5, 0 - beq _081A8EF0 - ldr r0, [r3] - ldr r1, =0x00000cdc - adds r0, r1 - ldr r2, [r0] - movs r0, 0x80 - lsls r0, 6 - b _081A8EFC - .pool -_081A8EF0: - ldr r0, [r3] - ldr r6, =0x00000cdc - adds r0, r6 - ldr r2, [r0] - movs r0, 0x80 - lsls r0, 5 -_081A8EFC: - ands r2, r0 - cmp r2, 0 - bne _081A8F14 - ldr r0, [r3] - lsls r1, r5, 1 - ldr r3, =0x00000e1a - adds r0, r3 - adds r0, r1 - strh r2, [r0] - adds r0, r5, 0 - bl sub_81AAA7C -_081A8F14: - bl sub_81C4EEC - ldr r0, =gTrainerBattleOpponent_A - movs r1, 0 - strh r1, [r0] - ldr r0, =gBattleOutcome - strb r1, [r0] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A8E9C - - thumb_func_start sub_81A8F38 -sub_81A8F38: @ 81A8F38 - push {r4,lr} - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r4, r0, 30 - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - adds r3, r1, 0 - cmp r0, 0x6 - bls _081A8F54 - b _081A903A -_081A8F54: - lsls r0, 2 - ldr r1, =_081A8F70 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A8F70: - .4byte _081A8F8C - .4byte _081A8F9C - .4byte _081A8FB4 - .4byte _081A8FE4 - .4byte _081A8FF8 - .4byte _081A9010 - .4byte _081A9028 -_081A8F8C: - ldr r0, =gSpecialVar_Result - ldr r1, [r3] - ldr r3, =0x00000e18 - b _081A8FFE - .pool -_081A8F9C: - ldr r2, =gSpecialVar_Result - ldr r0, [r3] - lsls r1, r4, 1 - ldr r3, =0x00000e1a - adds r0, r3 - adds r0, r1 - ldrh r0, [r0] - b _081A9038 - .pool -_081A8FB4: - cmp r4, 0 - beq _081A8FCC - ldr r2, =gSpecialVar_Result - ldr r0, [r3] - ldr r1, =0x00000cdc - adds r0, r1 - b _081A9030 - .pool -_081A8FCC: - ldr r2, =gSpecialVar_Result - ldr r0, [r3] - ldr r3, =0x00000cdc - adds r0, r3 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 5 - b _081A9036 - .pool -_081A8FE4: - ldr r0, =gSpecialVar_Result - ldr r1, [r3] - ldr r2, =0x00000e1a - adds r1, r2 - b _081A9000 - .pool -_081A8FF8: - ldr r0, =gSpecialVar_Result - ldr r1, [r3] - ldr r3, =0x00000e1c -_081A8FFE: - adds r1, r3 -_081A9000: - ldrh r1, [r1] - strh r1, [r0] - b _081A903A - .pool -_081A9010: - ldr r2, =gSpecialVar_Result - ldr r0, [r3] - ldr r1, =0x00000cdc - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 5 - b _081A9036 - .pool -_081A9028: - ldr r2, =gSpecialVar_Result - ldr r0, [r3] - ldr r3, =0x00000cdc - adds r0, r3 -_081A9030: - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 6 -_081A9036: - ands r0, r1 -_081A9038: - strh r0, [r2] -_081A903A: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A8F38 - - thumb_func_start sub_81A9048 -sub_81A9048: @ 81A9048 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldr r1, =0x00000ca9 - adds r0, r2, r1 - ldrb r0, [r0] - lsls r0, 30 - lsrs r1, r0, 30 - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - cmp r0, 0x1 - beq _081A9098 - cmp r0, 0x1 - bgt _081A9078 - cmp r0, 0 - beq _081A9082 - b _081A9126 - .pool -_081A9078: - cmp r0, 0x2 - beq _081A90B0 - cmp r0, 0x7 - beq _081A911C - b _081A9126 -_081A9082: - ldr r0, =gSpecialVar_0x8006 - ldrh r1, [r0] - ldr r3, =0x00000e18 - adds r0, r2, r3 - strh r1, [r0] - b _081A9126 - .pool -_081A9098: - lsls r1, 1 - ldr r3, =0x00000e1a - adds r0, r2, r3 - adds r0, r1 - ldr r1, =gSpecialVar_0x8006 - ldrh r1, [r1] - strh r1, [r0] - b _081A9126 - .pool -_081A90B0: - cmp r1, 0 - beq _081A90E4 - ldr r0, =gSpecialVar_0x8006 - ldrh r0, [r0] - cmp r0, 0 - beq _081A90D0 - ldr r1, =0x00000cdc - adds r0, r2, r1 - ldr r1, [r0] - movs r2, 0x80 - lsls r2, 6 - b _081A90F6 - .pool -_081A90D0: - ldr r3, =0x00000cdc - adds r0, r2, r3 - ldr r1, [r0] - ldr r2, =0xffffdfff - b _081A910C - .pool -_081A90E4: - ldr r0, =gSpecialVar_0x8006 - ldrh r0, [r0] - cmp r0, 0 - beq _081A9104 - ldr r1, =0x00000cdc - adds r0, r2, r1 - ldr r1, [r0] - movs r2, 0x80 - lsls r2, 5 -_081A90F6: - orrs r1, r2 - str r1, [r0] - b _081A9126 - .pool -_081A9104: - ldr r3, =0x00000cdc - adds r0, r2, r3 - ldr r1, [r0] - ldr r2, =0xffffefff -_081A910C: - ands r1, r2 - str r1, [r0] - b _081A9126 - .pool -_081A911C: - ldr r0, =gSpecialVar_0x8006 - ldrh r1, [r0] - ldr r3, =0x00000e2a - adds r0, r2, r3 - strb r1, [r0] -_081A9126: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9048 - - thumb_func_start sub_81A9134 -sub_81A9134: @ 81A9134 - push {r4,lr} - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r1, =gSpecialVar_0x8005 - ldrh r1, [r1] - ldr r2, =0x00000ca8 - adds r0, r2 - strb r1, [r0] - movs r0, 0x80 - lsls r0, 7 - movs r1, 0 - bl VarSet - ldr r1, [r4] - ldr r0, =0x00000ca9 - adds r1, r0 - ldrb r0, [r1] - movs r2, 0x4 - orrs r0, r2 - strb r0, [r1] - bl save_serialize_map - movs r0, 0x1 - bl TrySavingData - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9134 - - thumb_func_start sub_81A917C -sub_81A917C: @ 81A917C - push {r4,r5,lr} - ldr r4, =gSaveBlock2Ptr - ldr r1, [r4] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 29 - ldr r2, =0x00000e1a - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - cmp r0, 0x29 - bls _081A91CC - bl Random - ldr r4, [r4] - ldr r5, =gUnknown_08613F34 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x9 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 15 - adds r0, r5 - ldrh r0, [r0] - ldr r1, =0x00000e18 - adds r4, r1 - b _081A91EA - .pool -_081A91CC: - bl Random - ldr r4, [r4] - ldr r5, =gUnknown_08613F28 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x6 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 15 - adds r0, r5 - ldrh r0, [r0] - ldr r2, =0x00000e18 - adds r4, r2 -_081A91EA: - strh r0, [r4] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A917C - - thumb_func_start sub_81A91FC -sub_81A91FC: @ 81A91FC - push {r4,r5,lr} - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - ldr r1, =0x00000e18 - adds r0, r1 - ldrh r0, [r0] - movs r1, 0x1 - bl AddBagItem - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x1 - bne _081A9244 - ldr r0, [r4] - ldr r1, =0x00000e18 - adds r0, r1 - ldrh r0, [r0] - ldr r1, =gStringVar1 - bl CopyItemName - ldr r0, [r4] - ldr r1, =0x00000e18 - adds r0, r1 - movs r1, 0 - strh r1, [r0] - ldr r0, =gSpecialVar_Result - strh r5, [r0] - b _081A924A - .pool -_081A9244: - ldr r1, =gSpecialVar_Result - movs r0, 0 - strh r0, [r1] -_081A924A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A91FC - - thumb_func_start sub_81A9254 -sub_81A9254: @ 81A9254 - push {r4,r5,lr} - movs r4, 0 - ldr r5, =gSaveBlock2Ptr -_081A925A: - bl Random - ldr r1, [r5] - lsls r2, r4, 1 - ldr r3, =0x00000e22 - adds r1, r3 - adds r1, r2 - strh r0, [r1] - adds r4, 0x1 - cmp r4, 0x3 - ble _081A925A - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e2a - adds r0, r1 - movs r1, 0 - strb r1, [r0] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9254 - - thumb_func_start CalculateBattlePyramidItemBallItemId -CalculateBattlePyramidItemBallItemId: @ 81A9290 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - mov r10, r0 - adds r2, 0x9 - adds r0, r1, r2 - ldrh r0, [r0] - str r0, [sp] - mov r2, r10 - lsls r0, r2, 1 - ldr r2, =0x00000e1a - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x14 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - cmp r0, 0x13 - bls _081A92DE - movs r0, 0x13 - mov r8, r0 -_081A92DE: - bl sub_81AA9E4 - lsls r0, 24 - ldr r1, =gSpecialVar_LastTalked - ldrh r4, [r1] - ldr r1, =gUnknown_08613650 - lsrs r0, 20 - adds r0, r1 - ldrb r0, [r0, 0x1] - subs r4, r0 - subs r7, r4, 0x1 - ldr r1, [r5] - lsrs r0, r7, 31 - adds r0, r7, r0 - asrs r0, 1 - lsls r0, 1 - ldr r2, =0x00000e22 - adds r1, r2 - adds r1, r0 - ldrh r6, [r1] - adds r0, r6, 0 - bl SeedRng2 - movs r5, 0 - mov r0, r8 - lsls r0, 2 - mov r9, r0 - cmp r5, r4 - bge _081A9332 -_081A9318: - bl Random2 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x64 - bl __umodsi3 - lsls r0, 16 - lsrs r6, r0, 16 - adds r5, 0x1 - adds r0, r7, 0x1 - cmp r5, r0 - blt _081A9318 -_081A9332: - ldr r0, =gUnknown_08613B3A - ldr r1, [sp] - adds r0, r1, r0 - ldrb r5, [r0] - ldr r1, =gUnknown_08613ABC - ldr r3, =gSpecialVar_0x8000 - ldr r4, =gSpecialVar_0x8001 - cmp r5, 0x3E - bhi _081A935E - lsls r2, r5, 1 - adds r0, r2, r1 - ldrb r0, [r0] - cmp r6, r0 - blt _081A935E - adds r0, r2, r1 -_081A9350: - adds r0, 0x2 - adds r5, 0x1 - cmp r5, 0x3E - bhi _081A935E - ldrb r2, [r0] - cmp r6, r2 - bge _081A9350 -_081A935E: - mov r0, r10 - cmp r0, 0 - beq _081A9394 - ldr r2, =gUnknown_0861392C - b _081A9396 - .pool -_081A9394: - ldr r2, =gUnknown_0861379C -_081A9396: - lsls r0, r5, 1 - adds r1, 0x1 - adds r0, r1 - ldrb r0, [r0] - lsls r0, 1 - mov r1, r9 - add r1, r8 - lsls r1, 2 - adds r0, r1 - adds r0, r2 - ldrh r0, [r0] - strh r0, [r3] - movs r0, 0x1 - strh r0, [r4] - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end CalculateBattlePyramidItemBallItemId - - thumb_func_start sub_81A93C8 -sub_81A93C8: @ 81A93C8 - push {r4,r5,lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r3, r0, r1 - movs r2, 0 - ldr r4, =gSpecialVar_LastTalked - b _081A93F4 - .pool -_081A93E4: - adds r2, 0x1 - lsls r0, r2, 1 - adds r0, r2 - lsls r0, 3 - adds r0, r3 - ldrb r0, [r0] - cmp r0, 0 - beq _081A940A -_081A93F4: - lsls r0, r2, 1 - adds r0, r2 - lsls r0, 3 - adds r1, r0, r3 - ldrb r0, [r1] - ldrh r5, [r4] - cmp r0, r5 - bne _081A93E4 - ldr r0, =0x00007fff - strh r0, [r1, 0x4] - strh r0, [r1, 0x6] -_081A940A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A93C8 - - thumb_func_start sub_81A9414 -sub_81A9414: @ 81A9414 - ldr r1, =gFacilityTrainers - ldr r0, =gBattleFrontierTrainers - str r0, [r1] - bx lr - .pool - thumb_func_end sub_81A9414 - - thumb_func_start sub_81A9424 -sub_81A9424: @ 81A9424 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x8 - movs r0, 0 - mov r9, r0 - movs r7, 0 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r1, r0 - mov r8, r1 - ldr r2, =gEventObjects - ldr r0, =gSelectedEventObject - ldrb r1, [r0] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x8] - bl sub_81A9AA8 - lsls r0, 16 - lsrs r5, r0, 16 - movs r6, 0 - ldr r2, =gUnknown_08613C1C - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r5 - adds r0, r1 - ldrb r1, [r2] - ldrb r0, [r0] - cmp r1, r0 - bne _081A9488 - ldrb r2, [r2, 0x1] - mov r9, r2 - b _081A94AE - .pool -_081A9488: - adds r6, 0x1 - cmp r6, 0x31 - bhi _081A94AE - ldr r4, =gUnknown_08613C1C - lsls r3, r6, 1 - adds r2, r3, r4 - ldr r0, =gFacilityTrainers - ldr r1, [r0] - movs r0, 0x34 - muls r0, r5 - adds r0, r1 - ldrb r1, [r2] - ldrb r0, [r0] - cmp r1, r0 - bne _081A9488 - adds r0, r4, 0x1 - adds r0, r3, r0 - ldrb r0, [r0] - mov r9, r0 -_081A94AE: - ldr r3, =gUnknown_08613ED8 - ldr r2, =gEventObjects - ldr r0, =gSelectedEventObject - ldrb r1, [r0] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x8] - subs r0, 0x1 - adds r0, r3 - ldrb r0, [r0] - str r0, [sp] - movs r6, 0 - mov r3, r9 - lsls r3, 2 - mov r9, r3 -_081A94D0: - ldr r0, [sp] - cmp r0, 0x8 - bls _081A94D8 - b _081A95E8 -_081A94D8: - lsls r0, 2 - ldr r1, =_081A94FC - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A94FC: - .4byte _081A9520 - .4byte _081A9530 - .4byte _081A9572 - .4byte _081A95B4 - .4byte _081A95BA - .4byte _081A95C0 - .4byte _081A95C6 - .4byte _081A95D2 - .4byte _081A95DE -_081A9520: - mov r0, sp - movs r1, 0x8 - movs r2, 0 - bl sub_81A9998 - lsls r0, 24 - lsrs r7, r0, 24 - b _081A95EE -_081A9530: - movs r6, 0 - ldr r2, =0x7fff0000 - mov r4, r8 - adds r4, 0x4 - mov r5, r8 - b _081A9560 - .pool -_081A9540: - ldrb r0, [r5, 0x1] - cmp r0, 0x3B - bne _081A955A - movs r1, 0 - ldrsh r0, [r4, r1] - asrs r1, r2, 16 - cmp r0, r1 - beq _081A955A - movs r3, 0x2 - ldrsh r0, [r4, r3] - cmp r0, r1 - beq _081A955A - adds r7, 0x1 -_081A955A: - adds r4, 0x18 - adds r5, 0x18 - adds r6, 0x1 -_081A9560: - str r2, [sp, 0x4] - bl sub_81AAA40 - lsls r0, 24 - lsrs r0, 24 - ldr r2, [sp, 0x4] - cmp r6, r0 - blt _081A9540 - b _081A95EE -_081A9572: - bl sub_81AA9E4 - lsls r0, 24 - ldr r1, =gUnknown_08613650 - lsrs r0, 20 - adds r0, r1 - ldrb r7, [r0, 0x1] - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e2a - adds r0, r1 - ldrb r2, [r0] - ldr r1, =gBitTable - movs r6, 0x7 -_081A958E: - ldr r0, [r1] - ands r0, r2 - cmp r0, 0 - beq _081A9598 - subs r7, 0x1 -_081A9598: - adds r1, 0x4 - subs r6, 0x1 - cmp r6, 0 - bge _081A958E - b _081A95EE - .pool -_081A95B4: - mov r0, sp - movs r1, 0x8 - b _081A95D6 -_081A95BA: - mov r0, sp - movs r1, 0x8 - b _081A95CA -_081A95C0: - mov r0, sp - movs r1, 0x10 - b _081A95D6 -_081A95C6: - mov r0, sp - movs r1, 0x10 -_081A95CA: - movs r2, 0x1 - bl sub_81A9998 - b _081A95E8 -_081A95D2: - mov r0, sp - movs r1, 0x18 -_081A95D6: - movs r2, 0x2 - bl sub_81A9998 - b _081A95E8 -_081A95DE: - mov r0, sp - movs r1, 0x18 - movs r2, 0x1 - bl sub_81A9998 -_081A95E8: - cmp r6, 0 - bne _081A95EE - b _081A94D0 -_081A95EE: - ldr r1, =gUnknown_08613EC0 - add r1, r9 - ldr r0, [sp] - ldr r1, [r1] - lsls r0, 2 - adds r0, r1 - ldr r1, [r0] - lsls r0, r7, 2 - adds r0, r1 - ldr r0, [r0] - bl ShowFieldMessage - add sp, 0x8 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9424 - - thumb_func_start sub_81A9618 -sub_81A9618: @ 81A9618 - push {r4,r5,lr} - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r2, r0, 29 - ldr r4, =0x00000e1a - adds r1, r4 - adds r1, r2 - ldrh r3, [r1] - ldr r0, =0x000003e6 - cmp r3, r0 - bhi _081A963A - adds r0, r3, 0x1 - strh r0, [r1] -_081A963A: - ldr r0, [r5] - adds r1, r0, r4 - adds r1, r2 - ldr r3, =0x00000e1e - adds r0, r3 - adds r0, r2 - ldrh r1, [r1] - ldrh r2, [r0] - cmp r1, r2 - bls _081A9650 - strh r1, [r0] -_081A9650: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9618 - - thumb_func_start sub_81A966C -sub_81A966C: @ 81A966C - push {r4,lr} - ldr r4, =gSpecialVar_Result - bl InBattlePyramid - lsls r0, 24 - lsrs r0, 24 - strh r0, [r4] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A966C - - thumb_func_start sub_81A9684 -sub_81A9684: @ 81A9684 - push {r4,lr} - ldr r0, =gSpecialVar_0x8006 - ldrh r0, [r0] - cmp r0, 0 - beq _081A9698 - cmp r0, 0x1 - beq _081A96B4 - b _081A9754 - .pool -_081A9698: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =gSpecialVar_0x8005 - ldrh r1, [r1] - ldr r2, =0x00000e68 - adds r0, r2 - strb r1, [r0] - b _081A9754 - .pool -_081A96B4: - ldr r4, =gSpecialVar_Result - ldrh r0, [r4] - cmp r0, 0x1 - beq _081A9710 - cmp r0, 0x1 - bgt _081A9754 - cmp r0, 0 - bne _081A9754 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _081A9754 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000e68 - adds r1, r0, r2 - ldrb r0, [r1] - cmp r0, 0x77 - bls _081A96F4 - movs r0, 0x78 - strb r0, [r1] - b _081A96FC - .pool -_081A96F4: - ldr r0, =gSpecialVar_0x8007 - ldrh r0, [r0] - bl PlaySE -_081A96FC: - ldr r1, =gSpecialVar_Result - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] - b _081A9754 - .pool -_081A9710: - ldr r1, =gSpecialVar_0x8005 - ldrh r0, [r1] - cmp r0, 0 - beq _081A9750 - subs r0, 0x1 - strh r0, [r1] - ldr r3, =gSaveBlock2Ptr - ldr r1, [r3] - ldr r2, =0x00000e68 - adds r1, r2 - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - ldr r0, [r3] - adds r1, r0, r2 - ldrb r0, [r1] - cmp r0, 0x78 - bls _081A973E - movs r0, 0x78 - strb r0, [r1] - ldrh r0, [r4] - adds r0, 0x1 - strh r0, [r4] -_081A973E: - bl door_upload_tiles - b _081A9754 - .pool -_081A9750: - movs r0, 0x2 - strh r0, [r4] -_081A9754: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_81A9684 - - thumb_func_start sub_81A975C -sub_81A975C: @ 81A975C - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x4 - movs r1, 0 - mov r0, sp - strh r1, [r0] - movs r5, 0 - movs r0, 0x64 - mov r9, r0 - ldr r1, =gPlayerParty - mov r8, r1 -_081A9776: - movs r4, 0 - adds r7, r5, 0x1 - mov r6, r9 - muls r6, r5 -_081A977E: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - lsls r1, r4, 1 - ldr r2, =0x00000caa - adds r0, r2 - adds r1, r0, r1 - ldrh r0, [r1] - cmp r0, 0 - beq _081A97A2 - subs r0, 0x1 - cmp r0, r5 - bne _081A97A2 - mov r1, r8 - adds r0, r6, r1 - movs r1, 0xC - mov r2, sp - bl SetMonData -_081A97A2: - adds r4, 0x1 - cmp r4, 0x3 - ble _081A977E - adds r5, r7, 0 - cmp r5, 0x5 - ble _081A9776 - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A975C - - thumb_func_start sub_81A97C8 -sub_81A97C8: @ 81A97C8 - push {lr} - ldr r0, =sub_81A97DC - movs r1, 0 - bl CreateTask - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A97C8 - - thumb_func_start sub_81A97DC -sub_81A97DC: @ 81A97DC - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _081A980C - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000cb2 - adds r0, r1 - ldrh r0, [r0] - lsls r0, 5 - ldr r1, =gUnknown_08D856C8 - adds r0, r1 - ldr r1, =gPlttBufferUnfaded + 0xC0 - movs r2, 0x10 - bl CpuSet - adds r0, r4, 0 - bl DestroyTask -_081A980C: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A97DC - - thumb_func_start sub_81A9828 -sub_81A9828: @ 81A9828 - push {lr} - bl sub_809FDD4 - pop {r0} - bx r0 - thumb_func_end sub_81A9828 - - thumb_func_start sub_81A9834 -sub_81A9834: @ 81A9834 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x18 - movs r0, 0 - str r0, [sp] -_081A9844: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, [sp] - lsls r1, r2, 1 - ldr r5, =0x00000caa - adds r0, r5 - adds r0, r1 - ldrh r0, [r0] - subs r5, r0, 0x1 - movs r0, 0 - str r0, [sp, 0x4] - movs r2, 0x64 - adds r1, r5, 0 - muls r1, r2 - str r1, [sp, 0x8] - movs r0, 0x8E - lsls r0, 2 - adds r6, r1, r0 - movs r1, 0 - str r1, [sp, 0x10] -_081A986C: - ldr r2, =gSaveBlock1Ptr - ldr r0, [r2] - adds r0, r6 - movs r1, 0xB - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - ldr r3, =gPlayerParty - ldr r1, [sp, 0x10] - adds r0, r1, r3 - movs r1, 0xB - movs r2, 0 - str r3, [sp, 0x14] - bl GetMonData - ldr r3, [sp, 0x14] - cmp r4, r0 - bne _081A993C - movs r6, 0 - adds r2, r5, 0x1 - str r2, [sp, 0xC] - movs r1, 0x64 - adds r0, r5, 0 - muls r0, r1 - movs r5, 0x8E - lsls r5, 2 - adds r5, r0 - mov r9, r5 - ldr r7, [sp, 0x4] - muls r7, r1 - mov r10, r3 -_081A98AC: - movs r5, 0 - adds r0, r6, 0x1 - mov r8, r0 - b _081A98C6 - .pool -_081A98C4: - adds r5, 0x1 -_081A98C6: - cmp r5, 0x3 - bgt _081A98EE - ldr r1, =gSaveBlock1Ptr - ldr r0, [r1] - add r0, r9 - adds r1, r5, 0 - adds r1, 0xD - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - adds r1, r6, 0 - adds r1, 0xD - mov r2, r10 - adds r0, r7, r2 - movs r2, 0 - bl GetMonData - cmp r4, r0 - bne _081A98C4 -_081A98EE: - cmp r5, 0x4 - bne _081A9900 - lsls r2, r6, 24 - lsrs r2, 24 - mov r5, r10 - adds r0, r7, r5 - movs r1, 0xA6 - bl SetMonMoveSlot -_081A9900: - mov r6, r8 - cmp r6, 0x3 - ble _081A98AC - ldr r1, =gSaveBlock1Ptr - ldr r0, [r1] - ldr r2, [sp, 0x8] - adds r0, r2 - movs r5, 0x8E - lsls r5, 2 - adds r0, r5 - ldr r1, =gPlayerParty - ldr r2, [sp, 0x10] - adds r1, r2, r1 - movs r2, 0x64 - bl memcpy - ldr r0, =gUnknown_0203CEF8 - ldr r5, [sp, 0x4] - adds r0, r5, r0 - mov r1, sp - ldrb r1, [r1, 0xC] - strb r1, [r0] - b _081A994C - .pool -_081A993C: - ldr r2, [sp, 0x10] - adds r2, 0x64 - str r2, [sp, 0x10] - ldr r0, [sp, 0x4] - adds r0, 0x1 - str r0, [sp, 0x4] - cmp r0, 0x2 - ble _081A986C -_081A994C: - ldr r1, [sp] - adds r1, 0x1 - str r1, [sp] - cmp r1, 0x2 - bgt _081A9958 - b _081A9844 -_081A9958: - movs r2, 0 - str r2, [sp] - ldr r4, =gSaveBlock2Ptr - ldr r3, =0x00000caa - ldr r2, =gUnknown_0203CEF8 -_081A9962: - ldr r1, [r4] - ldr r5, [sp] - lsls r0, r5, 1 - adds r1, r3 - adds r1, r0 - adds r0, r5, r2 - ldrb r0, [r0] - strh r0, [r1] - adds r5, 0x1 - str r5, [sp] - cmp r5, 0x2 - ble _081A9962 - add sp, 0x18 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9834 - - thumb_func_start sub_81A9998 -sub_81A9998: @ 81A9998 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - mov r10, r0 - lsls r1, 24 - lsrs r6, r1, 24 - lsls r2, 24 - lsrs r7, r2, 24 - movs r4, 0 - ldr r0, =gUnknown_03005DC0 - ldr r5, [r0, 0x8] - ldr r1, [r0] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 1 - adds r0, 0xE - adds r5, r0 - movs r3, 0 - ldr r0, =0x000003ff - mov r8, r0 - ldr r1, =0x0000028e - mov r12, r1 - ldr r0, =gEventObjects - mov r9, r0 -_081A99CC: - movs r2, 0 -_081A99CE: - lsls r0, r2, 1 - adds r0, r5 - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - cmp r0, r12 - bne _081A9A8A - adds r2, 0x7 - ldr r0, =gSelectedEventObject - ldrb r1, [r0] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - add r0, r9 - movs r5, 0xC - ldrsh r1, [r0, r5] - subs r2, r1 - adds r1, r3, 0x7 - movs r3, 0xE - ldrsh r0, [r0, r3] - subs r3, r1, r0 - cmp r2, r6 - bge _081A9A0E - negs r0, r6 - cmp r2, r0 - ble _081A9A0E - cmp r3, r6 - bge _081A9A0E - cmp r3, r0 - ble _081A9A0E - cmp r7, 0 - bne _081A9A84 -_081A9A0E: - cmp r2, 0 - ble _081A9A34 - cmp r3, 0 - ble _081A9A34 - movs r4, 0x3 - cmp r2, r3 - blt _081A9A7C - movs r4, 0x2 - b _081A9A7C - .pool -_081A9A34: - cmp r2, 0 - bge _081A9A46 - cmp r3, 0 - bge _081A9A46 - movs r4, 0x1 - cmp r2, r3 - ble _081A9A7C - movs r4, 0 - b _081A9A7C -_081A9A46: - cmp r2, 0 - bne _081A9A54 - movs r4, 0 - cmp r3, 0 - ble _081A9A7C - movs r4, 0x3 - b _081A9A7C -_081A9A54: - cmp r3, 0 - bne _081A9A62 - movs r4, 0x1 - cmp r2, 0 - ble _081A9A7C - movs r4, 0x2 - b _081A9A7C -_081A9A62: - cmp r2, 0 - bge _081A9A72 - adds r0, r2, r3 - movs r4, 0x1 - cmp r0, 0 - ble _081A9A7C - movs r4, 0x3 - b _081A9A7C -_081A9A72: - adds r0, r2, r3 - mvns r0, r0 - asrs r4, r0, 31 - movs r0, 0x2 - ands r4, r0 -_081A9A7C: - movs r0, 0 - mov r5, r10 - str r0, [r5] - b _081A9A98 -_081A9A84: - mov r0, r10 - str r7, [r0] - b _081A9A98 -_081A9A8A: - adds r2, 0x1 - cmp r2, 0x1F - ble _081A99CE - adds r5, 0x5E - adds r3, 0x1 - cmp r3, 0x1F - ble _081A99CC -_081A9A98: - adds r0, r4, 0 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81A9998 - - thumb_func_start sub_81A9AA8 -sub_81A9AA8: @ 81A9AA8 - lsls r0, 24 - ldr r1, =gSaveBlock2Ptr - ldr r1, [r1] - lsrs r0, 23 - adds r1, r0 - ldr r0, =0x00000cb2 - adds r1, r0 - ldrh r0, [r1] - bx lr - .pool - thumb_func_end sub_81A9AA8 - - thumb_func_start GetBattlePyramidTrainerFlag -GetBattlePyramidTrainerFlag: @ 81A9AC4 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gSaveBlock2Ptr - ldr r2, [r1] - ldr r1, =0x00000e2a - adds r2, r1 - ldr r4, =gBitTable - ldr r3, =gEventObjects - lsls r1, r0, 3 - adds r1, r0 - lsls r1, 2 - adds r1, r3 - ldrb r0, [r1, 0x8] - subs r0, 0x1 - lsls r0, 2 - adds r0, r4 - ldr r0, [r0] - ldrb r1, [r2] - ands r0, r1 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end GetBattlePyramidTrainerFlag - - thumb_func_start sub_81A9B04 -sub_81A9B04: @ 81A9B04 - push {lr} - ldr r0, =gTrainerBattleOpponent_A - ldrh r0, [r0] - bl sub_81A9B44 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 8 - ands r0, r1 - cmp r0, 0 - beq _081A9B2E - movs r0, 0x1 - bl GetChosenApproachingTrainerEventObjectId - ldr r1, =gSelectedEventObject - strb r0, [r1] - ldr r0, =gTrainerBattleOpponent_B - ldrh r0, [r0] - bl sub_81A9B44 -_081A9B2E: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9B04 - - thumb_func_start sub_81A9B44 -sub_81A9B44: @ 81A9B44 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - lsls r0, 16 - lsrs r5, r0, 16 - movs r3, 0 - ldr r0, =gEventObjects - mov r12, r0 - ldr r6, =gSelectedEventObject - ldr r1, =gSaveBlock1Ptr - mov r10, r1 - ldr r7, =gSaveBlock2Ptr - mov r9, r7 - ldr r0, =0x00000cb4 - mov r8, r0 - ldr r4, =gBitTable -_081A9B68: - mov r1, r9 - ldr r2, [r1] - lsls r0, r3, 1 - mov r7, r8 - adds r1, r2, r7 - adds r1, r0 - ldrh r0, [r1] - cmp r0, r5 - bne _081A9B86 - ldr r1, =0x00000e2a - adds r0, r2, r1 - ldr r1, [r4] - ldrb r2, [r0] - orrs r1, r2 - strb r1, [r0] -_081A9B86: - adds r4, 0x4 - adds r3, 0x1 - cmp r3, 0x7 - ble _081A9B68 - ldrb r1, [r6] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - add r0, r12 - movs r3, 0x2 - strb r3, [r0, 0x6] - mov r7, r10 - ldr r2, [r7] - ldr r0, =gSpecialVar_LastTalked - ldrh r1, [r0] - subs r1, 0x1 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 3 - adds r2, r0 - ldr r1, =0x00000c79 - adds r2, r1 - strb r3, [r2] - ldrb r1, [r6] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - add r0, r12 - ldrh r1, [r0, 0x10] - strh r1, [r0, 0xC] - ldrb r1, [r6] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - add r0, r12 - ldrh r1, [r0, 0x12] - strh r1, [r0, 0xE] - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9B44 - - thumb_func_start GenerateBattlePyramidWildMon -GenerateBattlePyramidWildMon: @ 81A9C04 - push {r4-r6,lr} - sub sp, 0x14 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r5, r0, 30 - lsls r0, r5, 1 - ldr r2, =0x00000e1a - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x14 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x13 - bls _081A9C3A - movs r0, 0x13 -_081A9C3A: - cmp r5, 0 - beq _081A9C54 - ldr r1, =gBattlePyramidOpenLevelWildMonPointers - b _081A9C56 - .pool -_081A9C54: - ldr r1, =gBattlePyramidLevel50WildMonPointers -_081A9C56: - lsls r0, 2 - adds r0, r1 - ldr r6, [r0] - ldr r4, =gEnemyParty - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - subs r0, 0x1 - str r0, [sp, 0x10] - lsls r2, r0, 1 - adds r2, r0 - lsls r2, 2 - adds r2, r6, r2 - adds r0, r4, 0 - movs r1, 0xB - bl SetMonData - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrh r1, [r0] - mov r0, sp - bl GetSpeciesName - adds r0, r4, 0 - movs r1, 0x2 - mov r2, sp - bl SetMonData - cmp r5, 0 - beq _081A9CD4 - bl SetFacilityPtrsGetLevel - lsls r0, 24 - lsrs r5, r0, 24 - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrb r0, [r0, 0x2] - subs r5, r0 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xB - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - subs r0, 0x5 - adds r5, r0 - b _081A9CF6 - .pool -_081A9CD4: - bl Random - ldr r2, [sp, 0x10] - lsls r1, r2, 1 - adds r1, r2 - lsls r1, 2 - adds r1, r6 - ldrb r4, [r1, 0x2] - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xB - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - subs r0, 0x5 - adds r5, r4, r0 -_081A9CF6: - ldr r4, =gEnemyParty - ldr r2, =gBaseStats - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrh r1, [r0] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r1, [r0, 0x13] - movs r0, 0xCA - lsls r0, 1 - adds r2, r1, 0 - muls r2, r0 - lsls r0, r5, 2 - ldr r1, =gExperienceTables - adds r0, r1 - adds r2, r0 - adds r0, r4, 0 - movs r1, 0x19 - bl SetMonData - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrb r1, [r0, 0x3] - cmp r1, 0 - blt _081A9D4C - cmp r1, 0x1 - bgt _081A9D4C - adds r2, r0, 0x3 - b _081A9D7C - .pool -_081A9D4C: - ldr r2, =gBaseStats - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrh r1, [r0] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x17] - cmp r0, 0 - beq _081A9D90 - ldr r4, =gEnemyParty - adds r0, r4, 0 - movs r1, 0 - movs r2, 0 - bl GetMonData - movs r1, 0x1 - ands r1, r0 - str r1, [sp, 0xC] - add r2, sp, 0xC -_081A9D7C: - adds r0, r4, 0 - movs r1, 0x2E - bl SetMonData - b _081A9D9C - .pool -_081A9D90: - str r0, [sp, 0xC] - ldr r0, =gEnemyParty - add r2, sp, 0xC - movs r1, 0x2E - bl SetMonData -_081A9D9C: - movs r0, 0 - str r0, [sp, 0xC] - movs r2, 0 - lsls r4, r5, 1 -_081A9DA4: - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - lsls r1, r2, 1 - adds r0, 0x4 - adds r0, r1 - ldrh r1, [r0] - lsls r2, 24 - lsrs r2, 24 - ldr r0, =gEnemyParty - bl SetMonMoveSlot - ldr r0, [sp, 0xC] - adds r0, 0x1 - str r0, [sp, 0xC] - adds r2, r0, 0 - cmp r2, 0x3 - ble _081A9DA4 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e1a - adds r0, r1 - adds r0, r4 - ldrh r0, [r0] - cmp r0, 0x8B - bls _081A9E0C - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x11 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - adds r0, 0xF - str r0, [sp, 0x10] - movs r0, 0 - str r0, [sp, 0xC] -_081A9DF6: - adds r1, r0, 0 - adds r1, 0x27 - ldr r0, =gEnemyParty - add r2, sp, 0x10 - bl SetMonData - ldr r0, [sp, 0xC] - adds r0, 0x1 - str r0, [sp, 0xC] - cmp r0, 0x5 - ble _081A9DF6 -_081A9E0C: - ldr r0, =gEnemyParty - bl CalculateMonStats - add sp, 0x14 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end GenerateBattlePyramidWildMon - - thumb_func_start sub_81A9E28 -sub_81A9E28: @ 81A9E28 - push {lr} - bl sub_81AA9E4 - lsls r0, 24 - ldr r1, =gUnknown_08613650 - lsrs r0, 20 - adds r0, r1 - ldrb r0, [r0, 0x4] - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A9E28 - - thumb_func_start InBattlePyramid -InBattlePyramid: @ 81A9E40 - push {lr} - ldr r0, =gMapHeader - ldrh r1, [r0, 0x12] - ldr r0, =0x00000169 - cmp r1, r0 - bne _081A9E58 - movs r0, 0x1 - b _081A9E66 - .pool -_081A9E58: - movs r0, 0xBD - lsls r0, 1 - cmp r1, r0 - beq _081A9E64 - movs r0, 0 - b _081A9E66 -_081A9E64: - movs r0, 0x2 -_081A9E66: - pop {r1} - bx r1 - thumb_func_end InBattlePyramid - - thumb_func_start sub_81A9E6C -sub_81A9E6C: @ 81A9E6C - push {lr} - movs r2, 0 - ldr r0, =gMapHeader - ldrh r1, [r0, 0x12] - ldr r0, =0x00000169 - cmp r1, r0 - beq _081A9E80 - adds r0, 0x11 - cmp r1, r0 - bne _081A9E82 -_081A9E80: - movs r2, 0x1 -_081A9E82: - adds r0, r2, 0 - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A9E6C - - thumb_func_start sub_81A9E90 -sub_81A9E90: @ 81A9E90 - push {lr} - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - beq _081A9EB8 - bl sub_81A9834 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000ca8 - adds r0, r1 - movs r1, 0x2 - strb r1, [r0] - ldr r0, =0x0000400e - movs r1, 0 - bl VarSet - bl LoadPlayerParty -_081A9EB8: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9E90 - - thumb_func_start sub_81A9EC8 -sub_81A9EC8: @ 81A9EC8 - push {lr} - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - beq _081A9ED8 - bl DoSoftReset -_081A9ED8: - pop {r0} - bx r0 - thumb_func_end sub_81A9EC8 - - thumb_func_start sub_81A9EDC -sub_81A9EDC: @ 81A9EDC - push {lr} - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gFacilityTrainers - movs r1, 0x34 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0xC - bl FrontierSpeechToString - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9EDC - - thumb_func_start sub_81A9EFC -sub_81A9EFC: @ 81A9EFC - push {lr} - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gFacilityTrainers - movs r1, 0x34 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0x18 - bl FrontierSpeechToString - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9EFC - - thumb_func_start sub_81A9F1C -sub_81A9F1C: @ 81A9F1C - push {lr} - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gFacilityTrainers - movs r1, 0x34 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0x24 - bl FrontierSpeechToString - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9F1C - - thumb_func_start GetTrainerEncounterMusicIdInBattlePyramind -GetTrainerEncounterMusicIdInBattlePyramind: @ 81A9F3C - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - movs r4, 0 - ldr r3, =gFacilityClassToTrainerClass - ldr r1, =gFacilityTrainers - ldr r2, [r1] - movs r1, 0x34 - muls r0, r1 - adds r0, r2 - ldrb r0, [r0] - adds r0, r3 - ldrb r2, [r0] - ldr r1, =gUnknown_08613B44 -_081A9F58: - ldrb r0, [r1] - cmp r0, r2 - bne _081A9F70 - ldrb r0, [r1, 0x1] - b _081A9F7A - .pool -_081A9F70: - adds r1, 0x4 - adds r4, 0x1 - cmp r4, 0x35 - bls _081A9F58 - movs r0, 0 -_081A9F7A: - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetTrainerEncounterMusicIdInBattlePyramind - - thumb_func_start sub_81A9F80 -sub_81A9F80: @ 81A9F80 - push {lr} - ldr r0, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88 - bl ScriptContext1_SetupScript - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9F80 - - thumb_func_start sub_81A9F90 -sub_81A9F90: @ 81A9F90 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, =gSaveBlock2Ptr - ldr r4, [r0] - ldr r1, =0x00000ca9 - adds r0, r4, r1 - ldrb r1, [r0] - lsls r1, 30 - lsrs r1, 29 - ldr r2, =0x00000e1a - adds r0, r4, r2 - adds r0, r1 - ldrh r0, [r0] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - ldr r1, =0x00000cb2 - adds r4, r1 - ldrh r1, [r4] - cmp r1, 0x7 - bne _081AA020 - adds r0, 0x1 - lsls r7, r0, 24 - lsls r1, 24 - mov r8, r1 -_081A9FCC: - lsrs r0, r7, 24 - mov r2, r8 - lsrs r1, r2, 24 - bl sub_8162548 - lsls r0, 16 - lsrs r3, r0, 16 - movs r2, 0 - cmp r2, r5 - bge _081AA004 - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r4, =0x00000cb4 - adds r0, r4 - ldrh r0, [r0] - cmp r0, r3 - beq _081AA004 - adds r6, r1, 0 -_081A9FF0: - adds r2, 0x1 - cmp r2, r5 - bge _081AA004 - ldr r0, [r6] - lsls r1, r2, 1 - adds r0, r4 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r3 - bne _081A9FF0 -_081AA004: - cmp r2, r5 - bne _081A9FCC - b _081AA062 - .pool -_081AA020: - lsls r1, 24 - mov r8, r1 - lsls r7, r0, 24 -_081AA026: - lsrs r0, r7, 24 - mov r2, r8 - lsrs r1, r2, 24 - bl sub_8162548 - lsls r0, 16 - lsrs r3, r0, 16 - movs r2, 0 - cmp r2, r5 - bge _081AA05E - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r4, =0x00000cb4 - adds r0, r4 - ldrh r0, [r0] - cmp r0, r3 - beq _081AA05E - adds r6, r1, 0 -_081AA04A: - adds r2, 0x1 - cmp r2, r5 - bge _081AA05E - ldr r0, [r6] - lsls r1, r2, 1 - adds r0, r4 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r3 - bne _081AA04A -_081AA05E: - cmp r2, r5 - bne _081AA026 -_081AA062: - adds r0, r3, 0 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A9F90 - - thumb_func_start sub_81AA078 -sub_81AA078: @ 81AA078 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x1C - str r0, [sp, 0x4] - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x8] - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0xC] - bl sub_81AA96C - mov r4, sp - adds r4, 0x1 - mov r0, sp - adds r1, r4, 0 - bl sub_81AA33C - movs r7, 0 -_081AA0A6: - ldr r1, [sp, 0xC] - adds r0, r1, r7 - ldrb r0, [r0] - ldr r2, =0x00000169 - adds r0, r2 - lsls r0, 2 - ldr r1, =gMapLayouts - adds r0, r1 - ldr r6, [r0] - ldr r2, [r6, 0xC] - mov r10, r2 - ldr r0, [sp, 0x4] - ldr r1, =gUnknown_03005DC0 - str r0, [r1, 0x8] - ldr r0, [r6] - lsls r0, 2 - adds r2, r0, 0 - adds r2, 0xF - str r2, [r1] - ldr r0, [r6, 0x4] - lsls r0, 2 - adds r0, 0xE - str r0, [r1, 0x4] - ldr r0, [sp, 0x4] - mov r9, r0 - adds r1, r7, 0 - cmp r7, 0 - bge _081AA0E0 - adds r1, r7, 0x3 -_081AA0E0: - asrs r1, 2 - ldr r4, [r6, 0x4] - adds r0, r1, 0 - muls r0, r4 - adds r0, 0x7 - muls r2, r0 - lsls r1, 2 - subs r1, r7, r1 - ldr r3, [r6] - adds r0, r1, 0 - muls r0, r3 - adds r0, 0x7 - adds r2, r0 - lsls r2, 1 - add r9, r2 - movs r1, 0 - mov r8, r1 - adds r2, r7, 0x1 - str r2, [sp, 0x10] - cmp r8, r4 - bge _081AA1B6 -_081AA10A: - movs r0, 0 - mov r12, r0 - mov r1, r8 - adds r1, 0x1 - str r1, [sp, 0x14] - cmp r12, r3 - bge _081AA1A2 - ldr r2, =gSaveBlock1Ptr - str r2, [sp, 0x18] - mov r4, r9 - mov r5, r10 -_081AA120: - ldrh r1, [r5] - ldr r0, =0x000003ff - ands r0, r1 - ldr r2, =0x0000028e - cmp r0, r2 - bne _081AA194 - mov r0, sp - ldrb r0, [r0, 0x1] - cmp r7, r0 - beq _081AA194 - mov r0, sp - ldrb r0, [r0] - cmp r7, r0 - bne _081AA164 - ldr r1, [sp, 0x8] - cmp r1, 0 - bne _081AA164 - ldr r2, [sp, 0x18] - ldr r3, [r2] - adds r2, r7, 0 - cmp r7, 0 - bge _081AA14E - adds r2, r7, 0x3 -_081AA14E: - asrs r2, 2 - lsls r1, r2, 2 - subs r1, r7, r1 - ldr r0, [r6] - muls r0, r1 - add r0, r12 - strh r0, [r3] - ldr r0, [r6, 0x4] - muls r0, r2 - add r0, r8 - strh r0, [r3, 0x2] -_081AA164: - ldrh r0, [r5] - movs r1, 0xFC - lsls r1, 8 - ands r1, r0 - ldr r2, =0x0000028d - adds r0, r2, 0 - orrs r1, r0 - strh r1, [r4] - ldr r3, [r6] - b _081AA196 - .pool -_081AA194: - strh r1, [r4] -_081AA196: - adds r4, 0x2 - adds r5, 0x2 - movs r0, 0x1 - add r12, r0 - cmp r12, r3 - blt _081AA120 -_081AA1A2: - lsls r0, r3, 3 - adds r0, 0x1E - add r9, r0 - lsls r0, r3, 1 - add r10, r0 - ldr r1, [sp, 0x14] - mov r8, r1 - ldr r0, [r6, 0x4] - cmp r8, r0 - blt _081AA10A -_081AA1B6: - ldr r7, [sp, 0x10] - cmp r7, 0xF - bgt _081AA1BE - b _081AA0A6 -_081AA1BE: - bl mapheader_run_script_with_tag_x1 - ldr r0, [sp, 0xC] - bl Free - add sp, 0x1C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81AA078 - - thumb_func_start sub_81AA1D8 -sub_81AA1D8: @ 81AA1D8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - movs r5, 0 - mov r6, sp - adds r6, 0x1 - add r0, sp, 0x4 - mov r8, r0 - ldr r4, =gSaveBlock2Ptr - ldr r3, =0x00000cb4 - ldr r0, =0x0000ffff - adds r2, r0, 0 -_081AA1F2: - ldr r0, [r4] - lsls r1, r5, 1 - adds r0, r3 - adds r0, r1 - ldrh r1, [r0] - orrs r1, r2 - strh r1, [r0] - adds r5, 0x1 - cmp r5, 0x7 - ble _081AA1F2 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r7, r0, 24 - mov r0, sp - adds r1, r6, 0 - bl sub_81AA33C - movs r0, 0 - str r0, [sp, 0x4] - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - movs r0, 0xC7 - lsls r0, 4 - adds r1, r0 - ldr r2, =0x05000180 - mov r0, r8 - bl CpuSet - movs r5, 0 -_081AA22E: - cmp r5, 0 - bne _081AA254 - ldr r1, =gUnknown_08613650 - lsls r0, r7, 4 - adds r0, r1 - ldrb r0, [r0, 0x3] - b _081AA25C - .pool -_081AA254: - ldr r1, =gUnknown_08613650 - lsls r0, r7, 4 - adds r0, r1 - ldrb r0, [r0, 0x2] -_081AA25C: - cmp r0, 0x4 - bhi _081AA2E4 - lsls r0, 2 - ldr r1, =_081AA274 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081AA274: - .4byte _081AA288 - .4byte _081AA292 - .4byte _081AA2A2 - .4byte _081AA2B0 - .4byte _081AA2CC -_081AA288: - lsls r0, r5, 24 - lsrs r0, 24 - bl sub_81AA398 - b _081AA2E4 -_081AA292: - lsls r0, r5, 24 - lsrs r4, r0, 24 - mov r0, sp - ldrb r1, [r0] - adds r0, r4, 0 - bl sub_81AA4D8 - b _081AA2BE -_081AA2A2: - lsls r0, r5, 24 - lsrs r4, r0, 24 - ldrb r1, [r6] - adds r0, r4, 0 - bl sub_81AA4D8 - b _081AA2BE -_081AA2B0: - lsls r0, r5, 24 - lsrs r4, r0, 24 - mov r0, sp - ldrb r1, [r0] - adds r0, r4, 0 - bl sub_81AA648 -_081AA2BE: - lsls r0, 24 - cmp r0, 0 - beq _081AA2E4 - adds r0, r4, 0 - bl sub_81AA398 - b _081AA2E4 -_081AA2CC: - lsls r0, r5, 24 - lsrs r4, r0, 24 - ldrb r1, [r6] - adds r0, r4, 0 - bl sub_81AA648 - lsls r0, 24 - cmp r0, 0 - beq _081AA2E4 - adds r0, r4, 0 - bl sub_81AA398 -_081AA2E4: - adds r5, 0x1 - cmp r5, 0x1 - ble _081AA22E - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81AA1D8 - - thumb_func_start sub_81AA2F8 -sub_81AA2F8: @ 81AA2F8 - push {r4,r5,lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r5, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F - ldr r4, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A - movs r2, 0xC8 - lsls r2, 4 - adds r1, r0, r2 - movs r3, 0xC7 - lsls r3, 4 - adds r2, r0, r3 - movs r3, 0x3F -_081AA310: - ldrb r0, [r2, 0x1] - cmp r0, 0x3B - beq _081AA328 - str r5, [r1] - b _081AA32A - .pool -_081AA328: - str r4, [r1] -_081AA32A: - adds r1, 0x18 - adds r2, 0x18 - subs r3, 0x1 - cmp r3, 0 - bge _081AA310 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_81AA2F8 - - thumb_func_start sub_81AA33C -sub_81AA33C: @ 81AA33C - push {r4-r7,lr} - adds r4, r0, 0 - adds r6, r1, 0 - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - ldr r2, =0x00000e28 - adds r0, r1, r2 - ldrh r2, [r0] - movs r3, 0xF - ands r2, r3 - strb r2, [r4] - ldr r7, =0x00000e22 - adds r1, r7 - ldrh r0, [r1] - ands r0, r3 - strb r0, [r6] - cmp r2, r0 - bne _081AA386 - ldr r1, [r5] - ldr r2, =0x00000e28 - adds r0, r1, r2 - ldrh r2, [r0] - adds r3, r2, 0x1 - adds r0, r3, 0 - asrs r0, 4 - lsls r0, 4 - subs r0, r3, r0 - strb r0, [r4] - adds r0, r1, r7 - ldrh r1, [r0] - adds r2, r1, 0 - adds r2, 0xF - adds r0, r2, 0 - asrs r0, 4 - lsls r0, 4 - subs r0, r2, r0 - strb r0, [r6] -_081AA386: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AA33C - - thumb_func_start sub_81AA398 -sub_81AA398: @ 81AA398 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - movs r5, 0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r6, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x8] - bl sub_81AA96C - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e26 - adds r0, r1 - ldrh r4, [r0] - movs r0, 0xF - ands r4, r0 - ldr r0, [sp] - cmp r0, 0 - bne _081AA3F0 - ldr r1, =gUnknown_08613650 - lsls r0, r6, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - mov r10, r0 - movs r1, 0 - str r1, [sp, 0x4] - b _081AA3FE - .pool -_081AA3F0: - ldr r1, =gUnknown_08613650 - lsls r0, r6, 4 - adds r0, r1 - ldrb r1, [r0] - mov r10, r1 - ldrb r0, [r0, 0x1] - str r0, [sp, 0x4] -_081AA3FE: - movs r0, 0 - mov r8, r0 - cmp r8, r10 - bge _081AA4C0 -_081AA406: - movs r1, 0x1 - add r1, r8 - mov r9, r1 - b _081AA42E - .pool -_081AA414: - lsls r2, r4, 24 - lsrs r2, 24 - ldr r3, [sp, 0x4] - add r3, r8 - lsls r3, 24 - lsrs r3, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA4B6 -_081AA42E: - ldr r0, =gBitTable - mov r12, r0 - ldr r6, =gSaveBlock2Ptr - ldr r7, =0x00000e28 - movs r3, 0x2 - lsls r0, r4, 2 - mov r1, r12 - adds r2, r0, r1 -_081AA43E: - movs r0, 0x1 - ands r0, r5 - cmp r0, 0 - beq _081AA464 - ldr r0, [r6] - adds r0, r7 - ldrh r1, [r0] - ldr r0, [r2] - ands r0, r1 - cmp r0, 0 - bne _081AA474 - b _081AA472 - .pool -_081AA464: - ldr r0, [r6] - adds r0, r7 - ldrh r1, [r0] - ldr r0, [r2] - ands r0, r1 - cmp r0, 0 - beq _081AA474 -_081AA472: - orrs r5, r3 -_081AA474: - adds r2, 0x4 - adds r4, 0x1 - cmp r4, 0xF - ble _081AA480 - mov r2, r12 - movs r4, 0 -_081AA480: - ldr r0, [r6] - ldr r1, =0x00000e26 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0xF - ands r1, r0 - cmp r4, r1 - bne _081AA4A6 - movs r1, 0x1 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0 - beq _081AA4A4 - movs r0, 0x6 - orrs r5, r0 - b _081AA4A6 - .pool -_081AA4A4: - orrs r5, r1 -_081AA4A6: - adds r0, r5, 0 - ands r0, r3 - cmp r0, 0 - beq _081AA43E - movs r0, 0x4 - ands r0, r5 - cmp r0, 0 - beq _081AA414 -_081AA4B6: - movs r0, 0x1 - ands r5, r0 - mov r8, r9 - cmp r8, r10 - blt _081AA406 -_081AA4C0: - ldr r0, [sp, 0x8] - bl Free - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81AA398 - - thumb_func_start sub_81AA4D8 -sub_81AA4D8: @ 81AA4D8 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x4] - movs r6, 0 - movs r7, 0 - movs r0, 0 - str r0, [sp, 0xC] - bl sub_81AA9E4 - lsls r0, 24 - lsrs r4, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x14] - bl sub_81AA96C - ldr r1, [sp] - cmp r1, 0 - bne _081AA524 - ldr r1, =gUnknown_08613650 - lsls r0, r4, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - str r0, [sp, 0x10] - movs r0, 0 - b _081AA530 - .pool -_081AA524: - ldr r1, =gUnknown_08613650 - lsls r0, r4, 4 - adds r0, r1 - ldrb r2, [r0] - str r2, [sp, 0x10] - ldrb r0, [r0, 0x1] -_081AA530: - movs r3, 0 - str r3, [sp, 0x8] - ldr r1, [sp, 0x10] - asrs r1, 31 - str r1, [sp, 0x18] - ldr r2, [sp, 0x10] - cmp r3, r2 - bge _081AA622 - str r0, [sp, 0x1C] - adds r3, r0, 0 - lsls r3, 24 - mov r9, r3 -_081AA548: - cmp r7, 0 - bne _081AA56E - mov r0, r9 - lsrs r3, r0, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - ldr r2, [sp, 0x4] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA568 - movs r7, 0x1 - b _081AA56E - .pool -_081AA568: - ldr r1, [sp, 0xC] - adds r1, 0x1 - str r1, [sp, 0xC] -_081AA56E: - movs r0, 0x1 - ands r0, r7 - cmp r0, 0 - beq _081AA600 - ldr r2, =gUnknown_08613F46 - mov r8, r2 - ldr r3, [sp, 0x4] - lsls r4, r3, 2 - adds r0, r6, r4 - add r0, r8 - ldrb r2, [r0] - mov r0, r9 - lsrs r3, r0, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - bl sub_81AA760 - lsls r0, 24 - ldr r1, [sp, 0x1C] - mov r10, r1 - adds r5, r4, 0 - cmp r0, 0 - beq _081AA5E8 - ldr r4, [sp, 0xC] - adds r4, 0x1 - b _081AA5C2 - .pool -_081AA5A8: - adds r0, r6, r5 - adds r0, r2 - ldrb r2, [r0] - mov r0, r10 - lsls r3, r0, 24 - lsrs r3, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA5E0 -_081AA5C2: - adds r6, 0x1 - ldr r0, =gUnknown_08613F46 - adds r1, r6, r5 - adds r1, r0 - ldrb r1, [r1] - adds r2, r0, 0 - cmp r1, 0xFF - beq _081AA5D6 - cmp r6, 0x3 - ble _081AA5D8 -_081AA5D6: - movs r6, 0 -_081AA5D8: - adds r7, 0x2 - asrs r0, r7, 1 - cmp r0, 0x4 - bne _081AA5A8 -_081AA5E0: - str r4, [sp, 0xC] - b _081AA600 - .pool -_081AA5E8: - adds r6, 0x1 - adds r0, r6, r4 - add r0, r8 - ldrb r0, [r0] - cmp r0, 0xFF - beq _081AA5F8 - cmp r6, 0x3 - ble _081AA5FA -_081AA5F8: - movs r6, 0 -_081AA5FA: - ldr r1, [sp, 0xC] - adds r1, 0x1 - str r1, [sp, 0xC] -_081AA600: - asrs r0, r7, 1 - cmp r0, 0x4 - beq _081AA622 - movs r0, 0x1 - ands r7, r0 - ldr r2, [sp, 0x1C] - adds r2, 0x1 - str r2, [sp, 0x1C] - movs r3, 0x80 - lsls r3, 17 - add r9, r3 - ldr r0, [sp, 0x8] - adds r0, 0x1 - str r0, [sp, 0x8] - ldr r1, [sp, 0x10] - cmp r0, r1 - blt _081AA548 -_081AA622: - movs r1, 0 - ldr r2, [sp, 0x10] - ldr r3, [sp, 0x18] - subs r0, r2, r3 - asrs r0, 1 - ldr r2, [sp, 0xC] - cmp r0, r2 - ble _081AA634 - movs r1, 0x1 -_081AA634: - adds r0, r1, 0 - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA4D8 - - thumb_func_start sub_81AA648 -sub_81AA648: @ 81AA648 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r6, r1, 24 - movs r4, 0 - movs r7, 0 - movs r0, 0 - mov r8, r0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r5, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x8] - bl sub_81AA96C - ldr r1, [sp] - cmp r1, 0 - bne _081AA694 - ldr r1, =gUnknown_08613650 - lsls r0, r5, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - mov r10, r0 - movs r0, 0 - b _081AA6A0 - .pool -_081AA694: - ldr r1, =gUnknown_08613650 - lsls r0, r5, 4 - adds r0, r1 - ldrb r2, [r0] - mov r10, r2 - ldrb r0, [r0, 0x1] -_081AA6A0: - movs r3, 0 - str r3, [sp, 0x4] - mov r1, r10 - asrs r1, 31 - str r1, [sp, 0xC] - cmp r3, r10 - bge _081AA73E - ldr r2, =gUnknown_08613F46 - mov r9, r2 - lsls r5, r6, 2 - lsls r6, r0, 24 -_081AA6B6: - adds r0, r4, r5 - add r0, r9 - ldrb r2, [r0] - lsrs r3, r6, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA714 - adds r7, 0x1 - b _081AA6EE - .pool -_081AA6D8: - adds r0, r4, r5 - adds r0, r1 - ldrb r2, [r0] - lsrs r3, r6, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA728 -_081AA6EE: - adds r4, 0x1 - adds r0, r4, r5 - add r0, r9 - ldrb r0, [r0] - ldr r1, =gUnknown_08613F46 - cmp r0, 0xFF - beq _081AA700 - cmp r4, 0x3 - ble _081AA702 -_081AA700: - movs r4, 0 -_081AA702: - movs r3, 0x1 - add r8, r3 - mov r0, r8 - cmp r0, 0x4 - bne _081AA6D8 - b _081AA728 - .pool -_081AA714: - adds r4, 0x1 - adds r0, r4, r5 - add r0, r9 - ldrb r0, [r0] - cmp r0, 0xFF - beq _081AA724 - cmp r4, 0x3 - ble _081AA726 -_081AA724: - movs r4, 0 -_081AA726: - adds r7, 0x1 -_081AA728: - mov r1, r8 - cmp r1, 0x4 - beq _081AA73E - movs r2, 0x80 - lsls r2, 17 - adds r6, r2 - ldr r3, [sp, 0x4] - adds r3, 0x1 - str r3, [sp, 0x4] - cmp r3, r10 - blt _081AA6B6 -_081AA73E: - movs r1, 0 - mov r2, r10 - ldr r3, [sp, 0xC] - subs r0, r2, r3 - asrs r0, 1 - cmp r0, r7 - ble _081AA74E - movs r1, 0x1 -_081AA74E: - adds r0, r1, 0 - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA648 - - thumb_func_start sub_81AA760 -sub_81AA760: @ 81AA760 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - mov r10, r1 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r3, 24 - lsrs r7, r3, 24 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e22 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081AA7D0 - movs r6, 0x7 -_081AA792: - movs r4, 0x7 - lsls r5, r6, 24 -_081AA796: - lsls r1, r4, 24 - lsrs r1, 24 - mov r0, r8 - str r0, [sp] - str r7, [sp, 0x4] - mov r0, r9 - lsrs r2, r5, 24 - mov r3, r10 - bl sub_81AA810 - lsls r0, 24 - cmp r0, 0 - beq _081AA7CC - subs r4, 0x1 - cmp r4, 0 - bge _081AA796 - subs r6, 0x1 - movs r1, 0x1 - negs r1, r1 - cmp r6, r1 - bgt _081AA792 - b _081AA7FC - .pool -_081AA7CC: - movs r0, 0 - b _081AA7FE -_081AA7D0: - movs r6, 0 -_081AA7D2: - movs r4, 0 - lsls r5, r6, 24 -_081AA7D6: - lsls r1, r4, 24 - lsrs r1, 24 - mov r0, r8 - str r0, [sp] - str r7, [sp, 0x4] - mov r0, r9 - lsrs r2, r5, 24 - mov r3, r10 - bl sub_81AA810 - lsls r0, 24 - cmp r0, 0 - beq _081AA7CC - adds r4, 0x1 - cmp r4, 0x7 - ble _081AA7D6 - adds r6, 0x1 - cmp r6, 0x7 - ble _081AA7D2 -_081AA7FC: - movs r0, 0x1 -_081AA7FE: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA760 - - thumb_func_start sub_81AA810 -sub_81AA810: @ 81AA810 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x14 - ldr r4, [sp, 0x34] - ldr r5, [sp, 0x38] - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x4] - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r4, 24 - lsrs r4, 24 - mov r10, r4 - lsls r5, 24 - lsrs r6, r5, 24 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r1, r0, r1 - str r1, [sp, 0x8] - add r3, r10 - ldrb r1, [r3] - adds r1, 0x2C - movs r0, 0x19 - bl Overworld_GetMapHeaderByGroupAndId - adds r5, r0, 0 - movs r7, 0 - ldr r1, [r5, 0x4] - ldrb r2, [r1] - cmp r7, r2 - bge _081AA95A - movs r0, 0x3 - ands r0, r4 - lsls r0, 3 - str r0, [sp, 0xC] -_081AA868: - ldr r1, [r1, 0x4] - lsls r2, r7, 1 - adds r0, r2, r7 - lsls r0, 3 - adds r3, r0, r1 - movs r4, 0x4 - ldrsh r0, [r3, r4] - ldr r1, [r5, 0x4] - mov r12, r1 - mov r9, r2 - ldr r2, [sp, 0x4] - cmp r0, r2 - bne _081AA950 - movs r4, 0x6 - ldrsh r0, [r3, r4] - cmp r0, r8 - bne _081AA950 - ldr r0, [sp] - cmp r0, 0 - bne _081AA896 - ldrb r0, [r3, 0x1] - cmp r0, 0x3B - bne _081AA8A2 -_081AA896: - ldr r1, [sp] - cmp r1, 0x1 - bne _081AA950 - ldrb r0, [r3, 0x1] - cmp r0, 0x3B - bne _081AA950 -_081AA8A2: - movs r3, 0 - ldr r2, [r5, 0x4] - mov r12, r2 - cmp r3, r6 - bge _081AA8DC - ldr r4, [sp, 0x4] - ldr r0, [sp, 0xC] - adds r4, r0 - str r4, [sp, 0x10] - mov r1, r10 - lsrs r0, r1, 2 - lsls r0, 3 - mov r2, r8 - adds r1, r2, r0 - ldr r2, [sp, 0x8] - adds r2, 0x4 -_081AA8C2: - movs r4, 0 - ldrsh r0, [r2, r4] - ldr r4, [sp, 0x10] - cmp r0, r4 - bne _081AA8D4 - movs r4, 0x2 - ldrsh r0, [r2, r4] - cmp r0, r1 - beq _081AA8DC -_081AA8D4: - adds r2, 0x18 - adds r3, 0x1 - cmp r3, r6 - blt _081AA8C2 -_081AA8DC: - cmp r3, r6 - bne _081AA950 - lsls r0, r6, 1 - mov r8, r0 - adds r0, r6 - lsls r0, 3 - ldr r1, [sp, 0x8] - adds r5, r0, r1 - mov r3, r12 - ldr r2, [r3, 0x4] - mov r4, r9 - adds r1, r4, r7 - lsls r1, 3 - adds r0, r5, 0 - adds r1, r2 - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - ldrh r0, [r5, 0x4] - ldr r1, [sp, 0xC] - adds r0, r1 - strh r0, [r5, 0x4] - mov r2, r10 - lsrs r0, r2, 2 - lsls r0, 3 - ldrh r3, [r5, 0x6] - adds r0, r3 - strh r0, [r5, 0x6] - adds r0, r6, 0x1 - strb r0, [r5] - ldrb r0, [r5, 0x1] - cmp r0, 0x3B - beq _081AA940 - adds r0, r6, 0 - bl sub_81A9F90 - lsls r0, 16 - lsrs r7, r0, 16 - adds r4, r7, 0 - adds r0, r4, 0 - bl GetBattleFacilityTrainerGfxId - strb r0, [r5, 0x1] - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000cb4 - adds r0, r1 - add r0, r8 - strh r4, [r0] -_081AA940: - movs r0, 0 - b _081AA95C - .pool -_081AA950: - adds r7, 0x1 - mov r1, r12 - ldrb r2, [r1] - cmp r7, r2 - blt _081AA868 -_081AA95A: - movs r0, 0x1 -_081AA95C: - add sp, 0x14 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA810 - - thumb_func_start sub_81AA96C -sub_81AA96C: @ 81AA96C - push {r4-r7,lr} - adds r6, r0, 0 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000e22 - adds r1, r0, r2 - ldrh r4, [r1] - ldr r1, =0x00000e24 - adds r0, r1 - ldrh r0, [r0] - lsls r0, 16 - orrs r4, r0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r5, r0, 24 - movs r3, 0 - ldr r2, =gUnknown_08613650+0x5 - mov r12, r2 - movs r7, 0x7 -_081AA994: - adds r2, r6, r3 - adds r0, r4, 0 - ands r0, r7 - lsls r1, r5, 4 - adds r0, r1 - add r0, r12 - ldrb r0, [r0] - strb r0, [r2] - asrs r4, 3 - cmp r3, 0x7 - bne _081AA9C0 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000e26 - adds r0, r1, r2 - ldrh r4, [r0] - ldr r0, =0x00000e28 - adds r1, r0 - ldrh r0, [r1] - lsls r0, 16 - orrs r4, r0 - asrs r4, 8 -_081AA9C0: - adds r3, 0x1 - cmp r3, 0xF - ble _081AA994 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AA96C - - thumb_func_start sub_81AA9E4 -sub_81AA9E4: @ 81AA9E4 - push {r4,lr} - ldr r0, =gSaveBlock2Ptr - ldr r4, [r0] - ldr r1, =0x00000e28 - adds r0, r4, r1 - ldrh r0, [r0] - movs r1, 0x64 - bl __umodsi3 - lsls r0, 16 - lsrs r3, r0, 16 - ldr r0, =0x00000cb2 - adds r4, r0 - ldrh r0, [r4] - ldr r1, =gUnknown_08613794 - adds r0, r1 - ldrb r2, [r0] - cmp r2, 0x21 - bhi _081AAA38 - ldr r1, =gUnknown_08613750 - lsls r0, r2, 1 - adds r0, r1 -_081AAA10: - ldrb r1, [r0] - cmp r3, r1 - bge _081AAA30 - ldrb r0, [r0, 0x1] - b _081AAA3A - .pool -_081AAA30: - adds r0, 0x2 - adds r2, 0x1 - cmp r2, 0x21 - bls _081AAA10 -_081AAA38: - movs r0, 0 -_081AAA3A: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81AA9E4 - - thumb_func_start sub_81AAA40 -sub_81AAA40: @ 81AAA40 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r2, r0, r1 - movs r1, 0 - movs r3, 0xC7 - lsls r3, 4 - adds r0, r3 - b _081AAA6E - .pool -_081AAA5C: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0xF - bhi _081AAA74 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 3 - adds r0, r2 -_081AAA6E: - ldrb r0, [r0] - cmp r0, 0 - bne _081AAA5C -_081AAA74: - adds r0, r1, 0 - pop {r1} - bx r1 - thumb_func_end sub_81AAA40 - - thumb_func_start sub_81AAA7C -sub_81AAA7C: @ 81AAA7C - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r0, 24 - movs r3, 0 - ldr r1, =gSaveBlock2Ptr - mov r8, r1 - lsls r1, r0, 2 - adds r1, r0 - movs r0, 0 - mov r12, r0 - lsls r4, r1, 1 - ldr r7, =0x00000e2c - movs r6, 0 - ldr r5, =0x00000e54 - lsls r2, r1, 2 -_081AAA9E: - mov r1, r8 - ldr r0, [r1] - adds r1, r0, r7 - adds r1, r2 - strh r6, [r1] - adds r1, r3, r4 - adds r0, r5 - adds r0, r1 - mov r1, r12 - strb r1, [r0] - adds r2, 0x2 - adds r3, 0x1 - cmp r3, 0x9 - ble _081AAA9E - movs r0, 0x15 - movs r1, 0x1 - bl AddPyramidBagItem - movs r0, 0x22 - movs r1, 0x1 - bl AddPyramidBagItem - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AAA7C - - thumb_func_start GetBattlePyramidPickupItemId -GetBattlePyramidPickupItemId: @ 81AAAE0 - push {r4-r6,lr} - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r6, r0, 30 - lsls r0, r6, 1 - ldr r2, =0x00000e1a - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x13 - ble _081AAB0A - movs r4, 0x13 -_081AAB0A: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x64 - bl __umodsi3 - lsls r0, 16 - lsrs r2, r0, 16 - movs r1, 0 - ldr r3, =gUnknown_08613F86 - ldrb r0, [r3] - lsls r5, r4, 2 - cmp r0, r2 - bgt _081AAB36 -_081AAB28: - adds r1, 0x1 - cmp r1, 0x9 - bhi _081AAB3A - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - ble _081AAB28 -_081AAB36: - cmp r1, 0x9 - bls _081AAB3C -_081AAB3A: - movs r1, 0x9 -_081AAB3C: - cmp r6, 0 - bne _081AAB58 - ldr r2, =gUnknown_0861379C - b _081AAB5A - .pool -_081AAB58: - ldr r2, =gUnknown_0861392C -_081AAB5A: - lsls r1, 1 - adds r0, r5, r4 - lsls r0, 2 - adds r1, r0 - adds r1, r2 - ldrh r0, [r1] - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end GetBattlePyramidPickupItemId - .align 2, 0 @ Don't pad with nop. diff --git a/asm/battle_pyramid.s b/asm/battle_pyramid.s new file mode 100644 index 000000000..8d1c5b6b6 --- /dev/null +++ b/asm/battle_pyramid.s @@ -0,0 +1,2421 @@ + .include "asm/macros.inc" + .include "constants/constants.inc" + + .syntax unified + + .text + + + + + thumb_func_start sub_81A9834 +sub_81A9834: @ 81A9834 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + sub sp, 0x18 + movs r0, 0 + str r0, [sp] +_081A9844: + ldr r0, =gSaveBlock2Ptr + ldr r0, [r0] + ldr r2, [sp] + lsls r1, r2, 1 + ldr r5, =0x00000caa + adds r0, r5 + adds r0, r1 + ldrh r0, [r0] + subs r5, r0, 0x1 + movs r0, 0 + str r0, [sp, 0x4] + movs r2, 0x64 + adds r1, r5, 0 + muls r1, r2 + str r1, [sp, 0x8] + movs r0, 0x8E + lsls r0, 2 + adds r6, r1, r0 + movs r1, 0 + str r1, [sp, 0x10] +_081A986C: + ldr r2, =gSaveBlock1Ptr + ldr r0, [r2] + adds r0, r6 + movs r1, 0xB + movs r2, 0 + bl GetMonData + adds r4, r0, 0 + ldr r3, =gPlayerParty + ldr r1, [sp, 0x10] + adds r0, r1, r3 + movs r1, 0xB + movs r2, 0 + str r3, [sp, 0x14] + bl GetMonData + ldr r3, [sp, 0x14] + cmp r4, r0 + bne _081A993C + movs r6, 0 + adds r2, r5, 0x1 + str r2, [sp, 0xC] + movs r1, 0x64 + adds r0, r5, 0 + muls r0, r1 + movs r5, 0x8E + lsls r5, 2 + adds r5, r0 + mov r9, r5 + ldr r7, [sp, 0x4] + muls r7, r1 + mov r10, r3 +_081A98AC: + movs r5, 0 + adds r0, r6, 0x1 + mov r8, r0 + b _081A98C6 + .pool +_081A98C4: + adds r5, 0x1 +_081A98C6: + cmp r5, 0x3 + bgt _081A98EE + ldr r1, =gSaveBlock1Ptr + ldr r0, [r1] + add r0, r9 + adds r1, r5, 0 + adds r1, 0xD + movs r2, 0 + bl GetMonData + adds r4, r0, 0 + adds r1, r6, 0 + adds r1, 0xD + mov r2, r10 + adds r0, r7, r2 + movs r2, 0 + bl GetMonData + cmp r4, r0 + bne _081A98C4 +_081A98EE: + cmp r5, 0x4 + bne _081A9900 + lsls r2, r6, 24 + lsrs r2, 24 + mov r5, r10 + adds r0, r7, r5 + movs r1, 0xA6 + bl SetMonMoveSlot +_081A9900: + mov r6, r8 + cmp r6, 0x3 + ble _081A98AC + ldr r1, =gSaveBlock1Ptr + ldr r0, [r1] + ldr r2, [sp, 0x8] + adds r0, r2 + movs r5, 0x8E + lsls r5, 2 + adds r0, r5 + ldr r1, =gPlayerParty + ldr r2, [sp, 0x10] + adds r1, r2, r1 + movs r2, 0x64 + bl memcpy + ldr r0, =gUnknown_0203CEF8 + ldr r5, [sp, 0x4] + adds r0, r5, r0 + mov r1, sp + ldrb r1, [r1, 0xC] + strb r1, [r0] + b _081A994C + .pool +_081A993C: + ldr r2, [sp, 0x10] + adds r2, 0x64 + str r2, [sp, 0x10] + ldr r0, [sp, 0x4] + adds r0, 0x1 + str r0, [sp, 0x4] + cmp r0, 0x2 + ble _081A986C +_081A994C: + ldr r1, [sp] + adds r1, 0x1 + str r1, [sp] + cmp r1, 0x2 + bgt _081A9958 + b _081A9844 +_081A9958: + movs r2, 0 + str r2, [sp] + ldr r4, =gSaveBlock2Ptr + ldr r3, =0x00000caa + ldr r2, =gUnknown_0203CEF8 +_081A9962: + ldr r1, [r4] + ldr r5, [sp] + lsls r0, r5, 1 + adds r1, r3 + adds r1, r0 + adds r0, r5, r2 + ldrb r0, [r0] + strh r0, [r1] + adds r5, 0x1 + str r5, [sp] + cmp r5, 0x2 + ble _081A9962 + add sp, 0x18 + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r0} + bx r0 + .pool + thumb_func_end sub_81A9834 + + thumb_func_start sub_81A9998 +sub_81A9998: @ 81A9998 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + mov r10, r0 + lsls r1, 24 + lsrs r6, r1, 24 + lsls r2, 24 + lsrs r7, r2, 24 + movs r4, 0 + ldr r0, =gUnknown_03005DC0 + ldr r5, [r0, 0x8] + ldr r1, [r0] + lsls r0, r1, 3 + subs r0, r1 + lsls r0, 1 + adds r0, 0xE + adds r5, r0 + movs r3, 0 + ldr r0, =0x000003ff + mov r8, r0 + ldr r1, =0x0000028e + mov r12, r1 + ldr r0, =gEventObjects + mov r9, r0 +_081A99CC: + movs r2, 0 +_081A99CE: + lsls r0, r2, 1 + adds r0, r5 + ldrh r1, [r0] + mov r0, r8 + ands r0, r1 + cmp r0, r12 + bne _081A9A8A + adds r2, 0x7 + ldr r0, =gSelectedEventObject + ldrb r1, [r0] + lsls r0, r1, 3 + adds r0, r1 + lsls r0, 2 + add r0, r9 + movs r5, 0xC + ldrsh r1, [r0, r5] + subs r2, r1 + adds r1, r3, 0x7 + movs r3, 0xE + ldrsh r0, [r0, r3] + subs r3, r1, r0 + cmp r2, r6 + bge _081A9A0E + negs r0, r6 + cmp r2, r0 + ble _081A9A0E + cmp r3, r6 + bge _081A9A0E + cmp r3, r0 + ble _081A9A0E + cmp r7, 0 + bne _081A9A84 +_081A9A0E: + cmp r2, 0 + ble _081A9A34 + cmp r3, 0 + ble _081A9A34 + movs r4, 0x3 + cmp r2, r3 + blt _081A9A7C + movs r4, 0x2 + b _081A9A7C + .pool +_081A9A34: + cmp r2, 0 + bge _081A9A46 + cmp r3, 0 + bge _081A9A46 + movs r4, 0x1 + cmp r2, r3 + ble _081A9A7C + movs r4, 0 + b _081A9A7C +_081A9A46: + cmp r2, 0 + bne _081A9A54 + movs r4, 0 + cmp r3, 0 + ble _081A9A7C + movs r4, 0x3 + b _081A9A7C +_081A9A54: + cmp r3, 0 + bne _081A9A62 + movs r4, 0x1 + cmp r2, 0 + ble _081A9A7C + movs r4, 0x2 + b _081A9A7C +_081A9A62: + cmp r2, 0 + bge _081A9A72 + adds r0, r2, r3 + movs r4, 0x1 + cmp r0, 0 + ble _081A9A7C + movs r4, 0x3 + b _081A9A7C +_081A9A72: + adds r0, r2, r3 + mvns r0, r0 + asrs r4, r0, 31 + movs r0, 0x2 + ands r4, r0 +_081A9A7C: + movs r0, 0 + mov r5, r10 + str r0, [r5] + b _081A9A98 +_081A9A84: + mov r0, r10 + str r7, [r0] + b _081A9A98 +_081A9A8A: + adds r2, 0x1 + cmp r2, 0x1F + ble _081A99CE + adds r5, 0x5E + adds r3, 0x1 + cmp r3, 0x1F + ble _081A99CC +_081A9A98: + adds r0, r4, 0 + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r1} + bx r1 + thumb_func_end sub_81A9998 + + thumb_func_start sub_81A9AA8 +sub_81A9AA8: @ 81A9AA8 + lsls r0, 24 + ldr r1, =gSaveBlock2Ptr + ldr r1, [r1] + lsrs r0, 23 + adds r1, r0 + ldr r0, =0x00000cb2 + adds r1, r0 + ldrh r0, [r1] + bx lr + .pool + thumb_func_end sub_81A9AA8 + + thumb_func_start GetBattlePyramidTrainerFlag +GetBattlePyramidTrainerFlag: @ 81A9AC4 + push {r4,lr} + lsls r0, 24 + lsrs r0, 24 + ldr r1, =gSaveBlock2Ptr + ldr r2, [r1] + ldr r1, =0x00000e2a + adds r2, r1 + ldr r4, =gBitTable + ldr r3, =gEventObjects + lsls r1, r0, 3 + adds r1, r0 + lsls r1, 2 + adds r1, r3 + ldrb r0, [r1, 0x8] + subs r0, 0x1 + lsls r0, 2 + adds r0, r4 + ldr r0, [r0] + ldrb r1, [r2] + ands r0, r1 + pop {r4} + pop {r1} + bx r1 + .pool + thumb_func_end GetBattlePyramidTrainerFlag + + thumb_func_start sub_81A9B04 +sub_81A9B04: @ 81A9B04 + push {lr} + ldr r0, =gTrainerBattleOpponent_A + ldrh r0, [r0] + bl sub_81A9B44 + ldr r0, =gBattleTypeFlags + ldr r0, [r0] + movs r1, 0x80 + lsls r1, 8 + ands r0, r1 + cmp r0, 0 + beq _081A9B2E + movs r0, 0x1 + bl GetChosenApproachingTrainerEventObjectId + ldr r1, =gSelectedEventObject + strb r0, [r1] + ldr r0, =gTrainerBattleOpponent_B + ldrh r0, [r0] + bl sub_81A9B44 +_081A9B2E: + pop {r0} + bx r0 + .pool + thumb_func_end sub_81A9B04 + + thumb_func_start sub_81A9B44 +sub_81A9B44: @ 81A9B44 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + lsls r0, 16 + lsrs r5, r0, 16 + movs r3, 0 + ldr r0, =gEventObjects + mov r12, r0 + ldr r6, =gSelectedEventObject + ldr r1, =gSaveBlock1Ptr + mov r10, r1 + ldr r7, =gSaveBlock2Ptr + mov r9, r7 + ldr r0, =0x00000cb4 + mov r8, r0 + ldr r4, =gBitTable +_081A9B68: + mov r1, r9 + ldr r2, [r1] + lsls r0, r3, 1 + mov r7, r8 + adds r1, r2, r7 + adds r1, r0 + ldrh r0, [r1] + cmp r0, r5 + bne _081A9B86 + ldr r1, =0x00000e2a + adds r0, r2, r1 + ldr r1, [r4] + ldrb r2, [r0] + orrs r1, r2 + strb r1, [r0] +_081A9B86: + adds r4, 0x4 + adds r3, 0x1 + cmp r3, 0x7 + ble _081A9B68 + ldrb r1, [r6] + lsls r0, r1, 3 + adds r0, r1 + lsls r0, 2 + add r0, r12 + movs r3, 0x2 + strb r3, [r0, 0x6] + mov r7, r10 + ldr r2, [r7] + ldr r0, =gSpecialVar_LastTalked + ldrh r1, [r0] + subs r1, 0x1 + lsls r0, r1, 1 + adds r0, r1 + lsls r0, 3 + adds r2, r0 + ldr r1, =0x00000c79 + adds r2, r1 + strb r3, [r2] + ldrb r1, [r6] + lsls r0, r1, 3 + adds r0, r1 + lsls r0, 2 + add r0, r12 + ldrh r1, [r0, 0x10] + strh r1, [r0, 0xC] + ldrb r1, [r6] + lsls r0, r1, 3 + adds r0, r1 + lsls r0, 2 + add r0, r12 + ldrh r1, [r0, 0x12] + strh r1, [r0, 0xE] + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r0} + bx r0 + .pool + thumb_func_end sub_81A9B44 + + thumb_func_start GenerateBattlePyramidWildMon +GenerateBattlePyramidWildMon: @ 81A9C04 + push {r4-r6,lr} + sub sp, 0x14 + ldr r0, =gSaveBlock2Ptr + ldr r1, [r0] + ldr r2, =0x00000ca9 + adds r0, r1, r2 + ldrb r0, [r0] + lsls r0, 30 + lsrs r5, r0, 30 + lsls r0, r5, 1 + ldr r2, =0x00000e1a + adds r1, r2 + adds r1, r0 + ldrh r0, [r1] + movs r1, 0x7 + bl __udivsi3 + lsls r0, 16 + lsrs r0, 16 + movs r1, 0x14 + bl __umodsi3 + lsls r0, 16 + lsrs r0, 16 + cmp r0, 0x13 + bls _081A9C3A + movs r0, 0x13 +_081A9C3A: + cmp r5, 0 + beq _081A9C54 + ldr r1, =gBattlePyramidOpenLevelWildMonPointers + b _081A9C56 + .pool +_081A9C54: + ldr r1, =gBattlePyramidLevel50WildMonPointers +_081A9C56: + lsls r0, 2 + adds r0, r1 + ldr r6, [r0] + ldr r4, =gEnemyParty + adds r0, r4, 0 + movs r1, 0xB + movs r2, 0 + bl GetMonData + subs r0, 0x1 + str r0, [sp, 0x10] + lsls r2, r0, 1 + adds r2, r0 + lsls r2, 2 + adds r2, r6, r2 + adds r0, r4, 0 + movs r1, 0xB + bl SetMonData + ldr r1, [sp, 0x10] + lsls r0, r1, 1 + adds r0, r1 + lsls r0, 2 + adds r0, r6 + ldrh r1, [r0] + mov r0, sp + bl GetSpeciesName + adds r0, r4, 0 + movs r1, 0x2 + mov r2, sp + bl SetMonData + cmp r5, 0 + beq _081A9CD4 + bl SetFacilityPtrsGetLevel + lsls r0, 24 + lsrs r5, r0, 24 + ldr r1, [sp, 0x10] + lsls r0, r1, 1 + adds r0, r1 + lsls r0, 2 + adds r0, r6 + ldrb r0, [r0, 0x2] + subs r5, r0 + bl Random + lsls r0, 16 + lsrs r0, 16 + movs r1, 0xB + bl __umodsi3 + lsls r0, 16 + lsrs r0, 16 + subs r0, 0x5 + adds r5, r0 + b _081A9CF6 + .pool +_081A9CD4: + bl Random + ldr r2, [sp, 0x10] + lsls r1, r2, 1 + adds r1, r2 + lsls r1, 2 + adds r1, r6 + ldrb r4, [r1, 0x2] + lsls r0, 16 + lsrs r0, 16 + movs r1, 0xB + bl __umodsi3 + lsls r0, 16 + lsrs r0, 16 + subs r0, 0x5 + adds r5, r4, r0 +_081A9CF6: + ldr r4, =gEnemyParty + ldr r2, =gBaseStats + ldr r1, [sp, 0x10] + lsls r0, r1, 1 + adds r0, r1 + lsls r0, 2 + adds r0, r6 + ldrh r1, [r0] + lsls r0, r1, 3 + subs r0, r1 + lsls r0, 2 + adds r0, r2 + ldrb r1, [r0, 0x13] + movs r0, 0xCA + lsls r0, 1 + adds r2, r1, 0 + muls r2, r0 + lsls r0, r5, 2 + ldr r1, =gExperienceTables + adds r0, r1 + adds r2, r0 + adds r0, r4, 0 + movs r1, 0x19 + bl SetMonData + ldr r1, [sp, 0x10] + lsls r0, r1, 1 + adds r0, r1 + lsls r0, 2 + adds r0, r6 + ldrb r1, [r0, 0x3] + cmp r1, 0 + blt _081A9D4C + cmp r1, 0x1 + bgt _081A9D4C + adds r2, r0, 0x3 + b _081A9D7C + .pool +_081A9D4C: + ldr r2, =gBaseStats + ldr r1, [sp, 0x10] + lsls r0, r1, 1 + adds r0, r1 + lsls r0, 2 + adds r0, r6 + ldrh r1, [r0] + lsls r0, r1, 3 + subs r0, r1 + lsls r0, 2 + adds r0, r2 + ldrb r0, [r0, 0x17] + cmp r0, 0 + beq _081A9D90 + ldr r4, =gEnemyParty + adds r0, r4, 0 + movs r1, 0 + movs r2, 0 + bl GetMonData + movs r1, 0x1 + ands r1, r0 + str r1, [sp, 0xC] + add r2, sp, 0xC +_081A9D7C: + adds r0, r4, 0 + movs r1, 0x2E + bl SetMonData + b _081A9D9C + .pool +_081A9D90: + str r0, [sp, 0xC] + ldr r0, =gEnemyParty + add r2, sp, 0xC + movs r1, 0x2E + bl SetMonData +_081A9D9C: + movs r0, 0 + str r0, [sp, 0xC] + movs r2, 0 + lsls r4, r5, 1 +_081A9DA4: + ldr r1, [sp, 0x10] + lsls r0, r1, 1 + adds r0, r1 + lsls r0, 2 + adds r0, r6 + lsls r1, r2, 1 + adds r0, 0x4 + adds r0, r1 + ldrh r1, [r0] + lsls r2, 24 + lsrs r2, 24 + ldr r0, =gEnemyParty + bl SetMonMoveSlot + ldr r0, [sp, 0xC] + adds r0, 0x1 + str r0, [sp, 0xC] + adds r2, r0, 0 + cmp r2, 0x3 + ble _081A9DA4 + ldr r0, =gSaveBlock2Ptr + ldr r0, [r0] + ldr r1, =0x00000e1a + adds r0, r1 + adds r0, r4 + ldrh r0, [r0] + cmp r0, 0x8B + bls _081A9E0C + bl Random + lsls r0, 16 + lsrs r0, 16 + movs r1, 0x11 + bl __umodsi3 + lsls r0, 16 + lsrs r0, 16 + adds r0, 0xF + str r0, [sp, 0x10] + movs r0, 0 + str r0, [sp, 0xC] +_081A9DF6: + adds r1, r0, 0 + adds r1, 0x27 + ldr r0, =gEnemyParty + add r2, sp, 0x10 + bl SetMonData + ldr r0, [sp, 0xC] + adds r0, 0x1 + str r0, [sp, 0xC] + cmp r0, 0x5 + ble _081A9DF6 +_081A9E0C: + ldr r0, =gEnemyParty + bl CalculateMonStats + add sp, 0x14 + pop {r4-r6} + pop {r0} + bx r0 + .pool + thumb_func_end GenerateBattlePyramidWildMon + + thumb_func_start sub_81A9E28 +sub_81A9E28: @ 81A9E28 + push {lr} + bl sub_81AA9E4 + lsls r0, 24 + ldr r1, =gUnknown_08613650 + lsrs r0, 20 + adds r0, r1 + ldrb r0, [r0, 0x4] + pop {r1} + bx r1 + .pool + thumb_func_end sub_81A9E28 + + thumb_func_start InBattlePyramid +InBattlePyramid: @ 81A9E40 + push {lr} + ldr r0, =gMapHeader + ldrh r1, [r0, 0x12] + ldr r0, =0x00000169 + cmp r1, r0 + bne _081A9E58 + movs r0, 0x1 + b _081A9E66 + .pool +_081A9E58: + movs r0, 0xBD + lsls r0, 1 + cmp r1, r0 + beq _081A9E64 + movs r0, 0 + b _081A9E66 +_081A9E64: + movs r0, 0x2 +_081A9E66: + pop {r1} + bx r1 + thumb_func_end InBattlePyramid + + thumb_func_start sub_81A9E6C +sub_81A9E6C: @ 81A9E6C + push {lr} + movs r2, 0 + ldr r0, =gMapHeader + ldrh r1, [r0, 0x12] + ldr r0, =0x00000169 + cmp r1, r0 + beq _081A9E80 + adds r0, 0x11 + cmp r1, r0 + bne _081A9E82 +_081A9E80: + movs r2, 0x1 +_081A9E82: + adds r0, r2, 0 + pop {r1} + bx r1 + .pool + thumb_func_end sub_81A9E6C + + thumb_func_start sub_81A9E90 +sub_81A9E90: @ 81A9E90 + push {lr} + bl InBattlePyramid + lsls r0, 24 + cmp r0, 0 + beq _081A9EB8 + bl sub_81A9834 + ldr r0, =gSaveBlock2Ptr + ldr r0, [r0] + ldr r1, =0x00000ca8 + adds r0, r1 + movs r1, 0x2 + strb r1, [r0] + ldr r0, =0x0000400e + movs r1, 0 + bl VarSet + bl LoadPlayerParty +_081A9EB8: + pop {r0} + bx r0 + .pool + thumb_func_end sub_81A9E90 + + thumb_func_start sub_81A9EC8 +sub_81A9EC8: @ 81A9EC8 + push {lr} + bl InBattlePyramid + lsls r0, 24 + cmp r0, 0 + beq _081A9ED8 + bl DoSoftReset +_081A9ED8: + pop {r0} + bx r0 + thumb_func_end sub_81A9EC8 + + thumb_func_start sub_81A9EDC +sub_81A9EDC: @ 81A9EDC + push {lr} + lsls r0, 16 + lsrs r0, 16 + ldr r2, =gFacilityTrainers + movs r1, 0x34 + muls r1, r0 + ldr r0, [r2] + adds r0, r1 + adds r0, 0xC + bl FrontierSpeechToString + pop {r0} + bx r0 + .pool + thumb_func_end sub_81A9EDC + + thumb_func_start sub_81A9EFC +sub_81A9EFC: @ 81A9EFC + push {lr} + lsls r0, 16 + lsrs r0, 16 + ldr r2, =gFacilityTrainers + movs r1, 0x34 + muls r1, r0 + ldr r0, [r2] + adds r0, r1 + adds r0, 0x18 + bl FrontierSpeechToString + pop {r0} + bx r0 + .pool + thumb_func_end sub_81A9EFC + + thumb_func_start sub_81A9F1C +sub_81A9F1C: @ 81A9F1C + push {lr} + lsls r0, 16 + lsrs r0, 16 + ldr r2, =gFacilityTrainers + movs r1, 0x34 + muls r1, r0 + ldr r0, [r2] + adds r0, r1 + adds r0, 0x24 + bl FrontierSpeechToString + pop {r0} + bx r0 + .pool + thumb_func_end sub_81A9F1C + + thumb_func_start GetTrainerEncounterMusicIdInBattlePyramind +GetTrainerEncounterMusicIdInBattlePyramind: @ 81A9F3C + push {r4,lr} + lsls r0, 16 + lsrs r0, 16 + movs r4, 0 + ldr r3, =gFacilityClassToTrainerClass + ldr r1, =gFacilityTrainers + ldr r2, [r1] + movs r1, 0x34 + muls r0, r1 + adds r0, r2 + ldrb r0, [r0] + adds r0, r3 + ldrb r2, [r0] + ldr r1, =gUnknown_08613B44 +_081A9F58: + ldrb r0, [r1] + cmp r0, r2 + bne _081A9F70 + ldrb r0, [r1, 0x1] + b _081A9F7A + .pool +_081A9F70: + adds r1, 0x4 + adds r4, 0x1 + cmp r4, 0x35 + bls _081A9F58 + movs r0, 0 +_081A9F7A: + pop {r4} + pop {r1} + bx r1 + thumb_func_end GetTrainerEncounterMusicIdInBattlePyramind + + thumb_func_start sub_81A9F80 +sub_81A9F80: @ 81A9F80 + push {lr} + ldr r0, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88 + bl ScriptContext1_SetupScript + pop {r0} + bx r0 + .pool + thumb_func_end sub_81A9F80 + + thumb_func_start sub_81A9F90 +sub_81A9F90: @ 81A9F90 + push {r4-r7,lr} + mov r7, r8 + push {r7} + lsls r0, 24 + lsrs r5, r0, 24 + ldr r0, =gSaveBlock2Ptr + ldr r4, [r0] + ldr r1, =0x00000ca9 + adds r0, r4, r1 + ldrb r1, [r0] + lsls r1, 30 + lsrs r1, 29 + ldr r2, =0x00000e1a + adds r0, r4, r2 + adds r0, r1 + ldrh r0, [r0] + movs r1, 0x7 + bl __udivsi3 + lsls r0, 16 + lsrs r0, 16 + ldr r1, =0x00000cb2 + adds r4, r1 + ldrh r1, [r4] + cmp r1, 0x7 + bne _081AA020 + adds r0, 0x1 + lsls r7, r0, 24 + lsls r1, 24 + mov r8, r1 +_081A9FCC: + lsrs r0, r7, 24 + mov r2, r8 + lsrs r1, r2, 24 + bl sub_8162548 + lsls r0, 16 + lsrs r3, r0, 16 + movs r2, 0 + cmp r2, r5 + bge _081AA004 + ldr r1, =gSaveBlock2Ptr + ldr r0, [r1] + ldr r4, =0x00000cb4 + adds r0, r4 + ldrh r0, [r0] + cmp r0, r3 + beq _081AA004 + adds r6, r1, 0 +_081A9FF0: + adds r2, 0x1 + cmp r2, r5 + bge _081AA004 + ldr r0, [r6] + lsls r1, r2, 1 + adds r0, r4 + adds r0, r1 + ldrh r0, [r0] + cmp r0, r3 + bne _081A9FF0 +_081AA004: + cmp r2, r5 + bne _081A9FCC + b _081AA062 + .pool +_081AA020: + lsls r1, 24 + mov r8, r1 + lsls r7, r0, 24 +_081AA026: + lsrs r0, r7, 24 + mov r2, r8 + lsrs r1, r2, 24 + bl sub_8162548 + lsls r0, 16 + lsrs r3, r0, 16 + movs r2, 0 + cmp r2, r5 + bge _081AA05E + ldr r1, =gSaveBlock2Ptr + ldr r0, [r1] + ldr r4, =0x00000cb4 + adds r0, r4 + ldrh r0, [r0] + cmp r0, r3 + beq _081AA05E + adds r6, r1, 0 +_081AA04A: + adds r2, 0x1 + cmp r2, r5 + bge _081AA05E + ldr r0, [r6] + lsls r1, r2, 1 + adds r0, r4 + adds r0, r1 + ldrh r0, [r0] + cmp r0, r3 + bne _081AA04A +_081AA05E: + cmp r2, r5 + bne _081AA026 +_081AA062: + adds r0, r3, 0 + pop {r3} + mov r8, r3 + pop {r4-r7} + pop {r1} + bx r1 + .pool + thumb_func_end sub_81A9F90 + + thumb_func_start sub_81AA078 +sub_81AA078: @ 81AA078 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + sub sp, 0x1C + str r0, [sp, 0x4] + lsls r1, 24 + lsrs r1, 24 + str r1, [sp, 0x8] + movs r0, 0x10 + bl AllocZeroed + str r0, [sp, 0xC] + bl sub_81AA96C + mov r4, sp + adds r4, 0x1 + mov r0, sp + adds r1, r4, 0 + bl sub_81AA33C + movs r7, 0 +_081AA0A6: + ldr r1, [sp, 0xC] + adds r0, r1, r7 + ldrb r0, [r0] + ldr r2, =0x00000169 + adds r0, r2 + lsls r0, 2 + ldr r1, =gMapLayouts + adds r0, r1 + ldr r6, [r0] + ldr r2, [r6, 0xC] + mov r10, r2 + ldr r0, [sp, 0x4] + ldr r1, =gUnknown_03005DC0 + str r0, [r1, 0x8] + ldr r0, [r6] + lsls r0, 2 + adds r2, r0, 0 + adds r2, 0xF + str r2, [r1] + ldr r0, [r6, 0x4] + lsls r0, 2 + adds r0, 0xE + str r0, [r1, 0x4] + ldr r0, [sp, 0x4] + mov r9, r0 + adds r1, r7, 0 + cmp r7, 0 + bge _081AA0E0 + adds r1, r7, 0x3 +_081AA0E0: + asrs r1, 2 + ldr r4, [r6, 0x4] + adds r0, r1, 0 + muls r0, r4 + adds r0, 0x7 + muls r2, r0 + lsls r1, 2 + subs r1, r7, r1 + ldr r3, [r6] + adds r0, r1, 0 + muls r0, r3 + adds r0, 0x7 + adds r2, r0 + lsls r2, 1 + add r9, r2 + movs r1, 0 + mov r8, r1 + adds r2, r7, 0x1 + str r2, [sp, 0x10] + cmp r8, r4 + bge _081AA1B6 +_081AA10A: + movs r0, 0 + mov r12, r0 + mov r1, r8 + adds r1, 0x1 + str r1, [sp, 0x14] + cmp r12, r3 + bge _081AA1A2 + ldr r2, =gSaveBlock1Ptr + str r2, [sp, 0x18] + mov r4, r9 + mov r5, r10 +_081AA120: + ldrh r1, [r5] + ldr r0, =0x000003ff + ands r0, r1 + ldr r2, =0x0000028e + cmp r0, r2 + bne _081AA194 + mov r0, sp + ldrb r0, [r0, 0x1] + cmp r7, r0 + beq _081AA194 + mov r0, sp + ldrb r0, [r0] + cmp r7, r0 + bne _081AA164 + ldr r1, [sp, 0x8] + cmp r1, 0 + bne _081AA164 + ldr r2, [sp, 0x18] + ldr r3, [r2] + adds r2, r7, 0 + cmp r7, 0 + bge _081AA14E + adds r2, r7, 0x3 +_081AA14E: + asrs r2, 2 + lsls r1, r2, 2 + subs r1, r7, r1 + ldr r0, [r6] + muls r0, r1 + add r0, r12 + strh r0, [r3] + ldr r0, [r6, 0x4] + muls r0, r2 + add r0, r8 + strh r0, [r3, 0x2] +_081AA164: + ldrh r0, [r5] + movs r1, 0xFC + lsls r1, 8 + ands r1, r0 + ldr r2, =0x0000028d + adds r0, r2, 0 + orrs r1, r0 + strh r1, [r4] + ldr r3, [r6] + b _081AA196 + .pool +_081AA194: + strh r1, [r4] +_081AA196: + adds r4, 0x2 + adds r5, 0x2 + movs r0, 0x1 + add r12, r0 + cmp r12, r3 + blt _081AA120 +_081AA1A2: + lsls r0, r3, 3 + adds r0, 0x1E + add r9, r0 + lsls r0, r3, 1 + add r10, r0 + ldr r1, [sp, 0x14] + mov r8, r1 + ldr r0, [r6, 0x4] + cmp r8, r0 + blt _081AA10A +_081AA1B6: + ldr r7, [sp, 0x10] + cmp r7, 0xF + bgt _081AA1BE + b _081AA0A6 +_081AA1BE: + bl mapheader_run_script_with_tag_x1 + ldr r0, [sp, 0xC] + bl Free + add sp, 0x1C + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r0} + bx r0 + thumb_func_end sub_81AA078 + + thumb_func_start sub_81AA1D8 +sub_81AA1D8: @ 81AA1D8 + push {r4-r7,lr} + mov r7, r8 + push {r7} + sub sp, 0x8 + movs r5, 0 + mov r6, sp + adds r6, 0x1 + add r0, sp, 0x4 + mov r8, r0 + ldr r4, =gSaveBlock2Ptr + ldr r3, =0x00000cb4 + ldr r0, =0x0000ffff + adds r2, r0, 0 +_081AA1F2: + ldr r0, [r4] + lsls r1, r5, 1 + adds r0, r3 + adds r0, r1 + ldrh r1, [r0] + orrs r1, r2 + strh r1, [r0] + adds r5, 0x1 + cmp r5, 0x7 + ble _081AA1F2 + bl sub_81AA9E4 + lsls r0, 24 + lsrs r7, r0, 24 + mov r0, sp + adds r1, r6, 0 + bl sub_81AA33C + movs r0, 0 + str r0, [sp, 0x4] + ldr r0, =gSaveBlock1Ptr + ldr r1, [r0] + movs r0, 0xC7 + lsls r0, 4 + adds r1, r0 + ldr r2, =0x05000180 + mov r0, r8 + bl CpuSet + movs r5, 0 +_081AA22E: + cmp r5, 0 + bne _081AA254 + ldr r1, =gUnknown_08613650 + lsls r0, r7, 4 + adds r0, r1 + ldrb r0, [r0, 0x3] + b _081AA25C + .pool +_081AA254: + ldr r1, =gUnknown_08613650 + lsls r0, r7, 4 + adds r0, r1 + ldrb r0, [r0, 0x2] +_081AA25C: + cmp r0, 0x4 + bhi _081AA2E4 + lsls r0, 2 + ldr r1, =_081AA274 + adds r0, r1 + ldr r0, [r0] + mov pc, r0 + .pool + .align 2, 0 +_081AA274: + .4byte _081AA288 + .4byte _081AA292 + .4byte _081AA2A2 + .4byte _081AA2B0 + .4byte _081AA2CC +_081AA288: + lsls r0, r5, 24 + lsrs r0, 24 + bl sub_81AA398 + b _081AA2E4 +_081AA292: + lsls r0, r5, 24 + lsrs r4, r0, 24 + mov r0, sp + ldrb r1, [r0] + adds r0, r4, 0 + bl sub_81AA4D8 + b _081AA2BE +_081AA2A2: + lsls r0, r5, 24 + lsrs r4, r0, 24 + ldrb r1, [r6] + adds r0, r4, 0 + bl sub_81AA4D8 + b _081AA2BE +_081AA2B0: + lsls r0, r5, 24 + lsrs r4, r0, 24 + mov r0, sp + ldrb r1, [r0] + adds r0, r4, 0 + bl sub_81AA648 +_081AA2BE: + lsls r0, 24 + cmp r0, 0 + beq _081AA2E4 + adds r0, r4, 0 + bl sub_81AA398 + b _081AA2E4 +_081AA2CC: + lsls r0, r5, 24 + lsrs r4, r0, 24 + ldrb r1, [r6] + adds r0, r4, 0 + bl sub_81AA648 + lsls r0, 24 + cmp r0, 0 + beq _081AA2E4 + adds r0, r4, 0 + bl sub_81AA398 +_081AA2E4: + adds r5, 0x1 + cmp r5, 0x1 + ble _081AA22E + add sp, 0x8 + pop {r3} + mov r8, r3 + pop {r4-r7} + pop {r0} + bx r0 + thumb_func_end sub_81AA1D8 + + thumb_func_start sub_81AA2F8 +sub_81AA2F8: @ 81AA2F8 + push {r4,r5,lr} + ldr r0, =gSaveBlock1Ptr + ldr r0, [r0] + ldr r5, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F + ldr r4, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A + movs r2, 0xC8 + lsls r2, 4 + adds r1, r0, r2 + movs r3, 0xC7 + lsls r3, 4 + adds r2, r0, r3 + movs r3, 0x3F +_081AA310: + ldrb r0, [r2, 0x1] + cmp r0, 0x3B + beq _081AA328 + str r5, [r1] + b _081AA32A + .pool +_081AA328: + str r4, [r1] +_081AA32A: + adds r1, 0x18 + adds r2, 0x18 + subs r3, 0x1 + cmp r3, 0 + bge _081AA310 + pop {r4,r5} + pop {r0} + bx r0 + thumb_func_end sub_81AA2F8 + + thumb_func_start sub_81AA33C +sub_81AA33C: @ 81AA33C + push {r4-r7,lr} + adds r4, r0, 0 + adds r6, r1, 0 + ldr r5, =gSaveBlock2Ptr + ldr r1, [r5] + ldr r2, =0x00000e28 + adds r0, r1, r2 + ldrh r2, [r0] + movs r3, 0xF + ands r2, r3 + strb r2, [r4] + ldr r7, =0x00000e22 + adds r1, r7 + ldrh r0, [r1] + ands r0, r3 + strb r0, [r6] + cmp r2, r0 + bne _081AA386 + ldr r1, [r5] + ldr r2, =0x00000e28 + adds r0, r1, r2 + ldrh r2, [r0] + adds r3, r2, 0x1 + adds r0, r3, 0 + asrs r0, 4 + lsls r0, 4 + subs r0, r3, r0 + strb r0, [r4] + adds r0, r1, r7 + ldrh r1, [r0] + adds r2, r1, 0 + adds r2, 0xF + adds r0, r2, 0 + asrs r0, 4 + lsls r0, 4 + subs r0, r2, r0 + strb r0, [r6] +_081AA386: + pop {r4-r7} + pop {r0} + bx r0 + .pool + thumb_func_end sub_81AA33C + + thumb_func_start sub_81AA398 +sub_81AA398: @ 81AA398 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + sub sp, 0xC + lsls r0, 24 + lsrs r0, 24 + str r0, [sp] + movs r5, 0 + bl sub_81AA9E4 + lsls r0, 24 + lsrs r6, r0, 24 + movs r0, 0x10 + bl AllocZeroed + str r0, [sp, 0x8] + bl sub_81AA96C + ldr r0, =gSaveBlock2Ptr + ldr r0, [r0] + ldr r1, =0x00000e26 + adds r0, r1 + ldrh r4, [r0] + movs r0, 0xF + ands r4, r0 + ldr r0, [sp] + cmp r0, 0 + bne _081AA3F0 + ldr r1, =gUnknown_08613650 + lsls r0, r6, 4 + adds r0, r1 + ldrb r0, [r0, 0x1] + mov r10, r0 + movs r1, 0 + str r1, [sp, 0x4] + b _081AA3FE + .pool +_081AA3F0: + ldr r1, =gUnknown_08613650 + lsls r0, r6, 4 + adds r0, r1 + ldrb r1, [r0] + mov r10, r1 + ldrb r0, [r0, 0x1] + str r0, [sp, 0x4] +_081AA3FE: + movs r0, 0 + mov r8, r0 + cmp r8, r10 + bge _081AA4C0 +_081AA406: + movs r1, 0x1 + add r1, r8 + mov r9, r1 + b _081AA42E + .pool +_081AA414: + lsls r2, r4, 24 + lsrs r2, 24 + ldr r3, [sp, 0x4] + add r3, r8 + lsls r3, 24 + lsrs r3, 24 + ldr r0, [sp] + ldr r1, [sp, 0x8] + bl sub_81AA760 + lsls r0, 24 + cmp r0, 0 + beq _081AA4B6 +_081AA42E: + ldr r0, =gBitTable + mov r12, r0 + ldr r6, =gSaveBlock2Ptr + ldr r7, =0x00000e28 + movs r3, 0x2 + lsls r0, r4, 2 + mov r1, r12 + adds r2, r0, r1 +_081AA43E: + movs r0, 0x1 + ands r0, r5 + cmp r0, 0 + beq _081AA464 + ldr r0, [r6] + adds r0, r7 + ldrh r1, [r0] + ldr r0, [r2] + ands r0, r1 + cmp r0, 0 + bne _081AA474 + b _081AA472 + .pool +_081AA464: + ldr r0, [r6] + adds r0, r7 + ldrh r1, [r0] + ldr r0, [r2] + ands r0, r1 + cmp r0, 0 + beq _081AA474 +_081AA472: + orrs r5, r3 +_081AA474: + adds r2, 0x4 + adds r4, 0x1 + cmp r4, 0xF + ble _081AA480 + mov r2, r12 + movs r4, 0 +_081AA480: + ldr r0, [r6] + ldr r1, =0x00000e26 + adds r0, r1 + ldrh r1, [r0] + movs r0, 0xF + ands r1, r0 + cmp r4, r1 + bne _081AA4A6 + movs r1, 0x1 + adds r0, r5, 0 + ands r0, r1 + cmp r0, 0 + beq _081AA4A4 + movs r0, 0x6 + orrs r5, r0 + b _081AA4A6 + .pool +_081AA4A4: + orrs r5, r1 +_081AA4A6: + adds r0, r5, 0 + ands r0, r3 + cmp r0, 0 + beq _081AA43E + movs r0, 0x4 + ands r0, r5 + cmp r0, 0 + beq _081AA414 +_081AA4B6: + movs r0, 0x1 + ands r5, r0 + mov r8, r9 + cmp r8, r10 + blt _081AA406 +_081AA4C0: + ldr r0, [sp, 0x8] + bl Free + add sp, 0xC + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r0} + bx r0 + thumb_func_end sub_81AA398 + + thumb_func_start sub_81AA4D8 +sub_81AA4D8: @ 81AA4D8 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + sub sp, 0x20 + lsls r0, 24 + lsrs r0, 24 + str r0, [sp] + lsls r1, 24 + lsrs r1, 24 + str r1, [sp, 0x4] + movs r6, 0 + movs r7, 0 + movs r0, 0 + str r0, [sp, 0xC] + bl sub_81AA9E4 + lsls r0, 24 + lsrs r4, r0, 24 + movs r0, 0x10 + bl AllocZeroed + str r0, [sp, 0x14] + bl sub_81AA96C + ldr r1, [sp] + cmp r1, 0 + bne _081AA524 + ldr r1, =gUnknown_08613650 + lsls r0, r4, 4 + adds r0, r1 + ldrb r0, [r0, 0x1] + str r0, [sp, 0x10] + movs r0, 0 + b _081AA530 + .pool +_081AA524: + ldr r1, =gUnknown_08613650 + lsls r0, r4, 4 + adds r0, r1 + ldrb r2, [r0] + str r2, [sp, 0x10] + ldrb r0, [r0, 0x1] +_081AA530: + movs r3, 0 + str r3, [sp, 0x8] + ldr r1, [sp, 0x10] + asrs r1, 31 + str r1, [sp, 0x18] + ldr r2, [sp, 0x10] + cmp r3, r2 + bge _081AA622 + str r0, [sp, 0x1C] + adds r3, r0, 0 + lsls r3, 24 + mov r9, r3 +_081AA548: + cmp r7, 0 + bne _081AA56E + mov r0, r9 + lsrs r3, r0, 24 + ldr r0, [sp] + ldr r1, [sp, 0x14] + ldr r2, [sp, 0x4] + bl sub_81AA760 + lsls r0, 24 + cmp r0, 0 + beq _081AA568 + movs r7, 0x1 + b _081AA56E + .pool +_081AA568: + ldr r1, [sp, 0xC] + adds r1, 0x1 + str r1, [sp, 0xC] +_081AA56E: + movs r0, 0x1 + ands r0, r7 + cmp r0, 0 + beq _081AA600 + ldr r2, =gUnknown_08613F46 + mov r8, r2 + ldr r3, [sp, 0x4] + lsls r4, r3, 2 + adds r0, r6, r4 + add r0, r8 + ldrb r2, [r0] + mov r0, r9 + lsrs r3, r0, 24 + ldr r0, [sp] + ldr r1, [sp, 0x14] + bl sub_81AA760 + lsls r0, 24 + ldr r1, [sp, 0x1C] + mov r10, r1 + adds r5, r4, 0 + cmp r0, 0 + beq _081AA5E8 + ldr r4, [sp, 0xC] + adds r4, 0x1 + b _081AA5C2 + .pool +_081AA5A8: + adds r0, r6, r5 + adds r0, r2 + ldrb r2, [r0] + mov r0, r10 + lsls r3, r0, 24 + lsrs r3, 24 + ldr r0, [sp] + ldr r1, [sp, 0x14] + bl sub_81AA760 + lsls r0, 24 + cmp r0, 0 + beq _081AA5E0 +_081AA5C2: + adds r6, 0x1 + ldr r0, =gUnknown_08613F46 + adds r1, r6, r5 + adds r1, r0 + ldrb r1, [r1] + adds r2, r0, 0 + cmp r1, 0xFF + beq _081AA5D6 + cmp r6, 0x3 + ble _081AA5D8 +_081AA5D6: + movs r6, 0 +_081AA5D8: + adds r7, 0x2 + asrs r0, r7, 1 + cmp r0, 0x4 + bne _081AA5A8 +_081AA5E0: + str r4, [sp, 0xC] + b _081AA600 + .pool +_081AA5E8: + adds r6, 0x1 + adds r0, r6, r4 + add r0, r8 + ldrb r0, [r0] + cmp r0, 0xFF + beq _081AA5F8 + cmp r6, 0x3 + ble _081AA5FA +_081AA5F8: + movs r6, 0 +_081AA5FA: + ldr r1, [sp, 0xC] + adds r1, 0x1 + str r1, [sp, 0xC] +_081AA600: + asrs r0, r7, 1 + cmp r0, 0x4 + beq _081AA622 + movs r0, 0x1 + ands r7, r0 + ldr r2, [sp, 0x1C] + adds r2, 0x1 + str r2, [sp, 0x1C] + movs r3, 0x80 + lsls r3, 17 + add r9, r3 + ldr r0, [sp, 0x8] + adds r0, 0x1 + str r0, [sp, 0x8] + ldr r1, [sp, 0x10] + cmp r0, r1 + blt _081AA548 +_081AA622: + movs r1, 0 + ldr r2, [sp, 0x10] + ldr r3, [sp, 0x18] + subs r0, r2, r3 + asrs r0, 1 + ldr r2, [sp, 0xC] + cmp r0, r2 + ble _081AA634 + movs r1, 0x1 +_081AA634: + adds r0, r1, 0 + add sp, 0x20 + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r1} + bx r1 + thumb_func_end sub_81AA4D8 + + thumb_func_start sub_81AA648 +sub_81AA648: @ 81AA648 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + sub sp, 0x10 + lsls r0, 24 + lsrs r0, 24 + str r0, [sp] + lsls r1, 24 + lsrs r6, r1, 24 + movs r4, 0 + movs r7, 0 + movs r0, 0 + mov r8, r0 + bl sub_81AA9E4 + lsls r0, 24 + lsrs r5, r0, 24 + movs r0, 0x10 + bl AllocZeroed + str r0, [sp, 0x8] + bl sub_81AA96C + ldr r1, [sp] + cmp r1, 0 + bne _081AA694 + ldr r1, =gUnknown_08613650 + lsls r0, r5, 4 + adds r0, r1 + ldrb r0, [r0, 0x1] + mov r10, r0 + movs r0, 0 + b _081AA6A0 + .pool +_081AA694: + ldr r1, =gUnknown_08613650 + lsls r0, r5, 4 + adds r0, r1 + ldrb r2, [r0] + mov r10, r2 + ldrb r0, [r0, 0x1] +_081AA6A0: + movs r3, 0 + str r3, [sp, 0x4] + mov r1, r10 + asrs r1, 31 + str r1, [sp, 0xC] + cmp r3, r10 + bge _081AA73E + ldr r2, =gUnknown_08613F46 + mov r9, r2 + lsls r5, r6, 2 + lsls r6, r0, 24 +_081AA6B6: + adds r0, r4, r5 + add r0, r9 + ldrb r2, [r0] + lsrs r3, r6, 24 + ldr r0, [sp] + ldr r1, [sp, 0x8] + bl sub_81AA760 + lsls r0, 24 + cmp r0, 0 + beq _081AA714 + adds r7, 0x1 + b _081AA6EE + .pool +_081AA6D8: + adds r0, r4, r5 + adds r0, r1 + ldrb r2, [r0] + lsrs r3, r6, 24 + ldr r0, [sp] + ldr r1, [sp, 0x8] + bl sub_81AA760 + lsls r0, 24 + cmp r0, 0 + beq _081AA728 +_081AA6EE: + adds r4, 0x1 + adds r0, r4, r5 + add r0, r9 + ldrb r0, [r0] + ldr r1, =gUnknown_08613F46 + cmp r0, 0xFF + beq _081AA700 + cmp r4, 0x3 + ble _081AA702 +_081AA700: + movs r4, 0 +_081AA702: + movs r3, 0x1 + add r8, r3 + mov r0, r8 + cmp r0, 0x4 + bne _081AA6D8 + b _081AA728 + .pool +_081AA714: + adds r4, 0x1 + adds r0, r4, r5 + add r0, r9 + ldrb r0, [r0] + cmp r0, 0xFF + beq _081AA724 + cmp r4, 0x3 + ble _081AA726 +_081AA724: + movs r4, 0 +_081AA726: + adds r7, 0x1 +_081AA728: + mov r1, r8 + cmp r1, 0x4 + beq _081AA73E + movs r2, 0x80 + lsls r2, 17 + adds r6, r2 + ldr r3, [sp, 0x4] + adds r3, 0x1 + str r3, [sp, 0x4] + cmp r3, r10 + blt _081AA6B6 +_081AA73E: + movs r1, 0 + mov r2, r10 + ldr r3, [sp, 0xC] + subs r0, r2, r3 + asrs r0, 1 + cmp r0, r7 + ble _081AA74E + movs r1, 0x1 +_081AA74E: + adds r0, r1, 0 + add sp, 0x10 + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r1} + bx r1 + thumb_func_end sub_81AA648 + + thumb_func_start sub_81AA760 +sub_81AA760: @ 81AA760 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + sub sp, 0x8 + mov r10, r1 + lsls r0, 24 + lsrs r0, 24 + mov r9, r0 + lsls r2, 24 + lsrs r2, 24 + mov r8, r2 + lsls r3, 24 + lsrs r7, r3, 24 + ldr r0, =gSaveBlock2Ptr + ldr r0, [r0] + ldr r1, =0x00000e22 + adds r0, r1 + ldrh r1, [r0] + movs r0, 0x1 + ands r0, r1 + cmp r0, 0 + beq _081AA7D0 + movs r6, 0x7 +_081AA792: + movs r4, 0x7 + lsls r5, r6, 24 +_081AA796: + lsls r1, r4, 24 + lsrs r1, 24 + mov r0, r8 + str r0, [sp] + str r7, [sp, 0x4] + mov r0, r9 + lsrs r2, r5, 24 + mov r3, r10 + bl sub_81AA810 + lsls r0, 24 + cmp r0, 0 + beq _081AA7CC + subs r4, 0x1 + cmp r4, 0 + bge _081AA796 + subs r6, 0x1 + movs r1, 0x1 + negs r1, r1 + cmp r6, r1 + bgt _081AA792 + b _081AA7FC + .pool +_081AA7CC: + movs r0, 0 + b _081AA7FE +_081AA7D0: + movs r6, 0 +_081AA7D2: + movs r4, 0 + lsls r5, r6, 24 +_081AA7D6: + lsls r1, r4, 24 + lsrs r1, 24 + mov r0, r8 + str r0, [sp] + str r7, [sp, 0x4] + mov r0, r9 + lsrs r2, r5, 24 + mov r3, r10 + bl sub_81AA810 + lsls r0, 24 + cmp r0, 0 + beq _081AA7CC + adds r4, 0x1 + cmp r4, 0x7 + ble _081AA7D6 + adds r6, 0x1 + cmp r6, 0x7 + ble _081AA7D2 +_081AA7FC: + movs r0, 0x1 +_081AA7FE: + add sp, 0x8 + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r1} + bx r1 + thumb_func_end sub_81AA760 + + thumb_func_start sub_81AA810 +sub_81AA810: @ 81AA810 + push {r4-r7,lr} + mov r7, r10 + mov r6, r9 + mov r5, r8 + push {r5-r7} + sub sp, 0x14 + ldr r4, [sp, 0x34] + ldr r5, [sp, 0x38] + lsls r0, 24 + lsrs r0, 24 + str r0, [sp] + lsls r1, 24 + lsrs r1, 24 + str r1, [sp, 0x4] + lsls r2, 24 + lsrs r2, 24 + mov r8, r2 + lsls r4, 24 + lsrs r4, 24 + mov r10, r4 + lsls r5, 24 + lsrs r6, r5, 24 + ldr r0, =gSaveBlock1Ptr + ldr r0, [r0] + movs r1, 0xC7 + lsls r1, 4 + adds r1, r0, r1 + str r1, [sp, 0x8] + add r3, r10 + ldrb r1, [r3] + adds r1, 0x2C + movs r0, 0x19 + bl Overworld_GetMapHeaderByGroupAndId + adds r5, r0, 0 + movs r7, 0 + ldr r1, [r5, 0x4] + ldrb r2, [r1] + cmp r7, r2 + bge _081AA95A + movs r0, 0x3 + ands r0, r4 + lsls r0, 3 + str r0, [sp, 0xC] +_081AA868: + ldr r1, [r1, 0x4] + lsls r2, r7, 1 + adds r0, r2, r7 + lsls r0, 3 + adds r3, r0, r1 + movs r4, 0x4 + ldrsh r0, [r3, r4] + ldr r1, [r5, 0x4] + mov r12, r1 + mov r9, r2 + ldr r2, [sp, 0x4] + cmp r0, r2 + bne _081AA950 + movs r4, 0x6 + ldrsh r0, [r3, r4] + cmp r0, r8 + bne _081AA950 + ldr r0, [sp] + cmp r0, 0 + bne _081AA896 + ldrb r0, [r3, 0x1] + cmp r0, 0x3B + bne _081AA8A2 +_081AA896: + ldr r1, [sp] + cmp r1, 0x1 + bne _081AA950 + ldrb r0, [r3, 0x1] + cmp r0, 0x3B + bne _081AA950 +_081AA8A2: + movs r3, 0 + ldr r2, [r5, 0x4] + mov r12, r2 + cmp r3, r6 + bge _081AA8DC + ldr r4, [sp, 0x4] + ldr r0, [sp, 0xC] + adds r4, r0 + str r4, [sp, 0x10] + mov r1, r10 + lsrs r0, r1, 2 + lsls r0, 3 + mov r2, r8 + adds r1, r2, r0 + ldr r2, [sp, 0x8] + adds r2, 0x4 +_081AA8C2: + movs r4, 0 + ldrsh r0, [r2, r4] + ldr r4, [sp, 0x10] + cmp r0, r4 + bne _081AA8D4 + movs r4, 0x2 + ldrsh r0, [r2, r4] + cmp r0, r1 + beq _081AA8DC +_081AA8D4: + adds r2, 0x18 + adds r3, 0x1 + cmp r3, r6 + blt _081AA8C2 +_081AA8DC: + cmp r3, r6 + bne _081AA950 + lsls r0, r6, 1 + mov r8, r0 + adds r0, r6 + lsls r0, 3 + ldr r1, [sp, 0x8] + adds r5, r0, r1 + mov r3, r12 + ldr r2, [r3, 0x4] + mov r4, r9 + adds r1, r4, r7 + lsls r1, 3 + adds r0, r5, 0 + adds r1, r2 + ldm r1!, {r2-r4} + stm r0!, {r2-r4} + ldm r1!, {r2-r4} + stm r0!, {r2-r4} + ldrh r0, [r5, 0x4] + ldr r1, [sp, 0xC] + adds r0, r1 + strh r0, [r5, 0x4] + mov r2, r10 + lsrs r0, r2, 2 + lsls r0, 3 + ldrh r3, [r5, 0x6] + adds r0, r3 + strh r0, [r5, 0x6] + adds r0, r6, 0x1 + strb r0, [r5] + ldrb r0, [r5, 0x1] + cmp r0, 0x3B + beq _081AA940 + adds r0, r6, 0 + bl sub_81A9F90 + lsls r0, 16 + lsrs r7, r0, 16 + adds r4, r7, 0 + adds r0, r4, 0 + bl GetBattleFacilityTrainerGfxId + strb r0, [r5, 0x1] + ldr r0, =gSaveBlock2Ptr + ldr r0, [r0] + ldr r1, =0x00000cb4 + adds r0, r1 + add r0, r8 + strh r4, [r0] +_081AA940: + movs r0, 0 + b _081AA95C + .pool +_081AA950: + adds r7, 0x1 + mov r1, r12 + ldrb r2, [r1] + cmp r7, r2 + blt _081AA868 +_081AA95A: + movs r0, 0x1 +_081AA95C: + add sp, 0x14 + pop {r3-r5} + mov r8, r3 + mov r9, r4 + mov r10, r5 + pop {r4-r7} + pop {r1} + bx r1 + thumb_func_end sub_81AA810 + + thumb_func_start sub_81AA96C +sub_81AA96C: @ 81AA96C + push {r4-r7,lr} + adds r6, r0, 0 + ldr r0, =gSaveBlock2Ptr + ldr r0, [r0] + ldr r2, =0x00000e22 + adds r1, r0, r2 + ldrh r4, [r1] + ldr r1, =0x00000e24 + adds r0, r1 + ldrh r0, [r0] + lsls r0, 16 + orrs r4, r0 + bl sub_81AA9E4 + lsls r0, 24 + lsrs r5, r0, 24 + movs r3, 0 + ldr r2, =gUnknown_08613650+0x5 + mov r12, r2 + movs r7, 0x7 +_081AA994: + adds r2, r6, r3 + adds r0, r4, 0 + ands r0, r7 + lsls r1, r5, 4 + adds r0, r1 + add r0, r12 + ldrb r0, [r0] + strb r0, [r2] + asrs r4, 3 + cmp r3, 0x7 + bne _081AA9C0 + ldr r0, =gSaveBlock2Ptr + ldr r1, [r0] + ldr r2, =0x00000e26 + adds r0, r1, r2 + ldrh r4, [r0] + ldr r0, =0x00000e28 + adds r1, r0 + ldrh r0, [r1] + lsls r0, 16 + orrs r4, r0 + asrs r4, 8 +_081AA9C0: + adds r3, 0x1 + cmp r3, 0xF + ble _081AA994 + pop {r4-r7} + pop {r0} + bx r0 + .pool + thumb_func_end sub_81AA96C + + thumb_func_start sub_81AA9E4 +sub_81AA9E4: @ 81AA9E4 + push {r4,lr} + ldr r0, =gSaveBlock2Ptr + ldr r4, [r0] + ldr r1, =0x00000e28 + adds r0, r4, r1 + ldrh r0, [r0] + movs r1, 0x64 + bl __umodsi3 + lsls r0, 16 + lsrs r3, r0, 16 + ldr r0, =0x00000cb2 + adds r4, r0 + ldrh r0, [r4] + ldr r1, =gUnknown_08613794 + adds r0, r1 + ldrb r2, [r0] + cmp r2, 0x21 + bhi _081AAA38 + ldr r1, =gUnknown_08613750 + lsls r0, r2, 1 + adds r0, r1 +_081AAA10: + ldrb r1, [r0] + cmp r3, r1 + bge _081AAA30 + ldrb r0, [r0, 0x1] + b _081AAA3A + .pool +_081AAA30: + adds r0, 0x2 + adds r2, 0x1 + cmp r2, 0x21 + bls _081AAA10 +_081AAA38: + movs r0, 0 +_081AAA3A: + pop {r4} + pop {r1} + bx r1 + thumb_func_end sub_81AA9E4 + + thumb_func_start sub_81AAA40 +sub_81AAA40: @ 81AAA40 + push {lr} + ldr r0, =gSaveBlock1Ptr + ldr r0, [r0] + movs r1, 0xC7 + lsls r1, 4 + adds r2, r0, r1 + movs r1, 0 + movs r3, 0xC7 + lsls r3, 4 + adds r0, r3 + b _081AAA6E + .pool +_081AAA5C: + adds r0, r1, 0x1 + lsls r0, 24 + lsrs r1, r0, 24 + cmp r1, 0xF + bhi _081AAA74 + lsls r0, r1, 1 + adds r0, r1 + lsls r0, 3 + adds r0, r2 +_081AAA6E: + ldrb r0, [r0] + cmp r0, 0 + bne _081AAA5C +_081AAA74: + adds r0, r1, 0 + pop {r1} + bx r1 + thumb_func_end sub_81AAA40 + + thumb_func_start sub_81AAA7C +sub_81AAA7C: @ 81AAA7C + push {r4-r7,lr} + mov r7, r8 + push {r7} + lsls r0, 24 + lsrs r0, 24 + movs r3, 0 + ldr r1, =gSaveBlock2Ptr + mov r8, r1 + lsls r1, r0, 2 + adds r1, r0 + movs r0, 0 + mov r12, r0 + lsls r4, r1, 1 + ldr r7, =0x00000e2c + movs r6, 0 + ldr r5, =0x00000e54 + lsls r2, r1, 2 +_081AAA9E: + mov r1, r8 + ldr r0, [r1] + adds r1, r0, r7 + adds r1, r2 + strh r6, [r1] + adds r1, r3, r4 + adds r0, r5 + adds r0, r1 + mov r1, r12 + strb r1, [r0] + adds r2, 0x2 + adds r3, 0x1 + cmp r3, 0x9 + ble _081AAA9E + movs r0, 0x15 + movs r1, 0x1 + bl AddPyramidBagItem + movs r0, 0x22 + movs r1, 0x1 + bl AddPyramidBagItem + pop {r3} + mov r8, r3 + pop {r4-r7} + pop {r0} + bx r0 + .pool + thumb_func_end sub_81AAA7C + + thumb_func_start GetBattlePyramidPickupItemId +GetBattlePyramidPickupItemId: @ 81AAAE0 + push {r4-r6,lr} + ldr r0, =gSaveBlock2Ptr + ldr r1, [r0] + ldr r2, =0x00000ca9 + adds r0, r1, r2 + ldrb r0, [r0] + lsls r0, 30 + lsrs r6, r0, 30 + lsls r0, r6, 1 + ldr r2, =0x00000e1a + adds r1, r2 + adds r1, r0 + ldrh r0, [r1] + movs r1, 0x7 + bl __udivsi3 + lsls r0, 16 + lsrs r4, r0, 16 + cmp r4, 0x13 + ble _081AAB0A + movs r4, 0x13 +_081AAB0A: + bl Random + lsls r0, 16 + lsrs r0, 16 + movs r1, 0x64 + bl __umodsi3 + lsls r0, 16 + lsrs r2, r0, 16 + movs r1, 0 + ldr r3, =gUnknown_08613F86 + ldrb r0, [r3] + lsls r5, r4, 2 + cmp r0, r2 + bgt _081AAB36 +_081AAB28: + adds r1, 0x1 + cmp r1, 0x9 + bhi _081AAB3A + adds r0, r1, r3 + ldrb r0, [r0] + cmp r0, r2 + ble _081AAB28 +_081AAB36: + cmp r1, 0x9 + bls _081AAB3C +_081AAB3A: + movs r1, 0x9 +_081AAB3C: + cmp r6, 0 + bne _081AAB58 + ldr r2, =sPickupItemsLvl50 + b _081AAB5A + .pool +_081AAB58: + ldr r2, =sPickupItemsLvlOpen +_081AAB5A: + lsls r1, 1 + adds r0, r5, r4 + lsls r0, 2 + adds r1, r0 + adds r1, r2 + ldrh r0, [r1] + pop {r4-r6} + pop {r1} + bx r1 + .pool + thumb_func_end GetBattlePyramidPickupItemId + + .align 2, 0 @ Don't pad with nop. diff --git a/data/battle_frontier_3.s b/data/battle_frontier_3.s index 29f0b2df1..bcf043576 100644 --- a/data/battle_frontier_3.s +++ b/data/battle_frontier_3.s @@ -72,7 +72,7 @@ gUnknown_08613794:: @ 8613794 .byte 0x00, 0x04, 0x09, 0x0e, 0x13, 0x18, 0x1d, 0x00 .align 1 -gUnknown_0861379C:: @ 861379C +sPickupItemsLvl50:: @ 861379C .2byte 0x0015, 0x0051, 0x0085, 0x0022, 0x008d, 0x0018, 0x00b3, 0x00db, 0x0019, 0x002d, 0x0015, 0x004a, 0x0087, 0x0022, 0x008a, 0x0018 .2byte 0x00c8, 0x00ba, 0x0013, 0x0025, 0x0015, 0x004b, 0x0088, 0x0022, 0x008d, 0x0018, 0x00c6, 0x00c4, 0x0019, 0x002d, 0x0015, 0x004c .2byte 0x008d, 0x0022, 0x008a, 0x0018, 0x00b7, 0x00bb, 0x0013, 0x0025, 0x0015, 0x004d, 0x0086, 0x0022, 0x008d, 0x0018, 0x00b3, 0x00db @@ -88,7 +88,7 @@ gUnknown_0861379C:: @ 861379C .2byte 0x008d, 0x0022, 0x008a, 0x0018, 0x00b7, 0x00bb, 0x0013, 0x0025 .align 1 -gUnknown_0861392C:: @ 861392C +sPickupItemsLvlOpen:: @ 861392C .2byte 0x0015, 0x0051, 0x0085, 0x0022, 0x008d, 0x0018, 0x00b3, 0x00db, 0x0019, 0x002d, 0x0015, 0x004a, 0x0087, 0x0022, 0x008a, 0x0018 .2byte 0x00c8, 0x00ba, 0x0013, 0x0025, 0x0015, 0x004b, 0x0088, 0x0022, 0x008d, 0x0018, 0x00c6, 0x00c4, 0x0019, 0x002d, 0x0015, 0x004c .2byte 0x008d, 0x0022, 0x008a, 0x0018, 0x00b7, 0x00bb, 0x0013, 0x0025, 0x0015, 0x004d, 0x0086, 0x0022, 0x008d, 0x0018, 0x00b3, 0x00db @@ -519,7 +519,7 @@ gUnknown_08613EE0:: @ 8613EE0 .4byte sub_81A917C .4byte sub_81A91FC .4byte sub_81A9254 - .4byte CalculateBattlePyramidItemBallItemId + .4byte sub_81A9290 .4byte sub_81A93C8 .4byte sub_81A9414 .4byte sub_81A9424 diff --git a/include/battle_pyramid_bag.h b/include/battle_pyramid_bag.h index 2301b0aa0..48f8de3c0 100644 --- a/include/battle_pyramid_bag.h +++ b/include/battle_pyramid_bag.h @@ -34,6 +34,7 @@ struct PyramidBagCursorData extern struct PyramidBagResources *gPyramidBagResources; extern struct PyramidBagCursorData gPyramidBagCursorData; +void sub_81C4EEC(void); void CB2_PyramidBagMenuFromStartMenu(void); void sub_81C4F84(void); void sub_81C5924(void); diff --git a/include/global.h b/include/global.h index 5a86d5daa..25e8c7faa 100644 --- a/include/global.h +++ b/include/global.h @@ -442,12 +442,14 @@ struct BattleFrontier /*0xE10*/ u8 field_E10_1:3; /*0xE10*/ u8 field_E10_2:4; /*0xE10*/ u8 field_E10_3:1; - /*0xE12*/ u16 field_E12[4]; + /*0xE12*/ u16 field_E12[3]; + /*0xE18*/ u16 field_E18; /*0xE1A*/ u16 pyramidWinStreaks[2]; /*0xE1E*/ u16 pyramidRecordStreaks[2]; - /*0xE1E*/ u16 field_E1F[5]; + /*0xE22*/ u16 field_E22[4]; + /*0xE2A*/ u8 field_E2A; /*0xE2C*/ struct PyramidBag pyramidBag; - /*0xE58*/ u16 field_E58; + /*0xE68*/ u8 field_E68; /*0xE6A*/ u16 field_E6A; /*0xE6C*/ u16 field_E6C; /*0xE6E*/ u16 field_E6E; diff --git a/ld_script.txt b/ld_script.txt index 0454dc86b..9de96ebcc 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -269,6 +269,8 @@ SECTIONS { src/battle_factory.o(.text); src/battle_pike.o(.text); asm/battle_frontier_2.o(.text); + src/battle_pyramid.o(.text); + asm/battle_pyramid.o(.text); src/item_menu.o(.text); src/list_menu.o(.text); src/dynamic_placeholder_text_util.o(.text); diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c new file mode 100644 index 000000000..248e58a9d --- /dev/null +++ b/src/battle_pyramid.c @@ -0,0 +1,425 @@ +#include "global.h" +#include "battle_pyramid_bag.h" +#include "event_data.h" +#include "battle.h" +#include "battle_setup.h" +#include "battle_tower.h" +#include "save.h" +#include "fieldmap.h" +#include "palette.h" +#include "field_message_box.h" +#include "random.h" +#include "item.h" +#include "util.h" +#include "sound.h" +#include "task.h" +#include "start_menu.h" +#include "constants/battle_frontier.h" +#include "constants/event_objects.h" + +extern void door_upload_tiles(void); + +#define PICKUP_ITEMS_SET_COUNT 20 + +struct Struct_08613650 +{ + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; + u8 unk4; + u8 unk5; + u8 unk6[10]; +}; + +extern const u16 gBattleFrontierHeldItems[]; +extern const struct FacilityMon gBattleFrontierMons[]; +extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; + +// This file's functions. +void sub_81AAA7C(u8 lvlMode); +u8 sub_81AA9E4(void); +u16 sub_81A9AA8(u8); +u8 sub_81A9998(s32 *, u8, u8); +u8 sub_81AAA40(void); +bool8 InBattlePyramid(void); +void sub_81A97DC(u8 taskId); + +// Const rom data. +extern void (* const gUnknown_08613EE0[])(void); +extern const struct Struct_08613650 gUnknown_08613650[]; +extern const u16 sPickupItemsLvl50[PICKUP_ITEMS_SET_COUNT][10]; +extern const u16 sPickupItemsLvlOpen[PICKUP_ITEMS_SET_COUNT][10]; +extern const u8 gUnknown_08613ABC[63][2]; +extern const u8 gUnknown_08613B3A[]; +extern const u16 gUnknown_08613F34[9]; +extern const u16 gUnknown_08613F28[6]; + +// code +void sub_81A8E7C(void) +{ + gUnknown_08613EE0[gSpecialVar_0x8004](); +} + +void sub_81A8E9C(void) +{ + bool32 isCurrent; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + gSaveBlock2Ptr->frontier.field_CA8 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; + gSaveBlock2Ptr->frontier.field_CA9_a = 0; + if (lvlMode != FRONTIER_LVL_50) + isCurrent = gSaveBlock2Ptr->frontier.field_CDC & 0x2000; + else + isCurrent = gSaveBlock2Ptr->frontier.field_CDC & 0x1000; + + if (!isCurrent) + { + gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] = 0; + sub_81AAA7C(lvlMode); + } + + sub_81C4EEC(); + gTrainerBattleOpponent_A = 0; + gBattleOutcome = 0; +} + +void sub_81A8F38(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + switch (gSpecialVar_0x8005) + { + case 0: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_E18; + break; + case 1: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode]; + break; + case 2: + if (lvlMode != FRONTIER_LVL_50) + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x2000; + else + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x1000; + break; + case 3: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pyramidWinStreaks[FRONTIER_LVL_50]; + break; + case 4: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pyramidWinStreaks[FRONTIER_LVL_OPEN]; + break; + case 5: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x1000; + break; + case 6: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x2000; + break; + } +} + +void sub_81A9048(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + switch (gSpecialVar_0x8005) + { + case 0: + gSaveBlock2Ptr->frontier.field_E18 = gSpecialVar_0x8006; + break; + case 1: + gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] = gSpecialVar_0x8006; + break; + case 2: + if (lvlMode != FRONTIER_LVL_50) + { + if (gSpecialVar_0x8006) + gSaveBlock2Ptr->frontier.field_CDC |= 0x2000; + else + gSaveBlock2Ptr->frontier.field_CDC &= ~(0x2000); + } + else + { + if (gSpecialVar_0x8006) + gSaveBlock2Ptr->frontier.field_CDC |= 0x1000; + else + gSaveBlock2Ptr->frontier.field_CDC &= ~(0x1000); + } + break; + case 7: + gSaveBlock2Ptr->frontier.field_E2A = gSpecialVar_0x8006; + break; + } +} + +void sub_81A9134(void) +{ + gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8005; + VarSet(VAR_TEMP_0, 0); + gSaveBlock2Ptr->frontier.field_CA9_a = 1; + save_serialize_map(); + TrySavingData(SAVE_LINK); +} + +void sub_81A917C(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] > 41) + gSaveBlock2Ptr->frontier.field_E18 = gUnknown_08613F34[Random() % ARRAY_COUNT(gUnknown_08613F34)]; + else + gSaveBlock2Ptr->frontier.field_E18 = gUnknown_08613F28[Random() % ARRAY_COUNT(gUnknown_08613F28)]; +} + +void sub_81A91FC(void) +{ + if (AddBagItem(gSaveBlock2Ptr->frontier.field_E18, 1) == TRUE) + { + CopyItemName(gSaveBlock2Ptr->frontier.field_E18, gStringVar1); + gSaveBlock2Ptr->frontier.field_E18 = 0; + gSpecialVar_Result = TRUE; + } + else + { + gSpecialVar_Result = FALSE; + } +} + +void sub_81A9254(void) +{ + s32 i; + + for (i = 0; i < 4; i++) + gSaveBlock2Ptr->frontier.field_E22[i] = Random(); + + gSaveBlock2Ptr->frontier.field_E2A = 0; +} + +void sub_81A9290(void) +{ + s32 i; + s32 r7; + s32 rand; + u8 id; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u32 floor = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + u32 setId = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7) % PICKUP_ITEMS_SET_COUNT; + + if (setId >= PICKUP_ITEMS_SET_COUNT) + setId = PICKUP_ITEMS_SET_COUNT - 1; + + id = sub_81AA9E4(); + r7 = (gSpecialVar_LastTalked - gUnknown_08613650[id].unk1) - 1; + rand = gSaveBlock2Ptr->frontier.field_E22[r7 / 2]; + SeedRng2(rand); + + for (i = 0; i < r7 + 1; i++) + rand = Random2() % 100; + + for (i = gUnknown_08613B3A[floor]; i < ARRAY_COUNT(gUnknown_08613ABC); i++) + { + if (rand < gUnknown_08613ABC[i][0]) + break; + } + + if (lvlMode != FRONTIER_LVL_50) + gSpecialVar_0x8000 = sPickupItemsLvlOpen[setId][gUnknown_08613ABC[i][1]]; + else + gSpecialVar_0x8000 = sPickupItemsLvl50[setId][gUnknown_08613ABC[i][1]]; + + gSpecialVar_0x8001 = 1; +} + +void sub_81A93C8(void) +{ + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + s32 i = 0; + + for (;;) + { + if (events[i].localId == gSpecialVar_LastTalked) + { + events[i].x = 0x7FFF; + events[i].y = 0x7FFF; + break; + } + i++; + if (events[i].localId == 0) + break; + } +} + +void sub_81A9414(void) +{ + gFacilityTrainers = gBattleFrontierTrainers; +} + +extern const u8 gUnknown_08613C1C[50][2]; +extern const u8 gUnknown_08613ED8[]; +extern const u8 *const *const *const gUnknown_08613EC0[]; + +void sub_81A9424(void) +{ + s32 i; + s32 var_24; + u8 id; + s32 class = 0; + s32 r7 = 0; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + u16 trainerId = sub_81A9AA8(gEventObjects[gSelectedEventObject].localId); + + for (i = 0; i < ARRAY_COUNT(gUnknown_08613C1C); i++) + { + if (gUnknown_08613C1C[i][0] == gFacilityTrainers[trainerId].facilityClass) + { + class = gUnknown_08613C1C[i][1]; + break; + } + } + + var_24 = gUnknown_08613ED8[gEventObjects[gSelectedEventObject].localId - 1]; + i = 0; + while (!i) + { + switch (var_24) + { + case 0: + r7 = sub_81A9998(&var_24, 8, 0); + i = 1; + break; + case 1: + for (i = 0; i < sub_81AAA40(); i++) + { + if (events[i].graphicsId == EVENT_OBJ_GFX_ITEM_BALL && events[i].x != 0x7FFF && events[i].y != 0x7FFF) + r7++; + } + i = 1; + break; + case 2: + id = sub_81AA9E4(); + r7 = gUnknown_08613650[id].unk1; + for (i = 0; i < 8; i++) + { + if (gBitTable[i] & gSaveBlock2Ptr->frontier.field_E2A) + r7--; + } + i = 1; + break; + case 3: + sub_81A9998(&var_24, 8, 2); + break; + case 4: + sub_81A9998(&var_24, 8, 1); + break; + case 5: + sub_81A9998(&var_24, 16, 2); + break; + case 6: + sub_81A9998(&var_24, 16, 1); + break; + case 7: + sub_81A9998(&var_24, 24, 2); + break; + case 8: + sub_81A9998(&var_24, 24, 1); + break; + } + } + ShowFieldMessage(gUnknown_08613EC0[class][var_24][r7]); +} + +void sub_81A9618(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] < 999) + gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode]++; + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] > gSaveBlock2Ptr->frontier.pyramidRecordStreaks[lvlMode]) + gSaveBlock2Ptr->frontier.pyramidRecordStreaks[lvlMode] = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode]; +} + +void sub_81A966C(void) +{ + gSpecialVar_Result = InBattlePyramid(); +} + +void sub_81A9684(void) +{ + switch (gSpecialVar_0x8006) + { + case 0: + gSaveBlock2Ptr->frontier.field_E68 = gSpecialVar_0x8005; + break; + case 1: + switch (gSpecialVar_Result) + { + case 0: + if (!gPaletteFade.active) + { + if (gSaveBlock2Ptr->frontier.field_E68 >= 120) + gSaveBlock2Ptr->frontier.field_E68 = 120; + else + PlaySE(gSpecialVar_0x8007); + gSpecialVar_Result++; + } + break; + case 1: + if (gSpecialVar_0x8005 != 0) + { + gSpecialVar_0x8005--; + gSaveBlock2Ptr->frontier.field_E68++; + if (gSaveBlock2Ptr->frontier.field_E68 > 120) + { + gSaveBlock2Ptr->frontier.field_E68 = 120; + gSpecialVar_Result++; + } + door_upload_tiles(); + } + else + { + gSpecialVar_Result = 2; + } + break; + case 2: + default: + break; + } + break; + } +} + +void sub_81A975C(void) +{ + s32 i, j; + u16 item = 0; + + for (i = 0; i < PARTY_SIZE; i++) + { + for (j = 0; j < 4; j++) + { + if (gSaveBlock2Ptr->frontier.selectedPartyMons[j] != 0 && gSaveBlock2Ptr->frontier.selectedPartyMons[j] - 1 == i) + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &item); + } + } +} + +void sub_81A97C8(void) +{ + CreateTask(sub_81A97DC, 0); +} + +extern const u16 gUnknown_08D856C8[][16]; + +void sub_81A97DC(u8 taskId) +{ + if (gPaletteFade.active) + { + CpuCopy16(gUnknown_08D856C8[gSaveBlock2Ptr->frontier.curChallengeBattleNum], &gPlttBufferUnfaded[96], 32); + DestroyTask(taskId); + } +} + +void sub_81A9828(void) +{ + sub_809FDD4(); +} diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 665ee3750..920e1045b 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9860,71 +9860,72 @@ static void atkE4_getsecretpowereffect(void) static void atkE5_pickup(void) { - if (!InBattlePike()) + s32 i; + u16 species, heldItem; + u8 ability; + + if (InBattlePike()) { - s32 i; - u16 species, heldItem; - u8 ability; - if (InBattlePyramid()) + } + else if (InBattlePyramid()) + { + for (i = 0; i < PARTY_SIZE; i++) { - for (i = 0; i < 6; i++) + species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); + heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + + if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY)) + ability = gBaseStats[species].ability2; + else + ability = gBaseStats[species].ability1; + + if (ability == ABILITY_PICKUP + && species != 0 + && species != SPECIES_EGG + && heldItem == ITEM_NONE + && (Random() % 10) == 0) { - species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); - heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); - - if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY)) - ability = gBaseStats[species].ability2; - else - ability = gBaseStats[species].ability1; - - if (ability == ABILITY_PICKUP - && species != 0 - && species != SPECIES_EGG - && heldItem == ITEM_NONE - && (Random() % 10) == 0) - { - heldItem = GetBattlePyramidPickupItemId(); - SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &heldItem); - } + heldItem = GetBattlePyramidPickupItemId(); + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &heldItem); } } - else + } + else + { + for (i = 0; i < PARTY_SIZE; i++) { - for (i = 0; i < 6; i++) + species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); + heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + + if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY)) + ability = gBaseStats[species].ability2; + else + ability = gBaseStats[species].ability1; + + if (ability == ABILITY_PICKUP + && species != 0 + && species != SPECIES_EGG + && heldItem == ITEM_NONE + && (Random() % 10) == 0) { - species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); - heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + s32 j; + s32 rand = Random() % 100; + u8 lvlDivBy10 = (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) - 1) / 10; + if (lvlDivBy10 > 9) + lvlDivBy10 = 9; - if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY)) - ability = gBaseStats[species].ability2; - else - ability = gBaseStats[species].ability1; - - if (ability == ABILITY_PICKUP - && species != 0 - && species != SPECIES_EGG - && heldItem == ITEM_NONE - && (Random() % 10) == 0) + for (j = 0; j < 9; j++) { - s32 j; - s32 rand = Random() % 100; - u8 lvlDivBy10 = (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) - 1) / 10; - if (lvlDivBy10 > 9) - lvlDivBy10 = 9; - - for (j = 0; j < 9; j++) + if (sPickupProbabilities[j] > rand) { - if (sPickupProbabilities[j] > rand) - { - SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sPickupItems[lvlDivBy10 + j]); - break; - } - else if (rand == 99 || rand == 98) - { - SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sRarePickupItems[lvlDivBy10 + (99 - rand)]); - break; - } + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sPickupItems[lvlDivBy10 + j]); + break; + } + else if (rand == 99 || rand == 98) + { + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sRarePickupItems[lvlDivBy10 + (99 - rand)]); + break; } } } diff --git a/src/graphics.c b/src/graphics.c index b055e5249..005737035 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1485,7 +1485,7 @@ const u32 gUnknown_08DD4C4C[] = INCBIN_U32("graphics/link/link_winedge.bin.lz"); const u32 gUnknown_08DD4CF8[] = INCBIN_U32("graphics/interface/unk_change_case.4bpp.lz"); -const u16 gTilesetPalettes_General[][16] = +const u16 gTilesetPalettes_General[][16] = { INCBIN_U16("data/tilesets/primary/general/palettes/00.gbapal"), INCBIN_U16("data/tilesets/primary/general/palettes/01.gbapal"), From 40a44a8508fb728e2bc528586c6fba717222751f Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 17 Nov 2018 22:55:39 +0100 Subject: [PATCH 2/7] more battle pytamid --- asm/battle_pyramid.s | 1183 ------------------------------------------ src/battle_pyramid.c | 425 ++++++++++++++- src/overworld.c | 4 +- src/start_menu.c | 6 +- 4 files changed, 415 insertions(+), 1203 deletions(-) diff --git a/asm/battle_pyramid.s b/asm/battle_pyramid.s index 8d1c5b6b6..eb63d0838 100644 --- a/asm/battle_pyramid.s +++ b/asm/battle_pyramid.s @@ -8,1189 +8,6 @@ - thumb_func_start sub_81A9834 -sub_81A9834: @ 81A9834 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x18 - movs r0, 0 - str r0, [sp] -_081A9844: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, [sp] - lsls r1, r2, 1 - ldr r5, =0x00000caa - adds r0, r5 - adds r0, r1 - ldrh r0, [r0] - subs r5, r0, 0x1 - movs r0, 0 - str r0, [sp, 0x4] - movs r2, 0x64 - adds r1, r5, 0 - muls r1, r2 - str r1, [sp, 0x8] - movs r0, 0x8E - lsls r0, 2 - adds r6, r1, r0 - movs r1, 0 - str r1, [sp, 0x10] -_081A986C: - ldr r2, =gSaveBlock1Ptr - ldr r0, [r2] - adds r0, r6 - movs r1, 0xB - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - ldr r3, =gPlayerParty - ldr r1, [sp, 0x10] - adds r0, r1, r3 - movs r1, 0xB - movs r2, 0 - str r3, [sp, 0x14] - bl GetMonData - ldr r3, [sp, 0x14] - cmp r4, r0 - bne _081A993C - movs r6, 0 - adds r2, r5, 0x1 - str r2, [sp, 0xC] - movs r1, 0x64 - adds r0, r5, 0 - muls r0, r1 - movs r5, 0x8E - lsls r5, 2 - adds r5, r0 - mov r9, r5 - ldr r7, [sp, 0x4] - muls r7, r1 - mov r10, r3 -_081A98AC: - movs r5, 0 - adds r0, r6, 0x1 - mov r8, r0 - b _081A98C6 - .pool -_081A98C4: - adds r5, 0x1 -_081A98C6: - cmp r5, 0x3 - bgt _081A98EE - ldr r1, =gSaveBlock1Ptr - ldr r0, [r1] - add r0, r9 - adds r1, r5, 0 - adds r1, 0xD - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - adds r1, r6, 0 - adds r1, 0xD - mov r2, r10 - adds r0, r7, r2 - movs r2, 0 - bl GetMonData - cmp r4, r0 - bne _081A98C4 -_081A98EE: - cmp r5, 0x4 - bne _081A9900 - lsls r2, r6, 24 - lsrs r2, 24 - mov r5, r10 - adds r0, r7, r5 - movs r1, 0xA6 - bl SetMonMoveSlot -_081A9900: - mov r6, r8 - cmp r6, 0x3 - ble _081A98AC - ldr r1, =gSaveBlock1Ptr - ldr r0, [r1] - ldr r2, [sp, 0x8] - adds r0, r2 - movs r5, 0x8E - lsls r5, 2 - adds r0, r5 - ldr r1, =gPlayerParty - ldr r2, [sp, 0x10] - adds r1, r2, r1 - movs r2, 0x64 - bl memcpy - ldr r0, =gUnknown_0203CEF8 - ldr r5, [sp, 0x4] - adds r0, r5, r0 - mov r1, sp - ldrb r1, [r1, 0xC] - strb r1, [r0] - b _081A994C - .pool -_081A993C: - ldr r2, [sp, 0x10] - adds r2, 0x64 - str r2, [sp, 0x10] - ldr r0, [sp, 0x4] - adds r0, 0x1 - str r0, [sp, 0x4] - cmp r0, 0x2 - ble _081A986C -_081A994C: - ldr r1, [sp] - adds r1, 0x1 - str r1, [sp] - cmp r1, 0x2 - bgt _081A9958 - b _081A9844 -_081A9958: - movs r2, 0 - str r2, [sp] - ldr r4, =gSaveBlock2Ptr - ldr r3, =0x00000caa - ldr r2, =gUnknown_0203CEF8 -_081A9962: - ldr r1, [r4] - ldr r5, [sp] - lsls r0, r5, 1 - adds r1, r3 - adds r1, r0 - adds r0, r5, r2 - ldrb r0, [r0] - strh r0, [r1] - adds r5, 0x1 - str r5, [sp] - cmp r5, 0x2 - ble _081A9962 - add sp, 0x18 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9834 - - thumb_func_start sub_81A9998 -sub_81A9998: @ 81A9998 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - mov r10, r0 - lsls r1, 24 - lsrs r6, r1, 24 - lsls r2, 24 - lsrs r7, r2, 24 - movs r4, 0 - ldr r0, =gUnknown_03005DC0 - ldr r5, [r0, 0x8] - ldr r1, [r0] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 1 - adds r0, 0xE - adds r5, r0 - movs r3, 0 - ldr r0, =0x000003ff - mov r8, r0 - ldr r1, =0x0000028e - mov r12, r1 - ldr r0, =gEventObjects - mov r9, r0 -_081A99CC: - movs r2, 0 -_081A99CE: - lsls r0, r2, 1 - adds r0, r5 - ldrh r1, [r0] - mov r0, r8 - ands r0, r1 - cmp r0, r12 - bne _081A9A8A - adds r2, 0x7 - ldr r0, =gSelectedEventObject - ldrb r1, [r0] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - add r0, r9 - movs r5, 0xC - ldrsh r1, [r0, r5] - subs r2, r1 - adds r1, r3, 0x7 - movs r3, 0xE - ldrsh r0, [r0, r3] - subs r3, r1, r0 - cmp r2, r6 - bge _081A9A0E - negs r0, r6 - cmp r2, r0 - ble _081A9A0E - cmp r3, r6 - bge _081A9A0E - cmp r3, r0 - ble _081A9A0E - cmp r7, 0 - bne _081A9A84 -_081A9A0E: - cmp r2, 0 - ble _081A9A34 - cmp r3, 0 - ble _081A9A34 - movs r4, 0x3 - cmp r2, r3 - blt _081A9A7C - movs r4, 0x2 - b _081A9A7C - .pool -_081A9A34: - cmp r2, 0 - bge _081A9A46 - cmp r3, 0 - bge _081A9A46 - movs r4, 0x1 - cmp r2, r3 - ble _081A9A7C - movs r4, 0 - b _081A9A7C -_081A9A46: - cmp r2, 0 - bne _081A9A54 - movs r4, 0 - cmp r3, 0 - ble _081A9A7C - movs r4, 0x3 - b _081A9A7C -_081A9A54: - cmp r3, 0 - bne _081A9A62 - movs r4, 0x1 - cmp r2, 0 - ble _081A9A7C - movs r4, 0x2 - b _081A9A7C -_081A9A62: - cmp r2, 0 - bge _081A9A72 - adds r0, r2, r3 - movs r4, 0x1 - cmp r0, 0 - ble _081A9A7C - movs r4, 0x3 - b _081A9A7C -_081A9A72: - adds r0, r2, r3 - mvns r0, r0 - asrs r4, r0, 31 - movs r0, 0x2 - ands r4, r0 -_081A9A7C: - movs r0, 0 - mov r5, r10 - str r0, [r5] - b _081A9A98 -_081A9A84: - mov r0, r10 - str r7, [r0] - b _081A9A98 -_081A9A8A: - adds r2, 0x1 - cmp r2, 0x1F - ble _081A99CE - adds r5, 0x5E - adds r3, 0x1 - cmp r3, 0x1F - ble _081A99CC -_081A9A98: - adds r0, r4, 0 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81A9998 - - thumb_func_start sub_81A9AA8 -sub_81A9AA8: @ 81A9AA8 - lsls r0, 24 - ldr r1, =gSaveBlock2Ptr - ldr r1, [r1] - lsrs r0, 23 - adds r1, r0 - ldr r0, =0x00000cb2 - adds r1, r0 - ldrh r0, [r1] - bx lr - .pool - thumb_func_end sub_81A9AA8 - - thumb_func_start GetBattlePyramidTrainerFlag -GetBattlePyramidTrainerFlag: @ 81A9AC4 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gSaveBlock2Ptr - ldr r2, [r1] - ldr r1, =0x00000e2a - adds r2, r1 - ldr r4, =gBitTable - ldr r3, =gEventObjects - lsls r1, r0, 3 - adds r1, r0 - lsls r1, 2 - adds r1, r3 - ldrb r0, [r1, 0x8] - subs r0, 0x1 - lsls r0, 2 - adds r0, r4 - ldr r0, [r0] - ldrb r1, [r2] - ands r0, r1 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end GetBattlePyramidTrainerFlag - - thumb_func_start sub_81A9B04 -sub_81A9B04: @ 81A9B04 - push {lr} - ldr r0, =gTrainerBattleOpponent_A - ldrh r0, [r0] - bl sub_81A9B44 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 8 - ands r0, r1 - cmp r0, 0 - beq _081A9B2E - movs r0, 0x1 - bl GetChosenApproachingTrainerEventObjectId - ldr r1, =gSelectedEventObject - strb r0, [r1] - ldr r0, =gTrainerBattleOpponent_B - ldrh r0, [r0] - bl sub_81A9B44 -_081A9B2E: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9B04 - - thumb_func_start sub_81A9B44 -sub_81A9B44: @ 81A9B44 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - lsls r0, 16 - lsrs r5, r0, 16 - movs r3, 0 - ldr r0, =gEventObjects - mov r12, r0 - ldr r6, =gSelectedEventObject - ldr r1, =gSaveBlock1Ptr - mov r10, r1 - ldr r7, =gSaveBlock2Ptr - mov r9, r7 - ldr r0, =0x00000cb4 - mov r8, r0 - ldr r4, =gBitTable -_081A9B68: - mov r1, r9 - ldr r2, [r1] - lsls r0, r3, 1 - mov r7, r8 - adds r1, r2, r7 - adds r1, r0 - ldrh r0, [r1] - cmp r0, r5 - bne _081A9B86 - ldr r1, =0x00000e2a - adds r0, r2, r1 - ldr r1, [r4] - ldrb r2, [r0] - orrs r1, r2 - strb r1, [r0] -_081A9B86: - adds r4, 0x4 - adds r3, 0x1 - cmp r3, 0x7 - ble _081A9B68 - ldrb r1, [r6] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - add r0, r12 - movs r3, 0x2 - strb r3, [r0, 0x6] - mov r7, r10 - ldr r2, [r7] - ldr r0, =gSpecialVar_LastTalked - ldrh r1, [r0] - subs r1, 0x1 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 3 - adds r2, r0 - ldr r1, =0x00000c79 - adds r2, r1 - strb r3, [r2] - ldrb r1, [r6] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - add r0, r12 - ldrh r1, [r0, 0x10] - strh r1, [r0, 0xC] - ldrb r1, [r6] - lsls r0, r1, 3 - adds r0, r1 - lsls r0, 2 - add r0, r12 - ldrh r1, [r0, 0x12] - strh r1, [r0, 0xE] - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9B44 - - thumb_func_start GenerateBattlePyramidWildMon -GenerateBattlePyramidWildMon: @ 81A9C04 - push {r4-r6,lr} - sub sp, 0x14 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r5, r0, 30 - lsls r0, r5, 1 - ldr r2, =0x00000e1a - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x14 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x13 - bls _081A9C3A - movs r0, 0x13 -_081A9C3A: - cmp r5, 0 - beq _081A9C54 - ldr r1, =gBattlePyramidOpenLevelWildMonPointers - b _081A9C56 - .pool -_081A9C54: - ldr r1, =gBattlePyramidLevel50WildMonPointers -_081A9C56: - lsls r0, 2 - adds r0, r1 - ldr r6, [r0] - ldr r4, =gEnemyParty - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - subs r0, 0x1 - str r0, [sp, 0x10] - lsls r2, r0, 1 - adds r2, r0 - lsls r2, 2 - adds r2, r6, r2 - adds r0, r4, 0 - movs r1, 0xB - bl SetMonData - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrh r1, [r0] - mov r0, sp - bl GetSpeciesName - adds r0, r4, 0 - movs r1, 0x2 - mov r2, sp - bl SetMonData - cmp r5, 0 - beq _081A9CD4 - bl SetFacilityPtrsGetLevel - lsls r0, 24 - lsrs r5, r0, 24 - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrb r0, [r0, 0x2] - subs r5, r0 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xB - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - subs r0, 0x5 - adds r5, r0 - b _081A9CF6 - .pool -_081A9CD4: - bl Random - ldr r2, [sp, 0x10] - lsls r1, r2, 1 - adds r1, r2 - lsls r1, 2 - adds r1, r6 - ldrb r4, [r1, 0x2] - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xB - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - subs r0, 0x5 - adds r5, r4, r0 -_081A9CF6: - ldr r4, =gEnemyParty - ldr r2, =gBaseStats - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrh r1, [r0] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r1, [r0, 0x13] - movs r0, 0xCA - lsls r0, 1 - adds r2, r1, 0 - muls r2, r0 - lsls r0, r5, 2 - ldr r1, =gExperienceTables - adds r0, r1 - adds r2, r0 - adds r0, r4, 0 - movs r1, 0x19 - bl SetMonData - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrb r1, [r0, 0x3] - cmp r1, 0 - blt _081A9D4C - cmp r1, 0x1 - bgt _081A9D4C - adds r2, r0, 0x3 - b _081A9D7C - .pool -_081A9D4C: - ldr r2, =gBaseStats - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - ldrh r1, [r0] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x17] - cmp r0, 0 - beq _081A9D90 - ldr r4, =gEnemyParty - adds r0, r4, 0 - movs r1, 0 - movs r2, 0 - bl GetMonData - movs r1, 0x1 - ands r1, r0 - str r1, [sp, 0xC] - add r2, sp, 0xC -_081A9D7C: - adds r0, r4, 0 - movs r1, 0x2E - bl SetMonData - b _081A9D9C - .pool -_081A9D90: - str r0, [sp, 0xC] - ldr r0, =gEnemyParty - add r2, sp, 0xC - movs r1, 0x2E - bl SetMonData -_081A9D9C: - movs r0, 0 - str r0, [sp, 0xC] - movs r2, 0 - lsls r4, r5, 1 -_081A9DA4: - ldr r1, [sp, 0x10] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r6 - lsls r1, r2, 1 - adds r0, 0x4 - adds r0, r1 - ldrh r1, [r0] - lsls r2, 24 - lsrs r2, 24 - ldr r0, =gEnemyParty - bl SetMonMoveSlot - ldr r0, [sp, 0xC] - adds r0, 0x1 - str r0, [sp, 0xC] - adds r2, r0, 0 - cmp r2, 0x3 - ble _081A9DA4 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e1a - adds r0, r1 - adds r0, r4 - ldrh r0, [r0] - cmp r0, 0x8B - bls _081A9E0C - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x11 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - adds r0, 0xF - str r0, [sp, 0x10] - movs r0, 0 - str r0, [sp, 0xC] -_081A9DF6: - adds r1, r0, 0 - adds r1, 0x27 - ldr r0, =gEnemyParty - add r2, sp, 0x10 - bl SetMonData - ldr r0, [sp, 0xC] - adds r0, 0x1 - str r0, [sp, 0xC] - cmp r0, 0x5 - ble _081A9DF6 -_081A9E0C: - ldr r0, =gEnemyParty - bl CalculateMonStats - add sp, 0x14 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end GenerateBattlePyramidWildMon - - thumb_func_start sub_81A9E28 -sub_81A9E28: @ 81A9E28 - push {lr} - bl sub_81AA9E4 - lsls r0, 24 - ldr r1, =gUnknown_08613650 - lsrs r0, 20 - adds r0, r1 - ldrb r0, [r0, 0x4] - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A9E28 - - thumb_func_start InBattlePyramid -InBattlePyramid: @ 81A9E40 - push {lr} - ldr r0, =gMapHeader - ldrh r1, [r0, 0x12] - ldr r0, =0x00000169 - cmp r1, r0 - bne _081A9E58 - movs r0, 0x1 - b _081A9E66 - .pool -_081A9E58: - movs r0, 0xBD - lsls r0, 1 - cmp r1, r0 - beq _081A9E64 - movs r0, 0 - b _081A9E66 -_081A9E64: - movs r0, 0x2 -_081A9E66: - pop {r1} - bx r1 - thumb_func_end InBattlePyramid - - thumb_func_start sub_81A9E6C -sub_81A9E6C: @ 81A9E6C - push {lr} - movs r2, 0 - ldr r0, =gMapHeader - ldrh r1, [r0, 0x12] - ldr r0, =0x00000169 - cmp r1, r0 - beq _081A9E80 - adds r0, 0x11 - cmp r1, r0 - bne _081A9E82 -_081A9E80: - movs r2, 0x1 -_081A9E82: - adds r0, r2, 0 - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A9E6C - - thumb_func_start sub_81A9E90 -sub_81A9E90: @ 81A9E90 - push {lr} - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - beq _081A9EB8 - bl sub_81A9834 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000ca8 - adds r0, r1 - movs r1, 0x2 - strb r1, [r0] - ldr r0, =0x0000400e - movs r1, 0 - bl VarSet - bl LoadPlayerParty -_081A9EB8: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9E90 - - thumb_func_start sub_81A9EC8 -sub_81A9EC8: @ 81A9EC8 - push {lr} - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - beq _081A9ED8 - bl DoSoftReset -_081A9ED8: - pop {r0} - bx r0 - thumb_func_end sub_81A9EC8 - - thumb_func_start sub_81A9EDC -sub_81A9EDC: @ 81A9EDC - push {lr} - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gFacilityTrainers - movs r1, 0x34 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0xC - bl FrontierSpeechToString - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9EDC - - thumb_func_start sub_81A9EFC -sub_81A9EFC: @ 81A9EFC - push {lr} - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gFacilityTrainers - movs r1, 0x34 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0x18 - bl FrontierSpeechToString - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9EFC - - thumb_func_start sub_81A9F1C -sub_81A9F1C: @ 81A9F1C - push {lr} - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gFacilityTrainers - movs r1, 0x34 - muls r1, r0 - ldr r0, [r2] - adds r0, r1 - adds r0, 0x24 - bl FrontierSpeechToString - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9F1C - - thumb_func_start GetTrainerEncounterMusicIdInBattlePyramind -GetTrainerEncounterMusicIdInBattlePyramind: @ 81A9F3C - push {r4,lr} - lsls r0, 16 - lsrs r0, 16 - movs r4, 0 - ldr r3, =gFacilityClassToTrainerClass - ldr r1, =gFacilityTrainers - ldr r2, [r1] - movs r1, 0x34 - muls r0, r1 - adds r0, r2 - ldrb r0, [r0] - adds r0, r3 - ldrb r2, [r0] - ldr r1, =gUnknown_08613B44 -_081A9F58: - ldrb r0, [r1] - cmp r0, r2 - bne _081A9F70 - ldrb r0, [r1, 0x1] - b _081A9F7A - .pool -_081A9F70: - adds r1, 0x4 - adds r4, 0x1 - cmp r4, 0x35 - bls _081A9F58 - movs r0, 0 -_081A9F7A: - pop {r4} - pop {r1} - bx r1 - thumb_func_end GetTrainerEncounterMusicIdInBattlePyramind - - thumb_func_start sub_81A9F80 -sub_81A9F80: @ 81A9F80 - push {lr} - ldr r0, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88 - bl ScriptContext1_SetupScript - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A9F80 - - thumb_func_start sub_81A9F90 -sub_81A9F90: @ 81A9F90 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, =gSaveBlock2Ptr - ldr r4, [r0] - ldr r1, =0x00000ca9 - adds r0, r4, r1 - ldrb r1, [r0] - lsls r1, 30 - lsrs r1, 29 - ldr r2, =0x00000e1a - adds r0, r4, r2 - adds r0, r1 - ldrh r0, [r0] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r0, 16 - ldr r1, =0x00000cb2 - adds r4, r1 - ldrh r1, [r4] - cmp r1, 0x7 - bne _081AA020 - adds r0, 0x1 - lsls r7, r0, 24 - lsls r1, 24 - mov r8, r1 -_081A9FCC: - lsrs r0, r7, 24 - mov r2, r8 - lsrs r1, r2, 24 - bl sub_8162548 - lsls r0, 16 - lsrs r3, r0, 16 - movs r2, 0 - cmp r2, r5 - bge _081AA004 - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r4, =0x00000cb4 - adds r0, r4 - ldrh r0, [r0] - cmp r0, r3 - beq _081AA004 - adds r6, r1, 0 -_081A9FF0: - adds r2, 0x1 - cmp r2, r5 - bge _081AA004 - ldr r0, [r6] - lsls r1, r2, 1 - adds r0, r4 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r3 - bne _081A9FF0 -_081AA004: - cmp r2, r5 - bne _081A9FCC - b _081AA062 - .pool -_081AA020: - lsls r1, 24 - mov r8, r1 - lsls r7, r0, 24 -_081AA026: - lsrs r0, r7, 24 - mov r2, r8 - lsrs r1, r2, 24 - bl sub_8162548 - lsls r0, 16 - lsrs r3, r0, 16 - movs r2, 0 - cmp r2, r5 - bge _081AA05E - ldr r1, =gSaveBlock2Ptr - ldr r0, [r1] - ldr r4, =0x00000cb4 - adds r0, r4 - ldrh r0, [r0] - cmp r0, r3 - beq _081AA05E - adds r6, r1, 0 -_081AA04A: - adds r2, 0x1 - cmp r2, r5 - bge _081AA05E - ldr r0, [r6] - lsls r1, r2, 1 - adds r0, r4 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r3 - bne _081AA04A -_081AA05E: - cmp r2, r5 - bne _081AA026 -_081AA062: - adds r0, r3, 0 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A9F90 - - thumb_func_start sub_81AA078 -sub_81AA078: @ 81AA078 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x1C - str r0, [sp, 0x4] - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x8] - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0xC] - bl sub_81AA96C - mov r4, sp - adds r4, 0x1 - mov r0, sp - adds r1, r4, 0 - bl sub_81AA33C - movs r7, 0 -_081AA0A6: - ldr r1, [sp, 0xC] - adds r0, r1, r7 - ldrb r0, [r0] - ldr r2, =0x00000169 - adds r0, r2 - lsls r0, 2 - ldr r1, =gMapLayouts - adds r0, r1 - ldr r6, [r0] - ldr r2, [r6, 0xC] - mov r10, r2 - ldr r0, [sp, 0x4] - ldr r1, =gUnknown_03005DC0 - str r0, [r1, 0x8] - ldr r0, [r6] - lsls r0, 2 - adds r2, r0, 0 - adds r2, 0xF - str r2, [r1] - ldr r0, [r6, 0x4] - lsls r0, 2 - adds r0, 0xE - str r0, [r1, 0x4] - ldr r0, [sp, 0x4] - mov r9, r0 - adds r1, r7, 0 - cmp r7, 0 - bge _081AA0E0 - adds r1, r7, 0x3 -_081AA0E0: - asrs r1, 2 - ldr r4, [r6, 0x4] - adds r0, r1, 0 - muls r0, r4 - adds r0, 0x7 - muls r2, r0 - lsls r1, 2 - subs r1, r7, r1 - ldr r3, [r6] - adds r0, r1, 0 - muls r0, r3 - adds r0, 0x7 - adds r2, r0 - lsls r2, 1 - add r9, r2 - movs r1, 0 - mov r8, r1 - adds r2, r7, 0x1 - str r2, [sp, 0x10] - cmp r8, r4 - bge _081AA1B6 -_081AA10A: - movs r0, 0 - mov r12, r0 - mov r1, r8 - adds r1, 0x1 - str r1, [sp, 0x14] - cmp r12, r3 - bge _081AA1A2 - ldr r2, =gSaveBlock1Ptr - str r2, [sp, 0x18] - mov r4, r9 - mov r5, r10 -_081AA120: - ldrh r1, [r5] - ldr r0, =0x000003ff - ands r0, r1 - ldr r2, =0x0000028e - cmp r0, r2 - bne _081AA194 - mov r0, sp - ldrb r0, [r0, 0x1] - cmp r7, r0 - beq _081AA194 - mov r0, sp - ldrb r0, [r0] - cmp r7, r0 - bne _081AA164 - ldr r1, [sp, 0x8] - cmp r1, 0 - bne _081AA164 - ldr r2, [sp, 0x18] - ldr r3, [r2] - adds r2, r7, 0 - cmp r7, 0 - bge _081AA14E - adds r2, r7, 0x3 -_081AA14E: - asrs r2, 2 - lsls r1, r2, 2 - subs r1, r7, r1 - ldr r0, [r6] - muls r0, r1 - add r0, r12 - strh r0, [r3] - ldr r0, [r6, 0x4] - muls r0, r2 - add r0, r8 - strh r0, [r3, 0x2] -_081AA164: - ldrh r0, [r5] - movs r1, 0xFC - lsls r1, 8 - ands r1, r0 - ldr r2, =0x0000028d - adds r0, r2, 0 - orrs r1, r0 - strh r1, [r4] - ldr r3, [r6] - b _081AA196 - .pool -_081AA194: - strh r1, [r4] -_081AA196: - adds r4, 0x2 - adds r5, 0x2 - movs r0, 0x1 - add r12, r0 - cmp r12, r3 - blt _081AA120 -_081AA1A2: - lsls r0, r3, 3 - adds r0, 0x1E - add r9, r0 - lsls r0, r3, 1 - add r10, r0 - ldr r1, [sp, 0x14] - mov r8, r1 - ldr r0, [r6, 0x4] - cmp r8, r0 - blt _081AA10A -_081AA1B6: - ldr r7, [sp, 0x10] - cmp r7, 0xF - bgt _081AA1BE - b _081AA0A6 -_081AA1BE: - bl mapheader_run_script_with_tag_x1 - ldr r0, [sp, 0xC] - bl Free - add sp, 0x1C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81AA078 - thumb_func_start sub_81AA1D8 sub_81AA1D8: @ 81AA1D8 push {r4-r7,lr} diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 248e58a9d..1ef59a438 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -14,12 +14,22 @@ #include "sound.h" #include "task.h" #include "start_menu.h" +#include "trainer_see.h" +#include "main.h" +#include "load_save.h" +#include "script.h" +#include "malloc.h" #include "constants/battle_frontier.h" #include "constants/event_objects.h" +#include "constants/event_object_movement_constants.h" +#include "constants/moves.h" +extern u8 gUnknown_0203CEF8[3]; extern void door_upload_tiles(void); -#define PICKUP_ITEMS_SET_COUNT 20 +extern const struct MapLayout *const gMapLayouts[]; + +#define TOTAL_ROUNDS 20 struct Struct_08613650 { @@ -42,18 +52,25 @@ u8 sub_81AA9E4(void); u16 sub_81A9AA8(u8); u8 sub_81A9998(s32 *, u8, u8); u8 sub_81AAA40(void); -bool8 InBattlePyramid(void); +u8 InBattlePyramid(void); void sub_81A97DC(u8 taskId); +void sub_81A9B44(u16 trainerId); +void sub_81AA96C(u8 *); +void sub_81AA33C(u8 *, u8 *); // Const rom data. extern void (* const gUnknown_08613EE0[])(void); extern const struct Struct_08613650 gUnknown_08613650[]; -extern const u16 sPickupItemsLvl50[PICKUP_ITEMS_SET_COUNT][10]; -extern const u16 sPickupItemsLvlOpen[PICKUP_ITEMS_SET_COUNT][10]; +extern const u16 sPickupItemsLvl50[TOTAL_ROUNDS][10]; +extern const u16 sPickupItemsLvlOpen[TOTAL_ROUNDS][10]; extern const u8 gUnknown_08613ABC[63][2]; extern const u8 gUnknown_08613B3A[]; extern const u16 gUnknown_08613F34[9]; extern const u16 gUnknown_08613F28[6]; +extern const u16 gUnknown_08D856C8[][16]; +extern const u8 gUnknown_08613C1C[50][2]; +extern const u8 gUnknown_08613ED8[]; +extern const u8 *const *const *const gUnknown_08613EC0[]; // code void sub_81A8E7C(void) @@ -203,10 +220,10 @@ void sub_81A9290(void) u8 id; u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u32 floor = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - u32 setId = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7) % PICKUP_ITEMS_SET_COUNT; + u32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7) % TOTAL_ROUNDS; - if (setId >= PICKUP_ITEMS_SET_COUNT) - setId = PICKUP_ITEMS_SET_COUNT - 1; + if (round >= TOTAL_ROUNDS) + round = TOTAL_ROUNDS - 1; id = sub_81AA9E4(); r7 = (gSpecialVar_LastTalked - gUnknown_08613650[id].unk1) - 1; @@ -223,9 +240,9 @@ void sub_81A9290(void) } if (lvlMode != FRONTIER_LVL_50) - gSpecialVar_0x8000 = sPickupItemsLvlOpen[setId][gUnknown_08613ABC[i][1]]; + gSpecialVar_0x8000 = sPickupItemsLvlOpen[round][gUnknown_08613ABC[i][1]]; else - gSpecialVar_0x8000 = sPickupItemsLvl50[setId][gUnknown_08613ABC[i][1]]; + gSpecialVar_0x8000 = sPickupItemsLvl50[round][gUnknown_08613ABC[i][1]]; gSpecialVar_0x8001 = 1; } @@ -254,10 +271,6 @@ void sub_81A9414(void) gFacilityTrainers = gBattleFrontierTrainers; } -extern const u8 gUnknown_08613C1C[50][2]; -extern const u8 gUnknown_08613ED8[]; -extern const u8 *const *const *const gUnknown_08613EC0[]; - void sub_81A9424(void) { s32 i; @@ -408,8 +421,6 @@ void sub_81A97C8(void) CreateTask(sub_81A97DC, 0); } -extern const u16 gUnknown_08D856C8[][16]; - void sub_81A97DC(u8 taskId) { if (gPaletteFade.active) @@ -423,3 +434,387 @@ void sub_81A9828(void) { sub_809FDD4(); } + +void sub_81A9834(void) +{ + s32 i, j, k, l; + + for (i = 0; i < 3; i++) + { + s32 id = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1; + for (j = 0; j < 3; j++) + { + if (GetMonData(&gSaveBlock1Ptr->playerParty[id], MON_DATA_SPECIES, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_SPECIES, NULL)) + { + for (k = 0; k < 4; k++) + { + for (l = 0; l < 4; l++) + { + if (GetMonData(&gSaveBlock1Ptr->playerParty[id], MON_DATA_MOVE1 + l, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_MOVE1 + k, NULL)) + break; + } + if (l == 4) + SetMonMoveSlot(&gPlayerParty[j], MOVE_SKETCH, k); + } + gSaveBlock1Ptr->playerParty[id] = gPlayerParty[j]; + gUnknown_0203CEF8[j] = id + 1; + break; + } + } + } + + for (i = 0; i < 3; i++) + gSaveBlock2Ptr->frontier.selectedPartyMons[i] = gUnknown_0203CEF8[i]; +} + +u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) +{ + s32 i, j; + u8 ret = 0; + u16 *map = gUnknown_03005DC0.map; + map += gUnknown_03005DC0.width * 7 + 7; + + for (i = 0; i < 32; map += 47, i++) + { + for (j = 0; j < 32; j++) + { + if ((map[j] & 0x3FF) == 0x28E) + { + j += 7 - gEventObjects[gSelectedEventObject].initialCoords.x; + i += 7 - gEventObjects[gSelectedEventObject].initialCoords.y; + if (j >= arg1 || j <= -arg1 || i >= arg1 || i <= -arg1 || arg2 == 0) + { + if (j > 0 && i > 0) + { + if (j >= i) + ret = 2; + else + ret = 3; + } + else if (j < 0 && i < 0) + { + if (j > i) + ret = 0; + else + ret = 1; + } + else if (j == 0) + { + if (i > 0) + ret = 3; + else + ret = 0; + } + else if (i == 0) + { + if (j > 0) + ret = 2; + else + ret = 1; + } + else if (j < 0) + { + if (j + i > 0) + ret = 3; + else + ret = 1; + } + else + { + ret = (~(j + i) >= 0) ? 0 : 2; + } + *arg0 = 0; + } + else + { + *arg0 = arg2; + } + return ret; + } + } + } + + return ret; +} + +u16 sub_81A9AA8(u8 arg0) +{ + return gSaveBlock2Ptr->frontier.field_CB4[arg0 - 1]; +} + +bool8 GetBattlePyramidTrainerFlag(u8 eventId) +{ + return gSaveBlock2Ptr->frontier.field_E2A & gBitTable[gEventObjects[eventId].localId - 1]; +} + +void sub_81A9B04(void) +{ + sub_81A9B44(gTrainerBattleOpponent_A); + if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) + { + gSelectedEventObject = GetChosenApproachingTrainerEventObjectId(1); + sub_81A9B44(gTrainerBattleOpponent_B); + } +} + +struct PyramidWildMon +{ + u16 species; + u8 lvl; + u8 abilityBit; + u16 moves[4]; +}; + +extern const struct PyramidWildMon *const gBattlePyramidOpenLevelWildMonPointers[]; +extern const struct PyramidWildMon *const gBattlePyramidLevel50WildMonPointers[]; + +void sub_81A9B44(u16 trainerId) +{ + s32 i; + + for (i = 0; i < 8; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + gSaveBlock2Ptr->frontier.field_E2A |= gBitTable[i]; + } + + gEventObjects[gSelectedEventObject].movementType = MOVEMENT_TYPE_WANDER_AROUND; + gSaveBlock1Ptr->eventObjectTemplates[gSpecialVar_LastTalked - 1].movementType = MOVEMENT_TYPE_WANDER_AROUND; + gEventObjects[gSelectedEventObject].initialCoords.x = gEventObjects[gSelectedEventObject].currentCoords.x; + gEventObjects[gSelectedEventObject].initialCoords.y = gEventObjects[gSelectedEventObject].currentCoords.y; +} + +void GenerateBattlePyramidWildMon(void) +{ + u8 name[POKEMON_NAME_LENGTH + 1]; + s32 i; + const struct PyramidWildMon *wildMons; + u32 id; + u32 lvl = gSaveBlock2Ptr->frontier.lvlMode; + u16 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] / 7) % TOTAL_ROUNDS; + + if (round >= TOTAL_ROUNDS) + round = TOTAL_ROUNDS - 1; + + if (lvl != FRONTIER_LVL_50) + wildMons = gBattlePyramidOpenLevelWildMonPointers[round]; + else + wildMons = gBattlePyramidLevel50WildMonPointers[round]; + + id = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL) - 1; + SetMonData(&gEnemyParty[0], MON_DATA_SPECIES, &wildMons[id].species); + GetSpeciesName(name, wildMons[id].species); + SetMonData(&gEnemyParty[0], MON_DATA_NICKNAME, &name); + if (lvl != FRONTIER_LVL_50) + { + lvl = SetFacilityPtrsGetLevel(); + lvl -= wildMons[id].lvl; + lvl = lvl - 5 + (Random() % 11); + } + else + { + lvl = wildMons[id].lvl - 5 + ((Random() % 11)); + } + SetMonData(&gEnemyParty[0], + MON_DATA_EXP, + &gExperienceTables[gBaseStats[wildMons[id].species].growthRate][lvl]); + + switch (wildMons[id].abilityBit) + { + case 0: + case 1: + SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &wildMons[id].abilityBit); + break; + case 2: + default: + if (gBaseStats[wildMons[id].species].ability2) + { + i = GetMonData(&gEnemyParty[0], MON_DATA_PERSONALITY, NULL) % 2; + SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &i); + } + else + { + i = 0; + SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &i); + } + break; + } + + for (i = 0; i < 4; i++) + SetMonMoveSlot(&gEnemyParty[0], wildMons[id].moves[i], i); + + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] >= 140) // BUG: Reading outside the array as lvl was used for mon level instead of frontier lvl mode. + { + id = (Random() % 17) + 15; + for (i = 0; i < NUM_STATS; i++) + SetMonData(&gEnemyParty[0], MON_DATA_HP_IV + i, &id); + } + CalculateMonStats(&gEnemyParty[0]); +} + +u8 sub_81A9E28(void) +{ + u8 id = sub_81AA9E4(); + return gUnknown_08613650[id].unk4; +} + +u8 InBattlePyramid(void) +{ + if (gMapHeader.mapLayoutId == 361) + return 1; + else if (gMapHeader.mapLayoutId == 378) + return 2; + else + return FALSE; +} + +bool8 InBattlePyramid_(void) +{ + return (gMapHeader.mapLayoutId == 361 || gMapHeader.mapLayoutId == 378); +} + +void sub_81A9E90(void) +{ + if (InBattlePyramid()) + { + sub_81A9834(); + gSaveBlock2Ptr->frontier.field_CA8 = 2; + VarSet(VAR_TEMP_E, 0); + LoadPlayerParty(); + } +} + +void sub_81A9EC8(void) +{ + if (InBattlePyramid()) + DoSoftReset(); +} + +void sub_81A9EDC(u16 trainerId) +{ + FrontierSpeechToString(gFacilityTrainers[trainerId].speechBefore); +} + +void sub_81A9EFC(u16 trainerId) +{ + FrontierSpeechToString(gFacilityTrainers[trainerId].speechWin); +} + +void sub_81A9F1C(u16 trainerId) +{ + FrontierSpeechToString(gFacilityTrainers[trainerId].speechLose); +} + +struct ClassMusic +{ + u8 class; + u8 music; +}; + +extern const struct ClassMusic gUnknown_08613B44[54]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88[]; + +u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId) +{ + s32 i; + + for (i = 0; i < ARRAY_COUNT(gUnknown_08613B44); i++) + { + if (gUnknown_08613B44[i].class == gFacilityClassToTrainerClass[gFacilityTrainers[trainerId].facilityClass]) + return gUnknown_08613B44[i].music; + } + return 0; +} + +void sub_81A9F80(void) +{ + ScriptContext1_SetupScript(BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88); +} + +u16 sub_81A9F90(u8 count) +{ + s32 i; + u16 trainerId; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u32 challengeNum = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7; + u32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + if (battleNum == 7) + { + do + { + trainerId = sub_8162548(challengeNum + 1, battleNum); + for (i = 0 ; i < count; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + break; + } + } while (i != count); + } + else + { + do + { + trainerId = sub_8162548(challengeNum, battleNum); + for (i = 0 ; i < count; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + break; + } + } while (i != count); + } + + return trainerId; +} + +void sub_81AA078(u16 *mapArg, u8 arg1) +{ + s32 j, k; + s32 i; + u8 var0, var1; + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + sub_81AA33C(&var0, &var1); + for (i = 0; i < 16; i++) + { + u16 *map; + s32 heightAdd, widthAdd; + const struct MapLayout *mapLayout = gMapLayouts[allocated[i] + 0x169]; + const u16 *layoutMap = mapLayout->map; + + gUnknown_03005DC0.map = mapArg; + gUnknown_03005DC0.width = mapLayout->width * 4 + 15; + gUnknown_03005DC0.height = mapLayout->height * 4 + 14; + map = mapArg; + heightAdd = (((i / 4 * mapLayout->height) + 7) * (gUnknown_03005DC0.width)); + widthAdd = ((i % 4 * mapLayout->width) + 7); + map += heightAdd + widthAdd; + for (j = 0; j < mapLayout->height; j++) + { + for (k = 0; k < mapLayout->width; k++) + { + if ((layoutMap[k] & 0x3FF) != 0x28E) + { + map[k] = layoutMap[k]; + } + else if (i != var1) + { + if (i == var0 && arg1 == 0) + { + gSaveBlock1Ptr->pos.x = (mapLayout->width * (i % 4)) + k; + gSaveBlock1Ptr->pos.y = (mapLayout->height * (i / 4)) + j; + } + map[k] = (layoutMap[k] & 0xFC00) | 0x28D; + } + else + { + map[k] = layoutMap[k]; + } + } + map += 15 + (mapLayout->width * 4); + layoutMap += mapLayout->width; + } + } + mapheader_run_script_with_tag_x1(); + free(allocated); +} diff --git a/src/overworld.c b/src/overworld.c index 69ac9c822..4e1f8cc4f 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -113,7 +113,7 @@ extern void ShowMapNamePopup(void); extern bool32 InTrainerHill(void); extern bool32 sub_808651C(void); extern bool8 sub_80AF6A4(void); -extern bool8 sub_81A9E6C(void); +extern bool8 InBattlePyramid_(void); extern bool8 sub_80E909C(void); extern void sub_81AA1D8(void); extern void c2_change_map(void); @@ -1808,7 +1808,7 @@ static void InitCurrentFlashLevelScanlineEffect(void) { u8 flashLevel; - if (sub_81A9E6C()) + if (InBattlePyramid_()) { door_upload_tiles(); ScanlineEffect_SetParams(sFlashEffectParams); diff --git a/src/start_menu.c b/src/start_menu.c index 173d0a79f..976cbe2a6 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -460,18 +460,18 @@ static bool32 InitStartMenuStep(void) sUnknown_02037619[0]++; break; case 3: - if (GetSafariZoneFlag() != FALSE) + if (GetSafariZoneFlag()) { ShowSafariBallsWindow(); } - if (InBattlePyramid() != FALSE) + if (InBattlePyramid()) { ShowPyramidFloorWindow(); } sUnknown_02037619[0]++; break; case 4: - if (PrintStartMenuActions(&sUnknown_02037619[1], 2) == FALSE) + if (!PrintStartMenuActions(&sUnknown_02037619[1], 2)) { break; } From 4e3772328815e4b01042239c1079395018fb8f81 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 18 Nov 2018 17:52:22 +0100 Subject: [PATCH 3/7] Document Battle Pyramid --- asm/battle_pyramid.s | 1238 ----------------- data/battle_frontier_3.s | 39 - data/event_scripts.s | 4 +- .../scripts.inc | 26 +- .../scripts.inc | 34 +- .../scripts.inc | 6 +- .../scripts.inc | 2 +- data/specials.inc | 2 +- include/battle_pyramid.h | 24 + include/global.h | 3 +- ld_script.txt | 2 +- src/battle_main.c | 7 +- src/battle_pyramid.c | 619 ++++++++- src/battle_script_commands.c | 4 +- src/battle_setup.c | 14 +- src/item.c | 2 +- src/overworld.c | 2 +- src/pokemon.c | 3 +- src/trainer_see.c | 3 +- src/wild_encounter.c | 4 +- 20 files changed, 626 insertions(+), 1412 deletions(-) delete mode 100644 asm/battle_pyramid.s create mode 100644 include/battle_pyramid.h diff --git a/asm/battle_pyramid.s b/asm/battle_pyramid.s deleted file mode 100644 index eb63d0838..000000000 --- a/asm/battle_pyramid.s +++ /dev/null @@ -1,1238 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - - - thumb_func_start sub_81AA1D8 -sub_81AA1D8: @ 81AA1D8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - movs r5, 0 - mov r6, sp - adds r6, 0x1 - add r0, sp, 0x4 - mov r8, r0 - ldr r4, =gSaveBlock2Ptr - ldr r3, =0x00000cb4 - ldr r0, =0x0000ffff - adds r2, r0, 0 -_081AA1F2: - ldr r0, [r4] - lsls r1, r5, 1 - adds r0, r3 - adds r0, r1 - ldrh r1, [r0] - orrs r1, r2 - strh r1, [r0] - adds r5, 0x1 - cmp r5, 0x7 - ble _081AA1F2 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r7, r0, 24 - mov r0, sp - adds r1, r6, 0 - bl sub_81AA33C - movs r0, 0 - str r0, [sp, 0x4] - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - movs r0, 0xC7 - lsls r0, 4 - adds r1, r0 - ldr r2, =0x05000180 - mov r0, r8 - bl CpuSet - movs r5, 0 -_081AA22E: - cmp r5, 0 - bne _081AA254 - ldr r1, =gUnknown_08613650 - lsls r0, r7, 4 - adds r0, r1 - ldrb r0, [r0, 0x3] - b _081AA25C - .pool -_081AA254: - ldr r1, =gUnknown_08613650 - lsls r0, r7, 4 - adds r0, r1 - ldrb r0, [r0, 0x2] -_081AA25C: - cmp r0, 0x4 - bhi _081AA2E4 - lsls r0, 2 - ldr r1, =_081AA274 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081AA274: - .4byte _081AA288 - .4byte _081AA292 - .4byte _081AA2A2 - .4byte _081AA2B0 - .4byte _081AA2CC -_081AA288: - lsls r0, r5, 24 - lsrs r0, 24 - bl sub_81AA398 - b _081AA2E4 -_081AA292: - lsls r0, r5, 24 - lsrs r4, r0, 24 - mov r0, sp - ldrb r1, [r0] - adds r0, r4, 0 - bl sub_81AA4D8 - b _081AA2BE -_081AA2A2: - lsls r0, r5, 24 - lsrs r4, r0, 24 - ldrb r1, [r6] - adds r0, r4, 0 - bl sub_81AA4D8 - b _081AA2BE -_081AA2B0: - lsls r0, r5, 24 - lsrs r4, r0, 24 - mov r0, sp - ldrb r1, [r0] - adds r0, r4, 0 - bl sub_81AA648 -_081AA2BE: - lsls r0, 24 - cmp r0, 0 - beq _081AA2E4 - adds r0, r4, 0 - bl sub_81AA398 - b _081AA2E4 -_081AA2CC: - lsls r0, r5, 24 - lsrs r4, r0, 24 - ldrb r1, [r6] - adds r0, r4, 0 - bl sub_81AA648 - lsls r0, 24 - cmp r0, 0 - beq _081AA2E4 - adds r0, r4, 0 - bl sub_81AA398 -_081AA2E4: - adds r5, 0x1 - cmp r5, 0x1 - ble _081AA22E - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81AA1D8 - - thumb_func_start sub_81AA2F8 -sub_81AA2F8: @ 81AA2F8 - push {r4,r5,lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r5, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F - ldr r4, =BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A - movs r2, 0xC8 - lsls r2, 4 - adds r1, r0, r2 - movs r3, 0xC7 - lsls r3, 4 - adds r2, r0, r3 - movs r3, 0x3F -_081AA310: - ldrb r0, [r2, 0x1] - cmp r0, 0x3B - beq _081AA328 - str r5, [r1] - b _081AA32A - .pool -_081AA328: - str r4, [r1] -_081AA32A: - adds r1, 0x18 - adds r2, 0x18 - subs r3, 0x1 - cmp r3, 0 - bge _081AA310 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_81AA2F8 - - thumb_func_start sub_81AA33C -sub_81AA33C: @ 81AA33C - push {r4-r7,lr} - adds r4, r0, 0 - adds r6, r1, 0 - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - ldr r2, =0x00000e28 - adds r0, r1, r2 - ldrh r2, [r0] - movs r3, 0xF - ands r2, r3 - strb r2, [r4] - ldr r7, =0x00000e22 - adds r1, r7 - ldrh r0, [r1] - ands r0, r3 - strb r0, [r6] - cmp r2, r0 - bne _081AA386 - ldr r1, [r5] - ldr r2, =0x00000e28 - adds r0, r1, r2 - ldrh r2, [r0] - adds r3, r2, 0x1 - adds r0, r3, 0 - asrs r0, 4 - lsls r0, 4 - subs r0, r3, r0 - strb r0, [r4] - adds r0, r1, r7 - ldrh r1, [r0] - adds r2, r1, 0 - adds r2, 0xF - adds r0, r2, 0 - asrs r0, 4 - lsls r0, 4 - subs r0, r2, r0 - strb r0, [r6] -_081AA386: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AA33C - - thumb_func_start sub_81AA398 -sub_81AA398: @ 81AA398 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - movs r5, 0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r6, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x8] - bl sub_81AA96C - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e26 - adds r0, r1 - ldrh r4, [r0] - movs r0, 0xF - ands r4, r0 - ldr r0, [sp] - cmp r0, 0 - bne _081AA3F0 - ldr r1, =gUnknown_08613650 - lsls r0, r6, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - mov r10, r0 - movs r1, 0 - str r1, [sp, 0x4] - b _081AA3FE - .pool -_081AA3F0: - ldr r1, =gUnknown_08613650 - lsls r0, r6, 4 - adds r0, r1 - ldrb r1, [r0] - mov r10, r1 - ldrb r0, [r0, 0x1] - str r0, [sp, 0x4] -_081AA3FE: - movs r0, 0 - mov r8, r0 - cmp r8, r10 - bge _081AA4C0 -_081AA406: - movs r1, 0x1 - add r1, r8 - mov r9, r1 - b _081AA42E - .pool -_081AA414: - lsls r2, r4, 24 - lsrs r2, 24 - ldr r3, [sp, 0x4] - add r3, r8 - lsls r3, 24 - lsrs r3, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA4B6 -_081AA42E: - ldr r0, =gBitTable - mov r12, r0 - ldr r6, =gSaveBlock2Ptr - ldr r7, =0x00000e28 - movs r3, 0x2 - lsls r0, r4, 2 - mov r1, r12 - adds r2, r0, r1 -_081AA43E: - movs r0, 0x1 - ands r0, r5 - cmp r0, 0 - beq _081AA464 - ldr r0, [r6] - adds r0, r7 - ldrh r1, [r0] - ldr r0, [r2] - ands r0, r1 - cmp r0, 0 - bne _081AA474 - b _081AA472 - .pool -_081AA464: - ldr r0, [r6] - adds r0, r7 - ldrh r1, [r0] - ldr r0, [r2] - ands r0, r1 - cmp r0, 0 - beq _081AA474 -_081AA472: - orrs r5, r3 -_081AA474: - adds r2, 0x4 - adds r4, 0x1 - cmp r4, 0xF - ble _081AA480 - mov r2, r12 - movs r4, 0 -_081AA480: - ldr r0, [r6] - ldr r1, =0x00000e26 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0xF - ands r1, r0 - cmp r4, r1 - bne _081AA4A6 - movs r1, 0x1 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0 - beq _081AA4A4 - movs r0, 0x6 - orrs r5, r0 - b _081AA4A6 - .pool -_081AA4A4: - orrs r5, r1 -_081AA4A6: - adds r0, r5, 0 - ands r0, r3 - cmp r0, 0 - beq _081AA43E - movs r0, 0x4 - ands r0, r5 - cmp r0, 0 - beq _081AA414 -_081AA4B6: - movs r0, 0x1 - ands r5, r0 - mov r8, r9 - cmp r8, r10 - blt _081AA406 -_081AA4C0: - ldr r0, [sp, 0x8] - bl Free - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81AA398 - - thumb_func_start sub_81AA4D8 -sub_81AA4D8: @ 81AA4D8 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x4] - movs r6, 0 - movs r7, 0 - movs r0, 0 - str r0, [sp, 0xC] - bl sub_81AA9E4 - lsls r0, 24 - lsrs r4, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x14] - bl sub_81AA96C - ldr r1, [sp] - cmp r1, 0 - bne _081AA524 - ldr r1, =gUnknown_08613650 - lsls r0, r4, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - str r0, [sp, 0x10] - movs r0, 0 - b _081AA530 - .pool -_081AA524: - ldr r1, =gUnknown_08613650 - lsls r0, r4, 4 - adds r0, r1 - ldrb r2, [r0] - str r2, [sp, 0x10] - ldrb r0, [r0, 0x1] -_081AA530: - movs r3, 0 - str r3, [sp, 0x8] - ldr r1, [sp, 0x10] - asrs r1, 31 - str r1, [sp, 0x18] - ldr r2, [sp, 0x10] - cmp r3, r2 - bge _081AA622 - str r0, [sp, 0x1C] - adds r3, r0, 0 - lsls r3, 24 - mov r9, r3 -_081AA548: - cmp r7, 0 - bne _081AA56E - mov r0, r9 - lsrs r3, r0, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - ldr r2, [sp, 0x4] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA568 - movs r7, 0x1 - b _081AA56E - .pool -_081AA568: - ldr r1, [sp, 0xC] - adds r1, 0x1 - str r1, [sp, 0xC] -_081AA56E: - movs r0, 0x1 - ands r0, r7 - cmp r0, 0 - beq _081AA600 - ldr r2, =gUnknown_08613F46 - mov r8, r2 - ldr r3, [sp, 0x4] - lsls r4, r3, 2 - adds r0, r6, r4 - add r0, r8 - ldrb r2, [r0] - mov r0, r9 - lsrs r3, r0, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - bl sub_81AA760 - lsls r0, 24 - ldr r1, [sp, 0x1C] - mov r10, r1 - adds r5, r4, 0 - cmp r0, 0 - beq _081AA5E8 - ldr r4, [sp, 0xC] - adds r4, 0x1 - b _081AA5C2 - .pool -_081AA5A8: - adds r0, r6, r5 - adds r0, r2 - ldrb r2, [r0] - mov r0, r10 - lsls r3, r0, 24 - lsrs r3, 24 - ldr r0, [sp] - ldr r1, [sp, 0x14] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA5E0 -_081AA5C2: - adds r6, 0x1 - ldr r0, =gUnknown_08613F46 - adds r1, r6, r5 - adds r1, r0 - ldrb r1, [r1] - adds r2, r0, 0 - cmp r1, 0xFF - beq _081AA5D6 - cmp r6, 0x3 - ble _081AA5D8 -_081AA5D6: - movs r6, 0 -_081AA5D8: - adds r7, 0x2 - asrs r0, r7, 1 - cmp r0, 0x4 - bne _081AA5A8 -_081AA5E0: - str r4, [sp, 0xC] - b _081AA600 - .pool -_081AA5E8: - adds r6, 0x1 - adds r0, r6, r4 - add r0, r8 - ldrb r0, [r0] - cmp r0, 0xFF - beq _081AA5F8 - cmp r6, 0x3 - ble _081AA5FA -_081AA5F8: - movs r6, 0 -_081AA5FA: - ldr r1, [sp, 0xC] - adds r1, 0x1 - str r1, [sp, 0xC] -_081AA600: - asrs r0, r7, 1 - cmp r0, 0x4 - beq _081AA622 - movs r0, 0x1 - ands r7, r0 - ldr r2, [sp, 0x1C] - adds r2, 0x1 - str r2, [sp, 0x1C] - movs r3, 0x80 - lsls r3, 17 - add r9, r3 - ldr r0, [sp, 0x8] - adds r0, 0x1 - str r0, [sp, 0x8] - ldr r1, [sp, 0x10] - cmp r0, r1 - blt _081AA548 -_081AA622: - movs r1, 0 - ldr r2, [sp, 0x10] - ldr r3, [sp, 0x18] - subs r0, r2, r3 - asrs r0, 1 - ldr r2, [sp, 0xC] - cmp r0, r2 - ble _081AA634 - movs r1, 0x1 -_081AA634: - adds r0, r1, 0 - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA4D8 - - thumb_func_start sub_81AA648 -sub_81AA648: @ 81AA648 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r6, r1, 24 - movs r4, 0 - movs r7, 0 - movs r0, 0 - mov r8, r0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r5, r0, 24 - movs r0, 0x10 - bl AllocZeroed - str r0, [sp, 0x8] - bl sub_81AA96C - ldr r1, [sp] - cmp r1, 0 - bne _081AA694 - ldr r1, =gUnknown_08613650 - lsls r0, r5, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - mov r10, r0 - movs r0, 0 - b _081AA6A0 - .pool -_081AA694: - ldr r1, =gUnknown_08613650 - lsls r0, r5, 4 - adds r0, r1 - ldrb r2, [r0] - mov r10, r2 - ldrb r0, [r0, 0x1] -_081AA6A0: - movs r3, 0 - str r3, [sp, 0x4] - mov r1, r10 - asrs r1, 31 - str r1, [sp, 0xC] - cmp r3, r10 - bge _081AA73E - ldr r2, =gUnknown_08613F46 - mov r9, r2 - lsls r5, r6, 2 - lsls r6, r0, 24 -_081AA6B6: - adds r0, r4, r5 - add r0, r9 - ldrb r2, [r0] - lsrs r3, r6, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA714 - adds r7, 0x1 - b _081AA6EE - .pool -_081AA6D8: - adds r0, r4, r5 - adds r0, r1 - ldrb r2, [r0] - lsrs r3, r6, 24 - ldr r0, [sp] - ldr r1, [sp, 0x8] - bl sub_81AA760 - lsls r0, 24 - cmp r0, 0 - beq _081AA728 -_081AA6EE: - adds r4, 0x1 - adds r0, r4, r5 - add r0, r9 - ldrb r0, [r0] - ldr r1, =gUnknown_08613F46 - cmp r0, 0xFF - beq _081AA700 - cmp r4, 0x3 - ble _081AA702 -_081AA700: - movs r4, 0 -_081AA702: - movs r3, 0x1 - add r8, r3 - mov r0, r8 - cmp r0, 0x4 - bne _081AA6D8 - b _081AA728 - .pool -_081AA714: - adds r4, 0x1 - adds r0, r4, r5 - add r0, r9 - ldrb r0, [r0] - cmp r0, 0xFF - beq _081AA724 - cmp r4, 0x3 - ble _081AA726 -_081AA724: - movs r4, 0 -_081AA726: - adds r7, 0x1 -_081AA728: - mov r1, r8 - cmp r1, 0x4 - beq _081AA73E - movs r2, 0x80 - lsls r2, 17 - adds r6, r2 - ldr r3, [sp, 0x4] - adds r3, 0x1 - str r3, [sp, 0x4] - cmp r3, r10 - blt _081AA6B6 -_081AA73E: - movs r1, 0 - mov r2, r10 - ldr r3, [sp, 0xC] - subs r0, r2, r3 - asrs r0, 1 - cmp r0, r7 - ble _081AA74E - movs r1, 0x1 -_081AA74E: - adds r0, r1, 0 - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA648 - - thumb_func_start sub_81AA760 -sub_81AA760: @ 81AA760 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - mov r10, r1 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r3, 24 - lsrs r7, r3, 24 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000e22 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081AA7D0 - movs r6, 0x7 -_081AA792: - movs r4, 0x7 - lsls r5, r6, 24 -_081AA796: - lsls r1, r4, 24 - lsrs r1, 24 - mov r0, r8 - str r0, [sp] - str r7, [sp, 0x4] - mov r0, r9 - lsrs r2, r5, 24 - mov r3, r10 - bl sub_81AA810 - lsls r0, 24 - cmp r0, 0 - beq _081AA7CC - subs r4, 0x1 - cmp r4, 0 - bge _081AA796 - subs r6, 0x1 - movs r1, 0x1 - negs r1, r1 - cmp r6, r1 - bgt _081AA792 - b _081AA7FC - .pool -_081AA7CC: - movs r0, 0 - b _081AA7FE -_081AA7D0: - movs r6, 0 -_081AA7D2: - movs r4, 0 - lsls r5, r6, 24 -_081AA7D6: - lsls r1, r4, 24 - lsrs r1, 24 - mov r0, r8 - str r0, [sp] - str r7, [sp, 0x4] - mov r0, r9 - lsrs r2, r5, 24 - mov r3, r10 - bl sub_81AA810 - lsls r0, 24 - cmp r0, 0 - beq _081AA7CC - adds r4, 0x1 - cmp r4, 0x7 - ble _081AA7D6 - adds r6, 0x1 - cmp r6, 0x7 - ble _081AA7D2 -_081AA7FC: - movs r0, 0x1 -_081AA7FE: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA760 - - thumb_func_start sub_81AA810 -sub_81AA810: @ 81AA810 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x14 - ldr r4, [sp, 0x34] - ldr r5, [sp, 0x38] - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r1, 24 - lsrs r1, 24 - str r1, [sp, 0x4] - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r4, 24 - lsrs r4, 24 - mov r10, r4 - lsls r5, 24 - lsrs r6, r5, 24 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r1, r0, r1 - str r1, [sp, 0x8] - add r3, r10 - ldrb r1, [r3] - adds r1, 0x2C - movs r0, 0x19 - bl Overworld_GetMapHeaderByGroupAndId - adds r5, r0, 0 - movs r7, 0 - ldr r1, [r5, 0x4] - ldrb r2, [r1] - cmp r7, r2 - bge _081AA95A - movs r0, 0x3 - ands r0, r4 - lsls r0, 3 - str r0, [sp, 0xC] -_081AA868: - ldr r1, [r1, 0x4] - lsls r2, r7, 1 - adds r0, r2, r7 - lsls r0, 3 - adds r3, r0, r1 - movs r4, 0x4 - ldrsh r0, [r3, r4] - ldr r1, [r5, 0x4] - mov r12, r1 - mov r9, r2 - ldr r2, [sp, 0x4] - cmp r0, r2 - bne _081AA950 - movs r4, 0x6 - ldrsh r0, [r3, r4] - cmp r0, r8 - bne _081AA950 - ldr r0, [sp] - cmp r0, 0 - bne _081AA896 - ldrb r0, [r3, 0x1] - cmp r0, 0x3B - bne _081AA8A2 -_081AA896: - ldr r1, [sp] - cmp r1, 0x1 - bne _081AA950 - ldrb r0, [r3, 0x1] - cmp r0, 0x3B - bne _081AA950 -_081AA8A2: - movs r3, 0 - ldr r2, [r5, 0x4] - mov r12, r2 - cmp r3, r6 - bge _081AA8DC - ldr r4, [sp, 0x4] - ldr r0, [sp, 0xC] - adds r4, r0 - str r4, [sp, 0x10] - mov r1, r10 - lsrs r0, r1, 2 - lsls r0, 3 - mov r2, r8 - adds r1, r2, r0 - ldr r2, [sp, 0x8] - adds r2, 0x4 -_081AA8C2: - movs r4, 0 - ldrsh r0, [r2, r4] - ldr r4, [sp, 0x10] - cmp r0, r4 - bne _081AA8D4 - movs r4, 0x2 - ldrsh r0, [r2, r4] - cmp r0, r1 - beq _081AA8DC -_081AA8D4: - adds r2, 0x18 - adds r3, 0x1 - cmp r3, r6 - blt _081AA8C2 -_081AA8DC: - cmp r3, r6 - bne _081AA950 - lsls r0, r6, 1 - mov r8, r0 - adds r0, r6 - lsls r0, 3 - ldr r1, [sp, 0x8] - adds r5, r0, r1 - mov r3, r12 - ldr r2, [r3, 0x4] - mov r4, r9 - adds r1, r4, r7 - lsls r1, 3 - adds r0, r5, 0 - adds r1, r2 - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - ldm r1!, {r2-r4} - stm r0!, {r2-r4} - ldrh r0, [r5, 0x4] - ldr r1, [sp, 0xC] - adds r0, r1 - strh r0, [r5, 0x4] - mov r2, r10 - lsrs r0, r2, 2 - lsls r0, 3 - ldrh r3, [r5, 0x6] - adds r0, r3 - strh r0, [r5, 0x6] - adds r0, r6, 0x1 - strb r0, [r5] - ldrb r0, [r5, 0x1] - cmp r0, 0x3B - beq _081AA940 - adds r0, r6, 0 - bl sub_81A9F90 - lsls r0, 16 - lsrs r7, r0, 16 - adds r4, r7, 0 - adds r0, r4, 0 - bl GetBattleFacilityTrainerGfxId - strb r0, [r5, 0x1] - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000cb4 - adds r0, r1 - add r0, r8 - strh r4, [r0] -_081AA940: - movs r0, 0 - b _081AA95C - .pool -_081AA950: - adds r7, 0x1 - mov r1, r12 - ldrb r2, [r1] - cmp r7, r2 - blt _081AA868 -_081AA95A: - movs r0, 0x1 -_081AA95C: - add sp, 0x14 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81AA810 - - thumb_func_start sub_81AA96C -sub_81AA96C: @ 81AA96C - push {r4-r7,lr} - adds r6, r0, 0 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000e22 - adds r1, r0, r2 - ldrh r4, [r1] - ldr r1, =0x00000e24 - adds r0, r1 - ldrh r0, [r0] - lsls r0, 16 - orrs r4, r0 - bl sub_81AA9E4 - lsls r0, 24 - lsrs r5, r0, 24 - movs r3, 0 - ldr r2, =gUnknown_08613650+0x5 - mov r12, r2 - movs r7, 0x7 -_081AA994: - adds r2, r6, r3 - adds r0, r4, 0 - ands r0, r7 - lsls r1, r5, 4 - adds r0, r1 - add r0, r12 - ldrb r0, [r0] - strb r0, [r2] - asrs r4, 3 - cmp r3, 0x7 - bne _081AA9C0 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000e26 - adds r0, r1, r2 - ldrh r4, [r0] - ldr r0, =0x00000e28 - adds r1, r0 - ldrh r0, [r1] - lsls r0, 16 - orrs r4, r0 - asrs r4, 8 -_081AA9C0: - adds r3, 0x1 - cmp r3, 0xF - ble _081AA994 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AA96C - - thumb_func_start sub_81AA9E4 -sub_81AA9E4: @ 81AA9E4 - push {r4,lr} - ldr r0, =gSaveBlock2Ptr - ldr r4, [r0] - ldr r1, =0x00000e28 - adds r0, r4, r1 - ldrh r0, [r0] - movs r1, 0x64 - bl __umodsi3 - lsls r0, 16 - lsrs r3, r0, 16 - ldr r0, =0x00000cb2 - adds r4, r0 - ldrh r0, [r4] - ldr r1, =gUnknown_08613794 - adds r0, r1 - ldrb r2, [r0] - cmp r2, 0x21 - bhi _081AAA38 - ldr r1, =gUnknown_08613750 - lsls r0, r2, 1 - adds r0, r1 -_081AAA10: - ldrb r1, [r0] - cmp r3, r1 - bge _081AAA30 - ldrb r0, [r0, 0x1] - b _081AAA3A - .pool -_081AAA30: - adds r0, 0x2 - adds r2, 0x1 - cmp r2, 0x21 - bls _081AAA10 -_081AAA38: - movs r0, 0 -_081AAA3A: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81AA9E4 - - thumb_func_start sub_81AAA40 -sub_81AAA40: @ 81AAA40 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - movs r1, 0xC7 - lsls r1, 4 - adds r2, r0, r1 - movs r1, 0 - movs r3, 0xC7 - lsls r3, 4 - adds r0, r3 - b _081AAA6E - .pool -_081AAA5C: - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0xF - bhi _081AAA74 - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 3 - adds r0, r2 -_081AAA6E: - ldrb r0, [r0] - cmp r0, 0 - bne _081AAA5C -_081AAA74: - adds r0, r1, 0 - pop {r1} - bx r1 - thumb_func_end sub_81AAA40 - - thumb_func_start sub_81AAA7C -sub_81AAA7C: @ 81AAA7C - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r0, 24 - movs r3, 0 - ldr r1, =gSaveBlock2Ptr - mov r8, r1 - lsls r1, r0, 2 - adds r1, r0 - movs r0, 0 - mov r12, r0 - lsls r4, r1, 1 - ldr r7, =0x00000e2c - movs r6, 0 - ldr r5, =0x00000e54 - lsls r2, r1, 2 -_081AAA9E: - mov r1, r8 - ldr r0, [r1] - adds r1, r0, r7 - adds r1, r2 - strh r6, [r1] - adds r1, r3, r4 - adds r0, r5 - adds r0, r1 - mov r1, r12 - strb r1, [r0] - adds r2, 0x2 - adds r3, 0x1 - cmp r3, 0x9 - ble _081AAA9E - movs r0, 0x15 - movs r1, 0x1 - bl AddPyramidBagItem - movs r0, 0x22 - movs r1, 0x1 - bl AddPyramidBagItem - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AAA7C - - thumb_func_start GetBattlePyramidPickupItemId -GetBattlePyramidPickupItemId: @ 81AAAE0 - push {r4-r6,lr} - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, =0x00000ca9 - adds r0, r1, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r6, r0, 30 - lsls r0, r6, 1 - ldr r2, =0x00000e1a - adds r1, r2 - adds r1, r0 - ldrh r0, [r1] - movs r1, 0x7 - bl __udivsi3 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x13 - ble _081AAB0A - movs r4, 0x13 -_081AAB0A: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x64 - bl __umodsi3 - lsls r0, 16 - lsrs r2, r0, 16 - movs r1, 0 - ldr r3, =gUnknown_08613F86 - ldrb r0, [r3] - lsls r5, r4, 2 - cmp r0, r2 - bgt _081AAB36 -_081AAB28: - adds r1, 0x1 - cmp r1, 0x9 - bhi _081AAB3A - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - ble _081AAB28 -_081AAB36: - cmp r1, 0x9 - bls _081AAB3C -_081AAB3A: - movs r1, 0x9 -_081AAB3C: - cmp r6, 0 - bne _081AAB58 - ldr r2, =sPickupItemsLvl50 - b _081AAB5A - .pool -_081AAB58: - ldr r2, =sPickupItemsLvlOpen -_081AAB5A: - lsls r1, 1 - adds r0, r5, r4 - lsls r0, 2 - adds r1, r0 - adds r1, r2 - ldrh r0, [r1] - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end GetBattlePyramidPickupItemId - - .align 2, 0 @ Don't pad with nop. diff --git a/data/battle_frontier_3.s b/data/battle_frontier_3.s index bcf043576..fc5a45e37 100644 --- a/data/battle_frontier_3.s +++ b/data/battle_frontier_3.s @@ -506,42 +506,3 @@ gUnknown_08613EC0:: @ 8613EC0 .4byte gUnknown_08613E9C .4byte gUnknown_08613EA8 .4byte gUnknown_08613EB4 - -gUnknown_08613ED8:: @ 8613ED8 - .byte 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x03, 0x04 - - .align 2 -gUnknown_08613EE0:: @ 8613EE0 - .4byte sub_81A8E9C - .4byte sub_81A8F38 - .4byte sub_81A9048 - .4byte sub_81A9134 - .4byte sub_81A917C - .4byte sub_81A91FC - .4byte sub_81A9254 - .4byte sub_81A9290 - .4byte sub_81A93C8 - .4byte sub_81A9414 - .4byte sub_81A9424 - .4byte sub_81A9618 - .4byte sub_81A966C - .4byte sub_81A9684 - .4byte sub_81A975C - .4byte sub_81A97C8 - .4byte sub_81A9828 - .4byte sub_81A9834 - - .align 1 -gUnknown_08613F28:: @ 8613F28 - .2byte 0x003f, 0x0040, 0x0041, 0x0043, 0x0042, 0x0046 - - .align 2 -gUnknown_08613F34:: @ 8613F34 - .2byte 0x00b3, 0x00b4, 0x00b7, 0x00c8, 0x00b9, 0x00bb, 0x00c4, 0x00c6, 0x00ba - -gUnknown_08613F46:: @ 8613F46 - .byte 0x01, 0x04, 0xff, 0xff, 0x00, 0x02, 0x05, 0xff, 0x01, 0x03, 0x06, 0xff, 0x02, 0x07, 0xff, 0xff, 0x00, 0x05, 0x08, 0xff, 0x01, 0x04, 0x06, 0x09, 0x02, 0x05, 0x07, 0x0a, 0x03, 0x06, 0x0b, 0xff - .byte 0x04, 0x09, 0x0c, 0xff, 0x05, 0x08, 0x0a, 0x0d, 0x06, 0x09, 0x0b, 0x0e, 0x07, 0x0a, 0x0f, 0xff, 0x08, 0x0d, 0xff, 0xff, 0x09, 0x0c, 0x0e, 0xff, 0x0a, 0x0d, 0x0f, 0xff, 0x0b, 0x0e, 0xff, 0xff - -gUnknown_08613F86:: @ 8613F86 - .byte 0x1e, 0x28, 0x32, 0x3c, 0x46, 0x50, 0x55, 0x5a, 0x5f, 0x64 diff --git a/data/event_scripts.s b/data/event_scripts.s index e52b95f24..115c9921a 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -1662,7 +1662,7 @@ EventScript_271C3A:: @ 8271C3A waitmessage bufferitemnameplural 1, VAR_0x8004, 32773 setvar VAR_0x8004, 12 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 1 goto_eq EventScript_271C86 msgbox gUnknown_08272A9A, 4 @@ -3361,7 +3361,7 @@ EventScript_2736F8:: @ 82736F8 compare VAR_RESULT, 1 goto_eq BattleFrontier_BattlePikeThreePathRoom_EventScript_2C4222 setvar VAR_0x8004, 12 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 1 goto_eq BattleFrontier_BattlePyramidTop_EventScript_252B42 compare VAR_RESULT, 2 diff --git a/data/maps/BattleFrontier_BattlePyramidEmptySquare/scripts.inc b/data/maps/BattleFrontier_BattlePyramidEmptySquare/scripts.inc index 6225ae0cc..facd60979 100644 --- a/data/maps/BattleFrontier_BattlePyramidEmptySquare/scripts.inc +++ b/data/maps/BattleFrontier_BattlePyramidEmptySquare/scripts.inc @@ -19,7 +19,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252A5D:: @ 8252A5D setvar VAR_RESULT, 0 BattleFrontier_BattlePyramidEmptySquare_EventScript_252A77:: @ 8252A77 - special sub_81A8E7C + special CallBattlePyramidFunction delay 2 compare VAR_RESULT, 2 goto_if 5, BattleFrontier_BattlePyramidEmptySquare_EventScript_252A77 @@ -39,7 +39,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252A98:: @ 8252A98 BattleFrontier_BattlePyramidEmptySquare_MapScript1_252AA2: @ 8252AA2 setvar VAR_0x8004, 15 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 0 special CallFrontierUtilFunc switch VAR_TEMP_0 @@ -68,7 +68,7 @@ BattleFrontier_BattlePyramidEmptySquare_MapScript1_252AA2: @ 8252AA2 BattleFrontier_BattlePyramidEmptySquare_EventScript_252B39:: @ 8252B39 setvar VAR_0x8004, 17 - special sub_81A8E7C + special CallBattlePyramidFunction end BattleFrontier_BattlePyramidEmptySquare_EventScript_252B42:: @ 8252B42 @@ -80,16 +80,16 @@ BattleFrontier_BattlePyramidTop_EventScript_252B42:: @ 8252B42 setvar VAR_0x8004, 2 setvar VAR_0x8005, 7 setvar VAR_0x8006, 255 - special sub_81A8E7C + special CallBattlePyramidFunction BattleFrontier_BattlePyramidEmptySquare_EventScript_252B66:: @ 8252B66 BattleFrontier_BattlePyramidTop_EventScript_252B66:: @ 8252B66 setvar VAR_0x8004, 13 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 14 - special sub_81A8E7C + special CallBattlePyramidFunction special HealPlayerParty warpsilent MAP_BATTLE_FRONTIER_BATTLE_PYRAMID_LOBBY, 255, 7, 13 waitstate @@ -98,14 +98,14 @@ BattleFrontier_BattlePyramidTop_EventScript_252B66:: @ 8252B66 BattleFrontier_BattlePyramidEmptySquare_EventScript_252B8D:: @ 8252B8D setvar VAR_0x8004, 3 setvar VAR_0x8005, 1 - special sub_81A8E7C + special CallBattlePyramidFunction special SavePlayerParty setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 special CallFrontierUtilFunc setvar VAR_0x8004, 9 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 3 setvar VAR_0x8005, 3 special CallFrontierUtilFunc @@ -121,7 +121,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252BD5:: @ 8252BD5 setvar VAR_0x8004, 13 setvar VAR_0x8005, 32 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction return BattleFrontier_BattlePyramidEmptySquare_EventScript_252BE8:: @ 8252BE8 @@ -137,7 +137,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252BE8:: @ 8252BE8 compare VAR_RESULT, 7 goto_eq BattleFrontier_BattlePyramidEmptySquare_EventScript_252C45 setvar VAR_0x8004, 6 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 @@ -155,7 +155,7 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252C45:: @ 8252C45 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F:: @ 8252C4F trainerbattle 9, TRAINER_PHILLIP, 0, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D setvar VAR_0x8004, 10 - special sub_81A8E7C + special CallBattlePyramidFunction waitmessage waitbuttonpress closemessage @@ -164,12 +164,12 @@ BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F:: @ 8252C4F BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A:: @ 8252C6A setvar VAR_0x8004, 7 - special sub_81A8E7C + special CallBattlePyramidFunction callstd 1 compare VAR_0x8007, 0 goto_eq BattleFrontier_BattlePyramidEmptySquare_EventScript_252C87 setvar VAR_0x8004, 8 - special sub_81A8E7C + special CallBattlePyramidFunction BattleFrontier_BattlePyramidEmptySquare_EventScript_252C87:: @ 8252C87 end diff --git a/data/maps/BattleFrontier_BattlePyramidLobby/scripts.inc b/data/maps/BattleFrontier_BattlePyramidLobby/scripts.inc index 4ae7b8e55..bcd2e32c9 100644 --- a/data/maps/BattleFrontier_BattlePyramidLobby/scripts.inc +++ b/data/maps/BattleFrontier_BattlePyramidLobby/scripts.inc @@ -35,11 +35,11 @@ BattleFrontier_BattlePyramidLobby_EventScript_250768:: @ 8250768 setvar VAR_0x8004, 2 setvar VAR_0x8005, 1 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 2 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 @@ -69,7 +69,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_2507DA:: @ 82507DA special CallFrontierUtilFunc special LoadPlayerParty setvar VAR_0x8004, 14 - special sub_81A8E7C + special CallBattlePyramidFunction special HealPlayerParty message BattleFrontier_BattlePyramidLobby_Text_2519F8 waitmessage @@ -82,10 +82,10 @@ BattleFrontier_BattlePyramidLobby_EventScript_2507DA:: @ 82507DA message BattleFrontier_BattlePyramidLobby_Text_251A77 waitmessage setvar VAR_0x8004, 4 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 3 setvar VAR_0x8005, 0 - special sub_81A8E7C + special CallBattlePyramidFunction playse SE_SAVE waitse msgbox BattleFrontier_BattlePyramidLobby_Text_251BB6, 4 @@ -99,7 +99,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250852:: @ 8250852 special CallFrontierUtilFunc special LoadPlayerParty setvar VAR_0x8004, 14 - special sub_81A8E7C + special CallBattlePyramidFunction special HealPlayerParty lockall message BattleFrontier_BattlePyramidLobby_Text_251B5A @@ -111,10 +111,10 @@ BattleFrontier_BattlePyramidLobby_EventScript_250852:: @ 8250852 setvar VAR_0x8004, 2 setvar VAR_0x8005, 2 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 3 setvar VAR_0x8005, 0 - special sub_81A8E7C + special CallBattlePyramidFunction playse SE_SAVE waitse msgbox BattleFrontier_BattlePyramidLobby_Text_251BB6, 4 @@ -180,11 +180,11 @@ BattleFrontier_BattlePyramidLobby_EventScript_2509A5:: @ 82509A5 setvar VAR_0x8005, 4 special CallFrontierUtilFunc setvar VAR_0x8004, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 2 setvar VAR_0x8006, 1 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 1 @@ -194,9 +194,9 @@ BattleFrontier_BattlePyramidLobby_EventScript_2509A5:: @ 82509A5 setvar VAR_0x8006, 0 special CallFrontierUtilFunc setvar VAR_0x8004, 6 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 9 - special sub_81A8E7C + special CallBattlePyramidFunction special LoadPlayerParty closemessage delay 2 @@ -284,7 +284,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250B28:: @ 8250B28 msgbox BattleFrontier_BattlePyramidLobby_Text_251C8A, 4 setvar VAR_0x8004, 1 setvar VAR_0x8005, 5 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 0 goto_if 5, BattleFrontier_BattlePyramidLobby_EventScript_250B53 setvar VAR_RESULT, 0 @@ -294,7 +294,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250B28:: @ 8250B28 BattleFrontier_BattlePyramidLobby_EventScript_250B53:: @ 8250B53 setvar VAR_0x8004, 1 setvar VAR_0x8005, 3 - special sub_81A8E7C + special CallBattlePyramidFunction goto BattleFrontier_BattlePyramidLobby_EventScript_250BA4 return @@ -302,7 +302,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250B66:: @ 8250B66 msgbox BattleFrontier_BattlePyramidLobby_Text_251C8A, 4 setvar VAR_0x8004, 1 setvar VAR_0x8005, 6 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 0 goto_if 5, BattleFrontier_BattlePyramidLobby_EventScript_250B91 setvar VAR_RESULT, 0 @@ -312,7 +312,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250B66:: @ 8250B66 BattleFrontier_BattlePyramidLobby_EventScript_250B91:: @ 8250B91 setvar VAR_0x8004, 1 setvar VAR_0x8005, 4 - special sub_81A8E7C + special CallBattlePyramidFunction goto BattleFrontier_BattlePyramidLobby_EventScript_250BA4 return @@ -439,7 +439,7 @@ BattleFrontier_BattlePyramidLobby_EventScript_250D56:: @ 8250D56 msgbox BattleFrontier_BattlePyramidLobby_Text_251569, 4 setvar VAR_0x8004, 1 setvar VAR_0x8005, 1 - special sub_81A8E7C + special CallBattlePyramidFunction compare VAR_RESULT, 0 goto_eq BattleFrontier_BattlePyramidLobby_EventScript_250D94 msgbox BattleFrontier_BattlePyramidLobby_Text_2515AD, 4 diff --git a/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc b/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc index 46ecef737..e77013519 100644 --- a/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc +++ b/data/maps/BattleFrontier_BattlePyramidTop/scripts.inc @@ -9,7 +9,7 @@ BattleFrontier_BattlePyramidTop_MapScript1_2550B6: @ 82550B6 setvar VAR_0x8004, 13 setvar VAR_0x8005, 200 setvar VAR_0x8006, 0 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_TEMP_F, 1 end @@ -71,14 +71,14 @@ BattleFrontier_BattlePyramidTop_EventScript_25518A:: @ 825518A BattleFrontier_BattlePyramidTop_EventScript_255193:: @ 8255193 setvar VAR_0x8004, 3 setvar VAR_0x8005, 1 - special sub_81A8E7C + special CallBattlePyramidFunction special SavePlayerParty setvar VAR_0x8004, 2 setvar VAR_0x8005, 0 setvar VAR_0x8006, 0 special CallFrontierUtilFunc setvar VAR_0x8004, 9 - special sub_81A8E7C + special CallBattlePyramidFunction setvar VAR_0x8004, 3 setvar VAR_0x8005, 3 special CallFrontierUtilFunc diff --git a/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc index de179850d..f16b7e6a0 100644 --- a/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc @@ -7,7 +7,7 @@ BattleFrontier_BattleTowerMultiBattleRoom_MapScripts:: @ 8243D92 BattleFrontier_BattleTowerMultiBattleRoom_MapScript1_243DA7: @ 8243DA7 setvar VAR_0x8004, 17 - special sub_81A8E7C + special CallBattlePyramidFunction end BattleFrontier_BattleTowerMultiBattleRoom_MapScript1_243DB0: @ 8243DB0 diff --git a/data/specials.inc b/data/specials.inc index 5b2459805..75f180420 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -251,7 +251,7 @@ gSpecials:: @ 81DBA64 def_special CallBattleArenaFunction def_special CallBattleFactoryFunction def_special CallBattlePikeFunction - def_special sub_81A8E7C + def_special CallBattlePyramidFunction def_special StopMapMusic def_special sub_81B99B4 def_special sub_81B9B80 diff --git a/include/battle_pyramid.h b/include/battle_pyramid.h new file mode 100644 index 000000000..5d38e9f35 --- /dev/null +++ b/include/battle_pyramid.h @@ -0,0 +1,24 @@ +#ifndef GUARD_BATTLE_PYRAMID_H +#define GUARD_BATTLE_PYRAMID_H + +void CallBattlePyramidFunction(void); +u16 LocalIdToPyramidTrainerId(u8 localId); +bool8 GetBattlePyramidTrainerFlag(u8 eventId); +void sub_81A9B04(void); +void GenerateBattlePyramidWildMon(void); +u8 GetPyramidRunMultiplier(void); +u8 InBattlePyramid(void); +bool8 InBattlePyramid_(void); +void sub_81A9E90(void); +void sub_81A9EC8(void); +void CopyPyramidTrainerSpeechBefore(u16 trainerId); +void CopyPyramidTrainerWinSpeech(u16 trainerId); +void CopyPyramidTrainerLoseSpeech(u16 trainerId); +u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId); +void sub_81AA078(u16 *mapArg, u8 arg1); +void sub_81AA1D8(void); +void sub_81AA2F8(void); +u8 sub_81AAA40(void); +u16 GetBattlePyramidPickupItemId(void); + +#endif // GUARD_BATTLE_PYRAMID_H diff --git a/include/global.h b/include/global.h index 25e8c7faa..3da68185f 100644 --- a/include/global.h +++ b/include/global.h @@ -135,6 +135,7 @@ enum LanguageId #define BAG_POKEBALLS_COUNT 16 #define BAG_TMHM_COUNT 64 #define BAG_BERRIES_COUNT 46 +#define EVENT_OBJECT_TEMPLATES_COUNT 64 #define PYRAMID_BAG_ITEMS_COUNT 10 #define HALL_FACILITIES_COUNT 9 // 7 facilities for single mode + tower double mode + tower multi mode. @@ -907,7 +908,7 @@ struct SaveBlock1 /*0x9C8*/ u16 trainerRematchStepCounter; /*0x9CA*/ u8 trainerRematches[100]; /*0xA30*/ struct EventObject eventObjects[EVENT_OBJECTS_COUNT]; - /*0xC70*/ struct EventObjectTemplate eventObjectTemplates[64]; + /*0xC70*/ struct EventObjectTemplate eventObjectTemplates[EVENT_OBJECT_TEMPLATES_COUNT]; /*0x1270*/ u8 flags[FLAGS_COUNT]; /*0x139C*/ u16 vars[VARS_COUNT]; /*0x159C*/ u32 gameStats[NUM_GAME_STATS]; diff --git a/ld_script.txt b/ld_script.txt index 9de96ebcc..21fff394d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -270,7 +270,6 @@ SECTIONS { src/battle_pike.o(.text); asm/battle_frontier_2.o(.text); src/battle_pyramid.o(.text); - asm/battle_pyramid.o(.text); src/item_menu.o(.text); src/list_menu.o(.text); src/dynamic_placeholder_text_util.o(.text); @@ -581,6 +580,7 @@ SECTIONS { data/battle_pike.o(.rodata); src/battle_pike.o(.rodata); data/battle_frontier_3.o(.rodata); + src/battle_pyramid.o(.rodata); src/item_menu.o(.rodata); src/list_menu.o(.rodata); src/save_location.o(.rodata); diff --git a/src/battle_main.c b/src/battle_main.c index f6c01aee2..dee2adf0b 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5,6 +5,7 @@ #include "battle_controllers.h" #include "battle_interface.h" #include "battle_message.h" +#include "battle_pyramid.h" #include "battle_scripts.h" #include "battle_setup.h" #include "battle_tower.h" @@ -109,10 +110,8 @@ extern const u8 gText_Love[]; // functions extern void sub_81B9150(void); extern void sub_80B3AF8(u8 taskId); // cable club -extern u8 sub_81A9E28(void); // battle frontier 2 extern void sub_81B8FB0(u8, u8); // party menu extern u8 pokemon_order_func(u8); // party menu -extern bool8 InBattlePyramid(void); // this file's functions static void CB2_InitBattleInternal(void); @@ -5604,7 +5603,7 @@ bool8 TryRunFromBattle(u8 battler) if (InBattlePyramid()) { gBattleStruct->runTries++; - pyramidMultiplier = sub_81A9E28(); + pyramidMultiplier = GetPyramidRunMultiplier(); speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); if (speedVar > (Random() & 0xFF)) { @@ -5630,7 +5629,7 @@ bool8 TryRunFromBattle(u8 battler) { if (InBattlePyramid()) { - pyramidMultiplier = sub_81A9E28(); + pyramidMultiplier = GetPyramidRunMultiplier(); speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); if (speedVar > (Random() & 0xFF)) effect++; diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 1ef59a438..34dd353d0 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -1,4 +1,5 @@ #include "global.h" +#include "battle_pyramid.h" #include "battle_pyramid_bag.h" #include "event_data.h" #include "battle.h" @@ -19,9 +20,12 @@ #include "load_save.h" #include "script.h" #include "malloc.h" +#include "overworld.h" #include "constants/battle_frontier.h" #include "constants/event_objects.h" #include "constants/event_object_movement_constants.h" +#include "constants/items.h" +#include "constants/maps.h" #include "constants/moves.h" extern u8 gUnknown_0203CEF8[3]; @@ -30,6 +34,7 @@ extern void door_upload_tiles(void); extern const struct MapLayout *const gMapLayouts[]; #define TOTAL_ROUNDS 20 +#define PICKUP_ITEMS_PER_ROUND 10 struct Struct_08613650 { @@ -38,47 +43,134 @@ struct Struct_08613650 u8 unk2; u8 unk3; u8 unk4; - u8 unk5; - u8 unk6[10]; + u8 unk5[11]; +}; + +struct PyramidWildMon +{ + u16 species; + u8 lvl; + u8 abilityBit; + u16 moves[4]; +}; + +struct ClassMusic +{ + u8 class; + u8 music; }; extern const u16 gBattleFrontierHeldItems[]; extern const struct FacilityMon gBattleFrontierMons[]; extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88[]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F[]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A[]; + // This file's functions. -void sub_81AAA7C(u8 lvlMode); -u8 sub_81AA9E4(void); -u16 sub_81A9AA8(u8); -u8 sub_81A9998(s32 *, u8, u8); -u8 sub_81AAA40(void); -u8 InBattlePyramid(void); -void sub_81A97DC(u8 taskId); -void sub_81A9B44(u16 trainerId); -void sub_81AA96C(u8 *); -void sub_81AA33C(u8 *, u8 *); +static void sub_81A8E9C(void); +static void sub_81A8F38(void); +static void sub_81A9048(void); +static void sub_81A9134(void); +static void sub_81A917C(void); +static void sub_81A91FC(void); +static void sub_81A9254(void); +static void sub_81A9290(void); +static void sub_81A93C8(void); +static void sub_81A9414(void); +static void sub_81A9424(void); +static void sub_81A9618(void); +static void sub_81A966C(void); +static void sub_81A9684(void); +static void sub_81A975C(void); +static void sub_81A97C8(void); +static void sub_81A9828(void); +static void sub_81A9834(void); +static void InitBagItems(u8 lvlMode); +static u8 sub_81AA9E4(void); +static u8 sub_81A9998(s32 *, u8, u8); +static void sub_81A97DC(u8 taskId); +static void sub_81A9B44(u16 trainerId); +static void sub_81AA96C(u8 *mapNums); +static void sub_81AA33C(u8 *, u8 *); +static void sub_81AA398(u8); +static bool8 sub_81AA4D8(u8, u8); +static bool8 sub_81AA648(u8, u8); +static bool8 sub_81AA760(u8 arg0, u8 *mapNums, u8 whichMap, u8 id); +static bool8 sub_81AA810(u8 arg0, u8 x, u8 y, u8 *mapNums, u8 whichMap, u8 id); // Const rom data. -extern void (* const gUnknown_08613EE0[])(void); extern const struct Struct_08613650 gUnknown_08613650[]; -extern const u16 sPickupItemsLvl50[TOTAL_ROUNDS][10]; -extern const u16 sPickupItemsLvlOpen[TOTAL_ROUNDS][10]; +extern const u16 sPickupItemsLvl50[TOTAL_ROUNDS][PICKUP_ITEMS_PER_ROUND]; +extern const u16 sPickupItemsLvlOpen[TOTAL_ROUNDS][PICKUP_ITEMS_PER_ROUND]; extern const u8 gUnknown_08613ABC[63][2]; extern const u8 gUnknown_08613B3A[]; -extern const u16 gUnknown_08613F34[9]; -extern const u16 gUnknown_08613F28[6]; extern const u16 gUnknown_08D856C8[][16]; extern const u8 gUnknown_08613C1C[50][2]; -extern const u8 gUnknown_08613ED8[]; extern const u8 *const *const *const gUnknown_08613EC0[]; +extern const struct ClassMusic gUnknown_08613B44[54]; +extern const struct PyramidWildMon *const gBattlePyramidOpenLevelWildMonPointers[]; +extern const struct PyramidWildMon *const gBattlePyramidLevel50WildMonPointers[]; +extern const u8 gUnknown_08613794[]; +extern const u8 gUnknown_08613750[34][2]; + +static const u8 gUnknown_08613ED8[] = {3, 4, 5, 6, 7, 8, 3, 4}; + +static void (* const sBattlePyramidFunctions[])(void) = +{ + sub_81A8E9C, + sub_81A8F38, + sub_81A9048, + sub_81A9134, + sub_81A917C, + sub_81A91FC, + sub_81A9254, + sub_81A9290, + sub_81A93C8, + sub_81A9414, + sub_81A9424, + sub_81A9618, + sub_81A966C, + sub_81A9684, + sub_81A975C, + sub_81A97C8, + sub_81A9828, + sub_81A9834, +}; + +static const u16 gUnknown_08613F28[] = {ITEM_HP_UP, ITEM_PROTEIN, ITEM_IRON, ITEM_CALCIUM, ITEM_CARBOS, ITEM_ZINC}; +static const u16 gUnknown_08613F34[] = {ITEM_BRIGHT_POWDER, ITEM_WHITE_HERB, ITEM_QUICK_CLAW, ITEM_LEFTOVERS, ITEM_MENTAL_HERB, ITEM_KINGS_ROCK, ITEM_FOCUS_BAND, ITEM_SCOPE_LENS, ITEM_CHOICE_BAND}; + +static const u8 gUnknown_08613F46[][4] = +{ + {0x01, 0x04, 0xff, 0xff}, + {0x00, 0x02, 0x05, 0xff}, + {0x01, 0x03, 0x06, 0xff}, + {0x02, 0x07, 0xff, 0xff}, + {0x00, 0x05, 0x08, 0xff}, + {0x01, 0x04, 0x06, 0x09}, + {0x02, 0x05, 0x07, 0x0a}, + {0x03, 0x06, 0x0b, 0xff}, + {0x04, 0x09, 0x0c, 0xff}, + {0x05, 0x08, 0x0a, 0x0d}, + {0x06, 0x09, 0x0b, 0x0e}, + {0x07, 0x0a, 0x0f, 0xff}, + {0x08, 0x0d, 0xff, 0xff}, + {0x09, 0x0c, 0x0e, 0xff}, + {0x0a, 0x0d, 0x0f, 0xff}, + {0x0b, 0x0e, 0xff, 0xff}, +}; + +static const u8 sPickupPercentages[PICKUP_ITEMS_PER_ROUND] = {30, 40, 50, 60, 70, 80, 85, 90, 95, 100}; // code -void sub_81A8E7C(void) +void CallBattlePyramidFunction(void) { - gUnknown_08613EE0[gSpecialVar_0x8004](); + sBattlePyramidFunctions[gSpecialVar_0x8004](); } -void sub_81A8E9C(void) +static void sub_81A8E9C(void) { bool32 isCurrent; u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -94,7 +186,7 @@ void sub_81A8E9C(void) if (!isCurrent) { gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] = 0; - sub_81AAA7C(lvlMode); + InitBagItems(lvlMode); } sub_81C4EEC(); @@ -102,7 +194,7 @@ void sub_81A8E9C(void) gBattleOutcome = 0; } -void sub_81A8F38(void) +static void sub_81A8F38(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -135,7 +227,7 @@ void sub_81A8F38(void) } } -void sub_81A9048(void) +static void sub_81A9048(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -169,7 +261,7 @@ void sub_81A9048(void) } } -void sub_81A9134(void) +static void sub_81A9134(void) { gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8005; VarSet(VAR_TEMP_0, 0); @@ -178,7 +270,7 @@ void sub_81A9134(void) TrySavingData(SAVE_LINK); } -void sub_81A917C(void) +static void sub_81A917C(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -188,7 +280,7 @@ void sub_81A917C(void) gSaveBlock2Ptr->frontier.field_E18 = gUnknown_08613F28[Random() % ARRAY_COUNT(gUnknown_08613F28)]; } -void sub_81A91FC(void) +static void sub_81A91FC(void) { if (AddBagItem(gSaveBlock2Ptr->frontier.field_E18, 1) == TRUE) { @@ -202,7 +294,7 @@ void sub_81A91FC(void) } } -void sub_81A9254(void) +static void sub_81A9254(void) { s32 i; @@ -212,7 +304,7 @@ void sub_81A9254(void) gSaveBlock2Ptr->frontier.field_E2A = 0; } -void sub_81A9290(void) +static void sub_81A9290(void) { s32 i; s32 r7; @@ -247,7 +339,7 @@ void sub_81A9290(void) gSpecialVar_0x8001 = 1; } -void sub_81A93C8(void) +static void sub_81A93C8(void) { struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; s32 i = 0; @@ -266,12 +358,12 @@ void sub_81A93C8(void) } } -void sub_81A9414(void) +static void sub_81A9414(void) { gFacilityTrainers = gBattleFrontierTrainers; } -void sub_81A9424(void) +static void sub_81A9424(void) { s32 i; s32 var_24; @@ -279,7 +371,7 @@ void sub_81A9424(void) s32 class = 0; s32 r7 = 0; struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; - u16 trainerId = sub_81A9AA8(gEventObjects[gSelectedEventObject].localId); + u16 trainerId = LocalIdToPyramidTrainerId(gEventObjects[gSelectedEventObject].localId); for (i = 0; i < ARRAY_COUNT(gUnknown_08613C1C); i++) { @@ -341,7 +433,7 @@ void sub_81A9424(void) ShowFieldMessage(gUnknown_08613EC0[class][var_24][r7]); } -void sub_81A9618(void) +static void sub_81A9618(void) { u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -351,12 +443,12 @@ void sub_81A9618(void) gSaveBlock2Ptr->frontier.pyramidRecordStreaks[lvlMode] = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode]; } -void sub_81A966C(void) +static void sub_81A966C(void) { gSpecialVar_Result = InBattlePyramid(); } -void sub_81A9684(void) +static void sub_81A9684(void) { switch (gSpecialVar_0x8006) { @@ -401,7 +493,7 @@ void sub_81A9684(void) } } -void sub_81A975C(void) +static void sub_81A975C(void) { s32 i, j; u16 item = 0; @@ -416,12 +508,12 @@ void sub_81A975C(void) } } -void sub_81A97C8(void) +static void sub_81A97C8(void) { CreateTask(sub_81A97DC, 0); } -void sub_81A97DC(u8 taskId) +static void sub_81A97DC(u8 taskId) { if (gPaletteFade.active) { @@ -430,12 +522,12 @@ void sub_81A97DC(u8 taskId) } } -void sub_81A9828(void) +static void sub_81A9828(void) { sub_809FDD4(); } -void sub_81A9834(void) +static void sub_81A9834(void) { s32 i, j, k, l; @@ -467,7 +559,7 @@ void sub_81A9834(void) gSaveBlock2Ptr->frontier.selectedPartyMons[i] = gUnknown_0203CEF8[i]; } -u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) +static u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) { s32 i, j; u8 ret = 0; @@ -537,9 +629,9 @@ u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) return ret; } -u16 sub_81A9AA8(u8 arg0) +u16 LocalIdToPyramidTrainerId(u8 localId) { - return gSaveBlock2Ptr->frontier.field_CB4[arg0 - 1]; + return gSaveBlock2Ptr->frontier.field_CB4[localId - 1]; } bool8 GetBattlePyramidTrainerFlag(u8 eventId) @@ -557,18 +649,7 @@ void sub_81A9B04(void) } } -struct PyramidWildMon -{ - u16 species; - u8 lvl; - u8 abilityBit; - u16 moves[4]; -}; - -extern const struct PyramidWildMon *const gBattlePyramidOpenLevelWildMonPointers[]; -extern const struct PyramidWildMon *const gBattlePyramidLevel50WildMonPointers[]; - -void sub_81A9B44(u16 trainerId) +static void sub_81A9B44(u16 trainerId) { s32 i; @@ -652,7 +733,7 @@ void GenerateBattlePyramidWildMon(void) CalculateMonStats(&gEnemyParty[0]); } -u8 sub_81A9E28(void) +u8 GetPyramidRunMultiplier(void) { u8 id = sub_81AA9E4(); return gUnknown_08613650[id].unk4; @@ -690,30 +771,21 @@ void sub_81A9EC8(void) DoSoftReset(); } -void sub_81A9EDC(u16 trainerId) +void CopyPyramidTrainerSpeechBefore(u16 trainerId) { FrontierSpeechToString(gFacilityTrainers[trainerId].speechBefore); } -void sub_81A9EFC(u16 trainerId) +void CopyPyramidTrainerWinSpeech(u16 trainerId) { FrontierSpeechToString(gFacilityTrainers[trainerId].speechWin); } -void sub_81A9F1C(u16 trainerId) +void CopyPyramidTrainerLoseSpeech(u16 trainerId) { FrontierSpeechToString(gFacilityTrainers[trainerId].speechLose); } -struct ClassMusic -{ - u8 class; - u8 music; -}; - -extern const struct ClassMusic gUnknown_08613B44[54]; -extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88[]; - u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId) { s32 i; @@ -726,12 +798,12 @@ u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId) return 0; } -void sub_81A9F80(void) +static void sub_81A9F80(void) { ScriptContext1_SetupScript(BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88); } -u16 sub_81A9F90(u8 count) +static u16 sub_81A9F90(u8 count) { s32 i; u16 trainerId; @@ -818,3 +890,408 @@ void sub_81AA078(u16 *mapArg, u8 arg1) mapheader_run_script_with_tag_x1(); free(allocated); } + +void sub_81AA1D8(void) +{ + s32 i; + u8 id; + u8 var0, var1; + + for (i = 0; i < 8; i++) + gSaveBlock2Ptr->frontier.field_CB4[i] |= 0xFFFF; + + id = sub_81AA9E4(); + sub_81AA33C(&var0, &var1); + CpuFill32(0, gSaveBlock1Ptr->eventObjectTemplates, sizeof(gSaveBlock1Ptr->eventObjectTemplates)); + for (i = 0; i < 2; i++) + { + u8 value; + + if (i == 0) + value = gUnknown_08613650[id].unk3; + else + value = gUnknown_08613650[id].unk2; + + switch (value) + { + case 0: + sub_81AA398(i); + break; + case 1: + if (sub_81AA4D8(i, var0)) + sub_81AA398(i); + break; + case 2: + if (sub_81AA4D8(i, var1)) + sub_81AA398(i); + break; + case 3: + if (sub_81AA648(i, var0)) + sub_81AA398(i); + break; + case 4: + if (sub_81AA648(i, var1)) + sub_81AA398(i); + break; + } + } +} + +void sub_81AA2F8(void) +{ + s32 i; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++) + { + if (events[i].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + events[i].script = BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F; + else + events[i].script = BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A; + } +} + +static void sub_81AA33C(u8 *var0, u8 *var1) +{ + *var0 = gSaveBlock2Ptr->frontier.field_E22[3] % 16; + *var1 = gSaveBlock2Ptr->frontier.field_E22[0] % 16; + + if (*var0 == *var1) + { + *var0 = (gSaveBlock2Ptr->frontier.field_E22[3] + 1 ) % 16; + *var1 = (gSaveBlock2Ptr->frontier.field_E22[0] + 15) % 16; + } +} + +static void sub_81AA398(u8 arg0) +{ + s32 i; + s32 count; + s32 var_28; + s32 r4; + u32 bits = 0; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + r4 = gSaveBlock2Ptr->frontier.field_E22[2] % 16; + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + do + { + do + { + if (bits & 1) + { + if (!(gBitTable[r4] & gSaveBlock2Ptr->frontier.field_E22[3])) + bits |= 2; + } + else + { + if (gBitTable[r4] & gSaveBlock2Ptr->frontier.field_E22[3]) + bits |= 2; + } + if (++r4 >= 16) + r4 = 0; + + if (r4 == gSaveBlock2Ptr->frontier.field_E22[2] % 16) + { + if (bits & 1) + bits |= 6; + else + bits |= 1; + } + } while (!(bits & 2)); + + } while (!(bits & 4) && sub_81AA760(arg0, allocated, r4, var_28 + i)); + bits &= 1; + } + free(allocated); +} + +static bool8 sub_81AA4D8(u8 arg0, u8 arg1) +{ + s32 i; + s32 var_28; + s32 r6 = 0; + s32 r7 = 0; + s32 var_34 = 0; + s32 count; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + if (r7 == 0) + { + if (sub_81AA760(arg0, allocated, arg1, var_28 + i)) + r7 = 1; + else + var_34++; + } + if (r7 & 1) + { + if (sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r6], var_28 + i)) + { + do + { + r6++; + if (gUnknown_08613F46[arg1][r6] == 0xFF || r6 >= 4) + r6 = 0; + r7 += 2; + } while (r7 >> 1 != 4 && sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r6], var_28 + i)); + var_34++; + } + else + { + r6++; + if (gUnknown_08613F46[arg1][r6] == 0xFF || r6 >= 4) + r6 = 0; + var_34++; + } + } + + if (r7 >> 1 == 4) + break; + + r7 &= 1; + } + // free(allocated); BUG: allocated memory not freed + + return (count / 2 > var_34); +} + +static bool8 sub_81AA648(u8 arg0, u8 arg1) +{ + s32 i; + s32 var_28; + s32 r4 = 0; + s32 r7 = 0; + s32 r8 = 0; + s32 count; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + if (sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r4], var_28 + i)) + { + do + { + r4++; + if (gUnknown_08613F46[arg1][r4] == 0xFF || r4 >= 4) + r4 = 0; + r8++; + } while (r8 != 4 && sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r4], var_28 + i)); + r7++; + } + else + { + r4++; + if (gUnknown_08613F46[arg1][r4] == 0xFF || r4 >= 4) + r4 = 0; + r7++; + } + + if (r8 == 4) + break; + } + // free(allocated); BUG: allocated memory not freed + + return (count / 2 > r7); +} + +static bool8 sub_81AA760(u8 arg0, u8 *mapNums, u8 whichMap, u8 id) +{ + s32 i, j; + + if (gSaveBlock2Ptr->frontier.field_E22[0] & 1) + { + s32 minus1 = -1; + for (i = 7; i > minus1; i--) + { + for (j = 7; j >= 0; j--) + { + if (!sub_81AA810(arg0, j, i, mapNums, whichMap, id)) + return FALSE; + } + } + } + else + { + for (i = 0; i < 8; i++) + { + for (j = 0; j < 8; j++) + { + if (!sub_81AA810(arg0, j, i, mapNums, whichMap, id)) + return FALSE; + } + } + } + + return TRUE; +} + +static bool8 sub_81AA810(u8 arg0, u8 x, u8 y, u8 *mapNums, u8 whichMap, u8 id) +{ + s32 i, j; + const struct MapHeader *mapHeader; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + mapHeader = Overworld_GetMapHeaderByGroupAndId(MAP_GROUP(BATTLE_PYRAMID_SQUARE01), mapNums[whichMap] + MAP_NUM(BATTLE_PYRAMID_SQUARE01)); + for (i = 0; i < mapHeader->events->eventObjectCount; i++) + { + if (mapHeader->events->eventObjects[i].x != x || mapHeader->events->eventObjects[i].y != y) + continue; + + if (arg0 != 0 || mapHeader->events->eventObjects[i].graphicsId == EVENT_OBJ_GFX_ITEM_BALL) + { + if (arg0 != 1 || mapHeader->events->eventObjects[i].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + continue; + } + + for (j = 0; j < id; j++) + { + if (events[j].x == x + ((whichMap % 4) * 8) && events[j].y == y + ((whichMap / 4) * 8)) + break; + } + if (j != id) + continue; + + events[id] = mapHeader->events->eventObjects[i]; + events[id].x += ((whichMap % 4) * 8); + events[id].y += ((whichMap / 4) * 8); + events[id].localId = id + 1; + if (events[id].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + { + i = sub_81A9F90(id); + events[id].graphicsId = GetBattleFacilityTrainerGfxId(i); + gSaveBlock2Ptr->frontier.field_CB4[id] = i; + } + return FALSE; + } + + return TRUE; +} + +static void sub_81AA96C(u8 *mapNums) +{ + s32 i; + s32 bits = (gSaveBlock2Ptr->frontier.field_E22[0]) | (gSaveBlock2Ptr->frontier.field_E22[1] << 16); + u8 id = sub_81AA9E4(); + + for (i = 0; i < 16; i++) + { + mapNums[i] = gUnknown_08613650[id].unk5[bits & 7]; + bits >>= 3; + if (i == 7) + { + bits = (gSaveBlock2Ptr->frontier.field_E22[2]) | (gSaveBlock2Ptr->frontier.field_E22[3] << 16); + bits >>= 8; + } + } +} + +static u8 sub_81AA9E4(void) +{ + s32 i; + s32 var = gSaveBlock2Ptr->frontier.field_E22[3] % 100; + s32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + + for (i = gUnknown_08613794[battleNum]; i < ARRAY_COUNT(gUnknown_08613750); i++) + { + if (var < gUnknown_08613750[i][0]) + return gUnknown_08613750[i][1]; + } + return 0; +} + +u8 sub_81AAA40(void) +{ + u8 i; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + for (i = 0; i < 16; i++) + { + if (events[i].localId == 0) + break; + } + + return i; +} + +static void InitBagItems(u8 lvlMode) +{ + s32 i; + + for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) + { + gSaveBlock2Ptr->frontier.pyramidBag.itemId[lvlMode][i] = 0; + gSaveBlock2Ptr->frontier.pyramidBag.quantity[lvlMode][i] = 0; + } + + AddPyramidBagItem(ITEM_HYPER_POTION, 1); + AddPyramidBagItem(ITEM_ETHER, 1); +} + +u16 GetBattlePyramidPickupItemId(void) +{ + s32 rand; + u32 i; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + s32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7); + + if (round >= TOTAL_ROUNDS) + round = TOTAL_ROUNDS - 1; + + rand = Random() % 100; + + for (i = 0; i < ARRAY_COUNT(sPickupPercentages); i++) + { + if (sPickupPercentages[i] > rand) + break; + } + + if (i >= PICKUP_ITEMS_PER_ROUND) + i = PICKUP_ITEMS_PER_ROUND - 1; + + if (lvlMode != FRONTIER_LVL_50) + return sPickupItemsLvlOpen[round][i]; + else + return sPickupItemsLvl50[round][i]; +} diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 920e1045b..ae397159a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -45,6 +45,7 @@ #include "party_menu.h" #include "battle_arena.h" #include "battle_pike.h" +#include "battle_pyramid.h" extern u16 gBattle_BG1_X; extern u16 gBattle_BG1_Y; @@ -62,11 +63,8 @@ extern void sub_81D388C(struct Pokemon* mon, void* statStoreLocation); // pokena extern void sub_81D3640(u8 arg0, void* statStoreLocation1, void* statStoreLocation2, u8 arg3, u8 arg4, u8 arg5); // pokenav.s extern void sub_81D3784(u8 arg0, void* statStoreLocation1, u8 arg2, u8 arg3, u8 arg4); // pokenav.s extern u8* GetMonNickname(struct Pokemon* mon, u8* dst); // party_menu -extern u8 BattleArena_ShowJudgmentWindow(u8* arg0); // battle frontier 2 extern void sub_81B8E80(u8 battlerId, u8, u8); // party menu extern bool8 sub_81B1250(void); // ? -extern bool8 InBattlePyramid(void); -extern u16 GetBattlePyramidPickupItemId(void); extern u8 sub_813B21C(void); extern u16 get_unknown_box_id(void); diff --git a/src/battle_setup.c b/src/battle_setup.c index 18998e564..ab2a12fb7 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -34,6 +34,7 @@ #include "battle_tower.h" #include "gym_leader_rematch.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "constants/map_types.h" #include "constants/battle_frontier.h" @@ -54,7 +55,6 @@ struct TrainerBattleParameter u8 ptrType; }; -extern bool8 InBattlePyramid(void); extern bool32 InTrainerHill(void); extern bool32 FieldPoisonEffectIsRunning(void); extern void RestartWildEncounterImmunitySteps(void); @@ -63,17 +63,13 @@ extern void sub_81BE72C(void); extern void sub_808BCF4(void); extern void sub_80EECC8(void); extern void sub_80AF6F0(void); -extern u16 sub_81A9AA8(u8 localId); extern u16 sub_81D6180(u8 localId); -extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjId); extern bool8 GetTrainerHillTrainerFlag(u8 eventObjId); extern bool8 sub_81D5C18(void); -extern void sub_81A9B04(void); extern void sub_81D639C(void); extern void sub_81D6384(void); extern void sub_81D61E8(void); extern void sub_80982B8(void); -extern void sub_81A9EDC(u16 a0); extern void CopyTrainerHillTrainerText(u8 a0, u16 arg1); // this file's functions @@ -1131,12 +1127,12 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) { TrainerBattleLoadArgs(sOrdinaryBattleParams, data); SetMapVarsToTrainer(); - gTrainerBattleOpponent_A = sub_81A9AA8(gSpecialVar_LastTalked); + gTrainerBattleOpponent_A = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); } else { TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); - gTrainerBattleOpponent_B = sub_81A9AA8(gSpecialVar_LastTalked); + gTrainerBattleOpponent_B = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); } return EventScript_271362; case TRAINER_BATTLE_SET_TRAINER_A: @@ -1360,9 +1356,9 @@ void ShowTrainerIntroSpeech(void) if (InBattlePyramid()) { if (gNoOfApproachingTrainers == 0 || gNoOfApproachingTrainers == 1) - sub_81A9EDC(sub_81A9AA8(gSpecialVar_LastTalked)); + CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gSpecialVar_LastTalked)); else - sub_81A9EDC(sub_81A9AA8(gEventObjects[gApproachingTrainers[gApproachingTrainerId].eventObjectId].localId)); + CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gEventObjects[gApproachingTrainers[gApproachingTrainerId].eventObjectId].localId)); sub_80982B8(); } diff --git a/src/item.c b/src/item.c index b4a2fd6f0..b2c009be6 100644 --- a/src/item.c +++ b/src/item.c @@ -10,9 +10,9 @@ #include "item_menu.h" #include "strings.h" #include "load_save.h" +#include "battle_pyramid.h" #include "battle_pyramid_bag.h" -extern bool8 InBattlePyramid(void); extern u16 gUnknown_0203CF30[]; extern const struct Item gItems[]; diff --git a/src/overworld.c b/src/overworld.c index 4e1f8cc4f..5c0a06f38 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1,5 +1,6 @@ #include "global.h" #include "overworld.h" +#include "battle_pyramid.h" #include "battle_setup.h" #include "berry.h" #include "bg.h" @@ -113,7 +114,6 @@ extern void ShowMapNamePopup(void); extern bool32 InTrainerHill(void); extern bool32 sub_808651C(void); extern bool8 sub_80AF6A4(void); -extern bool8 InBattlePyramid_(void); extern bool8 sub_80E909C(void); extern void sub_81AA1D8(void); extern void c2_change_map(void); diff --git a/src/pokemon.c b/src/pokemon.c index 47c4f9217..0f7c80b77 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4,6 +4,7 @@ #include "battle_controllers.h" #include "battle_message.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "battle_setup.h" #include "battle_tower.h" #include "event_data.h" @@ -81,9 +82,7 @@ extern u8 StorageGetCurrentBox(void); extern void set_unknown_box_id(u8); extern void sub_803FA70(u8 battlerId); extern u8 sav1_map_get_name(void); -extern bool8 InBattlePyramid(void); extern bool8 sub_806F104(void); -extern u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerOpponentId); extern u8 sub_81D63C8(u16 trainerOpponentId); extern void SummaryScreen_SetUnknownTaskId(u8); diff --git a/src/trainer_see.c b/src/trainer_see.c index 726d89847..b74608d0b 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -12,11 +12,10 @@ #include "task.h" #include "trainer_see.h" #include "util.h" +#include "battle_pyramid.h" #include "constants/field_effects.h" -extern bool8 InBattlePyramid(void); extern bool32 InTrainerHill(void); -extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjectId); extern bool8 GetTrainerHillTrainerFlag(u8 eventObjectId); extern void sub_809BE48(u16 npcId); diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 52dbdf65e..9b3c70ad7 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -19,6 +19,7 @@ #include "link.h" #include "script.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "constants/items.h" #include "constants/maps.h" @@ -26,9 +27,6 @@ extern const u8 EventScript_RepelWoreOff[]; #define NUM_FEEBAS_SPOTS 6 -extern void GenerateBattlePyramidWildMon(void); -extern bool8 InBattlePyramid(void); - // this file's functions static u16 FeebasRandom(void); static void FeebasSeedRng(u16 seed); From 4803a31b84431a1e631c544af3eca8fd098b4dce Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 18 Nov 2018 17:54:15 +0100 Subject: [PATCH 4/7] Fix unk5 field --- src/battle_pyramid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 34dd353d0..878ea4e70 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -42,8 +42,8 @@ struct Struct_08613650 u8 unk1; u8 unk2; u8 unk3; - u8 unk4; - u8 unk5[11]; + u8 runMultiplier; + u8 unk5[8]; }; struct PyramidWildMon @@ -736,7 +736,7 @@ void GenerateBattlePyramidWildMon(void) u8 GetPyramidRunMultiplier(void) { u8 id = sub_81AA9E4(); - return gUnknown_08613650[id].unk4; + return gUnknown_08613650[id].runMultiplier; } u8 InBattlePyramid(void) From 7ce3473b0e5858b98a2ac1c393dc46c54ecfdf22 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 18 Nov 2018 19:37:18 +0100 Subject: [PATCH 5/7] Clean up save related files --- include/decoration_inventory.h | 5 +- include/load_save.h | 1 - include/overworld.h | 2 +- include/save.h | 27 ++---- include/save_location.h | 1 - src/clear_save_data_screen.c | 146 ++++++++++++++++---------------- src/hall_of_fame.c | 2 +- src/load_save.c | 9 +- src/overworld.c | 2 +- src/recorded_battle.c | 2 +- src/save.c | 122 +++++++++++++-------------- src/save_failed_screen.c | 148 ++++++++++++++++----------------- src/save_location.c | 19 ++--- 13 files changed, 235 insertions(+), 251 deletions(-) diff --git a/include/decoration_inventory.h b/include/decoration_inventory.h index e1fec36ea..7539f7240 100644 --- a/include/decoration_inventory.h +++ b/include/decoration_inventory.h @@ -1,12 +1,15 @@ #ifndef GUARD_DECORATION_INVENTORY_H #define GUARD_DECORATION_INVENTORY_H -struct DecorationInventory { + +struct DecorationInventory +{ u8 *items; u8 size; }; extern struct DecorationInventory gDecorationInventories[]; +void SetDecorationInventoriesPointers(void); void ClearDecorationInventories(void); s8 GetFirstEmptyDecorSlot(u8 idx); u8 CheckHasDecoration(u8); diff --git a/include/load_save.h b/include/load_save.h index b8b27ade5..c64a1179b 100644 --- a/include/load_save.h +++ b/include/load_save.h @@ -30,6 +30,5 @@ void LoadPlayerBag(void); void SavePlayerBag(void); void ApplyNewEncryptionKeyToHword(u16 *hWord, u32 newKey); void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey); -void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey); #endif // GUARD_LOAD_SAVE_H diff --git a/include/overworld.h b/include/overworld.h index 6b38a8782..3e9d42a22 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -73,7 +73,7 @@ void SetFixedHoleWarpAsDestination(s16 x, s16 y); void warp1_set_to_sav1w(void); void sub_8084F2C(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void sub_8084F6C(u8 a1); -void sub_8084FAC(void); +void sub_8084FAC(int unused); const struct MapConnection *GetMapConnection(u8 dir); static bool8 SetDiveWarp(u8 dir, u16 x, u16 y); bool8 SetDiveWarpEmerge(u16 x, u16 y); diff --git a/include/save.h b/include/save.h index a5f014904..b151f1064 100644 --- a/include/save.h +++ b/include/save.h @@ -54,7 +54,12 @@ enum SAVE_HALL_OF_FAME_ERASE_BEFORE // unused }; -#define SECTION_ID_RECORDED_BATTLE 31 +#define SECTOR_SAVE_SLOT_LENGTH 14 +#define SECTOR_ID_HOF_1 28 +#define SECTOR_ID_HOF_2 29 +#define SECTOR_ID_TRAINER_HILL 30 +#define SECTOR_ID_RECORDED_BATTLE 31 +#define SECTORS_COUNT 32 extern u16 gLastWrittenSector; extern u32 gLastSaveCounter; @@ -72,26 +77,6 @@ extern struct SaveSection gSaveDataBuffer; void ClearSaveData(void); void Save_ResetSaveCounters(void); -bool32 SetDamagedSectorBits(u8 op, u8 bit); -u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location); -u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location); -u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size); -u8 TryWriteSector(u8 sector, u8 *data); -u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location); -u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location); -u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location); -u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location); -u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location); -u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location); -u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location); -u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location); -u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location); -u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location); -u8 GetSaveValidStatus(const struct SaveSectionLocation *location); -u8 sub_81530DC(u8 a1, u8 *data, u16 size); -u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section); -u16 CalculateChecksum(void *data, u16 size); -void UpdateSaveAddresses(void); u8 HandleSavingData(u8 saveType); u8 TrySavingData(u8 saveType); bool8 sub_8153380(void); diff --git a/include/save_location.h b/include/save_location.h index 95b3a7d7d..71dbd3fd8 100644 --- a/include/save_location.h +++ b/include/save_location.h @@ -1,7 +1,6 @@ #ifndef GUARD_SAVE_LOCATION_H #define GUARD_SAVE_LOCATION_H -bool32 sub_81AFCEC(void); void TrySetMapSaveWarpStatus(void); void sub_81AFDA0(void); void sub_81AFDD0(void); diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c index 8da8502b3..eb79f7b5e 100644 --- a/src/clear_save_data_screen.c +++ b/src/clear_save_data_screen.c @@ -10,6 +10,7 @@ #include "bg.h" #include "text_window.h" #include "constants/songs.h" +#include "constants/rgb.h" extern const u8 gText_ClearAllSaveData[]; extern const u8 gText_ClearingData[]; @@ -72,7 +73,7 @@ static const struct WindowTemplate sClearSaveYesNo[] = void CB2_InitClearSaveDataScreen(void) { - if(SetupClearSaveDataScreen()) + if (SetupClearSaveDataScreen()) CreateTask(Task_DoClearSaveDataScreenYesNo, 0); } @@ -86,18 +87,18 @@ static void Task_DoClearSaveDataScreenYesNo(u8 taskId) static void Task_ClearSaveDataScreenYesNoChoice(u8 taskId) { - switch(Menu_ProcessInputNoWrapClearOnChoose()) + switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: - FillWindowPixelBuffer(0, 17); - AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0); - gTasks[taskId].func = Task_ClearSaveData; - break; - case 1: - case -1: - PlaySE(SE_SELECT); - DestroyTask(taskId); - SetMainCallback2(CB2_FadeAndDoReset); + case 0: + FillWindowPixelBuffer(0, 17); + AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0); + gTasks[taskId].func = Task_ClearSaveData; + break; + case 1: + case -1: + PlaySE(SE_SELECT); + DestroyTask(taskId); + SetMainCallback2(CB2_FadeAndDoReset); } } @@ -125,55 +126,55 @@ static bool8 SetupClearSaveDataScreen(void) switch(gMain.state) { - case 0: - default: - SetVBlankCallback(NULL); - SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BG0HOFS, 0); - SetGpuReg(REG_OFFSET_BG0VOFS, 0); - SetGpuReg(REG_OFFSET_BG3HOFS, 0); - SetGpuReg(REG_OFFSET_BG3VOFS, 0); - SetGpuReg(REG_OFFSET_WIN0H, 0); - SetGpuReg(REG_OFFSET_WIN0V, 0); - SetGpuReg(REG_OFFSET_WININ, 0); - SetGpuReg(REG_OFFSET_WINOUT, 0); - SetGpuReg(REG_OFFSET_BLDCNT, 0); - SetGpuReg(REG_OFFSET_BLDALPHA, 0); - SetGpuReg(REG_OFFSET_BLDY, 0); - DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE); - DmaFill32(3, 0, (void *)OAM, OAM_SIZE); - DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2); - ResetPaletteFade(); - gPlttBufferUnfaded[0] = 0x7fff; - gPlttBufferFaded[0] = 0x7fff; - gPlttBufferUnfaded[1] = 0x3945; - gPlttBufferFaded[1] = 0x3945; - for (i = 0; i < 0x10; i++) - ((u16 *)(VRAM + 0x20))[i] = 0x1111; + case 0: + default: + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 0); + SetGpuReg(REG_OFFSET_WINOUT, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); + DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE); + DmaFill32(3, 0, (void *)OAM, OAM_SIZE); + DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2); + ResetPaletteFade(); + gPlttBufferUnfaded[0] = RGB_WHITE; + gPlttBufferFaded[0] = RGB_WHITE; + gPlttBufferUnfaded[1] = RGB(5, 10, 14); + gPlttBufferFaded[1] = RGB(5, 10, 14); + for (i = 0; i < 0x10; i++) + ((u16 *)(VRAM + 0x20))[i] = 0x1111; - for (i = 0; i < 0x400; i++) - ((u16 *)(VRAM + 0xF000))[i] = 0x0001; - ResetTasks(); - ResetSpriteData(); - ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates)); - SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); - ShowBg(0); - ShowBg(3); - SetGpuReg(REG_OFFSET_BLDCNT, 0); - InitClearSaveDataScreenWindows(); - BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF); - EnableInterrupts(1); - SetVBlankCallback(VBlankCB); - gMain.state = 1; - break; - case 1: - UpdatePaletteFade(); - if(!gPaletteFade.active) - { - SetMainCallback2(MainCB); - return TRUE; - } + for (i = 0; i < 0x400; i++) + ((u16 *)(VRAM + 0xF000))[i] = 0x0001; + ResetTasks(); + ResetSpriteData(); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates)); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + ShowBg(0); + ShowBg(3); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + InitClearSaveDataScreenWindows(); + BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF); + EnableInterrupts(INTR_FLAG_VBLANK); + SetVBlankCallback(VBlankCB); + gMain.state = 1; + break; + case 1: + UpdatePaletteFade(); + if(!gPaletteFade.active) + { + SetMainCallback2(MainCB); + return TRUE; + } } return FALSE; } @@ -182,18 +183,19 @@ static void CB2_FadeAndDoReset(void) { switch(gMain.state) { - case 0: - default: - BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, 0xFFFF); - gMain.state = 1; - break; - case 1: - UpdatePaletteFade(); - if(!gPaletteFade.active) - { - FreeAllWindowBuffers(); - DoSoftReset(); - } + case 0: + default: + BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, 0xFFFF); + gMain.state = 1; + break; + case 1: + UpdatePaletteFade(); + if(!gPaletteFade.active) + { + FreeAllWindowBuffers(); + DoSoftReset(); + } + break; } } diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 22206405b..a197b7a18 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -521,7 +521,7 @@ static void Task_Hof_InitTeamSaveData(u8 taskId) static void Task_Hof_TrySaveData(u8 taskId) { gGameContinueCallback = CB2_DoHallOfFameScreenDontSaveData; - if (TrySavingData(3) == 0xFF && gDamagedSaveSectors != 0) + if (TrySavingData(SAVE_HALL_OF_FAME) == 0xFF && gDamagedSaveSectors != 0) { UnsetBgTilemapBuffer(1); UnsetBgTilemapBuffer(3); diff --git a/src/load_save.c b/src/load_save.c index 45b4d200b..960a98981 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -6,14 +6,15 @@ #include "random.h" #include "malloc.h" #include "item.h" +#include "overworld.h" +#include "decoration_inventory.h" + +static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey); extern void* gUnknown_0203CF5C; extern bool16 IdentifyFlash(void); -extern void SetDecorationInventoriesPointers(void); -extern void ApplyNewEncryptionKeyToGameStats(u32 key); extern void ApplyNewEncryptionKeyToBerryPowder(u32 key); -extern void sub_8084FAC(int unused); #define SAVEBLOCK_MOVE_RANGE 128 @@ -286,7 +287,7 @@ void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey) *word ^= newKey; } -void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey) +static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey) { ApplyNewEncryptionKeyToGameStats(encryptionKey); ApplyNewEncryptionKeyToBagItems_(encryptionKey); diff --git a/src/overworld.c b/src/overworld.c index 69ac9c822..d73a89d33 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -764,7 +764,7 @@ void sub_8084F6C(u8 a1) SetWarpData(&gSaveBlock1Ptr->warp1, warp->group, warp->map, -1, warp->x, warp->y); } -void sub_8084FAC(void) +void sub_8084FAC(int unused) { gSaveBlock1Ptr->warp1 = gSaveBlock1Ptr->warp2; } diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 50dd2efa8..5d79cb789 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -490,7 +490,7 @@ bool32 MoveRecordedBattleToSaveData(void) static bool32 TryCopyRecordedBattleSaveData(struct RecordedBattleSave *dst, struct SaveSection *saveBuffer) { - if (TryCopySpecialSaveSection(SECTION_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1) + if (TryCopySpecialSaveSection(SECTOR_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1) return FALSE; memcpy(dst, saveBuffer, sizeof(struct RecordedBattleSave)); diff --git a/src/save.c b/src/save.c index 0bd48cca9..3ee98f4f7 100644 --- a/src/save.c +++ b/src/save.c @@ -1,15 +1,23 @@ #include "global.h" #include "gba/flash_internal.h" #include "save.h" -#include "constants/game_stat.h" #include "task.h" #include "decompress.h" #include "load_save.h" #include "overworld.h" +#include "main.h" +#include "constants/game_stat.h" + +static u16 CalculateChecksum(void *data, u16 size); +static u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section); +static u8 GetSaveValidStatus(const struct SaveSectionLocation *location); +static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location); +static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location); +static u8 TryWriteSector(u8 sector, u8 *data); +static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location); // for the chunk declarations -extern bool8 gSoftResetDisabled; extern u32 gUnknown_0203CF5C; // Divide save blocks into individual chunks to be written to flash sectors @@ -24,7 +32,7 @@ extern u32 gUnknown_0203CF5C; * Sectors 0 - 13: Save Slot 1 * Sectors 14 - 27: Save Slot 2 * Sectors 28 - 29: Hall of Fame - * Sector 30: e-Reader/Mystery Gift Stuff (note: e-Reader is deprecated in Emerald US) + * Sector 30: Trainer Hill * Sector 31: Recorded Battle * * There are two save slots for saving the player's game data. We alternate between @@ -105,7 +113,7 @@ void Save_ResetSaveCounters(void) gDamagedSaveSectors = 0; } -bool32 SetDamagedSectorBits(u8 op, u8 bit) +static bool32 SetDamagedSectorBits(u8 op, u8 bit) { bool32 retVal = FALSE; @@ -126,7 +134,7 @@ bool32 SetDamagedSectorBits(u8 op, u8 bit) return retVal; } -u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) +static u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) { u32 retVal; u16 i; @@ -142,11 +150,11 @@ u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) gLastKnownGoodSector = gLastWrittenSector; // backup the current written sector before attempting to write. gLastSaveCounter = gSaveCounter; gLastWrittenSector++; - gLastWrittenSector = gLastWrittenSector % 0xE; // array count save sector locations + gLastWrittenSector = gLastWrittenSector % SECTOR_SAVE_SLOT_LENGTH; // array count save sector locations gSaveCounter++; retVal = 1; - for (i = 0; i < 0xE; i++) + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) HandleWriteSector(i, location); if (gDamagedSaveSectors != 0) // skip the damaged sector. @@ -160,7 +168,7 @@ u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) return retVal; } -u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) +static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) { u16 i; u16 sector; @@ -168,8 +176,8 @@ u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) u16 size; sector = a1 + gLastWrittenSector; - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); data = location[a1].data; size = location[a1].size; @@ -189,7 +197,7 @@ u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) return TryWriteSector(sector, gFastSaveSection->data); } -u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size) +static u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size) { u16 i; struct SaveSection *section = &gSaveDataBuffer; @@ -206,7 +214,7 @@ u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size) return TryWriteSector(sector, section->data); } -u8 TryWriteSector(u8 sector, u8 *data) +static u8 TryWriteSector(u8 sector, u8 *data) { if (ProgramFlashSectorAndVerify(sector, data) != 0) // is damaged? { @@ -220,20 +228,20 @@ u8 TryWriteSector(u8 sector, u8 *data) } } -u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location) // location is unused +static u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location) // location is unused { gFastSaveSection = &gSaveDataBuffer; gLastKnownGoodSector = gLastWrittenSector; gLastSaveCounter = gSaveCounter; gLastWrittenSector++; - gLastWrittenSector = gLastWrittenSector % 0xE; + gLastWrittenSector %= SECTOR_SAVE_SLOT_LENGTH; gSaveCounter++; gUnknown_03006208 = 0; gDamagedSaveSectors = 0; return 0; } -u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ever called once, and gSaveBlock2 is passed to this function. location is unused +static u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ever called once, and gSaveBlock2 is passed to this function. location is unused { gFastSaveSection = &gSaveDataBuffer; gLastKnownGoodSector = gLastWrittenSector; @@ -243,7 +251,7 @@ u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ev return 0; } -u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location) { u8 retVal; @@ -267,7 +275,7 @@ u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location) return retVal; } -u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location) { u8 retVal = 1; @@ -282,7 +290,7 @@ u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location) return retVal; } -u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) +static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) { u16 i; u16 sector; @@ -291,8 +299,8 @@ u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) u8 status; sector = a1 + gLastWrittenSector; - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); data = location[a1].data; size = location[a1].size; @@ -356,13 +364,13 @@ u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) } } -u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location) +static u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location) { u16 sector; sector = a1 + gLastWrittenSector; // no sub 1? - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25)) { @@ -379,13 +387,13 @@ u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location) } } -u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location) { u16 sector; sector = a1 + gLastWrittenSector - 1; - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), ((u8 *)gFastSaveSection)[sizeof(struct UnkSaveSection)])) { @@ -402,13 +410,13 @@ u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location) } } -u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location) { u16 sector; sector = a1 + gLastWrittenSector - 1; // no sub 1? - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25)) { @@ -425,7 +433,7 @@ u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location) } } -u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location) { u8 retVal; gFastSaveSection = &gSaveDataBuffer; @@ -442,14 +450,14 @@ u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location) return retVal; } -u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location) { u16 i; u16 checksum; - u16 v3 = 0xE * (gSaveCounter % 2); + u16 v3 = SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); u16 id; - for (i = 0; i < 0xE; i++) + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) { DoReadFlashWholeSection(i + v3, gFastSaveSection); id = gFastSaveSection->id; @@ -468,7 +476,7 @@ u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location) return 1; } -u8 GetSaveValidStatus(const struct SaveSectionLocation *location) +static u8 GetSaveValidStatus(const struct SaveSectionLocation *location) { u16 i; u16 checksum; @@ -480,7 +488,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location) u8 saveSlot2Status; // check save slot 1. - for (i = 0; i < 0xE; i++) + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) { DoReadFlashWholeSection(i, gFastSaveSection); if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE) @@ -511,9 +519,9 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location) securityPassed = FALSE; // check save slot 2. - for (i = 0; i < 0xE; i++) + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) { - DoReadFlashWholeSection(i + 0xE, gFastSaveSection); + DoReadFlashWholeSection(i + SECTOR_SAVE_SLOT_LENGTH, gFastSaveSection); if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE) { securityPassed = TRUE; @@ -543,24 +551,16 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location) if ((saveSlot1Counter == -1 && saveSlot2Counter == 0) || (saveSlot1Counter == 0 && saveSlot2Counter == -1)) { if ((unsigned)(saveSlot1Counter + 1) < (unsigned)(saveSlot2Counter + 1)) - { gSaveCounter = saveSlot2Counter; - } else - { gSaveCounter = saveSlot1Counter; - } } else { if (saveSlot1Counter < saveSlot2Counter) - { gSaveCounter = saveSlot2Counter; - } else - { gSaveCounter = saveSlot1Counter; - } } return 1; } @@ -593,7 +593,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location) return 2; } -u8 sub_81530DC(u8 a1, u8 *data, u16 size) +static u8 sub_81530DC(u8 a1, u8 *data, u16 size) { u16 i; struct SaveSection *section = &gSaveDataBuffer; @@ -618,13 +618,13 @@ u8 sub_81530DC(u8 a1, u8 *data, u16 size) } } -u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section) +static u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section) { ReadFlash(sector, 0, section->data, sizeof(struct SaveSection)); return 1; } -u16 CalculateChecksum(void *data, u16 size) +static u16 CalculateChecksum(void *data, u16 size) { u16 i; u32 checksum = 0; @@ -635,7 +635,7 @@ u16 CalculateChecksum(void *data, u16 size) return ((checksum >> 16) + checksum); } -void UpdateSaveAddresses(void) +static void UpdateSaveAddresses(void) { int i = 0; @@ -668,7 +668,7 @@ u8 HandleSavingData(u8 saveType) switch (saveType) { case SAVE_HALL_OF_FAME_ERASE_BEFORE: // deletes HOF before overwriting HOF completely. unused - for (i = 0xE * 2 + 0; i < 32; i++) + for (i = SECTOR_ID_HOF_1; i < SECTORS_COUNT; i++) EraseFlashSector(i); case SAVE_HALL_OF_FAME: // hall of fame. if (GetGameStat(GAME_STAT_ENTERED_HOF) < 999) @@ -676,8 +676,8 @@ u8 HandleSavingData(u8 saveType) SaveSerializedGame(); save_write_to_flash(0xFFFF, gRamSaveSectionLocations); tempAddr = gDecompressionBuffer; - HandleWriteSectorNBytes(0x1C, tempAddr, 0xF80); - HandleWriteSectorNBytes(0x1D, tempAddr + 0xF80, 0xF80); + HandleWriteSectorNBytes(SECTOR_ID_HOF_1, tempAddr, 0xF80); + HandleWriteSectorNBytes(SECTOR_ID_HOF_2, tempAddr + 0xF80, 0xF80); break; case SAVE_NORMAL: // normal save. also called by overwriting your own save. default: @@ -692,7 +692,7 @@ u8 HandleSavingData(u8 saveType) for(i = 0; i < 5; i++) sav12_xor_get(i, gRamSaveSectionLocations); break; - // support for Ereader was removed in Emerald. + // Support for Ereader was removed in Emerald. /* case EREADER_SAVE: // used in mossdeep "game corner" before/after battling old man e-reader trainer SaveSerializedGame(); @@ -700,7 +700,7 @@ u8 HandleSavingData(u8 saveType) break; */ case SAVE_OVERWRITE_DIFFERENT_FILE: - for (i = (0xE * 2 + 0); i < 32; i++) + for (i = SECTOR_ID_HOF_1; i < SECTORS_COUNT; i++) EraseFlashSector(i); // erase HOF. SaveSerializedGame(); save_write_to_flash(0xFFFF, gRamSaveSectionLocations); @@ -710,7 +710,7 @@ u8 HandleSavingData(u8 saveType) return 0; } -u8 TrySavingData(u8 saveType) // TrySave +u8 TrySavingData(u8 saveType) { if (gFlashMemoryPresent != TRUE) { @@ -744,7 +744,7 @@ bool8 sub_8153380(void) // trade.s save bool8 sub_81533AC(void) // trade.s save { - u8 retVal = sub_81529D4(0xE, gRamSaveSectionLocations); + u8 retVal = sub_81529D4(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations); if (gDamagedSaveSectors) DoSaveFailedScreen(0); if (retVal == 0xFF) @@ -755,7 +755,7 @@ bool8 sub_81533AC(void) // trade.s save u8 sub_81533E0(void) // trade.s save { - sub_8152A34(0xE, gRamSaveSectionLocations); + sub_8152A34(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations); if (gDamagedSaveSectors) DoSaveFailedScreen(0); return 0; @@ -763,7 +763,7 @@ u8 sub_81533E0(void) // trade.s save u8 sub_8153408(void) // trade.s save { - sub_8152CAC(0xE, gRamSaveSectionLocations); + sub_8152CAC(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations); if (gDamagedSaveSectors) DoSaveFailedScreen(0); return 0; @@ -840,8 +840,8 @@ u16 sub_815355C(void) return 0; UpdateSaveAddresses(); GetSaveValidStatus(gRamSaveSectionLocations); - v3 = 0xE * (gSaveCounter % 2); - for (i = 0; i < 14; i++) + v3 = SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) { DoReadFlashWholeSection(i + v3, gFastSaveSection); if (gFastSaveSection->id == 0) @@ -859,7 +859,7 @@ u32 TryCopySpecialSaveSection(u8 sector, u8* dst) s32 size; u8* savData; - if (sector != 30 && sector != 31) + if (sector != SECTOR_ID_TRAINER_HILL && sector != SECTOR_ID_RECORDED_BATTLE) return 0xFF; ReadFlash(sector, 0, (u8 *)&gSaveDataBuffer, sizeof(struct SaveSection)); if (*(u32*)(&gSaveDataBuffer.data[0]) != 0xB39D) diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 010279a87..ede9fe672 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -17,12 +17,12 @@ #define MSG_WIN_TOP 12 #define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) -extern u8 gText_SaveFailedCheckingBackup[]; -extern u8 gText_BackupMemoryDamaged[]; -extern u8 gText_CheckCompleted[]; -extern u8 gText_SaveCompleteGameCannotContinue[]; -extern u8 gText_SaveCompletePressA[]; -extern u8 gText_GamePlayCannotBeContinued[]; +extern const u8 gText_SaveFailedCheckingBackup[]; +extern const u8 gText_BackupMemoryDamaged[]; +extern const u8 gText_CheckCompleted[]; +extern const u8 gText_SaveCompleteGameCannotContinue[]; +extern const u8 gText_SaveCompletePressA[]; +extern const u8 gText_GamePlayCannotBeContinued[]; // gSaveFailedClockInfo enum enum @@ -155,8 +155,8 @@ static void VBlankCB_UpdateClockGraphics(void); static bool8 VerifySectorWipe(u16 sector); static bool8 WipeSectors(u32); -// although this is a general text printer, it's only used in this file. -static void SaveFailedScreenTextPrint(u8 *text, u8 var1, u8 var2) +// Although this is a general text printer, it's only used in this file. +static void SaveFailedScreenTextPrint(const u8 *text, u8 var1, u8 var2) { u8 color[3]; @@ -187,72 +187,70 @@ static void CB2_SaveFailedScreen(void) { switch (gMain.state) { - case 0: - default: - SetVBlankCallback(NULL); - SetGpuReg(REG_OFFSET_DISPCNT, 0); - SetGpuReg(REG_OFFSET_BG3CNT, 0); - SetGpuReg(REG_OFFSET_BG2CNT, 0); - SetGpuReg(REG_OFFSET_BG1CNT, 0); - SetGpuReg(REG_OFFSET_BG0CNT, 0); - SetGpuReg(REG_OFFSET_BG3HOFS, 0); - SetGpuReg(REG_OFFSET_BG3VOFS, 0); - SetGpuReg(REG_OFFSET_BG2HOFS, 0); - SetGpuReg(REG_OFFSET_BG2VOFS, 0); - SetGpuReg(REG_OFFSET_BG1HOFS, 0); - SetGpuReg(REG_OFFSET_BG1VOFS, 0); - SetGpuReg(REG_OFFSET_BG0HOFS, 0); - SetGpuReg(REG_OFFSET_BG0VOFS, 0); - // how come this doesnt use the Dma manager? - DmaFill16(3, 0, VRAM, VRAM_SIZE); - DmaFill32(3, 0, OAM, OAM_SIZE); - DmaFill16(3, 0, PLTT, PLTT_SIZE); - LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM); - LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000)); - LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800)); - LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020)); - ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, gUnknown_085EFD88, 3); - SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]); - CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800); - LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214); - InitWindows(gUnknown_085EFD94); - // AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug? - gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C); - SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]); - gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4); - SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]); - DeactivateAllTextPrinters(); - ResetSpriteData(); - ResetTasks(); - ResetPaletteFade(); - LoadPalette(gBirchBagGrassPal, 0, 0x40); - LoadPalette(sSaveFailedClockPal, 0x100, 0x20); - LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20); - LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); - SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); - FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards? - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); - CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? - CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); - SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); - BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); - EnableInterrupts(1); - SetVBlankCallback(VBlankCB); - SetGpuReg(0, 0x1040); - ShowBg(0); - ShowBg(2); - ShowBg(3); - gMain.state++; - break; - case 1: - if (!UpdatePaletteFade()) - { - SetMainCallback2(CB2_WipeSave); - SetVBlankCallback(VBlankCB_UpdateClockGraphics); - } - break; + case 0: + default: + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG3CNT, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + DmaFill16(3, 0, VRAM, VRAM_SIZE); + DmaFill32(3, 0, OAM, OAM_SIZE); + DmaFill16(3, 0, PLTT, PLTT_SIZE); + LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM); + LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000)); + LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800)); + LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020)); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gUnknown_085EFD88, 3); + SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]); + CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800); + LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214); + InitWindows(gUnknown_085EFD94); + gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C); + SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]); + gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4); + SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]); + DeactivateAllTextPrinters(); + ResetSpriteData(); + ResetTasks(); + ResetPaletteFade(); + LoadPalette(gBirchBagGrassPal, 0, 0x40); + LoadPalette(sSaveFailedClockPal, 0x100, 0x20); + LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20); + LoadPalette(gUnknown_0860F074, 0xF0, 0x20); + SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); + SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); + FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards? + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? + CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); + SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); + EnableInterrupts(1); + SetVBlankCallback(VBlankCB); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + ShowBg(0); + ShowBg(2); + ShowBg(3); + gMain.state++; + break; + case 1: + if (!UpdatePaletteFade()) + { + SetMainCallback2(CB2_WipeSave); + SetVBlankCallback(VBlankCB_UpdateClockGraphics); + } + break; } } @@ -346,7 +344,7 @@ static void CB2_ReturnToTitleScreen(void) static void VBlankCB_UpdateClockGraphics(void) { - unsigned int n = (gMain.vblankCounter2 >> 3) & 7; + u32 n = (gMain.vblankCounter2 >> 3) & 7; gMain.oamBuffer[0] = sClockOamData; gMain.oamBuffer[0].x = 112; diff --git a/src/save_location.c b/src/save_location.c index 262aaf40c..d49afa736 100644 --- a/src/save_location.c +++ b/src/save_location.c @@ -9,21 +9,18 @@ static bool32 IsCurMapInLocationList(const u16 *list) { + s32 i; u16 locSum = (gSaveBlock1Ptr->location.mapGroup << 8) + (gSaveBlock1Ptr->location.mapNum); - // im sure it was written a different way, but for the love of christ I cant figure out how to write it different where it still matches. - if (*list != 0xFFFF) + for (i = 0; list[i] != 0xFFFF; i++) { - u16 termValue = 0xFFFF; - const u16 *localList; - for (localList = list; *localList != termValue; localList++) - if (*localList == locSum) - return TRUE; + if (list[i] == locSum) + return TRUE; } + return FALSE; } -// TODO: Not require a packed u16 array for these lists static const u16 sSaveLocationPokeCenterList[] = { MAP_OLDALE_TOWN_POKEMON_CENTER_1F, @@ -72,7 +69,7 @@ static bool32 IsCurMapPokeCenter(void) return IsCurMapInLocationList(sSaveLocationPokeCenterList); } -static const u16 sSaveLocationReloadLocList[] = // there's only 1 location, and it's presumed its for the save reload feature for battle tower +static const u16 sSaveLocationReloadLocList[] = // There's only 1 location, and it's presumed its for the save reload feature for battle tower. { MAP_BATTLE_FRONTIER_BATTLE_TOWER_LOBBY, 0xFFFF, @@ -83,13 +80,13 @@ static bool32 IsCurMapReloadLocation(void) return IsCurMapInLocationList(sSaveLocationReloadLocList); } -// nulled out list. unknown what this would have been +// Nulled out list. Unknown what this would have been. static const u16 sUnknown_0861440E[] = { 0xFFFF, }; -bool32 sub_81AFCEC(void) +static bool32 sub_81AFCEC(void) { return IsCurMapInLocationList(sUnknown_0861440E); } From f2d3babd30c51b79c48d065f809273a10929a2ee Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 18 Nov 2018 20:04:53 +0100 Subject: [PATCH 6/7] rename to mossdeep gym --- asm/{battle_frontier_2.s => mossdeep_gym.s} | 0 ld_script.txt | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename asm/{battle_frontier_2.s => mossdeep_gym.s} (100%) diff --git a/asm/battle_frontier_2.s b/asm/mossdeep_gym.s similarity index 100% rename from asm/battle_frontier_2.s rename to asm/mossdeep_gym.s diff --git a/ld_script.txt b/ld_script.txt index 21fff394d..ea6ef5bcd 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -268,7 +268,7 @@ SECTIONS { src/battle_arena.o(.text); src/battle_factory.o(.text); src/battle_pike.o(.text); - asm/battle_frontier_2.o(.text); + asm/mossdeep_gym.o(.text); src/battle_pyramid.o(.text); src/item_menu.o(.text); src/list_menu.o(.text); From 682e6c85126c6853ab85996ef63f57e4a02651fb Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 18 Nov 2018 20:09:11 +0100 Subject: [PATCH 7/7] Use RGB constants in save files --- src/clear_save_data_screen.c | 2 +- src/save_failed_screen.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c index eb79f7b5e..72d0daf55 100644 --- a/src/clear_save_data_screen.c +++ b/src/clear_save_data_screen.c @@ -185,7 +185,7 @@ static void CB2_FadeAndDoReset(void) { case 0: default: - BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, 0xFFFF); + BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, RGB_WHITEALPHA); gMain.state = 1; break; case 1: diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index ede9fe672..c668c1db0 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -13,6 +13,7 @@ #include "starter_choose.h" #include "gba/flash_internal.h" #include "text_window.h" +#include "constants/rgb.h" #define MSG_WIN_TOP 12 #define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) @@ -235,7 +236,7 @@ static void CB2_SaveFailedScreen(void) CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); - BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); EnableInterrupts(1); SetVBlankCallback(VBlankCB); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);