Prev: 26116 Up: Map Next: 26437
26217: Parser: Match Input Word
Read the next word of the command and turn it into a vocabulary token.
Parser_MatchInputWord 26217 LD DE,25246 The typed word is held as four letters.
26220 LD B,4 A word is at most four letters.
26222 LD A,32 Pad the typed word with spaces.
Parser_MatchInputWord_Loop1 26224 LD (DE),A Fill the four-letter word with spaces.
26225 INC DE
26226 DJNZ Parser_MatchInputWord_Loop1
26228 XOR A No words left means the command has been parsed.
26229 OR C
26230 JP Z,Handler_UnknownWord An empty command is an unknown word.
26233 LD A,(HL) Read the next character of the command.
26234 CP 13 Jump to Handler_UnknownWord when ENTER (13) was pressed.
26236 JP Z,Handler_UnknownWord
26239 LD B,4 Keep at most four letters of this word.
26241 LD DE,25246 The typed word is held as four letters.
Parser_MatchInputWord_Loop2 26244 LD A,(HL) Stop copying when ENTER ends the command.
26245 CP 13
26247 JR Z,Parser_MatchInputWord_Step1
26249 CP 32 Stop copying at a space or a comma.
26251 JR Z,Parser_MatchInputWord_Loop4
26253 CP 44
26255 JR Z,Parser_MatchInputWord_Loop4
26257 LD (DE),A Store this letter and read the next.
26258 INC HL
26259 INC DE
26260 DJNZ Parser_MatchInputWord_Loop2
Parser_MatchInputWord_Loop3 26262 LD A,(HL) Stop skipping when ENTER ends the command.
26263 CP 13
26265 JR Z,Parser_MatchInputWord_Step1
26267 CP 32 Stop skipping at a space or a comma.
26269 JR Z,Parser_MatchInputWord_Loop4
26271 CP 44
26273 JR Z,Parser_MatchInputWord_Loop4
26275 INC HL Skip this extra letter.
26276 JR Parser_MatchInputWord_Loop3
Parser_MatchInputWord_Loop4 26278 INC HL Skip spaces before the next word.
26279 LD A,(HL)
26280 CP 32
26282 JR Z,Parser_MatchInputWord_Loop4
26284 CP 44 Jump back to Parser_MatchInputWord_Loop4 when that character is a comma (44).
26286 JR Z,Parser_MatchInputWord_Loop4
The word THE is ignored.
Parser_MatchInputWord_Step1 26288 EXX Compare the word with THE without losing the command pointer.
26289 LD HL,25319
26292 LD DE,25246
26295 LD B,4
Parser_MatchInputWord_Loop5 26297 LD A,(DE) Match the four letters of "THE ".
26298 CP (HL)
26299 JR NZ,Parser_MatchInputWord_Step2
26301 INC DE
26302 INC HL
26303 DJNZ Parser_MatchInputWord_Loop5
Parser_MatchInputWord_Step2 26305 EXX Ignore the word and parse again when it was "THE ".
26306 JR Z,Parser_MatchInputWord
26308 DEC C
26309 EXX Search the vocabulary addressed by *25244.
26310 LD HL,(25244)
26313 LD C,0
Parser_MatchInputWord_Loop6 26315 LD A,(HL) Read the next vocabulary letter.
26316 CP 255 Jump to Parser_MatchInputWord_Step5 when the vocabulary list ends (255).
26318 JR Z,Parser_MatchInputWord_Step5
Parser_MatchInputWord_Loop7 26320 LD DE,25246 The typed word is held as four letters.
26323 LD B,4 Compare four letters of this vocabulary word.
Parser_MatchInputWord_Loop8 26325 LD A,(DE) Match the typed word against this vocabulary entry.
26326 CP (HL)
26327 JR NZ,Parser_MatchInputWord_Step3
26329 INC DE
26330 INC HL
26331 DJNZ Parser_MatchInputWord_Loop8
26333 EXX Store this vocabulary number as the current word's token.
26334 LD A,9
26336 SUB C
26337 EXX
26338 LD D,0
26340 LD E,A
26341 LD HL,25233
26344 ADD HL,DE
26345 LD (HL),C
26346 EXX
26347 JP Parser_MatchInputWord Jump to Parser_MatchInputWord to read the next word.
Parser_MatchInputWord_Step3 26350 LD E,B Skip the letters left in a word that did not match.
26351 LD D,0
26353 ADD HL,DE
26354 LD A,(HL) Read the byte that follows this vocabulary word.
26355 CP 44 A comma marks another synonym of the same word.
26357 JR NZ,Parser_MatchInputWord_Step4
26359 INC HL Step past that comma.
26360 JR Parser_MatchInputWord_Loop7 Continue at Parser_MatchInputWord_Loop7 to match this synonym against the typed word.
Parser_MatchInputWord_Step4 26362 INC C Try the next vocabulary word.
26363 JR Parser_MatchInputWord_Loop6 Continue at Parser_MatchInputWord_Loop6 to try the next vocabulary word.
Parser_MatchInputWord_Step5 26365 EXX The word is unknown. Count back to it from the end of the command.
26366 LD A,10
26368 SUB C
26369 LD C,A
26370 LD HL,25183
Parser_MatchInputWord_Loop9 26373 DEC C Step back to the previous word of the command.
26374 JR Z,Parser_MatchInputWord_Step6 This is the word the game could not recognise.
Parser_MatchInputWord_Loop10 26376 LD A,(HL) Find the end of the previous word.
26377 CP 32
26379 JR Z,Parser_MatchInputWord_Loop11
26381 CP 44
26383 JR Z,Parser_MatchInputWord_Loop11
26385 INC HL
26386 JR Parser_MatchInputWord_Loop10
Parser_MatchInputWord_Loop11 26388 INC HL Skip the gap after that word.
26389 LD A,(HL)
26390 CP 32
26392 JR Z,Parser_MatchInputWord_Loop11
26394 CP 44 Jump back to Parser_MatchInputWord_Loop11 when that character is a comma (44).
26396 JR Z,Parser_MatchInputWord_Loop11
26398 JR Parser_MatchInputWord_Loop9 Continue at Parser_MatchInputWord_Loop9 to count back another word of the command.
Parser_MatchInputWord_Step6 26400 PUSH HL Remember where the unknown word starts.
26401 LD HL,25344 Print I don't know the word:-.
26404 CALL PrintStringAndANewline
26407 POP HL The unknown word starts at the address just saved.
26408 LD A,34 Print a quotation mark before the unknown word.
26410 CALL PrintCharacter
Parser_MatchInputWord_Loop12 26413 LD A,(HL) Print the characters of the unknown word.
26414 CP 33
26416 JR C,Parser_MatchInputWord_Step7
26418 INC HL
26419 CALL PrintCharacter
26422 JR Parser_MatchInputWord_Loop12
Parser_MatchInputWord_Step7 26424 LD A,34 Close the quotation.
26426 CALL PrintCharacter
26429 LD HL,25707 Print ..
26432 CALL PrintStringAndANewline
26435 JR Handler_UnknownWord_Step1 Continue at Handler_UnknownWord_Step1 to ask for another command.
Prev: 26116 Up: Map Next: 26437