decompile sub_802C68C

This commit is contained in:
camthesaxman 2017-08-14 10:20:58 -05:00
parent 04110a7040
commit b57c52c1b3
2 changed files with 158 additions and 465 deletions

View File

@ -6,471 +6,6 @@
.text
thumb_func_start sub_802C68C
sub_802C68C: @ 802C68C
push {r4-r7,lr}
mov r7, r8
push {r7}
sub sp, 0x8
movs r0, 0
mov r8, r0
ldr r7, _0802C6E4 @ =gActiveBank
ldrb r2, [r7]
lsls r0, r2, 9
ldr r1, _0802C6E8 @ =gUnknown_02023A64
adds r6, r0, r1
ldr r0, _0802C6EC @ =gMain
ldrh r1, [r0, 0x2E]
movs r5, 0x1
adds r4, r5, 0
ands r4, r1
cmp r4, 0
bne _0802C6B2
b _0802C864
_0802C6B2:
movs r0, 0x5
bl PlaySE
ldr r1, _0802C6F0 @ =gMoveSelectionCursor
ldrb r0, [r7]
adds r0, r1
ldrb r0, [r0]
lsls r0, 1
adds r1, r6, r0
ldrh r0, [r1]
cmp r0, 0xAE
bne _0802C6F4
ldrb r0, [r6, 0x12]
movs r4, 0
cmp r0, 0x7
beq _0802C702
ldrb r1, [r6, 0x13]
movs r0, 0x7
eors r1, r0
negs r0, r1
orrs r0, r1
asrs r4, r0, 31
movs r0, 0x10
ands r4, r0
b _0802C702
.align 2, 0
_0802C6E4: .4byte gActiveBank
_0802C6E8: .4byte gUnknown_02023A64
_0802C6EC: .4byte gMain
_0802C6F0: .4byte gMoveSelectionCursor
_0802C6F4:
ldr r2, _0802C714 @ =gBattleMoves
ldrh r1, [r1]
lsls r0, r1, 1
adds r0, r1
lsls r0, 2
adds r0, r2
ldrb r4, [r0, 0x6]
_0802C702:
movs r0, 0x10
ands r0, r4
cmp r0, 0
beq _0802C720
ldr r0, _0802C718 @ =gUnknown_03004344
ldr r1, _0802C71C @ =gActiveBank
ldrb r1, [r1]
strb r1, [r0]
b _0802C73A
.align 2, 0
_0802C714: .4byte gBattleMoves
_0802C718: .4byte gUnknown_03004344
_0802C71C: .4byte gActiveBank
_0802C720:
ldr r0, _0802C764 @ =gActiveBank
ldrb r0, [r0]
bl GetBankIdentity
adds r1, r0, 0
movs r2, 0x1
movs r0, 0x1
ands r0, r1
eors r0, r2
bl GetBankByPlayerAI
ldr r1, _0802C768 @ =gUnknown_03004344
strb r0, [r1]
_0802C73A:
ldr r3, _0802C76C @ =gBattleBufferA
ldr r5, _0802C764 @ =gActiveBank
ldrb r2, [r5]
lsls r1, r2, 9
adds r0, r3, 0x1
adds r0, r1, r0
ldrb r0, [r0]
cmp r0, 0
bne _0802C770
movs r0, 0x2
ands r0, r4
cmp r0, 0
beq _0802C7B2
adds r0, r3, 0x2
adds r0, r1, r0
ldrb r0, [r0]
cmp r0, 0
bne _0802C7B2
movs r2, 0x1
add r8, r2
b _0802C7B2
.align 2, 0
_0802C764: .4byte gActiveBank
_0802C768: .4byte gUnknown_03004344
_0802C76C: .4byte gBattleBufferA
_0802C770:
movs r0, 0x7D
ands r0, r4
cmp r0, 0
bne _0802C77C
movs r0, 0x1
add r8, r0
_0802C77C:
ldr r0, _0802C7D0 @ =gMoveSelectionCursor
adds r0, r2, r0
adds r1, r6, 0
adds r1, 0x8
ldrb r0, [r0]
adds r1, r0
ldrb r0, [r1]
cmp r0, 0
beq _0802C7B8
movs r0, 0x12
ands r0, r4
cmp r0, 0
bne _0802C7B2
movs r0, 0
bl CountAliveMons
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1
bhi _0802C7B2
ldrb r0, [r5]
bl sub_803C434
ldr r1, _0802C7D4 @ =gUnknown_03004344
strb r0, [r1]
movs r2, 0
mov r8, r2
_0802C7B2:
mov r0, r8
cmp r0, 0
bne _0802C7DC
_0802C7B8:
bl DestroyMenuCursor
ldr r1, _0802C7D0 @ =gMoveSelectionCursor
ldr r0, _0802C7D8 @ =gActiveBank
ldrb r0, [r0]
adds r0, r1
ldrb r2, [r0]
ldr r0, _0802C7D4 @ =gUnknown_03004344
ldrb r0, [r0]
lsls r0, 8
orrs r2, r0
b _0802C888
.align 2, 0
_0802C7D0: .4byte gMoveSelectionCursor
_0802C7D4: .4byte gUnknown_03004344
_0802C7D8: .4byte gActiveBank
_0802C7DC:
ldr r1, _0802C7F8 @ =gBattleBankFunc
ldr r2, _0802C7FC @ =gActiveBank
ldrb r0, [r2]
lsls r0, 2
adds r0, r1
ldr r1, _0802C800 @ =sub_802C2EC
str r1, [r0]
movs r0, 0x12
ands r4, r0
cmp r4, 0
beq _0802C808
ldr r1, _0802C804 @ =gUnknown_03004344
ldrb r0, [r2]
b _0802C838
.align 2, 0
_0802C7F8: .4byte gBattleBankFunc
_0802C7FC: .4byte gActiveBank
_0802C800: .4byte sub_802C2EC
_0802C804: .4byte gUnknown_03004344
_0802C808:
movs r0, 0x1
bl GetBankByPlayerAI
ldr r1, _0802C828 @ =gAbsentBankFlags
ldrb r1, [r1]
ldr r2, _0802C82C @ =gBitTable
lsls r0, 24
lsrs r0, 22
adds r0, r2
ldr r0, [r0]
ands r1, r0
cmp r1, 0
beq _0802C830
movs r0, 0x3
b _0802C832
.align 2, 0
_0802C828: .4byte gAbsentBankFlags
_0802C82C: .4byte gBitTable
_0802C830:
movs r0, 0x1
_0802C832:
bl GetBankByPlayerAI
ldr r1, _0802C854 @ =gUnknown_03004344
_0802C838:
strb r0, [r1]
ldr r2, _0802C858 @ =gSprites
ldr r1, _0802C85C @ =gObjectBankIDs
ldr r0, _0802C854 @ =gUnknown_03004344
ldrb r0, [r0]
adds r0, r1
ldrb r1, [r0]
lsls r0, r1, 4
adds r0, r1
lsls r0, 2
adds r2, 0x1C
adds r0, r2
ldr r1, _0802C860 @ =sub_8010520
b _0802CA36
.align 2, 0
_0802C854: .4byte gUnknown_03004344
_0802C858: .4byte gSprites
_0802C85C: .4byte gObjectBankIDs
_0802C860: .4byte sub_8010520
_0802C864:
movs r6, 0x2
adds r0, r6, 0
ands r0, r1
cmp r0, 0
beq _0802C8A4
bl DestroyMenuCursor
movs r0, 0x5
bl PlaySE
ldr r0, _0802C898 @ =gUnknown_030042A4
strh r4, [r0]
ldr r1, _0802C89C @ =gUnknown_030042A0
movs r2, 0xA0
lsls r2, 1
adds r0, r2, 0
strh r0, [r1]
ldr r2, _0802C8A0 @ =0x0000ffff
_0802C888:
movs r0, 0x1
movs r1, 0xA
bl dp01_build_cmdbuf_x21_a_bb
bl PlayerBufferExecCompleted
b _0802CA38
.align 2, 0
_0802C898: .4byte gUnknown_030042A4
_0802C89C: .4byte gUnknown_030042A0
_0802C8A0: .4byte 0x0000ffff
_0802C8A4:
movs r0, 0x20
ands r0, r1
cmp r0, 0
beq _0802C8D4
ldr r4, _0802C8D0 @ =gMoveSelectionCursor
adds r2, r4
ldrb r1, [r2]
adds r0, r5, 0
ands r0, r1
cmp r0, 0
bne _0802C8BC
b _0802CA38
_0802C8BC:
ldrb r0, [r2]
bl nullsub_7
ldrb r1, [r7]
adds r1, r4
ldrb r0, [r1]
movs r2, 0x1
eors r0, r2
b _0802C976
.align 2, 0
_0802C8D0: .4byte gMoveSelectionCursor
_0802C8D4:
movs r0, 0x10
ands r0, r1
cmp r0, 0
beq _0802C914
ldr r4, _0802C90C @ =gMoveSelectionCursor
adds r3, r2, r4
ldrb r2, [r3]
movs r6, 0x1
adds r0, r5, 0
ands r0, r2
cmp r0, 0
beq _0802C8EE
b _0802CA38
_0802C8EE:
ldr r1, _0802C910 @ =gUnknown_03004348
adds r0, r6, 0
eors r0, r2
ldrb r1, [r1]
cmp r0, r1
bcc _0802C8FC
b _0802CA38
_0802C8FC:
ldrb r0, [r3]
bl nullsub_7
ldrb r1, [r7]
adds r1, r4
ldrb r0, [r1]
eors r0, r6
b _0802C976
.align 2, 0
_0802C90C: .4byte gMoveSelectionCursor
_0802C910: .4byte gUnknown_03004348
_0802C914:
movs r0, 0x40
ands r0, r1
cmp r0, 0
beq _0802C944
ldr r4, _0802C940 @ =gMoveSelectionCursor
adds r2, r4
ldrb r1, [r2]
adds r0, r6, 0
ands r0, r1
cmp r0, 0
bne _0802C92C
b _0802CA38
_0802C92C:
ldrb r0, [r2]
bl nullsub_7
ldrb r1, [r7]
adds r1, r4
ldrb r0, [r1]
movs r2, 0x2
eors r0, r2
b _0802C976
.align 2, 0
_0802C940: .4byte gMoveSelectionCursor
_0802C944:
movs r0, 0x80
ands r0, r1
cmp r0, 0
beq _0802C99C
ldr r4, _0802C994 @ =gMoveSelectionCursor
adds r3, r2, r4
ldrb r2, [r3]
movs r5, 0x2
adds r0, r6, 0
ands r0, r2
cmp r0, 0
bne _0802CA38
ldr r1, _0802C998 @ =gUnknown_03004348
adds r0, r5, 0
eors r0, r2
ldrb r1, [r1]
cmp r0, r1
bcs _0802CA38
ldrb r0, [r3]
bl nullsub_7
ldrb r1, [r7]
adds r1, r4
ldrb r0, [r1]
eors r0, r5
_0802C976:
strb r0, [r1]
movs r0, 0x5
bl PlaySE
ldrb r0, [r7]
adds r0, r4
ldrb r0, [r0]
movs r1, 0
bl sub_802E3B4
bl sub_802E220
bl sub_802E2D4
b _0802CA38
.align 2, 0
_0802C994: .4byte gMoveSelectionCursor
_0802C998: .4byte gUnknown_03004348
_0802C99C:
movs r0, 0x4
ands r0, r1
cmp r0, 0
beq _0802CA38
ldr r0, _0802C9D8 @ =gUnknown_03004348
ldrb r0, [r0]
cmp r0, 0x1
bls _0802CA38
ldr r0, _0802C9DC @ =gBattleTypeFlags
ldrh r1, [r0]
adds r0, r6, 0
ands r0, r1
lsls r0, 16
lsrs r5, r0, 16
cmp r5, 0
bne _0802CA38
ldr r4, _0802C9E0 @ =gMoveSelectionCursor
adds r0, r2, r4
ldrb r0, [r0]
ldr r1, _0802C9E4 @ =gUnknown_081FAE80
bl sub_802E12C
ldrb r0, [r7]
adds r0, r4
ldrb r0, [r0]
cmp r0, 0
beq _0802C9EC
ldr r0, _0802C9E8 @ =gUnknown_03004344
strb r5, [r0]
b _0802C9F4
.align 2, 0
_0802C9D8: .4byte gUnknown_03004348
_0802C9DC: .4byte gBattleTypeFlags
_0802C9E0: .4byte gMoveSelectionCursor
_0802C9E4: .4byte gUnknown_081FAE80
_0802C9E8: .4byte gUnknown_03004344
_0802C9EC:
ldr r1, _0802CA44 @ =gUnknown_03004344
adds r0, 0x1
strb r0, [r1]
adds r0, r1, 0
_0802C9F4:
ldrb r0, [r0]
movs r1, 0x1B
bl sub_802E3B4
ldr r4, _0802CA48 @ =gUnknown_03004210
ldr r1, _0802CA4C @ =0x00001016
movs r0, 0x1C
str r0, [sp]
movs r0, 0x3A
str r0, [sp, 0x4]
adds r0, r4, 0
movs r2, 0x17
movs r3, 0x37
bl FillWindowRect
ldr r1, _0802CA50 @ =gUnknown_08400D89
movs r2, 0xA4
lsls r2, 2
movs r0, 0x37
str r0, [sp]
adds r0, r4, 0
movs r3, 0x17
bl InitWindow
adds r0, r4, 0
bl sub_8002F44
ldr r1, _0802CA54 @ =gBattleBankFunc
ldr r0, _0802CA58 @ =gActiveBank
ldrb r0, [r0]
lsls r0, 2
adds r0, r1
ldr r1, _0802CA5C @ =sub_802CA60
_0802CA36:
str r1, [r0]
_0802CA38:
add sp, 0x8
pop {r3}
mov r8, r3
pop {r4-r7}
pop {r0}
bx r0
.align 2, 0
_0802CA44: .4byte gUnknown_03004344
_0802CA48: .4byte gUnknown_03004210
_0802CA4C: .4byte 0x00001016
_0802CA50: .4byte gUnknown_08400D89
_0802CA54: .4byte gBattleBankFunc
_0802CA58: .4byte gActiveBank
_0802CA5C: .4byte sub_802CA60
thumb_func_end sub_802C68C
thumb_func_start sub_802CA60
sub_802CA60: @ 802CA60
push {r4-r7,lr}

View File

@ -9,6 +9,7 @@
#include "rom3.h"
#include "songs.h"
#include "sound.h"
#include "text.h"
#include "util.h"
extern u8 gActiveBank;
@ -25,6 +26,11 @@ extern u8 gUnknown_03004344;
extern u8 gNoOfAllBanks;
extern u16 gBattlePartyID[];
extern const struct BattleMove gBattleMoves[];
extern u16 gUnknown_030042A0;
extern u16 gUnknown_030042A4;
extern struct Window gUnknown_03004210;
extern const u8 gUnknown_08400D89[];
extern u8 gUnknown_03004348;
extern void dp11b_obj_instanciate(u8, u8, s8, s8);
extern u8 GetBankIdentity(u8);
@ -32,6 +38,11 @@ extern u8 GetBankByPlayerAI(u8);
extern void dp11b_obj_free(u8, u8);
extern void sub_8010520(struct Sprite *);
extern void sub_8010574(struct Sprite *);
extern void nullsub_7(u8);
extern void sub_802E3B4();
extern void sub_802E220();
extern void sub_802E2D4();
extern void sub_802E12C();
void PlayerHandleGetAttributes(void);
void sub_802ECF0(void);
@ -154,9 +165,12 @@ void (*const gPlayerBufferCommands[])(void) =
nullsub_43,
};
extern const u8 gUnknown_081FAE80[];
void PlayerBufferRunCommand(void);
void sub_802C2EC(void);
void sub_802C68C(void);
void sub_802CA60(void);
void nullsub_91(void)
{
@ -431,3 +445,147 @@ void sub_802C2EC(void)
gSprites[gObjectBankIDs[gUnknown_03004344]].callback = sub_8010520;
}
}
struct UnknownStruct1
{
u16 unk0[4];
u8 unk8[4];
u8 fillerC[0x12-0xC];
u8 unk12;
u8 unk13;
};
void sub_802C68C(void)
{
u32 r8 = 0;
struct UnknownStruct1 *r6 = (struct UnknownStruct1 *)(gBattleBufferA[gActiveBank] + 4);
if (gMain.newKeys & A_BUTTON)
{
u32 r4;
PlaySE(SE_SELECT);
if (r6->unk0[gMoveSelectionCursor[gActiveBank]] == 0xAE)
r4 = (r6->unk12 != 7 && (r6->unk13 ^ 7)) ? 0x10 : 0;
else
r4 = gBattleMoves[r6->unk0[gMoveSelectionCursor[gActiveBank]]].target;
if (r4 & 0x10)
gUnknown_03004344 = gActiveBank;
else
gUnknown_03004344 = GetBankByPlayerAI((GetBankIdentity(gActiveBank) & 1) ^ 1);
if (gBattleBufferA[gActiveBank][1] == 0)
{
if ((r4 & 2) && gBattleBufferA[gActiveBank][2] == 0)
r8++;
}
else
{
if (!(r4 & 0x7D))
r8++;
if (r6->unk8[gMoveSelectionCursor[gActiveBank]] == 0)
{
r8 = 0;
}
else if (!(r4 & 0x12) && CountAliveMons(0) <= 1)
{
gUnknown_03004344 = sub_803C434(gActiveBank);
r8 = 0;
}
}
if (r8 == 0)
{
DestroyMenuCursor();
dp01_build_cmdbuf_x21_a_bb(1, 10, gMoveSelectionCursor[gActiveBank] | (gUnknown_03004344 << 8));
PlayerBufferExecCompleted();
}
else
{
gBattleBankFunc[gActiveBank] = sub_802C2EC;
if (r4 & 0x12)
gUnknown_03004344 = gActiveBank;
else if (gAbsentBankFlags & gBitTable[GetBankByPlayerAI(1)])
gUnknown_03004344 = GetBankByPlayerAI(3);
else
gUnknown_03004344 = GetBankByPlayerAI(1);
gSprites[gObjectBankIDs[gUnknown_03004344]].callback = sub_8010520;
}
}
else if (gMain.newKeys & B_BUTTON)
{
DestroyMenuCursor();
PlaySE(SE_SELECT);
gUnknown_030042A4 = 0;
gUnknown_030042A0 = 320;
dp01_build_cmdbuf_x21_a_bb(1, 10, 0xFFFF);
PlayerBufferExecCompleted();
}
else if (gMain.newKeys & DPAD_LEFT)
{
if (gMoveSelectionCursor[gActiveBank] & 1)
{
nullsub_7(gMoveSelectionCursor[gActiveBank]);
gMoveSelectionCursor[gActiveBank] ^= 1;
PlaySE(SE_SELECT);
sub_802E3B4(gMoveSelectionCursor[gActiveBank], 0);
sub_802E220();
sub_802E2D4();
}
}
else if (gMain.newKeys & DPAD_RIGHT)
{
if (!(gMoveSelectionCursor[gActiveBank] & 1)
&& (gMoveSelectionCursor[gActiveBank] ^ 1) < gUnknown_03004348)
{
nullsub_7(gMoveSelectionCursor[gActiveBank]);
gMoveSelectionCursor[gActiveBank] ^= 1;
PlaySE(SE_SELECT);
sub_802E3B4(gMoveSelectionCursor[gActiveBank], 0);
sub_802E220();
sub_802E2D4();
}
}
else if (gMain.newKeys & DPAD_UP)
{
if (gMoveSelectionCursor[gActiveBank] & 2)
{
nullsub_7(gMoveSelectionCursor[gActiveBank]);
gMoveSelectionCursor[gActiveBank] ^= 2;
PlaySE(SE_SELECT);
sub_802E3B4(gMoveSelectionCursor[gActiveBank], 0);
sub_802E220();
sub_802E2D4();
}
}
else if (gMain.newKeys & DPAD_DOWN)
{
if (!(gMoveSelectionCursor[gActiveBank] & 2)
&& (gMoveSelectionCursor[gActiveBank] ^ 2) < gUnknown_03004348)
{
nullsub_7(gMoveSelectionCursor[gActiveBank]);
gMoveSelectionCursor[gActiveBank] ^= 2;
PlaySE(SE_SELECT);
sub_802E3B4(gMoveSelectionCursor[gActiveBank], 0);
sub_802E220();
sub_802E2D4();
}
}
else if (gMain.newKeys & SELECT_BUTTON)
{
if (gUnknown_03004348 > 1 && !(gBattleTypeFlags & BATTLE_TYPE_LINK))
{
sub_802E12C(gMoveSelectionCursor[gActiveBank], gUnknown_081FAE80);
if (gMoveSelectionCursor[gActiveBank] != 0)
gUnknown_03004344 = 0;
else
gUnknown_03004344 = gMoveSelectionCursor[gActiveBank] + 1;
sub_802E3B4(gUnknown_03004344, 27);
FillWindowRect(&gUnknown_03004210, 0x1016, 0x17, 0x37, 0x1C, 0x3A);
InitWindow(&gUnknown_03004210, gUnknown_08400D89, 0x290, 0x17, 0x37);
sub_8002F44(&gUnknown_03004210);
gBattleBankFunc[gActiveBank] = sub_802CA60;
}
}
}