Sherlock: annotated disassembly

Routines

Prev: AB91 Up: Map Next: AC8F
AC24: Read a noun phrase into the pattern at $AAA8
Addresses named in the title: $AAA8.
Clears ten bytes at $AAA8, then takes tokens: an article ($80) once; up to three of class $10 or $70 (prepositions; counted in $AAA7, stored by AC8F); adjectives ($60, by AC94); and ends on the noun ($50) or a number ($F0), whose reference goes to $AAAC. Carry when a word comes in the wrong place; on return NZ if bit 5 of E is set.
How it works:
1. Clear the ten bytes of the noun-phrase pattern at $AAA8 and set E bits 2, 4 and 5.
2. Take tokens. An article ($80) is allowed once, at the start; a second one returns carry.
3. Up to three words of class $10 or $70 (adjectives and prepositions) are counted in $AAA7 and stored by AC8F or AC94.
4. A noun ends the phrase. The pattern is then copied into the node as the first or second object (ACA6).
Input
E Flags for the kinds of word still allowed (bits 2, 4, 5)
Output
F Carry set for a word out of place
E Updated
The ten-byte pattern at $AAA8
AC24 LD HL,$AAA8 Point HL at $AAA8 - Clear the ten-byte pattern
AC27 LD B,$0A Load B with $0A
AC29 CALL $A2AB Call the routine "Fill B bytes at HL with zero (or, from A2AC, with A)" (A2AB)
AC2C LD A,E Copy E into A - E bits 2, 4 and 5: each kind of word still allowed
AC2D OR $34 Set bits 2, 4, 5 of A (mask $34)
AC2F LD E,A Copy A into E
AC30 CALL $AE7F Next token
AC33 CP $80 Compare A with $80 - An article ($80): once only, at the start
AC35 JR NZ,$AC41 If A differs from $80, skip ahead to AC41
AC37 BIT 4,E Test bit 4 of E
AC39 JR Z,$AC3F If bit 4 of E is clear, skip ahead to AC3F
AC3B RES 4,E Clear bit 4 of E
AC3D JR $AC30 Go back to AC30
AC3F SCF Set the carry flag for the caller - Carry: a word out of place
AC40 RET Return to the caller
AC41 CP $10 Compare A with $10 - Class $10 or $70: only before any adjective ($AAA7 counts them, up to three)
AC43 JR Z,$AC49 If A equals $10, skip ahead to AC49
AC45 CP $70 Compare A with $70
AC47 JR NZ,$AC65 If A differs from $70, skip ahead to AC65
AC49 BIT 4,E Test bit 4 of E
AC4B JR Z,$AC3F If bit 4 of E is clear, go back to AC3F
AC4D BIT 2,E Test bit 2 of E
AC4F JR Z,$AC3F If bit 2 of E is clear, go back to AC3F
AC51 LD A,($AAA7) Read $AAA7 into A
AC54 CP $03 Compare A with $03
AC56 JR NC,$AC3F If A is $03 or more, go back to AC3F
AC58 INC A Add one to A
AC59 LD ($AAA7),A Store A in $AAA7
AC5C CALL $AC8F Call the routine "Put word BC in the first empty pair at $AAA8 (NZ if..." (AC8F) - Store it in one of the two slots at $AAA8 (AC8F; a third is out of place)
AC5F JR NZ,$AC3F If the zero flag is clear, go back to AC3F
AC61 RES 5,E Clear bit 5 of E
AC63 JR $AC30 Go back to AC30
AC65 CP $60 Compare A with $60 - An adjective ($60): in one of the two slots at $AAAE (AC94); no more articles or class $10/$70 words
AC67 JR NZ,$AC78 If A differs from $60, skip ahead to AC78
AC69 BIT 2,E Test bit 2 of E
AC6B JR Z,$AC3F If bit 2 of E is clear, go back to AC3F
AC6D RES 4,E Clear bit 4 of E
AC6F RES 5,E Clear bit 5 of E
AC71 CALL $AC94 Call the routine "Put word BC in the first empty pair at $AAAE (NZ if..." (AC94)
AC74 JR NZ,$AC3F If the zero flag is clear, go back to AC3F
AC76 JR $AC30 Go back to AC30
AC78 CP $F0 Compare A with $F0 - The noun ($50) or a number ($F0) ends the phrase: its reference to $AAAC
AC7A JR Z,$AC80 If A equals $F0, skip ahead to AC80
AC7C CP $50 Compare A with $50
AC7E JR NZ,$AC8B If A differs from $50, skip ahead to AC8B
AC80 LD A,E Copy E into A
AC81 AND $CB Keep only bits 0, 1, 3, 6, 7 of A (mask $CB)
AC83 LD E,A Copy A into E
AC84 LD ($AAAC),BC Store BC in $AAAC
AC88 CALL $AE7F and the token after it is read
AC8B AND A Test A for zero (this leaves A as it was and clears carry) - No carry; NZ if the phrase was empty (bit 5 still set)
AC8C BIT 5,E Test bit 5 of E
AC8E RET Return to the caller
Prev: AB91 Up: Map Next: AC8F