Field Engine
This page is a guide to the games/tbs/src/field/ folder of the Alchemy
project. The field engine in it runs every non-battle scene in Golden Sun: The
Broken Seal, from walking through towns and dungeons to crossing the World Map.
At the centre of this folder is fdEngineRun, which coordinates up to 64 active
actors, wall-sliding physics, height-based terrain, field Psynergy, random
encounters, and Tolbi's Lucky Dice and Lucky Wheels minigames. Whenever Isaac
explores Vale, pushes a pillar in a dungeon, or talks to a villager, this code
is running.
Because so many parts share each frame, the field engine relies on strict event priorities and a ranked request queue. The sections below cover the tick order, the behaviour of actors and the World Map, and a full file map. The conceptual model is described in World, Scenes & Maps.
Event priorities and field requests
| Priority offset | Callback | Per-tick job |
|---|---|---|
+15 | fdPaletteFadeUpdate | Step active palette fades toward target |
+10 | fdActorUpdateAllOnField | Step every actor's SC_* script and physics |
+5 | fdMapGridUpdateLayerScroll (or fdWorldMapUpdateView) | Follow camera actor and scroll map layers |
+0 | fdActorSystemPlaceSprites (or fdActorSystemProjectSprites) | Submit actor sprites to OAM depth buckets |
+0 | mnWindowSystemUpdate | Animate windows and type dialogue |
+0 (if animated) | fdTilesetAnimationUpdate | Repaint animated map tiles on timers |
| VBlank pass | mnWindowSystemUploadTilemap | Copy window tilemap to VRAM |
Running actors (+10) before camera scroll (+5) and sprite placement (+0)
keeps Isaac locked to the camera instead of lagging a tick behind.
Between ticks, fdEngineRun services requests recorded in FieldStateWork in
strict priority order:
- Exit
- Engine or scene override (e.g., poison fainting)
- Random battle (in TBS, checked before step and push)
- Step cue on the current metatile
- Push into a ledge, ladder, or door (after consecutive blocked ticks)
Abutton (resolves to talk, examine, or field menu)- Field menu (
SelectorAfacing nothing) - Talk to nearest actor roughly in front
- Examine metatile ahead
- Field Psynergy
- Field item
- Pause menu (
Start)
Actors, World Map, encounters, and minigames

- Actors (
ActorsWork): 64 active slots map from 66 scene actor IDs (0–7for characters,8–65for placements). Most NPCs select one of 7 stock scripts inactor_scripts.c(MovementTypeWanderScript, etc.), and targeting opcodes act on the actor's watched actor.vault.ccontains a short custom script (the boy running around Vault's well). - Movement, collision, and targeting:
SC_PLAYEReases acceleration and braking, probing 8 pixels ahead plus angled side probes (±22.5°,±45°, and up to±67.5°) so that Isaac slides along walls. It steps up at most 8 px, drops at most 12 px, and matches talk targets within 32 px (beyond 11 px, roughly in front). - World Map and map screen:
world_map_lines.c(ARM in IWRAM) writes per-scanline affine parameters across all 160 lines while streaming four 512×512 chunks at a time.Ropens the flat chart (map_screen_markers.c), scaling each visited area's own World Map coordinates directly onto the chart. - Random battles and overworld steps:
encounter_rules.sselects one zone for each of the 7 terrain types on scene load. Every 10 metatiles outside towns restores PP and ticks poison. - Tolbi minigames: Standalone engines
ENGINE_LUCKY_DICE(lucky_dice.c) andENGINE_LUCKY_WHEELS(lucky_wheels.c).
File map
| File(s) | Role |
|---|---|
field.c, field_internal.h | Parent translation unit #includeing the field_*.c parts below in ROM order |
field_actors.c, field_actor_motion.c, field_actor_camera.c, field_player_control.c | 64-actor table, eased movement, camera tracking, and SC_PLAYER collision and wall-sliding |
field_map_grid.c, field_terrain.c, field_tile_animation.c, field_world_map.c | Map loading, height shapes, animated tiles, and World Map chunk streaming and view |
field_decompress.c, field_sprite_animation.c, field_sprite_draw.c, field_view.c | Field graphics decompression, sprite animation, OAM placement, and sprite viewer |
field_engine.c, field_engine_internal.h, field_engine_run.c, field_engine_walking.c | fdEngineRun setup, walking loop, and request dispatcher |
field_engine_cues.c, field_engine_actors.c, field_engine_targets.c, field_engine_encounter.c | Cue table scanning, actor spawning, talk and examine targeting, and random encounters |
field_engine_psynergy.c, field_engine_items.c, field_engine_item_display.c, field_engine_treasure_spots.c | Field Psynergy and item triggers, found-item displays, Reveal sparkles, and chest spots |
field_engine_speakers.c, field_engine_palette_fade.c, field_engine_screen_transition.c, field_engine_palette_editor.c | Dialogue portraits, fades, screen transitions, ground mask, and debug palette editor |
script_commands.c, script_commands_*.c | Blocking and non-blocking C script commands and all TBS field Psynergy implementations |
actor_scripts.c, field_script_commands.c, facing.c | SC_* bytecode interpreter, stock movement scripts, and 5-direction facing tables |
actor_update_arm.c, world_map_lines.c, map_grid_convert.s, picture_decode.s | Hot ARM and IWRAM routines for actor ticks, World Map scanlines, and map and sprite decoding |
scenes.s, map_grid_data.c, encounter_*.{s,c}, music_rules.s, *_rules.{s,c}, map_screen_markers.c | ScenesWork (201 scenes), MapsWork, and rule tables for areas, encounters, music, restarts, and map markers |
lucky_dice.c, lucky_wheels.c, stubs.s, engine_stubs.s, lucky_*_stubs.s | Tolbi minigames and module stub tables |
Source files
| File | Description |
|---|---|
actor_placement.c | The party leader's actor placement, which fdActorResetForLeader copies before a scene places its own actors, and the script it gives the leader. |
actor_script.c | Actor scripts: the ones the field starts itself, and the command table. |
actor_script_operands.c | Script state values: the handler SC_SET, SC_ADD and SC_CMP call for each. |
actor_scripts.c | The actor scripts the field's commands start: walking off and turning to face a set way, the dust puffs, the emote bubble's pop and the movement types fdActorSetMovementType starts by number; and, among them, the glyphs a message types before its speaker's first voice blip. |
actor_update_arm.c | Unused: an ARM copy of the actors' update, made to run from RAM. |
battle_background_rules.c | The battle background of each scene (fdBattleBackgroundSelectForMap). |
battle_music.c | The music a battle plays: the bosses, the guards of Crossbone Isle, the Colosso finals and the fights with Saturos have their own, and every other battle plays the usual battle music. |
encounter_zones.c | The 104 encounter zones, by zone number. |
facing.c | Which picture a sprite shows for the way it faces, and the small tables the actors read as they move: the direction pad's headings, the World Map camera's lean, a floating actor's bob, how long a footprint lasts and the order a sprite dissolves in. |
field.c | The field object: the code that draws and moves everything in towns, dungeons and the world map. |
field_actor_camera.c | The actor cameras, which place every actor's sprite each tick. |
field_actor_motion.c | Actor motion, each tick, and the first actor script commands. |
field_actors.c | The field's actors: the 64 slots and creating and releasing them, starting them on their scripts, setting their sprites' animations and looks, and dissolving sprites pixel by pixel. |
field_decompress.c | LZ decompression. |
field_effect_tables.c | A field Psynergy's cast colours, and two script tables of the field effects. |
field_engine.c | The field engine's object: random encounters, a field scene's actors, the leader's walking and the requests they raise, fdEngineRun, the scene's cues, using items and Psynergy on the field, the map's treasure spots, and the screen transitions and palette fade that the field and battles share. |
field_engine_actors.c | The party's sprites, placing a scene's actors, and the actor slots. |
field_engine_cues.c | Finding and running a scene's cues: talking, step cues, examine cues. |
field_engine_encounter.c | Random encounters, and each scene's music, area name and battle background. |
field_engine_ground_mask.c | The ground mask: raised ground in front of an actor hides the part of it behind, as a ledge in the Kalay Tunnel's treasure room hides Isaac's legs. |
field_engine_internal.h | What every part of field_engine.c shares: its includes and the macros and types more than one part uses. |
field_engine_item_display.c | Showing a found item, and Reveal's sparkles on hidden things. |
field_engine_items.c | Using an item on the field. |
field_engine_palette_editor.c | The debug palette editor. |
field_engine_palette_fade.c | The palette fade: palettes moved toward target colours. |
field_engine_psynergy.c | Using Psynergy on the field. |
field_engine_run.c | The field engine: running a scene until the party leaves it, and its entrance. |
field_engine_screen_transition.c | How a scene fades in and out: from or to black or the backdrop colour, through windows that open or close over the screen line by line, from or to the centre line, or by a dissolve, which no scene uses. |
field_engine_speakers.c | Speaker definitions: voices and Halted lines by sprite. |
field_engine_tables.c | The field engine's tables: the actor scripts its effects run, the colour curves of the palette tints, and the lookup tables of its transitions, speakers, weather and Psynergy. |
field_engine_targets.c | The actor a field Psynergy or item aims at, and the helpers that follow it. |
field_engine_treasure_spots.c | The map's treasure spots: chests and Psynergy Stones. |
field_engine_walking.c | Field requests and each tick of the leader's walking: exits, encounters, damage. |
field_internal.h | What every part of the field object shares: its includes and the few names more than one part uses. |
field_map_grid.c | Layered maps: loading, drawing and scrolling, and copying metatiles. |
field_player_control.c | Player control: the configured keys and moving actors by the pad. |
field_script_commands.c | Actor script commands: waits, jumps, flags, moves and state values. |
field_sprite_animation.c | Sprites, their animations and the picture caches they draw from. |
field_sprite_draw.c | Drawing sprites: composing their animations and placing them on screen. |
field_sprite_viewer.c | The debug sprite viewer: one sprite shown once for each way it can face, in a ring, with up to four sprite animations laid over it and the keys to change each one's sprite, animation, priority and colour mode. |
field_terrain.c | Ground heights, and the collision of metatiles and the world map. |
field_tile_animation.c | Timed map changes: the tileset animations that redraw a map's tiles in turn, the blend script that changes over time how its layers blend, and the palette cycles, which nothing starts. |
field_view.c | The screen shake, and two parts of the world map's view: its still image drawn from its tile maps, and its ground tilted away from the camera, worked out a screen line at a time. |
field_world_map.c | The world map: its perspective view, its tiles, and the still image of the view BG1 shows while a menu or script runs. |
lucky_dice.c | Lucky Dice, the dice game in Tolbi, drawn with the battles' 3D camera. |
lucky_wheels.c | Lucky Wheels, Tolbi's game of chance: the player bets game tickets on paylines, pulls the lever up to five times and locks wheels between pulls to line up matching symbols. |
map_grid_data.c | Map ground: the height curve of each metatile kind and the world map's battle environments. |
map_screen_markers.c | The map screen's markers (fdMapScreenShow). |
palette_scale.c | The fade of the Lucky Dice and Lucky Wheels screens, which darken and brighten by scaling their palettes; each game's object includes it. |
screen_transition_shapes.c | The window shapes of WINDOW_TRANSITION_SHAPE, one for each step of its progress (fdScreenTransitionUpdateScanlineTable): a clock wipe, a wedge from the screen's centre (120, 80) that sweeps round from twelve o'clock, over the right half in the first 16 steps and the left half in the next 16. |
script_commands.c | The field Psynergy and script command object: the commands scripts run (waits, items, questions, destinations, actors, messages and the camera), moving on the field (views, jumps and climbing), the field's weather and line scrolls, Djinn joining the party, each field Psynergy, the field effect sprites its particles use, and the map screen. |
script_commands_actor_commands.c | Script commands on actors: placing, moving and animating them. |
script_commands_arcs.c | The golden rings that swell around a caster and rise up its body: each ring is two arcs of SPRITE_GOLDEN_RINGS, its back half behind the caster and its front half, the same arc upside down, in front. |
script_commands_avoid.c | Avoid: the caster spins among falling arcs and flashes, and monsters attack less often until it wears off. |
script_commands_camera.c | The camera a script moves: following an actor, panning to a point kept inside the map, and waiting for it to arrive. |
script_commands_carry.c | Carry: two hands lift the target, move it with the d-pad and drop it. |
script_commands_catch.c | Catch: a hand reaches out from the caster, grabs what is ahead and takes it off the map. |
script_commands_climbing.c | Jumping and climbing on the field. |
script_commands_cloak.c | Cloak: the leader blinks into a dark outline and stays hidden while it walks on metatiles that allow it (METATILE_BEHAVIOR_CLOAK). |
script_commands_djinni.c | A Djinni's hop before its battle, a Djinni joining the party, and the field effect sprites the joining lights are drawn with. |
script_commands_douse.c | Douse: a rain cloud floats out over the target and rains on it, then shrinks back into the caster. |
script_commands_exit_animations.c | An actor's screen position, the encounter transition, and the leader leaving through an exit and arriving. |
script_commands_field_particles.c | Field effect sprites: the particles field Psynergy moves and draws. |
script_commands_field_psynergy.c | Running a field Psynergy by its kind, and helpers its kinds share. |
script_commands_field_psynergy_state.c | A field Psynergy's state: setting it up, its caster and target, cleaning up. |
script_commands_force.c | Force: a fist flies out from the caster and knocks what it hits back a metatile. |
script_commands_frost.c | Frost: snowflakes spiral in on the target, and a puddle freezes into an ice pillar. |
script_commands_ground_particles.c | The ground particles (rain) start and the floating motes' update. |
script_commands_growth.c | Growth: green sparks fly from the caster, and a sprout grows tall. |
script_commands_halt.c | Halt: a stopwatch flies out to the target, ticks and bursts into sparkles, and the target stands frozen, its colours flickering. |
script_commands_internal.h | What every part of script_commands.c shares: its includes and the macros and types more than one part uses. |
script_commands_jupiter.c | A Jupiter Djinni joining the party, and the first of the Mars Djinni's functions, linked after it: its shrinking and its sparks. |
script_commands_lift.c | Lift: two hands grip the target and raise it, and Force's flashes and heavy impact, linked beside it. |
script_commands_line_scroll.c | The line scroll: per-line scroll offsets fed by HBlank DMA. |
script_commands_map_screen.c | The map screen R shows on the World Map: its area markers, the cursor and the name of the area nearest it. |
script_commands_mars.c | A Mars Djinni joining the party, and the first of the Venus Djinni's functions, linked after it: its shrinking, its falling motes and its rising particles. |
script_commands_mercury.c | A Mercury Djinni joining the party. |
script_commands_messages.c | The scene scripts' speech: a message window opened beside the actor who speaks, with the speaker's portrait, a yes-or-no question, two speakers at once, and the speaker's voice. |
script_commands_mind_read.c | Mind Read: scanline waves, shifting colours and flowing particles. |
script_commands_motes.c | Weather drawn in sprites on the field, and the storm's lightning: floating motes, rising sparkles, and the flashes of the palettes. |
script_commands_move.c | Move: a hand pushes the target, steered with the d-pad. |
script_commands_movement_types.c | Actor scripts: moving, turning and the built-in movement types. |
script_commands_ply.c | Ply cast in the field: eight winged figures spiral into one, which flashes, sheds sparks and flies off. |
script_commands_requests.c | Battles and destinations a script requests, and the queued sound. |
script_commands_retreat.c | Retreat, the caster spinning away in a spray of sparks, and the golden rings that fall round the caster of Avoid. |
script_commands_reveal.c | Reveal: the world turns grey but for a rippling window round the leader, which ends when the leader walks out of it or its time runs out. |
script_commands_scripts.c | Script commands: waits, received items, questions and destinations. |
script_commands_venus.c | A Venus Djinni joining the party. |
script_commands_view.c | The view bounds, zoom transitions and actors that ride another. |
script_commands_weather.c | The weather on the field: the rain splashing round the leader and the lightning of the storm over Vale. |
script_commands_whirlwind.c | Whirlwind: an orb flies from the caster and spins up a ring of leaves that blows its target away. |
sprite_color_tables.c | The colour tables of the sprite colour modes (SPR_COL_MODE) that remap a pixel's colour, 256 bytes each: five that swap a sprite's colour channels, SPRITE_COLOR_GRB to SPRITE_COLOR_BRG (also used by fdSpritePictureCacheLoad for variants 1 to 5), then the grey one and the blue, red and green tints. |
sprite_viewer_scale.c | Unused: the scale of the debug sprite viewer's ring of sprites, which nothing in the game opens (field_sprite_viewer.c). |
terrain_tables.c | The ground's shape inside a metatile for two of its height kinds (enum TERRAIN_KIND): where a raised or sunken square rounds off at its corners, and which of three heights each pixel takes, split along two diagonals. |
world_map_encounter_rules.c | Where the World Map's random battles come from: each region of the map, and its forests, take their own encounter zone. |
world_map_lines.c | The World Map's tilt: each line of the screen draws the flat map at its own scale and turn, so the ground seems to stretch away to a horizon. |
world_map_resources.c | World map graphics: a palette and five tilesets for each of its two looks, the second the snowfield's (fdWorldMapLoadGraphics). |
| File | Description |
|---|---|
actor.h | Actors, the actor snapshot, and the screen transition styles. |
actor_script.h | Actor scripts: one Sint32 command word, then its operands, as ActorScriptCommandTable runs them. |
actor_update_arm.h | The unused ARM copy of the actors' update (actor_update_arm.c), and ACTOR_ARM_VIEW, ACTOR as GCC 2.95.2 reads it. |
curve.h | The step counts, value shift, and per-pixel tables of the terrain height curves (terrain_tables.c). |
emote.h | What an actor shows over it: the bubbles of fdActorShowEmoteById and the effects fdEffectSetAttached attaches. |
encounter_zone.h | The encounter zones. |
engine_stubs.h | The field engine module's stub calls: the commands scripts are written in (actors, messages, camera, destinations), field Psynergy, weather and the field's effects. |
facing.h | The constant tables of facing.c: which picture of an animation an actor shows for each way it faces, and beside them the sprite dissolve's pixel order, the fixed camera's matrix, a floating actor's bob, the actor scripts' end script and the World Map camera's lean for the direction pad. |
field.h | The field engine's shared functions, globals and actor scripts. |
field_blend.h | FIELD_BLEND_STATE, the field's colour blend state. |
field_coordinate.h | FIELD_COORDINATE, a position on the field. |
field_effect.h | Field effects, their scripts and the flags that spawn them. |
field_effect_scripts.h | The actor scripts field effects give their particles and fragments. |
field_engine.h | What the field engine's object (field_engine.c) defines for the code outside it: encounters, the field's actors, the leader's walking, the scene's cues, treasure spots, screen transitions and the palette fade. |
field_engine_functions.h | The field-engine module's functions, declared in the order of its stub table. |
field_engine_script.h | The field engine's script functions (field_engine_items.c, script_commands_field_psynergy.c, script_commands_scripts.c and script_commands_messages.c). |
field_functions.h | The field module's functions, declared in the order of its stub table, without the tables and types field.h brings in. |
field_particle.h | The particles field Psynergy moves and draws, each with a sprite of its own. |
field_psynergy_state.h | FIELD_EFFECT_STATE, the state of a field Psynergy. |
field_state.h | FIELD_STATE, the running scene's state, with its treasure spots and the raised cues the field engine handles itself. |
ground_mask.h | The ground mask, which hides the parts of an actor that raised ground in front of it should cover. |
lucky_dice.h | Lucky Dice, the dice game in Tolbi (lucky_dice.c), and the small fixed-point helpers it keeps for its 3D camera. |
lucky_dice_stubs.h | Lucky Dice's entry point. |
lucky_wheels.h | Lucky Wheels, Tolbi's game of chance (lucky_wheels.c), and the unused LZ packer kept beside it. |
lucky_wheels_lzpack.h | The LZ packer's state: hash chains over a 1024-byte window, one chain per byte value, and the output it is building. |
lucky_wheels_stubs.h | The Lucky Wheels entry point. |
map_grid.h | Map grids: their metatiles, layers, animations and blend scripts, and the map grid state. |
particle.h | Particle and SCREEN_POINT, the positions animations move through. |
perspective.h | The world map's perspective view state. |
scene_tables.h | The scene table formats: entrances, exits, actor placements and cues, and the macros that write them. |
screen_transition.h | What the field engine's parts share with the files that define their tables: the item-display and Reveal scripts, the palette fade's colour curves, and the screen transitions' shapes, tables and window values. |
script.h | The calls scripts are written in: the constants and small inlines a scene's scripts share, over the main-image functions they call by those functions' own names (fdScriptStart, fdActorJump, fdScriptSetMessageId and the rest), whose declarations it includes. |
script_commands.h | What script_commands.c declares for the files that use it: the commands scripts run, moving on the field, weather and line scrolls, Djinn joining the party, each field Psynergy and its effects, and the map screen. |
script_inline.h | The script inlines: one typed inline for each script command a script calls by its own name, passing it on to the main image's import (fdActorFaceEachOther calls fdActorTurnToFaceEachOther). |
script_operands.h | The actor script interpreter and the operands its commands read. |
speaker.h | The speaker lookup's view of an actor's sprite, the speaker definitions, and the palette fade's heap slot. |
sprite.h | Animated sprites: their layers, pictures and colour modes, and the resource slots they draw from. |
stubs.h | The field module's stub calls: actors and their sprites, movement, and the map and world map. |
weather.h | The ground particles, motes of light and sparkles that the weather state holds. |
world_map_affine.h | The world map's scanlines and affine lines. |
world_map_encounter_rules.h | Which encounter zone each part of the World Map takes, and the Djinn battles' formations. |