Prev: 839A Up: Map Next: 8405
83A7: Find the action and objects for a command
The target ($B5D9) and instrument (B5DA) are set to $FF (none) and the work area is cleared. 858F then finds the action table entry that matches the frame's verb, particle and preposition; if none does, the routine returns with Z set.
The action number (1-59) is worked out from the entry's address and stored in B5D8. The flags of the entry (8569) say whether the action needs a target and an instrument (bits 3 and 2 of $B60D). If it needs neither, the routine is done. Otherwise 8405 searches for suitable objects, trying each candidate with a dry run. If the objects cannot be decided, 87AD deals with it (asking 'which key?', saying 'I do not see the key', and so on). With ALL, 8464 moves on to the next object.
Output
F Z set if the command could not be matched
83A7 LD A,$FF No instrument or target chosen yet
83A9 LD ($B5DA),A
83AC LD ($B5D9),A
83AF CALL $839A Clear the work area
83B2 CALL $858F Find the action table entry that matches this frame's verb and words
83B5 RET Z No such action exists: give up
83B6 LD A,$01 Work out the action's own number...
83B8 PUSH IX
83BA POP HL
83BB LD DE,$AA47
83BE SBC HL,DE
83C0 JR Z,$83CA
83C2 LD DE,$0008 ...by counting how many 8-byte entries lie before it in the action table
83C5 INC A
83C6 SBC HL,DE
83C8 JR NZ,$83C5
83CA LD ($B5D8),A Remember the action number
83CD LD ($B5D7),A ...(kept a second time, so A79F can read Bard's own last order from it later)
83D0 LD ($834F),IX Remember the action table entry itself
83D4 CALL $8569 Work out what this action needs: a target, an instrument, whether it works in the dark
83D7 CALL $8492 Start searching for a target
83DA XOR A For now, everything is only a trial: nothing really happens yet
83DB LD ($B5EB),A
83DE LD A,($B60D) Does this action need a target, an instrument, or both?
83E1 AND $0C
83E3 JR Z,$8402 Neither: the action can go ahead with no objects at all
83E5 LD A,($8343) Is this whole command an ALL?
83E8 LD ($B60C),A
83EB RLCA Is only a single candidate wanted, rather than every matching object?
83EC AND $01
83EE LD ($8344),A
83F1 CALL $8405 Search for a workable target and instrument
83F4 JP NZ,$87AD None found, or more than one possible: explain why, or ask "which key?"
83F7 LD A,($B60C) Is this an ALL command, with more objects still to try?
83FA AND A
83FB JR Z,$8402 No: this one candidate is the whole answer
83FD CALL $8464 Yes: is there another object ALL should also apply to?
8400 JR NZ,$83F1 If so, search again with it in mind
8402 OR $01 Make A non-zero...
8404 RET ...telling the caller a workable command was found
Prev: 839A Up: Map Next: 8405