Sherlock: annotated disassembly

Routines

Prev: A4CD Up: Map Next: A536
A51B: Does the word reference at HL match the one at IY? (Z)
An empty one (0) at HL matches anything. Otherwise compares the low byte and the low nibble of the high byte. HL and IY both move on two bytes.
Input
HL A word reference of the command (0 matches anything)
IY A word reference of the pattern
Output
F Z when they match
HL, IY Both moved on two bytes
A51B PUSH HL Save HL on the stack - A zero word at HL ends the comparison (Z unset)
A51C LD A,(HL) Read the byte HL points at into A
A51D INC HL Step HL on to the next byte
A51E OR (HL) Set in A the bits that are set in the byte HL points at
A51F JR Z,$A52E If the result is zero, skip ahead to A52E
A521 LD A,(IY+$01) Read byte +1 of the record at IY into A - The low nibbles of the two high bytes must agree...
A524 XOR (HL) Flip in A the bits that are set in the byte HL points at
A525 AND $0F Keep only bits 0, 1, 2, 3 of A (mask $0F)
A527 JR NZ,$A52E If any of bits 0, 1, 2, 3 of A was set, skip ahead to A52E
A529 DEC HL Step HL back one byte - ...and the low bytes: a 12-bit match
A52A LD A,(HL) Read the byte HL points at into A
A52B CP (IY+$00) Compare A with the first byte of the record at IY
A52E POP HL Restore HL from the stack - Either way both pointers move on two bytes
A52F INC HL Step HL on to the next byte
A530 INC HL Step HL on to the next byte
A531 INC IY Step IY on to the next byte
A533 INC IY Step IY on to the next byte
A535 RET Return to the caller
Prev: A4CD Up: Map Next: A536