Alchemy
Loading...
Searching...
No Matches

heap.c File Reference

The heap: its two bump allocators and named slots. More...

Go to the source code of this file.

Functions

void Runtime_InitializeHeap (void)
 Empties the heap: clears the 64 words of gWorkSlot (both pool pointers and every named slot) and sets the pools' next addresses to gIwramHeap and gEwramHeap.
s32 Runtime_GetRemainingIwram (void)
 Returns the IWRAM bytes left to allocate, up to gCartridgeResetMarker (0x03007800), the same end the allocators test.
s32 Runtime_GetRemainingEwram (void)
 Returns the EWRAM bytes left to allocate, up to the end of EWRAM.
void * Runtime_AllocateHeapBlock (s32 kind, s32 size)
 Returns heap slot kind's block, first allocating size bytes for it (rounded up to words), from IWRAM when they fit and EWRAM otherwise.
void * Runtime_AllocateBlock (s32 kind, s32 size)
 As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the battle, shop and save work, among others.
void * MemAlloc (s32 size)
 Allocates size bytes (rounded up to words) with no slot, from IWRAM when they fit and EWRAM otherwise, and advances that pool's next address.
void * Runtime_BumpAllocateAlternatePool (s32 size)
 As MemAlloc, but tries EWRAM first.
UNUSED void RuntimeMemory_ReservedNoOp (void)
 Reserved empty memory export; its historical purpose is not established.

Detailed Description

The heap: its two bump allocators and named slots.

Part of runtime.c, the runtime object, compiled only through it.

Definition in file heap.c.

Function Documentation

◆ Runtime_InitializeHeap()

void Runtime_InitializeHeap ( void )

Empties the heap: clears the 64 words of gWorkSlot (both pool pointers and every named slot) and sets the pools' next addresses to gIwramHeap and gEwramHeap.

Called by System_Initialize, by Game_ResetForNewGame and by the debug modes that start over, so every earlier block is forgotten.

Definition at line 15 of file heap.c.

Referenced by DebugBattle_RunMenu(), Game_ResetForNewGame(), memcpy(), Runtime_InitializeHeap(), System_Initialize(), and Ui_RunIconMonitor().

◆ Runtime_GetRemainingIwram()

s32 Runtime_GetRemainingIwram ( void )

Returns the IWRAM bytes left to allocate, up to gCartridgeResetMarker (0x03007800), the same end the allocators test.

Battle_RunEncounter calls it around each action and ignores the result.

Definition at line 26 of file heap.c.

Referenced by Battle_RunEncounter(), memcpy(), and Runtime_GetRemainingIwram().

◆ Runtime_GetRemainingEwram()

s32 Runtime_GetRemainingEwram ( void )

Returns the EWRAM bytes left to allocate, up to the end of EWRAM.

Battle_RunEncounter calls it around each action and ignores the result.

Definition at line 34 of file heap.c.

Referenced by Battle_RunEncounter(), memcpy(), and Runtime_GetRemainingEwram().

◆ Runtime_AllocateHeapBlock()

void * Runtime_AllocateHeapBlock ( s32 kind,
s32 size )

Returns heap slot kind's block, first allocating size bytes for it (rounded up to words), from IWRAM when they fit and EWRAM otherwise.

A new block advances that pool's next address and is stored in the slot, so later calls with the same kind return it until Runtime_ReleaseHeapBlock frees it. Returns NULL when neither pool has room. Called throughout the game for long-lived work blocks, and by WaitFrames for each frame's OAM list.

Definition at line 47 of file heap.c.

Referenced by BattleFx_BuildBlitter(), BattleFx_DispatchByIdRange(), BattleFx_InitializeSlots(), BattleFx_InitializeStarField(), BattleFx_LoadActionEffectResources(), BattleFx_RunElementBurst(), BattleFx_RunElementPillar(), BattleFx_RunSceneEffect(), BattleFx_RunShatteringOpening(), BattleFx_RunTableEffect(), BattleFx_StartEffectObject22(), BattleFx_StartElementStreaks(), BattleFx_StartFadeOverlay(), BattleFx_StartRandomParticleEmitter(), BattlePres_RunEntryTransition(), Colosso_ShowItemIcon(), DjinnMenu_Run(), ItemMenu_Run(), LuckyDice_Run(), Map_InitializePerspectiveScene(), Map_WriteLayerCellTile(), memcpy(), Menu_OpenCharacterSelector(), ObjectSystem_Configure(), PsynergyMenu_Run(), ReelGame_Run(), Resource_LoadIndexedIntoBuffer(), Runtime_AllocateHeapBlock(), Sanctum_RaiseItemIcon(), SaveMenu_SelectSlot(), SelectionScreen_LoadLargeIcon(), Shop_InitializeCursorWork(), Sprite_ComposeAnimationFrame(), StatusMenu_Run(), Title_ShowIntro(), Ui_BuildPairedPatternsToSlot(), Ui_BuildPatternToSlot(), UiGlyph_LoadEntryWithPalette(), UiIcon_BuildAbilityIconTiles(), UiIcon_BuildItemIconTiles(), UiIcon_CopyResourceToSlot(), UiText_BuildRenderEntries(), UiText_LoadRemappedGlyph(), and WaitFrames().

◆ Runtime_AllocateBlock()

void * Runtime_AllocateBlock ( s32 kind,
s32 size )

As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the battle, shop and save work, among others.

Definition at line 80 of file heap.c.

Referenced by AffineEffect_InitializeWork(), Battle_CollectPartyCommands(), Battle_RunEncounter(), BattleEffect_InitializeBuffers(), BattleFx_DispatchByIdRange(), BattleFx_InitializeStarField(), BattleFx_RunVisibilityTransition(), BattleFx_ScheduleRatioTransition(), BattleFx_StartBufferBlend(), BattleFx_StartFadeOverlay(), BattlePresentation_InitializeWorkAndResetState(), Camera_FollowActor(), Camera_FollowObject(), Camera_GetEventObject(), Camera_MoveWithinMapBounds(), Camera_SetSpeedParameters(), Camera_WaitForArrival(), Colosso_StartRaceGauge(), ColossoWall_RollLogToCell(), DisplayScroll_InitializeHBlankDma(), DisplayTransition_AllocateAndClearState(), DisplayTransition_InitializeBattleEffectState(), DisplayTransition_InitializeState(), Event_PushPipeworksBlock(), Event_RollLongLog(), Event_WaitForZoomTransition(), Field_RunScene(), FieldEffect_InitSparkles(), FieldFx_LastLightning(), FieldFx_ResumeLightning(), FieldFx_StartGroundParticles(), FieldFx_StartLightning(), FieldFx_StepRatioTransition(), FieldFx_StopLightning(), FieldMotes_Start(), FieldScene_BuildDescriptorAndInstallTask(), ItemIcon_LoadIntoSlot(), ItemMenu_SelectGiveQuantity(), KolimaForestBend_RollLog(), LinkLobby_EnterBattle(), LuckyDice_Run(), Map_InitializePerspectiveScene(), Map_LoadLayeredScene(), Map_ShowWorldMap(), memcpy(), Menu_AllocateSelectionWorkspace(), MercuryLighthouse_RemoveColumnOnRetreat(), MercuryLighthouse_RestoreLights(), Object_PlaceCurrentWithinCameraBounds(), ObjectSystem_Configure(), ObjectSystem_Initialize(), OptionMenu_InitializeWork(), PaletteFade_Init(), PaletteQueue_Initialize(), ReelGame_Run(), Render_ResetTransformState(), RenderResource_LoadFrame(), RenderResource_LoadPair(), Resource_LoadIndexedEntryToBuffer(), Resource_LoadTableEntryToBuffer(), RunSceneTransitionEffect(), Runtime_AllocateBlock(), SaveState_InitializeWorkspace(), Shop_CreatePriceSprite(), Shop_SelectQuantity(), SolSanctum_StartFloatingLights(), SolSanctum_UpdateRing(), SolSanctumStatue_InitializeScrollingSprites(), SystemMenu_Initialize(), Title_ShowIntro(), Ui_RunIconMonitor(), UiGlyph_ResetWorkState(), UiIcon_LoadResourceIntoSlot(), UiWindow_CreateWithLayoutBounds(), UiWork_Initialize(), UiWork_InitializeWithResourceCounters(), WorldMap_BeginEvent(), and WorldMap_EndEvent().

◆ MemAlloc()

void * MemAlloc ( s32 size)

Allocates size bytes (rounded up to words) with no slot, from IWRAM when they fit and EWRAM otherwise, and advances that pool's next address.

Returns NULL when neither has room. Called for short-lived buffers (decode buffers, RAM copies of code), which MemFree rewinds the pool over.

Definition at line 115 of file heap.c.

Referenced by Battle_CollectPartyCommands(), BattleTargetExec(), Debug_SelectAbilityPair(), DjinnMenu_DrawStatPreview(), DjinnMenu_ShowChangePreview(), HeatGauge_Draw(), ItemMenu_ConfirmEquip(), ItemMenu_DrawEquipPreview(), ItemMenu_RunCommands(), Map_LoadLayeredScene(), MemAlloc(), memcpy(), Menu_DrawOwnerStatusPanel(), Menu_LoadResourceSlot(), PsynergyMenu_SelectMember(), RunLuckyDice(), RunReelGame(), Sprite_ComposeAnimationFrame(), StatusMenu_ShowOwnerProgressMessage(), Ui_RunOwnerStatusScreen(), UiText_LoadRemappedGlyph(), UiText_RenderStringTiles(), and WorldMap_LoadGraphics().

◆ Runtime_BumpAllocateAlternatePool()

◆ RuntimeMemory_ReservedNoOp()

UNUSED void RuntimeMemory_ReservedNoOp ( void )

Reserved empty memory export; its historical purpose is not established.

Definition at line 164 of file heap.c.

Referenced by memcpy(), and RuntimeMemory_ReservedNoOp().