Alchemy
Loading...
Searching...
No Matches

frame.c File Reference

Interrupt handlers, the frame wait, key repeat and the VBlank handler. More...

Go to the source code of this file.

Macros

#define VBlankIntrWait()
 Sleeps in the BIOS Halt until the VBlank handler has run once.
#define INPUT_KEY_REPEAT_FIRST   19
 Frames a key is held before it first repeats, and between later repeats.
#define INPUT_KEY_REPEAT_NEXT   6
#define SOUND_PRESET_COUNT   5
#define SOUND_PRESET_SIZE   152

Enumerations

enum  {
  SLEEP_IDLE_FRAMES = 3 * 60 * 60 , SLEEP_COMBO_FRAMES = 3 * 60 , SLEEP_WHITE_FRAMES = 60 , SLEEP_WAKE_FRAMES = 10 ,
  CPU_LOAD_PEAK_FRAMES = 30
}
 Frame counts used by the sleep transitions and the CPU-load peak display. More...

Functions

static __inline__ void System_SoftReset (void)
 Restarts the game from the cartridge entry point.
void Runtime_SetIrqHandler (u32 irq, s32 vcount, InterruptHandler handler)
 Installs handler for interrupt irq and enables that interrupt, or with a null handler disables it and installs the do-nothing handler.
void WaitFrames (s32 frames)
 The game's frame loop: runs frames frames and returns.
void Input_ResetKeyRepeat (void)
 Restarts the key repeat delay, so held keys wait the full delay again.
void Input_UpdateKeyRepeatAndDirection (void)
 Runs once a frame after VBlank, called by WaitFrames.
void System_VBlankHandler (void)
 The VBlank interrupt handler, installed by System_Initialize.
s32 Sound_LoadPresetParameters (s32 preset)
 Copies the mixer code for sound preset preset (0 to 4; anything else is 0) from ROM into IwramSoundPresetCode.
UNUSED void Sound_ReservedNoOpA (void)
 Nothing calls it.
UNUSED void Sound_ReservedNoOpB (void)
 Nothing calls it.
void Input_HandleKeyInterrupt (void)
 The keypad interrupt, from the handler table: A+B+Select+Start was pressed, so it sets gResetRequested for the frame loop and disarms the interrupt.

Detailed Description

Interrupt handlers, the frame wait, key repeat and the VBlank handler.

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

Definition in file frame.c.

Macro Definition Documentation

◆ VBlankIntrWait

#define VBlankIntrWait ( )
Value:
{ \
gVBlankDone &= ~1; \
do { \
CAMELOT_ASM("Halt, which no C compiles to") \
__asm__ volatile("swi 2"); \
} while (!(gVBlankDone & 1)); \
}
volatile u16 gVBlankDone
Bit 0 is set by the VBlank handler; WaitFrames clears it and halts until it is set again.

Sleeps in the BIOS Halt until the VBlank handler has run once.

Definition at line 21 of file frame.c.

Referenced by WaitFrames().

◆ INPUT_KEY_REPEAT_FIRST

#define INPUT_KEY_REPEAT_FIRST   19

Frames a key is held before it first repeats, and between later repeats.

Definition at line 285 of file frame.c.

Referenced by Input_ResetKeyRepeat(), Input_UpdateKeyRepeatAndDirection(), and System_VBlankHandler().

◆ INPUT_KEY_REPEAT_NEXT

#define INPUT_KEY_REPEAT_NEXT   6

Definition at line 286 of file frame.c.

Referenced by Input_UpdateKeyRepeatAndDirection().

◆ SOUND_PRESET_COUNT

#define SOUND_PRESET_COUNT   5

Definition at line 364 of file frame.c.

Referenced by Sound_LoadPresetParameters().

◆ SOUND_PRESET_SIZE

#define SOUND_PRESET_SIZE   152

Definition at line 365 of file frame.c.

Referenced by Sound_LoadPresetParameters().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Frame counts used by the sleep transitions and the CPU-load peak display.

Enumerator
SLEEP_IDLE_FRAMES 
SLEEP_COMBO_FRAMES 
SLEEP_WHITE_FRAMES 
SLEEP_WAKE_FRAMES 
CPU_LOAD_PEAK_FRAMES 

Definition at line 74 of file frame.c.

Function Documentation

◆ System_SoftReset()

__inline__ void System_SoftReset ( void )
static

Restarts the game from the cartridge entry point.

The marker word it leaves in IWRAM is cleared again by System_Initialize; nothing else reads it.

Definition at line 9 of file frame.c.

Referenced by System_SoftReset(), and WaitFrames().

◆ Runtime_SetIrqHandler()

void Runtime_SetIrqHandler ( u32 irq,
s32 vcount,
InterruptHandler handler )

Installs handler for interrupt irq and enables that interrupt, or with a null handler disables it and installs the do-nothing handler.

The three display interrupts are also switched in DISPSTAT; for VCount, vcount is the line it fires on. Writes REG_IE, REG_DISPSTAT and gIrqHandlers with interrupts disabled. Called by System_Initialize, the link cable and save code for their timer and serial interrupts, and the battle transitions for their HBlank and VCount effects.

Definition at line 37 of file frame.c.

Referenced by AltinPeak_DrainFirstWater(), AltinPeak_DrainSecondWater(), AltinPeak_DrainThirdWater(), BattleFx_RunNeptune(), BattlePres_RunEntryTransition(), CrossboneIslePillarRooms_AnimateWaterLevel(), DisplayTransition_Finish(), DisplayTransition_Start(), DisplayTransition_Update(), DisplayTransition_UpdateFromCentre(), Game_ResetForNewGame(), Graphics_InstallBg1VCountHandler(), KolimaForestBend_FlipFloodgateSwitch(), Menu_RunCommandRow(), Runtime_RemoveIrqHandlerSlot2(), Runtime_SetIrqHandler(), SaveState_ReleaseWorkspace(), SerialRuntime_Initialize(), SerialRuntime_RemoveIrqHandlers(), System_GetLanguage(), System_Initialize(), and TretTreeBranch_StartBg3Split().

◆ WaitFrames()

void WaitFrames ( s32 frames)

The game's frame loop: runs frames frames and returns.

Each frame runs the scheduled main-loop tasks, builds the OAM list, measures CPU load for the debug display, counts idle time for sleep, steps the debug pause, waits for VBlank and then reads the keys. Holding L and R for three seconds, or three idle minutes with idle sleep on, puts the system into Stop until L and R are pressed again. A soft reset requested by the keypad interrupt happens here. Called everywhere the game waits: every scene, menu and battle step that lets time pass goes through it.

Code may call WaitFrames deep inside its own call chains, so a caller whose stack has grown below the frame-wait stack top has its stack copied aside into gSavedStack first, and the loop runs at that top; the copy is put back on return. Each frame it allocates and releases the frame scratch heap slot, sets gFrameRenderPending, and counts up gFrameCount and gPlayTimeFrames.

Definition at line 97 of file frame.c.

Referenced by Actor_JumpDownLedge(), Actor_WaitForAnimationEnd(), AudioCommand_WaitForCompletion(), AudioCommand_WaitForStateByteClear(), AudioTest_RunParameterController(), Battle_CollectPartyCommands(), Battle_RunEncounter(), Battle_SelectAbility(), Battle_ShowPairedUnitWorkAndWait(), BattleActor_SpawnObjectsForList(), BattleCommand_BuildPlan(), BattleEffect_CleanupSceneObjects(), BattleEffect_RunFallbackObjectTransition(), BattleEffect_SpawnBurstParticleField(), BattleEscape_PlayRun(), BattleEventRuntime_WaitForReady(), BattleFx_BeginCanvasLayer(), BattleFx_ClearActiveSlotsAndScheduleUpdates(), BattleFx_ConfigureEffectDisplay(), BattleFx_EndCanvasLayer(), BattleFx_HideBg1AndRestoreBackdrop(), BattleFx_OpenCanvasLayer(), BattleFx_PlayCueAndStartEmitterOnTarget(), BattleFx_PlayUnitElementEffect(), BattleFx_RunAnnihilation(), BattleFx_RunAtalanta(), BattleFx_RunBeamSequence(), BattleFx_RunBoreas(), BattleFx_RunBurstScene(), BattleFx_RunDeathPlunge(), BattleFx_RunFlashingStrike(), BattleFx_RunJudgment(), BattleFx_RunKirin(), BattleFx_RunMercuryDjinnCapture(), BattleFx_RunNeptune(), BattleFx_RunNereid(), BattleFx_RunPaletteParticles(), BattleFx_RunParticleStreams(), BattleFx_RunRamses(), BattleFx_RunRingAndSparkScene(), BattleFx_RunShatteringOpening(), BattleFx_RunSparkApproachVariant3(), BattleFx_RunSpiderWeb(), BattleFx_RunThrash(), BattleFx_RunTorch(), BattleFx_RunVenusDjinnCapture(), BattleFx_RunVisibilityTransition(), BattleFx_RunWhirlwind(), BattleFx_SetupBlendedDisplay(), BattleFx_SetupCanvasTileMap(), BattleFx_SpawnItemBreakMode1(), BattleFx_SpawnItemBreakMode3(), BattleFx_StartEffectObject22(), BattleFx_StartRandomParticleEmitter(), BattleFx_SteerLiftedTarget(), BattleFx_SteerPushedTarget(), BattleMenu_RunActionSelection(), BattleMotion_FlashHit(), BattleMotion_SetMode5AndActivateSlot(), BattleMotion_ShowDowned(), BattleMotion_SpawnSlotEffectAndWait(), BattlePres_RunAction(), BattlePres_RunActorEntries(), BattlePres_RunApproachAction(), BattlePres_RunAttack(), BattlePres_RunEntryTransition(), BattlePres_RunEscape(), BattlePres_RunItem(), BattlePres_RunMosaicFadeOut(), BattlePres_RunPlainAttack(), BattlePres_RunUnitAction(), BattlePres_SetActorModes(), BattlePres_SyncTurn(), BattlePres_WaitSync(), BattlePresentation_AppendLinkedActions(), BattlePresentation_DispatchAction(), BattlePresentation_RunPairedUnitTransition(), BattlePresentation_RunUnitTransition(), BattlePresentation_WaitForAdvance(), BattlePresentation_WaitForPromptAt(), BattleTarget_RunSelection(), Camera_FollowActor(), Camera_MoveWithinMapBounds(), CharacterMenu_DrawStatusAilments(), CharacterMenu_SelectCommand(), CharacterMenu_SelectOwner(), CharacterSelector_RunRearrange(), Debug_RunPaletteEditor(), Debug_SelectAbilityPair(), DebugBattle_RunMenu(), DebugBattle_ViewMessages(), DebugMenu_BrowseEntryGlyphs(), DebugMenu_BrowseIcons(), DisplayScroll_RunSlideshow(), DisplayTransition_Finish(), DisplayTransition_InitializeState(), DisplayTransition_Start(), Djinn_ResolvePendingEvent(), Djinn_RunBattleStartHop(), Djinn_RunJupiterJoinEffect(), Djinn_RunMarsJoinEffect(), Djinn_ShowJoinedMessage(), DjinnMenu_Run(), DjinnMenu_RunScreen(), DjinnMenu_SelectDjinn(), DjinnMenu_ShowCurrentList(), DjinnMenu_ShowHelp(), DjinnMenu_ShowOwnerStatus(), EffectRuntime_RunRisingObjectSequence(), EffectRuntime_StopCurrentObject(), Event_AskYesNoWithActorAnimation(), Event_RunObjectHookAndWait(), Event_ShowMessageAtPosition(), Event_ShowSpeakerMessage(), Event_WaitForZoomTransition(), Event_WaitTransitionFrames(), FacingObject_TurnPairToFaceEachOther(), Fade_Wait(), Field_ClimbUp(), Field_RunScene(), Field_SearchTile(), Field_StartEncounterTransition(), Field_TryJumpForward(), FieldEvent_ShowMessageAndWait(), FieldEvent_WaitFrames(), FieldFx_EndCloak(), FieldFx_RunAvoid(), FieldFx_RunCatch(), FieldFx_RunDouse(), FieldFx_RunForce(), FieldFx_RunFrost(), FieldFx_RunGrowth(), FieldFx_RunGrowthOnTarget(), FieldFx_RunLiftOnTarget(), FieldFx_RunMove(), FieldFx_RunPly(), FieldFx_RunRetreat(), FieldFx_RunReveal(), FieldFx_RunWhirlwind(), FieldFx_StartCloak(), FieldObject_WaitForMove(), Graphics_ConvertBackgroundToBlueRamp(), Graphics_FadeAlphaIn(), Graphics_FadeAlphaOut(), Inn_PlaySleep(), InventoryMenu_ShowModalMessage(), ItemDisplay_RaiseAboveLeader(), ItemList_SelectEntry(), ItemMenu_ChooseCommand(), ItemMenu_Close(), ItemMenu_ConfirmDrop(), ItemMenu_ConfirmEquip(), ItemMenu_DrawCategory(), ItemMenu_DrawEquipPage(), ItemMenu_DrawItemDetailPage(), ItemMenu_DrawOwnerStatus(), ItemMenu_Run(), ItemMenu_RunCommands(), ItemMenu_RunList(), ItemMenu_RunOwnerSelection(), ItemMenu_SelectGiveQuantity(), ItemMenu_SelectItem(), ItemMenu_SelectMember(), ItemMenu_SelectTarget(), LinkBattle_ReceiveParty(), LinkBattle_SendParty(), LuckyDice_Run(), Map_LoadAreaGraphics(), Map_LoadDefaultCellsAndUpdateBlock(), Map_PlayMetatileCopySequence(), Map_RenderAllAnimatedTileFrames(), Map_RenderAnimatedTileFramesForObject(), Map_ShowWorldMap(), Map_WaitForShakeToSettle(), Marker_LaunchMimic(), Menu_ConfirmSelection(), Menu_DrawOwnerStatusPanel(), Menu_EndResourceSelection(), Menu_MoveSelectionBackward(), Menu_MoveSelectionForward(), Menu_OpenBackdropScreen(), Menu_OpenCharacterSelector(), Menu_ReleaseSelectionWorkspace(), Menu_ResolveSelectedAction(), Menu_RunCommandRow(), Menu_RunResourceSelectionLoop(), Menu_RunSelection(), Menu_RunSelectionWithCursorObject(), Menu_RunTopSelection(), Menu_RunWorkspaceOptions(), Menu_RunWorkspaceSelectionLoop(), Menu_ScrollSelectionList(), Menu_SelectionLoop(), Menu_SelectQuantity(), Menu_SelectResource(), Menu_SelectResourceLayout(), Menu_StepLeft(), Menu_StepRight(), Menu_WaitForSelectionInput(), NameEntry_EditOwnerName(), ObjectDispatch_WaitForValue16(), ObjectEffect_EndContextEffect(), ObjectEffect_PrepareContextEffect(), ObjectEffect_RunPendingFlagEvent(), ObjectMotion_WaitForAnimationChange(), ObjectSystem_SuspendProjectionAndShowSprites(), OwnerAction_RunCompareLoop(), Party_ShowJoinedMessage(), Party_ShowPairJoinedMessage(), PartyTalkMenu_Choose(), PsynergyMenu_DrawDetailPage(), PsynergyMenu_DrawRangePage(), PsynergyMenu_Run(), PsynergyMenu_RunList(), PsynergyMenu_SelectAction(), PsynergyMenu_SelectMember(), PsynergyMenu_SelectOwner(), PsynergyMenu_SelectPartySlot(), PsynergyMenu_SelectTarget(), ReelGame_Run(), ResetSceneTransitionEffect(), Resource_ResetOwnerEntries(), Runtime_AdjustDebugValueWithButtons(), Runtime_IdleForever(), Sanctum_RunPartyService(), Save_WriteSelectedSlot(), SaveMenu_SelectSlot(), SaveState_ConfirmAndProcessSelectedSlot(), SaveState_DeleteSelectedSlot(), SaveState_InitializeWorkspace(), SelectionScreen_CreateEmpty(), SerialRuntime_WaitForStatusMask(), SerialRuntime_WaitForTransfers(), SerialTest_Run(), SetMarkerAnimationAndPlaySound(), Shop_BuySpecialItem(), Shop_ConfirmEquip(), Shop_DrawMsg(), Shop_PickUnit(), Shop_PickUnitItem(), Shop_RepairItem(), Shop_Run(), Shop_RunPartyMemberIconBurst(), Shop_SelectBuy(), Shop_SelectQuantity(), Shop_SelectRepair(), Shop_SelectSell(), Shop_SelectSellNum(), Shop_SelectUse(), StatusMenu_Run(), SummonMenu_SelectSummon(), System_GetLanguage(), System_Initialize(), Title_ShowAnimatedSplash(), Title_ShowIntro(), Title_ShowSplashScreen(), Ui_RunIconMonitor(), Ui_RunOwnerStatusScreen(), UiMenu_SlideCursor(), UiMessage_ShowAndRestoreState(), UiMessage_ShowAndWait(), UiMessage_ShowResolvedAndRestoreState(), UiMessage_ShowResolvedAndWait(), UiText_OpenMessageAtObject(), UiText_ShowCenteredMessage(), UiText_ShowLocalizedMessageAndWait(), UiText_ShowMessageAndWaitComplete(), UiText_ShowMessageAndWaitCore(), UiText_ShowPositionedMessageAndWait(), UiWindow_Create(), UiWindow_OpenMode1AndWaitFrame(), UiWindow_WaitZoom(), UiWork_DrainPending(), UiWork_FinalizePendingCore(), UpdateRisingParticleBurst(), WaitFrames(), and WorldMap_BeginStillView().

◆ Input_ResetKeyRepeat()

void Input_ResetKeyRepeat ( void )

◆ Input_UpdateKeyRepeatAndDirection()

void Input_UpdateKeyRepeatAndDirection ( void )

Runs once a frame after VBlank, called by WaitFrames.

When the repeat timer has run out, the held keys repeat into gKeysRepeat. gKeysRepeatDirected is the same keys with at most one D-pad direction: of several held directions it keeps the one added last (gKeysDirection remembers it), and with all four it keeps none. Last, the keys newly held since the previous frame go to gKeysPressed, and gKeysHeldLast takes gKeysHeld.

Definition at line 297 of file frame.c.

Referenced by Input_UpdateKeyRepeatAndDirection(), System_GetLanguage(), and WaitFrames().

◆ System_VBlankHandler()

void System_VBlankHandler ( void )

The VBlank interrupt handler, installed by System_Initialize.

It trades the link cable payloads, steps the music fades and the screen fade, and when the frame loop has finished a frame copies its OAM list and BG scroll registers, flushes the queued register writes and clears gFrameRenderPending. Then it runs and clears the one-shot gVBlankHook, runs the VBlank tasks, reads the keypad into gKeysHeld and gKeysPressed, sets gVBlankDone and finally mixes the next sound buffer.

Definition at line 374 of file frame.c.

Referenced by System_GetLanguage(), System_Initialize(), and System_VBlankHandler().

◆ Sound_LoadPresetParameters()

s32 Sound_LoadPresetParameters ( s32 preset)

Copies the mixer code for sound preset preset (0 to 4; anything else is 0) from ROM into IwramSoundPresetCode.

Called by the battle and the link lobby for their music, and by the audio test. Always returns 0.

Definition at line 439 of file frame.c.

Referenced by AudioCommand_Play(), AudioTest_RunParameterController(), Battle_RunEncounter(), LinkLobby_LeaveArena(), LinkLobby_RunRoundResult(), Sound_LoadPresetParameters(), and System_GetLanguage().

◆ Sound_ReservedNoOpA()

UNUSED void Sound_ReservedNoOpA ( void )

Nothing calls it.

Definition at line 452 of file frame.c.

Referenced by Sound_ReservedNoOpA(), and System_GetLanguage().

◆ Sound_ReservedNoOpB()

UNUSED void Sound_ReservedNoOpB ( void )

Nothing calls it.

Definition at line 455 of file frame.c.

Referenced by Sound_ReservedNoOpB(), and System_GetLanguage().

◆ Input_HandleKeyInterrupt()

void Input_HandleKeyInterrupt ( void )

The keypad interrupt, from the handler table: A+B+Select+Start was pressed, so it sets gResetRequested for the frame loop and disarms the interrupt.

During sleep the same interrupt only wakes the CPU.

Definition at line 460 of file frame.c.

Referenced by Input_HandleKeyInterrupt(), and System_GetLanguage().