register match sub_800A4E4

This commit is contained in:
Kermalis 2024-11-05 07:02:02 -05:00
parent 5f02fed1c5
commit 9ae9b85c75
2 changed files with 71 additions and 107 deletions

View File

@ -5,112 +5,6 @@
.text
thumb_func_start sub_800A4E4
sub_800A4E4:
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
mov r8, r0
adds r5, r1, 0
adds r6, r2, 0
adds r0, r5, 0
bl sub_800A2A0
lsls r0, 24
lsrs r4, r0, 24
cmp r4, 0
beq _0800A50C
movs r0, 0
mov r1, r8
str r0, [r1]
str r0, [r1, 0x4]
b _0800A596
_0800A50C:
adds r0, r6, 0
bl sub_800A2A0
lsls r0, 24
cmp r0, 0
beq _0800A520
mov r7, r8
str r4, [r7]
str r4, [r7, 0x4]
b _0800A596
_0800A520:
ldr r1, [r5]
ldr r4, [r5, 0x4]
ldr r0, [r6]
mov r10, r0
ldr r2, [r6, 0x4]
movs r6, 0
movs r5, 0
movs r7, 0x80
lsls r7, 24
mov r9, r7
movs r0, 0x3F
mov r12, r0
_0800A538:
adds r3, r5, 0
movs r0, 0x1
ands r0, r2
cmp r0, 0
beq _0800A54C
adds r5, r4
adds r6, r1
cmp r3, r5
bls _0800A54C
adds r6, 0x1
_0800A54C:
lsrs r2, 1
movs r3, 0x1
mov r0, r10
ands r0, r3
cmp r0, 0
beq _0800A55C
mov r7, r9
orrs r2, r7
_0800A55C:
mov r0, r10
lsrs r0, 1
mov r10, r0
lsls r1, 1
adds r0, r4, 0
mov r7, r9
ands r0, r7
cmp r0, 0
beq _0800A570
orrs r1, r3
_0800A570:
lsls r4, 1
movs r0, 0x1
negs r0, r0
add r12, r0
mov r7, r12
cmp r7, 0
bge _0800A538
lsrs r1, r5, 15
ands r1, r3
lsrs r5, 16
lsls r0, r6, 16
orrs r5, r0
lsrs r6, 16
cmp r1, 0
beq _0800A590
adds r5, 0x1
_0800A590:
mov r0, r8
str r6, [r0]
str r5, [r0, 0x4]
_0800A596:
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
thumb_func_end sub_800A4E4
thumb_func_start sub_800A5A4
sub_800A5A4:
push {r4-r7,lr}

View File

@ -9,7 +9,7 @@ u24_8 u24_8_mul(u24_8, u24_8);
bool8 u32_pair_less_than(u32, u32, u32, u32);
void sub_800A5A4(unkStruct_80943A8 *, unkStruct_80943A8 *, unkStruct_80943A8 *);
void sub_800A4E4(unkStruct_80943A8 *, unkStruct_80943A8 *, unkStruct_80943A8 *);
static void sub_800A4E4(unkStruct_80943A8 *, unkStruct_80943A8 *, unkStruct_80943A8 *);
/**
* This function computes a value modulo 3, using a lookup table for values less
@ -677,4 +677,74 @@ void sub_800A4A0(unkStruct_80943A8 *a)
a->s0 = res.s0;
a->s4 = res.s4;
}
}
// Regswap https://decomp.me/scratch/HNmlz
static void sub_800A4E4(unkStruct_80943A8 *dst, unkStruct_80943A8 *a, unkStruct_80943A8 *b)
{
u32 sl;
u32 r1;
u32 r2;
u32 r3;
u32 r4;
#ifdef NONMATCHING
u32 r5;
#else
register u32 r5 asm("r5");
#endif
u32 r6;
s32 i;
if (sub_800A2A0(a)) {
dst->s0 = 0;
dst->s4 = 0;
}
else if (sub_800A2A0(b)) {
dst->s0 = 0;
dst->s4 = 0;
}
else {
r1 = a->s0;
r4 = a->s4;
sl = b->s0;
r2 = b->s4;
r6 = 0;
r5 = 0;
for (i = 0; i < 64; i++) {
r3 = r5;
if (r2 & 1) {
r5 += r4;
r6 += r1;
if (r3 > r5)
r6++;
}
r2 >>= 1;
if (sl & 1)
r2 |= 0x80000000;
sl >>= 1;
r1 <<= 1;
if (r4 & 0x80000000)
r1 |= 1;
r4 <<= 1;
}
r1 = (r5 >> 15) & 1;
r5 >>= 16;
r5 |= (r6 << 16);
r6 >>= 16;
if (r1 != 0)
r5++;
dst->s0 = r6;
dst->s4 = r5;
}
}