Prev: F104 Up: Map Next: F1AF
F107: Handler: Keys And Locked Doors
Used by the routine at Handler_Player.
Picks up the key at BC, blanks it, and reprints any previously held key.
Handler_KeysAndLockedDoors F107 PUSH IX Stash the player slot on the stack.
F109 LD IX,($5BDA) Point IX at *ReferenceKeysAndLockedDoors.
Handler_KeysAndLockedDoors_Loop F10D LD A,(IX+$00) Jump to Handler_Housekeeping if this key entry is the terminator (FF).
F110 CP $FF
F112 JR Z,Handler_Housekeeping
F114 LD A,(IX+$05) A=the key state.
F117 AND %00000010 Keep only bit 1 (key still in the room).
F119 JR Z,Handler_KeysAndLockedDoors_Next Jump to Handler_KeysAndLockedDoors_Next if this key has already been taken.
F11B LD A,(IX+$02) Jump to Handler_KeysAndLockedDoors_Next if the player is not in this key's column.
F11E CP C
F11F JR NZ,Handler_KeysAndLockedDoors_Next
F121 LD A,(IX+$03) Jump to Handler_KeysAndLockedDoors_CollectKey if the player is on this key's row.
F124 CP B
F125 JR Z,Handler_KeysAndLockedDoors_CollectKey
Handler_KeysAndLockedDoors_Next F127 LD DE,$0006 Move IX on to the next six-byte key entry.
F12A ADD IX,DE
F12C JR Handler_KeysAndLockedDoors_Loop Jump to Handler_KeysAndLockedDoors_Loop.
Collect this key and blank its graphic.
Handler_KeysAndLockedDoors_CollectKey F12E LD A,$06 Queue the collected-key sound at SoundFlag_General.
F130 LD ($FFFE),A
F133 LD (IX+$05),$01 Mark this key as taken.
F137 LD C,(IX+$02) C=the key's horizontal co-ordinate.
F13A LD B,(IX+$03) B=the key's vertical co-ordinate.
F13D LD E,$01 Set the blank sprite width/ height (01/ 02).
F13F LD D,$02
F141 LD A,$00 A=00.
F143 CALL WriteGameSpriteBuffer Blank the key in the game sprite buffer.
F146 LD HL,($5C36) HL=*CHARS.
F149 PUSH HL Stash the current character set pointer on the stack.
F14A LD HL,$9F6C Write 9F6C to *CHARS.
F14D LD ($5C36),HL
F150 LD A,$20 A=a blank character.
F152 CALL PrintSprite Print the blank over the key.
F155 POP HL Restore the original character set pointer from the stack.
F156 LD ($5C36),HL Write it back to *CHARS.
F159 LD A,(IX+$04) A=this key's ID.
F15C POP IX Restore the player slot from the stack.
F15E PUSH AF Stash the new key ID on the stack.
F15F LD A,(IX+$10) Jump to Handler_KeysAndLockedDoors_RestoreKey if *PlayerKeyHeld is empty.
F162 CP $00
F164 JR Z,Handler_KeysAndLockedDoors_RestoreKey
Drop the previously held key back into the room.
F166 PUSH IX Stash the player slot on the stack.
F168 CALL FindMatchingKey Find the table entry for the held key.
F16B LD HL,($5C36) HL=*CHARS.
F16E PUSH HL Stash the current character set pointer on the stack.
F16F LD HL,$8378 Write 8378 to *CHARS.
F172 LD ($5C36),HL
F175 LD A,$10 Set INK: *ActiveRoom_KeyColour.
F177 RST $10
F178 LD A,($5BCC)
F17B RST $10
F17C LD (IX+$05),$03 Mark that key as back in the room.
F180 LD C,(IX+$02) C=the dropped key's horizontal co-ordinate.
F183 LD B,(IX+$03) B=the dropped key's vertical co-ordinate.
F186 PUSH BC Stash the key position on the stack.
F187 CALL ConvertCoordinateToBufferOffset Convert it into a room-buffer offset.
F18A CALL $0DD9 Call CL_SET.
F18D LD A,(IX+$04) A=the dropped key's ID.
F190 ADD A,$41 A+=41 (key label; see Graphics_KeyLabels).
F192 CALL PopulateGameRoomBuffer Call PopulateGameRoomBuffer.
F195 RST $10 Print the key letter using RST PRINT_A_1.
F196 POP BC Restore the key position from the stack.
F197 DEC B Move one row down for the key stem.
F198 CALL ConvertCoordinateToBufferOffset Convert it into a room-buffer offset.
F19B CALL $0DD9 Call CL_SET.
F19E LD A,$4B A=Graphics_KeyBottom (4B).
F1A0 CALL PopulateGameRoomBuffer Call PopulateGameRoomBuffer.
F1A3 RST $10 Print the key stem using RST PRINT_A_1.
F1A4 POP HL Restore the original character set pointer from the stack.
F1A5 LD ($5C36),HL Write it back to *CHARS.
F1A8 POP IX Restore the player slot from the stack.
Handler_KeysAndLockedDoors_RestoreKey F1AA POP AF Restore the new key ID from the stack.
F1AB LD (IX+$10),A Write it to *PlayerKeyHeld.
F1AE RET Return.
Prev: F104 Up: Map Next: F1AF