The battle action state machine owns the order of a turn and almost none of its arithmetic. Range tests, damage rolls, the escape roll, AI picks, effect and summon spawns, camera framings and voice cues all live in helper routines it calls, or that run beside it each frame. This page is the map of those helpers: what each reads and writes, and the constants it carries.
0x801CE818; a few in SCUS_942.540x8007BD24: ctx[7] is the action state, ctx[+0x13] the acting slot0x801C9370, eight slots: 0..2 party, 3.. monstersDAT_8007BD10[slot], 1-based: Vahn, Noa, Gala, and 4 the AI companion0x801F69D8 where cast modules page inengine-battle-vm::battle_action, battle_formulas, battle_cam_script; world glue in engine-core::world::battle0x801CE818); the range metric, stat aggregator, XA player and loader B are in the main executable. Every scan pairs the status halfword with the liveness halfword, because a dead actor is only one whose HP reads zero.FUN_8004E2F0 answers “is the attacker close enough” for the attack chain and for the animation tick’s root-motion gate. It returns a 16-bit distance, and zero means in range.
+0x34 / +0x38 against the target’s seat pair +0x3C / +0x40.+0x1F. Small classes compare against the thresholds {256, 384, 1024} at DAT_80078870; a larger class compares against size << 4, unsigned.DAT_80078878: {+43, 0, -53, -100} for roster ids 1 to 4. It is added to the distance, so a positive value is a shorter reach.Every capture-class hit goes through one of two sibling wrappers. Each draws an attacker roll and a defender roll, applies the element-affinity scale FUN_801DD864, then the closed-form finisher FUN_801DDB30.
| Wrapper | Stat mixed into both rolls | Fifth finisher argument | Party resist ladder |
|---|---|---|---|
FUN_801DD4B0 | INT-working +0x168 | 0 | runs: jewels, elemental guards, All Guard |
FUN_801DD6B4 | ATK-working +0x158 | 1 | skipped |
The fifth argument is the resist bypass: the finisher tests it once (bne a3,zero at 0x801DDBD4) and jumps past the whole party-defender block. That is the mechanism behind the boss casts that ignore elemental guards. The affinity scale still reads the caster’s element either way. Formulas: battle formulas.
One actor halfword, +0x16E, carries every condition. Its bits are pinned by the HUD icon selector’s priority ladder and by the appliers that set them.
| Bits | Condition |
|---|---|
0x0001 / 0x0002 | Venom / Toxic |
0x0004 | Stone |
0x0008 / 0x0010 / 0x0020 | Rot, one rolled limb |
0x0380 | AI delegation, always set as a group |
0x0400 / 0x0800 | Numb / Sleep |
0x1000 | Curse |
0x2000 and up | unused: no applier in the dumped corpus |
Three masks are read as units: 0xF84 gates a slot out of the selectable scans, 0x0F80 is what taking damage clears, and 0x0404 is the whole-actor inert test. There is no KO bit: a dead actor is one whose HP halfword is zero, which is why every consumer pairs the two.
The port keeps the word in two halves, the raw bits a cast writes and a typed tracker a hit’s status arm fills, and composes them back into one halfword for every reader. Retail reads the halfword whole everywhere, so each reader does too: the pickers, the Counterattack roll, the Auto fill, the HUD’s gauge colour and status element, the limb dimming and the cast modules’ seats. A reader of one half missed a Confuse the tracker held or a Curse a cast wrote; the off-disc differentials hold each one to the whole word.
FUN_801E791C decides a flee. Both sides score from speed plus how hurt they are, and each rolls rand() % score:
party_score = sum over party (SPD * 3) >> 1 + (maxHP - curHP) >> 4
enemy_score = sum over enemies SPD + (maxHP - curHP) >> 5
Escape Boost: roll_p += roll_p >> 1
Great Escape, a pre-emptive strike, or the forced-flee flag: roll_p = roll_e
FAIL iff not forced and (roll_p < roll_e or ctx[+0x287] != 0)
ctx[+0x287] is tested afterwards and still blocks the flee. That is why the Chicken King is assured escape from non-boss fights.ctx[+0x287] is not a counter-attack byte. Battle setup derives it as (DAT_8007BD60 >> 5) & 4, so it reads 0 or 4.ctx[+0x291] is re-copied from a cell the first round clears, so a pre-emptive strike’s unfailable compare lasts one round.FUN_801EED1C’s character-id-4 arm reads seat 0’s HP and status and writes seat 1’s queue. All three of its spell records carry applier classes, so the action state lands a companion heal the way it lands an item. Its physical leg redraws rand() % monster_count + 3 until the seat is alive.FUN_801F0450, which fills the same byte string a player would enter.FUN_801E9FD4); a delegated or confused monster re-rolls its target through FUN_801E7320 at the turn seed.The queue itself is on the action queue page.
| Routine | Role |
|---|---|
FUN_801DFDF8 | Public spawn into the effect pool (sprite animations) |
FUN_801D8DE8 | Raises a HUD text or chrome widget by element id |
FUN_801DEA50 | Steps the acting actor’s effect script and installs the move-power record |
FUN_801E09F8 | Counts outstanding effects; flies and lands projectiles. Its hit arm ORs +0x1DC and turns the victim toward the attacker |
FUN_801E0080 | Per-frame walker of the effect master and child pools |
FUN_801DF6B8 | The scaling damage-number popup |
FUN_8003EC70 | Loader B: pages a summon or cast module into slot B (raw index arg + 0x381) |
0x801F1ED4 / 0x801F2160 | Jump-table dispatch into the slot-B routine, by summon id or by effect class |
rand(), whatever impact selector it keeps. The loop runs once per draw, and each after-image ghost is a draw: a burning body with two ghosts sheds three times a lone body's puffs, as Astral Wave's charge shows. The port gates its burn sprites on the draw plan's verdict.0xFF byte of the landing list draws a streak ribbon on the victim. A flying slot draws the same ribbons at its head from its flight list. Thunder Break is the visible case: its victim stays blue under four lightning columns from the landing until the hit. A landing-list byte of 0x64 spawns a screen fade instead.The pool model is on the effect VM page; what a paged module does is on cast modules.
FUN_801D5854 is the pose driver: one presentation program per pose id 0..9, called with the acting slot. Three of its arms read the per-action style byte ctx[+0xD] through the same compare ladder: values 1 and 3 add half a turn of yaw, 2 and 3 tilt the pitch by 0x80 and store TR.y = 0x400. FUN_801D829C arms the eased tween every framing change goes through. The framings themselves are on battle stage and camera.
Nothing walks a combatant home after an action. Three helpers, plus the round start’s recentre, are what keep a formation in frame and its members out of each other’s way.
FUN_801EFE44) runs for every category but Run. It squashes a span over 0x800, then boxes only an Attack’s target (or its whole side for the group codes) and subtracts the box’s centre from every included actor, so a melee opens with its target on the stage origin. The round start’s FUN_801DB318 does the same over the whole formation.0x14 gives each bystander a heading a quarter turn off the attack line, on whichever side it already stands, and seeds a countdown from the melee monster’s size class. The action SM’s shared tail then steps those actors each pass until the countdown drains. Without it, an approach runs straight through a partner standing in the lane.FUN_80050BB8, driven by FUN_80051078 after the action SM) reads each pair’s radii - the seat stager writes 0x280 on a party seat, 0x400 on Terra’s, a monster’s size class << 5 - and nudges both live positions apart when their body pairs sit closer than a sixth of the summed radii. Neither routine reads the frame step, so the port runs it once a battle frame on either cadence.Ports: battle_action::seed_formation_recentre, arm_make_way and make_way_step in engine-battle-vm, and battle_separation::push_apart driven by World::tick_battle_separation.
_DAT_8007B910 is the live audio level, not screen brightness. The summon and capture arms ramp it down and back; two of those duck arms sit behind the scripted-fight flag and never run in an ordinary encounter.FUN_8003D53C: a grunt per normal move, a shout per Tactical Art chosen by FUN_8004C140, and a fanfare per Hyper Art.FUN_801F3990 fires the item and Spirit voice cue from the wait state 0x3D.The overlay also carries its own small PRNG (FUN_801D0290). It is a shape hash for the lightning ribbon emitter and feeds no gameplay roll - those draw the BIOS rand.
Every helper with its full read / write set, the leaf scans, the audio cue tables and the dump-alias list for the 0x801Fxxxx band are in docs/subsystems/battle-action-helpers.md.