From 9b1f2ccf5e523a6a196b3abc4afa4be7335fc715 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Mon, 26 Nov 2018 09:13:45 -0600 Subject: [PATCH] Decompile poison.c --- asm/flying.s | 36 ------ asm/poison.s | 306 -------------------------------------------------- ld_script.txt | 2 +- src/poison.c | 154 +++++++++++++++++++++++-- 4 files changed, 147 insertions(+), 351 deletions(-) delete mode 100644 asm/poison.s diff --git a/asm/flying.s b/asm/flying.s index 262fe3749..b981b4306 100644 --- a/asm/flying.s +++ b/asm/flying.s @@ -5,42 +5,6 @@ .text - thumb_func_start sub_810DE2C -sub_810DE2C: @ 810DE2C - push {r4,lr} - adds r4, r0, 0 - ldrh r0, [r4, 0x2E] - adds r0, 0xB - movs r1, 0xFF - ands r0, r1 - strh r0, [r4, 0x2E] - movs r1, 0x2E - ldrsh r0, [r4, r1] - movs r1, 0x4 - bl Sin - strh r0, [r4, 0x24] - ldrh r0, [r4, 0x30] - adds r0, 0x30 - strh r0, [r4, 0x30] - lsls r0, 16 - asrs r0, 24 - negs r0, r0 - strh r0, [r4, 0x26] - adds r0, r4, 0 - adds r0, 0x3F - ldrb r1, [r0] - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - beq _0810DE68 - adds r0, r4, 0 - bl DestroyAnimSprite -_0810DE68: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_810DE2C - thumb_func_start sub_810DE70 sub_810DE70: @ 810DE70 push {r4,lr} diff --git a/asm/poison.s b/asm/poison.s deleted file mode 100644 index d2266bfe5..000000000 --- a/asm/poison.s +++ /dev/null @@ -1,306 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_810DBAC -sub_810DBAC: @ 810DBAC - push {r4,r5,lr} - adds r5, r0, 0 - ldr r4, =gBattleAnimArgs - movs r1, 0x6 - ldrsh r0, [r4, r1] - cmp r0, 0 - bne _0810DBC2 - adds r0, r5, 0 - movs r1, 0x2 - bl StartSpriteAnim -_0810DBC2: - adds r0, r5, 0 - movs r1, 0x1 - bl InitAnimSpritePos - ldrh r0, [r4, 0x4] - strh r0, [r5, 0x2E] - ldr r4, =gBattleAnimTarget - ldrb r0, [r4] - movs r1, 0x2 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x32] - ldrb r0, [r4] - movs r1, 0x3 - bl GetBattlerSpriteCoord - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x36] - ldr r0, =0x0000ffe2 - strh r0, [r5, 0x38] - adds r0, r5, 0 - bl InitAnimArcTranslation - ldr r0, =sub_810DC10 - str r0, [r5, 0x1C] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_810DBAC - - thumb_func_start sub_810DC10 -sub_810DC10: @ 810DC10 - push {r4,lr} - adds r4, r0, 0 - bl TranslateAnimArc - lsls r0, 24 - cmp r0, 0 - beq _0810DC24 - adds r0, r4, 0 - bl DestroyAnimSprite -_0810DC24: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_810DC10 - - thumb_func_start sub_810DC2C -sub_810DC2C: @ 810DC2C - push {r4-r6,lr} - sub sp, 0x4 - adds r4, r0, 0 - ldr r5, =gBattleAnimArgs - movs r1, 0x6 - ldrsh r0, [r5, r1] - cmp r0, 0 - bne _0810DC44 - adds r0, r4, 0 - movs r1, 0x2 - bl StartSpriteAnim -_0810DC44: - adds r0, r4, 0 - movs r1, 0x1 - bl InitAnimSpritePos - ldr r0, =gBattleAnimTarget - ldrb r0, [r0] - mov r6, sp - adds r6, 0x2 - movs r1, 0x1 - mov r2, sp - adds r3, r6, 0 - bl SetAverageBattlerPositions - ldr r0, =gBattleAnimAttacker - ldrb r0, [r0] - bl GetBattlerSide - lsls r0, 24 - cmp r0, 0 - beq _0810DC72 - ldrh r0, [r5, 0x8] - negs r0, r0 - strh r0, [r5, 0x8] -_0810DC72: - ldrh r0, [r5, 0x4] - strh r0, [r4, 0x2E] - mov r1, sp - ldrh r0, [r5, 0x8] - ldrh r1, [r1] - adds r0, r1 - strh r0, [r4, 0x32] - ldrh r0, [r5, 0xA] - ldrh r6, [r6] - adds r0, r6 - strh r0, [r4, 0x36] - ldr r0, =0x0000ffe2 - strh r0, [r4, 0x38] - adds r0, r4, 0 - bl InitAnimArcTranslation - ldr r0, =sub_810DCB4 - str r0, [r4, 0x1C] - add sp, 0x4 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_810DC2C - - thumb_func_start sub_810DCB4 -sub_810DCB4: @ 810DCB4 - push {r4,lr} - adds r4, r0, 0 - bl TranslateAnimArc - lsls r0, 24 - cmp r0, 0 - beq _0810DCC8 - adds r0, r4, 0 - bl DestroyAnimSprite -_0810DCC8: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_810DCB4 - - thumb_func_start sub_810DCD0 -sub_810DCD0: @ 810DCD0 - push {r4,r5,lr} - adds r4, r0, 0 - ldr r5, =gBattleAnimArgs - ldrh r0, [r5, 0x4] - strh r0, [r4, 0x2E] - ldrh r0, [r4, 0x20] - strh r0, [r4, 0x30] - ldrh r1, [r5] - adds r0, r1 - strh r0, [r4, 0x32] - ldrh r0, [r4, 0x22] - strh r0, [r4, 0x34] - ldrh r1, [r5, 0x2] - adds r0, r1 - strh r0, [r4, 0x36] - adds r0, r4, 0 - bl InitSpriteDataForLinearTranslation - movs r1, 0x30 - ldrsh r0, [r4, r1] - movs r2, 0x4 - ldrsh r1, [r5, r2] - bl __divsi3 - strh r0, [r4, 0x38] - movs r1, 0x32 - ldrsh r0, [r4, r1] - movs r2, 0x4 - ldrsh r1, [r5, r2] - bl __divsi3 - strh r0, [r4, 0x3A] - ldr r0, =sub_810DD24 - str r0, [r4, 0x1C] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_810DCD0 - - thumb_func_start sub_810DD24 -sub_810DD24: @ 810DD24 - push {r4,lr} - adds r4, r0, 0 - bl sub_80A656C - ldrh r0, [r4, 0x30] - ldrh r1, [r4, 0x38] - subs r0, r1 - strh r0, [r4, 0x30] - ldrh r0, [r4, 0x32] - ldrh r1, [r4, 0x3A] - subs r0, r1 - strh r0, [r4, 0x32] - movs r1, 0x2E - ldrsh r0, [r4, r1] - cmp r0, 0 - bne _0810DD4A - adds r0, r4, 0 - bl DestroyAnimSprite -_0810DD4A: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_810DD24 - - thumb_func_start sub_810DD50 -sub_810DD50: @ 810DD50 - push {r4,lr} - adds r4, r0, 0 - ldr r0, =gBattleAnimTarget - ldrb r0, [r0] - adds r2, r4, 0 - adds r2, 0x20 - adds r3, r4, 0 - adds r3, 0x22 - movs r1, 0x1 - bl SetAverageBattlerPositions - ldr r0, =gBattleAnimAttacker - ldrb r0, [r0] - bl GetBattlerSide - lsls r0, 24 - cmp r0, 0 - beq _0810DD7C - ldr r1, =gBattleAnimArgs - ldrh r0, [r1] - negs r0, r0 - strh r0, [r1] -_0810DD7C: - ldr r0, =gBattleAnimArgs - ldrh r2, [r0] - ldrh r1, [r4, 0x20] - adds r2, r1 - strh r2, [r4, 0x20] - ldrh r1, [r0, 0x2] - ldrh r3, [r4, 0x22] - adds r1, r3 - strh r1, [r4, 0x22] - ldrh r3, [r0, 0x8] - strh r3, [r4, 0x2E] - ldrh r0, [r0, 0x4] - adds r2, r0 - strh r2, [r4, 0x32] - adds r1, r3 - strh r1, [r4, 0x36] - ldr r0, =StartAnimLinearTranslation - str r0, [r4, 0x1C] - ldr r1, =DestroyAnimSprite - adds r0, r4, 0 - bl StoreSpriteCallbackInData6 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_810DD50 - - thumb_func_start sub_810DDC4 -sub_810DDC4: @ 810DDC4 - push {r4,r5,lr} - adds r4, r0, 0 - ldr r5, =gBattleAnimArgs - movs r1, 0x4 - ldrsh r0, [r5, r1] - cmp r0, 0 - bne _0810DDE0 - adds r0, r4, 0 - movs r1, 0x1 - bl sub_80A6980 - b _0810DE16 - .pool -_0810DDE0: - ldr r0, =gBattleAnimTarget - ldrb r0, [r0] - adds r2, r4, 0 - adds r2, 0x20 - adds r3, r4, 0 - adds r3, 0x22 - movs r1, 0x1 - bl SetAverageBattlerPositions - ldr r0, =gBattleAnimAttacker - ldrb r0, [r0] - bl GetBattlerSide - lsls r0, 24 - cmp r0, 0 - beq _0810DE06 - ldrh r0, [r5] - negs r0, r0 - strh r0, [r5] -_0810DE06: - ldrh r0, [r5] - ldrh r1, [r4, 0x20] - adds r0, r1 - strh r0, [r4, 0x20] - ldrh r0, [r5, 0x2] - ldrh r1, [r4, 0x22] - adds r0, r1 - strh r0, [r4, 0x22] -_0810DE16: - ldr r0, =sub_810DE2C - str r0, [r4, 0x1C] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_810DDC4 - - .align 2, 0 diff --git a/ld_script.txt b/ld_script.txt index 6942c40a4..aa8e4b712 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -163,7 +163,7 @@ SECTIONS { asm/electric.o(.text); asm/ice.o(.text); asm/fight.o(.text); - asm/poison.o(.text); + src/poison.o(.text); asm/flying.o(.text); asm/psychic.o(.text); src/bug.o(.text); diff --git a/src/poison.c b/src/poison.c index f0d8ec553..efa89ec13 100644 --- a/src/poison.c +++ b/src/poison.c @@ -1,14 +1,19 @@ #include "global.h" #include "battle_anim.h" +#include "trig.h" #include "constants/rgb.h" extern void sub_80A77C8(struct Sprite *); -extern void sub_810DBAC(struct Sprite *); -extern void sub_810DC2C(struct Sprite *); -extern void sub_810DCD0(struct Sprite *); -extern void sub_810DD50(struct Sprite *); -extern void sub_810DDC4(struct Sprite *); -extern void sub_810DDC4(struct Sprite *); + +void sub_810DBAC(struct Sprite *); +void sub_810DC2C(struct Sprite *); +void sub_810DCD0(struct Sprite *); +void sub_810DD50(struct Sprite *); +void AnimBubbleEffect(struct Sprite *); +static void sub_810DC10(struct Sprite *); +static void sub_810DCB4(struct Sprite *); +static void sub_810DD24(struct Sprite *); +static void AnimBubbleEffectStep(struct Sprite *); extern const union AnimCmd *const gUnknown_08595200[]; @@ -170,7 +175,7 @@ const struct SpriteTemplate gPoisonBubbleSpriteTemplate = .anims = gUnknown_08596164, .images = NULL, .affineAnims = gUnknown_0859623C, - .callback = sub_810DDC4, + .callback = AnimBubbleEffect, }; const struct SpriteTemplate gWaterBubbleSpriteTemplate = @@ -181,5 +186,138 @@ const struct SpriteTemplate gWaterBubbleSpriteTemplate = .anims = gUnknown_08595200, .images = NULL, .affineAnims = gUnknown_0859623C, - .callback = sub_810DDC4, + .callback = AnimBubbleEffect, }; + +void sub_810DBAC(struct Sprite *sprite) +{ + if (!gBattleAnimArgs[3]) + StartSpriteAnim(sprite, 2); + + InitAnimSpritePos(sprite, 1); + + sprite->data[0] = gBattleAnimArgs[2]; + sprite->data[2] = GetBattlerSpriteCoord(gBattleAnimTarget, 2); + sprite->data[4] = GetBattlerSpriteCoord(gBattleAnimTarget, 3); + sprite->data[5] = -30; + + InitAnimArcTranslation(sprite); + + sprite->callback = sub_810DC10; +} + +static void sub_810DC10(struct Sprite *sprite) +{ + if (TranslateAnimArc(sprite)) + DestroyAnimSprite(sprite); +} + +void sub_810DC2C(struct Sprite *sprite) +{ + s16 l1, l2; + if (!gBattleAnimArgs[3]) + StartSpriteAnim(sprite, 2); + + InitAnimSpritePos(sprite, 1); + SetAverageBattlerPositions(gBattleAnimTarget, 1, &l1, &l2); + + if (GetBattlerSide(gBattleAnimAttacker)) + gBattleAnimArgs[4] = -gBattleAnimArgs[4]; + + sprite->data[0] = gBattleAnimArgs[2]; + sprite->data[2] = l1 + gBattleAnimArgs[4]; + sprite->data[4] = l2 + gBattleAnimArgs[5]; + sprite->data[5] = -30; + + InitAnimArcTranslation(sprite); + + sprite->callback = sub_810DCB4; +} + +static void sub_810DCB4(struct Sprite *sprite) +{ + if (TranslateAnimArc(sprite)) + DestroyAnimSprite(sprite); +} + +void sub_810DCD0(struct Sprite *sprite) +{ + sprite->data[0] = gBattleAnimArgs[2]; + sprite->data[1] = sprite->pos1.x; + sprite->data[2] = sprite->pos1.x + gBattleAnimArgs[0]; + sprite->data[3] = sprite->pos1.y; + sprite->data[4] = sprite->pos1.y + gBattleAnimArgs[1]; + + InitSpriteDataForLinearTranslation(sprite); + + sprite->data[5] = sprite->data[1] / gBattleAnimArgs[2]; + sprite->data[6] = sprite->data[2] / gBattleAnimArgs[2]; + + sprite->callback = sub_810DD24; +} + +static void sub_810DD24(struct Sprite *sprite) +{ + sub_80A656C(sprite); + + sprite->data[1] -= sprite->data[5]; + sprite->data[2] -= sprite->data[6]; + + if (!sprite->data[0]) + DestroyAnimSprite(sprite); +} + +void sub_810DD50(struct Sprite *sprite) +{ + SetAverageBattlerPositions(gBattleAnimTarget, TRUE, &sprite->pos1.x, &sprite->pos1.y); + + if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER) + gBattleAnimArgs[0] = -gBattleAnimArgs[0]; + + sprite->pos1.x += gBattleAnimArgs[0]; + sprite->pos1.y += gBattleAnimArgs[1]; + + sprite->data[0] = gBattleAnimArgs[4]; + sprite->data[2] = sprite->pos1.x + gBattleAnimArgs[2]; + sprite->data[4] = sprite->pos1.y + sprite->data[0]; + + sprite->callback = StartAnimLinearTranslation; + StoreSpriteCallbackInData6(sprite, DestroyAnimSprite); +} + +// Animates a bubble by rising upward, swaying side to side, and +// enlarging the sprite. This is used as an after-effect by poison-type +// moves, along with MOVE_BUBBLE, and MOVE_BUBBLEBEAM. +// arg 0: initial x pixel offset +// arg 1: initial y pixel offset +// arg 2: 0 = single-target, 1 = multi-target +void AnimBubbleEffect(struct Sprite *sprite) +{ + if (!gBattleAnimArgs[2]) + { + sub_80A6980(sprite, TRUE); + } + else + { + SetAverageBattlerPositions(gBattleAnimTarget, TRUE, &sprite->pos1.x, &sprite->pos1.y); + + if (GetBattlerSide(gBattleAnimAttacker) != B_SIDE_PLAYER) + gBattleAnimArgs[0] = -gBattleAnimArgs[0]; + + sprite->pos1.x += gBattleAnimArgs[0]; + sprite->pos1.y += gBattleAnimArgs[1]; + } + + sprite->callback = AnimBubbleEffectStep; +} + +static void AnimBubbleEffectStep(struct Sprite *sprite) +{ + sprite->data[0] = (sprite->data[0] + 0xB) & 0xFF; + sprite->pos2.x = Sin(sprite->data[0], 4); + sprite->data[1] += 0x30; + sprite->pos2.y = -(sprite->data[1] >> 8); + + if (sprite->affineAnimEnded) + DestroyAnimSprite(sprite); +}