1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-23 05:45:03 +00:00
oot/src/code/TwoHeadArena.c

142 lines
3.2 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <global.h>
2020-03-22 21:19:43 +00:00
void THGA_Ct(TwoHeadGfxArena* thga, Gfx* start, u32 size) {
2020-03-17 04:31:30 +00:00
THA_Ct((TwoHeadArena*)thga, start, size);
}
2020-03-22 21:19:43 +00:00
void THGA_Dt(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
THA_Dt((TwoHeadArena*)thga);
}
2020-03-22 21:19:43 +00:00
u32 THGA_IsCrash(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
return THA_IsCrash((TwoHeadArena*)thga);
}
2020-03-22 21:19:43 +00:00
void THGA_Init(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
THA_Init((TwoHeadArena*)thga);
}
2020-03-22 21:19:43 +00:00
s32 THGA_GetSize(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
return THA_GetSize((TwoHeadArena*)thga);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_GetHead(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
return THA_GetHead((TwoHeadArena*)thga);
}
2020-03-22 21:19:43 +00:00
void THGA_SetHead(TwoHeadGfxArena* thga, Gfx* start) {
2020-03-17 04:31:30 +00:00
THA_SetHead((TwoHeadArena*)thga, start);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_GetTail(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
return THA_GetTail((TwoHeadArena*)thga);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_AllocStartArray8(TwoHeadGfxArena* thga, u32 count) {
2020-03-17 04:31:30 +00:00
return THA_AllocStart((TwoHeadArena*)thga, count * 8);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_AllocStart8(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
return THGA_AllocStartArray8(thga, 1);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_AllocStart8Wrapper(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
return THGA_AllocStart8(thga);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_AllocEnd(TwoHeadGfxArena* thga, u32 size) {
2020-03-17 04:31:30 +00:00
return THA_AllocEnd((TwoHeadArena*)thga, size);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_AllocEndArray64(TwoHeadGfxArena* thga, u32 count) {
2020-03-17 04:31:30 +00:00
return THGA_AllocEnd(thga, count * 0x40);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_AllocEnd64(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
return THGA_AllocEnd(thga, 0x40);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_AllocEndArray16(TwoHeadGfxArena* thga, u32 count) {
2020-03-17 04:31:30 +00:00
return THGA_AllocEnd(thga, count * 0x10);
}
2020-03-22 21:19:43 +00:00
Gfx* THGA_AllocEnd16(TwoHeadGfxArena* thga) {
2020-03-17 04:31:30 +00:00
return THGA_AllocEnd(thga, 0x10);
}
2020-03-22 21:19:43 +00:00
void* THA_GetHead(TwoHeadArena* tha) {
2020-03-17 04:31:30 +00:00
return tha->head;
}
2020-03-22 21:19:43 +00:00
void THA_SetHead(TwoHeadArena* tha, void* start) {
2020-03-17 04:31:30 +00:00
tha->head = start;
}
2020-03-22 21:19:43 +00:00
void* THA_GetTail(TwoHeadArena* tha) {
2020-03-17 04:31:30 +00:00
return tha->tail;
}
2020-03-22 21:19:43 +00:00
void* THA_AllocStart(TwoHeadArena* tha, u32 size) {
2020-03-17 04:31:30 +00:00
void* start = tha->head;
tha->head += size;
return start;
}
2020-03-22 21:19:43 +00:00
void* THA_AllocStart1(TwoHeadArena* tha) {
2020-03-17 04:31:30 +00:00
return THA_AllocStart(tha, 1);
}
2020-03-22 21:19:43 +00:00
void* THA_AllocEnd(TwoHeadArena* tha, u32 size) {
2020-03-17 04:31:30 +00:00
u32 mask;
u32* temp;
2020-03-22 21:19:43 +00:00
if (size == 8) {
2020-03-17 04:31:30 +00:00
mask = ~7;
2020-03-22 21:19:43 +00:00
} else if (size == 4 || size == 12) {
2020-03-17 04:31:30 +00:00
mask = ~3;
2020-03-22 21:19:43 +00:00
} else if (size == 2 || size == 6 || size == 10 || size == 12 || size == 14) {
2020-03-17 04:31:30 +00:00
mask = ~1;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
mask = (size >= 0x10) ? ~0xF : 0;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
temp = (u32*)&tha->tail; // required to match
return tha->tail = (void*)(((*temp & mask) - size) & mask);
}
2020-03-22 21:19:43 +00:00
void* THA_AllocEndAlign16(TwoHeadArena* tha, u32 size) {
void* ret = (void*)(u32)((((u32)tha->tail & ~0xF) - size) &
((~(0xF & 0xFFFFFFFFFFFFFFFF)) & 0xFFFFFFFFu)); // required to match
2020-03-17 04:31:30 +00:00
tha->tail = ret;
return ret;
}
2020-03-22 21:19:43 +00:00
void* THA_AllocEndAlign(TwoHeadArena* tha, u32 size, u32 mask) {
2020-03-17 04:31:30 +00:00
void* ret = (void*)((((u32)tha->tail & mask) - size) & mask);
tha->tail = ret;
return ret;
}
2020-03-22 21:19:43 +00:00
s32 THA_GetSize(TwoHeadArena* tha) {
2020-03-17 04:31:30 +00:00
return tha->tail - tha->head;
}
2020-03-22 21:19:43 +00:00
u32 THA_IsCrash(TwoHeadArena* tha) {
2020-03-17 04:31:30 +00:00
return THA_GetSize(tha) < 0;
}
2020-03-22 21:19:43 +00:00
void THA_Init(TwoHeadArena* tha) {
2020-03-17 04:31:30 +00:00
tha->head = tha->bufp;
tha->tail = tha->bufp + tha->size;
}
2020-03-22 21:19:43 +00:00
void THA_Ct(TwoHeadArena* tha, void* ptr, u32 size) {
2020-03-17 04:31:30 +00:00
tha->bufp = ptr;
tha->size = size;
THA_Init(tha);
}
2020-03-22 21:19:43 +00:00
void THA_Dt(TwoHeadArena* tha) {
2020-03-17 04:31:30 +00:00
bzero(tha, sizeof(TwoHeadArena));
}