Skip to Content
The Alchemy Project

src/system/system_start_up.c

Power-up, the cartridge's language, the build stamp and code loading. More…

Included by system.c.

Macros

NameDescription
#defineTHUMB_BL_HIGH 0xf000A Thumb long branch (BL) is two halfwords: the first carries the marker THUMB_BL_HIGH and the offset's high eleven bits, from THUMB_BL_HIGH_SHIFT, the second the marker THUMB_BL_LOW and the low eleven bits of the halfword offset (THUMB_BL_OFFSET_BITS each).
#defineTHUMB_BL_LOW 0xf800
#defineTHUMB_BL_OFFSET_BITS 0x7ff
#defineTHUMB_BL_HIGH_SHIFT 12

Functions

NameDescription
voidsyInit (void)Powers the game up: stops any HBlank DMA left running, sets the cartridge wait states, clears IWRAM, installs the interrupt handlers and the resident IWRAM code, loads the window graphics and the sound driver, then enters gmMainRoutineRun and never returns.
voidsyIdleForever (void)Unused: lets ticks pass forever, the events still running each tick.
Sint32syGetLanguage (void)Returns the language of this cartridge from the last letter of the game code in its header, as an CARTRIDGE_LANGUAGE.
voidsyDummyReservedNoOperationA (void)Unused: five empty exports the system library's stub table reserves; nothing calls them.
voidsyDummyReservedNoOperationB (void)
voidsyDummyReservedNoOperationC (void)
voidsyDummyReservedNoOperationD (void)
voidsyDummyReservedNoOperationE (void)
Sint32syDummyReturnZero (Sint32 resourceId, const Uint8 *table)An exported stub that ignores its arguments and returns 0.
voidsyCopyBuildStamp (void)Copies the build stamp resource (three words) into BuildStampWork and writes the zero word that ends it.
voidsyResourceReservedNoOperation (Sint32 unused)An exported stub that does nothing with its argument.
void *syResourceGetTableEntry (Sint32 index)Returns the ROM address of resource index from the resource directory.
voidsyCodeResolveLongBranches (Uint16 *pair, Sint32 byteLength)Unused: resolves the Thumb long branches (BL pairs) of a block of code whose branch offsets are stored from the start of the block.
voidsyOverlayLoad (Uint32 index, void *dest)Decodes the compressed code resource index to dest and resolves its long branches there, with a RAM copy of the ARM function that does what syCodeResolveLongBranches does; the copy is allocated and freed again.
voidsyIRQIgnore (void)The handler of every interrupt nobody has claimed.
voidsyInstallIWRAMAndIRQs (void)Copies the resident code to IWRAM (4 KB), points the BIOS interrupt vector (IrqVector) at its dispatcher, installs the default handler table and enables the VBlank, keypad and cartridge-removed interrupts.

Description

Power-up, the cartridge's language, the build stamp and code loading. Part of system.c.

Macros in detail

THUMB_BL_HIGH

#define THUMB_BL_HIGH 0xf000

A Thumb long branch (BL) is two halfwords: the first carries the marker THUMB_BL_HIGH and the offset's high eleven bits, from THUMB_BL_HIGH_SHIFT, the second the marker THUMB_BL_LOW and the low eleven bits of the halfword offset (THUMB_BL_OFFSET_BITS each).

Referenced by syCodeResolveLongBranches().

Definition at line 136 of file system_start_up.c.

THUMB_BL_LOW

#define THUMB_BL_LOW 0xf800

Referenced by syCodeResolveLongBranches().

Definition at line 137 of file system_start_up.c.

THUMB_BL_OFFSET_BITS

#define THUMB_BL_OFFSET_BITS 0x7ff

Referenced by syCodeResolveLongBranches().

Definition at line 138 of file system_start_up.c.

THUMB_BL_HIGH_SHIFT

#define THUMB_BL_HIGH_SHIFT 12

Referenced by syCodeResolveLongBranches().

Definition at line 139 of file system_start_up.c.

Functions in detail

syInit

void syInit(void)

Powers the game up: stops any HBlank DMA left running, sets the cartridge wait states, clears IWRAM, installs the interrupt handlers and the resident IWRAM code, loads the window graphics and the sound driver, then enters gmMainRoutineRun and never returns.

References CartridgeResetMarker, CpuLoadDisplayEnabled, DebugMode, DebugTextEnabled, gmMainRoutineRunStub(), IoWriteQueueWork, OamCopyEnabled, OamUsageWork, SleepDisabled, syCopyBuildStamp(), syHalt(), syHeapInit(), syInitEvent(), syInstallIWRAMAndIRQs(), syIntFunction(), syPrintClear(), sySoundInitStub(), sySynch(), syVBlankHandler(), syVRAMCacheReset() and syWindowLoadGraphics().

Definition at line 10 of file system_start_up.c.

syIdleForever

void syIdleForever(void)

Unused: lets ticks pass forever, the events still running each tick.

References PerWork and sySynch().

Definition at line 47 of file system_start_up.c.

syGetLanguage

Sint32 syGetLanguage(void)

Returns the language of this cartridge from the last letter of the game code in its header, as an CARTRIDGE_LANGUAGE. Only the German, Spanish, French and Italian editions have it.

References Sint32.

Referenced by mnBattleStatusScreenRun() and mnBattleTargetRunSelection().

Definition at line 62 of file system_start_up.c.

syDummyReservedNoOperationA

void syDummyReservedNoOperationA(void)

Unused: five empty exports the system library's stub table reserves; nothing calls them.

Definition at line 80 of file system_start_up.c.

syDummyReservedNoOperationB

void syDummyReservedNoOperationB(void)

Definition at line 84 of file system_start_up.c.

syDummyReservedNoOperationC

void syDummyReservedNoOperationC(void)

Definition at line 88 of file system_start_up.c.

syDummyReservedNoOperationD

void syDummyReservedNoOperationD(void)

Definition at line 92 of file system_start_up.c.

syDummyReservedNoOperationE

void syDummyReservedNoOperationE(void)

Definition at line 96 of file system_start_up.c.

syDummyReturnZero

Sint32 syDummyReturnZero(Sint32 resourceId, const Uint8 *table)

An exported stub that ignores its arguments and returns 0.

References Sint32.

Referenced by fdSpriteViewerRun().

Definition at line 101 of file system_start_up.c.

syCopyBuildStamp

void syCopyBuildStamp(void)

Copies the build stamp resource (three words) into BuildStampWork and writes the zero word that ends it. Called at power-up, before the window graphics load.

References BuildStampWork, syDMAXCopy() and syResourceGetTableEntry().

Referenced by syInit().

Definition at line 109 of file system_start_up.c.

syResourceReservedNoOperation

void syResourceReservedNoOperation(Sint32 unused)

An exported stub that does nothing with its argument. The title, the staff credits, Lucky Dice, Super Lucky Dice and Lucky Wheels call it with a stub call resource id.

References Sint32.

Referenced by fdLuckyDiceRun(), fdLuckyWheelsRun(), fdSuperLuckyDiceRun() and scInit().

Definition at line 121 of file system_start_up.c.

syResourceGetTableEntry

void *syResourceGetTableEntry(Sint32 index)

Returns the ROM address of resource index from the resource directory. Called throughout the game before decoding a resource.

References ResourceDirectoryTable and Sint32.

Referenced by btBackgroundLoad(), btEffectRunAstralBlast(), btEffectRunAtalanta(), btEffectRunAttackSlash(), btEffectRunBackstab(), btEffectRunBallLightning(), btEffectRunBreak(), btEffectRunBubbleColumn(), btEffectRunBurstShower(), btEffectRunCanvasBurst(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunCharon(), btEffectRunCloudSwirl(), btEffectRunCoatlicue(), btEffectRunCool(), btEffectRunCrescentSlash(), btEffectRunCriticalHit(), btEffectRunCruelRuin(), btEffectRunCrystal(), btEffectRunDaedalus(), btEffectRunDaedalusStrike(), btEffectRunDeathPlunge(), btEffectRunDjinniEntrance(), btEffectRunDragonCloud(), btEffectRunDragonFire(), btEffectRunDrainMotes(), btEffectRunEclipse(), btEffectRunElementBurst(), btEffectRunElementPillar(), btEffectRunEruption(), btEffectRunFallingSword(), btEffectRunFirePuppet(), btEffectRunFlora(), btEffectRunFlurry(), btEffectRunFormChange(), btEffectRunGaia(), btEffectRunGeode(), btEffectRunGeyser(), btEffectRunHaunt(), btEffectRunHaures(), btEffectRunHealingMotes(), btEffectRunHelmSplitter(), btEffectRunHurricane(), btEffectRunIris(), btEffectRunJudgment(), btEffectRunLeapingStrike(), btEffectRunLobbedShells(), btEffectRunMars(), btEffectRunMegaera() and 120 more.

Definition at line 127 of file system_start_up.c.

syCodeResolveLongBranches

void syCodeResolveLongBranches(Uint16 *pair, Sint32 byteLength)

Unused: resolves the Thumb long branches (BL pairs) of a block of code whose branch offsets are stored from the start of the block. Each pair's offset is reduced by the pair's own position in the block, which turns it into the pc-relative offset the CPU expects; the pairs are rewritten in place. byteLength is the code size. Nothing calls it: syOverlayLoad uses the ARM function that does the same.

References Sint32.

Definition at line 147 of file system_start_up.c.

syOverlayLoad

void syOverlayLoad(Uint32 index, void *dest)

Decodes the compressed code resource index to dest and resolves its long branches there, with a RAM copy of the ARM function that does what syCodeResolveLongBranches does; the copy is allocated and freed again.

References Sint32, syDecompressTaggedLZ(), syHeapRelease(), syResourceGetTableEntry(), syResourcePatchThumbBranch and syResourcePatchThumbBranchCodeSize.

Referenced by gmLoadOverlay().

Definition at line 219 of file system_start_up.c.

syIRQIgnore

void syIRQIgnore(void)

The handler of every interrupt nobody has claimed.

Referenced by DefaultIrqHandlers and syIntFunction().

Definition at line 233 of file system_start_up.c.

syInstallIWRAMAndIRQs

void syInstallIWRAMAndIRQs(void)

Copies the resident code to IWRAM (4 KB), points the BIOS interrupt vector (IrqVector) at its dispatcher, installs the default handler table and enables the VBlank, keypad and cartridge-removed interrupts.

References DefaultIrqHandlers, IrqHandlers, IwramResidentRom, syDMAXCopy() and syIWRAMIRQMain.

Referenced by syInit().

Definition at line 240 of file system_start_up.c.