Sherlock: annotated disassembly

Routines

Prev: ACCC Up: Map Next: AD57
ACFB: After a sentence: copy the objects on, or rewind to read it again
In statement mode ($A024 = 2) copies the node's six bytes from +8 to +$18 and parses on (AB4C). Otherwise, unless $A01B is set, goes back to the position saved by ACCC and frees the nodes after it (A1AF).
How it works:
1. In statement mode ($A024 = 2), do this once only: copy the node's first group of six bytes (+8) to the third group (+24), so the subject can be shared, and read on for the object (AB4C).
2. In command mode, if $A01B is set (a line of sentences is being worked through), just read on.
3. Otherwise go back to the start of the sentence, whose position, flags, sentence count and node were saved by ACCC, free the nodes that were made after it (A1AF) and unhook them, ready to read the sentence again.
Input
E The flags for what may come next
IY The parse node
ACFB LD A,($A024) Read $A024 in "Game variables" into A - A statement ($A024 = 2)?
ACFE CP $02 Compare A with $02
AD00 JR NZ,$AD23 If A differs from $02, skip ahead to AD23
AD02 BIT 6,E Test bit 6 of E - Only once (E bit 6)
AD04 JP NZ,$AB4C If bit 6 of E is set, go back to AB4C
AD07 SET 6,E Set bit 6 of E
AD09 SET 3,E Set bit 3 of E
AD0B PUSH IY Save IY on the stack - Copy the first group (+8) to the third (+24)
AD0D EXX Swap BC, DE and HL with their shadow copies
AD0E POP HL Restore HL from the stack
AD0F LD DE,$0008 Load DE with $0008, the amount that is added next
AD12 ADD HL,DE Add DE to HL
AD13 PUSH HL Save HL on the stack
AD14 LD DE,$0010 Load DE with $0010, the amount that is added next
AD17 ADD HL,DE Add DE to HL
AD18 POP DE Restore DE from the stack
AD19 EX DE,HL Swap DE and HL
AD1A LD BC,$0006 Load BC with $0006
AD1D LDIR Copy BC bytes from where HL points to where DE points, counting up
AD1F EXX Swap BC, DE and HL with their shadow copies
AD20 JP $AB4C and parse on
AD23 LD A,($A01B) Read $A01B in "Game variables" into A - A command: with $A01B set, just parse on
AD26 AND A Test A for zero (this leaves A as it was and clears carry)
AD27 JR Z,$AD2E If A is zero, skip ahead to AD2E
AD29 SET 3,E Set bit 3 of E
AD2B JP $AB4C Go back to AB4C
AD2E LD HL,($AAA1) Read AAA1 into HL - Otherwise go back to the start of the sentence (saved by ACCC): its token position...
AD31 LD ($A02B),HL Store HL in $A02B in "Game variables"
AD34 LD D,$B0 Load D with $B0 - ...the flags in E (D = $B0)...
AD36 LD A,($AAA3) Read AAA3 into A
AD39 LD E,A Copy A into E
AD3A LD A,($AAA6) Read $AAA6 into A - ...the sentence count...
AD3D LD ($A012),A Store A in A012 in "Game variables"
AD40 LD IY,($AAA4) ...and its node
AD44 LD L,(IY-$02) Read byte -2 of the record at IY into L - Free the nodes after it (A1AF) and unhook them
AD47 LD H,(IY-$01) Read byte -1 of the record at IY into H
AD4A PUSH HL Save HL on the stack
AD4B POP IX Restore IX from the stack
AD4D CALL $A1AF Call the routine "Free every node of the list starting at IX" (A1AF)
AD50 XOR A Clear A to zero (and the carry flag)
AD51 LD (IY-$02),A Store A in byte -2 of the record at IY
AD54 LD (IY-$01),A Store A in byte -1 of the record at IY
Prev: ACCC Up: Map Next: AD57