mirror of
https://github.com/zeldaret/af.git
synced 2026-10-02 07:49:50 -04:00
listalloc OK (#158)
This commit is contained in:
@@ -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;
|
||||
|
||||
+9
-4
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user