Prev: 7CBB Up: Map Next: 7DB6
7CC0: Parser: end of line (and THEN / full stop)
Handles the end-of-line token, and (from 7CC4) THEN or a full stop. It closes the current command frame. If a verb was required but none was given it complains (7FF9).
For ALL (see 808A) the verb is flagged. The frame count $B5F7 is increased and, for THEN, the parser goes back to the start state for the next command (7C6A).
At the end of the line some tidying up is done. If the previous command was unfinished ($B60A), the new words are merged into it (7D02-7D4B): empty slots in the old frame are filled from the new one. Then frames that have no verb of their own (because of AND, as in 'take the key and the sword') are given the verb of the frame before them (7F81). Finally, noun phrases consisting of IT are resolved, and if a quotation is still open the parser starts again.
7CC0 XOR A End of the line: no more commands will follow
7CC1 LD ($B5F6),A
This entry point is used by the routines at 7DD5 and 7DFB.
7CC4 BIT 1,E THEN, full stop or end: has a verb been given (bit 1 of E clear)?
7CC6 JR Z,$7CDE Yes: close the frame
7CC8 LD A,($B5F7) No verb. Is this the first frame?
7CCB AND A
7CCC JR NZ,$7CDE No: the verb will be copied from the frame before
7CCE LD A,($B5CF) First frame without a verb. Was the previous word the end of the line too?
7CD1 CP $C0
7CD3 JR NZ,$7CD8
7CD5 CP D
7CD6 JR Z,$7CB6 An empty line: nothing to do
7CD8 CALL $7CBB Inside a quotation?
7CDB JP Z,$7FF9 No: a command with no verb, so "what?"
This entry point is used by the routine at 7C4F.
7CDE LD A,($B609) Close the frame. Is ALL in force?
7CE1 DEC A
7CE2 JR NZ,$7CE8
7CE4 SET 7,(IY+$01) Yes: mark the verb with bit 7 (ALL)
7CE8 LD HL,$B5F7 HL = the frame count
7CEB DEC A
7CEC LD A,D
7CED JR NZ,$7CF3
7CEF CP $A0 (Under ALL EXCEPT, an AND does not start a new frame)
7CF1 JR Z,$7CF4
7CF3 INC (HL) Count the frame
7CF4 CALL $7F5D Move on to the next frame
7CF7 CP $A0 Was this an AND or THEN rather than the end of the line?
7CF9 JP Z,$7C6A Yes: start the next command
7CFC LD A,($B60A) END OF THE LINE. Is an unfinished command waiting?
7CFF AND A
7D00 JR Z,$7D4C No: go on to share verbs between frames
7D02 PUSH DE Yes: HL = the slot in the old frame that the question was about ($B60A holds its offset)
7D03 LD E,A
7D04 LD D,$00
7D06 LD HL,$B8B8
7D09 ADD HL,DE
7D0A PUSH IY
7D0C LD IY,$B8A0 IY = the frame just typed
7D10 LD A,(IY+$08) Does its first noun phrase have a noun?
7D13 OR (IY+$09)
7D16 LD DE,$B8A8
7D19 JR Z,$7D32 No: use it anyway
7D1B LD A,(IY+$08) Is it the same noun the old command used?
7D1E CP (HL)
7D1F JR NZ,$7D29
7D21 LD A,(IY+$09)
7D24 INC HL
7D25 CP (HL)
7D26 DEC HL
7D27 JR Z,$7D32 Yes: take this phrase
7D29 LD A,(IY+$12) Otherwise try the second noun phrase
7D2C OR (IY+$13)
7D2F LD DE,$B8B2
7D32 POP IY
7D34 JR NZ,$7D4B No suitable phrase: leave the old command as it was
7D36 EX DE,HL Fill the empty words of the old phrase (noun and two adjectives) from the new one...
7D37 LD B,$03
7D39 LD A,(HL)
7D3A INC HL
7D3B OR (HL)
7D3C DEC HL
7D3D JR NZ,$7D41 ...keeping any word already there
7D3F LD A,(DE)
7D40 LD (HL),A
7D41 INC HL
7D42 INC DE
7D43 JR NZ,$7D47
7D45 LD A,(DE)
7D46 LD (HL),A
7D47 INC HL
7D48 INC DE
7D49 DJNZ $7D39 ...for all three words
7D4B POP DE
7D4C PUSH IY SHARE VERBS: start just above the first frame
7D4E LD IY,$B8D0
7D52 LD A,($B5F7) B = the number of frames
7D55 LD B,A
7D56 PUSH BC
7D57 CALL $7F5C Step to the first frame
7D5A LD A,B Any frames left?
7D5B AND A
7D5C JR Z,$7D6E No
7D5E CALL $7F5C Step to the next frame
7D61 LD A,(IY+$01) Does it have a verb of its own?
7D64 AND $7F
7D66 OR (IY+$00)
7D69 CALL Z,$7F81 No (it came from AND): give it the previous frame's verb
7D6C JR $7D5A Loop
7D6E POP BC SHARE SECOND NOUN PHRASES, working backwards:
7D6F POP IY
7D71 PUSH IY
7D73 CALL $7F56 step to the previous frame
7D76 LD A,B Any frames left?
7D77 AND A
7D78 JP Z,$7DA8 No: finish
7D7B CALL $7F56 Step back one more
7D7E LD A,(IY+$12) Does this frame lack a second noun phrase...
7D81 OR (IY+$13)
7D84 JR NZ,$7D76
7D86 LD A,(IY+$00) ...and have the same verb as the frame after it...
7D89 CP (IX+$00)
7D8C JR NZ,$7D76
7D8E LD A,(IY+$01)
7D91 CP (IX+$01)
7D94 JR NZ,$7D76
7D96 LD A,(IX+$0E) ...which does have one?
7D99 OR (IX+$0F)
7D9C JR Z,$7D76
7D9E EXX Then copy that phrase into this frame ("put the key and the sword in the chest")
7D9F LD DE,$000E
7DA2 CALL $7FB4
7DA5 JP $7D76 Loop
7DA8 POP IY
7DAA LD A,($B5F6) More commands to come (THEN)?
7DAD AND A
7DAE RET Z No: parsing is complete
7DAF CALL $7CBB Inside a quotation?
7DB2 RET Z No: return
7DB3 JP $7C6A Yes: carry on parsing the words after it
Prev: 7CBB Up: Map Next: 7DB6