diff --git a/asm/ghost.s b/asm/ghost.s index 5a0991468..4afba4c9e 100644 --- a/asm/ghost.s +++ b/asm/ghost.s @@ -5,809 +5,6 @@ .text - thumb_func_start sub_811160C -sub_811160C: @ 811160C - push {r4,r5,lr} - adds r4, r0, 0 - movs r1, 0x1 - bl InitAnimSpritePos - ldr r0, =gBattleAnimArgs - ldrh r0, [r0, 0x4] - strh r0, [r4, 0x2E] - ldrh r0, [r4, 0x20] - strh r0, [r4, 0x30] - ldr r5, =gBattleAnimTarget - ldrb r0, [r5] - movs r1, 0x2 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r4, 0x32] - ldrh r0, [r4, 0x22] - strh r0, [r4, 0x34] - ldrb r0, [r5] - movs r1, 0x3 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r4, 0x36] - adds r0, r4, 0 - bl sub_80A6FD4 - ldr r0, =sub_8111674 - str r0, [r4, 0x1C] - movs r0, 0x10 - strh r0, [r4, 0x3A] - movs r1, 0xFD - lsls r1, 6 - movs r0, 0x50 - bl SetGpuReg - ldrh r1, [r4, 0x3A] - movs r0, 0x52 - bl SetGpuReg - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_811160C - - thumb_func_start sub_8111674 -sub_8111674: @ 8111674 - push {r4,lr} - adds r4, r0, 0 - bl sub_8111764 - adds r0, r4, 0 - bl TranslateAnimLinear - lsls r0, 24 - cmp r0, 0 - beq _08111694 - ldr r0, =sub_81116E8 - str r0, [r4, 0x1C] - b _081116DE - .pool -_08111694: - movs r1, 0x38 - ldrsh r0, [r4, r1] - movs r1, 0xA - bl Sin - ldrh r1, [r4, 0x24] - adds r0, r1 - strh r0, [r4, 0x24] - movs r1, 0x38 - ldrsh r0, [r4, r1] - movs r1, 0xF - bl Cos - ldrh r1, [r4, 0x26] - adds r0, r1 - strh r0, [r4, 0x26] - ldrh r2, [r4, 0x38] - adds r0, r2, 0x5 - movs r1, 0xFF - ands r0, r1 - strh r0, [r4, 0x38] - ldrh r0, [r4, 0x38] - lsls r2, 16 - asrs r2, 16 - cmp r2, 0 - beq _081116CC - cmp r2, 0xC4 - ble _081116DE -_081116CC: - lsls r0, 16 - cmp r0, 0 - ble _081116DE - ldr r0, =gUnknown_02038440 - movs r1, 0 - ldrsb r1, [r0, r1] - movs r0, 0xC4 - bl PlaySE12WithPanning -_081116DE: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8111674 - - thumb_func_start sub_81116E8 -sub_81116E8: @ 81116E8 - push {r4,lr} - adds r4, r0, 0 - movs r0, 0x1 - strh r0, [r4, 0x2E] - adds r0, r4, 0 - bl TranslateAnimLinear - movs r1, 0x38 - ldrsh r0, [r4, r1] - movs r1, 0xA - bl Sin - ldrh r1, [r4, 0x24] - adds r0, r1 - strh r0, [r4, 0x24] - movs r1, 0x38 - ldrsh r0, [r4, r1] - movs r1, 0xF - bl Cos - ldrh r1, [r4, 0x26] - adds r0, r1 - strh r0, [r4, 0x26] - ldrh r2, [r4, 0x38] - adds r0, r2, 0x5 - movs r1, 0xFF - ands r0, r1 - strh r0, [r4, 0x38] - ldrh r0, [r4, 0x38] - lsls r2, 16 - asrs r2, 16 - cmp r2, 0 - beq _0811172E - cmp r2, 0xC4 - ble _0811173A -_0811172E: - lsls r0, 16 - cmp r0, 0 - ble _0811173A - movs r0, 0xC4 - bl PlaySE -_0811173A: - movs r1, 0x3A - ldrsh r0, [r4, r1] - cmp r0, 0 - bne _08111758 - adds r2, r4, 0 - adds r2, 0x3E - ldrb r0, [r2] - movs r1, 0x4 - orrs r0, r1 - strb r0, [r2] - ldr r0, =sub_80A67F4 - str r0, [r4, 0x1C] - b _0811175E - .pool -_08111758: - adds r0, r4, 0 - bl sub_8111764 -_0811175E: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_81116E8 - - thumb_func_start sub_8111764 -sub_8111764: @ 8111764 - push {r4,lr} - adds r4, r0, 0 - ldrh r2, [r4, 0x3A] - movs r1, 0x3A - ldrsh r0, [r4, r1] - cmp r0, 0xFF - ble _08111788 - adds r0, r2, 0x1 - strh r0, [r4, 0x3A] - lsls r0, 16 - ldr r1, =0x010d0000 - cmp r0, r1 - bne _081117EE - movs r0, 0 - b _081117EC - .pool -_08111788: - ldrh r1, [r4, 0x3C] - adds r3, r1, 0x1 - strh r3, [r4, 0x3C] - movs r0, 0xFF - ands r0, r1 - cmp r0, 0 - bne _081117EE - ldr r1, =0xffffff00 - ands r1, r3 - strh r1, [r4, 0x3C] - movs r0, 0x80 - lsls r0, 1 - ands r0, r1 - cmp r0, 0 - beq _081117B0 - adds r0, r2, 0x1 - b _081117B2 - .pool -_081117B0: - subs r0, r2, 0x1 -_081117B2: - strh r0, [r4, 0x3A] - ldrh r0, [r4, 0x3A] - movs r1, 0x10 - subs r1, r0 - lsls r1, 8 - orrs r1, r0 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x52 - bl SetGpuReg - movs r2, 0x3A - ldrsh r0, [r4, r2] - cmp r0, 0 - beq _081117D4 - cmp r0, 0x10 - bne _081117E0 -_081117D4: - ldrh r0, [r4, 0x3C] - movs r2, 0x80 - lsls r2, 1 - adds r1, r2, 0 - eors r0, r1 - strh r0, [r4, 0x3C] -_081117E0: - movs r1, 0x3A - ldrsh r0, [r4, r1] - cmp r0, 0 - bne _081117EE - movs r0, 0x80 - lsls r0, 1 -_081117EC: - strh r0, [r4, 0x3A] -_081117EE: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_8111764 - - thumb_func_start sub_81117F4 -sub_81117F4: @ 81117F4 - push {r4,lr} - adds r4, r0, 0 - movs r1, 0x1 - bl sub_80A6980 - ldr r1, =sub_8111814 - str r1, [r4, 0x1C] - adds r0, r4, 0 - bl _call_via_r1 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81117F4 - - thumb_func_start sub_8111814 -sub_8111814: @ 8111814 - push {r4,lr} - adds r4, r0, 0 - movs r1, 0x2E - ldrsh r0, [r4, r1] - movs r1, 0x20 - bl Sin - strh r0, [r4, 0x24] - movs r1, 0x2E - ldrsh r0, [r4, r1] - movs r1, 0x8 - bl Cos - strh r0, [r4, 0x26] - ldrh r0, [r4, 0x2E] - subs r0, 0x41 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x82 - bhi _08111848 - ldrb r0, [r4, 0x5] - movs r1, 0xD - negs r1, r1 - ands r1, r0 - movs r0, 0x8 - b _08111852 -_08111848: - ldrb r0, [r4, 0x5] - movs r1, 0xD - negs r1, r1 - ands r1, r0 - movs r0, 0x4 -_08111852: - orrs r1, r0 - strb r1, [r4, 0x5] - ldrh r0, [r4, 0x2E] - adds r0, 0x13 - movs r1, 0xFF - ands r0, r1 - strh r0, [r4, 0x2E] - ldrh r0, [r4, 0x32] - adds r0, 0x50 - strh r0, [r4, 0x32] - lsls r0, 16 - asrs r0, 24 - ldrh r1, [r4, 0x26] - adds r0, r1 - strh r0, [r4, 0x26] - ldrh r0, [r4, 0x3C] - adds r0, 0x1 - strh r0, [r4, 0x3C] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x3D - bne _08111884 - adds r0, r4, 0 - bl DestroyAnimSprite -_08111884: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_8111814 - - thumb_func_start sub_811188C -sub_811188C: @ 811188C - push {r4,r5,lr} - adds r5, r0, 0 - lsls r5, 24 - lsrs r5, 24 - movs r1, 0xFD - lsls r1, 6 - movs r0, 0x50 - bl SetGpuReg - movs r1, 0x80 - lsls r1, 5 - movs r0, 0x52 - bl SetGpuReg - movs r0, 0 - bl GetAnimBattlerSpriteId - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r4, 0 - movs r1, 0x1 - bl sub_80A7270 - adds r0, r4, 0 - movs r1, 0x80 - movs r2, 0x80 - movs r3, 0 - bl obj_id_set_rotscale - ldr r1, =gSprites - lsls r0, r4, 4 - adds r0, r4 - lsls r0, 2 - adds r0, r1 - adds r0, 0x3E - ldrb r2, [r0] - movs r1, 0x5 - negs r1, r1 - ands r1, r2 - strb r1, [r0] - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r0, r1 - movs r2, 0 - movs r1, 0x80 - strh r1, [r0, 0x8] - ldr r1, =gBattleAnimArgs - ldrh r1, [r1] - strh r1, [r0, 0xA] - strh r2, [r0, 0xC] - movs r1, 0x10 - strh r1, [r0, 0xE] - ldr r1, =sub_8111914 - str r1, [r0] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_811188C - - thumb_func_start sub_8111914 -sub_8111914: @ 8111914 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r4, r1, r2 - ldrh r0, [r4, 0x1C] - adds r0, 0x1 - strh r0, [r4, 0x1C] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x3 - bne _0811195C - movs r0, 0 - strh r0, [r4, 0x1C] - ldrh r1, [r4, 0xC] - adds r1, 0x1 - strh r1, [r4, 0xC] - ldrh r0, [r4, 0xE] - subs r0, 0x1 - strh r0, [r4, 0xE] - lsls r0, 8 - orrs r1, r0 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x52 - bl SetGpuReg - movs r1, 0xC - ldrsh r0, [r4, r1] - cmp r0, 0x9 - bne _0811195C - ldr r0, =sub_811196C - str r0, [r4] -_0811195C: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8111914 - - thumb_func_start sub_811196C -sub_811196C: @ 811196C - push {r4,r5,lr} - lsls r0, 24 - lsrs r0, 24 - adds r5, r0, 0 - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r4, r0, r1 - ldrh r1, [r4, 0xA] - movs r2, 0xA - ldrsh r0, [r4, r2] - cmp r0, 0 - ble _08111994 - subs r0, r1, 0x1 - strh r0, [r4, 0xA] - b _081119D8 - .pool -_08111994: - movs r0, 0 - bl GetAnimBattlerSpriteId - lsls r0, 24 - lsrs r1, r0, 24 - ldrh r0, [r4, 0x8] - adds r0, 0x8 - strh r0, [r4, 0x8] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0xFF - bgt _081119BC - movs r0, 0x8 - ldrsh r2, [r4, r0] - adds r0, r1, 0 - adds r1, r2, 0 - movs r3, 0 - bl obj_id_set_rotscale - b _081119D8 -_081119BC: - adds r0, r1, 0 - bl sub_80A7344 - adds r0, r5, 0 - bl DestroyAnimVisualTask - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg -_081119D8: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_811196C - - thumb_func_start sub_81119E0 -sub_81119E0: @ 81119E0 - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - sub sp, 0x4 - adds r4, r0, 0 - ldrh r5, [r4, 0x20] - ldrh r6, [r4, 0x22] - ldr r0, =gBattleAnimAttacker - mov r8, r0 - ldrb r0, [r0] - movs r1, 0x2 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - movs r1, 0 - mov r9, r1 - strh r0, [r4, 0x20] - mov r1, r8 - ldrb r0, [r1] - movs r1, 0x3 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r4, 0x22] - mov r1, r9 - strh r1, [r4, 0x2E] - ldr r2, =gBattleAnimArgs - ldrh r1, [r2] - strh r1, [r4, 0x30] - ldrh r1, [r2, 0x2] - strh r1, [r4, 0x32] - ldrh r1, [r2, 0x4] - strh r1, [r4, 0x34] - ldrh r1, [r4, 0x20] - lsls r1, 4 - strh r1, [r4, 0x36] - lsls r0, 4 - strh r0, [r4, 0x38] - lsls r5, 16 - asrs r5, 16 - movs r1, 0x20 - ldrsh r0, [r4, r1] - subs r5, r0 - lsls r5, 4 - movs r0, 0 - ldrsh r1, [r2, r0] - lsls r1, 1 - adds r0, r5, 0 - str r2, [sp] - bl __divsi3 - strh r0, [r4, 0x3A] - lsls r6, 16 - asrs r6, 16 - movs r1, 0x22 - ldrsh r0, [r4, r1] - subs r6, r0 - lsls r6, 4 - ldr r2, [sp] - movs r0, 0 - ldrsh r1, [r2, r0] - lsls r1, 1 - adds r0, r6, 0 - bl __divsi3 - strh r0, [r4, 0x3C] - ldr r0, =sub_8111A88 - str r0, [r4, 0x1C] - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81119E0 - - thumb_func_start sub_8111A88 -sub_8111A88: @ 8111A88 - push {r4,r5,lr} - adds r5, r0, 0 - movs r1, 0x2E - ldrsh r0, [r5, r1] - cmp r0, 0x1 - beq _08111AD2 - cmp r0, 0x1 - bgt _08111A9E - cmp r0, 0 - beq _08111AA8 - b _08111B96 -_08111A9E: - cmp r0, 0x2 - beq _08111B3C - cmp r0, 0x3 - beq _08111B90 - b _08111B96 -_08111AA8: - ldrh r0, [r5, 0x3A] - ldrh r2, [r5, 0x36] - adds r0, r2 - strh r0, [r5, 0x36] - ldrh r1, [r5, 0x3C] - ldrh r2, [r5, 0x38] - adds r1, r2 - strh r1, [r5, 0x38] - lsls r0, 16 - asrs r0, 20 - strh r0, [r5, 0x20] - lsls r1, 16 - asrs r1, 20 - strh r1, [r5, 0x22] - ldrh r0, [r5, 0x30] - subs r0, 0x1 - strh r0, [r5, 0x30] - lsls r0, 16 - cmp r0, 0 - bgt _08111B96 - b _08111B82 -_08111AD2: - ldrh r0, [r5, 0x32] - subs r0, 0x1 - strh r0, [r5, 0x32] - lsls r0, 16 - cmp r0, 0 - bgt _08111B96 - ldr r4, =gBattleAnimTarget - ldrb r0, [r4] - movs r1, 0x2 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x30] - ldrb r0, [r4] - movs r1, 0x3 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x32] - ldrh r0, [r5, 0x20] - lsls r0, 4 - strh r0, [r5, 0x36] - ldrh r0, [r5, 0x22] - lsls r0, 4 - strh r0, [r5, 0x38] - movs r1, 0x30 - ldrsh r0, [r5, r1] - movs r2, 0x20 - ldrsh r1, [r5, r2] - subs r0, r1 - lsls r0, 4 - movs r2, 0x34 - ldrsh r1, [r5, r2] - bl __divsi3 - strh r0, [r5, 0x3A] - movs r1, 0x32 - ldrsh r0, [r5, r1] - movs r2, 0x22 - ldrsh r1, [r5, r2] - subs r0, r1 - lsls r0, 4 - movs r2, 0x34 - ldrsh r1, [r5, r2] - bl __divsi3 - strh r0, [r5, 0x3C] - b _08111B82 - .pool -_08111B3C: - ldrh r0, [r5, 0x3A] - ldrh r1, [r5, 0x36] - adds r0, r1 - strh r0, [r5, 0x36] - ldrh r1, [r5, 0x3C] - ldrh r2, [r5, 0x38] - adds r1, r2 - strh r1, [r5, 0x38] - lsls r0, 16 - asrs r0, 20 - strh r0, [r5, 0x20] - lsls r1, 16 - asrs r1, 20 - strh r1, [r5, 0x22] - ldrh r0, [r5, 0x34] - subs r0, 0x1 - strh r0, [r5, 0x34] - lsls r0, 16 - cmp r0, 0 - bgt _08111B96 - ldr r4, =gBattleAnimTarget - ldrb r0, [r4] - movs r1, 0x2 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x20] - ldrb r0, [r4] - movs r1, 0x3 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x22] -_08111B82: - ldrh r0, [r5, 0x2E] - adds r0, 0x1 - strh r0, [r5, 0x2E] - b _08111B96 - .pool -_08111B90: - adds r0, r5, 0 - bl move_anim_8074EE0 -_08111B96: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_8111A88 - - thumb_func_start sub_8111B9C -sub_8111B9C: @ 8111B9C - push {r4,lr} - adds r4, r0, 0 - movs r1, 0x1 - bl sub_80A6980 - ldr r0, =sub_8111BB4 - str r0, [r4, 0x1C] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8111B9C - - thumb_func_start sub_8111BB4 -sub_8111BB4: @ 8111BB4 - push {r4-r6,lr} - adds r3, r0, 0 - movs r5, 0 - movs r6, 0 - adds r0, 0x3F - ldrb r1, [r0] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _08111C4A - adds r1, r3, 0 - adds r1, 0x3E - ldrb r2, [r1] - movs r0, 0x4 - ands r0, r2 - adds r4, r1, 0 - cmp r0, 0 - bne _08111BDE - movs r0, 0x4 - orrs r0, r2 - strb r0, [r4] -_08111BDE: - movs r1, 0x2E - ldrsh r0, [r3, r1] - cmp r0, 0 - beq _08111BEE - cmp r0, 0x1 - beq _08111BF8 - movs r6, 0x1 - b _08111C02 -_08111BEE: - movs r1, 0x30 - ldrsh r0, [r3, r1] - cmp r0, 0x2 - bne _08111C02 - b _08111C06 -_08111BF8: - movs r1, 0x30 - ldrsh r0, [r3, r1] - cmp r0, 0x4 - bne _08111C02 - movs r5, 0x1 -_08111C02: - cmp r5, 0 - beq _08111C38 -_08111C06: - ldrb r2, [r4] - lsls r0, r2, 29 - lsrs r0, 31 - movs r1, 0x1 - eors r1, r0 - lsls r1, 2 - movs r0, 0x5 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r4] - ldrh r0, [r3, 0x32] - adds r0, 0x1 - movs r1, 0 - strh r0, [r3, 0x32] - strh r1, [r3, 0x30] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x5 - bne _08111C4A - strh r1, [r3, 0x32] - ldrh r0, [r3, 0x2E] - adds r0, 0x1 - strh r0, [r3, 0x2E] - b _08111C4A -_08111C38: - cmp r6, 0 - beq _08111C44 - adds r0, r3, 0 - bl DestroyAnimSprite - b _08111C4A -_08111C44: - ldrh r0, [r3, 0x30] - adds r0, 0x1 - strh r0, [r3, 0x30] -_08111C4A: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_8111BB4 - thumb_func_start sub_8111C50 sub_8111C50: @ 8111C50 push {r4-r6,lr} diff --git a/include/battle_anim.h b/include/battle_anim.h index 8d73ea9b3..fa4058c1b 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -130,6 +130,7 @@ void sub_80A7E6C(u8 spriteId); void sub_80A805C(struct Task *task, u8 a2, s16 a3, s16 a4, s16 a5, s16 a6, u16 a7); u8 sub_80A80C8(struct Task *task); void sub_80A8EE4(struct Sprite *); +void sub_80A67F4(struct Sprite *); enum { diff --git a/ld_script.txt b/ld_script.txt index f78c1ae52..83e2fa385 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -167,6 +167,7 @@ SECTIONS { asm/psychic.o(.text); src/bug.o(.text); src/rock.o(.text); + src/ghost.o(.text); asm/ghost.o(.text); src/dragon.o(.text); asm/dark.o(.text); diff --git a/src/ghost.c b/src/ghost.c index ce57df7e8..526e4e519 100644 --- a/src/ghost.c +++ b/src/ghost.c @@ -1,11 +1,23 @@ #include "global.h" #include "battle_anim.h" +#include "gpu_regs.h" #include "constants/rgb.h" +#include "constants/songs.h" +#include "sound.h" +#include "trig.h" -extern void sub_811160C(struct Sprite *); -extern void sub_81117F4(struct Sprite *); -extern void sub_81119E0(struct Sprite *); -extern void sub_8111B9C(struct Sprite *); +static void sub_811160C(struct Sprite *); +static void sub_8111674(struct Sprite *); +static void sub_81116E8(struct Sprite *); +static void sub_8111764(struct Sprite *); +static void sub_81117F4(struct Sprite *); +static void sub_8111814(struct Sprite *); +static void sub_8111914(u8 taskId); +static void sub_811196C(u8 taskId); +static void InitAnimShadowBall(struct Sprite *); +static void AnimShadowBallStep(struct Sprite *); +static void sub_8111B9C(struct Sprite *); +static void sub_8111BB4(struct Sprite *); extern void sub_8112264(struct Sprite *); extern void sub_81129F0(struct Sprite *); extern void sub_8112B78(struct Sprite *); @@ -65,7 +77,7 @@ const struct SpriteTemplate gUnknown_08596D58 = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gUnknown_08596D54, - .callback = sub_81119E0, + .callback = InitAnimShadowBall, }; const union AnimCmd gUnknown_08596D70[] = @@ -184,3 +196,1107 @@ const struct SpriteTemplate gUnknown_08596E48 = .affineAnims = gDummySpriteAffineAnimTable, .callback = sub_8112F60, }; + +static void sub_811160C(struct Sprite *sprite) +{ + InitAnimSpritePos(sprite, 1); + sprite->data[0] = gBattleAnimArgs[2]; + sprite->data[1] = sprite->pos1.x; + sprite->data[2] = GetBattlerSpriteCoord(gBattleAnimTarget, 2); + sprite->data[3] = sprite->pos1.y; + sprite->data[4] = GetBattlerSpriteCoord(gBattleAnimTarget, 3); + sub_80A6FD4(sprite); + sprite->callback = sub_8111674; + sprite->data[6] = 16; + SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); + SetGpuReg(REG_OFFSET_BLDALPHA, sprite->data[6]); +} + +static void sub_8111674(struct Sprite *sprite) +{ + s16 r0; + s16 r2; + sub_8111764(sprite); + if (TranslateAnimLinear(sprite)) + { + sprite->callback = sub_81116E8; + return; + } + + sprite->pos2.x += Sin(sprite->data[5], 10); + sprite->pos2.y += Cos(sprite->data[5], 15); + r2 = sprite->data[5]; + sprite->data[5] = (sprite->data[5] + 5) & 0xFF; + r0 = sprite->data[5]; + if (r2 != 0 && r2 <= 196) + return; + if (r0 <= 0) + return; + PlaySE12WithPanning(SE_W109, gUnknown_02038440); +} + +static void sub_81116E8(struct Sprite *sprite) +{ + s16 r2; + s16 r0; + sprite->data[0] = 1; + TranslateAnimLinear(sprite); + sprite->pos2.x += Sin(sprite->data[5], 10); + sprite->pos2.y += Cos(sprite->data[5], 15); + + r2 = sprite->data[5]; + sprite->data[5] = (sprite->data[5] + 5) & 0xFF; + r0 = sprite->data[5]; + + if (r2 == 0 || r2 > 196) + { + if (r0 > 0) + PlaySE(SE_W109); + } + + if (sprite->data[6] == 0) + { + sprite->invisible = TRUE; + sprite->callback = sub_80A67F4; + } + else + sub_8111764(sprite); +} + +static void sub_8111764(struct Sprite *sprite) +{ + + s16 r0; + if (sprite->data[6] > 0xFF) + { + if (++sprite->data[6] == 0x10d) + sprite->data[6] = 0; + return; + } + + r0 = sprite->data[7]; + sprite->data[7]++; + + if ((r0 & 0xFF) == 0) + { + sprite->data[7] &= 0xff00; + if ((sprite->data[7] & 0x100) != 0) + sprite->data[6]++; + else + sprite->data[6]--; + + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(sprite->data[6], 16 - sprite->data[6])); + if (sprite->data[6] == 0 || sprite->data[6] == 16) + sprite->data[7] ^= 0x100; + if (sprite->data[6] == 0) + sprite->data[6] = 0x100; + } +} + +static void sub_81117F4(struct Sprite *sprite) +{ + sub_80A6980(sprite, TRUE); + sprite->callback = sub_8111814; + sprite->callback(sprite); +} + +static void sub_8111814(struct Sprite *sprite) +{ + u16 temp1; + sprite->pos2.x = Sin(sprite->data[0], 32); + sprite->pos2.y = Cos(sprite->data[0], 8); + temp1 = sprite->data[0] - 65; + if (temp1 <= 130) + sprite->oam.priority = 2; + else + sprite->oam.priority = 1; + sprite->data[0] = (sprite->data[0] + 19) & 0xFF; + sprite->data[2] += 80; + sprite->pos2.y += sprite->data[2] >> 8; + sprite->data[7] += 1; + if (sprite->data[7] == 61) + DestroyAnimSprite(sprite); +} + +void sub_811188C(u8 taskId) +{ + u8 spriteId; + SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); + SetGpuReg(REG_OFFSET_BLDALPHA, 0x1000); + spriteId = GetAnimBattlerSpriteId(0); + sub_80A7270(spriteId, 1); + obj_id_set_rotscale(spriteId, 128, 128, 0); + gSprites[spriteId].invisible = FALSE; + gTasks[taskId].data[0] = 128; + gTasks[taskId].data[1] = *gBattleAnimArgs; + gTasks[taskId].data[2] = 0; + gTasks[taskId].data[3] = 16; + gTasks[taskId].func = sub_8111914; +} + +static void sub_8111914(u8 taskId) +{ + gTasks[taskId].data[10] += 1; + if (gTasks[taskId].data[10] == 3) + { + gTasks[taskId].data[10] = 0; + gTasks[taskId].data[2] += 1; + gTasks[taskId].data[3] -= 1; + SetGpuReg(REG_OFFSET_BLDALPHA, gTasks[taskId].data[3] << 8 | gTasks[taskId].data[2]); + if (gTasks[taskId].data[2] != 9) + return; + + gTasks[taskId].func = sub_811196C; + } +} + +static void sub_811196C(u8 taskId) +{ + u8 spriteId; + if (gTasks[taskId].data[1] > 0) + { + gTasks[taskId].data[1] -= 1; + return; + } + + spriteId = GetAnimBattlerSpriteId(0); + gTasks[taskId].data[0] += 8; + if (gTasks[taskId].data[0] <= 0xFF) + { + obj_id_set_rotscale(spriteId, gTasks[taskId].data[0], gTasks[taskId].data[0], 0); + } + else + { + sub_80A7344(spriteId); + DestroyAnimVisualTask(taskId); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + } +} + +// Spins a sprite towards the target, pausing in the middle. +// Used in Shadow Ball. +// arg 0: duration step 1 (attacker -> center) +// arg 1: duration step 2 (spin center) +// arg 2: duration step 3 (center -> target) +static void InitAnimShadowBall(struct Sprite *sprite) +{ + u16 r5, r6; + r5 = sprite->pos1.x; + r6 = sprite->pos1.y; + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 2); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimAttacker, 3); + sprite->data[0] = 0; + sprite->data[1] = gBattleAnimArgs[0]; + sprite->data[2] = gBattleAnimArgs[1]; + sprite->data[3] = gBattleAnimArgs[2]; + sprite->data[4] = sprite->pos1.x << 4; + sprite->data[5] = sprite->pos1.y << 4; + sprite->data[6] = (((s16)r5 - sprite->pos1.x) << 4) / (gBattleAnimArgs[0] << 1); + sprite->data[7] = (((s16)r6 - sprite->pos1.y) << 4) / (gBattleAnimArgs[0] << 1); + sprite->callback = AnimShadowBallStep; +} + +static void AnimShadowBallStep(struct Sprite *sprite) +{ + switch (sprite->data[0]) + { + case 0: + sprite->data[4] += sprite->data[6]; + sprite->data[5] += sprite->data[7]; + sprite->pos1.x = sprite->data[4] >> 4; + sprite->pos1.y = sprite->data[5] >> 4; + sprite->data[1] -= 1; + if (sprite->data[1] > 0) + break; + sprite->data[0] += 1; + break; + case 1: + sprite->data[2] -= 1; + if (sprite->data[2] > 0) + break; + sprite->data[1] = GetBattlerSpriteCoord(gBattleAnimTarget, 2); + sprite->data[2] = GetBattlerSpriteCoord(gBattleAnimTarget, 3); + sprite->data[4] = sprite->pos1.x << 4; + sprite->data[5] = sprite->pos1.y << 4; + sprite->data[6] = ((sprite->data[1] - sprite->pos1.x) << 4) / sprite->data[3]; + sprite->data[7] = ((sprite->data[2] - sprite->pos1.y) << 4) / sprite->data[3]; + sprite->data[0] += 1; + break; + case 2: + sprite->data[4] += sprite->data[6]; + sprite->data[5] += sprite->data[7]; + sprite->pos1.x = sprite->data[4] >> 4; + sprite->pos1.y = sprite->data[5] >> 4; + sprite->data[3] -= 1; + if (sprite->data[3] > 0) + break; + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimTarget, 2); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimTarget, 3); + sprite->data[0] += 1; + break; + case 3: + move_anim_8074EE0(sprite); + break; + } +} + +static void sub_8111B9C(struct Sprite *sprite) +{ + sub_80A6980(sprite, TRUE); + sprite->callback = sub_8111BB4; +} + +static void sub_8111BB4(struct Sprite *sprite) { + + s8 r5 = FALSE; + bool8 r6 = FALSE; + if(sprite->animEnded) + { + if(!(sprite->invisible)) + sprite->invisible=TRUE; + switch(sprite->data[0]) + { + case 0: + if((sprite->data[1]) != 2) + break; + goto loc_08111C06; + case 1: + if((sprite->data[1]) == 4) + r5 = TRUE; + break; + default: + r6 = TRUE; + } + if(r5) + { + loc_08111C06: + sprite->invisible ^= 1; + sprite->data[2]++; + sprite->data[1] = 0; + if(sprite->data[2] == 5) + { + sprite->data[2] = 0; + sprite->data[0]++; + } + } + else if(r6) + DestroyAnimSprite(sprite); + else + sprite->data[1]++; + } +} + +/* + +void sub_80DE1B0(u8 taskId) +{ + struct Task *task; + + task = &gTasks[taskId]; + task->data[0] = duplicate_obj_of_side_rel2move_in_transparent_mode(1); + if (task->data[0] < 0) + { + DestroyAnimVisualTask(taskId); + return; + } + task->data[1] = 0; + task->data[2] = 15; + task->data[3] = 2; + task->data[4] = 0; + REG_BLDCNT = 0x3F40; + REG_BLDALPHA = (task->data[3] << 8) | task->data[2]; + gSprites[task->data[0]].data[0] = 80; + if (GetBattlerSide(gAnimBankTarget) == 0) + { + gSprites[task->data[0]].data[1] = -144; + gSprites[task->data[0]].data[2] = 112; + } + else + { + gSprites[task->data[0]].data[1] = 144; + gSprites[task->data[0]].data[2] = -112; + } + gSprites[task->data[0]].data[3] = 0; + gSprites[task->data[0]].data[4] = 0; + StoreSpriteCallbackInData(&gSprites[task->data[0]], SpriteCallbackDummy); + gSprites[task->data[0]].callback = sub_8078394; + task->func = sub_80DE2DC; +} + +static void sub_80DE2DC(u8 taskId) +{ + struct Task *task; + + task = &gTasks[taskId]; + switch (task->data[4]) + { + case 0: + task->data[1] += 1; + task->data[5] = task->data[1] & 3; + if (task->data[5] == 1) + if (task->data[2] > 0) + task->data[2] -= 1; + if (task->data[5] == 3) + if (task->data[3] <= 15) + task->data[3] += 1; + REG_BLDALPHA = (task->data[3] << 8) | task->data[2]; + if (task->data[3] != 16 || task->data[2] != 0) + break; + if (task->data[1] <= 80) + break; + obj_delete_but_dont_free_vram(&gSprites[task->data[0]]); + task->data[4] = 1; + break; + case 1: + if (++task->data[6] <= 1) + break; + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + task->data[4] += 1; + break; + case 2: + DestroyAnimVisualTask(taskId); + } +} + +void sub_80DE3AC(u8 taskId) +{ + struct Task *task; + + task = &gTasks[taskId]; + task->data[15] = 0; + task->func = sub_80DE3D4; + task->func(taskId); +} + +static void sub_80DE3D4(u8 taskId) +{ + s16 startLine; + struct Task *task = &gTasks[taskId]; + u8 position = GetBattlerPosition_permutated(gAnimBankTarget); + + switch (task->data[15]) + { + case 0: + task->data[14] = AllocSpritePalette(0x2771); + if (task->data[14] == 0xFF) + { + DestroyAnimVisualTask(taskId); + } + else + { + task->data[0] = duplicate_obj_of_side_rel2move_in_transparent_mode(1); + if (task->data[0] < 0) + { + FreeSpritePaletteByTag(0x2771); + DestroyAnimVisualTask(taskId); + } + else + { + gSprites[task->data[0]].oam.paletteNum = task->data[14]; + gSprites[task->data[0]].oam.objMode = ST_OAM_OBJ_NORMAL; + gSprites[task->data[0]].oam.priority = 3; + task->data[1] = 0; + task->data[2] = 0; + task->data[3] = 16; + task->data[13] = GetAnimBattlerSpriteId(1); + task->data[4] = (gSprites[task->data[13]].oam.paletteNum + 16) * 16; + if (position == 1) + REG_DISPCNT &= 0xFDFF; + else + REG_DISPCNT &= 0xFBFF; + + task->data[15]++; + } + } + break; + case 1: + task->data[14] = (task->data[14] + 16) * 16; + CpuSet(&gPlttBufferUnfaded[task->data[4]], &gPlttBufferFaded[task->data[14]], 0x4000008); + BlendPalette(task->data[4], 16, 10, RGB(13, 0, 15)); + task->data[15]++; + break; + case 2: + startLine = gSprites[task->data[13]].pos1.y + gSprites[task->data[13]].pos2.y - 32; + if (startLine < 0) + startLine = 0; + + if (position == 1) + task->data[10] = ScanlineEffect_InitWave(startLine, startLine + 64, 2, 6, 0, 4, 1); + else + task->data[10] = ScanlineEffect_InitWave(startLine, startLine + 64, 2, 6, 0, 8, 1); + + task->data[15]++; + break; + case 3: + if (position == 1) + REG_BLDCNT = 0x3F42; + else + REG_BLDCNT = 0x3F44; + + REG_BLDALPHA = 0x1000; + task->data[15]++; + break; + case 4: + if (position == 1) + REG_DISPCNT |= DISPCNT_BG1_ON; + else + REG_DISPCNT |= DISPCNT_BG2_ON; + + task->func = sub_80DE61C; + task->data[15]++; + break; + default: + task->data[15]++; + break; + } +} + +static void sub_80DE61C(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + task->data[1]++; + task->data[5] = task->data[1] & 1; + if (task->data[5] == 0) + task->data[2] = gSineTable[task->data[1]] / 18; + + if (task->data[5] == 1) + task->data[3] = 16 - (gSineTable[task->data[1]] / 18); + + REG_BLDALPHA = (task->data[3] << 8) | task->data[2]; + if (task->data[1] == 128) + { + task->data[15] = 0; + task->func = sub_80DE6B0; + task->func(taskId); + } +} + +static void sub_80DE6B0(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + u8 position = GetBattlerPosition_permutated(gAnimBankTarget); + + switch (task->data[15]) + { + case 0: + gScanlineEffect.state = 3; + task->data[14] = GetAnimBattlerSpriteId(1); + if (position == 1) + REG_DISPCNT &= 0xFDFF; + else + REG_DISPCNT &= 0xFBFF; + break; + case 1: + BlendPalette(task->data[4], 16, 0, RGB(13, 0, 15)); + break; + case 2: + gSprites[task->data[14]].invisible = 1; + obj_delete_but_dont_free_vram(&gSprites[task->data[0]]); + FreeSpritePaletteByTag(0x2771); + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + if (position == 1) + REG_DISPCNT |= DISPCNT_BG1_ON; + else + REG_DISPCNT |= DISPCNT_BG2_ON; + + DestroyAnimVisualTask(taskId); + break; + } + + task->data[15]++; +} + +static void sub_80DE7B8(struct Sprite *sprite) +{ + s16 battler1X, battler1Y; + s16 battler2X, battler2Y; + s16 yDiff; + + if (gBattleAnimArgs[0] == 0) + { + battler1X = GetBattlerSpriteCoord(gAnimBankAttacker, 0); + battler1Y = GetBattlerSpriteCoord(gAnimBankAttacker, 1) + 28; + battler2X = GetBattlerSpriteCoord(gAnimBankTarget, 0); + battler2Y = GetBattlerSpriteCoord(gAnimBankTarget, 1) + 28; + } + else + { + battler1X = GetBattlerSpriteCoord(gAnimBankTarget, 0); + battler1Y = GetBattlerSpriteCoord(gAnimBankTarget, 1) + 28; + battler2X = GetBattlerSpriteCoord(gAnimBankAttacker, 0); + battler2Y = GetBattlerSpriteCoord(gAnimBankAttacker, 1) + 28; + } + + yDiff = battler2Y - battler1Y; + sprite->data[0] = battler1X * 16; + sprite->data[1] = battler1Y * 16; + sprite->data[2] = ((battler2X - battler1X) * 16) / gBattleAnimArgs[1]; + sprite->data[3] = (yDiff * 16) / gBattleAnimArgs[1]; + sprite->data[4] = gBattleAnimArgs[1]; + sprite->data[5] = battler2X; + sprite->data[6] = battler2Y; + sprite->data[7] = sprite->data[4] / 2; + sprite->oam.priority = 2; + sprite->pos1.x = battler1X; + sprite->pos1.y = battler1Y; + sprite->callback = sub_80DE8D8; + sprite->invisible = 1; +} + +static void sub_80DE8D8(struct Sprite *sprite) +{ + if (sprite->data[4]) + { + sprite->data[0] += sprite->data[2]; + sprite->data[1] += sprite->data[3]; + sprite->pos1.x = sprite->data[0] >> 4; + sprite->pos1.y = sprite->data[1] >> 4; + if (--sprite->data[4] == 0) + sprite->data[0] = 0; + } +} + +void sub_80DE918(u8 taskId) +{ + struct Task *task; + s16 battler; + u8 spriteId; + s16 baseX, baseY; + s16 x, y; + + task = &gTasks[taskId]; + REG_BLDCNT = 0x3F40; + REG_BLDALPHA = 0x1000; + task->data[5] = 0; + task->data[6] = 0; + task->data[7] = 0; + task->data[8] = 0; + task->data[9] = 16; + task->data[10] = gBattleAnimArgs[0]; + + baseX = GetBattlerSpriteCoord(gAnimBankAttacker, 2); + baseY = sub_807A100(gAnimBankAttacker, 3); + if (!IsContest()) + { + for (battler = 0; battler < 4; battler++) + { + if (battler != gAnimBankAttacker + && battler != (gAnimBankAttacker ^ 2) + && IsAnimBankSpriteVisible(battler)) + { + spriteId = CreateSprite(&gSpriteTemplate_83DAF08, baseX, baseY, 55); + if (spriteId != MAX_SPRITES) + { + x = GetBattlerSpriteCoord(battler, 2); + y = sub_807A100(battler, 3); + gSprites[spriteId].data[0] = baseX << 4; + gSprites[spriteId].data[1] = baseY << 4; + gSprites[spriteId].data[2] = ((x - baseX) << 4) / gBattleAnimArgs[1]; + gSprites[spriteId].data[3] = ((y - baseY) << 4) / gBattleAnimArgs[1]; + gSprites[spriteId].data[4] = gBattleAnimArgs[1]; + gSprites[spriteId].data[5] = x; + gSprites[spriteId].data[6] = y; + gSprites[spriteId].callback = sub_80DE8D8; + + task->data[task->data[12] + 13] = spriteId; + task->data[12]++; + } + } + } + } + else + { + spriteId = CreateSprite(&gSpriteTemplate_83DAF08, baseX, baseY, 55); + if (spriteId != MAX_SPRITES) + { + x = 48; + y = 40; + gSprites[spriteId].data[0] = baseX << 4; + gSprites[spriteId].data[1] = baseY << 4; + gSprites[spriteId].data[2] = ((x - baseX) << 4) / gBattleAnimArgs[1]; + gSprites[spriteId].data[3] = ((y - baseY) << 4) / gBattleAnimArgs[1]; + gSprites[spriteId].data[4] = gBattleAnimArgs[1]; + gSprites[spriteId].data[5] = x; + gSprites[spriteId].data[6] = y; + gSprites[spriteId].callback = sub_80DE8D8; + + task->data[13] = spriteId; + task->data[12] = 1; + } + } + + task->func = sub_80DEB38; +} + +static void sub_80DEB38(u8 taskId) +{ + u16 i; + struct Task *task = &gTasks[taskId]; + + switch (task->data[0]) + { + case 0: + if (task->data[6] == 0) + { + if (++task->data[5] > 1) + { + task->data[5] = 0; + task->data[7]++; + if (task->data[7] & 1) + { + if (task->data[8] < 16) + task->data[8]++; + } + else + { + if (task->data[9]) + task->data[9]--; + } + + REG_BLDALPHA = (task->data[9] << 8) | task->data[8]; + if (task->data[7] >= 24) + { + task->data[7] = 0; + task->data[6] = 1; + } + } + } + + if (task->data[10]) + task->data[10]--; + else if (task->data[6]) + task->data[0]++; + break; + case 1: + if (++task->data[5] > 1) + { + task->data[5] = 0; + task->data[7]++; + if (task->data[7] & 1) + { + if (task->data[8]) + task->data[8]--; + } + else + { + if (task->data[9] < 16) + task->data[9]++; + } + + REG_BLDALPHA = (task->data[9] << 8) | task->data[8]; + if (task->data[8] == 0 && task->data[9] == 16) + { + for (i = 0; i < task->data[12]; i++) + DestroySprite(&gSprites[task->data[i + 13]]); + + task->data[0]++; + } + } + break; + case 2: + if (++task->data[5] > 0) + task->data[0]++; + break; + case 3: + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + DestroyAnimVisualTask(taskId); + break; + } +} + +void sub_80DECB0(u8 taskId) +{ + s16 startX, startY; + s16 leftDistance, topDistance, bottomDistance, rightDistance; + + gBattle_WIN0H = 0; + gBattle_WIN0V = 0; + REG_WININ = 0x3F3F; + REG_WINOUT = 0x3F1F; + REG_BLDCNT = 0xC8; + REG_BLDY = 0x10; + + if (GetBattlerSide(gAnimBankAttacker) != B_SIDE_PLAYER || IsContest()) + startX = 40; + else + startX = 200; + + gBattle_WIN0H = (startX << 8) | startX; + startY = 40; + gBattle_WIN0V = (startY << 8) | startY; + + leftDistance = startX; + rightDistance = 240 - startX; + topDistance = startY; + bottomDistance = 72; + gTasks[taskId].data[1] = leftDistance; + gTasks[taskId].data[2] = rightDistance; + gTasks[taskId].data[3] = topDistance; + gTasks[taskId].data[4] = bottomDistance; + gTasks[taskId].data[5] = startX; + gTasks[taskId].data[6] = startY; + gTasks[taskId].func = sub_80DED60; +} + +static void sub_80DED60(u8 taskId) +{ + s16 step; + s16 leftDistance, rightDistance, topDistance, bottomDistance; + s16 startX, startY; + u16 left, right, top, bottom; + u16 selectedPalettes; + + step = gTasks[taskId].data[0]; + gTasks[taskId].data[0]++; + leftDistance = gTasks[taskId].data[1]; + rightDistance = gTasks[taskId].data[2]; + topDistance = gTasks[taskId].data[3]; + bottomDistance = gTasks[taskId].data[4]; + startX = gTasks[taskId].data[5]; + startY = gTasks[taskId].data[6]; + + if (step < 16) + { + left = startX - (leftDistance * 0.0625) * step; + right = startX + (rightDistance * 0.0625) * step; + top = startY - (topDistance * 0.0625) * step; + bottom = startY + (bottomDistance * 0.0625) * step; + } + else + { + left = 0; + right = 240; + top = 0; + bottom = 112; + selectedPalettes = sub_80791A8(1, 0, 0, 0, 0, 0, 0); + BeginNormalPaletteFade(selectedPalettes, 0, 16, 16, RGB(0, 0, 0)); + gTasks[taskId].func = sub_80DEEE8; + } + + gBattle_WIN0H = (left << 8) | right; + gBattle_WIN0V = (top << 8) | bottom; +} + +static void sub_80DEEE8(u8 taskId) +{ + if (!gPaletteFade.active) + { + gBattle_WIN0H = 0; + gBattle_WIN0V = 0; + REG_WININ = 0x3F3F; + REG_WINOUT = 0x3F3F; + REG_BLDCNT = 0; + REG_BLDY = 0; + DestroyAnimVisualTask(taskId); + } +} + +static void sub_80DEF3C(struct Sprite *sprite) +{ + s16 xDelta; + s16 xDelta2; + + InitAnimSpritePos(sprite, 1); + if (GetBattlerSide(gAnimBankAttacker) == B_SIDE_PLAYER) + { + xDelta = 24; + xDelta2 = -2; + sprite->oam.matrixNum = 8; + } + else + { + xDelta = -24; + xDelta2 = 2; + } + + sprite->pos1.x += xDelta; + sprite->data[1] = xDelta2; + sprite->data[0] = 60; + sprite->callback = sub_80DEF98; +} + +static void sub_80DEF98(struct Sprite *sprite) +{ + u16 var0; + + if (sprite->data[0] > 0) + { + sprite->data[0]--; + } + else + { + sprite->pos2.x += sprite->data[1]; + var0 = sprite->pos2.x + 7; + if (var0 > 14) + { + sprite->pos1.x += sprite->pos2.x; + sprite->pos2.x = 0; + sprite->oam.tileNum += 8; + if (++sprite->data[2] == 3) + { + sprite->data[0] = 30; + sprite->callback = WaitAnimForDuration; + StoreSpriteCallbackInData(sprite, sub_80DF018); + } + else + { + sprite->data[0] = 40; + } + } + } +} + +static void sub_80DF018(struct Sprite *sprite) +{ + if (sprite->data[0] == 0) + { + REG_BLDCNT = 0x3F40; + REG_BLDALPHA = 0x0010; + sprite->data[0]++; + sprite->data[1] = 0; + sprite->data[2] = 0; + } + else if (sprite->data[1] < 2) + { + sprite->data[1]++; + } + else + { + sprite->data[1] = 0; + sprite->data[2]++; + REG_BLDALPHA = (16 - sprite->data[2]) | (sprite->data[2] << 8); + if (sprite->data[2] == 16) + { + sprite->invisible = 1; + sprite->callback = sub_80DF090; + } + } +} + +static void sub_80DF090(struct Sprite *sprite) +{ + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + gBattle_WIN0H = 0; + gBattle_WIN0V = 0; + DestroyAnimSprite(sprite); +} + +static void sub_80DF0B8(struct Sprite *sprite) +{ + u16 coeffB; + u16 coeffA; + + sprite->pos2.x = Sin(sprite->data[0], 12); + if (GetBattlerSide(gAnimBankAttacker) != B_SIDE_PLAYER) + sprite->pos2.x = -sprite->pos2.x; + + sprite->data[0] = (sprite->data[0] + 6) & 0xFF; + sprite->data[1] += 0x100; + sprite->pos2.y = -(sprite->data[1] >> 8); + + sprite->data[7]++; + if (sprite->data[7] == 1) + { + sprite->data[6] = 0x050B; + REG_BLDCNT = 0x3F40; + REG_BLDALPHA = sprite->data[6]; + } + else if (sprite->data[7] > 30) + { + sprite->data[2]++; + coeffB = sprite->data[6] >> 8; + coeffA = sprite->data[6] & 0xFF; + + if (++coeffB > 16) + coeffB = 16; + if (--(s16)coeffA < 0) + coeffA = 0; + + REG_BLDALPHA = (coeffB << 8) | coeffA; + sprite->data[6] = (coeffB << 8) | coeffA; + if (coeffB == 16 && coeffA == 0) + { + sprite->invisible = 1; + sprite->callback = sub_80DF18C; + } + } +} + +static void sub_80DF18C(struct Sprite *sprite) +{ + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + DestroyAnimSprite(sprite); +} + +void sub_80DF1A4(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + + task->data[0] = 0; + task->data[1] = 16; + task->data[9] = GetBattlerSpriteCoord(gAnimBankAttacker, 2); + task->data[10] = sub_8077FC0(gAnimBankAttacker); + task->data[11] = (sub_807A100(gAnimBankAttacker, 1) / 2) + 8; + task->data[7] = 0; + task->data[5] = sub_8079ED4(gAnimBankAttacker); + task->data[6] = GetBattlerSubpriority(gAnimBankAttacker) - 2; + task->data[3] = 0; + task->data[4] = 16; + REG_BLDCNT = 0x3F40; + REG_BLDALPHA = 0x1000; + task->data[8] = 0; + task->func = sub_80DF24C; +} + +static void sub_80DF24C(u8 taskId) +{ + u16 i; + u8 spriteId; + struct Task *task = &gTasks[taskId]; + + switch (task->data[0]) + { + case 0: + for (i = 0; i < 6; i++) + { + spriteId = CreateSprite(&gSpriteTemplate_83DAF80, task->data[9], task->data[10], task->data[6]); + if (spriteId != MAX_SPRITES) + { + gSprites[spriteId].data[0] = taskId; + gSprites[spriteId].data[1] = GetBattlerSide(gAnimBankAttacker) == B_SIDE_PLAYER; + + gSprites[spriteId].data[2] = (i * 42) & 0xFF; + gSprites[spriteId].data[3] = task->data[11]; + gSprites[spriteId].data[5] = i * 6; + task->data[7]++; + } + } + + task->data[0]++; + break; + case 1: + if (++task->data[1] & 1) + { + if (task->data[3] < 14) + task->data[3]++; + } + else + { + if (task->data[4] > 4) + task->data[4]--; + } + + if (task->data[3] == 14 && task->data[4] == 4) + { + task->data[1] = 0; + task->data[0]++; + } + + REG_BLDALPHA = (task->data[4] << 8) | task->data[3]; + break; + case 2: + if (++task->data[1] > 30) + { + task->data[1] = 0; + task->data[0]++; + } + break; + case 3: + if (++task->data[1] & 1) + { + if (task->data[3] > 0) + task->data[3]--; + } + else + { + if (task->data[4] < 16) + task->data[4]++; + } + + if (task->data[3] == 0 && task->data[4] == 16) + { + task->data[8] = 1; + task->data[0]++; + } + + REG_BLDALPHA = (task->data[4] << 8) | task->data[3]; + break; + case 4: + if (task->data[7] == 0) + task->data[0]++; + break; + case 5: + REG_BLDCNT = 0; + REG_BLDALPHA = 0; + DestroyAnimVisualTask(taskId); + break; + } +} + +static void sub_80DF3D8(struct Sprite *sprite) +{ + u16 index; + + if (sprite->data[1] == 0) + sprite->data[2] += 2; + else + sprite->data[2] -= 2; + + sprite->data[2] &= 0xFF; + sprite->pos2.x = Sin(sprite->data[2], sprite->data[3]); + + index = sprite->data[2] - 65; + if (index < 127) + sprite->oam.priority = gTasks[sprite->data[0]].data[5] + 1; + else + sprite->oam.priority = gTasks[sprite->data[0]].data[5]; + + sprite->data[5]++; + sprite->data[6] = (sprite->data[5] * 8) & 0xFF; + sprite->pos2.y = Sin(sprite->data[6], 7); + if (gTasks[sprite->data[0]].data[8]) + { + gTasks[sprite->data[0]].data[7]--; + DestroySprite(sprite); + } +} + +static void sub_80DF49C(struct Sprite *sprite) +{ + sprite->invisible = 1; + sprite->data[5] = gBankSpriteIds[gAnimBankAttacker]; + sprite->data[0] = 128; + sprite->data[1] = 10; + sprite->data[2] = gBattleAnimArgs[0]; + sprite->data[3] = gBattleAnimArgs[1]; + sprite->callback = sub_80DF4F4; + + gSprites[sprite->data[5]].pos1.y += 8; +} + +static void sub_80DF4F4(struct Sprite *sprite) +{ + if (sprite->data[3]) + { + sprite->data[3]--; + gSprites[sprite->data[5]].pos2.x = Sin(sprite->data[0], sprite->data[1]); + gSprites[sprite->data[5]].pos2.y = Cos(sprite->data[0], sprite->data[1]); + sprite->data[0] += sprite->data[2]; + if (sprite->data[0] > 255) + sprite->data[0] -= 256; + } + else + { + gSprites[sprite->data[5]].pos2.x = 0; + gSprites[sprite->data[5]].pos2.y = 0; + gSprites[sprite->data[5]].pos1.y -= 8; + sprite->callback = move_anim_8074EE0; + } +}*/ +