Skip to Content
The Alchemy Project

src/game/main_routine.c

The main routine and scene changes: exits, returns from battle, entering.

Macros

NameDescription
#defineEXIT_DEFAULT_SCENE_MASK 0x1ffThe scene of a table's first exit word, the destination when no exit matches: nine bits, where EXIT_SCENE_MASK takes twelve.
#defineMAIN_ROUTINE_DEFINE_RUN_MINIGAME (name, start)Each runs a minigame's engine, preserving BG palettes 14 and 15 in a 64-byte syHeapAllocate copy freed afterwards, and returns its start function's result, 0, for gmReturnFromEngine.
#defineSCENE_ROW (id) (&ScenesWork[id])The scene id's row of ScenesWork.
#defineAREA_VISITED_MASK 0x7fFLAG_AREA_VISITED has a flag for each of 128 areas.

Enumerations

NameDescription
enumanonymous enum { MINIGAME_PALETTE_FIRST, MINIGAME_PALETTE_BYTES }The last two 16-colour background palettes, which the minigame runners save and restore around a minigame; palette 15 holds the window colours (mnWindowColorApply).

Functions

NameDescription
voidgmTakeExit (Sint32 exitId)Chooses the scene and entrance to go to when the party leaves the current scene. exitId is the kind of exit fdEngineRun ended on; the scene's exit table gives the first exit of that kind (or of any kind) whose flag, if it has one, is not set.
voidgmReturnFromEngine (Sint32 result)Chooses where the game continues after an engine other than the field engine (see gmMainRoutineRun). result is its result: -1 when the party was defeated, which revives the leader with 1 HP (and, with FLAG_CHILDHOOD, fully heals Isaac and Garet) and returns to the story battle's defeat point (fdScriptSetDefeatDestination) or, when none is set, to the restart point, usually the last Sanctum (fdSetRestartPoint).
Sint32gmGetArea (Sint32 sceneId)Returns the area sceneId belongs to.
voidgmMainRoutineRun (Sint32 start)The main routine: runs one engine after another and never returns. start, a GAME_START, chooses the first scene.
voidgmLoadOverlay (Sint32 unused)Loads the current scene's overlay code (its resource) into OverlayArea.
voidgmArrive (Sint32 unused, Sint32 keep)Updates the flags and state that last for one scene or one area, on entering the current scene.
voidgmPlayMusic (void)Starts the current scene's field music, chosen by fdChooseMusic.

Description

The main routine and scene changes: exits, returns from battle, entering.

Macros in detail

EXIT_DEFAULT_SCENE_MASK

#define EXIT_DEFAULT_SCENE_MASK 0x1ff

The scene of a table's first exit word, the destination when no exit matches: nine bits, where EXIT_SCENE_MASK takes twelve.

Referenced by gmTakeExit().

Definition at line 16 of file main_routine.c.

MAIN_ROUTINE_DEFINE_RUN_MINIGAME

#define MAIN_ROUTINE_DEFINE_RUN_MINIGAME(name, start)

Each runs a minigame's engine, preserving BG palettes 14 and 15 in a 64-byte syHeapAllocate copy freed afterwards, and returns its start function's result, 0, for gmReturnFromEngine.

Definition at line 189 of file main_routine.c.

SCENE_ROW

#define SCENE_ROW(id) (&ScenesWork[id])

The scene id's row of ScenesWork.

Referenced by gmArrive().

Definition at line 331 of file main_routine.c.

AREA_VISITED_MASK

#define AREA_VISITED_MASK 0x7f

FLAG_AREA_VISITED has a flag for each of 128 areas.

Referenced by gmArrive().

Definition at line 334 of file main_routine.c.

Enumerations in detail

anonymous enum

enum { MINIGAME_PALETTE_FIRST, MINIGAME_PALETTE_BYTES }

The last two 16-colour background palettes, which the minigame runners save and restore around a minigame; palette 15 holds the window colours (mnWindowColorApply).

EnumeratorValueDescription
MINIGAME_PALETTE_FIRST14BG palette 14
MINIGAME_PALETTE_BYTES64palettes 14 and 15: 2 x 16 colours x 2 bytes

Definition at line 180 of file main_routine.c.

Functions in detail

gmTakeExit

void gmTakeExit(Sint32 exitId)

Chooses the scene and entrance to go to when the party leaves the current scene. exitId is the kind of exit fdEngineRun ended on; the scene's exit table gives the first exit of that kind (or of any kind) whose flag, if it has one, is not set.

References gmFlagGetStub(), MainRoutineStateWork, OverlayArea and Sint32.

Referenced by gmMainRoutineRun().

Definition at line 22 of file main_routine.c.

gmReturnFromEngine

void gmReturnFromEngine(Sint32 result)

Chooses where the game continues after an engine other than the field engine (see gmMainRoutineRun). result is its result: -1 when the party was defeated, which revives the leader with 1 HP (and, with FLAG_CHILDHOOD, fully heals Isaac and Garet) and returns to the story battle's defeat point (fdScriptSetDefeatDestination) or, when none is set, to the restart point, usually the last Sanctum (fdSetRestartPoint).

References gmFlagGetStub(), gmFlagSetStub(), gmUnitGetStub(), MainRoutineStateWork and Sint32.

Referenced by gmMainRoutineRun().

Definition at line 96 of file main_routine.c.

gmGetArea

Sint32 gmGetArea(Sint32 sceneId)

Returns the area sceneId belongs to. The scenes of one area share their music, area name and the flags kept while inside it.

References ScenesWork and Sint32.

Referenced by fdAreaGetNameIndex().

Definition at line 172 of file main_routine.c.

gmMainRoutineRun

void gmMainRoutineRun(Sint32 start)

The main routine: runs one engine after another and never returns. start, a GAME_START, chooses the first scene.

References btRunStub(), DebugMode, fdChooseMusic(), fdEngineRun(), gmArrive(), gmFlagClearStub(), gmFlagGetStub(), gmLoadOverlay(), gmMainRoutineStateInitDefaultsStub(), gmPlayMusic(), gmReturnFromEngine(), gmTakeExit(), MainRoutineStateWork, mnWindowColorApplyStub(), ScenesWork, Sint32, syHeapInit(), syInitEvent(), syIntFunction(), syPrintClear(), sySoundPlayStub() and syVRAMCacheReset().

Definition at line 215 of file main_routine.c.

gmLoadOverlay

void gmLoadOverlay(Sint32 unused)

Loads the current scene's overlay code (its resource) into OverlayArea.

References MainRoutineStateWork, OverlayArea, ScenesWork, Sint32 and syOverlayLoad().

Referenced by gmMainRoutineRun().

Definition at line 322 of file main_routine.c.

gmArrive

void gmArrive(Sint32 unused, Sint32 keep)

Updates the flags and state that last for one scene or one area, on entering the current scene.

References gmFlagClearStub(), gmFlagRefreshLureCapStub(), gmFlagSetStub(), MainRoutineStateWork and Sint32.

Referenced by gmMainRoutineRun().

Definition at line 338 of file main_routine.c.

gmPlayMusic

void gmPlayMusic(void)

Starts the current scene's field music, chosen by fdChooseMusic.

References MainRoutineStateWork and sySoundPlayStub().

Referenced by gmMainRoutineRun(), scAltinPeakRunBoulderChase(), scAltmillerCaveMeetInvisibleBabi(), scAltmillerCaveRestoreBabiAndInviteParty(), scBabiPalaceMeetBabiAfterColosso(), scColossoShowOpeningLettering(), scFuchinFallsCaveLightDragonWithEye(), scKalayWatchTourGroupDeparture(), scKolimaForestEntranceWitnessForestCurse(), scKolimaForestTreeRejectHermesWater(), scKolimaWitnessForestCurse(), scLogRoomsADiscussMindReading(), scLogRoomsAMeetIvan(), scMercuryLighthouseAerieAlexAppears(), scShipRoomsDiscussLaunchingWithoutAnchor(), scTimberRoomsAIodemQuestionsWoundedSoldiers(), scValeKradensCottageMeetSaturosAndMenardi() and scValeMendingTheRoof().

Definition at line 390 of file main_routine.c.