Prev: F436 Up: Map Next: F4E6
F485: Make a character flip a light switch off or on occasionally
Used by the routines at F5AC and F600. 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 (0xD7-0xE5)
F485 CALL $F436 Is the character standing next to a light switch?
F488 RET Z Return if not
F489 BIT 5,A Does the light switch affect lights in more than one window or window-pair?
F48B JR NZ,$F4A2 Jump if so
This entry point is used by the routine at F5A0.
F48D LD A,(BC) A=window flags for the character's location
F48E BIT 5,A Is the light switch here in the 'off' position?
F490 RET NZ Return if so
This entry point is used by the routine at F4E6.
F491 CALL $F17F Get a random number in A
F494 CP $6E Is it greater than 0x6D?
F496 RET NC Return if so
This entry point is used by the routines at 717C and 7576.
F497 LD A,$20 Bit 5 set: light switch toggle
This entry point is used by the routines at 758C (with A=0x01 or 0x40), 7866 (with A=0x00) and F6E9 (with A=0x01, 0x20 or 0x40).
F499 PUSH BC Push the address of the window flags onto the stack
F49A EX (SP),HL Transfer this address into HL
F49B 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
F49C LD (HL),A
F49D CALL $F3A0 Update the SRB for the window
F4A0 POP HL Restore the character number to H
F4A1 RET
The character is standing next to a light switch that affects lights in more than one window or window-pair.
F4A2 LD A,(BC) A=window flags for the character's location
This entry point is used by the routine at 717C.
F4A3 BIT 5,A Is the light switch here in the 'on' position?
F4A5 RET Z Return if so
This entry point is used by the routines at 7576, 7866 and F4E6.
F4A6 PUSH BC Push the address of the window flags onto the stack
F4A7 EX (SP),HL Transfer this address into HL
F4A8 LD A,C A=LSB of the address of the window flags
F4A9 LD BC,$0420 B=4 (the four central windows on a floor of the hotel span four 8-tile wide segments), C=0x20 (bit 5 set: light switch toggle)
F4AC CP $48 Are we dealing with a window that is second from the left in the hotel?
F4AE JR NZ,$F4C1 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.
F4B0 LD L,$48 Point HL at the window flags for the leftmost of the four central windows
F4B2 PUSH HL Save the window flags pointer
F4B3 PUSH BC Save the segment counter
F4B4 LD A,(HL) Flip bit 5 of the window flags, thus flipping the light switch into the 'on' or 'off' position
F4B5 XOR C
F4B6 LD (HL),A
F4B7 CALL $F3A0 Update the SRB for the window
F4BA POP BC Restore the segment counter
F4BB POP HL Restore the window flags pointer to HL
F4BC INC L Move to the next window along
F4BD DJNZ $F4B2 Jump back until all four windows have been done
F4BF POP HL Restore the character number to H
F4C0 RET
F4C1 CP $4B Are we dealing with a window that is second from the right in the hotel?
F4C3 JR Z,$F4B0 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.
F4C5 SUB C Subtract 0x20 from the LSB of the window flags address
F4C6 DEC B B=3 (there are three floors to consider)
F4C7 NOP
F4C8 LD E,A Point DE at the fixture location flags for the area on the fourth floor (if any) above the light switch
F4C9 LD H,$BA The fourth floor window flags are in bytes 0x40-0x5F of page 0xBA (at BA40)
F4CB LD A,(DE) Collect the fixture location flags for the fourth floor
F4CC BIT 5,A Does the light switch affect any windows on this floor?
F4CE JR Z,$F4DD Jump if not
F4D0 PUSH HL Save the window flags pointer
F4D1 PUSH DE Save the fixture location flags pointer
F4D2 PUSH BC Save the floor counter
F4D3 LD A,(HL) Flip bit 5 of the window flags, thus flipping the light switch into the 'on' or 'off' position
F4D4 XOR $20
F4D6 LD (HL),A
F4D7 CALL $F3A0 Update the SRB for the windows on this floor
F4DA POP BC Restore the floor counter to B
F4DB POP DE Restore the fixture location flags pointer to DE
F4DC POP HL Restore the window flags pointer to HL
F4DD INC H Point HL at the window flags for the next floor down
F4DE LD A,E Point DE at the fixture location flags for the next floor down
F4DF ADD A,$20
F4E1 LD E,A
F4E2 DJNZ $F4CB Jump back until the windows on the fourth, third and second floors have been dealt with
F4E4 POP HL Restore the character number to H
F4E5 RET
Prev: F436 Up: Map Next: F4E6