Prev: 49066 Up: Map Next: 49332
49089: Handler: User Pressed "ENTER"
Used by the routine at Handler_UserInput.
The player pressed ENTER, so close the command and clear the tokens.
UserInput_Enter 49089 LD (HL),A Store ENTER as the end of the command.
49090 CALL SwitchNormalScreenOutput Call SwitchNormalScreenOutput to select the screen channel.
49093 CALL PrintCharacter Call PrintCharacter to echo ENTER.
49096 LD HL,47926 Start at the token buffer (UserInput_FirstToken) and prepare the empty marker 255.
49099 LD A,255
49101 LD B,10
EmptyWordTokenBuffer_Loop 49103 LD (HL),A Write 255 into each of the 10 token slots.
49104 INC HL
49105 DJNZ EmptyWordTokenBuffer_Loop
49107 LD HL,47876 Start at the command and allow 10 words, then fall into the parser.
49110 LD C,10
Split the command into words and look each one up in the vocabulary.
Clear the four-letter buffer to spaces so a short word cannot match the previous one's tail.
Parser_MatchInputWord 49112 LD DE,47937 DE=FourLetterBuffer.
49115 LD B,4 Set a counter in B for the 4 letters.
49117 LD A,32 A=32.
MatchInputWord_Clear 49119 LD (DE),A Write a space character (32) to the buffer.
49120 INC DE Move to the next letter.
49121 DJNZ MatchInputWord_Clear Decrease the counter by one and loop back to MatchInputWord_Clear until the counter is zero.
49123 XOR A Jump to Handler_UnknownWord when no token slots remain, or the command has ended.
49124 OR C
49125 JP Z,Handler_UnknownWord
49128 LD A,(HL)
49129 CP 13
49131 JP Z,Handler_UnknownWord
Copy the next word, up to 4 characters, stopping at a space, a comma or ENTER.
49134 LD B,4 Copy up to 4 characters into the word buffer.
49136 LD DE,47937
MatchInputWord_Copy 49139 LD A,(HL) Jump to MatchInputWord_IgnoreThe when the character is ENTER.
49140 CP 13
49142 JR Z,MatchInputWord_IgnoreThe
49144 CP 32 Jump to MatchInputWord_Delimiter when the character is a space or a comma.
49146 JR Z,MatchInputWord_Delimiter
49148 CP 44
49150 JR Z,MatchInputWord_Delimiter
49152 LD (DE),A Copy the character into the word buffer and advance both pointers.
49153 INC HL
49154 INC DE
49155 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 49157 LD A,(HL) Jump to MatchInputWord_IgnoreThe on ENTER, or to MatchInputWord_Delimiter on a space or a comma.
49158 CP 13
49160 JR Z,MatchInputWord_IgnoreThe
49162 CP 32
49164 JR Z,MatchInputWord_Delimiter
49166 CP 44
49168 JR Z,MatchInputWord_Delimiter
49170 INC HL Skip this character and keep looking for a delimiter.
49171 JR MatchInputWord_Skip
MatchInputWord_Delimiter 49173 INC HL Skip consecutive spaces and commas.
49174 LD A,(HL)
49175 CP 32
49177 JR Z,MatchInputWord_Delimiter
49179 CP 44
49181 JR Z,MatchInputWord_Delimiter
Ignore the word "THE ".
MatchInputWord_IgnoreThe 49183 EXX Switch in the spare registers and point them at "THE " and the word.
49184 LD HL,47964
49187 LD DE,47937
49190 LD B,4
MatchInputWord_The 49192 LD A,(DE) Compare the four characters.
49193 CP (HL)
49194 JR NZ,MatchInputWord_AfterThe
49196 INC DE
49197 INC HL
49198 DJNZ MatchInputWord_The
MatchInputWord_AfterThe 49200 EXX Switch back to the main registers to act on the comparison.
49201 JR Z,Parser_MatchInputWord Jump back to Parser_MatchInputWord when the word was THE, so it is not tokenised.
49203 DEC C Use up one token slot.
49204 EXX
Look the word up in the vocabulary. A comma separates synonyms of the same token; 255 ends the table.
49205 LD HL,(47836) HL=*Pointer_Vocabulary.
49208 LD C,0 Set the token number in C to 0.
MatchInputWord_Vocabulary 49210 LD A,(HL) Jump to MatchInputWord_Unknown if the word is the 255 terminator.
49211 CP 255
49213 JR Z,MatchInputWord_Unknown
MatchInputWord_CompareWord 49215 LD DE,47937 DE=FourLetterBuffer.
49218 LD B,4 Set a counter in B for the 4 letters.
MatchInputWord_CompareChar 49220 LD A,(DE) Jump to MatchInputWord_NextWord if this letter does not match.
49221 CP (HL)
49222 JR NZ,MatchInputWord_NextWord
49224 INC DE Move to the next letter of the four-letter buffer.
49225 INC HL Move to the next vocabulary letter.
49226 DJNZ MatchInputWord_CompareChar Decrease the letter counter by one and loop back to MatchInputWord_CompareChar until the counter is zero.
The word matched. Calculate which token-buffer slot to use and store the vocabulary index as the token.
49228 EXX Turn the vocabulary index into a token-slot offset.
49229 LD A,9
49231 SUB C
49232 EXX
49233 LD D,0
49235 LD E,A
49236 LD HL,47926 Store that token in its slot at UserInput_FirstToken and parse the next word.
49239 ADD HL,DE
49240 LD (HL),C
49241 EXX
49242 JP Parser_MatchInputWord
This vocabulary word did not match. Step past the remaining letters. A comma keeps the same token for a synonym; anything else advances the token number for the next entry.
MatchInputWord_NextWord 49245 LD E,B Turn the remaining letter count into a 16-bit offset in DE.
49246 LD D,0
49248 ADD HL,DE Move HL past the unmatched letters.
49249 LD A,(HL) Fetch the next vocabulary byte into A.
49250 CP 44 Jump to MatchInputWord_NextEntry if this byte is not a comma (44).
49252 JR NZ,MatchInputWord_NextEntry
49254 INC HL Move past the comma.
49255 JR MatchInputWord_CompareWord Jump to MatchInputWord_CompareWord to try matching the synonym.
MatchInputWord_NextEntry 49257 INC C Advance the token number for the next vocabulary entry.
49258 JR MatchInputWord_Vocabulary Jump to MatchInputWord_Vocabulary.
The word is not in the vocabulary, so quote it and ask again.
MatchInputWord_Unknown 49260 EXX Find the unknown word in the command buffer.
49261 LD A,10
49263 SUB C
49264 LD C,A
49265 LD HL,47876
MatchInputWord_SeekWord 49268 DEC C Step back through the copied word count.
49269 JR Z,MatchInputWord_PrintUnknown
MatchInputWord_FindWord 49271 LD A,(HL) Skip characters until a space or a comma.
49272 CP 32
49274 JR Z,MatchInputWord_FindDelimiter
49276 CP 44
49278 JR Z,MatchInputWord_FindDelimiter
49280 INC HL
49281 JR MatchInputWord_FindWord
MatchInputWord_FindDelimiter 49283 INC HL Skip spaces and commas, then look for the next word.
49284 LD A,(HL)
49285 CP 32
49287 JR Z,MatchInputWord_FindDelimiter
49289 CP 44
49291 JR Z,MatchInputWord_FindDelimiter
49293 JR MatchInputWord_SeekWord
MatchInputWord_PrintUnknown 49295 PUSH HL Print "I don't know the word:-".
49296 LD HL,47989
49299 CALL PrintStringAndNewline
49302 POP HL Restore the command pointer from the stack.
49303 LD A,34 Print a quote.
49305 CALL PrintCharacter
MatchInputWord_Quote 49308 LD A,(HL) Print the unknown word up to the next space.
49309 CP 33
49311 JR C,MatchInputWord_CloseQuote
49313 INC HL
49314 CALL PrintCharacter
49317 JR MatchInputWord_Quote
MatchInputWord_CloseQuote 49319 LD A,34 Print a closing quote.
49321 CALL PrintCharacter
49324 LD HL,48377 Print "." and read another command.
49327 CALL PrintStringAndNewline
49330 JR Handler_UnknownWord_Retry
Prev: 49066 Up: Map Next: 49332