Prev: 61700 Up: Map Next: 61871
61703: 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 61703 PUSH IX Stash the player slot on the stack.
61705 LD IX,(23514) Point IX at *ReferenceKeysAndLockedDoors.
Handler_KeysAndLockedDoors_Loop 61709 LD A,(IX+0) Jump to Handler_Housekeeping if this key entry is the terminator (255).
61712 CP 255
61714 JR Z,Handler_Housekeeping
61716 LD A,(IX+5) A=the key state.
61719 AND %00000010 Keep only bit 1 (key still in the room).
61721 JR Z,Handler_KeysAndLockedDoors_Next Jump to Handler_KeysAndLockedDoors_Next if this key has already been taken.
61723 LD A,(IX+2) Jump to Handler_KeysAndLockedDoors_Next if the player is not in this key's column.
61726 CP C
61727 JR NZ,Handler_KeysAndLockedDoors_Next
61729 LD A,(IX+3) Jump to Handler_KeysAndLockedDoors_CollectKey if the player is on this key's row.
61732 CP B
61733 JR Z,Handler_KeysAndLockedDoors_CollectKey
Handler_KeysAndLockedDoors_Next 61735 LD DE,6 Move IX on to the next six-byte key entry.
61738 ADD IX,DE
61740 JR Handler_KeysAndLockedDoors_Loop Jump to Handler_KeysAndLockedDoors_Loop.
Collect this key and blank its graphic.
Handler_KeysAndLockedDoors_CollectKey 61742 LD A,6 Queue the collected-key sound at SoundFlag_General.
61744 LD (65534),A
61747 LD (IX+5),1 Mark this key as taken.
61751 LD C,(IX+2) C=the key's horizontal co-ordinate.
61754 LD B,(IX+3) B=the key's vertical co-ordinate.
61757 LD E,1 Set the blank sprite width/ height (1/ 2).
61759 LD D,2
61761 LD A,0 A=0.
61763 CALL WriteGameSpriteBuffer Blank the key in the game sprite buffer.
61766 LD HL,(23606) HL=*CHARS.
61769 PUSH HL Stash the current character set pointer on the stack.
61770 LD HL,40812 Write 40812 to *CHARS.
61773 LD (23606),HL
61776 LD A,32 A=a blank character.
61778 CALL PrintSprite Print the blank over the key.
61781 POP HL Restore the original character set pointer from the stack.
61782 LD (23606),HL Write it back to *CHARS.
61785 LD A,(IX+4) A=this key's ID.
61788 POP IX Restore the player slot from the stack.
61790 PUSH AF Stash the new key ID on the stack.
61791 LD A,(IX+16) Jump to Handler_KeysAndLockedDoors_RestoreKey if *PlayerKeyHeld is empty.
61794 CP 0
61796 JR Z,Handler_KeysAndLockedDoors_RestoreKey
Drop the previously held key back into the room.
61798 PUSH IX Stash the player slot on the stack.
61800 CALL FindMatchingKey Find the table entry for the held key.
61803 LD HL,(23606) HL=*CHARS.
61806 PUSH HL Stash the current character set pointer on the stack.
61807 LD HL,33656 Write 33656 to *CHARS.
61810 LD (23606),HL
61813 LD A,16 Set INK: *ActiveRoom_KeyColour.
61815 RST 16
61816 LD A,(23500)
61819 RST 16
61820 LD (IX+5),3 Mark that key as back in the room.
61824 LD C,(IX+2) C=the dropped key's horizontal co-ordinate.
61827 LD B,(IX+3) B=the dropped key's vertical co-ordinate.
61830 PUSH BC Stash the key position on the stack.
61831 CALL ConvertCoordinateToBufferOffset Convert it into a room-buffer offset.
61834 CALL 3545 Call CL_SET.
61837 LD A,(IX+4) A=the dropped key's ID.
61840 ADD A,65 A+=65 (key label; see Graphics_KeyLabels).
61842 CALL PopulateGameRoomBuffer Call PopulateGameRoomBuffer.
61845 RST 16 Print the key letter using RST PRINT_A_1.
61846 POP BC Restore the key position from the stack.
61847 DEC B Move one row down for the key stem.
61848 CALL ConvertCoordinateToBufferOffset Convert it into a room-buffer offset.
61851 CALL 3545 Call CL_SET.
61854 LD A,75 A=Graphics_KeyBottom (75).
61856 CALL PopulateGameRoomBuffer Call PopulateGameRoomBuffer.
61859 RST 16 Print the key stem using RST PRINT_A_1.
61860 POP HL Restore the original character set pointer from the stack.
61861 LD (23606),HL Write it back to *CHARS.
61864 POP IX Restore the player slot from the stack.
Handler_KeysAndLockedDoors_RestoreKey 61866 POP AF Restore the new key ID from the stack.
61867 LD (IX+16),A Write it to *PlayerKeyHeld.
61870 RET Return.
Prev: 61700 Up: Map Next: 61871