Sherlock: annotated disassembly

Routines

Prev: C415 Up: Map Next: C45E
C41F: GET-KEY: has the player pressed a key?
Saves IY/IX/HL/DE/BC, points IY at the standard system-variable area ($5C3A), then does EI; HALT; DI - i.e. waits for exactly one interrupt, which is where a real Spectrum's ROM would normally have scanned the keyboard into FLAGS/LAST-K.
Checks FLAGS bit 5 ("a new key is waiting"); if not, returns A=0.
Called from three places, all real CALL instructions: $A080 (non-blocking poll during boot), $A53B, and $C416 (the wait-for-a-key loop at C415).
How it works:
1. Save the registers and point IY at the system variables.
2. Allow one interrupt (EI, HALT) so the keyboard is scanned.
3. If no new key is flagged, return 0. Otherwise take the key from $5C08, turn the ROM's editing codes into backspace and '[', and put it in capitals.
4. Set bit 7 to say a key was pressed.
Output
A The key with bit 7 set, or 0 if none
All other registers kept
C41F PUSH IY Save every register this routine touches
C421 PUSH IX Save IX, HL, DE, BC
C423 PUSH HL Save HL on the stack
C424 PUSH DE Save DE on the stack
C425 PUSH BC Save BC on the stack
C426 LD IY,$5C3A IY -> system variables, as ROM interrupt code expects
C42A EI Let exactly one interrupt happen...
C42B HALT ...(this is where the keyboard actually gets scanned)
C42C DI Disable interrupts
C42D LD A,($5C3B) Was a new key flagged as available?
C430 BIT 5,A Test bit 5 of A
C432 JR NZ,$C437 If bit 5 of A is set, skip ahead to C437
C434 XOR A No: return with A=0
C435 JR $C456 Skip ahead to C456
C437 RES 5,A Yes: consume the "new key" flag
C439 LD ($5C3B),A Store A in FLAGS ($5C3B)
C43C LD A,($5C08) A = the key, already decoded to ASCII by the ROM
C43F CP $5F Is it the ROM's DELETE-key code?
C441 JR NZ,$C445 If A differs from $5F, skip ahead to C445
C443 LD A,$18 ...remap it to a plain backspace
C445 CP $0C Is it this other ROM editing code?
C447 JR NZ,$C44B If A differs from $0C, skip ahead to C44B
C449 LD A,$08 ...remap it too
C44B CP $0B Is it this third ROM editing code?
C44D JR NZ,$C451 If A differs from $0B, skip ahead to C451
C44F LD A,$5B ...remap it to '['
C451 CALL $C240 Upper-case A if it is a lower-case letter (C240)
C454 SET 7,A Tag the result: bit 7 set means "a key was pressed"
C456 POP BC Restore every saved register
C457 POP DE Restore DE, HL, IX, IY and return
C458 POP HL (Restore the remaining registers)
C459 POP IX Restore IX from the stack
C45B POP IY Restore IY from the stack
C45D RET Return to the caller
Prev: C415 Up: Map Next: C45E