some more decomp + documenting

This commit is contained in:
Dennis H
2023-01-17 21:30:56 +01:00
parent 4844237add
commit 07eebda696
8 changed files with 154 additions and 326 deletions

View File

@@ -2776,7 +2776,7 @@ _08020460:
adds r1, r2, 0
adds r1, 0x24
adds r2, 0x64
bl sub_8093560
bl GetLinkedSequence
_0802046E:
ldr r0, [r5]
adds r0, 0x64

View File

@@ -1565,7 +1565,7 @@ _080263E0:
adds r1, r2, 0
adds r1, 0x28
adds r2, 0x68
bl sub_8093560
bl GetLinkedSequence
ldr r0, [r4]
adds r0, 0x68
bl sub_801F808

View File

@@ -77,7 +77,7 @@ _0801EAB4:
ldr r0, [r2, 0x20]
ldr r1, [r2, 0x10]
adds r2, 0x14
bl sub_8093560
bl GetLinkedSequence
ldr r0, [r4]
adds r0, 0x14
bl sub_801F808

View File

@@ -5,292 +5,6 @@
.text
thumb_func_start sub_8093784
sub_8093784:
push {r4-r7,lr}
adds r6, r0, 0
movs r2, 0
movs r4, 0
_0809378C:
lsls r0, r2, 5
adds r2, 0x1
movs r3, 0x3
adds r0, r1
adds r0, 0x18
_08093796:
strb r4, [r0]
subs r0, 0x8
subs r3, 0x1
cmp r3, 0
bge _08093796
cmp r2, 0x3
ble _0809378C
movs r3, 0
movs r5, 0
adds r4, r1, 0
subs r4, 0x20
movs r7, 0x2
_080937AE:
cmp r5, 0
beq _080937BC
ldrb r1, [r6]
adds r0, r7, 0
ands r0, r1
cmp r0, 0
bne _080937C0
_080937BC:
adds r4, 0x20
movs r3, 0
_080937C0:
lsls r2, r3, 3
adds r2, r4
ldm r6!, {r0,r1}
str r0, [r2]
str r1, [r2, 0x4]
ldrb r1, [r2]
movs r0, 0xFD
ands r0, r1
strb r0, [r2]
adds r3, 0x1
adds r5, 0x1
cmp r5, 0x3
ble _080937AE
pop {r4-r7}
pop {r0}
bx r0
thumb_func_end sub_8093784
thumb_func_start sub_80937E0
sub_80937E0:
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x10
str r0, [sp, 0x8]
mov r9, r1
movs r0, 0
mov r8, r0
movs r6, 0
add r1, sp, 0x4
mov r10, r1
mov r12, r6
movs r3, 0x1
_080937FE:
mov r2, sp
adds r0, r2, r6
mov r7, r12
strb r7, [r0]
mov r1, sp
adds r1, r6
adds r1, 0x4
mov r2, r12
strb r2, [r1]
adds r7, r0, 0
lsls r0, r6, 5
adds r6, 0x1
adds r5, r1, 0
mov r1, r9
adds r2, r0, r1
movs r4, 0x3
_0809381E:
ldrb r1, [r2]
adds r0, r3, 0
ands r0, r1
cmp r0, 0
beq _0809383E
movs r0, 0x8
ands r0, r1
cmp r0, 0
beq _08093832
strb r3, [r7]
_08093832:
ldrb r1, [r2]
movs r0, 0x4
ands r0, r1
cmp r0, 0
beq _0809383E
strb r3, [r5]
_0809383E:
adds r2, 0x8
subs r4, 0x1
cmp r4, 0
bge _0809381E
cmp r6, 0x3
ble _080937FE
movs r6, 0
mov r2, r8
lsls r2, 3
str r2, [sp, 0xC]
_08093852:
movs r4, 0
lsls r0, r6, 5
mov r7, r9
adds r5, r0, r7
ldr r0, [sp, 0xC]
ldr r1, [sp, 0x8]
adds r2, r0, r1
mov r7, r10
adds r7, r6
mov r12, r7
_08093866:
ldrb r1, [r5]
movs r0, 0x1
ands r0, r1
cmp r0, 0
beq _080938D6
ldr r0, [r5]
ldr r1, [r5, 0x4]
str r0, [r2]
str r1, [r2, 0x4]
cmp r4, 0
bne _08093884
ldrb r1, [r2]
movs r0, 0xFD
ands r0, r1
b _0809388A
_08093884:
ldrb r0, [r2]
movs r1, 0x2
orrs r0, r1
_0809388A:
strb r0, [r2]
ldrb r0, [r2]
movs r3, 0xF7
ands r3, r0
movs r1, 0
movs r0, 0xFB
ands r3, r0
strb r3, [r2]
mov r7, sp
adds r0, r7, r6
ldrb r0, [r0]
cmp r0, 0
beq _080938B0
cmp r4, 0
bne _080938B0
movs r1, 0x8
adds r0, r3, 0
orrs r0, r1
strb r0, [r2]
_080938B0:
mov r1, r12
ldrb r0, [r1]
cmp r0, 0
beq _080938C4
cmp r4, 0
bne _080938C4
ldrb r0, [r2]
movs r1, 0x4
orrs r0, r1
strb r0, [r2]
_080938C4:
adds r2, 0x8
ldr r7, [sp, 0xC]
adds r7, 0x8
str r7, [sp, 0xC]
movs r0, 0x1
add r8, r0
mov r1, r8
cmp r1, 0x4
beq _080938E4
_080938D6:
adds r5, 0x8
adds r4, 0x1
cmp r4, 0x3
ble _08093866
adds r6, 0x1
cmp r6, 0x3
ble _08093852
_080938E4:
add sp, 0x10
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
thumb_func_end sub_80937E0
thumb_func_start sub_80938F4
sub_80938F4:
push {r4-r7,lr}
adds r7, r0, 0
movs r4, 0
movs r6, 0x1
movs r5, 0x80
_080938FE:
movs r3, 0
lsls r0, r4, 6
adds r2, r0, r7
_08093904:
ldrb r1, [r2]
adds r0, r6, 0
ands r0, r1
cmp r0, 0
beq _0809391A
adds r0, r5, 0
ands r0, r1
cmp r0, 0
beq _0809391A
adds r0, r4, 0
b _0809392C
_0809391A:
adds r2, 0x8
adds r3, 0x1
cmp r3, 0x7
ble _08093904
adds r4, 0x1
cmp r4, 0x7
ble _080938FE
movs r0, 0x1
negs r0, r0
_0809392C:
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end sub_80938F4
thumb_func_start sub_8093934
sub_8093934:
push {r4-r7,lr}
adds r7, r0, 0
movs r4, 0
movs r6, 0x1
movs r5, 0x80
_0809393E:
movs r3, 0
lsls r0, r4, 6
adds r2, r0, r7
_08093944:
ldrb r1, [r2]
adds r0, r6, 0
ands r0, r1
cmp r0, 0
beq _0809395A
adds r0, r5, 0
ands r0, r1
cmp r0, 0
beq _0809395A
adds r0, r4, 0
b _0809396C
_0809395A:
adds r2, 0x8
adds r3, 0x1
cmp r3, 0x7
ble _08093944
adds r4, 0x1
cmp r4, 0x7
ble _0809393E
movs r0, 0x1
negs r0, r0
_0809396C:
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end sub_8093934
thumb_func_start sub_8093974
sub_8093974:

View File

@@ -10,7 +10,8 @@ enum MoveFlag
MOVE_FLAG_ENABLED = 1 << 2, // Enabled for the AI to use.
MOVE_FLAG_SET = 1 << 3, // This move can be triggered by pressing L+A instead of having to go to the move menu.
MOVE_FLAG_LAST_USED = 1 << 4, // The most recent move used by the Pokémon.
MOVE_FLAG_DISABLED = 1 << 5 // Disabled by an effect like Taunt.
MOVE_FLAG_DISABLED = 1 << 5, // Disabled by an effect like Taunt.
MOVE_FLAG_UNK80 = 1 << 7
};
enum MoveFlag2

View File

@@ -27,7 +27,7 @@ extern void sub_8023B7C(u32);
extern void sub_8023DA4();
extern void sub_8024458(s16, u32);
extern void sub_801BEEC(s16);
extern void sub_8093560(u32, struct PokemonMove *, u16*);
extern void GetLinkedSequence(u32, struct PokemonMove *, u16*);
extern void sub_801F808(u16*);
extern void sub_8027794();
extern void sub_801A5D8(u32, u32, u32, u32);
@@ -229,7 +229,7 @@ void sub_8027274(void)
sub_8014248(gUnknown_80DD7FC,0,3,gUnknown_203B2BC->menuItems,0,4,0,0,0x101);
break;
case 0x10:
sub_8093560(gUnknown_203B2BC->moveData20.moveIndex,gUnknown_203B2BC->moveData20.moves,gUnknown_203B2BC->moveData20.moveIDs);
GetLinkedSequence(gUnknown_203B2BC->moveData20.moveIndex,gUnknown_203B2BC->moveData20.moves,gUnknown_203B2BC->moveData20.moveIDs);
sub_801F808(gUnknown_203B2BC->moveData20.moveIDs);
break;
case 6:

View File

@@ -82,7 +82,7 @@ extern void sub_8023DA4(void);
extern void sub_809401C(struct PokemonMove *, struct PokemonMove *); // TODO convert arg 0 to PokemonMove struct *
extern void sub_801EE10(u32, s16, struct PokemonMove *, u32, u32, u32);
extern void sub_8093560(u32, struct PokemonMove *, u16*);
extern void GetLinkedSequence(u32, struct PokemonMove *, u16*);
extern void sub_801F808(u16 *);
u32 sub_801602C(u32 r0, u8 *name);
extern void sub_8025E68(u32 , u32 *);
@@ -283,7 +283,7 @@ void sub_8025518(void)
sub_801F1B0(1,0);
break;
case 0x11:
sub_8093560(gUnknown_203B2B4->moveData20.moveIndex,gUnknown_203B2B4->moveData20.moves, gUnknown_203B2B4->moveData20.moveIDs);
GetLinkedSequence(gUnknown_203B2B4->moveData20.moveIndex,gUnknown_203B2B4->moveData20.moves, gUnknown_203B2B4->moveData20.moveIDs);
sub_801F808(gUnknown_203B2B4->moveData20.moveIDs);
break;
case 0x12:

View File

@@ -10,8 +10,8 @@ u8 sub_80933D8(int param_1, void* src_struct);
bool8 DoesMoveCharge(u16 move);
// second arg should be some sort of struct pointer
void sub_8093784(int, u8*);
void sub_80937E0(int, u8*);
void sub_8093784(struct PokemonMove* moves, struct PokemonMove moveSets[4][4]);
void sub_80937E0(struct PokemonMove* moves, struct PokemonMove moveSets[4][4]);
void sub_8093974(int, u8*);
void sub_8093A2C(int, u8*);
@@ -208,70 +208,70 @@ int ToggleMoveEnabled(int index, struct PokemonMove* moves) {
return 1;
}
int sub_8093560(int index, struct PokemonMove* moves, u16* dest) {
int GetLinkedSequence(int index, struct PokemonMove* moves, u16* sequenceMoveIDs) {
int i;
int counter;
int linkedSequenceLength;
struct PokemonMove* move;
counter = 1;
linkedSequenceLength = 1;
move = &moves[index];
dest[0] = move->moveID;
sequenceMoveIDs[0] = move->moveID;
for (i = 1; i < 4; i++) {
dest[i] = 0;
sequenceMoveIDs[i] = 0;
}
for (index++, dest++; index < 8 && counter <= 3; index++) {
for (index++, sequenceMoveIDs++; index < 8 && linkedSequenceLength <= 3; index++) {
move = &moves[index];
if ((move->moveFlags & MOVE_FLAG_LINKED) == 0) {
return counter;
return linkedSequenceLength;
}
*dest++ = move->moveID;
counter++;
*sequenceMoveIDs++ = move->moveID;
linkedSequenceLength++;
}
return counter;
return linkedSequenceLength;
}
int sub_80935B8(struct PokemonMove *moves, int index) {
int i;
int last_index;
int for_loop_any1;
int linkSequenceStart;
int isNonTrivialLinkSequence;
int any_move_linked;
int pp;
int v1;
pp = 99;
any_move_linked = 0;
for_loop_any1 = 0;
isNonTrivialLinkSequence = 0;
last_index = index;
while (last_index >= 0) {
struct PokemonMove *move = &moves[last_index];
linkSequenceStart = index;
while (linkSequenceStart >= 0) {
struct PokemonMove *move = &moves[linkSequenceStart];
if (!((move->moveFlags & MOVE_FLAG_EXISTS) && (move->moveFlags & MOVE_FLAG_LINKED))) {
break;
}
last_index--;
linkSequenceStart--;
}
// this is so stupid but it works
for_loop_any1++;for_loop_any1--;
isNonTrivialLinkSequence++;isNonTrivialLinkSequence--;
for (i = last_index + 1; i < 4; i++) {
for (i = linkSequenceStart + 1; i < 4; i++) {
struct PokemonMove *move = &moves[i];
if (!((move->moveFlags & MOVE_FLAG_EXISTS) && (move->moveFlags & MOVE_FLAG_LINKED))) {
break;
}
for_loop_any1 = 1;
isNonTrivialLinkSequence = 1;
}
if (!for_loop_any1) {
if (!isNonTrivialLinkSequence) {
return 99;
}
v1 = 0;
while (--i >= last_index) {
while (--i >= linkSequenceStart) {
struct PokemonMove* move = &moves[i];
if (!(move->moveFlags & MOVE_FLAG_EXISTS)) {
break;
@@ -279,7 +279,7 @@ int sub_80935B8(struct PokemonMove *moves, int index) {
if (pp > move->PP) {
pp = move->PP;
}
if (!move->PP) {
if (move->PP == 0) {
v1 = 1;
}
if (move->moveFlags2 & MOVE_FLAG_REPLACE) {
@@ -291,7 +291,7 @@ int sub_80935B8(struct PokemonMove *moves, int index) {
return pp;
}
for (i = last_index + 1; i < 4; i++) {
for (i = linkSequenceStart + 1; i < 4; i++) {
struct PokemonMove* move = &moves[i];
if (!(moves[i].moveFlags & MOVE_FLAG_EXISTS)) {
break;
@@ -314,10 +314,10 @@ int sub_80935B8(struct PokemonMove *moves, int index) {
}
}
void sub_80936D8(int index) {
u8 someStruct[0x80];
sub_8093784(index, someStruct);
sub_80937E0(index, someStruct);
void sub_80936D8(struct PokemonMove* moves) {
struct PokemonMove someStruct[4][4];
sub_8093784(moves, someStruct);
sub_80937E0(moves, someStruct);
}
void sub_80936F4(int index) {
@@ -333,12 +333,12 @@ void sub_809371C(struct PokemonMove* move) {
sub_8093B40(move, moves);
}
int sub_8093744(struct PokemonMove moves[4][4], int index) {
int sub_8093744(struct PokemonMove moves[4][4]) {
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
if ((moves[i][j].moveFlags & 1) && (moves[i][j].moveFlags & 0x80)) {
if ((moves[i][j].moveFlags & MOVE_FLAG_EXISTS) && (moves[i][j].moveFlags & MOVE_FLAG_UNK80)) {
return i;
}
}
@@ -346,3 +346,116 @@ int sub_8093744(struct PokemonMove moves[4][4], int index) {
return -1;
}
void sub_8093784(struct PokemonMove* moves, struct PokemonMove moveSets[4][4]) {
int i, j;
int k;
int moveSetIndex;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
moveSets[i][j].moveFlags = 0;
}
}
moveSetIndex = -1;
for (j = 0, k = 0; k < 4; j++, k++) {
if (k == 0 || !(moves[k].moveFlags & MOVE_FLAG_LINKED)) {
moveSetIndex++;
j = 0;
}
moveSets[moveSetIndex][j] = moves[k];
moveSets[moveSetIndex][j].moveFlags &= ~MOVE_FLAG_LINKED;
}
}
void sub_80937E0(struct PokemonMove* moves, struct PokemonMove moveSets[4][4]) {
int i, j;
int movesCopied;
bool8 moveFlags8[4];
bool8 moveFlags4[4];
movesCopied = 0;
for (i = 0; i < 4; i++) {
moveFlags8[i] = 0;
moveFlags4[i] = 0;
for (j = 0; j < 4; j++) {
u8 flag;
if (!(moveSets[i][j].moveFlags & MOVE_FLAG_EXISTS)) {
continue;
}
flag = MOVE_FLAG_SET;
flag &= moveSets[i][j].moveFlags;
if (flag) {
moveFlags8[i] = TRUE;
}
if (moveSets[i][j].moveFlags & MOVE_FLAG_ENABLED) {
moveFlags4[i] = TRUE;
}
}
}
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
if (moveSets[i][j].moveFlags & MOVE_FLAG_EXISTS) {
moves[movesCopied] = moveSets[i][j];
if (j == 0) {
moves[movesCopied].moveFlags &= ~MOVE_FLAG_LINKED;
}
else {
moves[movesCopied].moveFlags |= MOVE_FLAG_LINKED;
}
moves[movesCopied].moveFlags &= ~MOVE_FLAG_SET;
moves[movesCopied].moveFlags &= ~MOVE_FLAG_ENABLED;
if (moveFlags8[i] && (j == 0)) {
moves[movesCopied].moveFlags |= MOVE_FLAG_SET;
}
if (moveFlags4[i] && (j == 0)) {
moves[movesCopied].moveFlags |= MOVE_FLAG_ENABLED;
}
movesCopied++;
if (movesCopied == 4) {
return;
}
}
}
}
}
// the next two functions are exactly the same
int sub_80938F4(struct PokemonMove moveSets[8][8]) {
int i, j;
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if ((moveSets[i][j].moveFlags & MOVE_FLAG_EXISTS) && (moveSets[i][j].moveFlags & MOVE_FLAG_UNK80)) {
return i;
}
}
}
return -1;
}
// I expect the intent was to check for a different flag in this one
int sub_8093934(struct PokemonMove moveSets[8][8]) {
int i, j;
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if ((moveSets[i][j].moveFlags & MOVE_FLAG_EXISTS) && (moveSets[i][j].moveFlags & MOVE_FLAG_UNK80)) {
return i;
}
}
}
return -1;
}