Merge pull request #284 from DizzyEggg/memory_mid
Some checks are pending
GithubCI / build (push) Waiting to run

This commit is contained in:
Seth Barberee
2024-12-02 08:07:45 -08:00
committed by GitHub
13 changed files with 1166 additions and 1475 deletions

View File

@@ -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.

View File

@@ -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

687
data/data1.s Normal file
View File

@@ -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

View File

@@ -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, ...);
@@ -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

View File

@@ -1,69 +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 */ u32 freeListLength;
/* 0x14 */ u8 *start;
/* 0x18 */ u32 size;
};
// size: 0x8
struct unkMemoryStruct
{
struct HeapDescriptor *unk0;
u32 end;
};
// size: 0x1C
struct unkMemoryStruct2
{
u8 fill[0xC];
/* 0xC */ struct HeapDescriptor *unkC;
/* 0x10 */ u32 end;
};
extern struct HeapDescriptor *gHeapDescriptorList[8];
extern s32 gHeapCount;
void InitHeap(void);
void MemoryClear8(u8 *dest, s32 size);
@@ -79,14 +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);
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);
void xxx_unused_memory_free(struct HeapDescriptor *a1);
void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2);
#endif // GUARD_MEMORY_H

View File

@@ -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);
@@ -420,6 +418,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);

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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

View File

@@ -1,16 +1,78 @@
#include "global.h"
#include "cpu.h"
#include "globaldata.h"
#include "memory.h"
#include "cpu.h"
#include "debug.h"
EWRAM_DATA struct HeapDescriptor *gHeapDescriptorList[8] = {0}; // 2000E88
EWRAM_DATA s32 gHeapCount = {0}; // 2000EA8
UNUSED static EWRAM_DATA u32 sUnused1 = {0}; // 2000EAC
EWRAM_DATA struct HeapDescriptor gMainHeapDescriptor = {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
#define HEAP_SIZE 0x24000
void InitHeapInternal(void);
// 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};
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);
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);
ALIGNED(4) static const char sFileNameText[] = "../system/memory_locate.c";
void InitHeap(void)
{
@@ -34,6 +96,7 @@ void MemoryClear16(u16 *dest, s32 size)
*dest++ = 0;
}
}
void MemoryClear32(u32 *dest, s32 size)
{
CpuClear(dest, size);
@@ -93,23 +156,23 @@ void MemoryCopy32(u32 *dest, u32 *src, s32 size)
}
}
void InitHeapInternal(void)
static void InitHeapInternal(void)
{
struct HeapSettings settings;
settings.start = gMainHeap;
settings.start = sMainHeap;
settings.size = HEAP_SIZE;
gHeapCount = 0;
DoInitHeap(&gMainHeapDescriptor, &settings, gMainHeapFreeList, sizeof(gMainHeapFreeList) / sizeof(struct HeapFreeListElement));
sHeapCount = 0;
DoInitHeap(&sMainHeapDescriptor, &settings, sMainHeapFreeList, sizeof(sMainHeapFreeList) / 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 & 0xFFFFFFFC;
aligned_size = settings->size & ~(3);
gHeapDescriptorList[gHeapCount++] = descriptor;
sHeapDescriptorList[sHeapCount++] = descriptor;
descriptor->start = settings->start;
descriptor->size = aligned_size;
@@ -127,7 +190,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;
@@ -145,7 +208,7 @@ void InitSubHeap(struct HeapDescriptor *parentHeap, struct HeapMemoryBlock2 *blo
DoInitHeap(parentHeap, &settings, freeList, freeListMax);
}
u8 xxx_memory_attr_related(u32 r0)
static u32 xxx_memory_attr_related(u32 r0)
{
u32 temp;
u32 return_var;
@@ -177,3 +240,375 @@ u8 xxx_memory_attr_related(u32 r0)
}
return return_var;
}
static 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;
}
static 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;
}
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;
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) {
FatalError(&sLocateSetFrontDebugLocation, "Memory Locate sprit max over [%3d/%3d]", 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 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;
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) {
FatalError(&sLocateSetBackDebugLocation, "Memory Locate sprit max over [%3d/%3d]", 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 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;
struct HeapFreeListElement * foundSet;
s32 atb;
if (heap == NULL) {
heap = &sMainHeapDescriptor;
}
// 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;
foundSet = _LocateSetFront(heap,index,atb,size,group);
return foundSet->block.start;
}
else {
index = MemorySearchFromBack(heap,atb,size);
if (index < 0) goto error;
foundSet = _LocateSetBack(heap,index,atb,size,group);
return foundSet->block.start;
}
error:
FatalError(&sLocateSetDebugLocation,
"Memroy LocateSet [%p] buffer %8x size can't locate\n atb %02x grp %3d ", // Spelling error is intentional
heap,size,atb,group);
}
void *MemoryAlloc(s32 size, s32 group)
{
DoAlloc(&sMainHeapDescriptor, size, group);
}
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;
struct HeapFreeListElement *foundSet;
struct HeapDescriptor *iVar3;
struct unkMemoryStruct local_1c;
if (parentHeap == NULL) {
parentHeap = &sMainHeapDescriptor;
}
index = MemorySearchFromBack(parentHeap,9,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;
local_1c.end = foundSet->block.size;
iVar3 = DoCreateSubHeap(&local_1c,param_3);
iVar3->parentHeap = parentHeap;
return iVar3;
}
static struct HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b)
{
struct HeapMemoryBlock2 s2;
struct HeapDescriptor *a1;
a1 = a->unk0;
s2.start = (struct HeapFreeListElement *)((u8*)a1 + sizeof(struct HeapDescriptor));
s2.size = a->end - sizeof(struct HeapDescriptor);
InitSubHeap(a1, &s2, b);
return a1;
}
UNUSED static 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 < sHeapCount; i++) {
if (sHeapDescriptorList[i] == a1) {
sHeapCount--;
for (; i < sHeapCount; i++) {
sHeapDescriptorList[i] = sHeapDescriptorList[i + 1];
}
temp = TRUE;
break;
}
}
if (temp && a1->parentHeap != NULL)
DoFree(a1->parentHeap, a1);
}
}
static void *DoAlloc(struct HeapDescriptor *heap, s32 size, u32 a2)
{
return _LocateSet(heap, size, a2 | 0x100);
}
static void DoFree(struct HeapDescriptor *heapDescriptior, void *ptrToFree)
{
struct HeapFreeListElement *curr;
struct HeapFreeListElement *next;
struct HeapFreeListElement *prev;
s32 i;
if (heapDescriptior == NULL)
heapDescriptior = &sMainHeapDescriptor;
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;
}
}
}
UNUSED static void nullsub_141(void)
{
}
UNUSED static void nullsub_142(void)
{
}

View File

@@ -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)
{
}

View File

@@ -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"