This commit is contained in:
Max 2020-10-23 23:22:36 -04:00
parent e3def2d7a3
commit 813f6a67a0
2 changed files with 37 additions and 56 deletions

View File

@ -7,23 +7,21 @@ extern "C" {
#include "code_801DB040.h"
// free store block?
struct gUnkClass3
{
gUnkClass3* unk0; // pointer to the next free block
gUnkClass1 unk4; // flexible array member to make this generic?
gUnkClass3* unk0;
gUnkClass1 unk4;
};
// linked list node free store?
struct gUnkClass2
{
u32 unk0; // counter for blocks currently allocated?
u32 unk4; // maximum number of blocks allocated so far?
u32 unk8; // number of linked list nodes initially requested
size_t unkC; // block size
u8* unk10; // TODO: change to gUnkClass3* for unk10 and unk14?
u8* unk14; // pointer to "end" block?
gUnkClass3* unk18; // head of the linked list of free nodes
u32 unk0;
u32 unk4;
u32 unk8;
size_t unkC;
u8* unk10;
u8* unk14;
gUnkClass3* unk18;
};
gUnkClass1* func_801DBC58(gUnkClass2* p1);

View File

@ -5,67 +5,53 @@
#include "code_801DB040.h"
#include "code_801DBB3C.h"
// array of free stores
static u32 func_801DBB3C(void);
static void func_801DBB44(u32);
static void func_801DBB48(gUnkClass2 *p1, size_t nodes, size_t size);
static gUnkClass2 gUnk80491470[32];
static ctorStruct gUnk8063F310(1, 4, 0);
extern "C" {
//static
u32 func_801DBB3C(void)
static u32 func_801DBB3C(void)
{
return 0;
}
//static
void func_801DBB44(u32)
static void func_801DBB44(u32)
{
}
//static
void func_801DBB48(gUnkClass2 *p1, size_t nodes, size_t size)
static void func_801DBB48(gUnkClass2 *p1, size_t nodes, size_t size)
{
size_t r31;
size_t r30;
gUnkClass2 *r29;
unsigned int new_var;
int new_var2;
u8 **new_var3;
size += 7;
r30 = size & (~0x3);
new_var = r30;
r31 = new_var;
r30 = nodes;
r29 = p1;
p1->unk8 = nodes;
new_var2 = nodes + 1;
p1->unkC = r31;
u8 *data = (u8 *) func_801DAD98(new_var2 * r31);
r29->unk10 = data;
r29->unk18 = (gUnkClass3 *) data;
r29->unk14 = data + (r30 * r31);
u8 *curr = data;
u8 *next;
size_t i;
new_var3 = &next;
gUnkClass3 *r8 = 0;
for (i = 0; i < r30; i++)
{
next = curr + r31;
r8 = (gUnkClass3 *) curr;
((gUnkClass3 *) curr)->unk0 = (gUnkClass3 *) (*new_var3);
curr = *new_var3;
}
r8->unk0 = 0;
size_t blockSize = (size+7) & ~0x3;
p1->unk8 = nodes;
p1->unkC = blockSize;
u8* data = (u8*)func_801DAD98((nodes + 1) * blockSize);
p1->unk10 = data;
p1->unk18 = (gUnkClass3*)data;
p1->unk14 = data + (nodes * blockSize);
u8* next;
u8** pnext = &next;
size_t i;
gUnkClass3* r8 = NULL;
for (i = 0; i < nodes; i++) {
*pnext = data + blockSize;
r8 = (gUnkClass3*)data;
((gUnkClass3*)data)->unk0 = (gUnkClass3*)(*pnext);
data = *pnext;
}
r8->unk0 = 0;
}
// allocate a linked list node from the free store
gUnkClass1* func_801DBC58(gUnkClass2* p1)
{
gUnkClass3* r31 = p1->unk18;
u32 r30 = func_801DBB3C();
func_801DBB44(0);
if (r31) {
p1->unk18 = r31->unk0; // point unk18 to possible next free block?
p1->unk18 = r31->unk0;
goto passCheck;
}
func_801DBB44(r30);
@ -78,8 +64,6 @@ passCheck:
return &r31->unk4;
}
// return node p2 to free store p1, making it the new head of the
// free node linked list
void func_801DBD00(gUnkClass2* p1, gUnkClass1* p2)
{
u32 r31;
@ -94,7 +78,6 @@ void func_801DBD00(gUnkClass2* p1, gUnkClass1* p2)
}
}
// allocate the free store given number of elements and size of each?
gUnkClass2* func_801DBD74(u32 nodes, u32 size)
{
size_t i;