decompile more of code_809D148

This commit is contained in:
DizzyEggg 2024-07-17 16:44:25 +02:00
parent c21a422bb9
commit 2de2dc0cb9
3 changed files with 171 additions and 229 deletions

View File

@ -5,211 +5,8 @@
.text
thumb_func_start nullsub_120
nullsub_120:
bx lr
thumb_func_end nullsub_120
thumb_func_start sub_809D490
sub_809D490:
push {r4,lr}
ldr r4, _0809D4AC
movs r0, 0x80
lsls r0, 3
movs r1, 0x6
bl MemoryAlloc
str r0, [r4]
bl sub_809D4B0
pop {r4}
pop {r0}
bx r0
.align 2, 0
_0809D4AC: .4byte gUnknown_203B4B0
thumb_func_end sub_809D490
thumb_func_start sub_809D4B0
sub_809D4B0:
push {r4,r5,lr}
ldr r0, _0809D4EC
movs r2, 0x1
negs r2, r2
adds r1, r2, 0
strh r1, [r0]
ldr r0, _0809D4F0
strh r1, [r0]
ldr r0, _0809D4F4
strh r1, [r0]
ldr r1, _0809D4F8
movs r0, 0
strb r0, [r1]
movs r1, 0
ldr r5, _0809D4FC
movs r2, 0
ldr r3, _0809D500
ldr r4, _0809D504
_0809D4D4:
adds r0, r1, r5
strb r2, [r0]
adds r0, r1, r3
strb r2, [r0]
stm r4!, {r2}
adds r1, 0x1
cmp r1, 0x80
ble _0809D4D4
pop {r4,r5}
pop {r0}
bx r0
.align 2, 0
_0809D4EC: .4byte gUnknown_2039A30
_0809D4F0: .4byte gUnknown_2039A32
_0809D4F4: .4byte gUnknown_2039A34
_0809D4F8: .4byte gUnknown_2039A36
_0809D4FC: .4byte gUnknown_2039A38
_0809D500: .4byte gUnknown_2039AC0
_0809D504: .4byte gUnknown_2039B48
thumb_func_end sub_809D4B0
thumb_func_start sub_809D508
sub_809D508:
push {r4,lr}
ldr r4, _0809D51C
ldr r0, [r4]
bl MemoryFree
movs r0, 0
str r0, [r4]
pop {r4}
pop {r0}
bx r0
.align 2, 0
_0809D51C: .4byte gUnknown_203B4B0
thumb_func_end sub_809D508
thumb_func_start sub_809D520
sub_809D520:
ldr r1, _0809D528
strh r1, [r0]
bx lr
.align 2, 0
_0809D528: .4byte 0x0000ffff
thumb_func_end sub_809D520
thumb_func_start sub_809D52C
sub_809D52C:
push {lr}
movs r2, 0
ldrsh r1, [r0, r2]
cmp r1, 0x1
beq _0809D544
cmp r1, 0x1
ble _0809D562
cmp r1, 0x2
beq _0809D54E
cmp r1, 0x3
beq _0809D558
b _0809D562
_0809D544:
movs r1, 0x2
ldrsh r0, [r0, r1]
bl sub_80A882C
b _0809D564
_0809D54E:
movs r2, 0x2
ldrsh r0, [r0, r2]
bl sub_80AC240
b _0809D564
_0809D558:
movs r1, 0x2
ldrsh r0, [r0, r1]
bl sub_80AD158
b _0809D564
_0809D562:
movs r0, 0
_0809D564:
pop {r1}
bx r1
thumb_func_end sub_809D52C
thumb_func_start sub_809D568
sub_809D568:
push {lr}
adds r3, r0, 0
ldr r0, _0809D5B4
strh r0, [r3]
movs r2, 0
movs r0, 0
strh r0, [r3, 0x2]
str r0, [r3, 0x8]
str r0, [r3, 0x4]
str r0, [r3, 0x14]
str r0, [r3, 0x10]
adds r1, r3, 0
adds r1, 0x20
strb r2, [r1]
str r0, [r3, 0x1C]
movs r1, 0x1
negs r1, r1
strh r1, [r3, 0x22]
strh r0, [r3, 0x24]
adds r2, r3, 0
adds r2, 0x26
movs r1, 0xFF
strb r1, [r2]
strh r0, [r3, 0x28]
strh r0, [r3, 0x2A]
strh r0, [r3, 0x2C]
str r0, [r3, 0x30]
movs r2, 0
movs r1, 0x3
adds r0, r3, 0
adds r0, 0x5C
_0809D5A6:
str r2, [r0]
subs r0, 0x4
subs r1, 0x1
cmp r1, 0
bge _0809D5A6
pop {r0}
bx r0
.align 2, 0
_0809D5B4: .4byte 0x0000ffff
thumb_func_end sub_809D568
thumb_func_start sub_809D5B8
sub_809D5B8:
push {r4,lr}
adds r4, r0, 0
movs r0, 0
str r0, [r4]
str r0, [r4, 0x4]
ldr r0, _0809D5FC
strh r0, [r4, 0x10]
movs r0, 0xFF
strb r0, [r4, 0x12]
adds r0, r4, 0
adds r0, 0xC
bl sub_809D520
movs r2, 0
movs r1, 0x3
adds r0, r4, 0
adds r0, 0x20
_0809D5DA:
str r2, [r0]
subs r0, 0x4
subs r1, 0x1
cmp r1, 0
bge _0809D5DA
adds r0, r4, 0
adds r0, 0x24
bl sub_809D568
adds r0, r4, 0
adds r0, 0x84
bl sub_809D568
pop {r4}
pop {r0}
bx r0
.align 2, 0
_0809D5FC: .4byte 0x0000ffff
thumb_func_end sub_809D5B8
thumb_func_start sub_809D600
sub_809D600:

View File

@ -29,6 +29,34 @@ typedef struct __attribute__((packed)) GroundScript_ExecutePP_1_sub
u8 fill50[0x60 - 0x2A];
} GroundScript_ExecutePP_1_sub;
// Needed for sub_809D568, possibly could be merged with GroundScript_ExecutePP_1_sub?
typedef struct GroundScript_ExecutePP_1_sub_not_packed
{
// size: 0x60
/* 0x0 */ s16 scriptType;
/* 0x2 */ s16 unk2;
/* 0x4 */ u8 *scriptPointer1;
/* 0x8 */ u8 *scriptPointer2;
/* 0xC */ u16 unkC;
/* 0xE */ u8 unkE;
/* 0xF */ u8 fillF;
/* 0x10 */ u32 unk10;
/* 0x14 */ u8 *unk14;
/* 0x18 */ u8 fill18[2];
/* 0x1C */ u32 unk1C;
/* 0x20 */ u8 unk20;
/* 0x22 */ u16 unk22;
/* 0x24 */ u16 unk24;
/* 0x26 */ u8 unk26;
/* 0x28 */ u16 unk28;
/* 0x2A */ u16 unk2A;
/* 0x2C */ u16 unk2C;
/* 0x2E */ u16 unk2E;
/* 0x30 */ u32 unk30;
u8 fill34[0x1C];
u32 unk5C[4];
} GroundScript_ExecutePP_1_sub_not_packed;
typedef void (*Callback)(u32, void *);
typedef struct GroundScript_ExecutePP_1_sub2
{
@ -40,7 +68,7 @@ typedef struct GroundScript_ExecutePP_1
{
GroundScript_ExecutePP_1_sub2 *unk0;
u32 unk4;
u32 fill8;
u16 unk8;
u32 unkC;
u16 unk10;
u8 unk12;
@ -51,6 +79,8 @@ typedef struct GroundScript_ExecutePP_1
u8 fillE8[0x110 - 0xE8];
} GroundScript_ExecutePP_1;
#include "debug.h"
bool8 GroundScript_ExecutePP(GroundScript_ExecutePP_1 *, s32 *, GroundScript_ExecutePP_3 *, const DebugLocation *unused);
#endif // GUARD_GROUND_SCRIPT_H
#endif // GUARD_GROUND_SCRIPT_H

View File

@ -1,5 +1,7 @@
#include "global.h"
#include "other_random.h"
#include "memory.h"
#include "ground_script.h"
struct unkStruct_809D158
{
@ -16,8 +18,8 @@ struct unkStruct_20399E8
s32 unk10;
struct unkStruct_809D158 unk14;
struct unkStruct_809D158 unk1C;
u32 unk24;
u32 unk28;
s32 unk24;
s32 unk28;
s32 unk2C;
s32 unk30;
s32 unk34;
@ -29,7 +31,8 @@ struct unkStruct_20399E8
extern struct unkStruct_20399E8 gUnknown_20399E8;
void sub_809D0BC(void);
void sub_809D158(u32 r0, const struct unkStruct_809D158 *r1);
void sub_809D4B0(void);
void sub_809D158(s32 r0, const struct unkStruct_809D158 *r1);
s32 sub_809CFE8(u16 param_1)
{
@ -121,7 +124,7 @@ void sub_809D0BC(void)
gUnknown_20399E8.unk38 = 0;
}
void sub_809D100(u32 r0)
void sub_809D100(s32 r0)
{
if(gUnknown_20399E8.unk24 != r0)
{
@ -134,7 +137,7 @@ void sub_809D100(u32 r0)
}
}
void sub_809D124(u32 r0, u32 r1, u32 r2)
void sub_809D124(s32 r0, s32 r1, s32 r2)
{
if(gUnknown_20399E8.unk24 != r0)
{
@ -147,7 +150,7 @@ void sub_809D124(u32 r0, u32 r1, u32 r2)
gUnknown_20399E8.unk2C = r2;
}
void sub_809D148(u32 r0)
void sub_809D148(s32 r0)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 0;
@ -159,28 +162,28 @@ struct Test1
u64 ukn0;
};
void sub_809D158(u32 r0, const struct unkStruct_809D158 *r1)
void sub_809D158(s32 r0, const struct unkStruct_809D158 *r1)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 0;
gUnknown_20399E8.unk1C = *r1;
}
void sub_809D170(u32 r0, u32 r1)
void sub_809D170(s32 r0, s32 r1)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 0;
gUnknown_20399E8.unk4 = r1;
}
void sub_809D180(u32 r0, u32 r1)
void sub_809D180(s32 r0, s32 r1)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 1;
gUnknown_20399E8.unkC = r1;
}
void sub_809D190(u32 r0, struct unkStruct_809D158 *r1, u32 r2)
void sub_809D190(s32 r0, struct unkStruct_809D158 *r1, s32 r2)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 1;
@ -188,7 +191,7 @@ void sub_809D190(u32 r0, struct unkStruct_809D158 *r1, u32 r2)
gUnknown_20399E8.unk14 = *r1;
}
void sub_809D1A8(u32 r0, u32 r1, u32 r2)
void sub_809D1A8(s32 r0, s32 r1, s32 r2)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 1;
@ -196,14 +199,14 @@ void sub_809D1A8(u32 r0, u32 r1, u32 r2)
gUnknown_20399E8.unk4 = r1;
}
void sub_809D1BC(u32 r0, u32 r1)
void sub_809D1BC(s32 r0, s32 r1)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 2;
gUnknown_20399E8.unk10 = r1;
}
void sub_809D1CC(u32 r0, struct unkStruct_809D158 *r1, u32 r2)
void sub_809D1CC(s32 r0, struct unkStruct_809D158 *r1, s32 r2)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 2;
@ -211,7 +214,7 @@ void sub_809D1CC(u32 r0, struct unkStruct_809D158 *r1, u32 r2)
gUnknown_20399E8.unk14 = *r1;
}
void sub_809D1E4(u32 r0, u32 r1, u32 r2)
void sub_809D1E4(s32 r0, s32 r1, s32 r2)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 2;
@ -219,14 +222,14 @@ void sub_809D1E4(u32 r0, u32 r1, u32 r2)
gUnknown_20399E8.unk4 = r1;
}
void sub_809D1F8(u32 r0, u32 r1)
void sub_809D1F8(s32 r0, s32 r1)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 3;
gUnknown_20399E8.unkC = r1;
}
void sub_809D208(u32 r0, struct unkStruct_809D158 *r1, u32 r2)
void sub_809D208(s32 r0, struct unkStruct_809D158 *r1, s32 r2)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 3;
@ -234,7 +237,7 @@ void sub_809D208(u32 r0, struct unkStruct_809D158 *r1, u32 r2)
gUnknown_20399E8.unk14 = *r1;
}
void sub_809D220(u32 r0, u32 r1, u32 r2)
void sub_809D220(s32 r0, s32 r1, s32 r2)
{
gUnknown_20399E8.unk0 = r0;
gUnknown_20399E8.unk8 = 3;
@ -253,13 +256,14 @@ u8 sub_809D248(struct unkStruct_809D158 *r0)
return gUnknown_20399E8.unk44;
}
s32 sub_80A8FD8(s16 a0, struct unkStruct_809D158 *a1);
s32 sub_80AC448(s16 a0, struct unkStruct_809D158 *a1);
s32 sub_80AD360(s16 a0, struct unkStruct_809D158 *a1);
void sub_800290C(struct unkStruct_809D158 *a0, s32 a1);
void sub_8002934(struct unkStruct_809D158 *a0, struct unkStruct_809D158 *a1, struct unkStruct_809D158 *a2, u32 a3, u32 a4);
s32 sub_8009FB8(s32 a0, s32 a1);
bool8 sub_80A579C(struct unkStruct_809D158 *a0, struct unkStruct_809D158 *a1);
// Todo: move these to appropriate header files
extern s32 sub_80A8FD8(s16 a0, struct unkStruct_809D158 *a1);
extern s32 sub_80AC448(s16 a0, struct unkStruct_809D158 *a1);
extern s32 sub_80AD360(s16 a0, struct unkStruct_809D158 *a1);
extern void sub_800290C(struct unkStruct_809D158 *a0, s32 a1);
extern void sub_8002934(struct unkStruct_809D158 *a0, struct unkStruct_809D158 *a1, struct unkStruct_809D158 *a2, u32 a3, u32 a4);
extern s32 sub_8009FB8(s32 a0, s32 a1);
extern bool8 sub_80A579C(struct unkStruct_809D158 *a0, struct unkStruct_809D158 *a1);
void sub_809D25C(void)
{
@ -368,3 +372,114 @@ void sub_809D25C(void)
gUnknown_20399E8.unk44 = 1;
}
}
void nullsub_120(void)
{}
// Different file below?
extern void *gUnknown_203B4B0;
void sub_809D490(void)
{
UNUSED void *oldPtr = gUnknown_203B4B0; // Needed to match
gUnknown_203B4B0 = MemoryAlloc(0x400, 6);
sub_809D4B0();
}
extern s16 gUnknown_2039A30;
extern s16 gUnknown_2039A32;
extern s16 gUnknown_2039A34;
extern u8 gUnknown_2039A36;
extern u8 gUnknown_2039A38[];
extern u8 gUnknown_2039AC0[];
extern u32 gUnknown_2039B48[];
void sub_809D4B0(void)
{
s32 i;
gUnknown_2039A30 = -1;
gUnknown_2039A32 = -1;
gUnknown_2039A34 = -1;
gUnknown_2039A36 = 0;
for (i = 0; i < 0x81; i++) {
gUnknown_2039A38[i] = 0;
gUnknown_2039AC0[i] = 0;
gUnknown_2039B48[i] = 0;
}
}
void sub_809D508(void)
{
MemoryFree(gUnknown_203B4B0);
gUnknown_203B4B0 = NULL;
}
// -1 didn't match
void sub_809D520(void *a0)
{
u16 *ptr = a0;
u16 v = 0xFFFF;
*ptr = v;
}
extern s32 sub_80A882C(s16);
extern s32 sub_80AC240(s16);
extern s32 sub_80AD158(s16);
s32 sub_809D52C(void *a0)
{
s16 *ptr = a0;
switch (ptr[0])
{
case 0: return 0;
case 1: return sub_80A882C(ptr[1]);
case 2: return sub_80AC240(ptr[1]);
case 3: return sub_80AD158(ptr[1]);
}
return 0;
}
void sub_809D568(GroundScript_ExecutePP_1_sub_not_packed *a0)
{
s32 i;
a0->scriptType = -1;
a0->unk2 = 0;
a0->scriptPointer2 = 0;
a0->scriptPointer1 = 0;
a0->unk14 = 0;
a0->unk10 = 0;
a0->unk20 = 0;
a0->unk1C = 0;
a0->unk22 = -1;
a0->unk24 = 0;
a0->unk26 = 0xFF;
a0->unk28 = 0;
a0->unk2A = 0;
a0->unk2C = 0;
a0->unk30 = 0;
for (i = 0; i < 4; i++) {
a0->unk5C[i] = 0;
}
}
void sub_809D5B8(GroundScript_ExecutePP_1 *a0)
{
s32 i;
a0->unk0 = 0;
a0->unk4 = 0;
a0->unk10 = -1;
a0->unk12 = 0xFF;
sub_809D520(&a0->unkC);
for (i = 0; i < 4; i++) {
a0->unk14[i] = 0;
}
sub_809D568((void *) &a0->unk24); // Casting to void* because packed/not packed
sub_809D568((void *) &a0->unk84); // Casting to void* because packed/not packed
}