Sherlock: annotated disassembly

Routines

Prev: C6BE Up: Map Next: C7A6
C74E: Test object C's +5 flags against a record's masks
B holds two 2-bit modes and L/H two masks. Mode 0: every mask bit must be set; 1: at least one (or the mask is 0); 2: none may be set; 3: not all may be set. On failure the offending bits go to CB79 (bit 7 set when a bit was present that should not be) and HL = CB7B, the refusal that names the flag.
OPEN YOUR DOOR when it is open leaves CB79 = $A0 and prints 'YOUR DOOR IS OPEN'; CLOSE YOUR DOOR when it is closed leaves $20 and prints 'YOUR DOOR IS CLOSED'. The door's +5 goes $80 -> $A0 when opened and back when closed.
Input
C An object
B Two modes (bits 2-3 for mask L, bits 0-1 for mask H)
L, H The masks
Output
F NZ if the object's +5 flags pass both tests; Z if not
C74E LD A,C Copy C into A - C = the object's +5 flags
C74F CALL $D237 Call the routine "Resolve an id (in A) to its full entity record" (D237)
C752 LD C,(IX+$05) Read byte +5 of the record at IX into C
C755 LD A,B Copy B into A - First the mode in bits 2-3 of B with mask L...
C756 RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
C757 RRCA Rotate A right one place (bit 0 goes to carry and bit 7)
C758 AND $03 Keep only bits 0, 1 of A (mask $03)
C75A LD D,L Copy L into D
C75B CALL $C763 Call C763 (inside "Test object C's +5 flags against a record's...")
C75E RET Z (failed: return Z)
C75F LD A,B Copy B into A - ...then the mode in bits 0-1 with mask H
C760 AND $03 Keep only bits 0, 1 of A (mask $03)
C762 LD D,H Copy H into D
C763 JR NZ,$C76D If any of bits 0, 1 of A was set, skip ahead to C76D - Mode 0: every mask bit must be set
C765 LD A,D Copy D into A
C766 AND C Keep only the bits of A that are set in C
C767 CP D Compare A with D
This entry point is used by the routine at C7A6.
C768 JP Z,$C62F If A equals D, go back to C62F
C76B JR $C792 (missing: note the bits that are not)
C76D CP $01 Compare A with $01 - Mode 1: at least one (or no mask at all)
C76F JR NZ,$C77B If A differs from $01, skip ahead to C77B
C771 LD A,D Copy D into A
C772 AND A Test A for zero (this leaves A as it was and clears carry)
C773 JR Z,$C768 If A is zero, go back to C768
C775 AND C Keep only the bits of A that are set in C
C776 JR Z,$C795 If none of those bits of A are set, skip ahead to C795
C778 JP $C62F Go back to C62F
C77B CP $02 Compare A with $02 - Mode 2: none may be set
C77D JR NZ,$C788 If A differs from $02, skip ahead to C788
C77F LD A,D Copy D into A
C780 AND C Keep only the bits of A that are set in C
C781 JP Z,$C62F If none of those bits of A are set, go back to C62F
C784 OR $80 Set bit 7 of A - (note them, with bit 7: present but should not be)
C786 JR $C797 Skip ahead to C797
C788 LD A,D Copy D into A - Mode 3: not all may be set
C789 AND C Keep only the bits of A that are set in C
C78A CP D Compare A with D
C78B JP NZ,$C62F If A differs from D, go back to C62F
C78E OR $80 Set bit 7 of A
C790 JR $C797 Skip ahead to C797
C792 XOR $FF Flip in A the bits that are set in $FF
C794 AND D Keep only the bits of A that are set in D
C795 AND $7F Keep only bits 0, 1, 2, 3, 4, 5, 6 of A (mask $7F)
C797 LD ($CB79),A Failed: the bits go to CB79
C79A LD A,($A00B) Read $A00B in "Game variables" into A - ...but the failure is ignored while $A00B is clear
C79D AND A Test A for zero (this leaves A as it was and clears carry)
C79E JP Z,$C62F If A is zero, go back to C62F
C7A1 LD HL,$CB7B Point HL at "Refuse by naming the flag that failed: "THE ......" (CB7B) - Z, with HL = the refusal that names the flag (CB7B)
C7A4 XOR A Set A to zero, which sets the zero flag for the caller
C7A5 RET Return to the caller
Prev: C6BE Up: Map Next: C7A6