Sherlock: annotated disassembly

Routines

Prev: A94D Up: Map Next: A990
A95B: Unpack a dictionary record's letters (front-coded)
The dictionary is front-coded: bits 6-4 of a record's count byte say how many letters to keep from the word before (IX simply starts that far into $5C42), bits 3-0 how many new letters follow, packed five bits each (A990). Records with bit 7 set carry two extra bytes.
Input
HL A dictionary record
Output
The record's spelling at $5C42, ended with 0
HL Past the record
A95B PUSH BC IX = the spelling buffer $5C42; HL past the record's first byte
A95C LD IX,$5C42 The spelling goes to $5C42 on (a ROM system-variable area the game reuses)
A960 INC HL A = the count byte; a record with bit 7 set has two more bytes before the letters
A961 LD A,(HL) Read the byte HL points at into A - The second byte: bit 7 set means two more bytes follow (a suffix reference)
A962 BIT 7,A Test bit 7 of A
A964 INC HL Step HL on to the next byte
A965 JR Z,$A969 If bit 7 of A is clear, skip ahead to A969
A967 INC HL Step HL on to the next byte
A968 INC HL Step HL on to the next byte
A969 PUSH AF Bits 6-4: letters kept from the word before - just skip over them
A96A AND $70 Keep only bits 4, 5, 6 of A (mask $70) - Bits 4-6: how many letters are kept from the previous word - IX steps over them
A96C JR Z,$A974 If bits 4, 5, 6 of A were all clear, skip ahead to A974
A96E INC IX Step IX on to the next byte
A970 SUB $10 Subtract $10 from A
A972 JR NZ,$A96E If the two values differ, go back to A96E
A974 LD C,$00 C = the bit position in the packed letters
A976 POP AF Bits 3-0: new letters to unpack
A977 AND $0F Keep only bits 0, 1, 2, 3 of A (mask $0F) - The low nibble: how many new letters follow, five bits each (A990)
A979 JR Z,$A986 If bits 0, 1, 2, 3 of A were all clear, skip ahead to A986
A97B LD B,A Copy A into B
A97C CALL $A990 Call the routine "Unpack the next five-bit letter (C = bit position)" (A990) - Unpack one and store it
A97F LD (IX+$00),A Store A in the first byte of the record at IX
A982 INC IX Step IX on to the next byte
A984 DJNZ $A97C Count B down and, while it is not zero, go back to A97C
A986 LD (IX+$00),$00 End the spelling with 0
A98A LD A,C Copy C into A - If the letters ended part-way through a byte, step HL past it
A98B POP BC Restore BC from the stack
A98C AND A Clear the carry flag for the caller (A is unchanged)
A98D RET Z If A is zero, return
A98E INC HL Step HL on to the next byte
A98F RET Return to the caller
Prev: A94D Up: Map Next: A990