Prev: 42459 Up: Map Next: 42540
42506: Parser: Count Item References
Count how many tokens in the user input refer to game items.
Output
A The number of references to items in the user input tokens
F The Z flag is set when there are no items present in the input
Parser_CountItems 42506 LD HL,41275 Set a pointer to UserInput_Token_1 in HL.
42509 LD B,10 Set a token count in B of 10 which is the total length of the user input tokens.
42511 LD E,0 Initialise the item counter held in E to 0.
Parser_CountItems_Loop 42513 LD A,(HL) Fetch a user input token.
42514 CP 255 Jump to Parser_CountItems_Process if the terminator character (255) has been reached.
42516 JR Z,Parser_CountItems_Process
42518 PUSH HL Stash the token pointer and token counter on the stack.
42519 PUSH BC
42520 LD HL,46238 HL=Table_TokenItemList.
42523 LD BC,(48073) Fetch the count of the number of items in the table from *Count_Objects_2.
42527 CPIR Search to see if the item ID is in the table.
42529 POP BC Restore the token counter and token pointer from the stack.
42530 POP HL
42531 JR NZ,Parser_CountItems_Skip Jump to Parser_CountItems_Skip if this token doesn't refer to a game item.
This token does point to a game item, so increase the item counter.
42533 INC E Increment item counter by one.
Parser_CountItems_Skip 42534 INC HL Move to the next token.
42535 DJNZ Parser_CountItems_Loop Decrease the token counter by one and loop back to Parser_CountItems_Loop until all the tokens have been evaluated.
Parser_CountItems_Process 42537 XOR A Transfer the item count into A and set flags accordingly.
42538 OR E
42539 RET Return.
View the equivalent code in;
Prev: 42459 Up: Map Next: 42540