| Routines

F4E6: Make a character flip a light switch on or off occasionally

Used by the routine at F5CE. If the character is standing next to a light switch, this routine makes him flip the switch off (if it's on and affects the lights in more than one window or window-pair), or consider flipping the switch on (if it's off and affects the lights in only one window or window-pair).
Input
H | Character number (0xD7-0xE5)
F4E6 | CALL $F436 | Is the character standing next to a light switch?
F4E9 | RET Z | Return if not
F4EA | BIT 5,A | Reset the zero flag if the light switch affects the lights in more than one window or window-pair
This entry point is used by the routine at F5A0.
F4EC | LD A,(BC) | A=window flags
F4ED | JR NZ,$F4F5 | Jump if the light switch affects the lights in more than one window or window-pair
F4EF | BIT 5,A | Is the light switch in the 'on' position?
F4F1 | RET Z | Return if so
F4F2 | JP $F491 | Flip the light switch on 109 times out of 256
F4F5 | BIT 5,A | Is the light switch in the 'off' position?
F4F7 | RET NZ | Return if so
F4F8 | JP $F4A6 | Flip the light switch off