| Routines

F6E9: Make a character walk up or down

The address of this interruptible subcommand routine is placed into bytes 0x0E and 0x0F of a character's buffer by the routine at F748. It makes a character start or continue walking up or down towards his walkabout destination, stopping occasionally on the way to flip a light switch or raise or lower a window blind.
Input
H | Character number (0xD7-0xE5)
F6E9 | CALL $F698 | Exit now if the character is midstride
F6EC | BIT 2,(HL) | Is the character's arm raised?
F6EE | JP NZ,$F37B | Lower his arm if so
This entry point is used by the routine at 7A57.
F6F1 | LD L,$11 | The counter in byte 0x11 of the character's buffer determines the delay until the character will next consider flipping a light switch or raising or lowering a window blind
F6F3 | DEC (HL) | Decrement that counter
F6F4 | JR NZ,$F722 | Jump unless the counter has reached 0
F6F6 | LD (HL),$04 | Reset the counter to 4 (in case the character is not standing next to a light switch or window blind at the moment)
F6F8 | CALL $F6B0 | Is the character standing next to a light switch or window blind?
F6FB | JR Z,$F722 | Jump if not
The character is standing next to a light switch or window blind.
F6FD | CP $40 | Is the character standing next to a window blind?
F6FF | JR C,$F70A | Jump if so
F701 | LD A,(DE) | A=fixture location flags
F702 | BIT 5,A | Does the light switch affect the lights in more than one window or window pair?
F704 | JR NZ,$F722 | Jump if so (the character will not flip the switch)
F706 | LD A,$20 | Bit 5 set: light switch toggle
F708 | JR $F712 |
F70A | CP $08 | Set the zero flag if the character standing next to the right-hand window of a pair
F70C | LD A,$01 | Bit 0 set: right-hand window blind toggle
F70E | JR Z,$F712 | Jump if the character is standing next to the right-hand window of a pair
F710 | LD A,$40 | Bit 6 set: left-hand window blind toggle
F712 | CALL $F499 | Flip the light switch, or raise or lower the window blind
F715 | CALL $F17F | Get a random number between 0x20 and 0x9F in A
F718 | AND $7F
F71A | ADD A,$20
F71C | LD L,$11 | Reset the counter in byte 0x11 of the character's buffer to this number
F71E | LD (HL),A
F71F | JP $F33C | Raise the character's arm
The character will not be flipping any light switches or raising or lowering any window blinds at this stage of his walkabout.
F722 | LD L,$01 | Collect the character's x-coordinate from byte 0x01 of his buffer
F724 | LD A,(HL)
F725 | LD L,$10 | Byte 0x10 of the character's buffer holds his walkabout destination x-coordinate
F727 | CP (HL) | Has the character reached his walkabout destination?
F728 | JP Z,$F284 | Terminate this subcommand if so
F72B | JP C,$EBAE | Move the character right if he's still to the left of his destination
F72E | JP $EBBB | Otherwise move him left