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.
#defineKEY_WORD_BITS 0xffffEvery bit of a key word, as KEYINPUT's 16 bits.
#defineSYNCH_WAIT_VBLANK ()Halts the CPU (the BIOS Halt) until the VBlank handler has run once.
#defineINPUT_KEY_REPEAT_FIRST 19Ticks a key is held before it first repeats, and between later repeats.
#defineINPUT_KEY_REPEAT_NEXT 6
#defineSOUND_REVERB_CODE_COUNT 5reverb codes in IwramSoundReverbCodes
#defineSOUND_REVERB_CODE_SIZE 152bytes in each reverb code

Enumerations

NameDescription
enumanonymous enum { SLEEP_IDLE_TICKS, SLEEP_COMBO_TICKS, SLEEP_WHITE_FRAMES, SLE … }Durations used by the sleep transitions: the first two in ticks, the last two in frames, since the sleep waits on SYNCH_WAIT_VBLANK alone.
enumanonymous enum { CPU_LOAD_PEAK_TICKS }Ticks the debug CPU-load display holds a peak.

Functions

NameDescription
static __inline__ voidsySoftReset (void)Restarts the game from the cartridge entry point.
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.
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)Works out this tick's repeating and newly pressed keys, once a tick after VBlank (sySynch()).
voidsyVBlankHandler (void)The VBlank interrupt handler, installed by syInit.
Sint32sySoundLoadReverbCode (Sint32 code)Copies the mixer code for reverb code code (enum SoundReverbCode; anything else loads SOUND_REVERB_MONO) from ROM into IwramSoundReverbCode.
voidsySoundReservedNoOperationA (void)Unused: two empty functions after the reverb loader, which nothing calls.
voidsySoundReservedNoOperationB (void)
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.

Referenced by sySoftReset().

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 14 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 17 of file system_frame.c.

SYNCH_WAIT_VBLANK

#define SYNCH_WAIT_VBLANK()

Halts the CPU (the BIOS Halt) until the VBlank handler has run once.

Referenced by sySynch().

Definition at line 31 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 306 of file system_frame.c.

INPUT_KEY_REPEAT_NEXT

#define INPUT_KEY_REPEAT_NEXT 6

Referenced by syInputUpdateKeyRepeatAndDirection().

Definition at line 307 of file system_frame.c.

SOUND_REVERB_CODE_COUNT

#define SOUND_REVERB_CODE_COUNT 5

reverb codes in IwramSoundReverbCodes

Referenced by sySoundLoadReverbCode().

Definition at line 390 of file system_frame.c.

SOUND_REVERB_CODE_SIZE

#define SOUND_REVERB_CODE_SIZE 152

bytes in each reverb code

Referenced by sySoundLoadReverbCode().

Definition at line 391 of file system_frame.c.

Enumerations in detail

anonymous enum

enum { SLEEP_IDLE_TICKS, SLEEP_COMBO_TICKS, SLEEP_WHITE_FRAMES, SLEEP_WAKE_FRAMES }

Durations used by the sleep transitions: the first two in ticks, the last two in frames, since the sleep waits on SYNCH_WAIT_VBLANK alone.

EnumeratorValueDescription
SLEEP_IDLE_TICKS3 * 60 * 60three minutes with no key held
SLEEP_COMBO_TICKS3 * 60three seconds holding only L and R
SLEEP_WHITE_FRAMES60the white screen shown before the Stop
SLEEP_WAKE_FRAMES10waited after waking, screen restored

Definition at line 84 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 93 of file system_frame.c.

Functions in detail

sySoftReset

static __inline__ void sySoftReset(void)

Restarts the game from the cartridge entry point. The marker word it leaves in IWRAM is cleared again by syInit; nothing else reads it.

References CartridgeResetMarker, Sint32 and void().

Referenced by sySynch().

Definition at line 21 of file system_frame.c.

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(), scAltinPeakFlickerWaterAway(), scCrossboneIsleSteppingStonesAnimateWaterLevel(), scKolimaForestFloodgateFlipFloodgateSwitch(), scTretTreeBranchStartBg3Split(), syBupReleaseState(), syInit(), sySerialInit() and sySerialRemoveIRQHandlers().

Definition at line 42 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, line, PerData, PerRepeat, PlayTimeTicks, ResetRequested, SavedStack, SavedStackSize, SerialExchangeActive, SerialStateWork, Sint32, SleepActive, SleepComboTicks, SleepDisabled, SleepRequested, syDMAXCopy(), syExecuteEvent(), syHeapSlotAllocate(), syHeapSlotRelease(), syInputUpdateKeyRepeatAndDirection(), syOAMBuildBuffer(), syOAMResetTick(), sySerialPollStatus(), sySoftReset(), syStackPointerSet(), TickCount, TickFrames and TickRenderPending.

Referenced by btActionRunBuild(), btAdjustDebugValue(), btAppendLinkedActions(), btAutoBattleRunAction(), btAutoBattleRunApproachAttack(), btAutoBattleRunAttackOrItem(), btAutoBattleRunPsynergy(), btBackgroundFadeAlphaIn(), btBackgroundFadeAlphaOut(), btDebugBattleRunMenu(), btDebugBattleViewMessages(), btEffectConfigureEffectDisplay(), btEffectConvertBackgroundToBlueRamp(), btEffectEndCanvasLayer(), btEffectHideBg1AndRestoreBackdrop(), btEffectOpenCanvasLayer(), btEffectRunAnnihilation(), btEffectRunAtalanta(), btEffectRunAttackSlash(), btEffectRunBoreas(), btEffectRunCriticalHit(), btEffectRunDeathPlunge(), btEffectRunDragonFire(), btEffectRunFlashingStrike(), btEffectRunFlurry(), btEffectRunJudgment(), btEffectRunKirin(), btEffectRunNeptune(), btEffectRunNereid(), btEffectRunRamses(), btEffectRunShatteringOpening(), btEffectRunStarfieldFall(), btEffectRunThrash(), btEffectRunTorch(), btEffectRunUnusedSevereBlowLeap(), btEffectRunWhirlwind(), btEffectSetupBlendedDisplay(), btEffectSetupCanvasTileMap(), btEffectStartCanvasLayer(), btElementGlowPlay(), btFleePlayRun(), btHighlightSetModes(), btLinkBattleReceiveParty(), btLinkBattleSendParty(), btLinkBattleSyncTurn(), btLinkBattleWaitSync(), btMessageWaitForAdvance(), btMessageWaitForAdvanceAt(), btMotionFlashHit(), btMotionPlayFall() and 594 more.

Definition at line 99 of file system_frame.c.

syInputResetKeyRepeat

void syInputResetKeyRepeat(void)

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

References PerRepeatTimer.

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

Definition at line 310 of file system_frame.c.

syInputUpdateKeyRepeatAndDirection

void syInputUpdateKeyRepeatAndDirection(void)

Works out this tick's repeating and newly pressed keys, once a tick after VBlank (sySynch()). Held keys repeat after INPUT_KEY_REPEAT_FIRST ticks, then every INPUT_KEY_REPEAT_NEXT; PerRepeatDirected is that repeat with at most one D-pad direction, the newer of two held and none of four.

References PerData, PerDataLast, PerDirection, PerPush, PerRepeat, PerRepeatDirected, PerRepeatTimer and Sint32.

Referenced by sySynch().

Definition at line 319 of file system_frame.c.

syVBlankHandler

void syVBlankHandler(void)

The VBlank interrupt handler, installed by syInit.

References BgScrollWork, FrameCount, HeapSlots, LinkStatusWork, MixerEnter(), OamCopyEnabled, PerData, PerDataAtVBlank, PerPush, PerPushLatch, PerRepeat, PerRepeatTimer, SerialExchangeActive, SerialPeerPayloads, SerialTransfer, syDMAXCopy(), syExecuteEvent(), syIOWriteQueueFlushPending(), syScreenFadeUpdate(), sySerialExchangePayloads(), sySerialStepBlockTransfer(), sySoundUpdateBGMRampsStub(), TickFrames, TickRenderPending, UserFunction() and VBlankDone.

Referenced by syInit().

Definition at line 394 of file system_frame.c.

sySoundLoadReverbCode

Sint32 sySoundLoadReverbCode(Sint32 code)

Copies the mixer code for reverb code code (enum SoundReverbCode; anything else loads SOUND_REVERB_MONO) from ROM into IwramSoundReverbCode.

References IwramSoundReverbCode, IwramSoundReverbCodes, Sint32 and syDMAXCopy().

Referenced by btRun(), scBattleArenaLeaveArena(), scInit(), sySoundPlay() and sySoundTestRun().

Definition at line 463 of file system_frame.c.

sySoundReservedNoOperationA

void sySoundReservedNoOperationA(void)

Unused: two empty functions after the reverb loader, which nothing calls.

Definition at line 480 of file system_frame.c.

sySoundReservedNoOperationB

void sySoundReservedNoOperationB(void)

Definition at line 484 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.

Definition at line 490 of file system_frame.c.