diff options
| author | kyleburnette <kyle@kyleburnette.com> | 2021-03-27 10:13:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-27 12:13:56 -0500 |
| commit | a0b8a7c718f32df1c30f5548fee494b8be6dffe4 (patch) | |
| tree | 77f245c819b7e976f4f886ae0450ba3f736d05fa /src/code | |
| parent | 6e4d156ad788f4add678481d38f6cfa5f35e33e2 (diff) | |
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
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/TwoHeadArena.c | 80 | ||||
| -rw-r--r-- | src/code/TwoHeadGfxArena.c | 66 | ||||
| -rw-r--r-- | src/code/game.c | 16 | ||||
| -rw-r--r-- | src/code/z_bgcheck.c | 2 | ||||
| -rw-r--r-- | src/code/z_effect_soft_sprite.c | 2 | ||||
| -rw-r--r-- | src/code/z_scene.c | 4 | ||||
| -rw-r--r-- | src/code/z_vr_box.c | 6 |
7 files changed, 161 insertions, 15 deletions
diff --git a/src/code/TwoHeadArena.c b/src/code/TwoHeadArena.c new file mode 100644 index 000000000..8ca24c67e --- /dev/null +++ b/src/code/TwoHeadArena.c @@ -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)); +} diff --git a/src/code/TwoHeadGfxArena.c b/src/code/TwoHeadGfxArena.c new file mode 100644 index 000000000..2cf73aa88 --- /dev/null +++ b/src/code/TwoHeadGfxArena.c @@ -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); +} diff --git a/src/code/game.c b/src/code/game.c index 206cd69a4..bde34635e 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -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) { diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 2f839a6d8..ed450a4de 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -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; } diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c index 19478622f..be20a2452 100644 --- a/src/code/z_effect_soft_sprite.c +++ b/src/code/z_effect_soft_sprite.c @@ -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; diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 5dc227d25..e697bd871 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -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); } diff --git a/src/code/z_vr_box.c b/src/code/z_vr_box.c index 50b28f042..46fb02935 100644 --- a/src/code/z_vr_box.c +++ b/src/code/z_vr_box.c @@ -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); } } |
