summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrakxo <87568477+Prakxo@users.noreply.github.com>2024-03-27 17:55:05 +0100
committerGitHub <noreply@github.com>2024-03-27 09:55:05 -0700
commit540648ef26d6dbdd4277bd4bdd8a38e32e8569ad (patch)
treeb708af79f4843a47daccc154aee8ff7057391e45
parent4b081155a9f62ccc0bf46245cd2219cfb9324cd9 (diff)
listalloc OK (#158)
-rw-r--r--include/PreRender.h5
-rw-r--r--include/listalloc.h13
-rw-r--r--linker_scripts/jp/symbol_addrs_code.txt8
-rw-r--r--src/code/listalloc.c63
-rw-r--r--yamls/jp/code.yaml2
5 files changed, 77 insertions, 14 deletions
diff --git a/include/PreRender.h b/include/PreRender.h
index 48d9c39..cc54950 100644
--- a/include/PreRender.h
+++ b/include/PreRender.h
@@ -4,11 +4,6 @@
#include "ultra64.h"
#include "unk.h"
-typedef struct ListAlloc {
- /* 0x0 */ struct ListAlloc* prev;
- /* 0x4 */ struct ListAlloc* next;
-} ListAlloc; // size = 0x8
-
typedef struct PreRender {
/* 0x00 */ u16 unk_00;
/* 0x02 */ u16 unk_02;
diff --git a/include/listalloc.h b/include/listalloc.h
index 9e3e0f4..e4ca07f 100644
--- a/include/listalloc.h
+++ b/include/listalloc.h
@@ -3,9 +3,14 @@
#include "ultra64.h"
-// void func_800D6390_jp();
-// void func_800D63A4_jp();
-// void func_800D6410_jp();
-// void func_800D6490_jp();
+typedef struct ListAlloc {
+ /* 0x0 */ struct ListAlloc* prev;
+ /* 0x4 */ struct ListAlloc* next;
+} ListAlloc; // size = 0x8
+
+ListAlloc* ListAlloc_Init(ListAlloc* this);
+void* ListAlloc_Alloc(ListAlloc* this, size_t size);
+void ListAlloc_Free(ListAlloc* this, void* data);
+void ListAlloc_FreeAll(ListAlloc* this);
#endif
diff --git a/linker_scripts/jp/symbol_addrs_code.txt b/linker_scripts/jp/symbol_addrs_code.txt
index ebf7290..11dc5e9 100644
--- a/linker_scripts/jp/symbol_addrs_code.txt
+++ b/linker_scripts/jp/symbol_addrs_code.txt
@@ -3491,10 +3491,10 @@ lbRk_IsLeapOnNextMonth = 0x800D5F44; // type:func
lbRk_KyuurekiDays = 0x800D5FA0; // type:func
lbRk_ToSeiyouReki = 0x800D60E4; // type:func
lbRk_ToKyuuReki = 0x800D6218; // type:func
-func_800D6390_jp = 0x800D6390; // type:func
-func_800D63A4_jp = 0x800D63A4; // type:func
-func_800D6410_jp = 0x800D6410; // type:func
-func_800D6490_jp = 0x800D6490; // type:func
+ListAlloc_Init = 0x800D6390; // type:func
+ListAlloc_Alloc = 0x800D63A4; // type:func
+ListAlloc_Free = 0x800D6410; // type:func
+ListAlloc_FreeAll = 0x800D6490; // type:func
func_800D64E0_jp = 0x800D64E0; // type:func
func_800D66D0_jp = 0x800D66D0; // type:func
padmgr_LockSerialMesgQ = 0x800D6A10; // type:func
diff --git a/src/code/listalloc.c b/src/code/listalloc.c
new file mode 100644
index 0000000..e6b62ee
--- /dev/null
+++ b/src/code/listalloc.c
@@ -0,0 +1,63 @@
+#include "listalloc.h"
+#include "libc64/malloc.h"
+
+ListAlloc* ListAlloc_Init(ListAlloc* this) {
+ this->prev = NULL;
+ this->next = NULL;
+ return this;
+}
+
+void* ListAlloc_Alloc(ListAlloc* this, size_t size) {
+ ListAlloc* ptr = malloc(size + sizeof(ListAlloc));
+ ListAlloc* next;
+
+ if (ptr == NULL) {
+ return NULL;
+ }
+
+ next = this->next;
+ if (next != NULL) {
+ next->next = ptr;
+ }
+
+ ptr->prev = next;
+ ptr->next = NULL;
+ this->next = ptr;
+
+ if (this->prev == NULL) {
+ this->prev = ptr;
+ }
+
+ return (u8*)ptr + sizeof(ListAlloc);
+}
+
+void ListAlloc_Free(ListAlloc* this, void* data) {
+ ListAlloc* ptr = &((ListAlloc*)data)[-1];
+
+ if (ptr->prev != NULL) {
+ ptr->prev->next = ptr->next;
+ }
+
+ if (ptr->next != NULL) {
+ ptr->next->prev = ptr->prev;
+ }
+
+ if (this->prev == ptr) {
+ this->prev = ptr->next;
+ }
+
+ if (this->next == ptr) {
+ this->next = ptr->prev;
+ }
+
+ free(ptr);
+}
+
+void ListAlloc_FreeAll(ListAlloc* this) {
+ ListAlloc* iter = this->prev;
+
+ while (iter != NULL) {
+ ListAlloc_Free(this, (u8*)iter + sizeof(ListAlloc));
+ iter = this->prev;
+ }
+}
diff --git a/yamls/jp/code.yaml b/yamls/jp/code.yaml
index fcf57e0..a245bbc 100644
--- a/yamls/jp/code.yaml
+++ b/yamls/jp/code.yaml
@@ -98,7 +98,7 @@
- [0x6F83B0, c, code/irqmgr]
- [0x6F8A60, c, code/lb_rtc]
- [0x6F9B10, c, code/lb_reki]
- - [0x6FA030, asm, code/listalloc]
+ - [0x6FA030, c, code/listalloc]
- [0x6FA180, c, code/main]
- [0x6FA6B0, asm, code/padmgr]
- [0x6FB340, asm, code/6FB340]