Sherlock: annotated disassembly

Routines

Prev: C29C Up: Map Next: C306
C2BA: Print one character (or handle a newline) at the cursor
The routine PLOT-CHAR's caller: restores the persisted cursor position/column-shift from C1F8/$C1FA, and either plots the passed-in character directly (calling PLOT-CHAR via C2EE), or, if the character is a carriage return ($0D), counts the line in $A019, waits for a key after fifteen (C306), and scrolls the window up (C316) to print the next line at the start of row 17. A character that fills the line (36 to a line, 18 beside a picture: C1F5) is followed by a newline of its own.
This, plus PLOT-CHAR and the page-wait wrapper at C306, forms the game's whole low-level text-output path: every piece of printed text - room descriptions, parser responses, dialogue - goes through here one character at a time.
How it works:
1. Pick up the text print position (C1F8) and pixel shift ($C1FA).
2. A character other than ENTER is printed (C388); if the line is then full a new line is started.
3. A new line after fifteen lines of text ($A019) waits for a key (C306) first. Scroll the text up a row (C316), and start the new line with 36 characters (18 beside a picture).
Input
A The character (or $0D for a new line)
Output
The character printed at the text cursor; registers kept
C2BA PUSH HL Save HL on the stack - Pick up the print position and pixel shift
C2BB PUSH BC Save BC on the stack
C2BC PUSH AF Save AF on the stack
C2BD LD HL,($C1F8) Read C1F8 in "Command-window state" into HL
C2C0 LD A,($C1FA) Read $C1FA in "Command-window state" into A
C2C3 LD C,A Copy A into C
C2C4 POP AF Restore AF from the stack
C2C5 PUSH AF Save AF on the stack
C2C6 CP $0D Compare A with $0D - Not a newline: print it
C2C8 JR NZ,$C2EE If A differs from $0D, skip ahead to C2EE
C2CA LD A,($A019) Read $A019 in "Game variables" into A - Newline: fifteen lines since the last pause?
C2CD CP $0F Compare A with $0F
C2CF JR NZ,$C2D6 If A differs from $0F, skip ahead to C2D6
C2D1 CALL $C306 Call the routine "Page-wait: flash the cursor, wait for a key, clear" (C306) - Yes: wait for a key (C306) and start the count again
C2D4 LD A,$FF Load A with $FF
C2D6 INC A Add one to A - Count the line
C2D7 LD ($A019),A Store A in $A019 in "Game variables"
C2DA LD HL,$5020 Back to the start of row 17...
C2DD LD C,$02 Load C with $02 - ...and scroll everything above up a row (C316)
C2DF CALL $C316 Call the routine "Scroll the text up a line, printing the line that..." (C316)
C2E2 LD A,($C128) Read "Flag: text lines are narrow (a picture is showing)" (C128) into A - A fresh line: 36 characters, or 18 beside a picture
C2E5 AND A Test A for zero (this leaves A as it was and clears carry)
C2E6 LD A,$24 Load A with $24
C2E8 JR Z,$C2F8 If A is zero, skip ahead to C2F8
C2EA LD A,$12 Load A with $12
C2EC JR $C2F8 Skip ahead to C2F8
C2EE CALL $C388 Print the character
C2F1 LD A,($C1F5) Read the characters left on the line (C1F5) into A - Line full? Then take a newline
C2F4 DEC A Subtract one from A
C2F5 JP Z,$C2CA If A has become zero, go back to C2CA
C2F8 LD ($C1F5),A Store A in the characters left on the line (C1F5) - Save the characters left, print position and pixel shift
C2FB LD ($C1F8),HL Store HL in C1F8 in "Command-window state"
C2FE LD A,C Copy C into A
C2FF LD ($C1FA),A Store A in $C1FA in "Command-window state"
C302 POP AF Restore AF from the stack
C303 POP BC Restore BC from the stack
C304 POP HL Restore HL from the stack
C305 RET Return to the caller
Prev: C29C Up: Map Next: C306