From 4b2f32bfd20ec8c37e28b317cad8672a12597b3b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Dec 2024 12:00:19 +0100 Subject: [PATCH 1/6] decompile memory.s --- asm/memory.s | 416 ----------------------------------------------- include/memory.h | 2 +- ld_script.txt | 2 - src/memory.c | 374 +++++++++++++++++++++++++++++++++++++++++- src/memory_mid.c | 201 ----------------------- 5 files changed, 374 insertions(+), 621 deletions(-) delete mode 100644 asm/memory.s delete mode 100644 src/memory_mid.c diff --git a/asm/memory.s b/asm/memory.s deleted file mode 100644 index 8fd07a209..000000000 --- a/asm/memory.s +++ /dev/null @@ -1,416 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start MemorySearchFromFront -MemorySearchFromFront: - push {r4-r7,lr} - adds r5, r0, 0 - adds r6, r2, 0 - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - beq _080030CC - movs r4, 0 - ldr r3, [r5, 0x8] - ldr r2, [r5, 0xC] - cmp r4, r2 - bge _08003104 - ldr r0, [r3, 0x4] - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - bne _08003090 - ldr r0, [r3, 0x10] - cmp r0, r6 - blt _080030AC - movs r0, 0 - b _08003108 -_08003090: - adds r4, 0x1 - adds r3, 0x18 - cmp r4, r2 - bge _08003104 - ldr r0, [r3, 0x4] - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - bne _08003090 - ldr r0, [r3, 0x10] - cmp r0, r6 - blt _080030AC -_080030A8: - adds r0, r4, 0 - b _08003108 -_080030AC: - cmp r4, r2 - bge _08003104 - movs r5, 0x1 - adds r1, r2, 0 -_080030B4: - ldr r0, [r3, 0x4] - ands r0, r5 - cmp r0, 0 - bne _080030C2 - ldr r0, [r3, 0x10] - cmp r0, r6 - bge _080030A8 -_080030C2: - adds r4, 0x1 - adds r3, 0x18 - cmp r4, r1 - blt _080030B4 - b _08003104 -_080030CC: - movs r7, 0x1 - negs r7, r7 - ldr r1, _08003100 - movs r4, 0 - ldr r3, [r5, 0x8] - ldr r2, [r5, 0xC] - cmp r4, r2 - bge _080030FC - movs r5, 0x1 -_080030DE: - ldr r0, [r3, 0x4] - ands r0, r5 - cmp r0, 0 - bne _080030F4 - ldr r0, [r3, 0x10] - cmp r0, r6 - blt _080030F4 - cmp r0, r1 - bge _080030F4 - adds r7, r4, 0 - adds r1, r0, 0 -_080030F4: - adds r4, 0x1 - adds r3, 0x18 - cmp r4, r2 - blt _080030DE -_080030FC: - adds r0, r7, 0 - b _08003108 - .align 2, 0 -_08003100: .4byte 0x00024001 -_08003104: - movs r0, 0x1 - negs r0, r0 -_08003108: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end MemorySearchFromFront - - thumb_func_start MemorySearchFromBack -MemorySearchFromBack: - push {r4-r7,lr} - adds r4, r0, 0 - adds r5, r2, 0 - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - beq _08003168 - ldr r0, [r4, 0xC] - subs r3, r0, 0x1 - lsls r0, r3, 1 - adds r0, r3 - lsls r0, 3 - ldr r1, [r4, 0x8] - adds r2, r1, r0 - b _08003132 -_0800312E: - subs r3, 0x1 - subs r2, 0x18 -_08003132: - cmp r3, 0 - blt _080031A8 - ldr r0, [r2, 0x4] - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0800312E - ldr r0, [r2, 0x10] - cmp r0, r5 - blt _0800314A -_08003146: - adds r0, r3, 0 - b _080031AC -_0800314A: - cmp r3, 0 - blt _080031A8 - movs r1, 0x1 -_08003150: - ldr r0, [r2, 0x4] - ands r0, r1 - cmp r0, 0 - bne _0800315E - ldr r0, [r2, 0x10] - cmp r0, r5 - bge _08003146 -_0800315E: - subs r3, 0x1 - subs r2, 0x18 - cmp r3, 0 - bge _08003150 - b _080031A8 -_08003168: - movs r7, 0x1 - negs r7, r7 - ldr r6, =0x24001 - ldr r0, [r4, 0xC] - subs r3, r0, 0x1 - lsls r0, r3, 1 - adds r0, r3 - lsls r0, 3 - ldr r1, [r4, 0x8] - adds r2, r1, r0 - cmp r3, 0 - blt _080031A0 - movs r1, 0x1 -_08003182: - ldr r0, [r2, 0x4] - ands r0, r1 - cmp r0, 0 - bne _08003198 - ldr r0, [r2, 0x10] - cmp r0, r5 - blt _08003198 - cmp r0, r6 - bge _08003198 - adds r7, r3, 0 - adds r6, r0, 0 -_08003198: - subs r3, 0x1 - subs r2, 0x18 - cmp r3, 0 - bge _08003182 -_080031A0: - adds r0, r7, 0 - b _080031AC - .align 2, 0 - .pool -_080031A8: - movs r0, 0x1 - negs r0, r0 -_080031AC: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end MemorySearchFromBack - - thumb_func_start _LocateSetFront -_LocateSetFront: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x14 - str r0, [sp, 0x8] - str r1, [sp, 0xC] - str r2, [sp] - str r3, [sp, 0x4] - adds r0, r3, 0 - adds r0, 0x3 - str r0, [sp, 0x10] - movs r0, 0x4 - negs r0, r0 - ldr r1, [sp, 0x10] - ands r1, r0 - str r1, [sp, 0x10] - ldr r2, [sp, 0xC] - lsls r2, 1 - mov r12, r2 - ldr r0, [sp, 0xC] - add r0, r12 - lsls r0, 3 - ldr r5, [sp, 0x8] - ldr r2, [r5, 0x8] - adds r4, r2, r0 - ldr r0, [r4, 0x10] - cmp r0, r1 - ble _08003260 - ldr r3, [r5, 0xC] - lsls r0, r3, 1 - adds r0, r3 - lsls r0, 3 - adds r1, r2, r0 - mov r9, r12 - mov r10, r2 - mov r12, r3 - ldr r6, [r5, 0x10] - mov r8, r6 - ldr r7, [sp, 0xC] - cmp r12, r7 - ble _08003222 -_0800320A: - adds r2, r1, 0 - subs r2, 0x18 - adds r0, r2, 0 - ldm r0!, {r5-r7} - stm r1!, {r5-r7} - ldm r0!, {r5-r7} - stm r1!, {r5-r7} - subs r3, 0x1 - adds r1, r2, 0 - ldr r0, [sp, 0xC] - cmp r3, r0 - bgt _0800320A -_08003222: - mov r2, r12 - adds r2, 0x1 - ldr r1, [sp, 0x8] - str r2, [r1, 0xC] - cmp r2, r8 - ble _08003240 - ldr r0, =gUnknown_80B7EB8 - ldr r1, =gUnknown_80B7EC4 - mov r3, r8 - bl FatalError - .align 2, 0 - .pool -_08003240: - ldr r0, [sp, 0xC] - add r0, r9 - lsls r0, 3 - adds r0, 0x18 - mov r2, r10 - adds r1, r2, r0 - ldr r0, [r1, 0xC] - ldr r5, [sp, 0x10] - adds r0, r5 - str r0, [r1, 0xC] - ldr r0, [r1, 0x10] - subs r0, r5 - str r0, [r1, 0x10] - str r5, [r4, 0x10] - ldr r6, [sp, 0x4] - str r6, [r4, 0x14] -_08003260: - ldr r0, [sp] - bl xxx_memory_attr_related - str r0, [r4] - ldr r7, [sp] - str r7, [r4, 0x4] - ldr r0, [sp, 0x34] - str r0, [r4, 0x8] - adds r0, r4, 0 - add sp, 0x14 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end _LocateSetFront - - thumb_func_start _LocateSetBack -_LocateSetBack: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x14 - str r0, [sp, 0x8] - str r1, [sp, 0xC] - str r2, [sp] - str r3, [sp, 0x4] - adds r0, r3, 0 - adds r0, 0x3 - str r0, [sp, 0x10] - movs r0, 0x4 - negs r0, r0 - ldr r1, [sp, 0x10] - ands r1, r0 - str r1, [sp, 0x10] - ldr r2, [sp, 0xC] - lsls r0, r2, 1 - adds r0, r2 - lsls r0, 3 - ldr r5, [sp, 0x8] - ldr r1, [r5, 0x8] - adds r4, r1, r0 - ldr r0, [r4, 0x10] - ldr r6, [sp, 0x10] - cmp r0, r6 - ble _08003328 - ldr r3, [r5, 0xC] - lsls r0, r3, 1 - adds r0, r3 - lsls r0, 3 - adds r1, r0 - mov r12, r3 - ldr r7, [r5, 0x10] - mov r8, r7 - ldr r0, [r4, 0xC] - mov r9, r0 - movs r2, 0x18 - adds r2, r4 - mov r10, r2 - ldr r5, [sp, 0xC] - cmp r12, r5 - ble _080032F6 -_080032DE: - adds r2, r1, 0 - subs r2, 0x18 - adds r0, r2, 0 - ldm r0!, {r5-r7} - stm r1!, {r5-r7} - ldm r0!, {r5-r7} - stm r1!, {r5-r7} - subs r3, 0x1 - adds r1, r2, 0 - ldr r6, [sp, 0xC] - cmp r3, r6 - bgt _080032DE -_080032F6: - mov r2, r12 - adds r2, 0x1 - ldr r7, [sp, 0x8] - str r2, [r7, 0xC] - cmp r2, r8 - ble _08003314 - ldr r0, =gUnknown_80B7EFC - ldr r1, =gUnknown_80B7EC4 - mov r3, r8 - bl FatalError - .align 2, 0 - .pool -_08003314: - ldr r0, [r4, 0x10] - ldr r1, [sp, 0x10] - subs r0, r1 - str r0, [r4, 0x10] - add r0, r9 - mov r4, r10 - str r0, [r4, 0xC] - str r1, [r4, 0x10] - ldr r2, [sp, 0x4] - str r2, [r4, 0x14] -_08003328: - ldr r0, [sp] - bl xxx_memory_attr_related - str r0, [r4] - ldr r5, [sp] - str r5, [r4, 0x4] - ldr r0, [sp, 0x34] - str r0, [r4, 0x8] - adds r0, r4, 0 - add sp, 0x14 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end _LocateSetBack - - - .align 2, 0 @ Don't pad with nop. diff --git a/include/memory.h b/include/memory.h index 48bba1793..37f3aad9f 100644 --- a/include/memory.h +++ b/include/memory.h @@ -41,7 +41,7 @@ struct HeapDescriptor /* 0x4 */ struct HeapDescriptor *parentHeap; /* 0x8 */ struct HeapFreeListElement *freeList; /* 0xC */ s32 freeCount; - /* 0x10 */ u32 freeListLength; + /* 0x10 */ s32 freeListLength; /* 0x14 */ u8 *start; /* 0x18 */ u32 size; }; diff --git a/ld_script.txt b/ld_script.txt index 7e04d3d29..a6d54e78c 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -52,8 +52,6 @@ SECTIONS { src/code_8002774.o(.text); asm/code_8002774_2.o(.text); src/memory.o(.text); - asm/memory.o(.text); - src/memory_mid.o(.text); asm/code_80035F0.o(.text); src/other_random.o(.text); src/util.o(.text); diff --git a/src/memory.c b/src/memory.c index 0a63bfd33..f30b2ff89 100644 --- a/src/memory.c +++ b/src/memory.c @@ -34,6 +34,7 @@ void MemoryClear16(u16 *dest, s32 size) *dest++ = 0; } } + void MemoryClear32(u32 *dest, s32 size) { CpuClear(dest, size); @@ -145,7 +146,7 @@ void InitSubHeap(struct HeapDescriptor *parentHeap, struct HeapMemoryBlock2 *blo DoInitHeap(parentHeap, &settings, freeList, freeListMax); } -u8 xxx_memory_attr_related(u32 r0) +u32 xxx_memory_attr_related(u32 r0) { u32 temp; u32 return_var; @@ -177,3 +178,374 @@ u8 xxx_memory_attr_related(u32 r0) } return return_var; } + +s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32 atb, s32 size) +{ + s32 i; + struct HeapFreeListElement *curr; + + if (atb & 4) { + i = 0; + curr = &heap->freeList[0]; + + for (; i < heap->freeCount; i++, curr++) { + if (!(curr->atb & 1)) { + if (curr->block.size >= size) + return i; + + break; + } + } + + for (; i < heap->freeCount; i++, curr++) { + if (!(curr->atb & 1)) { + if (curr->block.size >= size) + return i; + } + } + + } + else { + s32 ret = -1; + s32 sizeMax = HEAP_SIZE + 1; + i = 0; + curr = &heap->freeList[0]; + + for (; i < heap->freeCount; i++, curr++) { + if (!(curr->atb & 1) && curr->block.size >= size && curr->block.size < sizeMax) { + ret = i; + sizeMax = curr->block.size; + } + } + return ret; + } + + return -1; +} + +s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32 atb, s32 size) +{ + s32 i; + struct HeapFreeListElement *curr; + + if (atb & 4) { + i = heap->freeCount - 1; + curr = &heap->freeList[i]; + + for (; i >= 0; i--, curr--) { + if (!(curr->atb & 1)) { + if (curr->block.size >= size) + return i; + + break; + } + } + + for (; i >= 0; i--, curr--) { + if (!(curr->atb & 1)) { + if (curr->block.size >= size) + return i; + } + } + + } + else { + s32 ret = -1; + s32 sizeMax = HEAP_SIZE + 1; + i = heap->freeCount - 1; + curr = &heap->freeList[i]; + + for (; i >= 0; i--, curr--) { + if (!(curr->atb & 1) && curr->block.size >= size && curr->block.size < sizeMax) { + ret = i; + sizeMax = curr->block.size; + } + } + return ret; + } + + return -1; +} + +// Todo: fix fatal error and struct unkMemoryStruct2 * +void FatalError(const void *, const char *, ...) __attribute__((noreturn)); +extern const char *const gUnknown_80B7EB8; +extern const char *const gUnknown_80B7EFC; +extern const char gUnknown_80B7EC4[]; + +struct unkMemoryStruct2 * _LocateSetFront(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) +{ + s32 i; + struct HeapFreeListElement *curr; + struct HeapFreeListElement *block; + s32 sizeAligned; + + sizeAligned = size + 3; + sizeAligned &= ~(3); + curr = &heap->freeList[index]; + if (curr->block.size > sizeAligned) { + i = heap->freeCount; + block = &heap->freeList[heap->freeCount]; + for (; i > index; i--, block--) { + block[0] = block[-1]; + } + + heap->freeCount++; + if (heap->freeCount > heap->freeListLength) { + // ../system/memory_locate.c + // Memory Locate sprit max over [%3d/%3d] + FatalError(&gUnknown_80B7EB8, gUnknown_80B7EC4, heap->freeCount, heap->freeListLength); + } + + block = &heap->freeList[index + 1]; + block->block.start += sizeAligned; + block->block.size -= sizeAligned; + + curr->block.size = sizeAligned; + curr->block.allocatedSize = size; + } + + curr->unk_atb = xxx_memory_attr_related(atb); + curr->atb = atb; + curr->grp = group; + return (void*) curr; +} + +struct unkMemoryStruct2 * _LocateSetBack(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) +{ + s32 i; + struct HeapFreeListElement *curr; + struct HeapFreeListElement *block; + s32 sizeAligned; + u8 *newBlockStart; + + sizeAligned = size + 3; + sizeAligned &= ~(3); + curr = &heap->freeList[index]; + if (curr->block.size > sizeAligned) { + i = heap->freeCount; + block = &heap->freeList[heap->freeCount]; + for (; i > index; i--, block--) { + block[0] = block[-1]; + } + + heap->freeCount++; + if (heap->freeCount > heap->freeListLength) { + // ../system/memory_locate.c + // Memory Locate sprit max over [%3d/%3d] + FatalError(&gUnknown_80B7EFC, gUnknown_80B7EC4, heap->freeCount, heap->freeListLength); + } + + + curr->block.size -= sizeAligned; + newBlockStart = curr->block.size + curr->block.start; + + curr++; + curr->block.start = newBlockStart; + curr->block.size = sizeAligned; + curr->block.allocatedSize = size; + } + + curr->unk_atb = xxx_memory_attr_related(atb); + curr->atb = atb; + curr->grp = group; + return (void*) curr; +} + +extern u32 gUnknown_80B7F14; +extern u32 gUnknown_80B7F88; +extern const char gLocateSetErrorMessage[]; +extern struct HeapDescriptor gMainHeapDescriptor; +extern const char gLocalCreateErrorMessage[]; + +extern s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32, s32); +extern s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32, s32); + +void DoFree(struct HeapDescriptor *, void *); +void *DoAlloc(struct HeapDescriptor *, s32, u32); + + + + +struct HeapDescriptor* _LocateSet(struct HeapDescriptor *heap, s32 size, s32 group) +{ + s32 index; + struct unkMemoryStruct2 * uVar2; + s32 atb; + + if (heap == NULL) { + heap = &gMainHeapDescriptor; + } + + // Set some sort flag/attr? + atb = group >> 8 | 1; + + // Reset it? + group = group & 0xff; + + if ((atb & 2) != 0) { + index = MemorySearchFromFront(heap,atb,size); + if (index < 0) goto error; + uVar2 = _LocateSetFront(heap,index,atb,size,group); + return uVar2->unkC; + } + else { + index = MemorySearchFromBack(heap,atb,size); + if (index < 0) goto error; + uVar2 = _LocateSetBack(heap,index,atb,size,group); + return uVar2->unkC; + } + +error: + // LocateSet [%p] buffer %8x size can't locate + // atb %02x grp %3d + FatalError(&gUnknown_80B7F14, + gLocateSetErrorMessage, + heap,size,atb,group); +} + +void *MemoryAlloc(s32 size, s32 group) +{ + DoAlloc(&gMainHeapDescriptor, size, group); +} + +void MemoryFree(void *a) +{ + DoFree(&gMainHeapDescriptor, a); +} + +struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHeap,u32 size,u32 param_3,u32 group) +{ + int index; + struct unkMemoryStruct2 *iVar2; + struct HeapDescriptor *iVar3; + struct unkMemoryStruct local_1c; + + if (parentHeap == NULL) { + parentHeap = &gMainHeapDescriptor; + } + + index = MemorySearchFromBack(parentHeap,9,size); + if (index < 0) + // Memroy LocalCreate buffer %08x size can't locate + FatalError(&gUnknown_80B7F88,gLocalCreateErrorMessage,size); + + iVar2 = _LocateSetBack(parentHeap,index,9,size,group); + local_1c.unk0 = iVar2->unkC; + local_1c.end = iVar2->end; + + iVar3 = DoCreateSubHeap(&local_1c,param_3); + iVar3->parentHeap = parentHeap; + return iVar3; +} + +struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b) +{ + struct HeapMemoryBlock2 s2; + struct HeapDescriptor *a1; + u32 end; + + a1 = a->unk0; + s2.start = (struct HeapFreeListElement *)((u8*)a1 + sizeof(struct HeapDescriptor)); + end = a->end; + s2.size = end - sizeof(struct HeapDescriptor); + InitSubHeap(a1, &s2, b); + return a1; +} + +void xxx_unused_memory_free(struct HeapDescriptor *a1) +{ + bool8 b; + s32 i; + bool8 temp; + + if (a1 == NULL) + return; + + b = FALSE; + if (a1->freeCount == 1 && a1->freeList->atb == 0) + b = TRUE; + + if (b) { + temp = FALSE; + i = 0; + for (; i < gHeapCount; i++) { + if (gHeapDescriptorList[i] == a1) { + gHeapCount--; + for (; i < gHeapCount; i++) { + gHeapDescriptorList[i] = gHeapDescriptorList[i + 1]; + } + temp = TRUE; + break; + } + } + if (temp && a1->parentHeap != NULL) + DoFree(a1->parentHeap, a1); + } +} + +void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2) +{ + return _LocateSet(heap, size, a2 | 0x100); +} + +void DoFree(struct HeapDescriptor *heapDescriptior, void *ptrToFree) +{ + struct HeapFreeListElement *curr; + struct HeapFreeListElement *next; + struct HeapFreeListElement *prev; + s32 i; + + if (heapDescriptior == NULL) + heapDescriptior = &gMainHeapDescriptor; + + if (ptrToFree == NULL) + return; + + i = 0; + curr = &heapDescriptior->freeList[0]; + for (; i < heapDescriptior->freeCount; i++, curr++) { + if (curr->block.start == (u8 *)ptrToFree) { + curr->unk_atb = 0; + curr->atb = 0; + curr->block.allocatedSize = 0; + curr->grp = 0; + + if (i < heapDescriptior->freeCount - 1) { + s32 j; + + next = curr + 1; + if (next->atb == 0) { + curr->block.size += next->block.size; + heapDescriptior->freeCount--; + for (j = i + 1; j < heapDescriptior->freeCount; j++, next++) + next[0] = next[1]; + } + } + + if (i >= 1) { + s32 j; + prev = curr - 1; + if (prev->atb == 0) { + prev->block.size += curr->block.size; + heapDescriptior->freeCount--; + prev = curr; + for (j = i; j < heapDescriptior->freeCount; j++, prev++) + prev[0] = prev[1]; + } + } + + break; + } + } +} + +void nullsub_141(void) +{ + +} + +void nullsub_142(void) +{ + +} diff --git a/src/memory_mid.c b/src/memory_mid.c deleted file mode 100644 index c33585655..000000000 --- a/src/memory_mid.c +++ /dev/null @@ -1,201 +0,0 @@ -#include "global.h" -#include "memory.h" - -extern u32 gUnknown_80B7F14; -extern u32 gUnknown_80B7F88; -extern const char gLocateSetErrorMessage[]; -extern struct HeapDescriptor gMainHeapDescriptor; -extern const char gLocalCreateErrorMessage[]; - -extern s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32, s32); -extern s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32, s32); -extern struct unkMemoryStruct2 * _LocateSetBack(struct HeapDescriptor *, u32, u32, u32, u32); -extern struct unkMemoryStruct2 * _LocateSetFront(struct HeapDescriptor *, u32, u32, u32, u32); -void DoFree(struct HeapDescriptor *, void *); -void *DoAlloc(struct HeapDescriptor *, s32, u32); - -void FatalError(u32 *, const char *, ...) __attribute__((noreturn)); - - -struct HeapDescriptor* _LocateSet(struct HeapDescriptor *heap, s32 size, s32 group) -{ - s32 index; - struct unkMemoryStruct2 * uVar2; - s32 atb; - - if (heap == NULL) { - heap = &gMainHeapDescriptor; - } - - // Set some sort flag/attr? - atb = group >> 8 | 1; - - // Reset it? - group = group & 0xff; - - if ((atb & 2) != 0) { - index = MemorySearchFromFront(heap,atb,size); - if (index < 0) goto error; - uVar2 = _LocateSetFront(heap,index,atb,size,group); - return uVar2->unkC; - } - else { - index = MemorySearchFromBack(heap,atb,size); - if (index < 0) goto error; - uVar2 = _LocateSetBack(heap,index,atb,size,group); - return uVar2->unkC; - } - -error: - // LocateSet [%p] buffer %8x size can't locate - // atb %02x grp %3d - FatalError(&gUnknown_80B7F14, - gLocateSetErrorMessage, - heap,size,atb,group); -} - -void *MemoryAlloc(s32 size, s32 group) -{ - DoAlloc(&gMainHeapDescriptor, size, group); -} - -void MemoryFree(void *a) -{ - DoFree(&gMainHeapDescriptor, a); -} - -struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHeap,u32 size,u32 param_3,u32 group) -{ - int index; - struct unkMemoryStruct2 *iVar2; - struct HeapDescriptor *iVar3; - struct unkMemoryStruct local_1c; - - if (parentHeap == NULL) { - parentHeap = &gMainHeapDescriptor; - } - - index = MemorySearchFromBack(parentHeap,9,size); - if (index < 0) - // Memroy LocalCreate buffer %08x size can't locate - FatalError(&gUnknown_80B7F88,gLocalCreateErrorMessage,size); - - iVar2 = _LocateSetBack(parentHeap,index,9,size,group); - local_1c.unk0 = iVar2->unkC; - local_1c.end = iVar2->end; - - iVar3 = DoCreateSubHeap(&local_1c,param_3); - iVar3->parentHeap = parentHeap; - return iVar3; -} - -struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b) -{ - struct HeapMemoryBlock2 s2; - struct HeapDescriptor *a1; - u32 end; - - a1 = a->unk0; - s2.start = (struct HeapFreeListElement *)((u8*)a1 + sizeof(struct HeapDescriptor)); - end = a->end; - s2.size = end - sizeof(struct HeapDescriptor); - InitSubHeap(a1, &s2, b); - return a1; -} - -void xxx_unused_memory_free(struct HeapDescriptor *a1) -{ - bool8 b; - s32 i; - bool8 temp; - - if (a1 == NULL) - return; - - b = FALSE; - if (a1->freeCount == 1 && a1->freeList->atb == 0) - b = TRUE; - - if (b) { - temp = FALSE; - i = 0; - for (; i < gHeapCount; i++) { - if (gHeapDescriptorList[i] == a1) { - gHeapCount--; - for (; i < gHeapCount; i++) { - gHeapDescriptorList[i] = gHeapDescriptorList[i + 1]; - } - temp = TRUE; - break; - } - } - if (temp && a1->parentHeap != NULL) - DoFree(a1->parentHeap, a1); - } -} - -void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2) -{ - return _LocateSet(heap, size, a2 | 0x100); -} - -void DoFree(struct HeapDescriptor *heapDescriptior, void *ptrToFree) -{ - struct HeapFreeListElement *curr; - struct HeapFreeListElement *next; - struct HeapFreeListElement *prev; - s32 i; - - if (heapDescriptior == NULL) - heapDescriptior = &gMainHeapDescriptor; - - if (ptrToFree == NULL) - return; - - i = 0; - curr = &heapDescriptior->freeList[0]; - for (; i < heapDescriptior->freeCount; i++, curr++) { - if (curr->block.start == (u8 *)ptrToFree) { - curr->unk_atb = 0; - curr->atb = 0; - curr->block.allocatedSize = 0; - curr->grp = 0; - - if (i < heapDescriptior->freeCount - 1) { - s32 j; - - next = curr + 1; - if (next->atb == 0) { - curr->block.size += next->block.size; - heapDescriptior->freeCount--; - for (j = i + 1; j < heapDescriptior->freeCount; j++, next++) - next[0] = next[1]; - } - } - - if (i >= 1) { - s32 j; - prev = curr - 1; - if (prev->atb == 0) { - prev->block.size += curr->block.size; - heapDescriptior->freeCount--; - prev = curr; - for (j = i; j < heapDescriptior->freeCount; j++, prev++) - prev[0] = prev[1]; - } - } - - break; - } - } -} - -void nullsub_141(void) -{ - -} - -void nullsub_142(void) -{ - -} From 750bdcf2a55fe3857607ad5c887bd7dc16adbd1b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Dec 2024 12:19:15 +0100 Subject: [PATCH 2/6] get rid of unkMemoryStruct --- include/memory.h | 9 -------- src/memory.c | 58 ++++++++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/include/memory.h b/include/memory.h index 37f3aad9f..f6cb17d77 100644 --- a/include/memory.h +++ b/include/memory.h @@ -53,14 +53,6 @@ struct unkMemoryStruct u32 end; }; -// size: 0x1C -struct unkMemoryStruct2 -{ - u8 fill[0xC]; - /* 0xC */ struct HeapDescriptor *unkC; - /* 0x10 */ u32 end; -}; - extern struct HeapDescriptor *gHeapDescriptorList[8]; extern s32 gHeapCount; @@ -82,7 +74,6 @@ void MemoryCopy32(u32 *dest, u32 *src, s32 size); void InitHeapInternal(void); void DoInitHeap(struct HeapDescriptor *, struct HeapSettings *, struct HeapFreeListElement *, u32); void InitSubHeap(struct HeapDescriptor *, struct HeapMemoryBlock2 *, u32); -struct HeapDescriptor * _LocateSet(struct HeapDescriptor *heap, s32 size, s32 param_3); void *MemoryAlloc(s32 size, s32 group); void MemoryFree(void *a); struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b); diff --git a/src/memory.c b/src/memory.c index f30b2ff89..953587704 100644 --- a/src/memory.c +++ b/src/memory.c @@ -108,7 +108,7 @@ void DoInitHeap(struct HeapDescriptor *descriptor, struct HeapSettings *settings { u32 aligned_size; - aligned_size = settings->size & 0xFFFFFFFC; + aligned_size = settings->size & ~(3); gHeapDescriptorList[gHeapCount++] = descriptor; @@ -267,13 +267,24 @@ s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32 atb, s32 size) return -1; } -// Todo: fix fatal error and struct unkMemoryStruct2 * +// Todo: fix fatal error void FatalError(const void *, const char *, ...) __attribute__((noreturn)); extern const char *const gUnknown_80B7EB8; extern const char *const gUnknown_80B7EFC; extern const char gUnknown_80B7EC4[]; +extern u32 gUnknown_80B7F14; +extern u32 gUnknown_80B7F88; +extern const char gLocateSetErrorMessage[]; +extern struct HeapDescriptor gMainHeapDescriptor; +extern const char gLocalCreateErrorMessage[]; -struct unkMemoryStruct2 * _LocateSetFront(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) +extern s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32, s32); +extern s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32, s32); + +void DoFree(struct HeapDescriptor *, void *); +void *DoAlloc(struct HeapDescriptor *, s32, u32); + +struct HeapFreeListElement * _LocateSetFront(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) { s32 i; struct HeapFreeListElement *curr; @@ -308,10 +319,10 @@ struct unkMemoryStruct2 * _LocateSetFront(struct HeapDescriptor *heap, s32 index curr->unk_atb = xxx_memory_attr_related(atb); curr->atb = atb; curr->grp = group; - return (void*) curr; + return curr; } -struct unkMemoryStruct2 * _LocateSetBack(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) +struct HeapFreeListElement * _LocateSetBack(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) { s32 i; struct HeapFreeListElement *curr; @@ -349,28 +360,13 @@ struct unkMemoryStruct2 * _LocateSetBack(struct HeapDescriptor *heap, s32 index, curr->unk_atb = xxx_memory_attr_related(atb); curr->atb = atb; curr->grp = group; - return (void*) curr; + return curr; } -extern u32 gUnknown_80B7F14; -extern u32 gUnknown_80B7F88; -extern const char gLocateSetErrorMessage[]; -extern struct HeapDescriptor gMainHeapDescriptor; -extern const char gLocalCreateErrorMessage[]; - -extern s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32, s32); -extern s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32, s32); - -void DoFree(struct HeapDescriptor *, void *); -void *DoAlloc(struct HeapDescriptor *, s32, u32); - - - - -struct HeapDescriptor* _LocateSet(struct HeapDescriptor *heap, s32 size, s32 group) +void * _LocateSet(struct HeapDescriptor *heap, s32 size, s32 group) { s32 index; - struct unkMemoryStruct2 * uVar2; + struct HeapFreeListElement * foundSet; s32 atb; if (heap == NULL) { @@ -386,14 +382,14 @@ struct HeapDescriptor* _LocateSet(struct HeapDescriptor *heap, s32 size, s32 gro if ((atb & 2) != 0) { index = MemorySearchFromFront(heap,atb,size); if (index < 0) goto error; - uVar2 = _LocateSetFront(heap,index,atb,size,group); - return uVar2->unkC; + foundSet = _LocateSetFront(heap,index,atb,size,group); + return foundSet->block.start; } else { index = MemorySearchFromBack(heap,atb,size); if (index < 0) goto error; - uVar2 = _LocateSetBack(heap,index,atb,size,group); - return uVar2->unkC; + foundSet = _LocateSetBack(heap,index,atb,size,group); + return foundSet->block.start; } error: @@ -417,7 +413,7 @@ void MemoryFree(void *a) struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHeap,u32 size,u32 param_3,u32 group) { int index; - struct unkMemoryStruct2 *iVar2; + struct HeapFreeListElement *foundSet; struct HeapDescriptor *iVar3; struct unkMemoryStruct local_1c; @@ -430,9 +426,9 @@ struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHea // Memroy LocalCreate buffer %08x size can't locate FatalError(&gUnknown_80B7F88,gLocalCreateErrorMessage,size); - iVar2 = _LocateSetBack(parentHeap,index,9,size,group); - local_1c.unk0 = iVar2->unkC; - local_1c.end = iVar2->end; + foundSet = _LocateSetBack(parentHeap,index,9,size,group); + local_1c.unk0 = (void *) foundSet->block.start; + local_1c.end = foundSet->block.size; iVar3 = DoCreateSubHeap(&local_1c,param_3); iVar3->parentHeap = parentHeap; From 27bd13dd5b3f9da6528494e496f430c2b9f29352 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Dec 2024 12:25:04 +0100 Subject: [PATCH 3/6] clean memory include --- include/memory.h | 61 ------------------- src/memory.c | 153 +++++++++++++++++++++++++++++++---------------- 2 files changed, 102 insertions(+), 112 deletions(-) diff --git a/include/memory.h b/include/memory.h index f6cb17d77..cb69542e2 100644 --- a/include/memory.h +++ b/include/memory.h @@ -1,61 +1,6 @@ #ifndef GUARD_MEMORY_H #define GUARD_MEMORY_H -#define HEAP_SIZE 0x24000 - -// size: 0x8 -struct HeapSettings -{ - /* 0x0 */ u8 *start; - /* 0x4 */ u32 size; -}; - -// size: 0xC -struct HeapMemoryBlock -{ - /* 0x0 */ u8 *start; - /* 0x4 */ s32 size; - /* 0x8 */ s32 allocatedSize; -}; - -// size: 0x8 -struct HeapMemoryBlock2 -{ - /* 0x0 */ struct HeapFreeListElement *start; - /* 0x4 */ s32 size; -}; - -// size: 0x10 -struct HeapFreeListElement -{ - /* 0x0 */ u32 unk_atb; - /* 0x4 */ u32 atb; - /* 0x8 */ u32 grp; - /* 0xC */ struct HeapMemoryBlock block; -}; - -// size: 0x1C -struct HeapDescriptor -{ - u32 unk0; - /* 0x4 */ struct HeapDescriptor *parentHeap; - /* 0x8 */ struct HeapFreeListElement *freeList; - /* 0xC */ s32 freeCount; - /* 0x10 */ s32 freeListLength; - /* 0x14 */ u8 *start; - /* 0x18 */ u32 size; -}; - -// size: 0x8 -struct unkMemoryStruct -{ - struct HeapDescriptor *unk0; - u32 end; -}; - -extern struct HeapDescriptor *gHeapDescriptorList[8]; -extern s32 gHeapCount; - void InitHeap(void); void MemoryClear8(u8 *dest, s32 size); @@ -71,13 +16,7 @@ void MemoryCopy8(u8 *dest, u8 *src, s32 size); void MemoryCopy16(u16 *dest, u16 *src, s32 size); void MemoryCopy32(u32 *dest, u32 *src, s32 size); -void InitHeapInternal(void); -void DoInitHeap(struct HeapDescriptor *, struct HeapSettings *, struct HeapFreeListElement *, u32); -void InitSubHeap(struct HeapDescriptor *, struct HeapMemoryBlock2 *, u32); void *MemoryAlloc(s32 size, s32 group); void MemoryFree(void *a); -struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b); -void xxx_unused_memory_free(struct HeapDescriptor *a1); -void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2); #endif // GUARD_MEMORY_H diff --git a/src/memory.c b/src/memory.c index 953587704..66dfa29ed 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,16 +1,84 @@ #include "global.h" -#include "cpu.h" #include "memory.h" +#include "cpu.h" -EWRAM_DATA struct HeapDescriptor *gHeapDescriptorList[8] = {0}; // 2000E88 -EWRAM_DATA s32 gHeapCount = {0}; // 2000EA8 +#define HEAP_SIZE 0x24000 + +// size: 0x8 +struct HeapSettings +{ + /* 0x0 */ u8 *start; + /* 0x4 */ u32 size; +}; + +// size: 0xC +struct HeapMemoryBlock +{ + /* 0x0 */ u8 *start; + /* 0x4 */ s32 size; + /* 0x8 */ s32 allocatedSize; +}; + +// size: 0x8 +struct HeapMemoryBlock2 +{ + /* 0x0 */ struct HeapFreeListElement *start; + /* 0x4 */ s32 size; +}; + +// size: 0x10 +struct HeapFreeListElement +{ + /* 0x0 */ u32 unk_atb; + /* 0x4 */ u32 atb; + /* 0x8 */ u32 grp; + /* 0xC */ struct HeapMemoryBlock block; +}; + +// size: 0x1C +struct HeapDescriptor +{ + u32 unk0; + /* 0x4 */ struct HeapDescriptor *parentHeap; + /* 0x8 */ struct HeapFreeListElement *freeList; + /* 0xC */ s32 freeCount; + /* 0x10 */ s32 freeListLength; + /* 0x14 */ u8 *start; + /* 0x18 */ u32 size; +}; + +// size: 0x8 +struct unkMemoryStruct +{ + struct HeapDescriptor *unk0; + u32 end; +}; + +static EWRAM_DATA struct HeapDescriptor *sHeapDescriptorList[8] = {0}; // 2000E88 +static EWRAM_DATA s32 sHeapCount = {0}; // 2000EA8 UNUSED static EWRAM_DATA u32 sUnused1 = {0}; // 2000EAC -EWRAM_DATA struct HeapDescriptor gMainHeapDescriptor = {0}; // 2000EB0 +static EWRAM_DATA struct HeapDescriptor sMainHeapDescriptor = {0}; // 2000EB0 UNUSED static EWRAM_DATA u32 sUnused2 = {0}; // 2000ECC extern struct HeapFreeListElement gMainHeapFreeList[32]; // 2000ED0 (CAPACITY OR STRUCT SIZE IS WRONG) extern u8 gMainHeap[HEAP_SIZE]; // 20011D0 -void InitHeapInternal(void); +// Todo: fix fatal error +void FatalError(const void *, const char *, ...) __attribute__((noreturn)); +extern const char *const gUnknown_80B7EB8; +extern const char *const gUnknown_80B7EFC; +extern const char gUnknown_80B7EC4[]; +extern u32 gUnknown_80B7F14; +extern u32 gUnknown_80B7F88; +extern const char gLocateSetErrorMessage[]; +extern const char gLocalCreateErrorMessage[]; + +static void DoFree(struct HeapDescriptor *, void *); +static void *DoAlloc(struct HeapDescriptor *, s32, u32); +static void DoInitHeap(struct HeapDescriptor *, struct HeapSettings *, struct HeapFreeListElement *, u32); +static void InitSubHeap(struct HeapDescriptor *, struct HeapMemoryBlock2 *, u32); +static struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b); +static void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2); +static void InitHeapInternal(void); void InitHeap(void) { @@ -94,23 +162,23 @@ void MemoryCopy32(u32 *dest, u32 *src, s32 size) } } -void InitHeapInternal(void) +static void InitHeapInternal(void) { struct HeapSettings settings; settings.start = gMainHeap; settings.size = HEAP_SIZE; - gHeapCount = 0; - DoInitHeap(&gMainHeapDescriptor, &settings, gMainHeapFreeList, sizeof(gMainHeapFreeList) / sizeof(struct HeapFreeListElement)); + sHeapCount = 0; + DoInitHeap(&sMainHeapDescriptor, &settings, gMainHeapFreeList, sizeof(gMainHeapFreeList) / sizeof(struct HeapFreeListElement)); } -void DoInitHeap(struct HeapDescriptor *descriptor, struct HeapSettings *settings, struct HeapFreeListElement *freeList, u32 freeListLength) +static void DoInitHeap(struct HeapDescriptor *descriptor, struct HeapSettings *settings, struct HeapFreeListElement *freeList, u32 freeListLength) { u32 aligned_size; aligned_size = settings->size & ~(3); - gHeapDescriptorList[gHeapCount++] = descriptor; + sHeapDescriptorList[sHeapCount++] = descriptor; descriptor->start = settings->start; descriptor->size = aligned_size; @@ -128,7 +196,7 @@ void DoInitHeap(struct HeapDescriptor *descriptor, struct HeapSettings *settings freeList->grp = 0; } -void InitSubHeap(struct HeapDescriptor *parentHeap, struct HeapMemoryBlock2 *block, u32 freeListMax) +static void InitSubHeap(struct HeapDescriptor *parentHeap, struct HeapMemoryBlock2 *block, u32 freeListMax) { u32 freeListSize; u32 aligned_size; @@ -146,7 +214,7 @@ void InitSubHeap(struct HeapDescriptor *parentHeap, struct HeapMemoryBlock2 *blo DoInitHeap(parentHeap, &settings, freeList, freeListMax); } -u32 xxx_memory_attr_related(u32 r0) +static u32 xxx_memory_attr_related(u32 r0) { u32 temp; u32 return_var; @@ -179,7 +247,7 @@ u32 xxx_memory_attr_related(u32 r0) return return_var; } -s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32 atb, s32 size) +static s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32 atb, s32 size) { s32 i; struct HeapFreeListElement *curr; @@ -223,7 +291,7 @@ s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32 atb, s32 size) return -1; } -s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32 atb, s32 size) +static s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32 atb, s32 size) { s32 i; struct HeapFreeListElement *curr; @@ -267,24 +335,7 @@ s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32 atb, s32 size) return -1; } -// Todo: fix fatal error -void FatalError(const void *, const char *, ...) __attribute__((noreturn)); -extern const char *const gUnknown_80B7EB8; -extern const char *const gUnknown_80B7EFC; -extern const char gUnknown_80B7EC4[]; -extern u32 gUnknown_80B7F14; -extern u32 gUnknown_80B7F88; -extern const char gLocateSetErrorMessage[]; -extern struct HeapDescriptor gMainHeapDescriptor; -extern const char gLocalCreateErrorMessage[]; - -extern s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32, s32); -extern s32 MemorySearchFromFront(struct HeapDescriptor *heap, s32, s32); - -void DoFree(struct HeapDescriptor *, void *); -void *DoAlloc(struct HeapDescriptor *, s32, u32); - -struct HeapFreeListElement * _LocateSetFront(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) +static struct HeapFreeListElement * _LocateSetFront(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) { s32 i; struct HeapFreeListElement *curr; @@ -322,7 +373,7 @@ struct HeapFreeListElement * _LocateSetFront(struct HeapDescriptor *heap, s32 in return curr; } -struct HeapFreeListElement * _LocateSetBack(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) +static struct HeapFreeListElement * _LocateSetBack(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) { s32 i; struct HeapFreeListElement *curr; @@ -363,14 +414,14 @@ struct HeapFreeListElement * _LocateSetBack(struct HeapDescriptor *heap, s32 ind return curr; } -void * _LocateSet(struct HeapDescriptor *heap, s32 size, s32 group) +static void * _LocateSet(struct HeapDescriptor *heap, s32 size, s32 group) { s32 index; struct HeapFreeListElement * foundSet; s32 atb; if (heap == NULL) { - heap = &gMainHeapDescriptor; + heap = &sMainHeapDescriptor; } // Set some sort flag/attr? @@ -402,15 +453,15 @@ error: void *MemoryAlloc(s32 size, s32 group) { - DoAlloc(&gMainHeapDescriptor, size, group); + DoAlloc(&sMainHeapDescriptor, size, group); } void MemoryFree(void *a) { - DoFree(&gMainHeapDescriptor, a); + DoFree(&sMainHeapDescriptor, a); } -struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHeap,u32 size,u32 param_3,u32 group) +UNUSED static struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHeap,u32 size,u32 param_3,u32 group) { int index; struct HeapFreeListElement *foundSet; @@ -418,7 +469,7 @@ struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHea struct unkMemoryStruct local_1c; if (parentHeap == NULL) { - parentHeap = &gMainHeapDescriptor; + parentHeap = &sMainHeapDescriptor; } index = MemorySearchFromBack(parentHeap,9,size); @@ -435,7 +486,7 @@ struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHea return iVar3; } -struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b) +static struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b) { struct HeapMemoryBlock2 s2; struct HeapDescriptor *a1; @@ -449,7 +500,7 @@ struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b) return a1; } -void xxx_unused_memory_free(struct HeapDescriptor *a1) +UNUSED static void xxx_unused_memory_free(struct HeapDescriptor *a1) { bool8 b; s32 i; @@ -465,11 +516,11 @@ void xxx_unused_memory_free(struct HeapDescriptor *a1) if (b) { temp = FALSE; i = 0; - for (; i < gHeapCount; i++) { - if (gHeapDescriptorList[i] == a1) { - gHeapCount--; - for (; i < gHeapCount; i++) { - gHeapDescriptorList[i] = gHeapDescriptorList[i + 1]; + for (; i < sHeapCount; i++) { + if (sHeapDescriptorList[i] == a1) { + sHeapCount--; + for (; i < sHeapCount; i++) { + sHeapDescriptorList[i] = sHeapDescriptorList[i + 1]; } temp = TRUE; break; @@ -480,12 +531,12 @@ void xxx_unused_memory_free(struct HeapDescriptor *a1) } } -void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2) +static void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2) { return _LocateSet(heap, size, a2 | 0x100); } -void DoFree(struct HeapDescriptor *heapDescriptior, void *ptrToFree) +static void DoFree(struct HeapDescriptor *heapDescriptior, void *ptrToFree) { struct HeapFreeListElement *curr; struct HeapFreeListElement *next; @@ -493,7 +544,7 @@ void DoFree(struct HeapDescriptor *heapDescriptior, void *ptrToFree) s32 i; if (heapDescriptior == NULL) - heapDescriptior = &gMainHeapDescriptor; + heapDescriptior = &sMainHeapDescriptor; if (ptrToFree == NULL) return; @@ -536,12 +587,12 @@ void DoFree(struct HeapDescriptor *heapDescriptior, void *ptrToFree) } } -void nullsub_141(void) +UNUSED static void nullsub_141(void) { } -void nullsub_142(void) +UNUSED static void nullsub_142(void) { } From 235a453f1da24b8c11f1350347f722fd2a22a1cd Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Dec 2024 12:37:12 +0100 Subject: [PATCH 4/6] Fix fatal error func declarations --- include/debug.h | 5 +++-- src/debug.c | 8 ++++---- src/event_flag.c | 21 ++++++++++----------- src/ground_script.c | 11 +++++------ src/ground_script_1.c | 1 - src/memory.c | 15 ++++++--------- 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/include/debug.h b/include/debug.h index 71c86c954..df8f725c5 100644 --- a/include/debug.h +++ b/include/debug.h @@ -23,8 +23,8 @@ void nullsub_31(void); void nullsub_32(void); void nullsub_137(void); void nullsub_199(void); -void PrintFuncFileLine(u8 *buf, DebugLocation *loc, const u8 *prefix); -void PrintMessageWithFuncFileLine(u8 *buffer, DebugLocation *debug, const u8 *text, ...); +void PrintFuncFileLine(u8 *buf, const DebugLocation *loc, const u8 *prefix); +void PrintMessageWithFuncFileLine(u8 *buffer, const DebugLocation *debug, const u8 *text, ...); void sub_8011B08(void); void sub_8011B88(const u8 *text, ...); s8 ScriptLoggingEnabled(bool8); @@ -35,5 +35,6 @@ u8 sub_8011B20(void); u8 sub_8011B3C(void); void sub_8011BC8(u32, u32, u32, ...); void UnusedHang(void); +void FatalError(const DebugLocation *debug, const char *text, ...) __attribute__((noreturn)); #endif // GUARD_DEBUG_H diff --git a/src/debug.c b/src/debug.c index bff40650a..8e0aba6f9 100644 --- a/src/debug.c +++ b/src/debug.c @@ -79,12 +79,12 @@ UNUSED static void PrintFuncFileLineOrNotEntry(u8 *buf, DebugLocation *debug) sprintf(buf, gNotEntryText); } -void PrintFuncFileLine(u8 *buf, DebugLocation *loc, const u8* prefix) +void PrintFuncFileLine(u8 *buf, const DebugLocation *loc, const u8* prefix) { sprintf(buf, gFuncFileLineStringWPrefix, prefix, loc->func, loc->file, loc->line); } -void PrintMessageWithFuncFileLine(u8 *buffer, DebugLocation *debug, const u8 *text, ...) +void PrintMessageWithFuncFileLine(u8 *buffer, const DebugLocation *debug, const u8 *text, ...) { va_list vArgv; u32 length; @@ -135,7 +135,7 @@ void nullsub_137(void) } -static void FatalErrorPrintFuncFileLine(const char *prefix, DebugLocation *debug) +static void FatalErrorPrintFuncFileLine(const char *prefix, const DebugLocation *debug) { char buf[0x100]; if(prefix != NULL){ @@ -229,7 +229,7 @@ static void FatalErrorHang() Hang(); } -void FatalError(DebugLocation *debug, const char *text, ...) +void FatalError(const DebugLocation *debug, const char *text, ...) { char buf[0x100]; va_list vArgv; diff --git a/src/event_flag.c b/src/event_flag.c index 3609feb8c..1754f72b5 100644 --- a/src/event_flag.c +++ b/src/event_flag.c @@ -43,7 +43,6 @@ extern u8 gUnknown_80B735C[]; extern u8 gUnknown_80B7378[]; extern u8 gUnknown_80B7388[]; -void FatalError(DebugLocation *, const char *, ...) __attribute__((noreturn)); extern bool8 HasCompletedAllMazes(void); extern u8 sub_8002658(s16); extern void sub_809733C(u32, u32); @@ -93,7 +92,7 @@ UNUSED void GetScriptVarString(s16 varId, u8 *buf, s32 maxLen) s32 r2; u8 r0; struct ScriptVarPtr local_10; - + GetScriptVarRef(&local_10,0,varId); for (r1 = local_10.ptr, r2 = 0; r2 < maxLen; r2++) { r0 = *r1; @@ -110,7 +109,7 @@ UNUSED void ScriptVarStringPopFirstChar(s16 varId,u32 param_2,s32 maxLen) s32 r2; u8 r0; struct ScriptVarPtr local_10; - + GetScriptVarRef(&local_10,0,varId); for (r1 = local_10.ptr, r2 = 0; r2 < maxLen; r1++, r2++) { r0 = *r1; @@ -136,10 +135,10 @@ void ScenarioCalc(s16 param_1,s32 param_2,s32 param_3) s32 param_1_s32; u32 local_18; u32 local_14; - + param_1_s32 = param_1; GetScriptVarScenario(param_1_s32,&local_18,&local_14); - Log(6,gUnknown_80B72CC,param_1_s32,local_18,local_14,param_2,param_3); // SCENARIO CALC [%3d] %4d %4d -> %4d %4d + Log(6,gUnknown_80B72CC,param_1_s32,local_18,local_14,param_2,param_3); // SCENARIO CALC [%3d] %4d %4d -> %4d %4d if ((param_1_s32 == 3) && ((param_2 != local_18 || (param_3 != local_14)))) { SetScriptVarValue(NULL,CLEAR_COUNT,0); } @@ -233,7 +232,7 @@ void sub_8001D88(void) { u32 local_c; u32 auStack8; - + GetScriptVarScenario(3, &auStack8, &local_c); if (auStack8 - 1 < 0x1b) { if (ScriptVarScenarioBefore(SCENARIO_SUB1,0x1f,0) != 0) { @@ -323,7 +322,7 @@ void sub_8001D88(void) } s32 _FlagCalc(s32 param_1, s32 param_2, enum FlagCalcOperation operation) -{ +{ switch(operation) { case CALC_SET: return param_2; @@ -408,7 +407,7 @@ void UpdateScriptVarWithVar(u8 *param_1, s16 param_2, s16 param_3, enum FlagCalc s32 param_2_s32 = param_2; s32 param_3_s32 = param_3; - + uVar1 = GetScriptVarValue(param_1,param_2_s32); uVar2 = GetScriptVarValue(param_1,param_3_s32); uVar3 = _FlagCalc(uVar1,uVar2,operation); @@ -423,7 +422,7 @@ bool8 FlagJudge(s32 r0, s32 r1, enum FlagJudgeOperation operation) bool8 JudgeVarWithImmediate(u8 *param_1, s16 param_2, s32 param_3, enum FlagJudgeOperation operation) { s32 uVar1; - + uVar1 = GetScriptVarValue(param_1, param_2); return _FlagJudge(uVar1,param_3,operation); } @@ -435,7 +434,7 @@ bool8 JudgeVarWithVar(u8 *param_1, s16 param_2, s16 param_3, enum FlagJudgeOpera s32 param_2_s32 = param_2; s32 param_3_s32 = param_3; - + uVar1 = GetScriptVarValue(param_1,param_2_s32); uVar2 = GetScriptVarValue(param_1,param_3_s32); return _FlagJudge(uVar1,uVar2,operation); @@ -561,7 +560,7 @@ u8 sub_8002658(s16 param_1) struct GroundEventTableEntry *ptr; param_1_s32 = param_1; - + ptr = gGroundEnterLookupTable; sVar1 = gGroundEnterLookupTable[0].groundEnterId; if (sVar1 != -1) { diff --git a/src/ground_script.c b/src/ground_script.c index a79bdcd18..a1009f79c 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -7,9 +7,9 @@ extern u8 gScriptLocks[]; extern u32 gUnlockBranchLabels[]; extern u8 gScriptLockConds[]; -extern u32 gUnknown_8116588; -extern u32 gUnknown_8116538; -extern u32 gUnknown_8116560; +extern const DebugLocation gUnknown_8116588; +extern const DebugLocation gUnknown_8116538; +extern const DebugLocation gUnknown_8116560; extern u8 gUnknown_8116594[]; extern u8 gUnknown_8116544[]; extern u8 gUnknown_811656C[]; @@ -24,7 +24,6 @@ extern u8 IsTextboxOpen_809A750(void); extern s32 sub_80A882C(s16); extern s32 sub_80AC240(s16); extern s32 sub_80AD158(s16); -void FatalError(u32 *, const char *, ...) __attribute__((noreturn)); // -1 didn't match void sub_809D520(void *a0) @@ -321,7 +320,7 @@ bool8 GroundScriptNotify(Action *param_1, s16 param_2) bool8 ret; s32 param_2_s16 = param_2; - + ret = FALSE; sVar1 = param_1->scriptData.unk22; if ((sVar1 != -1) && (sVar1 == param_2_s16)) { @@ -355,7 +354,7 @@ void GroundScriptLock(s16 index, s32 r1) bool8 GroundScriptLockCond(Action *param_1, s16 index, u32 param_3) { s32 index_s32; - + index_s32 = index; gUnlockBranchLabels[index_s32] = param_3; if (index_s32 == 0) { diff --git a/src/ground_script_1.c b/src/ground_script_1.c index b9a536db1..0173fc43f 100644 --- a/src/ground_script_1.c +++ b/src/ground_script_1.c @@ -40,7 +40,6 @@ void GroundWeather_Select(s16); u32 GroundLives_ExecutePlayerScriptActionLives(); s16 GroundObject_Add(s16 id, GroundObjectData*, s16 group, s8 sector); s16 GroundEffect_Add(s16 id, GroundEffectData*, s16 group, s8 sector); -void FatalError(void* loc, char* fmt, ...) __attribute__((noreturn)); // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files diff --git a/src/memory.c b/src/memory.c index 66dfa29ed..461064833 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,6 +1,7 @@ #include "global.h" #include "memory.h" #include "cpu.h" +#include "debug.h" #define HEAP_SIZE 0x24000 @@ -62,13 +63,11 @@ UNUSED static EWRAM_DATA u32 sUnused2 = {0}; // 2000ECC extern struct HeapFreeListElement gMainHeapFreeList[32]; // 2000ED0 (CAPACITY OR STRUCT SIZE IS WRONG) extern u8 gMainHeap[HEAP_SIZE]; // 20011D0 -// Todo: fix fatal error -void FatalError(const void *, const char *, ...) __attribute__((noreturn)); -extern const char *const gUnknown_80B7EB8; -extern const char *const gUnknown_80B7EFC; extern const char gUnknown_80B7EC4[]; -extern u32 gUnknown_80B7F14; -extern u32 gUnknown_80B7F88; +extern const DebugLocation gUnknown_80B7EB8; +extern const DebugLocation gUnknown_80B7EFC; +extern const DebugLocation gUnknown_80B7F14; +extern const DebugLocation gUnknown_80B7F88; extern const char gLocateSetErrorMessage[]; extern const char gLocalCreateErrorMessage[]; @@ -490,12 +489,10 @@ static struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b) { struct HeapMemoryBlock2 s2; struct HeapDescriptor *a1; - u32 end; a1 = a->unk0; s2.start = (struct HeapFreeListElement *)((u8*)a1 + sizeof(struct HeapDescriptor)); - end = a->end; - s2.size = end - sizeof(struct HeapDescriptor); + s2.size = a->end - sizeof(struct HeapDescriptor); InitSubHeap(a1, &s2, b); return a1; } From ad09542cea723717defbb93cec56fb77f7a49554 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Dec 2024 13:16:40 +0100 Subject: [PATCH 5/6] move const data to memory.s --- data/data.s | 737 ------------------------------------------------ data/data1.s | 687 ++++++++++++++++++++++++++++++++++++++++++++ include/debug.h | 4 +- ld_script.txt | 2 + src/memory.c | 64 +++-- 5 files changed, 733 insertions(+), 761 deletions(-) create mode 100644 data/data1.s diff --git a/data/data.s b/data/data.s index 4a8527880..5738d9038 100644 --- a/data/data.s +++ b/data/data.s @@ -1017,740 +1017,3 @@ gVectorDirections: @ 80B7E3C @ ??? .string "pksdir0\0" -@ memory.s -.string "pksdir0\0" - -gUnknown_80B7E8C: - .string "../system/memory_locate.c\0" - .align 2, 0 - -gUnknown_80B7EA8: - .string "_LocateSetFront\0" - .align 2, 0 - - .global gUnknown_80B7EB8 -gUnknown_80B7EB8: @ 80B7EB8 - .4byte gUnknown_80B7E8C, 581, gUnknown_80B7EA8 - - .global gUnknown_80B7EC4 -gUnknown_80B7EC4: @ 80B7EC4 - .string "Memory Locate sprit max over [%3d/%3d]\0" - .align 2,0 - -LocateSetBackText: - .string "_LocateSetBack\0" - .align 2,0 - - .global gUnknown_80B7EFC -gUnknown_80B7EFC: @ 80B7EFC - .4byte gUnknown_80B7E8C, 673, LocateSetBackText - -LocateSetText: - .string "_LocateSet\0" - .align 2,0 - - .global gUnknown_80B7F14 -gUnknown_80B7F14: @ 80B7F14 - .4byte gUnknown_80B7E8C, 812, LocateSetText - - .global gLocateSetErrorMessage -gLocateSetErrorMessage: @ 80B7F20 - .ascii "Memroy LocateSet [%p] buffer %8x size can't locate\n" - .asciz " atb %02x grp %3d \0" - .align 2,0 - -MemoryLocate_LocalCreateText: - .string "MemoryLocate_LocalCreate\0" - .align 2,0 - - .global gUnknown_80B7F88 -gUnknown_80B7F88: @ 80B7F88 - .4byte gUnknown_80B7E8C, 1109, MemoryLocate_LocalCreateText - - .global gLocalCreateErrorMessage -gLocalCreateErrorMessage: @ 80B7F94 - .asciz "Memroy LocalCreate buffer %08x size can't locate\0" @ Spelling error is intentional - .align 2,0 - -@ code_80035F0 -.string "pksdir0\0" - -@ other_random -.string "pksdir0\0" - -@ util -.string "pksdir0\0" - -@ bg_palette_buffer -.string "pksdir0\0" - -@ input -.string "pksdir0\0" - -@ code_8004AA0 -.string "pksdir0\0" - -@ sprite -.string "pksdir0\0" - -@ code_800558C.c -.string "pksdir0\0" - - .global gUnknown_80B8008 -gUnknown_80B8008: @ 80B8008 - .2byte 16, 12, 9, 7, 6, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0 - - .global gUnknown_80B802A -gUnknown_80B802A: @ 80B802A - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x846C - .2byte 0x8967 - .2byte 0x8C64 - .2byte 0x8E62 - .2byte 0x9060 - .2byte 0x915F - .2byte 0x935D - .2byte 0x945C - .2byte 0x955B - .2byte 0x965A - .2byte 0x965A - .2byte 0x9759 - .2byte 0x9858 - .2byte 0x9858 - .2byte 0x9957 - .2byte 0x9957 - .2byte 0x9A56 - .2byte 0x9A56 - .2byte 0x9A56 - .2byte 0x9B55 - .2byte 0x9B55 - .2byte 0x9B55 - .2byte 0x9B55 - .2byte 0x9B55 - .2byte 0x9C55 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9C54 - .2byte 0x9B55 - .2byte 0x9B55 - .2byte 0x9B55 - .2byte 0x9B55 - .2byte 0x9B55 - .2byte 0x9A56 - .2byte 0x9A56 - .2byte 0x9A56 - .2byte 0x9957 - .2byte 0x9957 - .2byte 0x9858 - .2byte 0x9858 - .2byte 0x9759 - .2byte 0x965A - .2byte 0x965A - .2byte 0x955B - .2byte 0x945C - .2byte 0x935D - .2byte 0x915F - .2byte 0x9060 - .2byte 0x8E62 - .2byte 0x8C64 - .2byte 0x8967 - .2byte 0x846C - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - - .global gUnknown_80B816A -gUnknown_80B816A: @ 80B816A - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x8071 - .2byte 0x866B - .2byte 0x8A67 - .2byte 0x8D64 - .2byte 0x8F62 - .2byte 0x9160 - .2byte 0x935E - .2byte 0x955C - .2byte 0x975A - .2byte 0x9958 - .2byte 0x9A57 - .2byte 0x9B56 - .2byte 0x9D54 - .2byte 0x9E53 - .2byte 0xA051 - .2byte 0xA051 - .2byte 0xA150 - .2byte 0xA24F - .2byte 0xA44D - .2byte 0xA54C - .2byte 0xA54C - .2byte 0xA64B - .2byte 0xA74A - .2byte 0xA849 - .2byte 0xA948 - .2byte 0xA948 - .2byte 0xAA47 - .2byte 0xAA47 - .2byte 0xAB46 - .2byte 0xAC45 - .2byte 0xAC45 - .2byte 0xAD44 - .2byte 0xAD44 - .2byte 0xAE43 - .2byte 0xAE43 - .2byte 0xAF42 - .2byte 0xAF42 - .2byte 0xB041 - .2byte 0xB041 - .2byte 0xB140 - .2byte 0xB140 - .2byte 0xB140 - .2byte 0xB23F - .2byte 0xB23F - .2byte 0xB23F - .2byte 0xB23F - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB43D - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB33E - .2byte 0xB23F - .2byte 0xB23F - .2byte 0xB23F - .2byte 0xB23F - .2byte 0xB140 - .2byte 0xB140 - .2byte 0xB140 - .2byte 0xB041 - .2byte 0xB041 - .2byte 0xAF42 - .2byte 0xAF42 - .2byte 0xAE43 - .2byte 0xAE43 - .2byte 0xAD44 - .2byte 0xAD44 - .2byte 0xAC45 - .2byte 0xAC45 - .2byte 0xAB46 - .2byte 0xAA47 - .2byte 0xAA47 - .2byte 0xA948 - .2byte 0xA948 - .2byte 0xA849 - .2byte 0xA74A - .2byte 0xA64B - .2byte 0xA54C - .2byte 0xA54C - .2byte 0xA44D - .2byte 0xA24F - .2byte 0xA150 - .2byte 0xA051 - .2byte 0xA051 - .2byte 0x9E53 - .2byte 0x9D54 - .2byte 0x9B56 - .2byte 0x9A57 - .2byte 0x9958 - .2byte 0x975A - .2byte 0x955C - .2byte 0x935E - .2byte 0x9160 - .2byte 0x8F62 - .2byte 0x8D64 - .2byte 0x8A67 - .2byte 0x866B - .2byte 0x8071 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - - .global gUnknown_80B82AA -gUnknown_80B82AA: @ 80B82AA - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x9392 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - .2byte 0x0100 - - .global gUnknown_80B83EA -gUnknown_80B83EA: @ 80B83EA - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0000 - - .align 2, 0 - diff --git a/data/data1.s b/data/data1.s new file mode 100644 index 000000000..69d221ab0 --- /dev/null +++ b/data/data1.s @@ -0,0 +1,687 @@ + .section .rodata + + + + +@ code_80035F0 +.string "pksdir0\0" + +@ other_random +.string "pksdir0\0" + +@ util +.string "pksdir0\0" + +@ bg_palette_buffer +.string "pksdir0\0" + +@ input +.string "pksdir0\0" + +@ code_8004AA0 +.string "pksdir0\0" + +@ sprite +.string "pksdir0\0" + +@ code_800558C.c +.string "pksdir0\0" + + .global gUnknown_80B8008 +gUnknown_80B8008: @ 80B8008 + .2byte 16, 12, 9, 7, 6, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0 + + .global gUnknown_80B802A +gUnknown_80B802A: @ 80B802A + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x846C + .2byte 0x8967 + .2byte 0x8C64 + .2byte 0x8E62 + .2byte 0x9060 + .2byte 0x915F + .2byte 0x935D + .2byte 0x945C + .2byte 0x955B + .2byte 0x965A + .2byte 0x965A + .2byte 0x9759 + .2byte 0x9858 + .2byte 0x9858 + .2byte 0x9957 + .2byte 0x9957 + .2byte 0x9A56 + .2byte 0x9A56 + .2byte 0x9A56 + .2byte 0x9B55 + .2byte 0x9B55 + .2byte 0x9B55 + .2byte 0x9B55 + .2byte 0x9B55 + .2byte 0x9C55 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9C54 + .2byte 0x9B55 + .2byte 0x9B55 + .2byte 0x9B55 + .2byte 0x9B55 + .2byte 0x9B55 + .2byte 0x9A56 + .2byte 0x9A56 + .2byte 0x9A56 + .2byte 0x9957 + .2byte 0x9957 + .2byte 0x9858 + .2byte 0x9858 + .2byte 0x9759 + .2byte 0x965A + .2byte 0x965A + .2byte 0x955B + .2byte 0x945C + .2byte 0x935D + .2byte 0x915F + .2byte 0x9060 + .2byte 0x8E62 + .2byte 0x8C64 + .2byte 0x8967 + .2byte 0x846C + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + + .global gUnknown_80B816A +gUnknown_80B816A: @ 80B816A + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x8071 + .2byte 0x866B + .2byte 0x8A67 + .2byte 0x8D64 + .2byte 0x8F62 + .2byte 0x9160 + .2byte 0x935E + .2byte 0x955C + .2byte 0x975A + .2byte 0x9958 + .2byte 0x9A57 + .2byte 0x9B56 + .2byte 0x9D54 + .2byte 0x9E53 + .2byte 0xA051 + .2byte 0xA051 + .2byte 0xA150 + .2byte 0xA24F + .2byte 0xA44D + .2byte 0xA54C + .2byte 0xA54C + .2byte 0xA64B + .2byte 0xA74A + .2byte 0xA849 + .2byte 0xA948 + .2byte 0xA948 + .2byte 0xAA47 + .2byte 0xAA47 + .2byte 0xAB46 + .2byte 0xAC45 + .2byte 0xAC45 + .2byte 0xAD44 + .2byte 0xAD44 + .2byte 0xAE43 + .2byte 0xAE43 + .2byte 0xAF42 + .2byte 0xAF42 + .2byte 0xB041 + .2byte 0xB041 + .2byte 0xB140 + .2byte 0xB140 + .2byte 0xB140 + .2byte 0xB23F + .2byte 0xB23F + .2byte 0xB23F + .2byte 0xB23F + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB43D + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB33E + .2byte 0xB23F + .2byte 0xB23F + .2byte 0xB23F + .2byte 0xB23F + .2byte 0xB140 + .2byte 0xB140 + .2byte 0xB140 + .2byte 0xB041 + .2byte 0xB041 + .2byte 0xAF42 + .2byte 0xAF42 + .2byte 0xAE43 + .2byte 0xAE43 + .2byte 0xAD44 + .2byte 0xAD44 + .2byte 0xAC45 + .2byte 0xAC45 + .2byte 0xAB46 + .2byte 0xAA47 + .2byte 0xAA47 + .2byte 0xA948 + .2byte 0xA948 + .2byte 0xA849 + .2byte 0xA74A + .2byte 0xA64B + .2byte 0xA54C + .2byte 0xA54C + .2byte 0xA44D + .2byte 0xA24F + .2byte 0xA150 + .2byte 0xA051 + .2byte 0xA051 + .2byte 0x9E53 + .2byte 0x9D54 + .2byte 0x9B56 + .2byte 0x9A57 + .2byte 0x9958 + .2byte 0x975A + .2byte 0x955C + .2byte 0x935E + .2byte 0x9160 + .2byte 0x8F62 + .2byte 0x8D64 + .2byte 0x8A67 + .2byte 0x866B + .2byte 0x8071 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + + .global gUnknown_80B82AA +gUnknown_80B82AA: @ 80B82AA + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x9392 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + .2byte 0x0100 + + .global gUnknown_80B83EA +gUnknown_80B83EA: @ 80B83EA + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + .2byte 0x0000 + + .align 2, 0 + diff --git a/include/debug.h b/include/debug.h index df8f725c5..2f670f3ae 100644 --- a/include/debug.h +++ b/include/debug.h @@ -6,9 +6,9 @@ // size: 0xC typedef struct DebugLocation { - /* 0x0 */ u8 *file; + /* 0x0 */ const u8 *file; /* 0x4 */ u32 line; - /* 0x8 */ u8 *func; + /* 0x8 */ const u8 *func; } DebugLocation; void Log(u8 num, const u8 *text, ...); diff --git a/ld_script.txt b/ld_script.txt index a6d54e78c..c290ac4c1 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -420,6 +420,8 @@ SECTIONS { { data/data_code_2.o(.rodata); data/data.o(.rodata); + src/memory.o(.rodata); + data/data1.o(.rodata); src/random.o(.rodata); src/text.o(.rodata); data/data2.o(.rodata); diff --git a/src/memory.c b/src/memory.c index 461064833..2b65c4a66 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,4 +1,5 @@ #include "global.h" +#include "globaldata.h" #include "memory.h" #include "cpu.h" #include "debug.h" @@ -63,14 +64,6 @@ UNUSED static EWRAM_DATA u32 sUnused2 = {0}; // 2000ECC extern struct HeapFreeListElement gMainHeapFreeList[32]; // 2000ED0 (CAPACITY OR STRUCT SIZE IS WRONG) extern u8 gMainHeap[HEAP_SIZE]; // 20011D0 -extern const char gUnknown_80B7EC4[]; -extern const DebugLocation gUnknown_80B7EB8; -extern const DebugLocation gUnknown_80B7EFC; -extern const DebugLocation gUnknown_80B7F14; -extern const DebugLocation gUnknown_80B7F88; -extern const char gLocateSetErrorMessage[]; -extern const char gLocalCreateErrorMessage[]; - static void DoFree(struct HeapDescriptor *, void *); static void *DoAlloc(struct HeapDescriptor *, s32, u32); static void DoInitHeap(struct HeapDescriptor *, struct HeapSettings *, struct HeapFreeListElement *, u32); @@ -79,6 +72,8 @@ static struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b); static void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2); static void InitHeapInternal(void); +ALIGNED(4) static const char sFileNameText[] = "../system/memory_locate.c"; + void InitHeap(void) { InitHeapInternal(); @@ -334,6 +329,14 @@ static s32 MemorySearchFromBack(struct HeapDescriptor *heap, s32 atb, s32 size) return -1; } +ALIGNED(4) static const char sText_LocateSetFront[] = "_LocateSetFront"; +static const DebugLocation sLocateSetFrontDebugLocation = +{ + .file = sFileNameText, + .line = 581, + .func = sText_LocateSetFront +}; + static struct HeapFreeListElement * _LocateSetFront(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) { s32 i; @@ -353,9 +356,7 @@ static struct HeapFreeListElement * _LocateSetFront(struct HeapDescriptor *heap, heap->freeCount++; if (heap->freeCount > heap->freeListLength) { - // ../system/memory_locate.c - // Memory Locate sprit max over [%3d/%3d] - FatalError(&gUnknown_80B7EB8, gUnknown_80B7EC4, heap->freeCount, heap->freeListLength); + FatalError(&sLocateSetFrontDebugLocation, "Memory Locate sprit max over [%3d/%3d]", heap->freeCount, heap->freeListLength); } block = &heap->freeList[index + 1]; @@ -372,6 +373,14 @@ static struct HeapFreeListElement * _LocateSetFront(struct HeapDescriptor *heap, return curr; } +ALIGNED(4) static const char sText_LocateSetBack[] = "_LocateSetBack"; +static const DebugLocation sLocateSetBackDebugLocation = +{ + .file = sFileNameText, + .line = 673, + .func = sText_LocateSetBack +}; + static struct HeapFreeListElement * _LocateSetBack(struct HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group) { s32 i; @@ -392,12 +401,9 @@ static struct HeapFreeListElement * _LocateSetBack(struct HeapDescriptor *heap, heap->freeCount++; if (heap->freeCount > heap->freeListLength) { - // ../system/memory_locate.c - // Memory Locate sprit max over [%3d/%3d] - FatalError(&gUnknown_80B7EFC, gUnknown_80B7EC4, heap->freeCount, heap->freeListLength); + FatalError(&sLocateSetBackDebugLocation, "Memory Locate sprit max over [%3d/%3d]", heap->freeCount, heap->freeListLength); } - curr->block.size -= sizeAligned; newBlockStart = curr->block.size + curr->block.start; @@ -413,6 +419,14 @@ static struct HeapFreeListElement * _LocateSetBack(struct HeapDescriptor *heap, return curr; } +ALIGNED(4) static const char sText_LocateSet[] = "_LocateSet"; +static const DebugLocation sLocateSetDebugLocation = +{ + .file = sFileNameText, + .line = 812, + .func = sText_LocateSet +}; + static void * _LocateSet(struct HeapDescriptor *heap, s32 size, s32 group) { s32 index; @@ -443,10 +457,8 @@ static void * _LocateSet(struct HeapDescriptor *heap, s32 size, s32 group) } error: - // LocateSet [%p] buffer %8x size can't locate - // atb %02x grp %3d - FatalError(&gUnknown_80B7F14, - gLocateSetErrorMessage, + FatalError(&sLocateSetDebugLocation, + "Memroy LocateSet [%p] buffer %8x size can't locate\n atb %02x grp %3d ", // Spelling error is intentional heap,size,atb,group); } @@ -460,6 +472,8 @@ void MemoryFree(void *a) DoFree(&sMainHeapDescriptor, a); } +ALIGNED(4) static const char sText_MemoryLocate_LocalCreate[] = "MemoryLocate_LocalCreate"; + UNUSED static struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescriptor *parentHeap,u32 size,u32 param_3,u32 group) { int index; @@ -472,9 +486,15 @@ UNUSED static struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescrip } index = MemorySearchFromBack(parentHeap,9,size); - if (index < 0) - // Memroy LocalCreate buffer %08x size can't locate - FatalError(&gUnknown_80B7F88,gLocalCreateErrorMessage,size); + if (index < 0) { + static const DebugLocation debugInfo = { + .file = sFileNameText, + .line = 1109, + .func = sText_MemoryLocate_LocalCreate + }; + FatalError(&debugInfo,"Memroy LocalCreate buffer %08x size can't locate",size); // Spelling error is intentional + } + foundSet = _LocateSetBack(parentHeap,index,9,size,group); local_1c.unk0 = (void *) foundSet->block.start; From 406ea88f2b2e0f28ad246b65ff17fabe20988cc0 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Dec 2024 13:25:06 +0100 Subject: [PATCH 6/6] add remaining ewram vars to memory.c --- src/memory.c | 19 +++++++++---------- sym_ewram.txt | 5 ----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/memory.c b/src/memory.c index 2b65c4a66..be14134d4 100644 --- a/src/memory.c +++ b/src/memory.c @@ -56,13 +56,13 @@ struct unkMemoryStruct u32 end; }; -static EWRAM_DATA struct HeapDescriptor *sHeapDescriptorList[8] = {0}; // 2000E88 -static EWRAM_DATA s32 sHeapCount = {0}; // 2000EA8 -UNUSED static EWRAM_DATA u32 sUnused1 = {0}; // 2000EAC -static EWRAM_DATA struct HeapDescriptor sMainHeapDescriptor = {0}; // 2000EB0 -UNUSED static EWRAM_DATA u32 sUnused2 = {0}; // 2000ECC -extern struct HeapFreeListElement gMainHeapFreeList[32]; // 2000ED0 (CAPACITY OR STRUCT SIZE IS WRONG) -extern u8 gMainHeap[HEAP_SIZE]; // 20011D0 +static EWRAM_DATA struct HeapDescriptor *sHeapDescriptorList[8] = {0}; +static EWRAM_DATA s32 sHeapCount = {0}; +UNUSED static EWRAM_DATA u32 sUnused1 = 0; +static EWRAM_DATA struct HeapDescriptor sMainHeapDescriptor = {0}; +UNUSED static EWRAM_DATA u32 sUnused2 = 0; +static EWRAM_DATA struct HeapFreeListElement sMainHeapFreeList[32] = {0}; +static EWRAM_DATA u8 sMainHeap[HEAP_SIZE] = {0}; static void DoFree(struct HeapDescriptor *, void *); static void *DoAlloc(struct HeapDescriptor *, s32, u32); @@ -160,10 +160,10 @@ static void InitHeapInternal(void) { struct HeapSettings settings; - settings.start = gMainHeap; + settings.start = sMainHeap; settings.size = HEAP_SIZE; sHeapCount = 0; - DoInitHeap(&sMainHeapDescriptor, &settings, gMainHeapFreeList, sizeof(gMainHeapFreeList) / sizeof(struct HeapFreeListElement)); + DoInitHeap(&sMainHeapDescriptor, &settings, sMainHeapFreeList, sizeof(sMainHeapFreeList) / sizeof(struct HeapFreeListElement)); } static void DoInitHeap(struct HeapDescriptor *descriptor, struct HeapSettings *settings, struct HeapFreeListElement *freeList, u32 freeListLength) @@ -495,7 +495,6 @@ UNUSED static struct HeapDescriptor *MemoryLocate_LocalCreate(struct HeapDescrip FatalError(&debugInfo,"Memroy LocalCreate buffer %08x size can't locate",size); // Spelling error is intentional } - foundSet = _LocateSetBack(parentHeap,index,9,size,group); local_1c.unk0 = (void *) foundSet->block.start; local_1c.end = foundSet->block.size; diff --git a/sym_ewram.txt b/sym_ewram.txt index 851dd5c8d..c21f97dca 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -8,11 +8,6 @@ gScriptVarBuffer: /* 2000A88 (ThoroughlyResetScriptVars - RestoreGlobalScriptVar .space 0x400 .include "src/memory.o" -gMainHeapFreeList: /* 2000ED0 (InitHeapInternal) */ - .space 0x300 -gMainHeap: /* 20011D0 (InitHeapInternal) */ - .space 0x24000 - .include "src/bg_palette_buffer.o" .include "src/input.o" .include "src/sprite.o"