Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 96 additions & 12 deletions src/battle/battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const s32 D_800A0108 = 21;
const s32 D_800A010C[] = {2, 22, 3, 23, 4};

// entrypoint

s32 func_800AD8DC(s32); // extern

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A1158);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A1798);
Expand Down Expand Up @@ -357,6 +360,9 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A5250);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A555C);

extern s32 D_800F3A40;
extern s32 D_800F3A42;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have these moved in battle_private.h


INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A55BC);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A55F4);
Expand Down Expand Up @@ -444,25 +450,51 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A68FC);

void func_800A6A3C(s32 arg0, s32 arg1) { D_800F5BB8[arg0].unkE |= arg1; }

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6A70);
void func_800A555C(); // extern

void func_800A6A70(s32 arg0) {
s32 temp_v1;

func_800A555C();
temp_v1 = arg0 * 0x44;
*(&D_800F5BB8->unkE + temp_v1) = *(&D_800F5BB8->unkE + temp_v1) | 9;
Comment on lines +459 to +460
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
temp_v1 = arg0 * 0x44;
*(&D_800F5BB8->unkE + temp_v1) = *(&D_800F5BB8->unkE + temp_v1) | 9;
D_800F5BB8[arg0].unkE |= 9;

I believe this array access could be simplified, and s32 temp_v1; removed

}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6AC4);
void func_800A6AC4(void) {
D_800F5F44.D_800F7DC4 &= 0xFC0F;
D_800F5F44.D_800F7DCA = D_800F5F44.D_800F7DCA & 0xFC0F;
D_800F5F44.D_800F7DAC = D_800F5F44.D_800F7DAC & 0xFC0F;
D_800F5F44.D_800F7DC2 = D_800F5F44.D_800F7DC2 & 0xFC0F;
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6B1C);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6B88);

void func_800A6BFC(void) {}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6C04);
void func_800A6C04(s32 arg0) {
s16 sp10;

sp10 = (s16)D_801636B8[arg0].D_801636B8;
D_800F5F44.D_800F7DBE = func_800A5EB0(func_800151F4(0x26), &sp10) + 0x100;
D_800F5F44.D_800F7DC0 = 0xF;
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6C5C);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6CC0);

void func_800A6D10(s32 arg0) { func_800A3E98(arg0, 3, 2, 54, 0); }

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6D3C);
void func_800A6D3C(s32 arg0) {
s32 temp_v1;

temp_v1 = D_800F83E0[arg0].unk0;
if (temp_v1 & 0x2000) {
D_800F83E0[arg0].unk0 = (temp_v1 & ~0x2000) | 0x4000;
}
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A6D88);

Expand All @@ -485,7 +517,12 @@ void func_800A7034(s32 arg0, s16 arg1) {

void func_800A7060(s32 arg0, s32 arg1) { func_800A7254(0, arg0, 12, arg1); }

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A7090);
void func_800A7090(s32 arg0) {
s32 temp_v1;

temp_v1 = arg0 * 0x44;
*(&D_800F5BB8->unk29 + temp_v1) = *(&D_800F5BB8->unk29 + temp_v1) | 0x40;
}
Comment on lines +520 to +525
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void func_800A7090(s32 arg0) {
s32 temp_v1;
temp_v1 = arg0 * 0x44;
*(&D_800F5BB8->unk29 + temp_v1) = *(&D_800F5BB8->unk29 + temp_v1) | 0x40;
}
void func_800A7090(s32 arg0) {
D_800F5BB8[arg0].unk29 |= 0x40;
}

This should match. Most of the decompilation stuff is not only about getting a 1:1 match, but also trying to understand the original dev intention and how they could've written the code.


INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A70C4);

Expand Down Expand Up @@ -571,9 +608,17 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A866C);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A8A6C);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A8C94);
void func_800A8C94(void) {
D_80063014->unk8C = 0xFF;
D_80063014->unk40 = 0xB0;
D_80063014->unk80 |= 1;
D_80063014->unk3C = (s32)D_80063014->unk3C >> 1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
D_80063014->unk3C = (s32)D_80063014->unk3C >> 1;
D_80063014->unk3C = D_80063014->unk3C >> 1;

(s32) can be deleted. Most casts can actually be removed to make the code more readable.

Suggested change
D_80063014->unk3C = (s32)D_80063014->unk3C >> 1;
D_80063014->unk3C >>= 1;

the expression could even be further simplified

}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800A8CC8);
void func_800A8CC8(void) {
D_80063014->unk6C &= ~0x2000;
D_80063014->unk3C /= 3;
}

void func_800A8D04(void) { D_80063014->unk48 = 2; }

Expand Down Expand Up @@ -804,7 +849,15 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800AD73C);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800AD804);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800AD890);
s32 func_800AD890(s32 arg0) {
s32 var_a0;

var_a0 = arg0;
if (D_80063014->unk228 & 0x10) {
var_a0 -= (var_a0 * 3) / 10;
}
return var_a0;
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800AD8DC);

Expand All @@ -823,7 +876,15 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800ADDE8);

void func_800ADE5C(void) { D_80063014->unk214 = D_80063014->unk48 * 20; }

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800ADE84);
void func_800ADE84(void) {
s32 var_v1;

var_v1 = D_80063014->unk48 * (0x200 - D_80063014->unk210);
if (var_v1 < 0) {
var_v1 += 0x1F;
}
D_80063014->unk214 = func_800AD8DC(var_v1 >> 5);
Comment on lines +879 to +886
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void func_800ADE84(void) {
s32 var_v1;
var_v1 = D_80063014->unk48 * (0x200 - D_80063014->unk210);
if (var_v1 < 0) {
var_v1 += 0x1F;
}
D_80063014->unk214 = func_800AD8DC(var_v1 >> 5);
void func_800ADE84(void) {
s32 var_v1;
var_v1 = D_80063014->unk48 * (0x200 - D_80063014->unk210);
D_80063014->unk214 = func_800AD8DC(var_v1 / 32);

When you see expressions such as this, it usually suggests it's a compiler optimization for signed division. I am not sure if you even need var_v1

}

void func_800ADED8(void) {
if (D_80063014->unk230 & 0x40) {
Expand Down Expand Up @@ -977,9 +1038,30 @@ void func_800B0DF8(void) {
}
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800B0E5C);
s32 func_800B0E5C(s32 arg0) {
s32 var_a0;

var_a0 = arg0;
if ((var_a0 < 0xFF) && (D_80063014->unkC8 & 0x20)) {
var_a0 -= (var_a0 * 3) / 10;
}
return var_a0;
}

s32 func_800B0EB4(s32 arg0) {
s32 temp_v1;
s32 var_a0;

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800B0EB4);
temp_v1 = D_800F83E0[arg0].unk0;
var_a0 = arg0 < 4;
if (temp_v1 & 0x40) {
var_a0 += 1;
}
if (temp_v1 & 0x400000) {
var_a0 += 1;
}
return var_a0 & 1;
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800B0F04);

Expand Down Expand Up @@ -1074,7 +1156,9 @@ u8 func_800B2F30(void) { return func_80014B70(); }

u16 func_800B2F50(void) { return func_80014BE4(); }

INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800B2F70);
s32 func_800B2F70(void) {
return (((func_800B2F50() & 0xFFFF) * 0x63) / 65535) + 1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (((func_800B2F50() & 0xFFFF) * 0x63) / 65535) + 1;
return ((func_800B2F50() & 0xFFFF) * 99) / 65535 + 1;

should be a little nicer.

Suggested change
return (((func_800B2F50() & 0xFFFF) * 0x63) / 65535) + 1;
return (func_800B2F50() * 99) / 65535 + 1;

there might even be the possibility you don't need the & 0xFFFF at all. But I did not test it locally yet.

}

static s32 func_800B2FC4(s32 arg0) {
return (arg0 * (func_800B2F30() + 0xF01)) >> 12;
Expand Down
52 changes: 48 additions & 4 deletions src/battle/battle1.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ static void func_800BB864(void);
static void func_800C4D10(void);
DR_MODE* func_800C4DC8(s16 x, s16 y, s16 w, s16 h, s32*);

extern s8 D_800F8374;
extern s8 D_800F837C;
extern s8 D_800F8380;
extern s32 D_800F9F30;
extern s8 D_801031E0;
extern s8 D_801517C4;
extern s8 D_801620A0;
extern s8 D_801620A4;
extern s8 D_80162974;
extern s8 D_80163B38;
Comment on lines +21 to +30
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have these moved in battle_private.h


s16 SquareRoot0(s32, s16); // extern
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s16 SquareRoot0(s32, s16); // extern
s16 SquareRoot0(s32, s16);

For all of these, have the // extern comment stripped out


void func_800B30E4(void) {
s32 i;

Expand Down Expand Up @@ -162,6 +175,9 @@ static void func_800B3DBC(void) {
}
}

void func_800BC1E0(u8); // extern
void func_800C5BEC(); // extern

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800B3E2C);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800B3FAC);
Expand Down Expand Up @@ -590,13 +606,34 @@ static void func_800BB944(void) {
func_8002DA7C();
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800BB978);
void func_800BB978(void) {
*D_8009A000 = 0xC1;
*D_8009A004 = 0x12C;
*D_8009A008 = 0;
func_8002DA7C();
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800BB9B8);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800BB9FC);
void func_800BB9FC(s32 arg0) {
s32 temp_a0;

*D_8009A000 = 0x2B;
temp_a0 = arg0 & 0xFFFF;
*D_8009A004 = 0x40;
*D_8009A008 = temp_a0;
func_8002DA7C(temp_a0);
Comment on lines +618 to +625
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void func_800BB9FC(s32 arg0) {
s32 temp_a0;
*D_8009A000 = 0x2B;
temp_a0 = arg0 & 0xFFFF;
*D_8009A004 = 0x40;
*D_8009A008 = temp_a0;
func_8002DA7C(temp_a0);
void func_800BB9FC(s32 arg0) {
*D_8009A000 = 0x2B;
*D_8009A004 = 0x40;
*D_8009A008 = arg0 & 0xFFFF;
func_8002DA7C();

func_8002DA7C should be void func_8002DA7C(void) according to how func_800BB978 uses it. Sometimes the decompiler gets a bit confused if a function accepts parameters or not.

I also inlined *D_8009A008 = arg0 & 0xFFFF;. There's a possibility it could also match without the & 0xFFFF if s32 arg0 gets changed to u16 arg0

}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800BBA40);
void func_800BBA40(s32 arg0) {
s32 temp_a0;

*D_8009A000 = 0x20;
temp_a0 = arg0 & 0xFFFF;
*D_8009A004 = 0x40;
*D_8009A008 = temp_a0;
func_8002DA7C(temp_a0);
}
Comment on lines +628 to +636
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment I left for func_800BB9FC


INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800BBA84);

Expand Down Expand Up @@ -686,7 +723,12 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C0254);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C0314);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C03B8);
s16 func_800C03B8(s16 arg0, s16 arg1) {
s32 temp_a0;

temp_a0 = arg0 - arg1;
return SquareRoot0(temp_a0 * temp_a0, arg1);
}

s32 func_800C03FC(s32 arg0, s32 arg1) { return arg0 < 0 ? -arg1 : arg1; }

Expand Down Expand Up @@ -998,6 +1040,8 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C59B8);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C5ADC);

extern s32 D_800F9DA8;

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C5BEC);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C5C18);
Expand Down
47 changes: 40 additions & 7 deletions src/battle/battle2.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ void func_801B0040(s16, u8);
void func_801B0054(s16, u8);
void func_801B0084(s16, u8);

extern u8 D_800F10EC[];
extern u8 D_800F11E8[];
extern u8 D_800F1304[];
extern s32 D_800F14D4;

void func_800D6F78(); // extern
void func_800D70C0(); // extern

void func_800D57C0(); // extern

static s32 func_800C7B60(s16 arg0, s16 nItems, u8* arg2) {
BattleModelSub* var_a0;
s32 var_a1;
Expand Down Expand Up @@ -1127,7 +1137,15 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D5774);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D57C0);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D58D0);
void func_800D58D0(s16 arg0, s16 arg1, s16 arg2) {
Unk80162978* temp_v0;

temp_v0 = &D_80162978[func_800BBEAC(func_800D57C0)];
temp_v0->D_80162978 = 0;
temp_v0->D_80162980 = arg0;
temp_v0->D_8016297E = arg2;
temp_v0->D_8016297C = arg1;
}

void func_800D5938();
INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D5938);
Expand All @@ -1141,7 +1159,11 @@ static void func_800D5A68(s16 arg0, s16 arg1) {
temp_v0->D_8016297C = arg0;
}

INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D5AC0);
s32 func_800D5AC0(s32 arg0, s32 arg1) {
return (((s32)(arg0 & 0xFF0000) / arg1) & 0xFF0000) |
(((s32)(arg0 & 0xFF00) / arg1) & 0xFF00) |
(((s32)(arg0 & 0xFF) / arg1) & 0xFF);
}
Comment on lines +1163 to +1166
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (((s32)(arg0 & 0xFF0000) / arg1) & 0xFF0000) |
(((s32)(arg0 & 0xFF00) / arg1) & 0xFF00) |
(((s32)(arg0 & 0xFF) / arg1) & 0xFF);
}
return (((arg0 & 0xFF0000) / arg1) & 0xFF0000) |
(((arg0 & 0xFF00) / arg1) & 0xFF00) |
(((arg0 & 0xFF) / arg1) & 0xFF);
}

can remove (s32)


INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D5B6C);

Expand All @@ -1155,14 +1177,10 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D6394);

INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D650C);

extern u8 D_800F10EC[];
extern u8 D_800F11E8[];
extern u8 D_800F1304[];
u8* const D_800A0DC8[] = {D_800F10EC, D_800F11E8, D_800F1304};
INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D6734);

void func_800D6734(s32, s32);
extern s32 D_800F14D4;

static void func_800D67BC(s32 arg0) {
D_800F14D4 = 0x88;
Expand Down Expand Up @@ -1196,7 +1214,22 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D70C0);
INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D7178);

void func_800D72B4();
INCLUDE_ASM("asm/us/battle/nonmatchings/battle2", func_800D72B4);

void func_800D72B4(void) {
Unk801621F0* temp_s0;

temp_s0 = &D_801621F0[D_801590D4];
if (D_80062D98 == 0) {
if (temp_s0->D_801621F2 == 0) {
func_800D5138(1);
}
if (temp_s0->D_801621F2 == 2) {
func_800D51D4(1);
temp_s0->D_801621F0 = -1;
}
temp_s0->D_801621F2 = (u16)temp_s0->D_801621F2 + 1;
}
}

static void func_800D7340(void) { func_800BBEAC(func_800D72B4); }

Expand Down
Loading