mirror of
https://github.com/zeldaret/mm.git
synced 2026-05-25 15:25:04 -04:00
TwoHeadArena and TwoHeadGfxArena OK (#83)
* TwoHeadArena and TwoHeadGfxArena OK * Changed negatives to ~ in TwoHeadArena.c * Renamed functions to match OoT * Formatted code files * Removed dispbuf
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#include <ultra64.h>
|
||||
#include <global.h>
|
||||
|
||||
void* THA_GetHead(TwoHeadArena* tha) {
|
||||
return tha->head;
|
||||
}
|
||||
|
||||
void THA_SetHead(TwoHeadArena* tha, void* start) {
|
||||
tha->head = start;
|
||||
}
|
||||
|
||||
void* THA_GetTail(TwoHeadArena* tha) {
|
||||
return tha->tail;
|
||||
}
|
||||
|
||||
void* THA_AllocStart(TwoHeadArena* tha, u32 size) {
|
||||
void* start = tha->head;
|
||||
|
||||
tha->head = (u32)tha->head + size;
|
||||
return start;
|
||||
}
|
||||
|
||||
void* THA_AllocStart1(TwoHeadArena* tha) {
|
||||
return THA_AllocStart(tha, 1);
|
||||
}
|
||||
|
||||
void* THA_AllocEnd(TwoHeadArena* tha, u32 size) {
|
||||
u32 mask;
|
||||
|
||||
if (size >= 0x10) {
|
||||
mask = ~0xF;
|
||||
} else if (size & 1) {
|
||||
mask = -1;
|
||||
} else if (size & 2) {
|
||||
mask = ~0x1;
|
||||
} else if (size & 4) {
|
||||
mask = ~0x3;
|
||||
} else {
|
||||
mask = (size & 8) ? ~0x7 : -1;
|
||||
}
|
||||
|
||||
tha->tail = (((u32)tha->tail & mask) - size) & mask;
|
||||
return tha->tail;
|
||||
}
|
||||
|
||||
void* THA_AllocEndAlign16(TwoHeadArena* tha, u32 size) {
|
||||
u32 mask = ~0xF;
|
||||
|
||||
tha->tail = (((u32)tha->tail & mask) - size) & mask;
|
||||
return tha->tail;
|
||||
}
|
||||
|
||||
void* THA_AllocEndAlign(TwoHeadArena* tha, u32 size, u32 mask) {
|
||||
tha->tail = (((u32)tha->tail & mask) - size) & mask;
|
||||
return tha->tail;
|
||||
}
|
||||
|
||||
s32 THA_GetSize(TwoHeadArena* tha) {
|
||||
return (u32)tha->tail - (u32)tha->head;
|
||||
}
|
||||
|
||||
u32 THA_IsCrash(TwoHeadArena* tha) {
|
||||
return THA_GetSize(tha) < 0;
|
||||
}
|
||||
|
||||
void THA_Init(TwoHeadArena* tha) {
|
||||
tha->head = tha->bufp;
|
||||
tha->tail = (u32)tha->bufp + tha->size;
|
||||
}
|
||||
|
||||
void THA_Ct(TwoHeadArena* tha, void* ptr, u32 size) {
|
||||
bzero(tha, sizeof(TwoHeadArena));
|
||||
tha->bufp = ptr;
|
||||
tha->size = size;
|
||||
THA_Init(tha);
|
||||
}
|
||||
|
||||
void THA_Dt(TwoHeadArena* tha) {
|
||||
bzero(tha, sizeof(TwoHeadArena));
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <ultra64.h>
|
||||
#include <global.h>
|
||||
|
||||
void THGA_Ct(TwoHeadGfxArena* thga, Gfx* start, u32 size) {
|
||||
THA_Ct((TwoHeadArena*)thga, start, size);
|
||||
}
|
||||
|
||||
void THGA_Dt(TwoHeadGfxArena* thga) {
|
||||
THA_Dt((TwoHeadArena*)thga);
|
||||
}
|
||||
|
||||
u32 THGA_IsCrash(TwoHeadGfxArena* thga) {
|
||||
return THA_IsCrash((TwoHeadArena*)thga);
|
||||
}
|
||||
|
||||
void THGA_Init(TwoHeadGfxArena* thga) {
|
||||
THA_Init((TwoHeadArena*)thga);
|
||||
}
|
||||
|
||||
s32 THGA_GetSize(TwoHeadGfxArena* thga) {
|
||||
return THA_GetSize((TwoHeadArena*)thga);
|
||||
}
|
||||
|
||||
Gfx* THGA_GetHead(TwoHeadGfxArena* thga) {
|
||||
return THA_GetHead((TwoHeadArena*)thga);
|
||||
}
|
||||
|
||||
void THGA_SetHead(TwoHeadGfxArena* thga, Gfx* start) {
|
||||
THA_SetHead((TwoHeadArena*)thga, start);
|
||||
}
|
||||
|
||||
Gfx* THGA_GetTail(TwoHeadGfxArena* thga) {
|
||||
return THA_GetTail((TwoHeadArena*)thga);
|
||||
}
|
||||
|
||||
Gfx* THGA_AllocStartArray8(TwoHeadGfxArena* thga, u32 count) {
|
||||
return THA_AllocStart((TwoHeadArena*)thga, count * 8);
|
||||
}
|
||||
|
||||
Gfx* THGA_AllocStart8(TwoHeadGfxArena* thga) {
|
||||
return THGA_AllocStartArray8(thga, 1);
|
||||
}
|
||||
|
||||
Gfx* THGA_AllocStart8Wrapper(TwoHeadGfxArena* thga) {
|
||||
return THGA_AllocStart8(thga);
|
||||
}
|
||||
|
||||
Gfx* THGA_AllocEnd(TwoHeadGfxArena* thga, u32 size) {
|
||||
return THA_AllocEnd((TwoHeadArena*)thga, size);
|
||||
}
|
||||
|
||||
Gfx* THGA_AllocEndArray64(TwoHeadGfxArena* thga, u32 count) {
|
||||
return THGA_AllocEnd(thga, count * 0x40);
|
||||
}
|
||||
|
||||
Gfx* THGA_AllocEnd64(TwoHeadGfxArena* thga) {
|
||||
return THGA_AllocEnd(thga, 0x40);
|
||||
}
|
||||
|
||||
Gfx* THGA_AllocEndArray16(TwoHeadGfxArena* thga, u32 count) {
|
||||
return THGA_AllocEnd(thga, count * 0x10);
|
||||
}
|
||||
|
||||
Gfx* THGA_AllocEnd16(TwoHeadGfxArena* thga) {
|
||||
return THGA_AllocEnd(thga, 0x10);
|
||||
}
|
||||
+8
-8
@@ -151,11 +151,11 @@ void Game_InitHeap(GameState *ctxt, u32 size) {
|
||||
buf = Gamealloc_Alloc(&_ctx->alloc, size);
|
||||
|
||||
if (buf) {
|
||||
GameStateHeap_Init(&ctxt->heap, buf, size);
|
||||
THA_Ct(&ctxt->heap, buf, size);
|
||||
return;
|
||||
}
|
||||
|
||||
GameStateHeap_Init(&ctxt->heap, NULL, 0);
|
||||
THA_Ct(&ctxt->heap, NULL, 0);
|
||||
assert_fail("../game.c", 0x40B);
|
||||
}
|
||||
|
||||
@@ -168,9 +168,9 @@ void Game_ResizeHeap(GameState *ctxt, u32 size)
|
||||
u32 bytesAllocated;
|
||||
void *heapStart;
|
||||
|
||||
heapStart = ctxt->heap.heapStart;
|
||||
heapStart = ctxt->heap.bufp;
|
||||
alloc = &ctxt->alloc;
|
||||
GameStateHeap_Clear(&ctxt->heap);
|
||||
THA_Dt(&ctxt->heap);
|
||||
Gamealloc_Free(alloc, heapStart);
|
||||
StartHeap_AnalyzeArena(&systemMaxFree, &bytesFree, &bytesAllocated);
|
||||
size = ((systemMaxFree - (sizeof(ArenaNode))) < size) ? (0) : (size);
|
||||
@@ -181,11 +181,11 @@ void Game_ResizeHeap(GameState *ctxt, u32 size)
|
||||
|
||||
if (buf = Gamealloc_Alloc(alloc, size))
|
||||
{
|
||||
GameStateHeap_Init(&ctxt->heap, buf, size);
|
||||
THA_Ct(&ctxt->heap, buf, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameStateHeap_Init(&ctxt->heap, 0, 0);
|
||||
THA_Ct(&ctxt->heap, 0, 0);
|
||||
assert_fail("../game.c", 0x432);
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ void Game_StateFini(GameState *ctxt) {
|
||||
func_801420F4(&D_801F8020);
|
||||
func_80141900(&sMonoColors);
|
||||
func_80140900(&D_801F8048);
|
||||
GameStateHeap_Clear(&ctxt->heap);
|
||||
THA_Dt(&ctxt->heap);
|
||||
Gamealloc_FreeAll(&ctxt->alloc);
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ u32 Game_GetShouldContinue(GameState *ctxt) {
|
||||
}
|
||||
|
||||
s32 Game_GetHeapFreeSize(GameState *ctxt) {
|
||||
return GameStateHeap_GetFreeSize(&ctxt->heap);
|
||||
return THA_GetSize(&ctxt->heap);
|
||||
}
|
||||
|
||||
s32 func_80173B48(GameState *ctxt) {
|
||||
|
||||
@@ -32,7 +32,7 @@ void BgCheck_PolygonLinkedListInit(GlobalContext* ctxt, BgPolygonLinkedList* lis
|
||||
}
|
||||
|
||||
void BgCheck_PolygonLinkedListAlloc(GlobalContext* ctxt, BgPolygonLinkedList* list, u32 numNodes) {
|
||||
list->nodes = (BgPolygonLinkedListNode*)GameStateHeap_AllocFromEndAligned(&ctxt->state.heap, numNodes << 2, 0xfffffffe);
|
||||
list->nodes = (BgPolygonLinkedListNode*)THA_AllocEndAlign(&ctxt->state.heap, numNodes << 2, 0xfffffffe);
|
||||
list->maxNodes = numNodes;
|
||||
list->nextFreeNode = 0;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ void EffectSS_Init(GlobalContext* ctxt, s32 numEntries) {
|
||||
LoadedParticleEntry* iter;
|
||||
ParticleOverlay* iter2;
|
||||
|
||||
EffectSS2Info.data_table = (LoadedParticleEntry*)GameStateHeap_AllocFromEnd(&ctxt->state.heap, numEntries * sizeof(LoadedParticleEntry));
|
||||
EffectSS2Info.data_table = (LoadedParticleEntry*)THA_AllocEndAlign16(&ctxt->state.heap, numEntries * sizeof(LoadedParticleEntry));
|
||||
EffectSS2Info.searchIndex = 0;
|
||||
EffectSS2Info.size = numEntries;
|
||||
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ void Scene_Init(GlobalContext* ctxt, SceneContext* sceneCtxt) {
|
||||
// TODO: 0x23 is OBJECT_EXCHANGE_BANK_MAX in OOT
|
||||
for (i = 0; i < 0x23; i++) sceneCtxt->objects[i].id = 0;
|
||||
|
||||
sceneCtxt->objectVramStart = sceneCtxt->objects[0].vramAddr = GameStateHeap_AllocFromEnd(&ctxt->state.heap, spaceSize);
|
||||
sceneCtxt->objectVramStart = sceneCtxt->objects[0].vramAddr = THA_AllocEndAlign16(&ctxt->state.heap, spaceSize);
|
||||
// UB to cast sceneCtxt->objectVramStart to s32
|
||||
sceneCtxt->objectVramEnd = (void*)((u32)sceneCtxt->objectVramStart + spaceSize);
|
||||
// TODO: Second argument here is an object enum
|
||||
@@ -342,7 +342,7 @@ s32 func_8012FF10(GlobalContext* ctxt, s32 fileIndex) {
|
||||
u32 fileSize = D_801C2660[fileIndex].vromEnd - vromStart;
|
||||
|
||||
if (fileSize) {
|
||||
ctxt->roomContext.unk74 = GameStateHeap_AllocFromEnd(&ctxt->state.heap, fileSize);
|
||||
ctxt->roomContext.unk74 = THA_AllocEndAlign16(&ctxt->state.heap, fileSize);
|
||||
return DmaMgr_SendRequest0(ctxt->roomContext.unk74, vromStart, fileSize);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -146,15 +146,15 @@ void func_801434E4(GameState* state, SkyboxContext* skyboxCtx, s16 skyType) {
|
||||
func_801431E8(state, skyboxCtx, skyType);
|
||||
|
||||
if (skyType != 0) {
|
||||
skyboxCtx->unk17C = GameStateHeap_AllocFromEnd(&state->heap, 0x3840);
|
||||
skyboxCtx->unk17C = THA_AllocEndAlign16(&state->heap, 0x3840);
|
||||
|
||||
if (skyType == 5) {
|
||||
// Allocate enough space for the vertices for a 6 sided skybox (cube)
|
||||
skyboxCtx->roomVtx = GameStateHeap_AllocFromEnd(&state->heap, sizeof(Vtx) * 32 * 6);
|
||||
skyboxCtx->roomVtx = THA_AllocEndAlign16(&state->heap, sizeof(Vtx) * 32 * 6);
|
||||
func_80143148(skyboxCtx, 6);
|
||||
} else {
|
||||
// Allocate enough space for the vertices for a 5 sided skybox (bottom is missing)
|
||||
skyboxCtx->roomVtx = GameStateHeap_AllocFromEnd(&state->heap, sizeof(Vtx) * 32 * 5);
|
||||
skyboxCtx->roomVtx = THA_AllocEndAlign16(&state->heap, sizeof(Vtx) * 32 * 5);
|
||||
func_80143148(skyboxCtx, 5);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user