Wikifang:Telefang 1 Translation Patch/State Machine: Difference between revisions

From Wikifang, a definitive guide to Telefang, Dino Device and Bugsite
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:
|-
|-
| $1:D401 || W_Battle_4thOrderSubState || Fourth order state index (secondary)
| $1:D401 || W_Battle_4thOrderSubState || Fourth order state index (secondary)
|}
== System State Machine ==
Here's a breakdown of the sixteen first-order states in Telefang.
{| class="wikitable"
|-
! State ID. !! Impl. ROM Addr !! Disassembly Symbol !!
|-
| $00 || $2:5300 || || Intro logos.
|-
| $01 || $2:493F || || Title screen
|-
| $02 || $2:4000 || ||
|-
| $03 || $4:4000 || TitleMenu_GameStateMachine || Title menu (continue/new game/options/link)
|-
| $04 || $2:40BF || || Attract screen
|-
| $05 || $B:1EA1 || || Overworld
|-
| $06 || $1C:4000 || Encounter_GameStateMachine || Random, T-Fanger, and other plot-important encounters
|-
| $07 || $5:441B || || Battle system
|-
| $08 || $1D:4000 || Victory_ExternalStateMachine || Victory processing screens at end of battle (level-up, contact loss, game over)
|-
| $09 || $2:4B8B || || Status screen (used in a lot of places...)
|-
| $0A || $2:4824 || ||
|-
| $0B || colspan="3" style="text-align: center" | ''Aliases state $0C''
|-
| $0C || $4:45C0 || || Pause menu (contacts/index/save/dial etc)
|-
| $0D || $2:44CF || ||
|-
| $0E || $2:458E || ||
|-
| $0F || $1F:4000 || || Link communications (vs battle/trade/melo-d)
|}
|}

Revision as of 12:10, 22 July 2017

Telefang's primary game loop is structured as a state machine. Each iteration of the game loop executes a handful of predefined tasks, and then indexes a jump table to load other screens' code. This indexing can be recursive, with individual states running their own predefined tasks before jumping into sub-states. This is known to recurse to at least fourth-order state machines.

State machines are indexed through four primary SystemState variables, and two secondary state variables. The secondary state variables are used in certain states for various reasons - usually to prevent overwriting the state of another screen. (Why they didn't set up a proper state stack for this sort of thing is beyond me...)

WRAM Addr Disassembly Symbol
$C3E0 W_SystemState First order state index
$C3E1 W_SystemSubState Second order state index
$C3E2 W_SystemSubSubState Third order state index (primary)
$C3E3 (Not named) Fourth order state index (presumed primary, not yet seen in practice)
$1:D400 W_Battle_SubSubState Third order state index (secondary)
$1:D401 W_Battle_4thOrderSubState Fourth order state index (secondary)

System State Machine

Here's a breakdown of the sixteen first-order states in Telefang.

State ID. Impl. ROM Addr Disassembly Symbol
$00 $2:5300 Intro logos.
$01 $2:493F Title screen
$02 $2:4000
$03 $4:4000 TitleMenu_GameStateMachine Title menu (continue/new game/options/link)
$04 $2:40BF Attract screen
$05 $B:1EA1 Overworld
$06 $1C:4000 Encounter_GameStateMachine Random, T-Fanger, and other plot-important encounters
$07 $5:441B Battle system
$08 $1D:4000 Victory_ExternalStateMachine Victory processing screens at end of battle (level-up, contact loss, game over)
$09 $2:4B8B Status screen (used in a lot of places...)
$0A $2:4824
$0B Aliases state $0C
$0C $4:45C0 Pause menu (contacts/index/save/dial etc)
$0D $2:44CF
$0E $2:458E
$0F $1F:4000 Link communications (vs battle/trade/melo-d)