Skip to Content
The Alchemy Project

src/system/system_frame.c

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

Included by system.c.

Macros

NameDescription
#defineCARTRIDGE_RESET_MARK 0x19670704The word a soft reset leaves in CartridgeResetMarker: a date, 4 July 1967, its digits packed four bits each.
#defineDISPSTAT_FLAGS 0xffDISPSTAT's low byte: its flags and interrupt enables, without the VCount line above them.
#defineVBLANK_LINES (DISPLAY_TOTAL_LINES - DISPLAY_HEIGHT)The lines REG_VCOUNT counts in VBlank, after the DISPLAY_HEIGHT drawn: it runs to DISPLAY_TOTAL_LINES - 1.
#definesyReset (entry)Restarts the cartridge: marks CartridgeResetMarker, stops direct sound and jumps to the cartridge's start with interrupts off.
#defineINPUT_KEY_REPEAT_FIRST 19Ticks a key is held before it first repeats, and between later repeats.
#defineINPUT_KEY_REPEAT_NEXT 6
#defineKEY_WORD_BITS 0xffffEvery bit of a key word, as KEYINPUT's 16 bits.
#defineSOUND_REVERB_CODE_COUNT 5the codes of enum SoundReverbCode

Enumerations

NameDescription
enumanonymous enum { SLEEP_IDLE_TICKS, SLEEP_WHITE_FRAMES, SLEEP_WAKE_FRAMES }Durations of the sleep: the first in ticks, the others in frames, since the sleep waits on syWaitForVBlankInterrupt alone.
enumanonymous enum { CPU_LOAD_PEAK_TICKS }Ticks the debug CPU-load display holds a peak.

Functions

NameDescription
voidsyIntFunction (Uint32 irq, Sint32 vcount, INTERRUPT_HANDLER handler)Installs handler for interrupt irq and enables that interrupt, or with a null handler disables it and installs the do-nothing handler.
voidsyWaitForVBlankInterrupt (void)Waits for the next VBlank; outside the sound test it first runs the music ramps and the sound driver's VBlank update, and mixes this VBlank's sound when the driver is free.
voidsySynch (Sint32 ticks)The game's tick loop: runs ticks ticks and returns.
voidsyInputResetKeyRepeat (void)Restarts the key repeat delay, so held keys wait the full delay again.
voidsyInputUpdateKeyRepeatAndDirection (void)Turns the keys the VBlank handler read into repeats, once a tick after VBlank.
voidsyVBlankHandler (void)The VBlank interrupt handler, installed by syInit.
Sint32sySoundLoadReverbCode (Sint32 code)Where The Broken Seal copies the mixer code for reverb code code (enum SoundReverbCode) into IWRAM, The Lost Age keeps only the range check and returns 0, so its callers (the battle engine, the lobby, the sound test and the debug menu) change nothing.
voidsySoundReservedNoOperationA (void)Empty: nothing calls it or its neighbour.
voidsySoundReservedNoOperationB (void)Empty, as sySoundReservedNoOperationA.
voidsyInputHandleKeyInterrupt (void)The keypad interrupt, from the handler table: A+B+Select+Start was pressed, so it sets ResetRequested for the tick loop and disarms the interrupt.

Description

Interrupt handlers, the tick wait, key repeat and the VBlank handler. Part of system.c.

Macros in detail

CARTRIDGE_RESET_MARK

#define CARTRIDGE_RESET_MARK 0x19670704

The word a soft reset leaves in CartridgeResetMarker: a date, 4 July 1967, its digits packed four bits each.

Definition at line 6 of file system_frame.c.

DISPSTAT_FLAGS

#define DISPSTAT_FLAGS 0xff

DISPSTAT's low byte: its flags and interrupt enables, without the VCount line above them.

Referenced by syIntFunction().

Definition at line 10 of file system_frame.c.

VBLANK_LINES

#define VBLANK_LINES (DISPLAY_TOTAL_LINES - DISPLAY_HEIGHT)

The lines REG_VCOUNT counts in VBlank, after the DISPLAY_HEIGHT drawn: it runs to DISPLAY_TOTAL_LINES - 1.

Referenced by sySynch().

Definition at line 107 of file system_frame.c.

syReset

#define syReset(entry)

Restarts the cartridge: marks CartridgeResetMarker, stops direct sound and jumps to the cartridge's start with interrupts off. entry is the caller's local for the start address.

Referenced by sySynch().

Definition at line 112 of file system_frame.c.

INPUT_KEY_REPEAT_FIRST

#define INPUT_KEY_REPEAT_FIRST 19

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

Referenced by syInputResetKeyRepeat(), syInputUpdateKeyRepeatAndDirection() and syVBlankHandler().

Definition at line 282 of file system_frame.c.

INPUT_KEY_REPEAT_NEXT

#define INPUT_KEY_REPEAT_NEXT 6

Referenced by syInputUpdateKeyRepeatAndDirection().

Definition at line 283 of file system_frame.c.

KEY_WORD_BITS

#define KEY_WORD_BITS 0xffff

Every bit of a key word, as KEYINPUT's 16 bits.

Referenced by syInputUpdateKeyRepeatAndDirection() and syVBlankHandler().

Definition at line 286 of file system_frame.c.

SOUND_REVERB_CODE_COUNT

#define SOUND_REVERB_CODE_COUNT 5

the codes of enum SoundReverbCode

Referenced by sySoundLoadReverbCode().

Definition at line 467 of file system_frame.c.

Enumerations in detail

anonymous enum

enum { SLEEP_IDLE_TICKS, SLEEP_WHITE_FRAMES, SLEEP_WAKE_FRAMES }

Durations of the sleep: the first in ticks, the others in frames, since the sleep waits on syWaitForVBlankInterrupt alone.

EnumeratorValueDescription
SLEEP_IDLE_TICKS3 * 60 * 60three minutes with no key held
SLEEP_WHITE_FRAMES10the white screen shown before the Stop
SLEEP_WAKE_FRAMES10waited after waking, before the screen

Definition at line 98 of file system_frame.c.

anonymous enum

enum { CPU_LOAD_PEAK_TICKS }

Ticks the debug CPU-load display holds a peak.

EnumeratorValueDescription
CPU_LOAD_PEAK_TICKS30

Definition at line 122 of file system_frame.c.

Functions in detail

syIntFunction

void syIntFunction(Uint32 irq, Sint32 vcount, INTERRUPT_HANDLER handler)

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

References IrqHandlers, Sint32 and syIRQIgnore().

Referenced by btEffectRunNeptune(), btIRQRemoveVCountHandler(), btTransitionRun(), fdScreenTransitionFinish(), fdScreenTransitionStart(), fdScreenTransitionUpdate(), fdScreenTransitionUpdateFromCenter(), gmMainRoutineRun(), mnBattleCommandRowRun(), mnGraphicsInstallBg1VCountHandler(), scScrollStartHBlank(), syBupReleaseState(), syInit(), sySerialInit() and sySerialRemoveIRQHandlers().

Definition at line 14 of file system_frame.c.

syWaitForVBlankInterrupt

void syWaitForVBlankInterrupt(void)

Waits for the next VBlank; outside the sound test it first runs the music ramps and the sound driver's VBlank update, and mixes this VBlank's sound when the driver is free.

References FrameCount, IwramSoundRenderVBlank(), Sint32, SoundDriverEnterVBlankUpdate(), SoundInfoPointer, SoundVBlankStateWork, sySoundUpdateBGMRampsStub() and VBlankDone.

Referenced by sySynch().

Definition at line 57 of file system_frame.c.

sySynch

void sySynch(Sint32 ticks)

The game's tick loop: runs ticks ticks and returns.

References BiosSoundBiasOff(), BiosSoundBiasOn(), BiosStop(), CpuLoadDisplayEnabled, CpuLoadPeak, CpuLoadTimer, DebugMode, DebugPaused, EventsRunning, IdleSleepEnabled, IdleTicks, LastTickFrames, OamCopyEnabled, OamUsageWork, PerWork, PlayTimeTicks, ResetRequested, SerialExchangeActive, SerialStateWork, Sint32, SleepActive, SleepDisabled, SleepRequested, syExecuteEvent(), syHeapSlotAllocate(), syHeapSlotRelease(), syInputUpdateKeyRepeatAndDirection(), syOAMBuildBuffer(), syOAMResetTick(), sySerialPollStatus(), syWaitForVBlankInterrupt(), TickCount, TickFrames and TickRenderPending.

Referenced by btActionRunBuild(), btAdjustDebugValue(), btAppendLinkedActions(), btAutoBattleRunAction(), btAutoBattleRunApproachAttack(), btAutoBattleRunAttackOrItem(), btAutoBattleRunPsynergy(), btBackgroundFadeAlphaIn(), btBackgroundFadeAlphaOut(), btDebugBattleRunMenu(), btEffectConfigureEffectDisplay(), btEffectConvertBackgroundToBlueRamp(), btEffectEndCanvasLayer(), btEffectHideBg1AndRestoreBackdrop(), btEffectOpenCanvasLayer(), btEffectRunAnnihilation(), btEffectRunAtalanta(), btEffectRunAttackSlash(), btEffectRunAzul(), btEffectRunBackgroundFadeIn(), btEffectRunBoreas(), btEffectRunCanvasBurst(), btEffectRunCatastrophe(), btEffectRunCharon(), btEffectRunCloudSwirl(), btEffectRunCoatlicue(), btEffectRunCriticalHit(), btEffectRunCruelRuin(), btEffectRunDeathPlunge(), btEffectRunDragonFire(), btEffectRunEclipse(), btEffectRunFlashingStrike(), btEffectRunFlurry(), btEffectRunHaures(), btEffectRunJudgment(), btEffectRunKirin(), btEffectRunMadZephyr(), btEffectRunMegaera(), btEffectRunMeteorBlow(), btEffectRunMightyPress(), btEffectRunMoloch(), btEffectRunNeptune(), btEffectRunNereid(), btEffectRunNereidCopy(), btEffectRunRamses(), btEffectRunSevereBlow(), btEffectRunShatteringOpening(), btEffectRunStarfieldFall(), btEffectRunThrash(), btEffectRunTorch() and 781 more.

Definition at line 128 of file system_frame.c.

syInputResetKeyRepeat

void syInputResetKeyRepeat(void)

Restarts the key repeat delay, so held keys wait the full delay again.

References PerWork.

Referenced by mnBattleDjinnMenuRun(), mnBattleItemMenuRun(), mnBattlePsynergyMenuRun(), mnBattleSummonMenuRun(), mnDjinnMenuRunPreview(), mnDjinnMenuShowMemberStatus(), mnPagedListHandleInput() and mnStatusScreenShowDjinnList().

Definition at line 289 of file system_frame.c.

syInputUpdateKeyRepeatAndDirection

void syInputUpdateKeyRepeatAndDirection(void)

Turns the keys the VBlank handler read into repeats, once a tick after VBlank. When the repeat timer has run out, the held keys repeat into PerWork.repeat. PerWork.direction is the same keys with at most one D-pad direction: of several held directions it keeps the one added last (prevDirection remembers it), and with all four it keeps none. Last, the keys newly held since the previous tick go to pressed, and prevData takes held.

References PerWork and Sint32.

Referenced by sySynch().

Definition at line 300 of file system_frame.c.

syVBlankHandler

void syVBlankHandler(void)

The VBlank interrupt handler, installed by syInit.

References BgScrollWork, FrameCount, IwramSoundRenderVBlank(), LinkStatusWork, OamUsageWork, PerWork, ScreenFadeFrames, SerialExchangeActive, SerialPeerPayloads, SerialTransfer, Sint32, SoundDriverEnterVBlankUpdate(), SoundDriverVSyncRefresh(), SoundInfoPointer, SoundVBlankStateWork, syCopyWords(), syDMAXCopy(), syIOWriteQueueFlushPending(), syRunPassBeforeTickEvents(), syScreenFadeUpdate(), sySerialExchangePayloads(), sySerialStepBlockTransfer(), sySoundUpdateBGMRampsStub(), TickFrames, TickRenderPending, UserFunction() and VBlankDone.

Referenced by syInit().

Definition at line 375 of file system_frame.c.

sySoundLoadReverbCode

Sint32 sySoundLoadReverbCode(Sint32 code)

Where The Broken Seal copies the mixer code for reverb code code (enum SoundReverbCode) into IWRAM, The Lost Age keeps only the range check and returns 0, so its callers (the battle engine, the lobby, the sound test and the debug menu) change nothing.

References Sint32.

Referenced by btRun(), mnDebugSoundTestRun(), scInit(), scLinkLobbyLeaveArena(), sySoundPlay() and sySoundTestRun().

Definition at line 473 of file system_frame.c.

sySoundReservedNoOperationA

void sySoundReservedNoOperationA(void)

Empty: nothing calls it or its neighbour.

Definition at line 481 of file system_frame.c.

sySoundReservedNoOperationB

void sySoundReservedNoOperationB(void)

Empty, as sySoundReservedNoOperationA.

Definition at line 486 of file system_frame.c.

syInputHandleKeyInterrupt

void syInputHandleKeyInterrupt(void)

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

References ResetRequested and SleepActive.

Referenced by DefaultIrqHandlers.

Definition at line 492 of file system_frame.c.