1#ifndef ALCHEMY_UNIT_RUNTIME_RUNTIME_H
2#define ALCHEMY_UNIT_RUNTIME_RUNTIME_H
92void *
memcpy(
void *destination,
const void *source,
unsigned long size);
The task scheduler: tasks, their order and the scheduler's state.
void(*) SchedulerCallback(void)
void Fade_ToBlack(s32 frames)
Fades out to black.
void Fade_ToWhite(s32 frames)
Fades out to white.
void Fade_FromWhite(s32 frames)
Fades in from white.
void Fade_Wait(void)
Waits a frame at a time until the running fade has finished.
void Fade_FromBlack(s32 frames)
Fades in from black.
void Fade_Update(void)
Steps the screen fade once a frame, called by System_VBlankHandler: sets BLDCNT to brighten or darken...
void Fade_Start(s8 bright, s32 layer, u32 start, s32 target, s32 frames)
Starts a fade of any layers by setting the gBlend globals Fade_Update steps.
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.
void System_VBlankHandler(void)
The VBlank interrupt handler, installed by System_Initialize.
UNUSED void Sound_ReservedNoOpA(void)
Nothing calls it.
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.
s32 Runtime_GetRemainingIwram(void)
Returns the IWRAM bytes left to allocate, up to gCartridgeResetMarker (0x03007800),...
void Runtime_InitializeHeap(void)
Empties the heap: clears the 64 words of gWorkSlot (both pool pointers and every named slot) and sets...
void * Runtime_BumpAllocateAlternatePool(s32 size)
As MemAlloc, but tries EWRAM first.
void * MemAlloc(s32 size)
Allocates size bytes (rounded up to words) with no slot, from IWRAM when they fit and EWRAM otherwise...
s32 Runtime_GetRemainingEwram(void)
Returns the EWRAM bytes left to allocate, up to the end of EWRAM.
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
UNUSED void RuntimeMemory_ReservedNoOp(void)
Reserved empty memory export; its historical purpose is not established.
void * Runtime_AllocateHeapBlock(s32 kind, s32 size)
Returns heap slot kind's block, first allocating size bytes for it (rounded up to words),...
void IoWriteQueue_FlushPending(void)
Runs the queued register writes and empties the queue, with a copy of the executor routine on the sta...
The hardware's interrupt sources and the interrupt handler table.
void(*) InterruptHandler(void)
s32 Math_IntegerSqrt(s32 value)
Returns the integer square root of value, a bit at a time.
void Vector_AddPolarOffset(s32 radius, s32 angle, void *position)
Moves the point position by radius in direction angle on the ground plane: x by the cosine,...
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
s32 ArcTan2(s32 x, s32 y)
Returns the angle of the vector (x, y), in 1/65536 turns, measured from the y axis: 0 along +y,...
s32 Palette_GetBasicObjColors(void)
s32 FixedSqrt(s32 value)
Square root of a 16.16 fixed-point value, in 16.16.
void Render_ResetFrame(void)
Starts a new frame of sprites: frees the affine matrices and empties the 256 depth slots sprites are ...
s32 AffineMatrix_BuildForEffect(struct AffineTransform *source)
Hands out the next OAM affine matrix for a sprite drawn with source's scale and rotation and fills it...
void Runtime_PushSlotEntry(void *slotEntry, s32 slot)
Links a sprite entry into depth slot slot (clamped to 0..255) for this frame.
void Render_BuildOamList(void *work)
Builds this frame's OAM list in work from the sprites linked into the depth slots,...
void ColorBuffer_BackupAndBrightenPartial(u8 *buffer, u32 amount, u8 *backup, u32 bytes)
As ColorBuffer_BackupAndBrighten, skipping groups already all at 63.
void ColorBuffer_BackupAndScaleThreeQuarters(u8 *buffer, u8 *backup, u32 bytes)
Scales every pixel to three quarters.
void Resource_DecompressHalfwords(const void *source, void *destination)
Decompresses the halfword LZ stream at source to destination, with a copy of the ARM decoder on the s...
s32 Resource_DecodeType01(const void *source, void *destination)
Decodes a type-01 resource and returns its unpacked byte count.
void ColorBuffer_BackupAndHalve(u8 *buffer, u8 *backup, u32 bytes)
Halves every pixel. Called by the battle effect canvas's transfers.
void ColorBuffer_BackupAndBrighten(u8 *buffer, u32 amount, u8 *backup, u32 bytes)
Raises every pixel by amount, stopping at 63.
void ColorBuffer_BackupAndHalveNonzero(u8 *buffer, u8 *backup, u32 bytes)
Halves every pixel, skipping all-zero groups.
void ColorBuffer_BackupAndDarken(u8 *buffer, u32 amount, u8 *backup, u32 bytes)
Lowers every pixel by amount, stopping at 0.
s32 Resource_DecodeByteLz(const void *source, void *destination)
Decodes a byte-oriented LZ resource and returns its unpacked byte count.
void ColorBuffer_BackupAndScaleNonzeroThreeQuarters(u8 *buffer, u8 *backup, u32 bytes)
Scales every pixel to three quarters, skipping all-zero groups.
void ColorBuffer_BackupAndDarkenPartial(u8 *buffer, u32 amount, u8 *backup, u32 bytes)
As ColorBuffer_BackupAndDarken, skipping groups already all at 0.
s32 Resource_DecodeType2(const void *source, void *destination)
Decodes a type-02 resource and returns its unpacked byte count.
u32 SaveState_ReadRecordPayload(s32 recordId, void *destination)
Loads the current copy of record recordId into destination.
u32 SaveState_FindLatestSlot(s32 recordId)
Returns the occupied sector holding the newest copy of record recordId, or 16.
s32 SaveState_LoadSummaryRecords(void)
Reads the summary at the start of each of the three save files into summary for the file select scree...
u32 SaveState_ReleaseWorkspace(void)
Removes the flash timer handler and frees the save workspace's heap slot.
u32 SaveState_DeleteRecord(s32 recordId)
Invalidates the current copy of record recordId.
u32 SaveState_GetLatestSequence(s32 recordId)
Returns the highest sequence number among the copies of record recordId.
u32 SaveState_SelectWriteSlot(s32 mode)
Picks the free sector to write record mode to, at random.
s32 SaveState_WriteRecord(s32 recordId, void *source)
Saves 0xff0 bytes from source as record recordId: writes the new copy with the next sequence number,...
u32 SaveState_WriteWorkspaceSlot(s32 sector)
Programs the workspace's sector buffer into flash sector sector and verifies it, through the flash li...
s32 SaveState_ReadSlotAndCheckChecksum(s32 index)
Reads flash sector index into the workspace's sector buffer.
s32 SaveState_InvalidateSlot(s32 index)
Overwrites sector index with a header for no record (id 16) and clears its occupied entry.
s32 SaveState_CompareBytes(u8 *left, u8 *right, s32 count)
Compares count bytes, as memcmp does.
UNUSED u16 SaveState_EraseSlotSector(u16 sector)
Erases flash sector sector with the flash library's routine for this chip.
s32 SaveState_ChecksumWorkspace(void)
Sums the first 0xfe8 payload bytes of the workspace's sector buffer; the final eight payload bytes ar...
s32 SaveState_InitializeWorkspace(void)
Allocates the save workspace (heap slot HEAP_SLOT_SAVE), installs the flash library's timer 2 handler...
s32 Scheduler_ResumeTasks(SchedulerCallback callback)
Resumes the task running callback, or every task when callback is null, by clearing bit 0 of its orde...
s32 Scheduler_AddOrUpdateCallback(SchedulerCallback callback, s32 order)
Schedules callback with order, or gives a task already running it the new order, and re-sorts the tab...
void Scheduler_ResetTaskTable(void)
Empties the task table: every slot gets no routine, order 0xffff (sorted last) and no flags.
void Scheduler_RunPass(s32 key)
Runs one pass of the scheduler: every task whose order's high byte matches key's (SCHEDULER_KEY_MAIN_...
UNUSED void Scheduler_CopyWords(u32 *destination, u32 *source, u32 byteCount)
Copies byteCount bytes a word at a time. Nothing in ☀️ calls it.
s32 Scheduler_SuspendTasks(SchedulerCallback callback)
Suspends the task running callback, or every task when callback is null, by setting bit 0 of its orde...
s32 Scheduler_ResumeOverlayTasks(void)
Resumes every task whose routine is in an overlay, flagged or not.
s32 Scheduler_SuspendOverlayTasks(void)
Suspends every task whose routine is in an overlay (EWRAM, 0x02xxxxxx) unless its flag bit 0 asks to ...
UNUSED void Scheduler_Idle(void)
An empty routine; nothing in ☀️ calls it.
void Scheduler_SortTasks(void)
Bubble-sorts the task table by order, highest first, so each pass runs its tasks from the highest ord...
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
UNUSED s32 Scheduler_FindCallback(SchedulerCallback callback)
Returns the table index of the task running callback, or -1.
s32 Scheduler_SetTaskFlags(SchedulerCallback callback, u32 mask)
Stores mask as the flags of the task running callback; bit 0 keeps it running while the overlay tasks...
UNUSED void Scheduler_EmptyCallback(void)
An empty routine; nothing in ☀️ calls it.
void SerialRuntime_DisableTransfer(void)
Disables the serial and timer 3 interrupts, stops the transfer timer and clears gSerialRuntime....
void SerialRuntime_EnableTransferTimer(void)
Lets the timer start transfers again once a link mode is set, by setting gSerialRuntime....
void SerialRuntime_WaitForSend(void)
s32 SerialRuntime_BeginReceive(void *destination)
Starts receiving the partner's blocks into destination: sets the receive destination and clears the r...
void SerialRuntime_WaitForTransfers(void)
Waits until both the send and the receive have finished, giving up after 600000 frames.
void SerialTest_Delay(void)
An empty routine the link test calls to waste time.
s32 SerialRuntime_BeginSend(void *source, s32 size)
Starts sending size bytes from source to the partner in 20-byte blocks: sets the send source,...
void SerialRuntime_RemoveIrqHandlers(void)
Clears gSerialExchangeActive, which stops the per-frame exchange, and removes the link interrupt hand...
void BattleLink_ResetTransferState(void)
u32 SerialRuntime_WaitForStatusMask(s32 mask)
Waits a frame at a time until every status bit in mask is set in gLinkStatus, then returns this conso...
s32 SerialRuntime_PollStatus(void)
As SerialRuntime_PollAndTransfer, without exchanging data: WaitFrames calls it once a frame while gSe...
void SerialRuntime_WaitForReceive(void)
void SerialRuntime_PrepareSendPacket(void *payload)
Builds the packet to send in sendBuffer[0]: [0] the sequence number, [1] the consoles not yet heard f...
s32 SerialRuntime_PollAndTransfer(void *send, void *receive)
Looks for the link partner and, once connected, does one exchange (as SerialRuntime_ExchangePayloads)...
void SerialTest_Run(void)
A link cable test left in the game: it shows a row of tiles, receives blocks into the map cell buffer...
s32 SerialRuntime_GetActiveTransfers(void)
Returns bit 0 while a send runs and bit 1 while a receive runs.
void SerialRuntime_Initialize(void)
Resets the serial port into multiplayer mode, installs the serial and timer 3 interrupt handlers,...
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 ...
u8 SerialRuntime_CollectReceivedPayloads(void *payload)
Swaps in the packets the interrupt handler finished, then copies the payload of each one whose checks...
void SerialRuntime_HandleTransferInterrupt(void)
The serial and timer 3 interrupt, installed by SerialRuntime_Initialize: each one moves a halfword.
UNUSED void RuntimeDispatch_ReservedNoOpA(void)
Reserved empty export A in the runtime far-call table; no source caller.
void Runtime_IgnoreInterrupt(void)
The handler of every interrupt nobody has claimed.
void System_Initialize(void)
Powers the game up: stops any HBlank DMA left running, sets the cartridge wait states,...
void System_CopyBuildStamp(void)
Copies the build stamp resource (twelve digits) into gBuildStamp in high IWRAM and writes the zero wo...
UNUSED void RuntimeDispatch_ReservedNoOpB(void)
Reserved empty export B in the runtime far-call table; no source caller.
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
UNUSED void RuntimeDispatch_ReservedNoOpD(void)
Reserved empty export D in the runtime far-call table; no source caller.
UNUSED void RuntimeDispatch_ReservedNoOpC(void)
Reserved empty export C in the runtime far-call table; no source caller.
void RuntimeDispatch_NoOpHook(s32 unused)
An exported stub that does nothing with its argument.
void Resource_LoadCode(u32 index, void *destination)
Decodes the compressed code resource index to destination and resolves its long branches there,...
UNUSED void Code_ResolveLongBranches(u16 *entries, s32 byteLength)
Resolves the Thumb long branches (BL pairs) of a block of code whose branch offsets are stored from t...
UNUSED void RuntimeDispatch_ReservedNoOpE(void)
Reserved empty export E in the runtime far-call table; no source caller.
void Runtime_InstallIwramAndIrqs(void)
Copies the resident code to IWRAM, points the BIOS interrupt vector (gIrqVector) at its dispatcher,...
UNUSED void Runtime_IdleForever(void)
Waits out frames forever; the frame loop still runs the scheduled tasks.
s32 RuntimeDispatch_ReturnZero(s32 unused0, const u8 *unused1)
An exported stub that ignores its arguments and reports 0.
void DebugText_PrintDecimal(s32 value, s32 digits)
Prints the last digits characters of value in signed decimal (1 to 10; anything else prints 10).
void DebugText_PrintBlanks(u32 count)
Writes count blank characters at the debug text cursor and moves it on.
void Palette_LoadBasicObjColors(void)
Loads the basic sprite palettes (palettes 0 to 13).
void DebugText_PrintHex(u32 value, s32 digits)
Prints the last digits hexadecimal digits of value (1 to 8; anything else prints all 8).
void NumberText_FormatHex(u32 value)
Writes value as eight hexadecimal digits to the number buffer.
void DebugText_Print(const u8 *src)
Prints the string src (at most 32 characters) at the debug text cursor, wrapping from the end of the ...
void Ui_LoadWindowGraphics(void)
Loads the window font and frame tiles into BG character block 0, the window palette into BG palette 1...
void DebugText_Clear(void)
Blanks the debug text screen, homes the cursor and points BG0 at it.
void NumberText_FormatDecimal(s32 number)
Writes number to the number buffer as eleven characters: spaces, a sign (a space or '-') and its deci...
The integer types, TRUE, UNUSED and the fixed-address macros.
void * memcpy(void *destination, const void *source, unsigned long size)
s32 System_GetLanguage(void)
s32 VramCache_FreeBlocks(s32 id)
Frees every block entry id owns in gResourceBlockOwners.
void VramCache_Reset(void)
Frees every block and every cache entry.
s32 VramCache_AllocEntry(s32 size)
Takes a free cache entry, gives it size bytes of sprite VRAM and returns its number.
s32 VramCache_Reload(s32 no, s32 src)
Copies src again into entry no's VRAM, keeping its size.
s32 VramCache_GetLongestFreeRun(void)
Returns the length, in blocks, of the longest run of free blocks.
s32 VramCache_ReleaseVram(u32 no)
Gives back entry no's blocks but keeps the entry taken, with size 1, so a later VramCache_Load can re...
s32 VramCache_AllocateBlocks(u32 id, u32 size)
Finds the first run of free blocks that holds size bytes and gives it to entry id,...
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
s32 VramCache_Load(u32 no, u32 size, const void *src)
Gives cache entry no size bytes of sprite VRAM and copies src there.