src/game/main_routine.c
The main routine and scene changes: exits, returns from an engine, entering a scene. More…
#include "flags.h"#include "field/field_engine.h"#include "field/scene_tables.h"#include "sounds.h"#include "battle/battle_unit.h"#include "field/field.h"#include "game/stubs.h"#include "field/lucky_dice_stubs.h"#include "field/lucky_wheels_stubs.h"#include "field/super_lucky_dice_stubs.h"#include "window/stubs.h"
Macros
| Name | Description | |
|---|---|---|
#define | OWN_fdEngineRun | This unit declares its own form of fdEngineRun, below. |
#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. |
#define | MAIN_ROUTINE_RUN_MINIGAME (start) | Runs a minigame's engine, preserving BG palettes 14 and 15 in a 64-byte syHeapAllocate copy freed afterwards, and stores its start function's result for gmReturnFromEngine. |
#define | DEBUG_VENUS_LIGHTHOUSE_START 10 | The debug start's entrance into Venus Lighthouse's grounds: the path south of the plaza, which venus_lighthouse_entrance.c calls ENTRANCE_PLAZA_PATH. |
#define | DEBUG_MT_ALEPH_START 1 | The debug start's entrance into Mt. Aleph's summit, one no stretch of the ending uses: Alex stands on the summit while B is held, and the staff credits' opening follows. |
#define | MAP_HEADER_AT (id) (&ScenesWork[id]) | The scene's row of ScenesWork. |
Enumerations
| Name | Description | |
|---|---|---|
enum | anonymous 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
| Name | Description | |
|---|---|---|
Sint32 | fdEngineRun (Sint32 entrance) | The ROM's caller here is compiled against this form, which takes the entrance where the definition takes nothing. |
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. |
void | gmReturnFromEngine (Sint32 result) | Chooses where the game continues after an engine other than the field engine (see gmMainRoutineRun). |
Sint32 | gmGetArea (Sint32 sceneId) | Returns the area sceneId belongs to. |
Sint16 | gmFieldGetSceneAttributes (Sint32 sceneId) | Returns the scene's attributes, the last halfword of its ScenesWork row, which The Broken Seal leaves 0; the field engine splits it into two nibbles. |
void | gmMainRoutineRun (Sint32 start) | The main routine: runs one engine after another and never returns. start, a GAME_START, chooses the first scene. |
void | gmLoadOverlay (Sint32 unused) | Loads the current scene's overlay code (its resource) into OverlayArea. |
void | gmArrive (Sint32 unused, Sint32 keep) | Updates the flags and state that last for one scene or one area, on entering the current scene. |
void | gmPlayMusic (void) | Starts the current scene's field music, chosen by fdChooseMusic. |
Description
The main routine and scene changes: exits, returns from an engine, entering a
scene. As The Broken Seal's main_routine.c, in the same order; in module 04
it follows the field engine's picture decoders.
Macros in detail
OWN_fdEngineRun
#define OWN_fdEngineRun
This unit declares its own form of fdEngineRun, below.
Definition at line 6 of file main_routine.c.
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 30 of file main_routine.c.
MAIN_ROUTINE_RUN_MINIGAME
#define MAIN_ROUTINE_RUN_MINIGAME(start)
Runs a minigame's engine, preserving BG palettes 14 and 15 in a 64-byte
syHeapAllocate copy freed afterwards, and stores its start function's result
for gmReturnFromEngine. The Broken Seal writes the same as an inline function
for each minigame.
Referenced by gmMainRoutineRun().
Definition at line 210 of file main_routine.c.
DEBUG_VENUS_LIGHTHOUSE_START
#define DEBUG_VENUS_LIGHTHOUSE_START 10
The debug start's entrance into Venus Lighthouse's grounds: the path south of
the plaza, which venus_lighthouse_entrance.c calls ENTRANCE_PLAZA_PATH.
Referenced by gmMainRoutineRun().
Definition at line 228 of file main_routine.c.
DEBUG_MT_ALEPH_START
#define DEBUG_MT_ALEPH_START 1
The debug start's entrance into Mt. Aleph's summit, one no stretch of the ending uses: Alex stands on the summit while B is held, and the staff credits' opening follows.
Referenced by gmMainRoutineRun().
Definition at line 232 of file main_routine.c.
MAP_HEADER_AT
#define MAP_HEADER_AT(id) (&ScenesWork[id])
The scene's row of ScenesWork.
Referenced by gmArrive().
Definition at line 363 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).
| Enumerator | Value | Description |
|---|---|---|
MINIGAME_PALETTE_FIRST | 14 | BG palette 14 |
MINIGAME_PALETTE_BYTES | 64 | palettes 14 and 15: 2 x 16 colours x 2 bytes |
Definition at line 200 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. As The Broken Seal's, where a flag word of -1 also takes
the exit.
References MainRoutineStateWork, OverlayArea, Sint32 and syGameFlagGet().
Referenced by gmMainRoutineRun().
Definition at line 37 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: BATTLE_OUTCOME_LOST when the
party was defeated, which revives the leader with 1 HP and returns to the
story battle's defeat point (fdScriptSetDefeatDestination, defeatScene) or,
when none is set, to the restart point, usually the last Sanctum
(fdSetRestartPoint, restartScene); the world map is then told the scene was
left (fdWorldMapSetReturnLeavingScene). As The Broken Seal's, with no
childhood healing.
References fdWorldMapSetReturnLeavingScene(), gmUnitGet(), MainRoutineStateWork, result, Sint32 and syGameFlagSet().
Referenced by gmMainRoutineRun().
Definition at line 118 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 185 of file main_routine.c.
gmFieldGetSceneAttributes
Sint16 gmFieldGetSceneAttributes(Sint32 sceneId)
Returns the scene's attributes, the last halfword of its ScenesWork row,
which The Broken Seal leaves 0; the field engine splits it into two nibbles.
References ScenesWork and Sint32.
Referenced by fdEngineRun().
Definition at line 192 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. As The Broken Seal's, with this game's
four debug starts, rendering re-enabled after DMA 0 stops, and three
minigames, Super Lucky Dice the third.
References btRunStub(), DebugMode, fdChooseMusic(), fdEngineRun(), fdLuckyDiceStartStub(), fdLuckyWheelsStartStub(), fdSuperLuckyDiceStartStub(), gmArrive(), gmLoadOverlay(), gmMainRoutineStateInitDefaultsStub(), gmPlayMusic(), gmReturnFromEngine(), gmTakeExit(), MainRoutineStateWork, mnWindowColorApplyStub(), OamCopyEnabled, ScenesWork, Sint32, syGameFlagClear(), syGameFlagGet(), syHeapInit(), syInitEvent(), syIntFunction(), syPrintClear(), sySoundPlayStub() and syVRAMCacheReset().
Definition at line 238 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 354 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. As The Broken Seal's, with this game's flags, and
fdWorldMapMarkPlaceVisited in place of the area's visited flag.
References fdWorldMapMarkPlaceVisited(), gmFlagRefreshLureCapStub(), MainRoutineStateWork, Sint32, syGameFlagClear() and syGameFlagSet().
Referenced by gmMainRoutineRun().
Definition at line 368 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(), scAirsRockInsideShebaLearnsReveal(), scAlhafraManorBriggsEscapes(), scAquaRockInsidePiersLearnsParch(), scAquaRockInsideUseAquariusStone(), scChampaCliffCavesFightAvimander(), scChampaCliffCavesObabaForgesTrident(), scContigoTheReunion(), scGabombaCatacombsGabombaBestowsPower(), scGabombaStatueChamberWhereIsTheOrb(), scGaiaRockInsideFelixLearnsSand(), scInit(), scJupiterLighthouseKarstAndAgatioRetreat(), scJupiterLighthouseWeBeatThem(), scMadraMeetKarst(), scMagmaRockInsideLearnBlaze(), scMarsLighthouseStarRoomUseMarsStar(), scMarsLighthouseStarRoomWakeAfterBattle(), scSeaOfTimeOpen(), scShamanVillageRestartTrial(), scShamanVillageShebaClearsSand(), scShamanVillageShowShamansRod(), scShamanVillageTellFortune(), scWorldMapBoardShip(), scWorldMapLeaveShip(), scWorldMapMeetEcho() and scWorldMapTakeOff().
Definition at line 427 of file main_routine.c.