Prev: AF9B Up: Map Next: AFE1
AFB3: Search Command Handler Table
Used by the routines at AAB2 and AB52.
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 AFB3 LD HL,$AF6B Set the table pointer to Table_CommandHandlerLookup_Standard.
AFB6 LD A,($A024) Check which lookup table to use based on the current mode.
AFB9 CP $02
AFBB JR NZ,SearchCommandHandlerTable_StartSearch Use the alternate lookup table if the mode is 02.
AFBD LD HL,$AF9B Else, set the table pointer to Table_CommandHandlerLookup_Alternate.
SearchCommandHandlerTable_StartSearch AFC0 PUSH DE Stash DE on the stack.
AFC1 LD E,$0C Set the table entry counter to 0C entries, or 06 if the mode is 0C.
AFC3 JR NZ,SearchCommandHandlerTable_Loop
AFC5 LD E,$06
SearchCommandHandlerTable_Loop AFC7 LD A,(HL) Check if the first value in the current table entry matches the search value.
AFC8 INC HL
AFC9 CP C
AFCA JR NZ,SearchCommandHandlerTable_NextEntry Skip to the next entry if it doesn't match.
AFCC LD A,(HL) Check if the second value in the current table entry matches the search value.
AFCD CP B
AFCE JR Z,SearchCommandHandlerTable_Found Jump to the handler if both values match.
SearchCommandHandlerTable_NextEntry AFD0 INC HL Move to the next table entry.
AFD1 INC HL
AFD2 INC HL
AFD3 DEC E Decrease the entry counter and continue searching if there are more entries.
AFD4 JR NZ,SearchCommandHandlerTable_Loop
SearchCommandHandlerTable_NotFound AFD6 POP DE Restore DE from the stack.
AFD7 JP $AF67 Jump to AF67 (no handler found).
A handler was found, use it!
SearchCommandHandlerTable_Found AFDA INC HL Load the handler pointer from the table entry.
AFDB LD E,(HL)
AFDC INC HL
AFDD LD D,(HL)
AFDE EX DE,HL
AFDF POP DE
AFE0 JP (HL) Jump to the handler.
Prev: AF9B Up: Map Next: AFE1