| Routines

6390: Guide a character down a staircase

The address of this interruptible subcommand routine is placed into bytes 0x69 and 0x6A of a character's buffer by the routine at 63BE when the character has reached the top of a staircase he needs to descend to reach his destination.
Input
H | Character number (0x98-0xA9)
6390 | LD B,$01 | Signal that the character is going down a staircase
This entry point is used by the routine at 638C with B=0xFF.
6392 | LD L,$6B | Byte 0x6B of the character's buffer holds the number of movements remaining
6394 | DEC (HL) | Has the character finished going up or down the stairs?
6395 | JP Z,$62A4 | Terminate this interruptible subcommand if so
6398 | PUSH BC | Save the direction indicator (in B) briefly
6399 | CALL $6214 | Update the SRB for the character's current location
639C | POP BC | Restore the direction indicator to B
639D | LD C,A | C=character's current animatory state
639E | INC A | A=character's next animatory state
639F | BIT 0,A | Is the character midstride right now?
63A1 | JR Z,$63AB | Jump if so
The following four instructions calculate the character's next y-coordinate. The y-coordinate will be decremented if the character is going up the stairs and he's not midstride at the moment, incremented if he's going down the stairs and he is midstride at the moment, and otherwise unchanged.
63A3 | DEC D |
63A4 | INC B | Is the character going up the stairs?
63A5 | JR Z,$63A8 | Jump if so
63A7 | INC D |
At this point A holds the character's new animatory state, and DE his new location.
63A8 | JP $61B0 | Update the character's animatory state and location and update the SRB
The character is midstride. Now we calculate his next x-coordinate.
63AB | RLCA | Set the carry flag if the character is facing left
63AC | CCF
63AD | SBC A,A | A=0 (facing right) or -2 (facing left)
63AE | ADD A,A
63AF | ADD A,E | Set E equal to the character's new x-coordinate
63B0 | LD E,A
63B1 | INC E
63B2 | LD A,C | A=character's current animatory state
63B3 | INC A | A=character's next animatory state
63B4 | BIT 1,A | Will the character be standing (phase 3)?
63B6 | JR NZ,$63A4 | Jump if so
63B8 | SUB $04 | Adjust the animatory state to standing (phase 1)
63BA | JR $63A4 |