![]() |
Routines |
| Prev: BF73 | Up: Map | Next: C0B4 |
|
Split the command into words and look each one up in the vocabulary.
|
||||
|
Blank the four-character word buffer.
|
||||
| Parser_MatchInputWord | BFD8 | LD DE,$BB41 | Start at the word buffer (BB41). | |
| BFDB | LD B,$04 | Prepare a space and a counter of 04 characters. | ||
| BFDD | LD A,$20 | |||
| MatchInputWord_Clear | BFDF | LD (DE),A | Write spaces through the word buffer. | |
| BFE0 | INC DE | |||
| BFE1 | DJNZ MatchInputWord_Clear | |||
| BFE3 | XOR A | Jump to Handler_UnknownWord when no token slots remain, or the command has ended. | ||
| BFE4 | OR C | |||
| BFE5 | JP Z,Handler_UnknownWord | |||
| BFE8 | LD A,(HL) | |||
| BFE9 | CP $0D | |||
| BFEB | JP Z,Handler_UnknownWord | |||
|
Copy the next word, up to 04 characters, stopping at a space, a comma or ENTER.
|
||||
| BFEE | LD B,$04 | Copy up to 04 characters into the word buffer. | ||
| BFF0 | LD DE,$BB41 | |||
| MatchInputWord_Copy | BFF3 | LD A,(HL) | Jump to MatchInputWord_IgnoreThe when the character is ENTER. | |
| BFF4 | CP $0D | |||
| BFF6 | JR Z,MatchInputWord_IgnoreThe | |||
| BFF8 | CP $20 | Jump to MatchInputWord_Delimiter when the character is a space or a comma. | ||
| BFFA | JR Z,MatchInputWord_Delimiter | |||
| BFFC | CP $2C | |||
| BFFE | JR Z,MatchInputWord_Delimiter | |||
| C000 | LD (DE),A | Copy the character into the word buffer and advance both pointers. | ||
| C001 | INC HL | |||
| C002 | INC DE | |||
| C003 | DJNZ MatchInputWord_Copy | Repeat from MatchInputWord_Copy until four characters have been copied. | ||
|
A longer word is skipped up to the next delimiter.
|
||||
| MatchInputWord_Skip | C005 | LD A,(HL) | Jump to MatchInputWord_IgnoreThe on ENTER, or to MatchInputWord_Delimiter on a space or a comma. | |
| C006 | CP $0D | |||
| C008 | JR Z,MatchInputWord_IgnoreThe | |||
| C00A | CP $20 | |||
| C00C | JR Z,MatchInputWord_Delimiter | |||
| C00E | CP $2C | |||
| C010 | JR Z,MatchInputWord_Delimiter | |||
| C012 | INC HL | Skip this character and keep looking for a delimiter. | ||
| C013 | JR MatchInputWord_Skip | |||
| MatchInputWord_Delimiter | C015 | INC HL | Skip consecutive spaces and commas. | |
| C016 | LD A,(HL) | |||
| C017 | CP $20 | |||
| C019 | JR Z,MatchInputWord_Delimiter | |||
| C01B | CP $2C | |||
| C01D | JR Z,MatchInputWord_Delimiter | |||
|
Ignore the word "THE ".
|
||||
| MatchInputWord_IgnoreThe | C01F | EXX | Switch in the spare registers and point them at "THE " and the word. | |
| C020 | LD HL,$BB5C | |||
| C023 | LD DE,$BB41 | |||
| C026 | LD B,$04 | |||
| MatchInputWord_The | C028 | LD A,(DE) | Compare the four characters. | |
| C029 | CP (HL) | |||
| C02A | JR NZ,MatchInputWord_AfterThe | |||
| C02C | INC DE | |||
| C02D | INC HL | |||
| C02E | DJNZ MatchInputWord_The | |||
| MatchInputWord_AfterThe | C030 | EXX | Switch back to the main registers to act on the comparison. | |
| C031 | JR Z,Parser_MatchInputWord | Jump back to Parser_MatchInputWord when the word was THE, so it is not tokenised. | ||
| C033 | DEC C | Use up one token slot. | ||
| C034 | EXX | |||
|
Look the word up in the vocabulary. A comma separates synonyms.
|
||||
| C035 | LD HL,($BADC) | Start at the vocabulary, with the token index at zero. | ||
| C038 | LD C,$00 | |||
| MatchInputWord_Vocabulary | C03A | LD A,(HL) | Jump to MatchInputWord_Unknown when the vocabulary is exhausted. | |
| C03B | CP $FF | |||
| C03D | JR Z,MatchInputWord_Unknown | |||
| MatchInputWord_CompareWord | C03F | LD DE,$BB41 | Compare the next vocabulary word with the word buffer. | |
| C042 | LD B,$04 | |||
| MatchInputWord_CompareChar | C044 | LD A,(DE) | Compare the next character. | |
| C045 | CP (HL) | |||
| C046 | JR NZ,MatchInputWord_NextWord | Jump to MatchInputWord_NextWord when it does not match. | ||
| C048 | INC DE | |||
| C049 | INC HL | |||
| C04A | DJNZ MatchInputWord_CompareChar | |||
| C04C | EXX | Turn the vocabulary index into a token-slot offset. | ||
| C04D | LD A,$09 | |||
| C04F | SUB C | |||
| C050 | EXX | |||
| C051 | LD D,$00 | |||
| C053 | LD E,A | |||
| C054 | LD HL,$BB36 | Store that token in its slot at BB36 and parse the next word. | ||
| C057 | ADD HL,DE | |||
| C058 | LD (HL),C | |||
| C059 | EXX | |||
| C05A | JP Parser_MatchInputWord | |||
| MatchInputWord_NextWord | C05D | LD E,B | Step to the end of this vocabulary word. | |
| C05E | LD D,$00 | |||
| C060 | ADD HL,DE | |||
| C061 | LD A,(HL) | Jump back to MatchInputWord_CompareWord to try the synonym after a comma. | ||
| C062 | CP $2C | |||
| C064 | JR NZ,MatchInputWord_NextEntry | |||
| C066 | INC HL | |||
| C067 | JR MatchInputWord_CompareWord | |||
| MatchInputWord_NextEntry | C069 | INC C | Try the next vocabulary word. | |
| C06A | JR MatchInputWord_Vocabulary | |||
|
The word is not in the vocabulary, so quote it and ask again.
|
||||
| MatchInputWord_Unknown | C06C | EXX | Find the unknown word in the command buffer. | |
| C06D | LD A,$0A | |||
| C06F | SUB C | |||
| C070 | LD C,A | |||
| C071 | LD HL,$BB04 | |||
| MatchInputWord_SeekWord | C074 | DEC C | Step back through the copied word count. | |
| C075 | JR Z,MatchInputWord_PrintUnknown | |||
| MatchInputWord_FindWord | C077 | LD A,(HL) | Skip characters until a space or a comma. | |
| C078 | CP $20 | |||
| C07A | JR Z,MatchInputWord_FindDelimiter | |||
| C07C | CP $2C | |||
| C07E | JR Z,MatchInputWord_FindDelimiter | |||
| C080 | INC HL | |||
| C081 | JR MatchInputWord_FindWord | |||
| MatchInputWord_FindDelimiter | C083 | INC HL | Skip spaces and commas, then look for the next word. | |
| C084 | LD A,(HL) | |||
| C085 | CP $20 | |||
| C087 | JR Z,MatchInputWord_FindDelimiter | |||
| C089 | CP $2C | |||
| C08B | JR Z,MatchInputWord_FindDelimiter | |||
| C08D | JR MatchInputWord_SeekWord | |||
| MatchInputWord_PrintUnknown | C08F | PUSH HL | Print "I don't know the word:-". | |
| C090 | LD HL,$BB75 | |||
| C093 | CALL PrintStringAndANewline | |||
| C096 | POP HL | Restore the command pointer from the stack. | ||
| C097 | LD A,$22 | Print a quote. | ||
| C099 | CALL PrintCharacter | |||
| MatchInputWord_Quote | C09C | LD A,(HL) | Print the unknown word up to the next space. | |
| C09D | CP $21 | |||
| C09F | JR C,MatchInputWord_CloseQuote | |||
| C0A1 | INC HL | |||
| C0A2 | CALL PrintCharacter | |||
| C0A5 | JR MatchInputWord_Quote | |||
| MatchInputWord_CloseQuote | C0A7 | LD A,$22 | Print a closing quote. | |
| C0A9 | CALL PrintCharacter | |||
| C0AC | LD HL,$BCF9 | Print "." and read another command. | ||
| C0AF | CALL PrintStringAndANewline | |||
| C0B2 | JR Handler_UnknownWord_Retry | |||
|
View the equivalent code in;
|
||||
| Prev: BF73 | Up: Map | Next: C0B4 |