Routines
 Prev: 62518 Up: Map Next: 62694
62597: Make a character flip a light switch off or on occasionally
Used by the routines at 62892 and 62976. If the character is standing next to a light switch, this routine makes him flip the switch on (if it's off and affects the lights in more than one window or window-pair), or consider flipping the switch off (if it's on and affects the lights in only one window or window-pair).
Input
H Character number (215-229)
62597 CALL 62518 Is the character standing next to a light switch?
62600 RET Z Return if not
62601 BIT 5,A Does the light switch affect lights in more than one window or window-pair?
62603 JR NZ,62626 Jump if so
This entry point is used by the routine at 62880.
62605 LD A,(BC) A=window flags for the character's location
62606 BIT 5,A Is the light switch here in the 'off' position?
62608 RET NZ Return if so
This entry point is used by the routine at 62694.
62609 CALL 61823 Get a random number in A
62612 CP 110 Is it greater than 109?
62614 RET NC Return if so
This entry point is used by the routines at 29052 and 30070.
62615 LD A,32 Bit 5 set: light switch toggle
This entry point is used by the routines at 30092 (with A=1 or 64), 30822 (with A=0) and 63209 (with A=1, 32 or 64).
62617 PUSH BC Push the address of the window flags onto the stack
62618 EX (SP),HL Transfer this address into HL
62619 XOR (HL) Flip bit 1, 5 or 6 of the window flags, thus flipping the light switch that affects the window, or raising or lowering the blind
62620 LD (HL),A
62621 CALL 62368 Update the SRB for the window
62624 POP HL Restore the character number to H
62625 RET
The character is standing next to a light switch that affects lights in more than one window or window-pair.
62626 LD A,(BC) A=window flags for the character's location
This entry point is used by the routine at 29052.
62627 BIT 5,A Is the light switch here in the 'on' position?
62629 RET Z Return if so
This entry point is used by the routines at 30070, 30822 and 62694.
62630 PUSH BC Push the address of the window flags onto the stack
62631 EX (SP),HL Transfer this address into HL
62632 LD A,C A=LSB of the address of the window flags
62633 LD BC,1056 B=4 (the four central windows on a floor of the hotel span four 8-tile wide segments), C=32 (bit 5 set: light switch toggle)
62636 CP 72 Are we dealing with a window that is second from the left in the hotel?
62638 JR NZ,62657 Jump if not
A light switch that affects the lights in the the four central windows on one of the floors of the hotel has been flipped.
62640 LD L,72 Point HL at the window flags for the leftmost of the four central windows
62642 PUSH HL Save the window flags pointer
62643 PUSH BC Save the segment counter
62644 LD A,(HL) Flip bit 5 of the window flags, thus flipping the light switch into the 'on' or 'off' position
62645 XOR C
62646 LD (HL),A
62647 CALL 62368 Update the SRB for the window
62650 POP BC Restore the segment counter
62651 POP HL Restore the window flags pointer to HL
62652 INC L Move to the next window along
62653 DJNZ 62642 Jump back until all four windows have been done
62655 POP HL Restore the character number to H
62656 RET
62657 CP 75 Are we dealing with a window that is second from the right in the hotel?
62659 JR Z,62640 Jump if so
A light switch that affects the lights in the windows on more than one floor of a building other than the hotel has been flipped.
62661 SUB C Subtract 32 from the LSB of the window flags address
62662 DEC B B=3 (there are three floors to consider)
62663 NOP
62664 LD E,A Point DE at the fixture location flags for the area on the fourth floor (if any) above the light switch
62665 LD H,186 The fourth floor window flags are in bytes 64-95 of page 186 (at 47680)
62667 LD A,(DE) Collect the fixture location flags for the fourth floor
62668 BIT 5,A Does the light switch affect any windows on this floor?
62670 JR Z,62685 Jump if not
62672 PUSH HL Save the window flags pointer
62673 PUSH DE Save the fixture location flags pointer
62674 PUSH BC Save the floor counter
62675 LD A,(HL) Flip bit 5 of the window flags, thus flipping the light switch into the 'on' or 'off' position
62676 XOR 32
62678 LD (HL),A
62679 CALL 62368 Update the SRB for the windows on this floor
62682 POP BC Restore the floor counter to B
62683 POP DE Restore the fixture location flags pointer to DE
62684 POP HL Restore the window flags pointer to HL
62685 INC H Point HL at the window flags for the next floor down
62686 LD A,E Point DE at the fixture location flags for the next floor down