Prev: BFAA Up: Map Next: C0B4
BFC1: 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 BFC1 LD (HL),A Store ENTER as the end of the command.
BFC2 CALL SwitchNormalScreenOutput Call SwitchNormalScreenOutput to select the screen channel.
BFC5 CALL PrintCharacter Call PrintCharacter to echo ENTER.
BFC8 LD HL,$BB36 Start at the token buffer (UserInput_FirstToken) and prepare the empty marker FF.
BFCB LD A,$FF
BFCD LD B,$0A
EmptyWordTokenBuffer_Loop BFCF LD (HL),A Write FF into each of the 0A token slots.
BFD0 INC HL
BFD1 DJNZ EmptyWordTokenBuffer_Loop
BFD3 LD HL,$BB04 Start at the command and allow 0A words, then fall into the parser.
BFD6 LD C,$0A
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 BFD8 LD DE,$BB41 DE=FourLetterBuffer.
BFDB LD B,$04 Set a counter in B for the 04 letters.
BFDD LD A,$20 A=20.
MatchInputWord_Clear BFDF LD (DE),A Write a space character (20) to the buffer.
BFE0 INC DE Move to the next letter.
BFE1 DJNZ MatchInputWord_Clear Decrease the counter by one and loop back to MatchInputWord_Clear until the counter is zero.
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 of the same token; FF ends the table.
C035 LD HL,($BADC) HL=*Pointer_Vocabulary.
C038 LD C,$00 Set the token number in C to 00.
MatchInputWord_Vocabulary C03A LD A,(HL) Jump to MatchInputWord_Unknown if the word is the FF terminator.
C03B CP $FF
C03D JR Z,MatchInputWord_Unknown
MatchInputWord_CompareWord C03F LD DE,$BB41 DE=FourLetterBuffer.
C042 LD B,$04 Set a counter in B for the 04 letters.
MatchInputWord_CompareChar C044 LD A,(DE) Jump to MatchInputWord_NextWord if this letter does not match.
C045 CP (HL)
C046 JR NZ,MatchInputWord_NextWord
C048 INC DE Move to the next letter of the four-letter buffer.
C049 INC HL Move to the next vocabulary letter.
C04A 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.
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 UserInput_FirstToken and parse the next word.
C057 ADD HL,DE
C058 LD (HL),C
C059 EXX
C05A 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 C05D LD E,B Turn the remaining letter count into a 16-bit offset in DE.
C05E LD D,$00
C060 ADD HL,DE Move HL past the unmatched letters.
C061 LD A,(HL) Fetch the next vocabulary byte into A.
C062 CP $2C Jump to MatchInputWord_NextEntry if this byte is not a comma (2C).
C064 JR NZ,MatchInputWord_NextEntry
C066 INC HL Move past the comma.
C067 JR MatchInputWord_CompareWord Jump to MatchInputWord_CompareWord to try matching the synonym.
MatchInputWord_NextEntry C069 INC C Advance the token number for the next vocabulary entry.
C06A JR MatchInputWord_Vocabulary Jump to 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 PrintStringAndNewline
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 PrintStringAndNewline
C0B2 JR Handler_UnknownWord_Retry
Prev: BFAA Up: Map Next: C0B4