mirror of
https://github.com/ACreTeam/ac-decomp
synced 2026-06-05 18:57:17 -04:00
Implement & link gamealloc.c
This commit is contained in:
@@ -79,6 +79,8 @@ THA_GA.c:
|
||||
.text: [0x80404AE0, 0x80404B40]
|
||||
TwoHeadArena.c:
|
||||
.text: [0x80404B40, 0x80404C68]
|
||||
gamealloc.c:
|
||||
.text: [0x80405370, 0x804054B0]
|
||||
gfxalloc.c:
|
||||
.text: [0x804054b0, 0x80405518]
|
||||
graph.c:
|
||||
|
||||
@@ -21,6 +21,8 @@ typedef struct gameAlloc_s {
|
||||
/* 0x10 */ GameAllocList* tail;
|
||||
} GameAlloc;
|
||||
|
||||
extern void* gamealloc_malloc(GameAlloc* gamealloc, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "gamealloc.h"
|
||||
|
||||
#include "libc64/malloc.h"
|
||||
|
||||
extern void* gamealloc_malloc(GameAlloc* gamealloc, size_t size) {
|
||||
GameAllocList* alloc = (GameAllocList*)malloc(size + sizeof(GameAllocList));
|
||||
|
||||
if (alloc != NULL) {
|
||||
alloc->alloc_size = size;
|
||||
alloc->prev = gamealloc->tail;
|
||||
gamealloc->tail->next = alloc;
|
||||
gamealloc->tail = alloc;
|
||||
gamealloc->tail->next = &gamealloc->head;
|
||||
gamealloc->head.prev = gamealloc->tail;
|
||||
|
||||
return (void*)(alloc + 1); // data starts after GameAllocList structure
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern void gamealloc_free(GameAlloc* gamealloc, void* ptr) {
|
||||
if (ptr != NULL) {
|
||||
GameAllocList* alloc = ((GameAllocList*)ptr) - 1; // back up to GameAllocList struct
|
||||
|
||||
alloc->prev->next = alloc->next;
|
||||
alloc->next->prev = alloc->prev;
|
||||
gamealloc->tail = gamealloc->head.prev;
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
}
|
||||
|
||||
extern void gamealloc_cleanup(GameAlloc* gamealloc) {
|
||||
GameAllocList* now_p = gamealloc->head.next;
|
||||
GameAllocList* end_p = &gamealloc->head;
|
||||
|
||||
/* Go through entire list and free each until we wrap around to the head list */
|
||||
while (now_p != end_p) {
|
||||
GameAllocList* temp_p = now_p;
|
||||
now_p = now_p->next;
|
||||
free(temp_p);
|
||||
}
|
||||
|
||||
gamealloc->tail = end_p;
|
||||
gamealloc->head.next = gamealloc->tail;
|
||||
gamealloc->head.prev = gamealloc->tail;
|
||||
}
|
||||
|
||||
extern void gamealloc_init(GameAlloc* gamealloc) {
|
||||
gamealloc->tail = &gamealloc->head;
|
||||
gamealloc->head.next = gamealloc->tail;
|
||||
gamealloc->head.prev = gamealloc->tail;
|
||||
}
|
||||
Reference in New Issue
Block a user