summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2017-12-12 08:44:14 -0500
committerPikalaxALT <pikalaxalt@gmail.com>2017-12-12 08:44:14 -0500
commit48f00a9b910f770211c2ac653160d5708956e2f8 (patch)
treee589f0cd74feccc516a05a1185ff0aca20c7db09
parentc418a4585f727f334ed3625cc656764b0c345589 (diff)
through InitHeapInternal
-rw-r--r--asm/memory.s183
-rw-r--r--include/code_800B540.h12
-rw-r--r--ld_script.txt2
-rw-r--r--src/memory.c118
4 files changed, 132 insertions, 183 deletions
diff --git a/asm/memory.s b/asm/memory.s
index e364f1b..f6a0a38 100644
--- a/asm/memory.s
+++ b/asm/memory.s
@@ -5,189 +5,6 @@
.text
- thumb_func_start InitHeap
-InitHeap:
- push {lr}
- bl InitHeapInternal
- pop {r0}
- bx r0
- thumb_func_end InitHeap
-
- thumb_func_start MemoryClear8
-MemoryClear8:
- push {lr}
- cmp r1, 0
- ble _08002EAA
- movs r2, 0
-_08002EA0:
- subs r1, 0x1
- strb r2, [r0]
- adds r0, 0x1
- cmp r1, 0
- bgt _08002EA0
-_08002EAA:
- pop {r0}
- bx r0
- thumb_func_end MemoryClear8
-
- thumb_func_start MemoryClear16
-MemoryClear16:
- push {lr}
- cmp r1, 0
- ble _08002EC2
- movs r2, 0
-_08002EB8:
- subs r1, 0x2
- strh r2, [r0]
- adds r0, 0x2
- cmp r1, 0
- bgt _08002EB8
-_08002EC2:
- pop {r0}
- bx r0
- thumb_func_end MemoryClear16
-
- thumb_func_start MemoryClear32
-MemoryClear32:
- push {lr}
- bl CpuClear
- pop {r0}
- bx r0
- thumb_func_end MemoryClear32
-
- thumb_func_start MemoryFill8
-MemoryFill8:
- push {lr}
- lsls r1, 24
- lsrs r1, 24
- cmp r2, 0
- ble _08002EE8
-_08002EDE:
- subs r2, 0x1
- strb r1, [r0]
- adds r0, 0x1
- cmp r2, 0
- bgt _08002EDE
-_08002EE8:
- pop {r0}
- bx r0
- thumb_func_end MemoryFill8
-
- thumb_func_start MemoryFill16
-MemoryFill16:
- push {lr}
- lsls r1, 16
- lsrs r1, 16
- cmp r2, 0
- ble _08002F00
-_08002EF6:
- subs r2, 0x2
- strh r1, [r0]
- adds r0, 0x2
- cmp r2, 0
- bgt _08002EF6
-_08002F00:
- pop {r0}
- bx r0
- thumb_func_end MemoryFill16
-
- thumb_func_start MemoryFill32
-MemoryFill32:
- push {lr}
- cmp r2, 0
- ble _08002F12
-_08002F0A:
- subs r2, 0x4
- stm r0!, {r1}
- cmp r2, 0
- bgt _08002F0A
-_08002F12:
- pop {r0}
- bx r0
- thumb_func_end MemoryFill32
-
- thumb_func_start MemoryCopy8
-MemoryCopy8:
- push {lr}
- adds r3, r0, 0
- cmp r2, 0
- ble _08002F2E
-_08002F20:
- subs r2, 0x1
- ldrb r0, [r1]
- strb r0, [r3]
- adds r1, 0x1
- adds r3, 0x1
- cmp r2, 0
- bgt _08002F20
-_08002F2E:
- pop {r0}
- bx r0
- thumb_func_end MemoryCopy8
-
- thumb_func_start MemoryCopy16
-MemoryCopy16:
- push {lr}
- adds r3, r0, 0
- cmp r2, 0
- ble _08002F4A
-_08002F3C:
- subs r2, 0x2
- ldrh r0, [r1]
- strh r0, [r3]
- adds r1, 0x2
- adds r3, 0x2
- cmp r2, 0
- bgt _08002F3C
-_08002F4A:
- pop {r0}
- bx r0
- thumb_func_end MemoryCopy16
-
- thumb_func_start MemoryCopy32
-MemoryCopy32:
- push {lr}
- adds r3, r0, 0
- cmp r2, 0
- ble _08002F62
-_08002F58:
- subs r2, 0x4
- ldm r1!, {r0}
- stm r3!, {r0}
- cmp r2, 0
- bgt _08002F58
-_08002F62:
- pop {r0}
- bx r0
- thumb_func_end MemoryCopy32
-
- thumb_func_start InitHeapInternal
-InitHeapInternal:
- push {lr}
- sub sp, 0x8
- ldr r0, _08002F90
- str r0, [sp]
- movs r0, 0x90
- lsls r0, 10
- str r0, [sp, 0x4]
- ldr r1, _08002F94
- movs r0, 0
- str r0, [r1]
- ldr r0, _08002F98
- ldr r2, _08002F9C
- mov r1, sp
- movs r3, 0x20
- bl DoInitHeap
- add sp, 0x8
- pop {r0}
- bx r0
- .align 2, 0
-_08002F90: .4byte gUnknown_20011D0
-_08002F94: .4byte gUnknown_2000EA8
-_08002F98: .4byte gUnknown_2000EB0
-_08002F9C: .4byte gUnknown_2000ED0
- thumb_func_end InitHeapInternal
-
thumb_func_start DoInitHeap
DoInitHeap:
push {r4-r6,lr}
diff --git a/include/code_800B540.h b/include/code_800B540.h
new file mode 100644
index 0000000..cc4adf8
--- /dev/null
+++ b/include/code_800B540.h
@@ -0,0 +1,12 @@
+#ifndef GUARD_code_800B540_H
+#define GUARD_code_800B540_H
+
+// Exported type declarations
+
+// Exported RAM declarations
+
+// Exported ROM declarations
+
+void CpuClear(u32 *dest, int size);
+
+#endif //GUARD_code_800B540_H
diff --git a/ld_script.txt b/ld_script.txt
index 4ce25b9..db25593 100644
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -14,6 +14,7 @@ SECTIONS {
tools/agbcc/lib/libgcc.a:fp-bit.o(.bss);
. = ALIGN(4);
tools/agbcc/lib/libgcc.a:dp-bit.o(.bss);
+ . = ALIGN(8); /* 0x39e18 */
<EWRAM2>
. = 0x40000;
}
@@ -37,6 +38,7 @@ SECTIONS {
asm/code.o(.text);
asm/event_flag.o(.text);
asm/code_8002774.o(.text);
+ src/memory.o(.text);
asm/memory.o(.text);
asm/code_80035F0.o(.text);
src/other_random.o(.text);
diff --git a/src/memory.c b/src/memory.c
new file mode 100644
index 0000000..1cf31f5
--- /dev/null
+++ b/src/memory.c
@@ -0,0 +1,118 @@
+
+// Includes
+#include "global.h"
+#include "code_800B540.h"
+
+// Static type declarations
+
+struct HeapInitArgs {
+ void *ptr;
+ u32 size;
+};
+
+// Static RAM declarations
+
+u32 gUnknown_2000EA8 = 0;
+u8 gUnknown_2000EB0[0x20] = {};
+u8 gUnknown_2000ED0[0x300] = {};
+u8 gUnknown_20011D0[0x24000] = {};
+
+// Static ROM declarations
+
+// .rodata
+
+// .text
+
+void InitHeapInternal(void);
+void DoInitHeap(void *a0, struct HeapInitArgs *args, void *a2, size_t a3);
+
+void InitHeap(void)
+{
+ InitHeapInternal();
+}
+
+void MemoryClear8(u8 *dst, int size)
+{
+ while (size > 0)
+ {
+ size -= 1;
+ *dst++ = 0;
+ }
+}
+
+void MemoryClear16(u16 *dst, int size)
+{
+ while (size > 0)
+ {
+ size -= 2;
+ *dst++ = 0;
+ }
+}
+
+void MemoryClear32(u32 *dst, int size)
+{
+ CpuClear(dst, size);
+}
+
+void MemoryFill8(u8 *dst, u8 val, int size)
+{
+ while (size > 0)
+ {
+ size -= 1;
+ *dst++ = val;
+ }
+}
+
+void MemoryFill16(u16 *dst, u16 val, int size)
+{
+ while (size > 0)
+ {
+ size -= 2;
+ *dst++ = val;
+ }
+}
+
+void MemoryFill32(u32 *dst, u32 val, int size)
+{
+ while (size > 0)
+ {
+ size -= 4;
+ *dst++ = val;
+ }
+}
+
+void MemoryCopy8(u8 *dst, const u8 *src, int size)
+{
+ while (size > 0)
+ {
+ size -= 1;
+ *dst++ = *src++;
+ }
+}
+
+void MemoryCopy16(u16 *dst, const u16 *src, int size)
+{
+ while (size > 0)
+ {
+ size -= 2;
+ *dst++ = *src++;
+ }
+}
+
+void MemoryCopy32(u32 *dst, const u32 *src, int size)
+{
+ while (size > 0)
+ {
+ size -= 4;
+ *dst++ = *src++;
+ }
+}
+
+void InitHeapInternal(void)
+{
+ struct HeapInitArgs args;
+ args.ptr = gUnknown_20011D0;
+ args.size = sizeof gUnknown_20011D0;
+ gUnknown_2000EA8 = 0;
+ DoInitHeap(gUnknown_2000EB0, &args, gUnknown_2000ED0, sizeof gUnknown_2000EB0);
+}