Wikifang:Telefang 1 Translation Patch/State Machine

From Wikifang, a definitive guide to Telefang, Dino Device and Bugsite
Jump to: navigation, search

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[edit]

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

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

Title Menu[edit]

State ID. Impl. ROM Addr Disassembly Symbol
$03 00 Load CGB Palette 0
$03 01 Initialize phone graphics & sprites
$03 02 Load initial menu tilemaps & initialize menu state
$03 03 Load tilemaps for each individual menu option.
$03 04 Load color palettes for the menu.

Then, move the window and background layers in place for the upcoming animation.

$03 05 Final commit of palettes. On DMG, this state configures the legacy palette registers instead.
$03 06
$03 07 Animate the two halves of the phone scrolling in.
$03 08 Player input handling
$03 09 Start menu-scrolling-up animation.
$03 0A Menu-scrolling-up animation, frame 2.
$03 0B End menu-scrolling animation (either direction).
$03 0C Start menu-scrolling-down animation.
$03 0D Menu-scrolling-down animation, frame 2.
$03 0E Fade out screen, then transfer to overworld ($05 00)
$03 0F
$03 10
$03 11 Time input
$03 12
$03 13 Initialize naming input, clear string buffers.
$03 14 Name input
$03 15 Saves the input buffer to the player name buffer.
$03 16
$03 17
$03 18 (Called when you select "Sound" on the menu. More info required.)
$03 19
$03 1A
$03 1B
$03 1C Save-file overwrite warning
$03 1D
$03 1E
$03 1F Aliases state $03 01
$03 20 Denjuu nicknaming screen init
$03 21 Denjuu nicknaming palette fade-in
$03 22 Denjuu nicknaming input handler
$03 23 Denjuu nickname save
$03 24
$03 25