Sherlock: annotated disassembly

Routines

Prev: A5C4 Up: Map Next: A621
A5CD: Interpret one message element at IX
Bit 7 set: a two-byte dictionary reference, printed by A887 - unless its flag nibble is $20, $30 or $60, which A647 treats as references to the command's own words (actor, objects). $00-$1F: a control code (A621). $20-$3F: that character. $40-$5F: a run of (low 5 bits + 1) letters packed 5 bits each, unpacked by A990. $60 and up: A83A.
How it works:
1. Bit 7 set: a two-byte dictionary reference. Classes $20, $30 and $60 are the sentence-ending words (A647); any other is printed (A887).
2. Codes $20 to $3F: a single literal character. $40 to $5F: a run of (code AND $1F) + 1 letters packed five bits each (A990), each printed as it is unpacked.
3. $60 and above: one of the common words (A83A).
4. Below $20: a control code, which is looked up in the handler table at A55D and called. Codes below $1D carry on; $1D and above end the message.
Input
IX The message position
Output
F NZ to go on with the next element; Z when the message has ended
IX Moved on
A5CD LD A,(IX+$00) The next byte
A5D0 BIT 7,A Test bit 7 of A - A word reference?
A5D2 JR Z,$A5F2 If bit 7 of A is clear, skip ahead to A5F2
A5D4 AND $7F Keep only bits 0, 1, 2, 3, 4, 5, 6 of A (mask $7F) - DE = the reference
A5D6 LD D,A Copy A into D
A5D7 LD E,(IX+$01) Read byte +1 of the record at IX into E
A5DA INC IX Step IX on to the next byte
A5DC AND $F0 Keep only bits 4, 5, 6, 7 of A (mask $F0) - One of the command's own words?
A5DE CP $30 Compare A with $30
A5E0 JR Z,$A647 If A equals $30, jump on to A647
A5E2 CP $20 Compare A with $20
A5E4 JR Z,$A647 If A equals $20, jump on to A647
A5E6 CP $60 Compare A with $60
A5E8 JR Z,$A647 If A equals $60, jump on to A647
This entry point is used by the routines at A621 and A83A.
A5EA CALL $A887 No: print the dictionary word
This entry point is used by the routine at A621.
A5ED INC IX Step IX on to the next byte - Move on
A5EF OR $01 Make A non-zero, which clears the zero flag, and hand that back to the caller
A5F1 RET Return to the caller
A5F2 CP $20 Compare A with $20 - A control code?
A5F4 JR C,$A621 If A is below $20, jump on to the routine "Run control code A" (A621)
A5F6 CP $60 Compare A with $60 - $60 and up
A5F8 JP NC,$A83A If A is $60 or more, jump on to the routine "Message bytes $60 and up: a common word" (A83A)
A5FB CP $40 Compare A with $40 - A literal character?
A5FD JR C,$A61C If A is below $40, skip ahead to A61C
A5FF AND $1F Keep only bits 0, 1, 2, 3, 4 of A (mask $1F) - Packed letters: how many
A601 INC A Add one to A
A602 LD B,A Copy A into B
A603 PUSH IX Save IX on the stack
A605 POP HL Restore HL from the stack
A606 INC HL Step HL on to the next byte
A607 LD C,$00 Load C with $00
A609 CALL $A990 Unpack one...
A60C CALL $A9B7 Call the routine "Print character A, a word at a time (word wrap)" (A9B7) - ...and print it
A60F DJNZ $A609 Count B down and, while it is not zero, go back to A609
A611 PUSH HL Save HL on the stack
A612 POP IX Restore IX from the stack
A614 LD A,C Copy C into A
A615 AND A Test A for zero (this leaves A as it was and clears carry)
A616 JR NZ,$A5ED If A is not zero, go back to A5ED
A618 DEC IX Step IX back one byte
A61A JR $A5ED Go back to A5ED
A61C CALL $A9B7 Call the routine "Print character A, a word at a time (word wrap)" (A9B7) - Print the character
A61F JR $A5ED Go back to A5ED
Prev: A5C4 Up: Map Next: A621