Sherlock: annotated disassembly

Routines

Prev: A95B Up: Map Next: A9B5
A990: Unpack the next five-bit letter (C = bit position)
Returns 'a' + n - 1 style codes ($60 + n).
Input
HL The packed text
C The bit position (0 to 7)
Output
A The letter code ($60 + n)
HL, C Moved on five bits
A990 PUSH DE HL = the packed text, C = the bit position (0-7) in the byte at HL
A991 LD D,(HL) Read the byte HL points at into D - DE = this byte and the next, big-endian
A992 INC HL Step HL on to the next byte
A993 LD E,(HL) Read the byte HL points at into E
A994 DEC HL Step HL back one byte
A995 LD A,C Copy C into A - Shift left C places to bring the letter to the top...
A996 AND A Test A for zero (this leaves A as it was and clears carry)
A997 JR Z,$A9A0 If A is zero, skip ahead to A9A0
A999 SLA E Shift E left (double it)
A99B RL D Rotate D left through the carry
A99D DEC A Subtract one from A
A99E JR NZ,$A999 If A is not zero, go back to A999
A9A0 LD A,C Copy C into A - Advance by five bits: C + 5, with a byte on (HL + 1) when it passes 8
A9A1 ADD A,$05 Add $05 to A
A9A3 CP $08 Compare A with $08
A9A5 JR C,$A9AA If A is below $08, skip ahead to A9AA
A9A7 SUB $08 Subtract $08 from A
A9A9 INC HL Step HL on to the next byte
A9AA LD C,A Copy A into C
A9AB LD A,D Copy D into A - The top five bits of D (RRCA x3, AND $1F)...
A9AC POP DE Restore DE from the stack
A9AD RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
A9AE RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
A9AF RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
A9B0 AND $1F Keep only bits 0, 1, 2, 3, 4 of A (mask $1F)
A9B2 ADD A,$60 Add $60 to A - ...plus $60: the letter's code, $60 (a) upwards
A9B4 RET Return to the caller
Prev: A95B Up: Map Next: A9B5