Sherlock: annotated disassembly

Routines

Prev: C1F4 Up: Map Next: C240
C1FC: Echo a typed character in the command window
Letters are shown in capitals (C240); ENTER becomes a space and a new line, DELETE steps back 7 pixels (C249, C267); at the end of a line the window scrolls (C271).
How it works:
1. ENTER prints a space over the cursor and starts a new line; DELETE rubs the last character out (C249).
2. Anything else is shown in capitals (C240) and printed (C388).
3. When the line is full, or after ENTER, the window scrolls up (C271) and 36 characters are available again.
4. Save the characters left, pixel shift and print position. Draw a '+' cursor after the character.
Input
A The character typed (ENTER $0D, DELETE $08, anything else)
Output
All registers kept
The character shown in the command window
C1FC POP AF Restore AF from the stack - Restore AF, then (entry C1FD) save HL, BC, AF
This entry point is used by the routines at C1C0 and C1CB.
C1FD PUSH HL Save HL on the stack
C1FE PUSH BC Save BC on the stack
C1FF PUSH AF Save AF on the stack
C200 LD A,($C1FB) Read C1FB in "Command-window state" into A - C = the command window's pixel shift, HL = its print position
C203 LD C,A Copy A into C
C204 POP AF Restore AF from the stack
C205 PUSH AF Save AF on the stack
C206 LD HL,($C1F6) Read C1F6 in "Command-window state" into HL
C209 CP $0D Compare A with $0D - ENTER: print a space over the cursor and start a new line
C20B JR NZ,$C214 If A differs from $0D, skip ahead to C214
C20D LD A,$20 Load A with $20
C20F CALL $C388 Call the routine "PLOT-CHAR: draw one character glyph at HL, shifted by..." (C388)
C212 JR $C224 Skip ahead to C224
C214 CP $08 Compare A with $08 - DELETE: rub the last character out (C249)
C216 JR Z,$C249 If A equals $08, jump on to the routine "Rub out the last character in the command window" (C249)
C218 CALL $C240 Call the routine "Upper-case A if it is a lower-case letter" (C240) - Anything else: in capitals (C240), printed
C21B CALL $C388 Call the routine "PLOT-CHAR: draw one character glyph at HL, shifted by..." (C388)
C21E LD A,($C1F4) Read "Command-window state" (C1F4) into A - Line full?
C221 DEC A Subtract one from A
C222 JR NZ,$C22D If A is not zero, skip ahead to C22D
C224 LD L,$E0 Load L with $E0 - New line: back to the start of the bottom row, pixel shift 2...
C226 LD C,$02 Load C with $02
C228 CALL $C271 ...scroll the window up (C271)...
C22B LD A,$24 ...and 36 characters to go
This entry point is used by the routine at C249.
C22D LD ($C1F4),A Store A in "Command-window state" (C1F4) - Save the characters left, pixel shift and print position
C230 LD A,C Copy C into A
C231 LD ($C1FB),A Store A in C1FB in "Command-window state"
C234 LD ($C1F6),HL Store HL in C1F6 in "Command-window state"
C237 LD A,$2B Load A with $2B - Draw the '+' cursor after it (overwritten by the next character)
C239 CALL $C388 Call the routine "PLOT-CHAR: draw one character glyph at HL, shifted by..." (C388)
C23C POP AF Restore AF from the stack
C23D POP BC Restore BC from the stack
C23E POP HL Restore HL from the stack
C23F RET Return to the caller
Prev: C1F4 Up: Map Next: C240