Prev: C4B7 Up: Map Next: C4EB
C4C7: Parser: Process Item
Used by the routine at GameLoop.
Processes the word tokens from the user's command, checking if any token refers to a game item. If a valid item token is found and the item is present (in the current room or player's inventory), the routine returns successfully. Otherwise, it continues checking tokens until one is found or all tokens have been processed.
Set up to loop through all word tokens in the token buffer.
Parser_ProcessItem C4C7 LD HL,$BD66 Set a pointer to the word token buffer (UserInput_Token_1) in HL.
C4CA LD B,$0A Set a counter in B for 0A tokens (the maximum number of words).
Check if there are any tokens to process. Return immediately if the first token is the terminator (FF), meaning the input was empty.
ProcessItem_Loop C4CC LD A,(HL) Return if the current token is FF (no more tokens to process).
C4CD CP $FF
C4CF RET Z
Check if this token refers to a game item by searching the object list table.
C4D0 PUSH HL Stash the token pointer and counter on the stack for later restoration.
C4D1 PUSH BC
C4D2 LD HL,($BD1E) Load the object list table pointer into HL.
C4D5 LD BC,($BD2A) Load the number of objects into BC (for the CPIR search).
C4D9 CPIR Search the object list table to see if the token matches any object ID.
C4DB JR NZ,ProcessItem_NextToken Jump to ProcessItem_NextToken if the token doesn't match any object ID (not an item token).
The token matches an object ID. Now verify that the item is actually present (in the current room or player's inventory).
C4DD CALL Action_ExamineItem Call Action_ExamineItem to check if the item is present and accessible.
C4E0 JR NC,ProcessItem_NextToken Jump to ProcessItem_NextToken if the item is not present (carry flag set).
The token refers to a valid item that is present. Success!
C4E2 POP BC Restore the token pointer and counter from the stack.
C4E3 POP HL
C4E4 RET Return successfully (the item was found and is accessible).
This token wasn't a valid item or the item isn't present. Move to the next token and continue searching.
ProcessItem_NextToken C4E5 POP BC Restore the token pointer and counter from the stack.
C4E6 POP HL
C4E7 INC HL Move to the next token in the buffer.
C4E8 DJNZ ProcessItem_Loop Decrease the counter by one and loop back to ProcessItem_Loop until all 0A tokens have been checked.
C4EA RET Return (no valid item tokens were found in the input).
Prev: C4B7 Up: Map Next: C4EB