From c2fdde3a498b6b6bbf8a57784e3208be74bf59f7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 2 Dec 2017 20:38:26 +0100 Subject: [PATCH] pokeball file is decompiled --- asm/crt0.s | 4 +- asm/main_menu.s | 2 +- asm/pokeball.s | 1194 ----------------------------------------- asm/trade.s | 4 +- data/graphics.s | 2 +- data/pokeball.s | 4 +- include/battle_anim.h | 3 +- include/pokeball.h | 17 +- ld_script.txt | 1 - src/pokeball.c | 429 ++++++++++++++- 10 files changed, 429 insertions(+), 1231 deletions(-) delete mode 100755 asm/pokeball.s diff --git a/asm/crt0.s b/asm/crt0.s index 0b14a1469..d99ce9deb 100644 --- a/asm/crt0.s +++ b/asm/crt0.s @@ -68,8 +68,8 @@ GPIOPortReadEnable: @ 80000C8 .4byte gAbilityDescriptionPointers .4byte gItems .4byte gBattleMoves - .4byte gUnknown_0832C400 - .4byte gUnknown_0832C460 + .4byte sBallSpriteSheets + .4byte sBallSpritePalettes .4byte 0x000000a8, 0x00000864, 0x0000089b diff --git a/asm/main_menu.s b/asm/main_menu.s index 6194f0487..7b7ce49f7 100644 --- a/asm/main_menu.s +++ b/asm/main_menu.s @@ -2215,7 +2215,7 @@ sub_8030A70: @ 8030A70 str r2, [sp, 0x10] movs r2, 0x70 movs r3, 0x3A - bl sub_8076438 + bl CreatePokeballSpriteToReleaseMon lsls r0, r4, 2 adds r0, r4 lsls r0, 3 diff --git a/asm/pokeball.s b/asm/pokeball.s deleted file mode 100755 index a512fd857..000000000 --- a/asm/pokeball.s +++ /dev/null @@ -1,1194 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - - - thumb_func_start SpriteCB_PlayerMonSendOut_2 -SpriteCB_PlayerMonSendOut_2: @ 8076204 - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r5, r0, 0 - ldrh r0, [r5, 0x3C] - movs r1, 0xFF - mov r8, r1 - lsrs r0, 8 - subs r0, 0x23 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x2C - bhi _080762F8 - ldrh r1, [r5, 0x6] - movs r0, 0xFF - lsls r0, 8 - ands r0, r1 - cmp r0, 0 - bne _08076266 - ldrh r0, [r5, 0x30] - movs r1, 0x1 - adds r6, r1, 0 - ands r6, r0 - ldrh r0, [r5, 0x32] - adds r7, r1, 0 - ands r7, r0 - movs r2, 0x30 - ldrsh r0, [r5, r2] - movs r1, 0x3 - bl __divsi3 - movs r1, 0x2 - negs r1, r1 - adds r4, r1, 0 - ands r0, r4 - orrs r6, r0 - strh r6, [r5, 0x30] - movs r2, 0x32 - ldrsh r0, [r5, r2] - movs r1, 0x3 - bl __divsi3 - ands r0, r4 - orrs r7, r0 - strh r7, [r5, 0x32] - adds r0, r5, 0 - movs r1, 0x4 - bl StartSpriteAffineAnim -_08076266: - ldrh r4, [r5, 0x2E] - adds r0, r5, 0 - bl sub_80A6F3C - movs r1, 0x3A - ldrsh r0, [r5, r1] - movs r1, 0x3 - bl __divsi3 - adds r1, r0, 0 - ldrh r0, [r5, 0x3C] - adds r0, r1 - strh r0, [r5, 0x3C] - lsls r0, 16 - asrs r0, 24 - mov r2, r8 - ands r0, r2 - movs r2, 0x38 - ldrsh r1, [r5, r2] - bl Sin - ldrh r1, [r5, 0x26] - adds r0, r1 - strh r0, [r5, 0x26] - movs r2, 0x80 - lsls r2, 1 - adds r0, r2, 0 - ldrh r1, [r5, 0x6] - adds r0, r1 - strh r0, [r5, 0x6] - lsls r0, 16 - lsrs r0, 24 - movs r1, 0x3 - bl __umodsi3 - lsls r0, 16 - cmp r0, 0 - beq _080762B6 - strh r4, [r5, 0x2E] - b _080762BE -_080762B6: - lsls r0, r4, 16 - asrs r0, 16 - subs r0, 0x1 - strh r0, [r5, 0x2E] -_080762BE: - ldrh r0, [r5, 0x3C] - lsrs r0, 8 - cmp r0, 0x4F - ble _08076364 - ldrh r0, [r5, 0x30] - movs r1, 0x1 - adds r6, r1, 0 - ands r6, r0 - ldrh r0, [r5, 0x32] - adds r7, r1, 0 - ands r7, r0 - movs r2, 0x30 - ldrsh r1, [r5, r2] - lsls r0, r1, 1 - adds r0, r1 - movs r1, 0x2 - negs r1, r1 - adds r2, r1, 0 - ands r0, r2 - orrs r0, r6 - strh r0, [r5, 0x30] - movs r0, 0x32 - ldrsh r1, [r5, r0] - lsls r0, r1, 1 - adds r0, r1 - ands r0, r2 - orrs r0, r7 - strh r0, [r5, 0x32] - b _08076364 -_080762F8: - adds r0, r5, 0 - bl AnimateBallThrow - lsls r0, 24 - cmp r0, 0 - beq _08076364 - ldrh r0, [r5, 0x24] - ldrh r1, [r5, 0x20] - adds r0, r1 - movs r1, 0 - strh r0, [r5, 0x20] - ldrh r0, [r5, 0x26] - ldrh r2, [r5, 0x22] - adds r0, r2 - strh r0, [r5, 0x22] - strh r1, [r5, 0x26] - strh r1, [r5, 0x24] - ldrb r0, [r5, 0x6] - strh r0, [r5, 0x3A] - strh r1, [r5, 0x2E] - bl IsDoubleBattle - lsls r0, 24 - cmp r0, 0 - beq _08076358 - ldr r0, =gBattleSpritesDataPtr - ldr r0, [r0] - ldr r0, [r0, 0x8] - ldrb r1, [r0, 0x9] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _08076358 - movs r0, 0x3A - ldrsh r4, [r5, r0] - movs r0, 0x2 - bl GetBankByIdentity - lsls r0, 24 - lsrs r0, 24 - cmp r4, r0 - bne _08076358 - ldr r0, =sub_8076374 - b _0807635A - .pool -_08076358: - ldr r0, =SpriteCB_ReleaseMonFromBall -_0807635A: - str r0, [r5, 0x1C] - adds r0, r5, 0 - movs r1, 0 - bl StartSpriteAffineAnim -_08076364: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end SpriteCB_PlayerMonSendOut_2 - - thumb_func_start sub_8076374 -sub_8076374: @ 8076374 - push {lr} - adds r2, r0, 0 - ldrh r0, [r2, 0x2E] - adds r1, r0, 0x1 - strh r1, [r2, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x18 - ble _0807638E - movs r0, 0 - strh r0, [r2, 0x2E] - ldr r0, =SpriteCB_ReleaseMonFromBall - str r0, [r2, 0x1C] -_0807638E: - pop {r0} - bx r0 - .pool - thumb_func_end sub_8076374 - - thumb_func_start SpriteCB_OpponentMonSendOut -SpriteCB_OpponentMonSendOut: @ 8076398 - push {r4,r5,lr} - adds r5, r0, 0 - ldrh r0, [r5, 0x2E] - adds r0, 0x1 - strh r0, [r5, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0xF - ble _080763EC - movs r0, 0 - strh r0, [r5, 0x2E] - bl IsDoubleBattle - lsls r0, 24 - cmp r0, 0 - beq _080763E8 - ldr r0, =gBattleSpritesDataPtr - ldr r0, [r0] - ldr r0, [r0, 0x8] - ldrb r1, [r0, 0x9] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080763E8 - movs r0, 0x3A - ldrsh r4, [r5, r0] - movs r0, 0x3 - bl GetBankByIdentity - lsls r0, 24 - lsrs r0, 24 - cmp r4, r0 - bne _080763E8 - ldr r0, =sub_8076374 - b _080763EA - .pool -_080763E8: - ldr r0, =SpriteCB_ReleaseMonFromBall -_080763EA: - str r0, [r5, 0x1C] -_080763EC: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end SpriteCB_OpponentMonSendOut - - thumb_func_start sub_80763F8 -sub_80763F8: @ 80763F8 - push {r4,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r1, 24 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsrs r3, 24 - movs r4, 0 - str r4, [sp] - bl LaunchBallStarsTask - lsls r0, 24 - lsrs r0, 24 - add sp, 0x4 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_80763F8 - - thumb_func_start sub_8076420 -sub_8076420: @ 8076420 - push {lr} - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r1, 24 - movs r3, 0 - bl LaunchBallFadeMonTask - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - thumb_func_end sub_8076420 - - thumb_func_start sub_8076438 -sub_8076438: @ 8076438 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r5, r0, 0 - mov r9, r2 - mov r10, r3 - ldr r6, [sp, 0x28] - ldr r4, [sp, 0x2C] - ldr r0, [sp, 0x30] - ldr r2, [sp, 0x38] - lsls r5, 24 - lsrs r5, 24 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp] - mov r1, r9 - lsls r1, 24 - lsrs r1, 24 - mov r9, r1 - lsls r3, 24 - lsrs r3, 24 - mov r10, r3 - lsls r6, 24 - lsrs r6, 24 - lsls r4, 24 - lsrs r4, 24 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x4] - lsls r0, r2, 16 - lsrs r7, r0, 16 - ldr r0, =gUnknown_0832C400 - bl LoadCompressedObjectPicUsingHeap - ldr r0, =gUnknown_0832C460 - bl LoadCompressedObjectPaletteUsingHeap - ldr r0, =gBallSpriteTemplates - mov r1, r9 - mov r2, r10 - adds r3, r4, 0 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gSprites - mov r8, r1 - lsls r4, r0, 4 - adds r4, r0 - lsls r4, 2 - adds r2, r4, r1 - strh r5, [r2, 0x2E] - lsls r1, r5, 4 - adds r1, r5 - lsls r1, 2 - add r1, r8 - ldrh r0, [r1, 0x20] - strh r0, [r2, 0x38] - ldrh r0, [r1, 0x22] - strh r0, [r2, 0x3A] - mov r3, r9 - strh r3, [r1, 0x20] - mov r0, r10 - strh r0, [r1, 0x22] - strh r7, [r1, 0x3C] - mov r3, sp - ldrh r3, [r3, 0x4] - strh r3, [r2, 0x30] - mov r0, sp - ldrh r0, [r0] - strh r0, [r2, 0x32] - mov r3, sp - ldrh r3, [r3, 0x34] - strh r3, [r2, 0x34] - ldr r3, [sp, 0x34] - lsrs r0, r3, 16 - strh r0, [r2, 0x36] - movs r0, 0x3 - ands r6, r0 - lsls r6, 2 - ldrb r3, [r2, 0x5] - movs r0, 0xD - negs r0, r0 - ands r0, r3 - orrs r0, r6 - strb r0, [r2, 0x5] - movs r0, 0x1C - add r8, r0 - add r4, r8 - ldr r0, =sub_8076524 - str r0, [r4] - adds r1, 0x3E - ldrb r0, [r1] - movs r2, 0x4 - orrs r0, r2 - strb r0, [r1] - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8076438 - - thumb_func_start sub_8076524 -sub_8076524: @ 8076524 - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r6, r0, 0 - ldrh r1, [r6, 0x30] - movs r2, 0x30 - ldrsh r0, [r6, r2] - cmp r0, 0 - bne _080765D0 - ldrh r0, [r6, 0x2E] - lsls r0, 24 - lsrs r7, r0, 24 - ldrh r0, [r6, 0x32] - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - ldrh r4, [r6, 0x34] - ldrh r0, [r6, 0x36] - lsls r0, 16 - orrs r4, r0 - adds r0, r6, 0 - adds r0, 0x43 - ldrb r0, [r0] - cmp r0, 0 - beq _0807655E - subs r0, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - b _08076560 -_0807655E: - movs r5, 0 -_08076560: - adds r0, r6, 0 - movs r1, 0x1 - bl StartSpriteAnim - ldrh r0, [r6, 0x20] - lsls r0, 24 - lsrs r0, 24 - ldrh r1, [r6, 0x22] - subs r1, 0x5 - lsls r1, 24 - lsrs r1, 24 - ldrb r2, [r6, 0x5] - lsls r2, 28 - lsrs r2, 30 - adds r3, r5, 0 - bl sub_80763F8 - movs r0, 0x1 - mov r1, r8 - adds r2, r4, 0 - bl sub_8076420 - lsls r0, 24 - lsrs r0, 24 - movs r5, 0 - strh r0, [r6, 0x30] - ldr r0, =sub_80765E0 - str r0, [r6, 0x1C] - ldr r0, =gSprites - lsls r4, r7, 4 - adds r4, r7 - lsls r4, 2 - adds r4, r0 - adds r2, r4, 0 - adds r2, 0x3E - ldrb r1, [r2] - movs r0, 0x5 - negs r0, r0 - ands r0, r1 - strb r0, [r2] - adds r0, r4, 0 - movs r1, 0x1 - bl StartSpriteAffineAnim - adds r0, r4, 0 - bl AnimateSprite - movs r0, 0x80 - lsls r0, 5 - strh r0, [r4, 0x30] - strh r5, [r6, 0x3C] - b _080765D4 - .pool -_080765D0: - subs r0, r1, 0x1 - strh r0, [r6, 0x30] -_080765D4: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8076524 - - thumb_func_start sub_80765E0 -sub_80765E0: @ 80765E0 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - adds r4, r0, 0 - movs r0, 0 - mov r12, r0 - movs r7, 0 - ldrh r0, [r4, 0x2E] - lsls r0, 24 - lsrs r6, r0, 24 - adds r0, r4, 0 - adds r0, 0x3F - ldrb r1, [r0] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _08076610 - adds r2, r4, 0 - adds r2, 0x3E - ldrb r0, [r2] - movs r1, 0x4 - orrs r0, r1 - strb r0, [r2] -_08076610: - ldr r1, =gSprites - lsls r2, r6, 4 - adds r0, r2, r6 - lsls r0, 2 - adds r5, r0, r1 - adds r0, r5, 0 - adds r0, 0x3F - ldrb r0, [r0] - lsls r0, 26 - mov r8, r2 - cmp r0, 0 - bge _08076634 - adds r0, r5, 0 - movs r1, 0 - bl StartSpriteAffineAnim - movs r1, 0x1 - mov r12, r1 -_08076634: - movs r2, 0x38 - ldrsh r0, [r4, r2] - movs r3, 0x20 - ldrsh r1, [r4, r3] - subs r0, r1 - movs r1, 0x3C - ldrsh r2, [r4, r1] - muls r0, r2 - cmp r0, 0 - bge _0807664A - adds r0, 0x7F -_0807664A: - asrs r0, 7 - ldrh r3, [r4, 0x20] - adds r0, r3 - lsls r0, 16 - lsrs r0, 16 - mov r9, r0 - movs r1, 0x3A - ldrsh r0, [r4, r1] - movs r3, 0x22 - ldrsh r1, [r4, r3] - subs r0, r1 - muls r0, r2 - cmp r0, 0 - bge _08076668 - adds r0, 0x7F -_08076668: - asrs r0, 7 - ldrh r1, [r4, 0x22] - adds r0, r1 - mov r2, r9 - strh r2, [r5, 0x20] - strh r0, [r5, 0x22] - ldrh r2, [r4, 0x3C] - movs r3, 0x3C - ldrsh r0, [r4, r3] - cmp r0, 0x7F - bgt _080766AC - ldr r1, =gSineTable - lsls r0, r2, 24 - lsrs r0, 23 - adds r0, r1 - movs r1, 0 - ldrsh r0, [r0, r1] - cmp r0, 0 - bge _08076690 - adds r0, 0x7 -_08076690: - asrs r0, 3 - negs r0, r0 - lsls r0, 16 - lsrs r0, 16 - adds r1, r2, 0x4 - strh r1, [r4, 0x3C] - strh r0, [r5, 0x24] - strh r0, [r5, 0x26] - b _080766BA - .pool -_080766AC: - ldrh r0, [r4, 0x38] - strh r0, [r5, 0x20] - ldrh r0, [r4, 0x3A] - strh r0, [r5, 0x22] - strh r7, [r5, 0x24] - strh r7, [r5, 0x26] - movs r7, 0x1 -_080766BA: - adds r0, r4, 0 - adds r0, 0x3F - ldrb r1, [r0] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _0807670E - mov r2, r12 - cmp r2, 0 - beq _0807670E - cmp r7, 0 - beq _0807670E - ldr r1, =gSprites - mov r3, r8 - adds r0, r3, r6 - lsls r0, 2 - adds r2, r0, r1 - movs r0, 0x3C - ldrsh r1, [r2, r0] - movs r0, 0xCE - lsls r0, 1 - cmp r1, r0 - bne _080766FC - ldrh r1, [r2, 0x3C] - adds r0, r2, 0 - movs r2, 0x1 - movs r3, 0 - bl DoMonFrontSpriteAnimation - b _08076708 - .pool -_080766FC: - ldrh r1, [r2, 0x3C] - adds r0, r2, 0 - movs r2, 0 - movs r3, 0 - bl DoMonFrontSpriteAnimation -_08076708: - adds r0, r4, 0 - bl DestroySpriteAndFreeResources -_0807670E: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80765E0 - - thumb_func_start sub_807671C -sub_807671C: @ 807671C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - mov r10, r0 - adds r6, r2, 0 - mov r8, r3 - ldr r5, [sp, 0x20] - ldr r4, [sp, 0x24] - ldr r0, [sp, 0x28] - mov r9, r0 - mov r0, r10 - lsls r0, 24 - lsrs r0, 24 - mov r10, r0 - lsls r1, 24 - lsrs r7, r1, 24 - lsls r6, 24 - lsrs r6, 24 - mov r1, r8 - lsls r1, 24 - lsrs r1, 24 - mov r8, r1 - lsls r5, 24 - lsrs r5, 24 - lsls r4, 24 - lsrs r4, 24 - mov r0, r9 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - ldr r0, =gUnknown_0832C400 - bl LoadCompressedObjectPicUsingHeap - ldr r0, =gUnknown_0832C460 - bl LoadCompressedObjectPaletteUsingHeap - ldr r0, =gBallSpriteTemplates - adds r1, r6, 0 - mov r2, r8 - adds r3, r4, 0 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r6, =gSprites - lsls r3, r0, 4 - adds r3, r0 - lsls r3, 2 - adds r2, r3, r6 - mov r1, r10 - strh r1, [r2, 0x2E] - mov r4, r9 - strh r4, [r2, 0x30] - strh r7, [r2, 0x32] - mov r1, sp - ldrh r1, [r1, 0x2C] - strh r1, [r2, 0x34] - ldr r4, [sp, 0x2C] - lsrs r1, r4, 16 - strh r1, [r2, 0x36] - movs r1, 0x3 - ands r5, r1 - lsls r5, 2 - ldrb r4, [r2, 0x5] - movs r1, 0xD - negs r1, r1 - ands r1, r4 - orrs r1, r5 - strb r1, [r2, 0x5] - adds r6, 0x1C - adds r3, r6 - ldr r1, =sub_80767D4 - str r1, [r3] - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_807671C - - thumb_func_start sub_80767D4 -sub_80767D4: @ 80767D4 - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r4, r0, 0 - ldrh r1, [r4, 0x30] - movs r2, 0x30 - ldrsh r0, [r4, r2] - cmp r0, 0 - bne _0807686C - ldrh r0, [r4, 0x2E] - lsls r0, 24 - lsrs r7, r0, 24 - ldrh r0, [r4, 0x32] - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - ldrh r5, [r4, 0x34] - ldrh r0, [r4, 0x36] - lsls r0, 16 - orrs r5, r0 - adds r0, r4, 0 - adds r0, 0x43 - ldrb r0, [r0] - cmp r0, 0 - beq _0807680E - subs r0, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - b _08076810 -_0807680E: - movs r6, 0 -_08076810: - adds r0, r4, 0 - movs r1, 0x1 - bl StartSpriteAnim - ldrh r0, [r4, 0x20] - lsls r0, 24 - lsrs r0, 24 - ldrh r1, [r4, 0x22] - subs r1, 0x5 - lsls r1, 24 - lsrs r1, 24 - ldrb r2, [r4, 0x5] - lsls r2, 28 - lsrs r2, 30 - adds r3, r6, 0 - bl sub_80763F8 - movs r0, 0x1 - mov r1, r8 - adds r2, r5, 0 - bl sub_8076420 - lsls r0, 24 - lsrs r0, 24 - movs r5, 0 - strh r0, [r4, 0x30] - ldr r0, =sub_807687C - str r0, [r4, 0x1C] - lsls r4, r7, 4 - adds r4, r7 - lsls r4, 2 - ldr r0, =gSprites - adds r4, r0 - adds r0, r4, 0 - movs r1, 0x2 - bl StartSpriteAffineAnim - adds r0, r4, 0 - bl AnimateSprite - strh r5, [r4, 0x30] - b _08076870 - .pool -_0807686C: - subs r0, r1, 0x1 - strh r0, [r4, 0x30] -_08076870: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80767D4 - - thumb_func_start sub_807687C -sub_807687C: @ 807687C - push {r4,r5,lr} - adds r5, r0, 0 - ldrh r0, [r5, 0x38] - adds r0, 0x1 - strh r0, [r5, 0x38] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0xB - bne _08076894 - movs r0, 0x3C - bl PlaySE -_08076894: - ldrh r1, [r5, 0x2E] - lsls r1, 24 - lsrs r1, 24 - ldr r2, =gSprites - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r4, r0, r2 - adds r0, r4, 0 - adds r0, 0x3F - ldrb r0, [r0] - lsls r0, 26 - cmp r0, 0 - bge _080768D8 - adds r0, r5, 0 - movs r1, 0x2 - bl StartSpriteAnim - adds r2, r4, 0 - adds r2, 0x3E - ldrb r0, [r2] - movs r1, 0x4 - orrs r0, r1 - strb r0, [r2] - movs r0, 0 - strh r0, [r5, 0x38] - ldr r0, =sub_80768F0 - str r0, [r5, 0x1C] - b _080768E8 - .pool -_080768D8: - ldrh r0, [r4, 0x30] - adds r0, 0x60 - strh r0, [r4, 0x30] - movs r1, 0x30 - ldrsh r0, [r4, r1] - negs r0, r0 - asrs r0, 8 - strh r0, [r4, 0x26] -_080768E8: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_807687C - - thumb_func_start sub_80768F0 -sub_80768F0: @ 80768F0 - push {lr} - adds r2, r0, 0 - adds r0, 0x3F - ldrb r1, [r0] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _08076904 - ldr r0, =SpriteCallbackDummy - str r0, [r2, 0x1C] -_08076904: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80768F0 - - thumb_func_start obj_delete_and_free_associated_resources_ -obj_delete_and_free_associated_resources_: @ 807690C - push {lr} - bl DestroySpriteAndFreeResources - pop {r0} - bx r0 - thumb_func_end obj_delete_and_free_associated_resources_ - - thumb_func_start sub_8076918 -sub_8076918: @ 8076918 - push {r4-r6,lr} - lsls r0, 24 - lsrs r0, 24 - adds r5, r0, 0 - ldr r0, =gHealthBoxesIds - adds r0, r5, r0 - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - ldr r6, =gSprites - adds r4, r0, r6 - movs r1, 0 - movs r0, 0x5 - strh r0, [r4, 0x2E] - strh r1, [r4, 0x30] - movs r0, 0x73 - strh r0, [r4, 0x24] - strh r1, [r4, 0x26] - ldr r0, =sub_80769CC - str r0, [r4, 0x1C] - adds r0, r5, 0 - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - beq _08076966 - ldrh r0, [r4, 0x2E] - negs r0, r0 - strh r0, [r4, 0x2E] - ldrh r0, [r4, 0x30] - negs r0, r0 - strh r0, [r4, 0x30] - ldrh r0, [r4, 0x24] - negs r0, r0 - strh r0, [r4, 0x24] - ldrh r0, [r4, 0x26] - negs r0, r0 - strh r0, [r4, 0x26] -_08076966: - movs r0, 0x38 - ldrsh r1, [r4, r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r1, r6, 0 - adds r1, 0x1C - adds r1, r0, r1 - adds r0, r6 - ldr r1, [r1] - bl _call_via_r1 - adds r0, r5, 0 - bl GetBankIdentity - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bne _08076990 - ldr r0, =sub_80769A8 - str r0, [r4, 0x1C] -_08076990: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8076918 - - thumb_func_start sub_80769A8 -sub_80769A8: @ 80769A8 - push {lr} - adds r1, r0, 0 - ldrh r0, [r1, 0x30] - adds r0, 0x1 - strh r0, [r1, 0x30] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x14 - bne _080769C2 - movs r0, 0 - strh r0, [r1, 0x30] - ldr r0, =sub_80769CC - str r0, [r1, 0x1C] -_080769C2: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80769A8 - - thumb_func_start sub_80769CC -sub_80769CC: @ 80769CC - push {lr} - adds r2, r0, 0 - ldrh r0, [r2, 0x24] - ldrh r1, [r2, 0x2E] - subs r0, r1 - strh r0, [r2, 0x24] - ldrh r0, [r2, 0x26] - ldrh r1, [r2, 0x30] - subs r0, r1 - strh r0, [r2, 0x26] - ldr r0, [r2, 0x24] - cmp r0, 0 - bne _080769EA - ldr r0, =SpriteCallbackDummy - str r0, [r2, 0x1C] -_080769EA: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80769CC - - thumb_func_start DoHitAnimHealthboxEffect -DoHitAnimHealthboxEffect: @ 80769F4 - push {r4,r5,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - ldr r5, =oamc_804BEB4 - adds r0, r5, 0 - bl CreateInvisibleSpriteWithCallback - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gSprites - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - adds r3, r1, r2 - movs r0, 0x1 - strh r0, [r3, 0x2E] - ldr r0, =gHealthBoxesIds - adds r4, r0 - ldrb r0, [r4] - strh r0, [r3, 0x30] - adds r2, 0x1C - adds r1, r2 - str r5, [r1] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end DoHitAnimHealthboxEffect - - thumb_func_start oamc_804BEB4 -oamc_804BEB4: @ 8076A38 - push {lr} - adds r3, r0, 0 - ldrh r1, [r3, 0x30] - lsls r1, 24 - lsrs r1, 24 - ldr r2, =gSprites - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r1, r0, r2 - ldrh r0, [r3, 0x2E] - movs r2, 0 - strh r0, [r1, 0x26] - ldrh r0, [r3, 0x2E] - negs r0, r0 - strh r0, [r3, 0x2E] - ldrh r0, [r3, 0x32] - adds r0, 0x1 - strh r0, [r3, 0x32] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x15 - bne _08076A70 - strh r2, [r1, 0x24] - strh r2, [r1, 0x26] - adds r0, r3, 0 - bl DestroySprite -_08076A70: - pop {r0} - bx r0 - .pool - thumb_func_end oamc_804BEB4 - - thumb_func_start LoadBallGfx -LoadBallGfx: @ 8076A78 - push {r4-r6,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r0, =gUnknown_0832C400 - lsls r6, r4, 3 - adds r5, r6, r0 - ldrh r0, [r5, 0x6] - bl GetSpriteTileStartByTag - lsls r0, 16 - ldr r1, =0xffff0000 - cmp r0, r1 - bne _08076AA0 - adds r0, r5, 0 - bl LoadCompressedObjectPicUsingHeap - ldr r0, =gUnknown_0832C460 - adds r0, r6, r0 - bl LoadCompressedObjectPaletteUsingHeap -_08076AA0: - cmp r4, 0x6 - beq _08076ACC - cmp r4, 0x6 - blt _08076AB0 - cmp r4, 0xB - bgt _08076AB0 - cmp r4, 0xA - bge _08076ACC -_08076AB0: - ldr r1, =gUnknown_0832C400 - lsls r0, r4, 3 - adds r0, r1 - ldrh r0, [r0, 0x6] - bl GetSpriteTileStartByTag - adds r1, r0, 0 - lsls r1, 16 - ldr r0, =gUnknown_08C02300 - lsrs r1, 11 - ldr r2, =0x06010100 - adds r1, r2 - bl LZDecompressVram -_08076ACC: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end LoadBallGfx - - thumb_func_start FreeBallGfx -FreeBallGfx: @ 8076AE8 - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - ldr r0, =gUnknown_0832C400 - lsrs r4, 21 - adds r0, r4, r0 - ldrh r0, [r0, 0x6] - bl FreeSpriteTilesByTag - ldr r0, =gUnknown_0832C460 - adds r4, r0 - ldrh r0, [r4, 0x4] - bl FreeSpritePaletteByTag - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end FreeBallGfx - - thumb_func_start GetBankPokeballItemId -GetBankPokeballItemId: @ 8076B14 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - beq _08076B40 - ldr r1, =gBattlePartyID - lsls r0, r4, 1 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gEnemyParty - b _08076B4E - .pool -_08076B40: - ldr r1, =gBattlePartyID - lsls r0, r4, 1 - adds r0, r1 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty -_08076B4E: - adds r0, r1 - movs r1, 0x26 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end GetBankPokeballItemId - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/trade.s b/asm/trade.s index 74e907aee..f850cc5b4 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -10445,7 +10445,7 @@ _0807CD1C: str r2, [sp, 0x10] movs r2, 0x78 movs r3, 0x54 - bl sub_8076438 + bl CreatePokeballSpriteToReleaseMon ldr r0, [r7] adds r0, 0xD3 ldrb r1, [r0] @@ -12550,7 +12550,7 @@ _0807E168: str r2, [sp, 0x10] movs r2, 0x78 movs r3, 0x54 - bl sub_8076438 + bl CreatePokeballSpriteToReleaseMon ldr r0, [r7] adds r0, 0xD3 ldrb r1, [r0] diff --git a/data/graphics.s b/data/graphics.s index 72daf144f..05e804578 100644 --- a/data/graphics.s +++ b/data/graphics.s @@ -21,7 +21,7 @@ gUnknown_08C01644:: @ 8C01644 gUnknown_08C01724:: @ 8C01724 .incbin "baserom.gba", 0xc01724, 0xBDC -gUnknown_08C02300:: @ 8C02300 +gOpenPokeballGfx:: @ 8C02300 .incbin "baserom.gba", 0xc02300, 0x7c gUnknown_08C0237C:: @ 8C0237C diff --git a/data/pokeball.s b/data/pokeball.s index 4decaa844..16c77a362 100644 --- a/data/pokeball.s +++ b/data/pokeball.s @@ -4,10 +4,10 @@ .section .rodata .align 2, 0 -gUnknown_0832C400:: @ 832C400 +sBallSpriteSheets:: @ 832C400 .incbin "baserom.gba", 0x32c400, 0x60 -gUnknown_0832C460:: @ 832C460 +sBallSpritePalettes:: @ 832C460 .incbin "baserom.gba", 0x32c460, 0x128 gBallSpriteTemplates:: @ 832C588 diff --git a/include/battle_anim.h b/include/battle_anim.h index 1bb85d023..9fb7ccd53 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -80,6 +80,7 @@ void HandleIntroSlide(u8 terrainId); // battle_anim_80A5C6C.s void sub_80A6EEC(struct Sprite *sprite); void sub_80A68D4(struct Sprite *sprite); +void sub_80A6F3C(struct Sprite *sprite); void sub_80A8278(void); void sub_80A6B30(struct UnknownAnimStruct2*); void sub_80A6B90(struct UnknownAnimStruct2*, u32 arg1); @@ -112,6 +113,6 @@ void LaunchStatusAnimation(u8 bank, u8 statusAnimId); // battle_anim_8170478.s u8 ItemIdToBallId(u16 itemId); u8 LaunchBallStarsTask(u8 x, u8 y, u8 kindOfStars, u8 arg3, u8 ballId); -u8 LaunchBallFadeMonTask(bool8 unFadeLater, u8 bank, u8 arg2, u8 ballId); +u8 LaunchBallFadeMonTask(bool8 unFadeLater, u8 bank, u32 arg2, u8 ballId); #endif // GUARD_BATTLE_ANIM_H diff --git a/include/pokeball.h b/include/pokeball.h index 863abe5c9..57e305ffd 100644 --- a/include/pokeball.h +++ b/include/pokeball.h @@ -1,7 +1,22 @@ #ifndef GUARD_POKEBALL_H #define GUARD_POKEBALL_H -#define POKEBALL_COUNT 12 +enum +{ + BALL_POKE, + BALL_GREAT, + BALL_SAFARI, + BALL_ULTRA, + BALL_MASTER, + BALL_NET, + BALL_DIVE, + BALL_NEST, + BALL_REPEAT, + BALL_TIMER, + BALL_LUXURY, + BALL_PREMIER, + POKEBALL_COUNT +}; #define POKEBALL_PLAYER_SENDOUT 0xFF #define POKEBALL_OPPONENT_SENDOUT 0xFE diff --git a/ld_script.txt b/ld_script.txt index 42755150d..019a44ebe 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -82,7 +82,6 @@ SECTIONS { src/battle_interface.o(.text); asm/smokescreen.o(.text); src/pokeball.o(.text); - asm/pokeball.o(.text); src/load_save.o(.text); asm/trade.o(.text); src/berry_blender.o(.text); diff --git a/src/pokeball.c b/src/pokeball.c index 93ef60c9f..a9172b7cf 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -1,4 +1,5 @@ #include "global.h" +#include "pokemon.h" #include "sprite.h" #include "pokeball.h" #include "battle.h" @@ -9,14 +10,20 @@ #include "trig.h" #include "main.h" #include "m4a.h" +#include "decompress.h" +#include "species.h" +#include "util.h" extern bool8 gDoingBattleAnim; extern u8 gActiveBank; extern u8 gBankTarget; extern u16 gBattlePartyID[]; extern u8 gBankSpriteIds[]; +extern u8 gHealthBoxesIds[]; extern struct MusicPlayerInfo gMPlay_BGM; +extern const u32 gOpenPokeballGfx[]; + // this file's functions void Task_DoPokeballSendOutAnim(u8 taskId); void SpriteCB_PlayerMonSendOut_1(struct Sprite *sprite); @@ -29,12 +36,23 @@ void sub_80757E4(struct Sprite *sprite); void sub_8075838(struct Sprite *sprite); void sub_8075930(struct Sprite *sprite); void SpriteCB_ReleaseMonFromBall(struct Sprite *sprite); +void SpriteCB_ReleaseMon2FromBall(struct Sprite *sprite); void sub_8075970(struct Sprite *sprite); void HandleBallAnimEnd(struct Sprite *sprite); void sub_8075FB4(struct Sprite *sprite); void sub_80760F8(struct Sprite *sprite); +void sub_8076524(struct Sprite *sprite); +void sub_80765E0(struct Sprite *sprite); +void sub_80767D4(struct Sprite *sprite); +void sub_807687C(struct Sprite *sprite); +void sub_80768F0(struct Sprite *sprite); +void sub_80769A8(struct Sprite *sprite); +void sub_80769CC(struct Sprite *sprite); +void SpriteCB_HitAnimHealthoxEffect(struct Sprite *sprite); u16 GetBankPokeballItemId(u8 bank); +extern const struct CompressedSpriteSheet sBallSpriteSheets[]; +extern const struct CompressedSpritePalette sBallSpritePalettes[]; extern const struct SpriteTemplate gBallSpriteTemplates[]; #define tFrames data[0] @@ -58,12 +76,6 @@ u8 DoPokeballSendOutAnimation(s16 pan, u8 kindOfThrow) return 0; } -#define sData0 data[0] -#define sData1 data[1] -#define sData2 data[2] -#define sData3 data[3] -#define sData4 data[4] -#define sData5 data[5] #define sBank data[6] void Task_DoPokeballSendOutAnim(u8 taskId) @@ -107,7 +119,7 @@ void Task_DoPokeballSendOutAnim(u8 taskId) gSprites[ballSpriteId].pos1.x = GetBankPosition(bank, BANK_X_POS); gSprites[ballSpriteId].pos1.y = GetBankPosition(bank, BANK_Y_POS) + 24; gBankTarget = bank; - gSprites[ballSpriteId].sData0 = 0; + gSprites[ballSpriteId].data[0] = 0; gSprites[ballSpriteId].callback = SpriteCB_OpponentMonSendOut; break; default: @@ -124,10 +136,10 @@ void Task_DoPokeballSendOutAnim(u8 taskId) } // this will perform an unused ball throw animation - gSprites[ballSpriteId].sData0 = 0x22; - gSprites[ballSpriteId].sData2 = GetBankPosition(gBankTarget, BANK_X_POS); - gSprites[ballSpriteId].sData4 = GetBankPosition(gBankTarget, BANK_Y_POS) - 16; - gSprites[ballSpriteId].sData5 = -40; + gSprites[ballSpriteId].data[0] = 0x22; + gSprites[ballSpriteId].data[2] = GetBankPosition(gBankTarget, BANK_X_POS); + gSprites[ballSpriteId].data[4] = GetBankPosition(gBankTarget, BANK_Y_POS) - 16; + gSprites[ballSpriteId].data[5] = -40; sub_80A68D4(&gSprites[ballSpriteId]); gSprites[ballSpriteId].oam.affineParam = taskId; gTasks[taskId].tOpponentBank = gBankTarget; @@ -150,10 +162,10 @@ void SpriteCB_TestBallThrow(struct Sprite *sprite) sprite->pos1.y += sprite->pos2.y; sprite->pos2.x = 0; sprite->pos2.y = 0; - sprite->sData5 = 0; + sprite->data[5] = 0; ballId = ItemIdToBallId(GetBankPokeballItemId(opponentBank)); LaunchBallStarsTask(sprite->pos1.x, sprite->pos1.y - 5, 1, 0x1C, ballId); - sprite->sData0 = LaunchBallFadeMonTask(FALSE, opponentBank, 14, ballId); + sprite->data[0] = LaunchBallFadeMonTask(FALSE, opponentBank, 14, ballId); sprite->sBank = opponentBank; sprite->data[7] = noOfShakes; DestroyTask(taskId); @@ -174,9 +186,9 @@ void sub_80756D4(struct Sprite *sprite) void sub_80756E0(struct Sprite *sprite) { - if (++sprite->sData5 == 10) + if (++sprite->data[5] == 10) { - sprite->sData5 = 0; + sprite->data[5] = 0; sprite->callback = sub_807574C; StartSpriteAffineAnim(&gSprites[gBankSpriteIds[sprite->sBank]], 2); AnimateSprite(&gSprites[gBankSpriteIds[sprite->sBank]]); @@ -189,17 +201,17 @@ void sub_807574C(struct Sprite *sprite) sprite->data[5]++; if (sprite->data[5] == 11) PlaySE(SE_SUIKOMU); - if (gSprites[gBankSpriteIds[sprite->data[6]]].affineAnimEnded) + if (gSprites[gBankSpriteIds[sprite->sBank]].affineAnimEnded) { StartSpriteAnim(sprite, 2); - gSprites[gBankSpriteIds[sprite->data[6]]].invisible = TRUE; + gSprites[gBankSpriteIds[sprite->sBank]].invisible = TRUE; sprite->data[5] = 0; sprite->callback = sub_80757E4; } else { - gSprites[gBankSpriteIds[sprite->data[6]]].data[1] += 0x60; - gSprites[gBankSpriteIds[sprite->data[6]]].pos2.y = -gSprites[gBankSpriteIds[sprite->data[6]]].data[1] >> 8; + gSprites[gBankSpriteIds[sprite->sBank]].data[1] += 0x60; + gSprites[gBankSpriteIds[sprite->sBank]].pos2.y = -gSprites[gBankSpriteIds[sprite->sBank]].data[1] >> 8; } } @@ -464,7 +476,7 @@ void SpriteCB_ReleaseMonFromBall(struct Sprite *sprite) StartSpriteAnim(sprite, 1); ballId = ItemIdToBallId(GetBankPokeballItemId(bank)); LaunchBallStarsTask(sprite->pos1.x, sprite->pos1.y - 5, 1, 0x1C, ballId); - sprite->sData0 = LaunchBallFadeMonTask(1, sprite->sBank, 14, ballId); + sprite->data[0] = LaunchBallFadeMonTask(1, sprite->sBank, 14, ballId); sprite->callback = HandleBallAnimEnd; if (gMain.inBattle) @@ -628,10 +640,375 @@ void SpriteCB_PlayerMonSendOut_1(struct Sprite *sprite) sprite->callback = SpriteCB_PlayerMonSendOut_2; } -#undef sData0 -#undef sData1 -#undef sData2 -#undef sData3 -#undef sData4 -#undef sData5 +#define HIBYTE(x) (((x) >> 8) & 0xFF) + +void SpriteCB_PlayerMonSendOut_2(struct Sprite *sprite) +{ + u32 r6; + u32 r7; + + if (HIBYTE(sprite->data[7]) >= 35 && HIBYTE(sprite->data[7]) < 80) + { + s16 r4; + + if ((sprite->oam.affineParam & 0xFF00) == 0) + { + r6 = sprite->data[1] & 1; + r7 = sprite->data[2] & 1; + sprite->data[1] = ((sprite->data[1] / 3) & ~1) | r6; + sprite->data[2] = ((sprite->data[2] / 3) & ~1) | r7; + StartSpriteAffineAnim(sprite, 4); + } + r4 = sprite->data[0]; + sub_80A6F3C(sprite); + sprite->data[7] += sprite->sBank / 3; + sprite->pos2.y += Sin(HIBYTE(sprite->data[7]), sprite->data[5]); + sprite->oam.affineParam += 0x100; + if ((sprite->oam.affineParam >> 8) % 3 != 0) + sprite->data[0] = r4; + else + sprite->data[0] = r4 - 1; + if (HIBYTE(sprite->data[7]) >= 80) + { + r6 = sprite->data[1] & 1; + r7 = sprite->data[2] & 1; + sprite->data[1] = ((sprite->data[1] * 3) & ~1) | r6; + sprite->data[2] = ((sprite->data[2] * 3) & ~1) | r7; + } + } + else + { + if (AnimateBallThrow(sprite)) + { + sprite->pos1.x += sprite->pos2.x; + sprite->pos1.y += sprite->pos2.y; + sprite->pos2.y = 0; + sprite->pos2.x = 0; + sprite->sBank = sprite->oam.affineParam & 0xFF; + sprite->data[0] = 0; + + if (IsDoubleBattle() && gBattleSpritesDataPtr->animationData->field_9_x1 + && sprite->sBank == GetBankByIdentity(IDENTITY_PLAYER_MON2)) + sprite->callback = SpriteCB_ReleaseMon2FromBall; + else + sprite->callback = SpriteCB_ReleaseMonFromBall; + + StartSpriteAffineAnim(sprite, 0); + } + } +} + +void SpriteCB_ReleaseMon2FromBall(struct Sprite *sprite) +{ + if (sprite->data[0]++ > 24) + { + sprite->data[0] = 0; + sprite->callback = SpriteCB_ReleaseMonFromBall; + } +} + +void SpriteCB_OpponentMonSendOut(struct Sprite *sprite) +{ + sprite->data[0]++; + if (sprite->data[0] > 15) + { + sprite->data[0] = 0; + if (IsDoubleBattle() && gBattleSpritesDataPtr->animationData->field_9_x1 + && sprite->sBank == GetBankByIdentity(IDENTITY_OPPONENT_MON2)) + sprite->callback = SpriteCB_ReleaseMon2FromBall; + else + sprite->callback = SpriteCB_ReleaseMonFromBall; + } +} + #undef sBank + +u8 LaunchBallStarsTaskForPokeball(u8 x, u8 y, u8 kindOfStars, u8 d) +{ + return LaunchBallStarsTask(x, y, kindOfStars, d, 0); +} + +u8 LaunchBallFadeMonTaskForPokeball(bool8 unFadeLater, u8 bank, u32 arg2) +{ + return LaunchBallFadeMonTask(unFadeLater, bank, arg2, 0); +} + +void CreatePokeballSpriteToReleaseMon(u8 monSpriteId, u8 bank, u8 x, u8 y, u8 oamPriority, u8 subpriortiy, u8 g, u32 h, u16 species) +{ + u8 spriteId; + + LoadCompressedObjectPicUsingHeap(&sBallSpriteSheets[0]); + LoadCompressedObjectPaletteUsingHeap(&sBallSpritePalettes[0]); + spriteId = CreateSprite(&gBallSpriteTemplates[0], x, y, subpriortiy); + + gSprites[spriteId].data[0] = monSpriteId; + gSprites[spriteId].data[5] = gSprites[monSpriteId].pos1.x; + gSprites[spriteId].data[6] = gSprites[monSpriteId].pos1.y; + + gSprites[monSpriteId].pos1.x = x; + gSprites[monSpriteId].pos1.y = y; + gSprites[monSpriteId].data[7] = species; + + gSprites[spriteId].data[1] = g; + gSprites[spriteId].data[2] = bank; + gSprites[spriteId].data[3] = h; + gSprites[spriteId].data[4] = h >> 0x10; + gSprites[spriteId].oam.priority = oamPriority; + gSprites[spriteId].callback = sub_8076524; + + gSprites[monSpriteId].invisible = TRUE; +} + +void sub_8076524(struct Sprite *sprite) +{ + if (sprite->data[1] == 0) + { + u8 r5; + u8 r7 = sprite->data[0]; + u8 bank = sprite->data[2]; + u32 r4 = (u16)sprite->data[3] | ((u16)sprite->data[4] << 16); + + if (sprite->subpriority != 0) + r5 = sprite->subpriority - 1; + else + r5 = 0; + + StartSpriteAnim(sprite, 1); + LaunchBallStarsTaskForPokeball(sprite->pos1.x, sprite->pos1.y - 5, sprite->oam.priority, r5); + sprite->data[1] = LaunchBallFadeMonTaskForPokeball(1, bank, r4); + sprite->callback = sub_80765E0; + gSprites[r7].invisible = FALSE; + StartSpriteAffineAnim(&gSprites[r7], 1); + AnimateSprite(&gSprites[r7]); + gSprites[r7].data[1] = 0x1000; + sprite->data[7] = 0; + } + else + { + sprite->data[1]--; + } +} + +void sub_80765E0(struct Sprite *sprite) +{ + bool8 r12 = FALSE; + bool8 r6 = FALSE; + u8 monSpriteId = sprite->data[0]; + u16 var1; + u16 var2; + + if (sprite->animEnded) + sprite->invisible = TRUE; + if (gSprites[monSpriteId].affineAnimEnded) + { + StartSpriteAffineAnim(&gSprites[monSpriteId], 0); + r12 = TRUE; + } + var1 = (sprite->data[5] - sprite->pos1.x) * sprite->data[7] / 128 + sprite->pos1.x; + var2 = (sprite->data[6] - sprite->pos1.y) * sprite->data[7] / 128 + sprite->pos1.y; + gSprites[monSpriteId].pos1.x = var1; + gSprites[monSpriteId].pos1.y = var2; + if (sprite->data[7] < 128) + { + s16 sine = -(gSineTable[(u8)sprite->data[7]] / 8); + + sprite->data[7] += 4; + gSprites[monSpriteId].pos2.x = sine; + gSprites[monSpriteId].pos2.y = sine; + } + else + { + gSprites[monSpriteId].pos1.x = sprite->data[5]; + gSprites[monSpriteId].pos1.y = sprite->data[6]; + gSprites[monSpriteId].pos2.x = 0; + gSprites[monSpriteId].pos2.y = 0; + r6 = TRUE; + } + if (sprite->animEnded && r12 && r6) + { + if (gSprites[monSpriteId].data[7] == SPECIES_EGG) + DoMonFrontSpriteAnimation(&gSprites[monSpriteId], gSprites[monSpriteId].data[7], TRUE, 0); + else + DoMonFrontSpriteAnimation(&gSprites[monSpriteId], gSprites[monSpriteId].data[7], FALSE, 0); + + DestroySpriteAndFreeResources(sprite); + } +} + +u8 sub_807671C(u8 a, u8 b, u8 x, u8 y, u8 oamPriority, u8 subPriority, u8 g, u32 h) +{ + u8 spriteId; + + LoadCompressedObjectPicUsingHeap(&sBallSpriteSheets[0]); + LoadCompressedObjectPaletteUsingHeap(&sBallSpritePalettes[0]); + spriteId = CreateSprite(&gBallSpriteTemplates[0], x, y, subPriority); + gSprites[spriteId].data[0] = a; + gSprites[spriteId].data[1] = g; + gSprites[spriteId].data[2] = b; + gSprites[spriteId].data[3] = h; + gSprites[spriteId].data[4] = h >> 16; + gSprites[spriteId].oam.priority = oamPriority; + gSprites[spriteId].callback = sub_80767D4; + return spriteId; +} + +void sub_80767D4(struct Sprite *sprite) +{ + if (sprite->data[1] == 0) + { + u8 r6; + u8 r7 = sprite->data[0]; + u8 r8 = sprite->data[2]; + u32 r5 = (u16)sprite->data[3] | ((u16)sprite->data[4] << 16); + + if (sprite->subpriority != 0) + r6 = sprite->subpriority - 1; + else + r6 = 0; + + StartSpriteAnim(sprite, 1); + LaunchBallStarsTaskForPokeball(sprite->pos1.x, sprite->pos1.y - 5, sprite->oam.priority, r6); + sprite->data[1] = LaunchBallFadeMonTaskForPokeball(1, r8, r5); + sprite->callback = sub_807687C; + StartSpriteAffineAnim(&gSprites[r7], 2); + AnimateSprite(&gSprites[r7]); + gSprites[r7].data[1] = 0; + } + else + { + sprite->data[1]--; + } +} + +void sub_807687C(struct Sprite *sprite) +{ + u8 r1; + + sprite->data[5]++; + if (sprite->data[5] == 11) + PlaySE(SE_SUIKOMU); + r1 = sprite->data[0]; + if (gSprites[r1].affineAnimEnded) + { + StartSpriteAnim(sprite, 2); + gSprites[r1].invisible = TRUE; + sprite->data[5] = 0; + sprite->callback = sub_80768F0; + } + else + { + gSprites[r1].data[1] += 96; + gSprites[r1].pos2.y = -gSprites[r1].data[1] >> 8; + } +} + +void sub_80768F0(struct Sprite *sprite) +{ + if (sprite->animEnded) + sprite->callback = SpriteCallbackDummy; +} + +static void DestroySpriteAndFreeResources_(struct Sprite *sprite) +{ + DestroySpriteAndFreeResources(sprite); +} + +void sub_8076918(u8 bank) +{ + struct Sprite *healthboxSprite = &gSprites[gHealthBoxesIds[bank]]; + + healthboxSprite->data[0] = 5; + healthboxSprite->data[1] = 0; + healthboxSprite->pos2.x = 0x73; + healthboxSprite->pos2.y = 0; + healthboxSprite->callback = sub_80769CC; + if (GetBankSide(bank) != SIDE_PLAYER) + { + healthboxSprite->data[0] = -healthboxSprite->data[0]; + healthboxSprite->data[1] = -healthboxSprite->data[1]; + healthboxSprite->pos2.x = -healthboxSprite->pos2.x; + healthboxSprite->pos2.y = -healthboxSprite->pos2.y; + } + gSprites[healthboxSprite->data[5]].callback(&gSprites[healthboxSprite->data[5]]); + if (GetBankIdentity(bank) == IDENTITY_PLAYER_MON2) + healthboxSprite->callback = sub_80769A8; +} + +void sub_80769A8(struct Sprite *sprite) +{ + sprite->data[1]++; + if (sprite->data[1] == 20) + { + sprite->data[1] = 0; + sprite->callback = sub_80769CC; + } +} + +void sub_80769CC(struct Sprite *sprite) +{ + sprite->pos2.x -= sprite->data[0]; + sprite->pos2.y -= sprite->data[1]; + if (sprite->pos2.x == 0 && sprite->pos2.y == 0) + sprite->callback = SpriteCallbackDummy; +} + +void DoHitAnimHealthboxEffect(u8 bank) +{ + u8 spriteId; + + spriteId = CreateInvisibleSpriteWithCallback(SpriteCB_HitAnimHealthoxEffect); + gSprites[spriteId].data[0] = 1; + gSprites[spriteId].data[1] = gHealthBoxesIds[bank]; + gSprites[spriteId].callback = SpriteCB_HitAnimHealthoxEffect; +} + +void SpriteCB_HitAnimHealthoxEffect(struct Sprite *sprite) +{ + u8 r1 = sprite->data[1]; + + gSprites[r1].pos2.y = sprite->data[0]; + sprite->data[0] = -sprite->data[0]; + sprite->data[2]++; + if (sprite->data[2] == 21) + { + gSprites[r1].pos2.x = 0; + gSprites[r1].pos2.y = 0; + DestroySprite(sprite); + } +} + +void LoadBallGfx(u8 ballId) +{ + u16 var; + + if (GetSpriteTileStartByTag(sBallSpriteSheets[ballId].tag) == 0xFFFF) + { + LoadCompressedObjectPicUsingHeap(&sBallSpriteSheets[ballId]); + LoadCompressedObjectPaletteUsingHeap(&sBallSpritePalettes[ballId]); + } + switch (ballId) + { + case BALL_DIVE: + case BALL_LUXURY: + case BALL_PREMIER: + break; + default: + var = GetSpriteTileStartByTag(sBallSpriteSheets[ballId].tag); + LZDecompressVram(gOpenPokeballGfx, (void *)(VRAM + 0x10100 + var * 32)); + break; + } +} + +void FreeBallGfx(u8 ballId) +{ + FreeSpriteTilesByTag(sBallSpriteSheets[ballId].tag); + FreeSpritePaletteByTag(sBallSpritePalettes[ballId].tag); +} + +u16 GetBankPokeballItemId(u8 bank) +{ + if (GetBankSide(bank) == SIDE_PLAYER) + return GetMonData(&gPlayerParty[gBattlePartyID[bank]], MON_DATA_POKEBALL); + else + return GetMonData(&gEnemyParty[gBattlePartyID[bank]], MON_DATA_POKEBALL); +}