Sherlock: annotated disassembly

Routines

Prev: D968 Up: Map Next: D99E
D978: A cursor key on an empty line is a compass move
Key codes $08, $09, $0A and '[' become W, E, S and N - stored in the line, printed, and followed at once by ENTER. GET-KEY (C41F) turns cursor-up ($0B) into '[' and DELETE ($0C) into $08, so on a Spectrum CAPS SHIFT with 5, 6, 7 or 8 (or DELETE) walks west, south, north or east with one key. After OPEN PLAIN DOOR, the single key '[' gave 'N. You go north. You are in a small closet...', $0A gave 'S. You go south.', $08 gave 'W. YOU CANNOT GO WEST.'
Input
A The key
HL The line buffer
Output
A $0D (ENTER) with N, E, S or W typed for a cursor key; the key itself for any other
HL Moved on
B One fewer
D978 CP $09 Compare A with $09 - Cursor right: E
D97A JR Z,$D996 If A equals $09, skip ahead to D996
D97C CP $08 Compare A with $08 - Cursor left (or DELETE, made $08 by GET-KEY): W
D97E JR Z,$D99A If A equals $08, skip ahead to D99A
D980 CP $0A Compare A with $0A - Cursor down: S
D982 JR Z,$D992 If A equals $0A, skip ahead to D992
D984 CP $5B Compare A with $5B - Cursor up (made '[' by GET-KEY): N; any other key: back
D986 RET NZ If A differs from $5B, return
D987 LD A,$4E Load A with $4E
D989 LD (HL),A Store A at the address HL points to - Put the letter in the line and print it
D98A INC HL Step HL on to the next byte
D98B CALL $A9B7 Call the routine "Print character A, a word at a time (word wrap)" (A9B7)
D98E DEC B One more character in the line
D98F LD A,$0D Load A with $0D - and press ENTER
D991 RET Return to the caller
D992 LD A,$53 Load A with $53
D994 JR $D989 Go back to D989
D996 LD A,$45 Load A with $45
D998 JR $D989 Go back to D989
D99A LD A,$57 Load A with $57
D99C JR $D989 Go back to D989
Prev: D968 Up: Map Next: D99E