Sherlock: annotated disassembly

Routines

Prev: A51B Up: Map Next: A55D
A536: Wait for a key, but not for ever
Polls the keyboard (C41F) up to $A03B times (reset to 3,000 each call), with a 256-step delay loop between polls. A key: returns it with bit 7 cleared. No key in that time: rubs out whatever has been typed on the line (D9B7) and returns 0 with Z set.
Output
A The key pressed (0 if none)
F Z when nothing was typed in time
A536 PUSH HL Save HL on the stack
A537 LD HL,($A03B) How many polls before giving up
A53A CALL $C41F A key?
A53D BIT 7,A Test bit 7 of A - Yes
A53F JR NZ,$A553 If bit 7 of A is set, skip ahead to A553
A541 LD A,$00 Load A with $00 - No: a short delay...
A543 DEC A Subtract one from A
A544 PUSH HL Save HL on the stack
A545 POP HL Restore HL from the stack
A546 JR NZ,$A543 If the zero flag is clear, go back to A543
A548 DEC HL Step HL back one byte - ...and count a poll
A549 LD A,H Copy H into A
A54A OR L Set in A the bits that are set in L
A54B JR NZ,$A53A If the result is not zero, go back to A53A - Try again
A54D POP HL Restore HL from the stack
A54E PUSH HL Save HL on the stack
A54F CALL $D9B7 Time is up: rub out the line
A552 XOR A Z: nothing typed
A553 AND $7F The key
A555 LD HL,$0BB8 Load HL with $0BB8 - Reset the limit for next time
A558 LD ($A03B),HL Store HL in $A03B in "Game variables"
A55B POP HL Restore HL from the stack
A55C RET Return to the caller
Prev: A51B Up: Map Next: A55D