Prev: 44955 Up: Map Next: 45025
44979: Search Command Handler Table
Used by the routines at 43698 and 43858.
Searches through a command handler lookup table for a matching value pair and jumps to the associated handler routine if found.
Input
B Second value to match
C First value to match
SearchCommandHandlerTable 44979 LD HL,44907 Set the table pointer to Table_CommandHandlerLookup_Standard.
44982 LD A,(40996) Check which lookup table to use based on the current mode.
44985 CP 2
44987 JR NZ,SearchCommandHandlerTable_StartSearch Use the alternate lookup table if the mode is 2.
44989 LD HL,44955 Else, set the table pointer to Table_CommandHandlerLookup_Alternate.
SearchCommandHandlerTable_StartSearch 44992 PUSH DE Stash DE on the stack.
44993 LD E,12 Set the table entry counter to 12 entries, or 6 if the mode is 12.
44995 JR NZ,SearchCommandHandlerTable_Loop
44997 LD E,6
SearchCommandHandlerTable_Loop 44999 LD A,(HL) Check if the first value in the current table entry matches the search value.
45000 INC HL
45001 CP C
45002 JR NZ,SearchCommandHandlerTable_NextEntry Skip to the next entry if it doesn't match.
45004 LD A,(HL) Check if the second value in the current table entry matches the search value.
45005 CP B
45006 JR Z,SearchCommandHandlerTable_Found Jump to the handler if both values match.
SearchCommandHandlerTable_NextEntry 45008 INC HL Move to the next table entry.
45009 INC HL
45010 INC HL
45011 DEC E Decrease the entry counter and continue searching if there are more entries.
45012 JR NZ,SearchCommandHandlerTable_Loop
SearchCommandHandlerTable_NotFound 45014 POP DE Restore DE from the stack.
45015 JP 44903 Jump to 44903 (no handler found).
A handler was found, use it!
SearchCommandHandlerTable_Found 45018 INC HL Load the handler pointer from the table entry.
45019 LD E,(HL)
45020 INC HL
45021 LD D,(HL)
45022 EX DE,HL
45023 POP DE
45024 JP (HL) Jump to the handler.
Prev: 44955 Up: Map Next: 45025