diff options
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/TwoHeadArena.c | 117 | ||||
| -rw-r--r-- | src/code/TwoHeadGfxArena.c | 102 | ||||
| -rw-r--r-- | src/code/game.c | 16 | ||||
| -rw-r--r-- | src/code/graph.c | 2 | ||||
| -rw-r--r-- | src/code/sched.c | 1 | ||||
| -rw-r--r-- | src/code/sys_matrix.c | 2 | ||||
| -rw-r--r-- | src/code/z_bgcheck.c | 14 | ||||
| -rw-r--r-- | src/code/z_debug_mode.c | 2 | ||||
| -rw-r--r-- | src/code/z_effect_soft_sprite.c | 2 | ||||
| -rw-r--r-- | src/code/z_kaleido_manager.c | 2 | ||||
| -rw-r--r-- | src/code/z_map_exp.c | 2 | ||||
| -rw-r--r-- | src/code/z_message.c | 2 | ||||
| -rw-r--r-- | src/code/z_parameter.c | 6 | ||||
| -rw-r--r-- | src/code/z_play.c | 8 | ||||
| -rw-r--r-- | src/code/z_room.c | 2 | ||||
| -rw-r--r-- | src/code/z_scene.c | 4 | ||||
| -rw-r--r-- | src/code/z_sram_NES.c | 2 | ||||
| -rw-r--r-- | src/code/z_vr_box.c | 6 |
18 files changed, 194 insertions, 98 deletions
diff --git a/src/code/TwoHeadArena.c b/src/code/TwoHeadArena.c index 83d5be3d1..a476c3d74 100644 --- a/src/code/TwoHeadArena.c +++ b/src/code/TwoHeadArena.c @@ -1,79 +1,136 @@ -#include "global.h" +/** + * @file TwoHeadArena.c + * + * This file implements a simple general purpose double-ended stack allocator. + * + * A double-ended stack allocator accepts allocations at either the "head" or "tail" of its allotted memory region. + * While in general this type of allocator could accept deallocations on the most recently allocated block at either + * end, this implementation does not support any individual deallocations; the only provided way to deallocate anything + * is to reset the entire arena, deallocating everything. This scheme is most applicable to allocating similar data + * with identical lifetime. + */ + +#include "tha.h" +#include "alignment.h" +#include "functions.h" void* THA_GetHead(TwoHeadArena* tha) { return tha->head; } -void THA_SetHead(TwoHeadArena* tha, void* start) { - tha->head = start; +void THA_SetHead(TwoHeadArena* tha, void* newHead) { + tha->head = newHead; } void* THA_GetTail(TwoHeadArena* tha) { return tha->tail; } -void* THA_AllocStart(TwoHeadArena* tha, size_t size) { +/** + * Allocates to the head of the Two Head Arena. The allocation will not have any alignment guarantees. + */ +void* THA_AllocHead(TwoHeadArena* tha, size_t size) { void* start = tha->head; - tha->head = (u32)tha->head + size; + tha->head = (u8*)tha->head + size; return start; } -void* THA_AllocStart1(TwoHeadArena* tha) { - return THA_AllocStart(tha, 1); +void* THA_AllocHeadByte(TwoHeadArena* tha) { + return THA_AllocHead(tha, 1); } -void* THA_AllocEnd(TwoHeadArena* tha, size_t size) { - u32 mask; +/** + * Allocates to the tail end of the Two Head Arena. The allocation will be aligned based on the size of the allocation. + * All allocations of 16 bytes or more will be aligned to 16-bytes. Otherwise, the alignment will be the largest power + * of 2 for which the size is a multiple, in order to accommodate the alignment requirements of any data types that can + * fit within the allocation. + */ +void* THA_AllocTail(TwoHeadArena* tha, size_t size) { + uintptr_t mask; if (size >= 0x10) { - mask = ~0xF; + // Align 0x10 for allocations greater than 0x10 + mask = ALIGN_MASK(0x10); } else if (size & 1) { - mask = -1; + // No alignment for odd sizes + mask = ALIGN_MASK(1); } else if (size & 2) { - mask = ~0x1; + // Align 2 for multiples of 2 + mask = ALIGN_MASK(2); } else if (size & 4) { - mask = ~0x3; + // Align 4 for multiples of 4 + mask = ALIGN_MASK(4); + } else if (size & 8) { + // Align 8 for multiples of 8 + mask = ALIGN_MASK(8); } else { - mask = (size & 8) ? ~0x7 : -1; + mask = ALIGN_MASK(1); } - tha->tail = (((u32)tha->tail & mask) - size) & mask; + tha->tail = (void*)((((uintptr_t)tha->tail & mask) - size) & mask); return tha->tail; } -void* THA_AllocEndAlign16(TwoHeadArena* tha, size_t size) { - u32 mask = ~0xF; +/** + * Allocates to the tail end of the Two Head Arena with guaranteed 16-byte alignment. + */ +void* THA_AllocTailAlign16(TwoHeadArena* tha, size_t size) { + uintptr_t mask = ALIGN_MASK(0x10); - tha->tail = (((u32)tha->tail & mask) - size) & mask; + tha->tail = (void*)((((uintptr_t)tha->tail & mask) - size) & mask); return tha->tail; } -void* THA_AllocEndAlign(TwoHeadArena* tha, size_t size, u32 mask) { - tha->tail = (((u32)tha->tail & mask) - size) & mask; +/** + * Allocates to the tail end of the Two Head Arena using the provided mask to align the allocated region. + * + * @param tha Arena to allocate to + * @param size Size of the allocation + * @param mask Mask to use to align the allocated region. To align to n-bytes where n is a power of 2, use the + * ALIGN_MASK(n) macro + * + * @return Pointer to the start of the allocated block + */ +void* THA_AllocTailAlign(TwoHeadArena* tha, size_t size, uintptr_t mask) { + tha->tail = (void*)((((uintptr_t)tha->tail & mask) - size) & mask); return tha->tail; } -s32 THA_GetSize(TwoHeadArena* tha) { - return (u32)tha->tail - (u32)tha->head; +/** + * Gets the remaining size of the Two Head Arena + * + * @return Remaining size. A negative number indicates an overflow. + */ +s32 THA_GetRemaining(TwoHeadArena* tha) { + return (s32)((u8*)tha->tail - (u8*)tha->head); } +/** + * @return true if the Two Head Arena has overflowed, false otherwise + */ u32 THA_IsCrash(TwoHeadArena* tha) { - return THA_GetSize(tha) < 0; + return THA_GetRemaining(tha) < 0; } -void THA_Init(TwoHeadArena* tha) { - tha->head = tha->bufp; - tha->tail = (u32)tha->bufp + tha->size; +void THA_Reset(TwoHeadArena* tha) { + tha->head = tha->start; + tha->tail = (u8*)tha->start + tha->size; } -void THA_Ct(TwoHeadArena* tha, void* ptr, size_t size) { +/** + * Creates a new Two Head Arena at `start` with available size `size` + */ +void THA_Init(TwoHeadArena* tha, void* start, size_t size) { bzero(tha, sizeof(TwoHeadArena)); - tha->bufp = ptr; + tha->start = start; tha->size = size; - THA_Init(tha); + THA_Reset(tha); } -void THA_Dt(TwoHeadArena* tha) { +/** + * Destroys the Two Head Arena, no further allocations are possible + */ +void THA_Destroy(TwoHeadArena* tha) { bzero(tha, sizeof(TwoHeadArena)); } diff --git a/src/code/TwoHeadGfxArena.c b/src/code/TwoHeadGfxArena.c index 2f1629765..d40512efd 100644 --- a/src/code/TwoHeadGfxArena.c +++ b/src/code/TwoHeadGfxArena.c @@ -1,65 +1,105 @@ -#include "global.h" +/** + * @file TwoHeadGfxArena.c + * + * This file implements a particular use of the double-ended stack allocator from TwoHeadArena.c for graphics data. + * + * Display list commands are allocated from the head while other graphics data such as matrices and vertices are + * allocated from the tail end. + * + * @see TwoHeadArena.c + */ -void THGA_Ct(TwoHeadGfxArena* thga, Gfx* start, size_t size) { - THA_Ct((TwoHeadArena*)thga, start, size); +#include "thga.h" +#include "alignment.h" +#include "functions.h" + +void THGA_Init(TwoHeadGfxArena* thga, void* start, size_t size) { + THA_Init(&thga->tha, start, size); } -void THGA_Dt(TwoHeadGfxArena* thga) { - THA_Dt((TwoHeadArena*)thga); +void THGA_Destroy(TwoHeadGfxArena* thga) { + THA_Destroy(&thga->tha); } u32 THGA_IsCrash(TwoHeadGfxArena* thga) { - return THA_IsCrash((TwoHeadArena*)thga); + return THA_IsCrash(&thga->tha); } -void THGA_Init(TwoHeadGfxArena* thga) { - THA_Init((TwoHeadArena*)thga); +void THGA_Reset(TwoHeadGfxArena* thga) { + THA_Reset(&thga->tha); } -s32 THGA_GetSize(TwoHeadGfxArena* thga) { - return THA_GetSize((TwoHeadArena*)thga); +s32 THGA_GetRemaining(TwoHeadGfxArena* thga) { + return THA_GetRemaining(&thga->tha); } Gfx* THGA_GetHead(TwoHeadGfxArena* thga) { - return THA_GetHead((TwoHeadArena*)thga); + return THA_GetHead(&thga->tha); } -void THGA_SetHead(TwoHeadGfxArena* thga, Gfx* start) { - THA_SetHead((TwoHeadArena*)thga, start); +void THGA_SetHead(TwoHeadGfxArena* thga, Gfx* newHead) { + THA_SetHead(&thga->tha, newHead); } -Gfx* THGA_GetTail(TwoHeadGfxArena* thga) { - return THA_GetTail((TwoHeadArena*)thga); +void* THGA_GetTail(TwoHeadGfxArena* thga) { + return THA_GetTail(&thga->tha); } -Gfx* THGA_AllocStartArray8(TwoHeadGfxArena* thga, u32 count) { - return THA_AllocStart((TwoHeadArena*)thga, count * 8); +/** + * Allocates a display list of `num` Gfx commands to the head of the Two Head Gfx Arena. + */ +Gfx* THGA_AllocDisplayList(TwoHeadGfxArena* thga, size_t num) { + return THA_AllocHead(&thga->tha, num * sizeof(Gfx)); } -Gfx* THGA_AllocStart8(TwoHeadGfxArena* thga) { - return THGA_AllocStartArray8(thga, 1); +/** + * Allocates a single Gfx command to the head of the Two Head Gfx Arena. + */ +Gfx* THGA_AllocGfx(TwoHeadGfxArena* thga) { + return THGA_AllocDisplayList(thga, 1); } -Gfx* THGA_AllocStart8Wrapper(TwoHeadGfxArena* thga) { - return THGA_AllocStart8(thga); +/** + * Identical to `THGA_AllocGfx` + * + * @see THGA_AllocGfx + */ +Gfx* THGA_AllocGfx2(TwoHeadGfxArena* thga) { + return THGA_AllocGfx(thga); } -Gfx* THGA_AllocEnd(TwoHeadGfxArena* thga, size_t size) { - return THA_AllocEnd((TwoHeadArena*)thga, size); +/** + * Allocates to the end of the Two Head Gfx Arena. Intended for data complementary to the display lists such as + * matrices and vertices that are only needed for a single graphics task. + */ +void* THGA_AllocTail(TwoHeadGfxArena* thga, size_t size) { + return THA_AllocTail(&thga->tha, size); } -Gfx* THGA_AllocEndArray64(TwoHeadGfxArena* thga, u32 count) { - return THGA_AllocEnd(thga, count * 0x40); +/** + * Allocates `num` matrices to the tail end of the Two Head Gfx Arena. + */ +Mtx* THGA_AllocMtxArray(TwoHeadGfxArena* thga, size_t num) { + return THGA_AllocTail(thga, num * sizeof(Mtx)); } -Gfx* THGA_AllocEnd64(TwoHeadGfxArena* thga) { - return THGA_AllocEnd(thga, 0x40); +/** + * Allocates a matrix to the tail end of the Two Head Gfx Arena. + */ +Mtx* THGA_AllocMtx(TwoHeadGfxArena* thga) { + return THGA_AllocTail(thga, sizeof(Mtx)); } -Gfx* THGA_AllocEndArray16(TwoHeadGfxArena* thga, u32 count) { - return THGA_AllocEnd(thga, count * 0x10); +/** + * Allocates `num` vertices to the tail end of the Two Head Gfx Arena. + */ +Vtx* THGA_AllocVtxArray(TwoHeadGfxArena* thga, u32 num) { + return THGA_AllocTail(thga, num * sizeof(Vtx)); } -Gfx* THGA_AllocEnd16(TwoHeadGfxArena* thga) { - return THGA_AllocEnd(thga, 0x10); +/** + * Allocates a vertex to the tail end of the Two Head Gfx Arena. + */ +Vtx* THGA_AllocVtx(TwoHeadGfxArena* thga) { + return THGA_AllocTail(thga, sizeof(Vtx)); } diff --git a/src/code/game.c b/src/code/game.c index f3c381e68..4a4be5291 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -158,11 +158,11 @@ void GameState_InitArena(GameState* gameState, size_t size) { void* buf = GameAlloc_Malloc(alloc, size); if (buf) { - THA_Ct(&gameState->heap, buf, size); + THA_Init(&gameState->heap, buf, size); return; } - THA_Ct(&gameState->heap, NULL, 0); + THA_Init(&gameState->heap, NULL, 0); __assert("../game.c", 1035); } @@ -174,9 +174,9 @@ void GameState_Realloc(GameState* gameState, size_t size) { size_t bytesAllocated; void* heapStart; - heapStart = gameState->heap.bufp; + heapStart = gameState->heap.start; alloc = &gameState->alloc; - THA_Dt(&gameState->heap); + THA_Destroy(&gameState->heap); GameAlloc_Free(alloc, heapStart); SystemArena_GetSizes(&systemMaxFree, &bytesFree, &bytesAllocated); size = ((systemMaxFree - (sizeof(ArenaNode))) < size) ? (0) : (size); @@ -185,9 +185,9 @@ void GameState_Realloc(GameState* gameState, size_t size) { } if ((gameArena = GameAlloc_Malloc(alloc, size)) != NULL) { - THA_Ct(&gameState->heap, gameArena, size); + THA_Init(&gameState->heap, gameArena, size); } else { - THA_Ct(&gameState->heap, 0, 0); + THA_Init(&gameState->heap, 0, 0); __assert("../game.c", 1074); } } @@ -240,7 +240,7 @@ void GameState_Destroy(GameState* gameState) { func_801420F4(&D_801F8020); VisMono_Destroy(&sMonoColors); func_80140900(&D_801F8048); - THA_Dt(&gameState->heap); + THA_Destroy(&gameState->heap); GameAlloc_Cleanup(&gameState->alloc); } @@ -257,7 +257,7 @@ u32 GameState_IsRunning(GameState* gameState) { } s32 GameState_GetArenaSize(GameState* gameState) { - return THA_GetSize(&gameState->heap); + return THA_GetRemaining(&gameState->heap); } s32 func_80173B48(GameState* gameState) { diff --git a/src/code/graph.c b/src/code/graph.c index 6cc8d7772..558f7d563 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -26,7 +26,7 @@ void Graph_FaultClient(void) { } void Graph_InitTHGA(TwoHeadGfxArena* arena, Gfx* buffer, s32 size) { - THGA_Ct(arena, buffer, size); + THGA_Init(arena, buffer, size); } void Graph_SetNextGfxPool(GraphicsContext* gfxCtx) { diff --git a/src/code/sched.c b/src/code/sched.c index 5f9cdf236..927a48f66 100644 --- a/src/code/sched.c +++ b/src/code/sched.c @@ -1,4 +1,3 @@ -#include "prevent_bss_reordering.h" #include "global.h" #define RSP_DONE_MSG 667 diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index f2ed19c38..63857676e 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -74,7 +74,7 @@ MtxF* sCurrentMatrix; //!< original name: "Matrix_now" * @remark original name: "new_Matrix" */ void Matrix_Init(GameState* gameState) { - sMatrixStack = THA_AllocEndAlign16(&gameState->heap, MATRIX_STACK_SIZE * sizeof(MtxF)); + sMatrixStack = THA_AllocTailAlign16(&gameState->heap, MATRIX_STACK_SIZE * sizeof(MtxF)); sCurrentMatrix = sMatrixStack; } diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 6d4414c38..c04fce680 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -140,7 +140,7 @@ void DynaSSNodeList_Init(PlayState* play, DynaSSNodeList* list) { } void DynaSSNodeList_Alloc(PlayState* play, DynaSSNodeList* list, u32 numNodes) { - list->tbl = (SSNode*)THA_AllocEndAlign(&play->state.heap, numNodes * sizeof(SSNode), -2); + list->tbl = (SSNode*)THA_AllocTailAlign(&play->state.heap, numNodes * sizeof(SSNode), -2); list->maxNodes = numNodes; list->count = 0; } @@ -1591,7 +1591,7 @@ void BgCheck_Allocate(CollisionContext* colCtx, PlayState* play, CollisionHeader colCtx->subdivAmount.z = 16; } } - colCtx->lookupTbl = THA_AllocEndAlign( + colCtx->lookupTbl = THA_AllocTailAlign( &play->state.heap, colCtx->subdivAmount.x * sizeof(StaticLookup) * colCtx->subdivAmount.y * colCtx->subdivAmount.z, ~1); if (colCtx->lookupTbl == NULL) { @@ -2478,8 +2478,8 @@ void SSNodeList_Init(SSNodeList* this) { void SSNodeList_Alloc(PlayState* play, SSNodeList* this, s32 tblMax, s32 numPolys) { this->max = tblMax; this->count = 0; - this->tbl = THA_AllocEndAlign(&play->state.heap, tblMax * sizeof(SSNode), -2); - this->polyCheckTbl = THA_AllocEndAlign16(&play->state.heap, numPolys * sizeof(u8)); + this->tbl = THA_AllocTailAlign(&play->state.heap, tblMax * sizeof(SSNode), -2); + this->polyCheckTbl = THA_AllocTailAlign16(&play->state.heap, numPolys * sizeof(u8)); if (this->polyCheckTbl == NULL) { sprintf(D_801ED950, "this->polygon_check == NULL(game_alloc() MemoryAllocationError.)\n"); @@ -2621,7 +2621,7 @@ void DynaPoly_NullPolyList(CollisionPoly** polyList) { * Allocate dyna.polyList */ void DynaPoly_AllocPolyList(PlayState* play, CollisionPoly** polyList, s32 numPolys) { - *polyList = THA_AllocEndAlign(&play->state.heap, numPolys * sizeof(CollisionPoly), -2); + *polyList = THA_AllocTailAlign(&play->state.heap, numPolys * sizeof(CollisionPoly), -2); } /** @@ -2635,7 +2635,7 @@ void DynaPoly_NullVtxList(Vec3s** vtxList) { * Allocate dyna.vtxList */ void DynaPoly_AllocVtxList(PlayState* play, Vec3s** vtxList, s32 numVtx) { - *vtxList = THA_AllocEndAlign(&play->state.heap, numVtx * sizeof(Vec3s), -2); + *vtxList = THA_AllocTailAlign(&play->state.heap, numVtx * sizeof(Vec3s), -2); } /** @@ -2650,7 +2650,7 @@ void DynaPoly_InitWaterBoxList(DynaWaterBoxList* waterBoxList) { * Allocate dyna.waterBoxList */ void DynaPoly_AllocWaterBoxList(PlayState* play, DynaWaterBoxList* waterBoxList, s32 numWaterBoxes) { - waterBoxList->boxes = THA_AllocEndAlign(&play->state.heap, numWaterBoxes * sizeof(WaterBox), -2); + waterBoxList->boxes = THA_AllocTailAlign(&play->state.heap, numWaterBoxes * sizeof(WaterBox), -2); } /** diff --git a/src/code/z_debug_mode.c b/src/code/z_debug_mode.c index a1b464463..a40bd29bd 100644 --- a/src/code/z_debug_mode.c +++ b/src/code/z_debug_mode.c @@ -128,7 +128,7 @@ void Debug_DrawText(GraphicsContext* gfxCtx) { Gfx* gfxHead; GfxPrint printer; - if (THGA_GetSize(&gfxCtx->polyOpa) >= 0x2800) { + if (THGA_GetRemaining(&gfxCtx->polyOpa) >= 0x2800) { GfxPrint_Init(&printer); OPEN_DISPS(gfxCtx); diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c index ea8a546d6..775b68f01 100644 --- a/src/code/z_effect_soft_sprite.c +++ b/src/code/z_effect_soft_sprite.c @@ -8,7 +8,7 @@ void EffectSS_Init(PlayState* play, s32 numEntries) { EffectSs* effectsSs; EffectSsOverlay* overlay; - sEffectSsInfo.data_table = (EffectSs*)THA_AllocEndAlign16(&play->state.heap, numEntries * sizeof(EffectSs)); + sEffectSsInfo.data_table = (EffectSs*)THA_AllocTailAlign16(&play->state.heap, numEntries * sizeof(EffectSs)); sEffectSsInfo.searchIndex = 0; sEffectSsInfo.size = numEntries; diff --git a/src/code/z_kaleido_manager.c b/src/code/z_kaleido_manager.c index 3771de9c0..0d9f30a08 100644 --- a/src/code/z_kaleido_manager.c +++ b/src/code/z_kaleido_manager.c @@ -65,7 +65,7 @@ void KaleidoManager_Init(PlayState* play) { } } - sKaleidoAreaPtr = THA_AllocEndAlign16(&play->state.heap, largestSize); + sKaleidoAreaPtr = THA_AllocTailAlign16(&play->state.heap, largestSize); gKaleidoMgrCurOvl = NULL; Fault_AddAddrConvClient(&sKaleidoMgrFaultAddrConvClient, KaleidoManager_FaultAddrConv, NULL); } diff --git a/src/code/z_map_exp.c b/src/code/z_map_exp.c index ac78d1229..381387c5e 100644 --- a/src/code/z_map_exp.c +++ b/src/code/z_map_exp.c @@ -180,7 +180,7 @@ void Map_Init(PlayState* play) { func_80105C40(play->roomCtx.curRoom.num); interfaceCtx->unk_278 = -1; interfaceCtx->dungeonOrBossAreaMapIndex = -1; - interfaceCtx->mapSegment = THA_AllocEndAlign16(&play->state.heap, 0x1000); + interfaceCtx->mapSegment = THA_AllocTailAlign16(&play->state.heap, 0x1000); if (func_8010A2AC(play)) { gSaveContext.mapIndex = func_8010A238(play); return; diff --git a/src/code/z_message.c b/src/code/z_message.c index cc1e0c876..01e4a366d 100644 --- a/src/code/z_message.c +++ b/src/code/z_message.c @@ -572,7 +572,7 @@ void Message_Init(PlayState* play) { messageCtx->ocarinaAction = messageCtx->unk11FF2 = 0; messageCtx->unk1201E = 0xFF; View_Init(&messageCtx->view, play->state.gfxCtx); - messageCtx->unk11EF8 = THA_AllocEndAlign16(&play->state.heap, 0x13C00); + messageCtx->unk11EF8 = THA_AllocTailAlign16(&play->state.heap, 0x13C00); font = &play->msgCtx.font; Font_LoadOrderedFont(&play->msgCtx.font); font->unk_11D88 = 0; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index ca127a8b6..5f5440a2f 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -6006,16 +6006,16 @@ void Interface_Init(PlayState* play) { interfaceCtx->healthTimer = 200; parameterStaticSize = SEGMENT_ROM_SIZE(parameter_static); - interfaceCtx->parameterSegment = THA_AllocEndAlign16(&play->state.heap, parameterStaticSize); + interfaceCtx->parameterSegment = THA_AllocTailAlign16(&play->state.heap, parameterStaticSize); DmaMgr_SendRequest0(interfaceCtx->parameterSegment, SEGMENT_ROM_START(parameter_static), parameterStaticSize); - interfaceCtx->doActionSegment = THA_AllocEndAlign16(&play->state.heap, 0xC90); + interfaceCtx->doActionSegment = THA_AllocTailAlign16(&play->state.heap, 0xC90); DmaMgr_SendRequest0(interfaceCtx->doActionSegment, SEGMENT_ROM_START(do_action_static), 0x300); DmaMgr_SendRequest0(interfaceCtx->doActionSegment + 0x300, SEGMENT_ROM_START(do_action_static) + 0x480, 0x180); Interface_NewDay(play, CURRENT_DAY); - interfaceCtx->iconItemSegment = THA_AllocEndAlign16(&play->state.heap, 0x4000); + interfaceCtx->iconItemSegment = THA_AllocTailAlign16(&play->state.heap, 0x4000); if (CUR_FORM_EQUIP(EQUIP_SLOT_B) < ITEM_F0) { Interface_LoadItemIconImpl(play, EQUIP_SLOT_B); diff --git a/src/code/z_play.c b/src/code/z_play.c index 5f8c197f2..52146a121 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -1545,7 +1545,7 @@ void Play_GetFloorSurface(PlayState* this, MtxF* mtx, Vec3f* pos) { void* Play_LoadFile(PlayState* this, RomFile* entry) { size_t size = entry->vromEnd - entry->vromStart; - void* allocp = THA_AllocEndAlign16(&this->state.heap, size); + void* allocp = THA_AllocTailAlign16(&this->state.heap, size); DmaMgr_SendRequest0(allocp, entry->vromStart, size); @@ -2295,9 +2295,9 @@ void Play_Init(GameState* thisx) { D_801F6D4C->envColor.b = 0; D_801F6D4C->envColor.a = 0; EnvFlags_UnsetAll(this); - THA_GetSize(&this->state.heap); - zAllocSize = THA_GetSize(&this->state.heap); - zAlloc = (uintptr_t)THA_AllocEndAlign16(&this->state.heap, zAllocSize); + THA_GetRemaining(&this->state.heap); + zAllocSize = THA_GetRemaining(&this->state.heap); + zAlloc = (uintptr_t)THA_AllocTailAlign16(&this->state.heap, zAllocSize); ZeldaArena_Init(((zAlloc + 8) & ~0xF), (zAllocSize - ((zAlloc + 8) & ~0xF)) + zAlloc); //! @bug: Incorrect ALIGN16s Actor_InitContext(this, &this->actorCtx, this->linkActorEntry); diff --git a/src/code/z_room.c b/src/code/z_room.c index 3358bb300..369b2b0e5 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -530,7 +530,7 @@ size_t Room_AllocateAndLoad(PlayState* play, RoomContext* roomCtx) { } } - roomCtx->roomMemPages[0] = THA_AllocEndAlign16(&play->state.heap, maxRoomSize); + roomCtx->roomMemPages[0] = THA_AllocTailAlign16(&play->state.heap, maxRoomSize); if (roomCtx->roomMemPages[0] == NULL) { __assert("../z_room.c", 1078); } diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 13d93c515..1db125af2 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -48,7 +48,7 @@ void Object_InitBank(GameState* gameState, ObjectContext* objectCtx) { for (i = 0; i < OBJECT_EXCHANGE_BANK_MAX; i++) { objectCtx->status[i].id = 0; } // clang-format on - objectCtx->spaceStart = objectCtx->status[0].segment = THA_AllocEndAlign16(&gameState->heap, spaceSize); + objectCtx->spaceStart = objectCtx->status[0].segment = THA_AllocTailAlign16(&gameState->heap, spaceSize); objectCtx->spaceEnd = (void*)((u32)objectCtx->spaceStart + spaceSize); objectCtx->mainKeepIndex = Object_Spawn(objectCtx, GAMEPLAY_KEEP); @@ -357,7 +357,7 @@ void Scene_LoadAreaTextures(PlayState* play, s32 fileIndex) { size_t size = sceneTextureFiles[fileIndex].vromEnd - vromStart; if (size != 0) { - play->roomCtx.unk74 = THA_AllocEndAlign16(&play->state.heap, size); + play->roomCtx.unk74 = THA_AllocTailAlign16(&play->state.heap, size); DmaMgr_SendRequest0(play->roomCtx.unk74, vromStart, size); } } diff --git a/src/code/z_sram_NES.c b/src/code/z_sram_NES.c index 67f8bdda6..c32a76d76 100644 --- a/src/code/z_sram_NES.c +++ b/src/code/z_sram_NES.c @@ -1600,7 +1600,7 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) { void Sram_Alloc(GameState* gameState, SramContext* sramCtx) { if (gSaveContext.unk_3F3F) { - sramCtx->saveBuf = THA_AllocEndAlign16(&gameState->heap, SAVE_BUFFER_SIZE); + sramCtx->saveBuf = THA_AllocTailAlign16(&gameState->heap, SAVE_BUFFER_SIZE); sramCtx->status = 0; } } diff --git a/src/code/z_vr_box.c b/src/code/z_vr_box.c index 4d44de0f9..911e3e757 100644 --- a/src/code/z_vr_box.c +++ b/src/code/z_vr_box.c @@ -294,15 +294,15 @@ void Skybox_Init(GameState* gameState, SkyboxContext* skyboxCtx, s16 skyboxId) { Skybox_Setup(gameState, skyboxCtx, skyboxId); if (skyboxId != SKYBOX_NONE) { - skyboxCtx->dListBuf = THA_AllocEndAlign16(&gameState->heap, 0x3840); + skyboxCtx->dListBuf = THA_AllocTailAlign16(&gameState->heap, 0x3840); if (skyboxId == SKYBOX_CUTSCENE_MAP) { // Allocate enough space for the vertices for a 6 sided skybox (cube) - skyboxCtx->roomVtx = THA_AllocEndAlign16(&gameState->heap, sizeof(Vtx) * 32 * 6); + skyboxCtx->roomVtx = THA_AllocTailAlign16(&gameState->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 = THA_AllocEndAlign16(&gameState->heap, sizeof(Vtx) * 32 * 5); + skyboxCtx->roomVtx = THA_AllocTailAlign16(&gameState->heap, sizeof(Vtx) * 32 * 5); func_80143148(skyboxCtx, 5); } } |
