Skip to Content
The Alchemy Project

include/macros.h

Small statement macros both games use for positions, velocities and bounds.

Included by battle_internal.h, battle_tables.c, debug_parameter_sets.c, battle_effect_internal.h, psynergy_test.c, test_scenes.c, field_engine_internal.h, field_psynergy_internal.h, field_sprite_draw.c, lucky_dice.c, lucky_wheels.c, script_commands_internal.h, speaker_voices.c, super_lucky_dice.c, game_units.c, credits.c, menu_internal.h, title_intro.c, airs_rock.c, airs_rock_inside.c, alhafra_rooms.c, alhafran_cave.c, anemos_inner_sanctum.c, anemos_inner_sanctum_dullahan.c, ankohl_ruins.c, apojii_islands.c, aqua_rock.c, aqua_rock_inside.c, caverns.c, champa_cliff_caves.c, clear.c, contigo.c, dehkan_plateau.c, eastern_alhafra.c, epilogue.c, gabomba_statue.c, gaia_rock_inside.c, garoh.c, gondowan_cliffs.c, idejima.c, islet_cave.c, islets.c, jupiter_lighthouse_aerie.c, jupiter_lighthouse_basement.c, jupiter_lighthouse_central_room.c, jupiter_lighthouse_cracked_floor.c, jupiter_lighthouse_entrance.c, jupiter_lighthouse_ground_floor.c, jupiter_lighthouse_left_tower_lower.c, jupiter_lighthouse_locked_doors.c and 40 more.

Macros

NameDescription
#defineSET_VECTOR (v, x, y, z) ((v)[0] = (x), (v)[1] = (y), (v)[2] = (z))Sets the x, y and z of a three-part vector: a position about to be projected, a per-tick step, a camera point or a scale.
#defineSET_POSITION (p, newX, newY, newZ)Sets the position or the velocity of a particle, a piece of debris or an actor in one statement.
#defineSET_VELOCITY (p, vx, vy, vz)
#defineCLAMP (v, low, high)Keeps v within low to high, the low bound tested first.
#defineABS (v) ((v) < 0 ? -(v) : (v))The magnitude of v. v is read twice.
#defineARRAY_COUNT (array) (sizeof(array) / sizeof((array)[0]))The entries of an array whose size is declared, as pret's global.h has it.
#defineNEXT_HALFWORD (i) ((Sint32)(((i) << 16) + (1 << 16)) >> 16)One more than i as a signed halfword, the step taken in the high half of a word: the scenes step the halfword counters of their short searches so, as scPushTargetFillRectangle does.
#defineLATE_DATA __attribute__((section(".data.late")))A scene's data that its overlay places after pictures linked between its tables: the overlay's linker script places .data.late after the first of them and .data.last after the next.
#defineLAST_DATA __attribute__((section(".data.last")))
#defineALIGNED (n) __attribute__((aligned(n)))Data aligned as the ROM places it, where its own type would not.
#defineBSS_DATA __attribute__((section(".bss")))A global kept in its object's .bss in the order written, where a plain one would be a common symbol the linker places in an order of its own.

Description

Small statement macros both games use for positions, velocities and bounds.

Macros in detail

SET_VECTOR

#define SET_VECTOR(v, x, y, z) ((v)[0] = (x), (v)[1] = (y), (v)[2] = (z))

Sets the x, y and z of a three-part vector: a position about to be projected, a per-tick step, a camera point or a scale.

Referenced by btCameraCreate(), btCameraSetCommandView(), btCameraSetDefaultView(), btEffectRunDeathPlunge(), btEffectRunDjinnBeams(), btEffectRunFrost(), btEffectRunHaunt(), btEffectRunQuake(), btEffectRunStatBoost(), btEffectRunStatReduction(), btEffectRunSwirlingStars(), btEffectRunTargetBursts(), btEffectRunThor(), btEffectRunUnusedOrbitingSpirals(), btRenderBuildQuadStrip(), btRenderProjectVertices(), fdActorSetTargetPosFromMagnitudeAngle(), fdCameraResetViewDefaults(), fdEffectSpriteDrawAtWorldXYZ(), fdMapGridIsSandMetatile(), fdParticleDraw(), fdRopeGetEndNodePos(), fdSceneItemFindPos(), fdScoopDustUpdateGrain(), fdSuperLuckyDiceResetViewDefaults(), fdWorldMapInitPerspective(), fdWorldMapUpdateView(), mnTitlePaletteFadeBuildColors(), scCavernsJumpEastAcrossGap(), scGabombaStatueGetToothPos(), scJupiterLighthouseRestartSpark(), scLemurianShipDeckEmitSparkle(), scLemurianShipDrawLightToOrb(), scMarsLighthouseTowersPushPipeOrJump(), scWorldMapSpawnParticle(), syMatrixRotate(), syMatrixRotateTranslate() and syMatrixRotateTranslateScale().

Definition at line 8 of file macros.h.

SET_POSITION

#define SET_POSITION(p, newX, newY, newZ)

Sets the position or the velocity of a particle, a piece of debris or an actor in one statement.

Referenced by btCameraUpdate(), btEffectRunAnnihilation(), btEffectRunAstralBlast(), btEffectRunAttackSlash(), btEffectRunAzul(), btEffectRunBurstShower(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunCoatlicue(), btEffectRunCriticalHit(), btEffectRunCruelRuin(), btEffectRunCrystal(), btEffectRunCybele(), btEffectRunDjinnBeams(), btEffectRunDjinnHeal(), btEffectRunDjinniCharge(), btEffectRunDjinniEntrance(), btEffectRunDjinniSign(), btEffectRunDragonCloud(), btEffectRunDrainMotes(), btEffectRunEclipse(), btEffectRunFire(), btEffectRunFlurry(), btEffectRunFrost(), btEffectRunFroth(), btEffectRunGaia(), btEffectRunGaspFamily(), btEffectRunGatheringLights(), btEffectRunGround(), btEffectRunHaunt(), btEffectRunHealingMotes(), btEffectRunLeapingStrike(), btEffectRunLightSurge(), btEffectRunLiquifier(), btEffectRunLobbedShells(), btEffectRunMegiddo(), btEffectRunNirvana(), btEffectRunProcne(), btEffectRunProjectileVolley(), btEffectRunRadiantFire(), btEffectRunRay(), btEffectRunSabreDance(), btEffectRunSerac(), btEffectRunShiningStar(), btEffectRunSoulShatter(), btEffectRunStarfieldFall(), btEffectRunStarMine(), btEffectRunStarSwarm(), btEffectRunStatBoost(), btEffectRunStreakVolley() and 72 more.

Definition at line 12 of file macros.h.

SET_VELOCITY

#define SET_VELOCITY(p, vx, vy, vz)

Referenced by btEffectPosAdvanceWithGravity3D(), btEffectRunDragonCloud(), btEffectRunEruption(), btEffectRunFire(), btEffectRunFlurry(), btEffectRunFroth(), btEffectRunGaia(), btEffectRunGatheringLights(), btEffectRunLobbedShells(), btEffectRunStarfieldFall(), btEffectRunStreakVolley(), btEffectRunSwirlingStars(), fdActorResetTargetsAndVelocity(), fdActorSetPosAndResetMotion(), scActorPark() and scActorStopWhereItStands().

Definition at line 14 of file macros.h.

CLAMP

#define CLAMP(v, low, high)

Keeps v within low to high, the low bound tested first. A plain block, so it cannot stand before an else.

Referenced by btEffectBuildWindowEdgeTable(), btEffectDrawClippedCanvasLine(), btEffectRunCastingImpact(), btEffectRunCriticalHit(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunEruption(), btEffectRunFire(), btEffectRunFroth(), btEffectRunGaia(), btEffectRunHealingMotes(), btEffectRunJudgment(), btEffectRunProcne(), btEffectRunStarfieldFall(), btEffectRunStarSwarm(), btEffectRunStatBoost(), btEffectRunSwirlingStars(), btEffectRunVoidBeam(), btEffectUpdatePhasePalette(), btEnemyAdjustLevel(), btUnitStrengthen(), fdEncounterCountStepsAndSelectFormation(), fdScriptShowMessageAtPos(), gmUnitCalculate(), mnColorScaleComponents(), mnDjinnMenuShowMemberStatus(), mnMessageType(), mnWindowColorApply() and scGabombaStatueFadeByDepth().

Definition at line 19 of file macros.h.

ABS

#define ABS(v) ((v) < 0 ? -(v) : (v))

The magnitude of v. v is read twice.

Referenced by btEffectDrawClippedCanvasLine(), btEffectRunProjectileVolley(), btPartyInsertUnitCentered(), fdActorIsBeside(), fdActorIsTouching(), fdActorPlaySoundInView(), fdActorUpdateWalkingControl(), fdDjinnRunBattleStartHop(), fdLuckyWheelsDrawCanvasLine(), fdMapGridCenterOnFollowedPoint(), fdMeasurePsynergyHeight(), fdMeasurePsynergyReach(), fdSuperLuckyDiceRun(), fdWorldMapSetWindowMetatileTile(), mnEndingImageScroll(), scActorIsAbove(), scActorRollAndCrumble(), scMarsLighthouseEntranceWaitForDragonFace(), scPushTargetFillRectangle(), scPushTargetFindStop(), scPushTargetPush(), scWorldMapUpdatePlacedActors(), scYampiDesertCaveFindLogRoll(), scYampiDesertCavePushLog() and scYampiDesertCaveSetLogMetatiles().

Definition at line 28 of file macros.h.

ARRAY_COUNT

#define ARRAY_COUNT(array) (sizeof(array) / sizeof((array)[0]))

The entries of an array whose size is declared, as pret's global.h has it.

Referenced by btEffectCountDownBattlerTints(), btEffectRunBladeRain(), btEffectRunBurstShower(), btEffectRunCards(), btEffectRunCatastrophe(), btEffectRunCoatlicue(), btEffectRunDiamondBerg(), btEffectRunDjinniEntrance(), btEffectRunDouse(), btEffectRunElementBurst(), btEffectRunFlurry(), btEffectRunFrost(), btEffectRunFume(), btEffectRunGaspFamily(), btEffectRunHaures(), btEffectRunHurricane(), btEffectRunJudgment(), btEffectRunKirin(), btEffectRunLightSurge(), btEffectRunMegaera(), btEffectRunMegiddo(), btEffectRunMeteorBlow(), btEffectRunMoloch(), btEffectRunOdyssey(), btEffectRunPlumeEdge(), btEffectRunProcne(), btEffectRunProjectileVolley(), btEffectRunRagingHeat(), btEffectRunRamses(), btEffectRunRisingDragon(), btEffectRunRisingDragonEnemy(), btEffectRunSerac(), btEffectRunStarfieldFall(), btEffectRunTargetBursts(), btEffectRunTargetStrike(), btEffectRunWaterSheet(), btEffectRunWyrdCurse(), btFormationSelectLevelMatchedCandidate(), btLinkBattleSendParty(), btSpriteDetachScripts(), fdBattleEffectUpdateAllEffectSlots(), fdCycloneCopyTouchedMetatiles(), fdDjinnRunJupiterJoinEffect(), fdDjinnRunMarsJoinEffect(), fdDjinnRunMercuryJoinEffect(), fdDjinnRunVenusJoinEffect(), fdEffectReleaseSlots(), fdEffectUpdateAllSlots(), fdEncounterCountStepsAndSelectFormation(), fdEncounterSelectMapZones() and 28 more.

Definition at line 31 of file macros.h.

NEXT_HALFWORD

#define NEXT_HALFWORD(i) ((Sint32)(((i) << 16) + (1 << 16)) >> 16)

One more than i as a signed halfword, the step taken in the high half of a word: the scenes step the halfword counters of their short searches so, as scPushTargetFillRectangle does.

Definition at line 36 of file macros.h.

LATE_DATA

#define LATE_DATA __attribute__((section(".data.late")))

A scene's data that its overlay places after pictures linked between its tables: the overlay's linker script places .data.late after the first of them and .data.last after the next.

Referenced by ActorPlacements, ALIGNED, AnemosInnerSanctumDullahanCues, AnemosInnerSanctumDullahanDragonStatueScript, AnemosInnerSanctumDullahanEmptyCues, AnemosInnerSanctumDullahanEmptyPlacements, AnemosInnerSanctumDullahanPlacements, AquaRockCues, AquaRockPlacements, AquaRockSlopesCues, AquaRockSlopesPlacements, AquaRockSlopesRegions, AquaRockSummitCues, AquaRockSummitPlacements, AquaRockSummitRegions, ChampaCliffCavesChaseToEastScript, ChampaCliffCavesChaseToNorthScript, ChampaCliffCavesChaseToSouthScript, ChampaCliffCavesChaseToWestScript, ChampaCliffCavesCloseDoor, ChampaCliffCavesCloseDoorFrames, ChampaCliffCavesForgeCues, ChampaCliffCavesForgePlacements, ChampaCliffCavesForgePlacementsAfterAvimander, ChampaCliffCavesForgePlacementsBriggsHome, ChampaCliffCavesLowerCues, ChampaCliffCavesLowerPlacements, ChampaCliffCavesLowerPlacementsAfterAvimander, ChampaCliffCavesLowerPlacementsBriggsHome, ChampaCliffCavesMiddleCues, ChampaCliffCavesMiddlePlacements, ChampaCliffCavesMiddlePlacementsAfterAvimander, ChampaCliffCavesMiddlePlacementsBriggsHome, ChampaCliffCavesOpenDoor, ChampaCliffCavesOpenDoorFrames, ChampaCliffCavesUpperCues, ChampaCliffCavesUpperPlacements, ChampaCliffCavesUpperPlacementsAfterAvimander, ChampaCliffCavesUpperPlacementsBriggsHome, ClearImportedKeyItems, ClearImportedMembers, ClearImportedStackItems, ClearPasswordFlags, ClearPasswordKeyItems, ClearPasswordMembers, ClearPasswordStackItems, DOOR_EDIT, FieldEffectDurationScripts, GabombaStatueAkafubuComesUpScript, GabombaStatueChannelSeeds and 155 more.

Definition at line 41 of file macros.h.

LAST_DATA

#define LAST_DATA __attribute__((section(".data.last")))

Definition at line 42 of file macros.h.

ALIGNED

#define ALIGNED(n) __attribute__((aligned(n)))

Data aligned as the ROM places it, where its own type would not.

Definition at line 45 of file macros.h.

BSS_DATA

#define BSS_DATA __attribute__((section(".bss")))

A global kept in its object's .bss in the order written, where a plain one would be a common symbol the linker places in an order of its own.

Definition at line 49 of file macros.h.