GroundEvent_Add

This commit is contained in:
DizzyEggg
2025-05-13 11:25:19 +02:00
parent d9bc5ea342
commit 2fd84a6e50
3 changed files with 104 additions and 167 deletions

View File

@@ -5,168 +5,6 @@
.text
thumb_func_start GroundEvent_Add
GroundEvent_Add:
push {r4-r7,lr}
mov r7, r9
mov r6, r8
push {r6,r7}
sub sp, 0x14
mov r8, r1
lsls r0, 16
asrs r7, r0, 16
lsls r2, 16
asrs r6, r2, 16
lsls r3, 24
asrs r3, 24
mov r9, r3
ldr r5, [r1, 0x8]
cmp r7, 0
bge _080ADB60
ldr r0, _080ADB38
ldr r4, [r0]
movs r2, 0
movs r0, 0x2
ldrsh r1, [r4, r0]
movs r0, 0x1
negs r0, r0
cmp r1, r0
bne _080ADB3C
movs r7, 0
b _080ADB68
.align 2, 0
_080ADB38: .4byte gGroundEvents
_080ADB3C:
adds r0, r2, 0x1
lsls r0, 16
asrs r2, r0, 16
adds r4, 0x20
cmp r2, 0x1F
bgt _080ADB56
movs r3, 0x2
ldrsh r1, [r4, r3]
movs r0, 0x1
negs r0, r0
cmp r1, r0
bne _080ADB3C
adds r7, r2, 0
_080ADB56:
cmp r7, 0
bge _080ADB68
movs r0, 0x1
negs r0, r0
b _080ADC24
_080ADB60:
ldr r0, _080ADBA0
lsls r1, r7, 5
ldr r0, [r0]
adds r4, r0, r1
_080ADB68:
ldr r1, _080ADBA4
movs r0, 0
ldrsh r3, [r5, r0]
str r6, [sp]
mov r2, r9
str r2, [sp, 0x4]
mov r2, r8
ldr r0, [r2, 0x8]
ldr r0, [r0, 0x8]
str r0, [sp, 0x8]
movs r0, 0
adds r2, r7, 0
bl Log
strh r7, [r4]
ldrh r0, [r5]
strh r0, [r4, 0x2]
strh r6, [r4, 0x4]
mov r3, r9
strb r3, [r4, 0x6]
movs r6, 0x2
ldrsh r0, [r5, r6]
cmp r0, 0x1
blt _080ADBA8
cmp r0, 0x2
bgt _080ADBA8
movs r0, 0x60
b _080ADBAA
.align 2, 0
_080ADBA0: .4byte gGroundEvents
_080ADBA4: .4byte gGroundEventAddText
_080ADBA8:
movs r0, 0x20
_080ADBAA:
str r0, [r4, 0x8]
mov r3, r8
ldrb r0, [r3]
lsls r1, r0, 11
ldrb r0, [r3, 0x1]
lsls r2, r0, 11
mov r5, r8
adds r5, 0x4
add r6, sp, 0xC
mov r12, r6
ldrb r6, [r5, 0x2]
movs r0, 0x4
ands r0, r6
cmp r0, 0
bne _080ADBDE
ldrb r0, [r3, 0x4]
lsls r3, r0, 11
str r3, [sp, 0xC]
movs r0, 0x2
ands r0, r6
cmp r0, 0
beq _080ADBDE
movs r6, 0x80
lsls r6, 3
adds r0, r3, r6
str r0, [sp, 0xC]
_080ADBDE:
ldrb r6, [r5, 0x3]
movs r0, 0x4
ands r0, r6
cmp r0, 0
bne _080ADC02
ldrb r0, [r5, 0x1]
lsls r3, r0, 11
mov r0, r12
str r3, [r0, 0x4]
movs r0, 0x2
ands r0, r6
cmp r0, 0
beq _080ADC02
movs r5, 0x80
lsls r5, 3
adds r0, r3, r5
mov r6, r12
str r0, [r6, 0x4]
_080ADC02:
ldr r0, [sp, 0xC]
str r0, [r4, 0xC]
ldr r0, [sp, 0xC]
adds r0, r1
str r0, [r4, 0x14]
ldr r0, [sp, 0x10]
str r0, [r4, 0x10]
ldr r0, [sp, 0x10]
adds r0, r2
str r0, [r4, 0x18]
mov r1, r8
ldr r0, [r1, 0x8]
ldr r0, [r0, 0x8]
str r0, [r4, 0x1C]
bl GroundLives_CancelBlank_2
adds r0, r7, 0
_080ADC24:
add sp, 0x14
pop {r3,r4}
mov r8, r3
mov r9, r4
pop {r4-r7}
pop {r1}
bx r1
thumb_func_end GroundEvent_Add
thumb_func_start GroundEvent_Delete
GroundEvent_Delete:
push {r4,lr}

View File

@@ -131,7 +131,7 @@ typedef struct GroundMapAction
typedef struct ScriptRef
{
u16 id;
s16 id;
s16 type;
u8 *name;
const ScriptCommand *script;

View File

@@ -9,18 +9,26 @@ typedef struct GroundEvent
s16 unk2;
s16 unk4; // scriptID
s8 unk6; // sector
u8 unk7[0x20 - 0x7];
s32 unk8;
s32 unkC;
s32 unk10;
s32 unk14;
s32 unk18;
const ScriptCommand *unk1C;
} GroundEvent;
IWRAM_INIT GroundEvent *gGroundEvents = NULL;
extern void GroundLives_CancelBlank_2(void);
void DeleteGroundEvents(void);
void GroundEvent_Delete(s32);
const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *);
s16 GroundEvent_Add(s32 id, const GroundEventData*, s32 group, s32 sector);
s32 GroundEvent_Add(s32 id, const GroundEventData*, s32 group, s32 sector);
extern DebugLocation gUnknown_81187DC;
extern u8 gGroundEventSelectText[];
extern u8 gGroundEventCancelText[];
extern u8 gGroundEventAddText[];
void AllocGroundEvents(void) {
s32 ind;
@@ -37,9 +45,9 @@ void AllocGroundEvents(void) {
void DeleteGroundEvents(void) {
s32 v1;
GroundEvent* current;
current = &gGroundEvents[0];
for (v1 = 0; v1 < 0x20; v1 = (s16) (v1 + 0x1), current++) {
for (v1 = 0; v1 < 0x20; v1 = (s16) (v1 + 0x1), current++) {
if(current->unk2 != -1)
GroundEvent_Delete(v1);
}
@@ -105,3 +113,94 @@ void GroundEvent_Cancel(s32 scriptID, s32 sector)
}
}
static inline void SetUnkInGroundEvent(const CompactPos *posPtr, s32 *dst)
{
if (!(posPtr->xFlags & 4)) {
s32 unk = posPtr->xTiles << 11;
dst[0] = unk;
if (posPtr->xFlags & 2) {
dst[0] = unk + 0x400;
}
}
if (!(posPtr->yFlags & 4)) {
s32 unk = posPtr->yTiles << 11;
dst[1] = unk;
if (posPtr->yFlags & 2) {
dst[1] = unk + 0x400;
}
}
}
struct TestStruct
{
u32 unk0;
u32 unk4;
};
extern struct TestStruct sUnknown; // Todo: figure out or guess what this variable could be.
s32 GroundEvent_Add(s32 id, const GroundEventData *eventData, s32 group, s32 sector)
{
s32 i;
s32 scriptID_s32 = (s16) id;
s32 group_s32 = (s16) group;
s32 sector_s32 = (s8) sector;
const ScriptRef *script;
GroundEvent *ptr;
struct TestStruct r;
s32 sp[2];
ASM_MATCH_TRICK(sector_s32);
script = eventData->script;
if (scriptID_s32 < 0) {
ptr = &gGroundEvents[0];
for (i = 0; i < 0x20; i = (s16)(i + 1), ptr++) {
if (ptr->unk2 == -1) {
scriptID_s32 = i;
break;
}
}
if (scriptID_s32 < 0) {
return -1;
}
}
else {
ptr = &gGroundEvents[scriptID_s32];
}
Log(0, gGroundEventAddText, scriptID_s32, script->id, group_s32, sector_s32, eventData->script->script);
ptr->unk0 = scriptID_s32;
ptr->unk2 = script->id;
ptr->unk4 = group_s32;
ptr->unk6 = sector_s32;
switch (script->type) {
case 1:
case 2:
ptr->unk8 = 0x60;
break;
case 7:
default:
ptr->unk8 = 0x20;
break;
}
// The line below effectively does nothing(it's not even generated in the asm, agbcc ignores it, but changes regalloc...), because 'r' is overwritten in the next two instructions, however it is REQUIRED to match. Only discovered, because it's present in Blue's asm.
r = sUnknown;
r.unk0 = eventData->kind << 11;
r.unk4 = eventData->unk1 << 11;
SetUnkInGroundEvent(&eventData->pos, sp);
ptr->unkC = sp[0];
ptr->unk14 = sp[0] + r.unk0;
ptr->unk10 = sp[1];
ptr->unk18 = sp[1] + r.unk4;
ptr->unk1C = eventData->script->script;
GroundLives_CancelBlank_2();
return scriptID_s32;
}