From 4855d0f4c59030ceff6f71f44ddecef5c0bb9624 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Mon, 21 Apr 2025 14:50:42 -0700 Subject: [PATCH] more decomp on ground object and event --- asm/ground_event.s | 83 ------------------------------------------ asm/ground_object.s | 87 --------------------------------------------- src/ground_event.c | 50 +++++++++++++++++++++++++- src/ground_object.c | 48 ++++++++++++++++++++++++- 4 files changed, 96 insertions(+), 172 deletions(-) diff --git a/asm/ground_event.s b/asm/ground_event.s index 29a6b5650..f75a1018a 100644 --- a/asm/ground_event.s +++ b/asm/ground_event.s @@ -5,89 +5,6 @@ .text - thumb_func_start AllocGroundEvents -AllocGroundEvents: - push {r4,lr} - ldr r4, _080AD9C8 - movs r0, 0x80 - lsls r0, 3 - movs r1, 0x6 - bl MemoryAlloc - str r0, [r4] - adds r1, r0, 0 - ldr r0, _080AD9CC - adds r4, r0, 0 - movs r2, 0x80 - lsls r2, 9 - adds r3, r2, 0 -_080AD9AC: - ldrh r0, [r1, 0x2] - orrs r0, r4 - strh r0, [r1, 0x2] - adds r0, r2, 0 - adds r2, r3 - asrs r0, 16 - adds r1, 0x20 - cmp r0, 0x1F - ble _080AD9AC - bl DeleteGroundEvents - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_080AD9C8: .4byte gGroundEvents -_080AD9CC: .4byte 0x0000ffff - thumb_func_end AllocGroundEvents - - thumb_func_start DeleteGroundEvents -DeleteGroundEvents: - push {r4-r6,lr} - ldr r0, _080ADA04 - ldr r4, [r0] - movs r1, 0 - movs r6, 0x1 - negs r6, r6 - movs r5, 0x80 - lsls r5, 9 -_080AD9E0: - movs r2, 0x2 - ldrsh r0, [r4, r2] - cmp r0, r6 - beq _080AD9EE - adds r0, r1, 0 - bl GroundEvent_Delete -_080AD9EE: - adds r0, r5, 0 - movs r1, 0x80 - lsls r1, 9 - adds r5, r1 - asrs r1, r0, 16 - adds r4, 0x20 - cmp r1, 0x1F - ble _080AD9E0 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_080ADA04: .4byte gGroundEvents - thumb_func_end DeleteGroundEvents - - thumb_func_start FreeGroundEvents -FreeGroundEvents: - push {r4,lr} - bl DeleteGroundEvents - ldr r4, _080ADA20 - ldr r0, [r4] - bl MemoryFree - movs r0, 0 - str r0, [r4] - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_080ADA20: .4byte gGroundEvents - thumb_func_end FreeGroundEvents - thumb_func_start GroundEvent_Select GroundEvent_Select: push {r4-r7,lr} diff --git a/asm/ground_object.s b/asm/ground_object.s index a29dfb014..4807a0db6 100644 --- a/asm/ground_object.s +++ b/asm/ground_object.s @@ -5,93 +5,6 @@ .text - thumb_func_start AllocGroundObjects -AllocGroundObjects: - push {r4,r5,lr} - ldr r4, _080ABB90 - movs r0, 0xE2 - lsls r0, 5 - movs r1, 0x6 - bl MemoryAlloc - str r0, [r4] - adds r1, r0, 0 - ldr r0, _080ABB94 - adds r5, r0, 0 - movs r4, 0xE2 - lsls r4, 1 - movs r2, 0x80 - lsls r2, 9 - adds r3, r2, 0 -_080ABB74: - ldrh r0, [r1, 0x6] - orrs r0, r5 - strh r0, [r1, 0x6] - adds r0, r2, 0 - adds r2, r3 - asrs r0, 16 - adds r1, r4 - cmp r0, 0xF - ble _080ABB74 - bl DeleteGroundObjects - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_080ABB90: .4byte gGroundObjects -_080ABB94: .4byte 0x0000ffff - thumb_func_end AllocGroundObjects - - thumb_func_start DeleteGroundObjects -DeleteGroundObjects: - push {r4-r6,lr} - ldr r0, _080ABBD0 - ldr r4, [r0] - movs r1, 0 - movs r6, 0x1 - negs r6, r6 - movs r5, 0x80 - lsls r5, 9 -_080ABBA8: - movs r2, 0x6 - ldrsh r0, [r4, r2] - cmp r0, r6 - beq _080ABBB6 - adds r0, r1, 0 - bl GroundObject_Delete -_080ABBB6: - adds r0, r5, 0 - movs r1, 0x80 - lsls r1, 9 - adds r5, r1 - asrs r1, r0, 16 - movs r2, 0xE2 - lsls r2, 1 - adds r4, r2 - cmp r1, 0xF - ble _080ABBA8 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_080ABBD0: .4byte gGroundObjects - thumb_func_end DeleteGroundObjects - - thumb_func_start FreeGroundObjects -FreeGroundObjects: - push {r4,lr} - bl DeleteGroundObjects - ldr r4, _080ABBEC - ldr r0, [r4] - bl MemoryFree - movs r0, 0 - str r0, [r4] - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_080ABBEC: .4byte gGroundObjects - thumb_func_end FreeGroundObjects - thumb_func_start GroundObject_Select GroundObject_Select: push {r4-r7,lr} diff --git a/src/ground_event.c b/src/ground_event.c index 88e328de0..c031512a8 100644 --- a/src/ground_event.c +++ b/src/ground_event.c @@ -1,3 +1,51 @@ #include "global.h" +#include "memory.h" + +struct GroundEvent_sub +{ + s16 unk0; + s16 unk2; + u8 unk4[0x20 - 0x4]; +}; + +struct GroundEvents +{ + // size: 0x400 + struct GroundEvent_sub arr[0x20]; +}; + +IWRAM_INIT struct GroundEvents *gGroundEvents = NULL; + +void DeleteGroundEvents(void); +void GroundEvent_Delete(s32); + +void AllocGroundEvents(void) { + s32 ind; + struct GroundEvent_sub *ptr; + gGroundEvents = MemoryAlloc(sizeof(struct GroundEvents), 0x6); + + for(ind = 0, ptr = &gGroundEvents->arr[ind]; ind < 0x20; ind = (s16)(ind + 1), ptr++) + { + ptr->unk2 |= -1; + } + DeleteGroundEvents(); +} + +void DeleteGroundEvents() { + s32 v1; + struct GroundEvent_sub* current; + + current = &gGroundEvents->arr[0]; + for (v1 = 0; v1 < 0x20; v1 = (s16) (v1 + 0x1), current++) { + if(current->unk2 != -1) + GroundEvent_Delete(v1); + } +} + +void FreeGroundEvents(void) +{ + DeleteGroundEvents(); + MemoryFree(gGroundEvents); + gGroundEvents = NULL; +} -IWRAM_INIT void *gGroundEvents = NULL; diff --git a/src/ground_object.c b/src/ground_object.c index d52fae479..f8622fa67 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -1,3 +1,49 @@ #include "global.h" +#include "memory.h" -IWRAM_INIT void *gGroundObjects = NULL; +typedef struct GroundObject { + // size: 0x1C4 + u8 unk0[6]; + s16 unk6; + u8 fill8[0x1C4 - 8]; +} GroundObject; + +IWRAM_INIT GroundObject *gGroundObjects = NULL; + +void DeleteGroundObjects(void); +void GroundObject_Delete(s32); + +void AllocGroundObjects(void) +{ + + GroundObject *ptr; + s32 index; + + gGroundObjects = MemoryAlloc(0x1C40, 6); + + for(index = 0, ptr = &gGroundObjects[index]; index < 0x10; index = (s16)(index + 1), ptr++) + { + ptr->unk6 |= -1; + } + DeleteGroundObjects(); +} + +void DeleteGroundObjects(void) +{ + GroundObject *ptr; + s32 index; + + ptr = &gGroundObjects[0]; + for(index = 0; index < 0x10; index = (s16)(index + 1), ptr++) + { + if(ptr->unk6 != -1) + GroundObject_Delete(index); + } +} + +void FreeGroundObjects(void) +{ + DeleteGroundObjects(); + MemoryFree(gGroundObjects); + gGroundObjects = NULL; +}