Sherlock: annotated disassembly

Routines

Prev: DB67 Up: Map Next: DC13
DBF7: Read a decimal number at HL into A
Used by the routines at DAEF and DB67.
Input
HL A decimal number
Output
A The number
HL Past it
BC Kept
DBF7 PUSH BC Save BC on the stack - Save BC; C = the number so far, 0
DBF8 LD C,$00 Load C with $00
DBFA LD A,(HL) Read the byte HL points at into A - Next character at HL: a digit (DAE8 sets carry if not)?
DBFB CALL $DAE8 Call the routine "Is A a digit? (carry if not)" (DAE8)
DBFE JR C,$DC10 Not a digit: finish
DC00 SUB $30 Subtract $30 from A - Digit value into B
DC02 LD B,A Copy A into B
DC03 RLC C Rotate C left - C = C x 10 + digit: C x 2 in A...
DC05 LD A,C Copy C into A
DC06 RLC C Rotate C left - ...C x 8 added...
DC08 RLC C Rotate C left
DC0A ADD A,C Add C to A
DC0B ADD A,B Add B to A - ...plus the digit
DC0C LD C,A Copy A into C
DC0D INC HL Step HL on to the next byte - Next character
DC0E JR $DBFA Go back to DBFA
DC10 LD A,C Copy C into A - A = the number
DC11 POP BC Restore BC from the stack
DC12 RET Return to the caller
Prev: DB67 Up: Map Next: DC13