21#define VBlankIntrWait() \
25 CAMELOT_ASM("Halt, which no C compiles to") \
26 __asm__ volatile("swi 2"); \
27 } while (!(gVBlankDone & 1)); \
103 s16 savedDisplayControl;
104 s16 savedBackdropColor;
106 CAMELOT_ASM(
"read the hardware stack pointer for the proven stack switch")
107 __asm__
volatile(
"mov %0, sp" :
"=r"(sp));
116 CAMELOT_ASM(
"the stack switch, a write to sp no C can express")
117 __asm__
volatile(
"mov sp, %0" : :
"r"(top) :
"memory");
119 for (frameIndex = 0; frameIndex < frames; frameIndex++) {
225 __asm__
volatile(
"swi 3");
254 CAMELOT_ASM(
"read the hardware stack pointer for its restore copy")
255 __asm__
volatile(
"mov %0, sp" :
"+r"(base));
259 base -= *(
volatile u32 *)size;
262 "restore the hardware stack pointer after the proven stack copy")
263 __asm__
volatile(
"mov sp, %0" : :
"r"(sp) :
"memory");
285#define INPUT_KEY_REPEAT_FIRST 19
286#define INPUT_KEY_REPEAT_NEXT 6
329 switch (directionCount) {
351 mask = 0xffff ^ axis;
364#define SOUND_PRESET_COUNT 5
365#define SOUND_PRESET_SIZE 152
468#undef INPUT_KEY_REPEAT_FIRST
469#undef INPUT_KEY_REPEAT_NEXT
470#undef SOUND_PRESET_COUNT
471#undef SOUND_PRESET_SIZE
#define SCHEDULER_KEY_VBLANK
A task's order: the high byte picks the pass that runs it, the low byte ranks it within the pass (hig...
volatile u8 gSchedulerStatus
#define SCHEDULER_KEY_MAIN_LOOP
#define DMA3
DMA3, the channel the game copies with, as its three registers.
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
void Fade_Update(void)
Steps the screen fade once a frame, called by System_VBlankHandler: sets BLDCNT to brighten or darken...
void MusicPlayer_StepVolumeAndPitchTowardTargetsFar(void)
void Input_HandleKeyInterrupt(void)
The keypad interrupt, from the handler table: A+B+Select+Start was pressed, so it sets gResetRequeste...
UNUSED void Sound_ReservedNoOpB(void)
Nothing calls it.
void Input_ResetKeyRepeat(void)
Restarts the key repeat delay, so held keys wait the full delay again.
#define INPUT_KEY_REPEAT_NEXT
#define SOUND_PRESET_COUNT
#define VBlankIntrWait()
Sleeps in the BIOS Halt until the VBlank handler has run once.
#define SOUND_PRESET_SIZE
#define INPUT_KEY_REPEAT_FIRST
Frames a key is held before it first repeats, and between later repeats.
void System_VBlankHandler(void)
The VBlank interrupt handler, installed by System_Initialize.
UNUSED void Sound_ReservedNoOpA(void)
Nothing calls it.
static __inline__ void System_SoftReset(void)
Restarts the game from the cartridge entry point.
s32 Sound_LoadPresetParameters(s32 preset)
Copies the mixer code for sound preset preset (0 to 4; anything else is 0) from ROM into IwramSoundPr...
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...
void Input_UpdateKeyRepeatAndDirection(void)
Runs once a frame after VBlank, called by WaitFrames.
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
u32 gCpuLoadPeak
The highest CPU load in the last 30 frames: the scanline the frame's work ended on,...
volatile u8 gCpuLoadDisplayEnabled
Debug: WaitFrames measures the CPU load into gCpuLoadPeak when set.
volatile u8 gSleepDisabled
Nonzero: WaitFrames counts no idle time and ignores sleep requests.
u32 gFrameTick
Counted up by every VBlank.
u32 gPlayTimeFrames
The play time clock, in frames.
u8 gFrameRenderPending
Set by WaitFrames once it has built a frame's OAM list; the VBlank handler then copies the list,...
u8 gSavedStack[]
The caller's stack below the frame-wait stack top, while WaitFrames runs.
volatile u16 gIdleFrames
Frames since a key was last held.
volatile u8 gSleepRequested
1: sleep this frame; more: count down to it.
u32 gCpuLoadTimer
Frames gCpuLoadPeak is still held.
u8 gResetRequested
Set by the keypad interrupt; WaitFrames performs the soft reset.
volatile u16 gVBlankDone
Bit 0 is set by the VBlank handler; WaitFrames clears it and halts until it is set again.
void(*) gVBlankHook(void)
Run once by the next VBlank handler, which clears it first.
u8 gDebugMode
Debug builds: Start+Select pauses the frame loop.
u8 gOamCopyEnabled
The VBlank handler copies the OAM list only while it is set; scenes clear it to keep their own sprite...
volatile u16 gLagFramesShown
gLagFrameCount as the last frame left it; the text typing paces itself by it.
u32 gCartridgeResetMarker
Written by the soft reset just before it restarts the cartridge, and cleared by System_Initialize; no...
u32 gSavedStackSize
Bytes of the caller's stack WaitFrames has copied into gSavedStack, or 0.
u16 gLagFrameCount
VBlanks since WaitFrames last started a frame: 1 when the frame took one.
u8 gDebugPaused
The debug pause is on.
volatile u16 gSleepComboFrames
Frames L and R have been held together; three seconds request sleep.
volatile u32 gFrameCount
Frames WaitFrames has finished.
volatile u8 gIdleSleepEnabled
Sleep after three idle minutes.
void * Runtime_AllocateHeapBlock(s32 kind, s32 size)
Returns heap slot kind's block, first allocating size bytes for it (rounded up to words),...
@ HEAP_SLOT_FRAME_SCRATCH
Lives for one frame: WaitFrames builds the OAM list in it, and the field sprite decoder keeps its cod...
void IoWriteQueue_FlushPending(void)
Runs the queued register writes and empties the queue, with a copy of the executor routine on the sta...
#define KEYCNT_DISARMED
Requires all ten keys together to prevent the reset chord retriggering it.
#define KEYCNT_SOFT_RESET
A, B, Select and Start.
#define RGB(r, g, b)
A 15-bit colour from its red, green and blue levels (0 to 31 each), as the palette stores it: blue in...
#define DMA_START_TIMING_DRQ_REPEAT
A DMA control's start timing (bits 12 and 13), cartridge request (bit 11) and repeat (bit 9): the bit...
#define OAM_SIZE
OAM's size in bytes: 128 sprites of 8 bytes.
#define DISPSTAT_VCOUNT_LINE(line)
DISPSTAT's high byte: the line the VCount interrupt fires on (the LYC compare).
#define DISPSTAT_VBLANK_INTR
#define DMA_COPY_WORDS(n)
#define KEYCNT_SHOULDERS_WAKE
L and R, which wake the sleep.
#define Io_Write16(v, reg)
Writes a value to a 16-bit register or memory location.
InterruptHandler gIrqHandlers[IRQ_COUNT]
The handler the IWRAM dispatcher calls for each interrupt source.
void(*) InterruptHandler(void)
#define IRQ_UNLOCK(saved)
Restores the IME value saved by IRQ_LOCK.
#define IRQ_LOCK(saved)
Disables interrupts and saves IME in saved; IRQ_UNLOCK restores it.
volatile u32 gKeysDirection
The D-pad direction gKeysRepeatDirected keeps: of several held, the one added last.
volatile u32 gKeysHeld
Keys down now.
volatile u32 gKeysPressed
Keys that went down this frame.
u32 gKeysPressedLatch
Presses since a reader last cleared it.
volatile u32 gKeysRepeat
Pressed keys, repeating while held: after 19 frames, then every 6.
volatile u32 gKeysRepeatDirected
gKeysRepeat with at most one D-pad direction.
u32 gKeysHeldLast
gKeysHeld when the frame loop last read it.
u32 gKeysHeldAtVBlank
gKeysHeld at the previous VBlank.
s32 gKeyRepeatTimer
Frames until the held keys repeat; -1 makes them repeat at once.
void Runtime_ReleaseHeapBlock(s32 slot)
#define Ram_FrameWaitStackTop
void Render_ResetFrame(void)
Starts a new frame of sprites: frees the affine matrices and empties the 256 depth slots sprites are ...
void Render_BuildOamList(void *work)
Builds this frame's OAM list in work from the sprites linked into the depth slots,...
What every part of the runtime object shares: its includes and the library call two parts make.
void Scheduler_RunPass(s32 key)
Runs one pass of the scheduler: every task whose order's high byte matches key's (SCHEDULER_KEY_MAIN_...
s32 SerialRuntime_PollStatus(void)
As SerialRuntime_PollAndTransfer, without exchanging data: WaitFrames calls it once a frame while gSe...
void SerialRuntime_StepBlockTransfer(void)
Runs each VBlank after the exchange, called by System_VBlankHandler: moves the bulk transfer on by on...
s32 SerialRuntime_ExchangePayloads(void *send, void *receive)
Once connected (phase 1), gathers the received payloads into receive and builds the next packet from ...
volatile u16 gLinkStatus
Link status, updated by the VBlank exchange handler.
struct SerialRuntime gSerialRuntime
u16 gSerialExchangeActive
u8 gSerialPeerPayloads[4][24]
struct SerialTransferState gSerialTransfer
u8 mode
SIOCNT's bits 7 and 3 when this console armed timer 3 to clock the transfers: 8 then,...
u8 transferEnabled
Nonzero lets a new packet restart timer 3.
void Runtime_IgnoreInterrupt(void)
The handler of every interrupt nobody has claimed.
u8 IwramSoundPresetCode[]
void Bios_SoundBiasOn(void)
void Bios_SoundBiasOff(void)
void SoundDriver_EnterMixer(void)
#define CAMELOT_ASM(proof)
The heap's 64 work slots, the first two holding the next free EWRAM and IWRAM addresses.