Decompiled a weird function

This commit is contained in:
Phlosioneer 2019-02-24 04:33:58 -05:00
parent 62589d7003
commit a25f4c75bc
2 changed files with 62 additions and 109 deletions

View File

@ -5,111 +5,6 @@
.text
thumb_func_start sub_81C83E0
sub_81C83E0: @ 81C83E0
push {lr}
ldr r0, =sub_81C83F0
bl sub_81C7124
pop {r1}
bx r1
.pool
thumb_func_end sub_81C83E0
thumb_func_start sub_81C83F0
sub_81C83F0: @ 81C83F0
push {r4-r7,lr}
sub sp, 0xC
adds r6, r0, 0
movs r0, 0x11
bl GetSubstructPtr
adds r4, r0, 0
cmp r6, 0
beq _081C8408
cmp r6, 0x1
beq _081C848C
b _081C849A
_081C8408:
ldrh r0, [r4, 0xA]
ldrh r1, [r4, 0xC]
adds r0, r1
ldr r1, [r4, 0x10]
adds r5, r0, r1
movs r0, 0xF
ands r5, r0
ldr r0, [r4, 0x1C]
adds r7, r4, 0
adds r7, 0x48
ldr r2, [r4, 0x34]
adds r1, r7, 0
bl _call_via_r2
ldr r3, [r4, 0x38]
cmp r3, 0
beq _081C8434
ldrh r0, [r4, 0x8]
ldr r1, [r4, 0x14]
adds r2, r5, 0
bl _call_via_r3
_081C8434:
ldrb r0, [r4, 0x8]
ldrb r1, [r4, 0x5]
lsls r2, r5, 4
movs r3, 0x1
orrs r2, r3
str r2, [sp]
movs r2, 0xFF
str r2, [sp, 0x4]
str r6, [sp, 0x8]
adds r2, r7, 0
movs r3, 0x8
bl AddTextPrinterParameterized
ldrh r0, [r4, 0xC]
adds r0, 0x1
strh r0, [r4, 0xC]
lsls r0, 16
lsrs r0, 16
ldrh r1, [r4, 0xE]
cmp r0, r1
bcc _081C847A
ldr r0, [r4, 0x38]
cmp r0, 0
beq _081C846E
ldrb r0, [r4, 0x8]
movs r1, 0x3
bl CopyWindowToVram
b _081C8476
_081C846E:
ldrb r0, [r4, 0x8]
movs r1, 0x2
bl CopyWindowToVram
_081C8476:
movs r0, 0
b _081C849C
_081C847A:
ldr r0, [r4, 0x1C]
ldr r1, [r4, 0x18]
adds r0, r1
str r0, [r4, 0x1C]
ldr r0, [r4, 0x14]
adds r0, 0x1
str r0, [r4, 0x14]
movs r0, 0x3
b _081C849C
_081C848C:
bl IsDma3ManagerBusyWithBgCopy
lsls r0, 24
cmp r0, 0
beq _081C849A
movs r0, 0x2
b _081C849C
_081C849A:
movs r0, 0x4
_081C849C:
add sp, 0xC
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end sub_81C83F0
thumb_func_start sub_81C84A4
sub_81C84A4: @ 81C84A4
push {lr}

View File

@ -33,7 +33,8 @@ struct UnknownSubSubStruct_0203CF40 {
u8 unk1;
u8 unk2;
u8 unk3;
u16 unk4;
u8 unk4;
u8 unk5;
u16 unk6;
u8 windowId;
u8 unk9;
@ -76,7 +77,17 @@ struct UnknownSubStruct_81C81D4
u32 unk14;
u32 unk18;
u32 unk1C;
u8 unk20[0x68];
u32 unk20;
u32 unk24;
u32 unk28;
u32 unk2C;
u32 unk30;
void (*unk34)(u32, char*);
void (*unk38)(u16, u32, u32);
u32 unk3C;
u32 unk40;
u32 unk44;
char unk48[0x40];
u8 tilemapBuffer[0x800];
struct UnknownSubSubStruct_81C81D4 unk888;
u8 unk898[0x6];
@ -159,11 +170,11 @@ extern u32 sub_81CFA04(void);
extern u32 sub_81CFE08(void);
extern u32 sub_81C91AC(struct UnknownSubStruct_81C81D4 *a0, const void *a1, void *a2, s32 a3);
extern u32 sub_81C9160(struct UnknownSubSubStruct_81C81D4 *a0, void *a1);
extern u32 sub_81C83E0(void);
extern void sub_81C8ED0(void);
extern void sub_81C8EF8(struct UnknownSubSubStruct_81C81D4 *a0, struct UnknownSubSubStruct_0203CF40 *a1);
extern u32 sub_81C83F0(s32);
u32 sub_81C83F0(s32);
u32 sub_81C83E0(void);
void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct UnknownSubStruct_81C81D4 *a5);
void sub_81C837C(struct UnknownSubSubStruct_81C81D4 *a0, struct UnknownSubStruct_81C81D4 *a1);
void sub_81C835C(struct UnknownSubSubStruct_0203CF40 *a0);
@ -1597,4 +1608,51 @@ void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct UnknownSubStruct
a5->unk14 = a1;
a5->unk10 = a4;
sub_81C7078(sub_81C83F0, 5);
}
u32 sub_81C83E0(void)
{
return sub_81C7124(sub_81C83F0);
}
u32 sub_81C83F0(s32 a0)
{
struct UnknownSubStruct_81C81D4 *structPtr;
u32 v1;
structPtr = GetSubstructPtr(0x11);
switch (a0)
{
case 0:
v1 = (structPtr->unk0.unkA + structPtr->unk0.unkC + structPtr->unk10) & 0xF;
structPtr->unk34(structPtr->unk1C, structPtr->unk48);
if (structPtr->unk38 != NULL)
// Accessing unk0.windowId as if it were a u16...?
// It's accessed as a u8 again in the very next line...
structPtr->unk38(*(u16*)(&structPtr->unk0.windowId), structPtr->unk14, v1);
AddTextPrinterParameterized(structPtr->unk0.windowId, structPtr->unk0.unk5, structPtr->unk48, 8, (v1 << 4) | 1, 255, (void (*)(struct TextPrinterTemplate*, u16))a0);
if (++structPtr->unk0.unkC >= structPtr->unk0.unkE)
{
if (structPtr->unk38 != NULL)
CopyWindowToVram(structPtr->unk0.windowId, 3);
else
CopyWindowToVram(structPtr->unk0.windowId, 2);
return 0;
}
else
{
structPtr->unk1C += structPtr->unk18;
structPtr->unk14++;
return 3;
}
case 1:
if (IsDma3ManagerBusyWithBgCopy())
return 2;
else
return 4;
default:
return 4;
}
}