Prev: 6604 Up: Map Next: 6745
6669: Parser: Match Input Word
Read the next word of the command and turn it into a vocabulary token.
Parser_MatchInputWord 6669 LD DE,$629E The typed word is held as four letters.
666C LD B,$04 A word is at most four letters.
666E LD A,$20 Pad the typed word with spaces.
Parser_MatchInputWord_Loop1 6670 LD (DE),A Fill the four-letter word with spaces.
6671 INC DE
6672 DJNZ Parser_MatchInputWord_Loop1
6674 XOR A No words left means the command has been parsed.
6675 OR C
6676 JP Z,Handler_UnknownWord An empty command is an unknown word.
6679 LD A,(HL) Read the next character of the command.
667A CP $0D Jump to Handler_UnknownWord when ENTER (0D) was pressed.
667C JP Z,Handler_UnknownWord
667F LD B,$04 Keep at most four letters of this word.
6681 LD DE,$629E The typed word is held as four letters.
Parser_MatchInputWord_Loop2 6684 LD A,(HL) Stop copying when ENTER ends the command.
6685 CP $0D
6687 JR Z,Parser_MatchInputWord_Step1
6689 CP $20 Stop copying at a space or a comma.
668B JR Z,Parser_MatchInputWord_Loop4
668D CP $2C
668F JR Z,Parser_MatchInputWord_Loop4
6691 LD (DE),A Store this letter and read the next.
6692 INC HL
6693 INC DE
6694 DJNZ Parser_MatchInputWord_Loop2
Parser_MatchInputWord_Loop3 6696 LD A,(HL) Stop skipping when ENTER ends the command.
6697 CP $0D
6699 JR Z,Parser_MatchInputWord_Step1
669B CP $20 Stop skipping at a space or a comma.
669D JR Z,Parser_MatchInputWord_Loop4
669F CP $2C
66A1 JR Z,Parser_MatchInputWord_Loop4
66A3 INC HL Skip this extra letter.
66A4 JR Parser_MatchInputWord_Loop3
Parser_MatchInputWord_Loop4 66A6 INC HL Skip spaces before the next word.
66A7 LD A,(HL)
66A8 CP $20
66AA JR Z,Parser_MatchInputWord_Loop4
66AC CP $2C Jump back to Parser_MatchInputWord_Loop4 when that character is a comma (2C).
66AE JR Z,Parser_MatchInputWord_Loop4
The word THE is ignored.
Parser_MatchInputWord_Step1 66B0 EXX Compare the word with THE without losing the command pointer.
66B1 LD HL,$62E7
66B4 LD DE,$629E
66B7 LD B,$04
Parser_MatchInputWord_Loop5 66B9 LD A,(DE) Match the four letters of "THE ".
66BA CP (HL)
66BB JR NZ,Parser_MatchInputWord_Step2
66BD INC DE
66BE INC HL
66BF DJNZ Parser_MatchInputWord_Loop5
Parser_MatchInputWord_Step2 66C1 EXX Ignore the word and parse again when it was "THE ".
66C2 JR Z,Parser_MatchInputWord
66C4 DEC C
66C5 EXX Search the vocabulary addressed by *629C.
66C6 LD HL,($629C)
66C9 LD C,$00
Parser_MatchInputWord_Loop6 66CB LD A,(HL) Read the next vocabulary letter.
66CC CP $FF Jump to Parser_MatchInputWord_Step5 when the vocabulary list ends (FF).
66CE JR Z,Parser_MatchInputWord_Step5
Parser_MatchInputWord_Loop7 66D0 LD DE,$629E The typed word is held as four letters.
66D3 LD B,$04 Compare four letters of this vocabulary word.
Parser_MatchInputWord_Loop8 66D5 LD A,(DE) Match the typed word against this vocabulary entry.
66D6 CP (HL)
66D7 JR NZ,Parser_MatchInputWord_Step3
66D9 INC DE
66DA INC HL
66DB DJNZ Parser_MatchInputWord_Loop8
66DD EXX Store this vocabulary number as the current word's token.
66DE LD A,$09
66E0 SUB C
66E1 EXX
66E2 LD D,$00
66E4 LD E,A
66E5 LD HL,$6291
66E8 ADD HL,DE
66E9 LD (HL),C
66EA EXX
66EB JP Parser_MatchInputWord Jump to Parser_MatchInputWord to read the next word.
Parser_MatchInputWord_Step3 66EE LD E,B Skip the letters left in a word that did not match.
66EF LD D,$00
66F1 ADD HL,DE
66F2 LD A,(HL) Read the byte that follows this vocabulary word.
66F3 CP $2C A comma marks another synonym of the same word.
66F5 JR NZ,Parser_MatchInputWord_Step4
66F7 INC HL Step past that comma.
66F8 JR Parser_MatchInputWord_Loop7 Continue at Parser_MatchInputWord_Loop7 to match this synonym against the typed word.
Parser_MatchInputWord_Step4 66FA INC C Try the next vocabulary word.
66FB JR Parser_MatchInputWord_Loop6 Continue at Parser_MatchInputWord_Loop6 to try the next vocabulary word.
Parser_MatchInputWord_Step5 66FD EXX The word is unknown. Count back to it from the end of the command.
66FE LD A,$0A
6700 SUB C
6701 LD C,A
6702 LD HL,$625F
Parser_MatchInputWord_Loop9 6705 DEC C Step back to the previous word of the command.
6706 JR Z,Parser_MatchInputWord_Step6 This is the word the game could not recognise.
Parser_MatchInputWord_Loop10 6708 LD A,(HL) Find the end of the previous word.
6709 CP $20
670B JR Z,Parser_MatchInputWord_Loop11
670D CP $2C
670F JR Z,Parser_MatchInputWord_Loop11
6711 INC HL
6712 JR Parser_MatchInputWord_Loop10
Parser_MatchInputWord_Loop11 6714 INC HL Skip the gap after that word.
6715 LD A,(HL)
6716 CP $20
6718 JR Z,Parser_MatchInputWord_Loop11
671A CP $2C Jump back to Parser_MatchInputWord_Loop11 when that character is a comma (2C).
671C JR Z,Parser_MatchInputWord_Loop11
671E JR Parser_MatchInputWord_Loop9 Continue at Parser_MatchInputWord_Loop9 to count back another word of the command.
Parser_MatchInputWord_Step6 6720 PUSH HL Remember where the unknown word starts.
6721 LD HL,$6300 Print I don't know the word:-.
6724 CALL PrintStringAndANewline
6727 POP HL The unknown word starts at the address just saved.
6728 LD A,$22 Print a quotation mark before the unknown word.
672A CALL PrintCharacter
Parser_MatchInputWord_Loop12 672D LD A,(HL) Print the characters of the unknown word.
672E CP $21
6730 JR C,Parser_MatchInputWord_Step7
6732 INC HL
6733 CALL PrintCharacter
6736 JR Parser_MatchInputWord_Loop12
Parser_MatchInputWord_Step7 6738 LD A,$22 Close the quotation.
673A CALL PrintCharacter
673D LD HL,$646B Print ..
6740 CALL PrintStringAndANewline
6743 JR Handler_UnknownWord_Step1 Continue at Handler_UnknownWord_Step1 to ask for another command.
Prev: 6604 Up: Map Next: 6745