Merge pull request #207 from ElectroDeoxys/master

Decompile code_8094148.s
This commit is contained in:
AnonymousRandomPerson 2024-08-27 17:41:44 -04:00 committed by GitHub
commit 8b027d5af0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 95 additions and 248 deletions

View File

@ -1,130 +0,0 @@
#include "asm/constants/gba_constants.inc"
#include "asm/macros.inc"
.syntax unified
.text
thumb_func_start sub_8094370
sub_8094370:
push {r4,r5,lr}
adds r5, r0, 0
lsls r1, 16
lsls r2, 16
ldr r4, _08094398
lsrs r3, r1, 16
orrs r3, r2
asrs r2, 16
ldr r1, _0809439C
asrs r0, r1, 16
cmp r2, r0
ble _0809438C
ands r3, r4
orrs r3, r1
_0809438C:
str r3, [r5]
adds r0, r5, 0
pop {r4,r5}
pop {r1}
bx r1
.align 2, 0
_08094398: .4byte 0x0000ffff
_0809439C: .4byte 0x03e70000
thumb_func_end sub_8094370
thumb_func_start sub_80943A0
sub_80943A0:
lsls r1, 16
lsrs r2, r1, 16
str r2, [r0]
bx lr
thumb_func_end sub_80943A0
thumb_func_start sub_80943A8
sub_80943A8:
push {r4,r5,lr}
ldr r3, [r1, 0x4]
lsrs r2, r3, 16
ldr r1, _080943D4
ands r5, r1
orrs r5, r2
ldr r4, _080943D8
adds r2, r4, 0
ands r2, r3
lsls r1, r2, 5
subs r1, r2
lsls r1, 2
adds r1, r2
lsls r1, 3
lsrs r1, 16
lsls r1, 16
ands r5, r4
orrs r5, r1
str r5, [r0]
pop {r4,r5}
pop {r1}
bx r1
.align 2, 0
_080943D4: .4byte 0xffff0000
_080943D8: .4byte 0x0000ffff
thumb_func_end sub_80943A8
thumb_func_start sub_80943DC
sub_80943DC:
push {r4-r6,lr}
mov r6, r8
push {r6}
mov r8, r0
adds r4, r1, 0
lsls r1, r4, 16
asrs r1, 16
lsls r0, r1, 5
subs r0, r1
lsls r0, 2
adds r0, r1
lsls r0, 3
asrs r1, r4, 16
adds r0, r1
lsls r3, r2, 16
asrs r3, 16
lsls r1, r3, 5
subs r1, r3
lsls r1, 2
adds r1, r3
lsls r1, 3
asrs r2, 16
adds r1, r2
muls r0, r1
movs r5, 0xFA
lsls r5, 2
adds r1, r5, 0
bl __divsi3
adds r6, r0, 0
adds r1, r5, 0
bl __divsi3
lsls r0, 16
lsrs r0, 16
ldr r1, _08094448
ands r4, r1
orrs r4, r0
adds r0, r6, 0
adds r1, r5, 0
bl __modsi3
lsls r0, 16
ldr r1, _0809444C
ands r1, r4
orrs r0, r1
mov r1, r8
str r0, [r1]
mov r0, r8
pop {r3}
mov r8, r3
pop {r4-r6}
pop {r1}
bx r1
.align 2, 0
_08094448: .4byte 0xffff0000
_0809444C: .4byte 0x0000ffff
thumb_func_end sub_80943DC
.align 2, 0

View File

@ -324,7 +324,6 @@ SECTIONS {
src/friend_area.o(.text);
src/moves.o(.text);
src/code_8094148.o(.text);
asm/code_8094148.o(.text);
src/number_util.o(.text);
src/code_809447C.o(.text);
src/code_8092334.o(.text);

View File

@ -1,147 +1,66 @@
#include "global.h"
s32 *sub_8094268(s32 *param_1, s32 param_2, s32 param_3)
typedef struct unkStruct_8094148
{
s32 x;
s32 y;
u16 z;
s16 unk0;
s16 unk2;
} unkStruct_8094148;
y = param_2;
unkStruct_8094148 *sub_8094268(unkStruct_8094148* param_1, unkStruct_8094148 param_2, unkStruct_8094148 param_3)
{
param_2.unk2 += param_3.unk2;
param_2.unk0 += param_3.unk0;
x = ((y >> 0x10) + (param_3 >> 0x10)) << 0x10;
y = (y & 0x0000ffff) | x;
z = y + param_3;
y = (y & 0xffff0000) | z;
if ((y >> 0x10) > 999) {
u16 b;
s32 c;
b = y + 1;
y = (y & 0xffff0000) | b;
c = ((y >> 0x10) - 1000) << 0x10;
y = (y & 0x0000ffff) | c;
if (param_2.unk2 > 999)
{
param_2.unk0++;
param_2.unk2 -= 1000;
}
*param_1 = y;
*param_1 = param_2;
return param_1;
}
#ifdef NONMATCHING
// https://decomp.me/scratch/RUfc2 (99.52% matching)
s32* sub_80942C0(s32* param_1, s32 param_2, s32 param_3)
unkStruct_8094148 *sub_80942C0(unkStruct_8094148* param_1, unkStruct_8094148 param_2, unkStruct_8094148 param_3)
{
s32 x;
s32 y;
u16 z;
s32* dest;
param_2.unk2 -= param_3.unk2;
param_2.unk0 -= param_3.unk0;
dest = param_1;
y = param_2;
x = ((y >> 0x10) - (param_3 >> 0x10)) << 0x10;
y = (y & 0x0000ffff) | x;
z = y - param_3;
y = (y & 0xffff0000) | z;
if (y < 0) {
u16 b;
s32 c;
b = (y - 1);
y = (y & 0xffff0000) | b;
c = ((y >> 0x10) + 1000) << 0x10;
y = (y & 0x0000ffff) | c;
if (param_2.unk2 < 0)
{
param_2.unk0--;
param_2.unk2 += 1000;
}
if ((y << 0x10) < 0) {
y = 0;
if (param_2.unk0 < 0)
{
param_2.unk0 = 0;
param_2.unk2 = 0;
}
*dest = y;
return dest;
*param_1 = param_2;
return param_1;
}
#else
NAKED
void sub_80942C0(s32* param_1, s32 param_2, s32 param_3)
unkStruct_8094148 *sub_8094318(unkStruct_8094148* param_1, unkStruct_8094148 param_2, unkStruct_8094148 param_3)
{
asm_unified(
"\tpush {r4,r5,lr}\n"
"\tadds r5, r0, 0\n"
"\tadds r3, r1, 0\n"
"\tasrs r0, r3, 16\n"
"\tasrs r1, r2, 16\n"
"\tsubs r0, r1\n"
"\tlsls r0, 16\n"
"\tldr r4, _08094310\n"
"\tands r3, r4\n"
"\torrs r3, r0\n"
"\tsubs r2, r3, r2\n"
"\tlsls r2, 16\n"
"\tlsrs r2, 16\n"
"\tldr r1, _08094314\n"
"\tands r3, r1\n"
"\torrs r3, r2\n"
"\tcmp r3, 0\n"
"\tbge _080942FC\n"
"\tsubs r0, r3, 0x1\n"
"\tlsls r0, 16\n"
"\tlsrs r0, 16\n"
"\tands r3, r1\n"
"\torrs r3, r0\n"
"\tasrs r0, r3, 16\n"
"\tmovs r2, 0xFA\n"
"\tlsls r2, 2\n"
"\tadds r0, r2\n"
"\tlsls r0, 16\n"
"\tands r3, r4\n"
"\torrs r3, r0\n"
"_080942FC:\n"
"\tlsls r0, r3, 16\n"
"\tcmp r0, 0\n"
"\tbge _08094304\n"
"\tmovs r3, 0\n"
"_08094304:\n"
"\tstr r3, [r5]\n"
"\tadds r0, r5, 0\n"
"\tpop {r4,r5}\n"
"\tpop {r1}\n"
"\tbx r1\n"
"\t.align 2, 0\n"
"_08094310: .4byte 0x0000ffff\n"
"_08094314: .4byte 0xffff0000\n"
);
}
#endif
s32* sub_8094318(s32* param_1, s32 param_2, s32 param_3)
{
s16 a;
s16 b;
a = param_3;
b = param_2;
if ((b > a) || (b >= a && (param_2 >> 0x10 > param_3 >> 0x10))) {
if (param_2.unk0 > param_3.unk0
|| (param_2.unk0 >= param_3.unk0 && param_2.unk2 > param_3.unk2))
{
*param_1 = param_3;
}
else {
else
{
*param_1 = param_2;
}
return param_1;
}
s32* sub_8094344(s32* param_1, s32 param_2, s32 param_3)
unkStruct_8094148 *sub_8094344(unkStruct_8094148* param_1, unkStruct_8094148 param_2, unkStruct_8094148 param_3)
{
s16 a;
s16 b;
a = param_3;
b = param_2;
if ((b > a) || (b >= a && (param_2 >> 0x10 > param_3 >> 0x10)))
if (param_2.unk0 > param_3.unk0
|| (param_2.unk0 >= param_3.unk0 && param_2.unk2 > param_3.unk2))
{
*param_1 = param_2;
}
@ -152,3 +71,62 @@ s32* sub_8094344(s32* param_1, s32 param_2, s32 param_3)
return param_1;
}
unkStruct_8094148 *sub_8094370(unkStruct_8094148* param_1, unkStruct_8094148 param_2, unkStruct_8094148 param_3)
{
unkStruct_8094148 p;
p.unk0 = param_2.unk0;
p.unk2 = param_3.unk0;
if (p.unk2 > 999)
{
p.unk2 = 999;
}
*param_1 = p;
return param_1;
}
void sub_80943A0(unkStruct_8094148* param_1, unkStruct_8094148 param_2)
{
unkStruct_8094148 p;
p.unk0 = param_2.unk0;
p.unk2 = 0;
*param_1 = p;
}
struct unkStruct_80943A8
{
s32 s0;
s32 s4;
} unkStruct_80943A8;
unkStruct_8094148 *sub_80943A8(unkStruct_8094148 *param_1, struct unkStruct_80943A8* param_2)
{
unkStruct_8094148 s;
s32 x;
s.unk0 = param_2->s4 >> 0x10;
x = param_2->s4 & 0xffff;
s.unk2 = (1000 * x) >> 0x10;
*param_1 = s;
return param_1;
}
unkStruct_8094148 *sub_80943DC(unkStruct_8094148 *param_1, unkStruct_8094148 param_2, unkStruct_8094148 param_3)
{
s32 div;
div = (1000 * param_2.unk0 + param_2.unk2);
div *= (1000 * param_3.unk0 + param_3.unk2);
div /= 1000;
param_2.unk0 = div / 1000;
param_2.unk2 = div % 1000;
*param_1 = param_2;
return param_1;
}