| The Hobbit (v1.0) | Routines |
| Prev: 9436 | Up: Map | Next: 953F |
|
Performs the current action (B5D8) with the current target ($B5D9) and instrument (B5DA). During a dry run ($B5EB = 0) nothing is printed or changed, and the routines report success in B5EC instead.
First the basic checks: the action must make sense (9A9F: you cannot, for instance, give something to yourself; if it fails, 'I cannot do that.'). If it is dark (954D) and the action needs light, 'I see nothing.' unless the objects are being carried. The records of the target and instrument are found and saved in B5F8 and $B5FA, and each must be within reach (9686).
Then the handlers are found. If the target (or, for certain actions listed at A13B, the instrument) has handlers of its own for this action (9ADC), they are called one after another: the matching entry and any entries with action 0 straight after it. Otherwise the default handler for the action is looked up in C61F. If there is none, 'I cannot do that.'
|
||||
| 946F | PUSH HL | |||
| 9470 | PUSH IX | |||
| 9472 | PUSH BC | |||
| 9473 | CALL $9A9F | Does the action make sense (not done to yourself, and so on)? | ||
| 9476 | JP Z,$953A | No: "I cannot do that." | ||
| 9479 | CALL $954D | Is it too dark for Bilbo to see? | ||
| 947C | JR NC,$9499 | No: carry on | ||
| 947E | LD A,($B601) | Dark. Can this action be done in the dark anyway? | ||
| 9481 | AND A | |||
| 9482 | JR NZ,$9491 | No: "I see nothing" | ||
| 9484 | CALL $9BCD | Is the target something Bilbo is holding? | ||
| 9487 | JR NC,$9491 | No: "I see nothing" | ||
| 9489 | LD A,($B5DA) | Is the instrument something he is holding? | ||
| 948C | CALL $9BD0 | |||
| 948F | JR C,$9499 | Yes: he can manage by touch | ||
| 9491 | LD HL,$AEB7 | "I see nothing." | ||
| 9494 | CALL $72D4 | |||
| 9497 | JR $94FB | |||
| 9499 | LD A,($B5EF) | Is the target a room? | ||
| 949C | CP $01 | |||
| 949E | JP Z,$952C | Yes: straight to the default handler | ||
| 94A1 | LD A,($B5D9) | Is there a target? | ||
| 94A4 | CP $FF | |||
| 94A6 | JP Z,$952C | No: straight to the default handler | ||
| 94A9 | CALL $9B25 | IX = the target's record... | ||
| 94AC | LD ($B5F8),IX | ...which is saved for the handlers | ||
| 94B0 | LD A,($B5D9) | Is it within the player's reach? | ||
| 94B3 | CALL $9686 | |||
| 94B6 | JR NZ,$94FB | No: stop (the reason has been printed) | ||
| 94B8 | LD A,($B5DA) | Is there an instrument? | ||
| 94BB | CP $FF | |||
| 94BD | JR Z,$94DA | No: use the target's handlers | ||
| 94BF | LD A,($B5F0) | Is the instrument a room? | ||
| 94C2 | CP $01 | |||
| 94C4 | JR Z,$952C | Yes: default handler | ||
| 94C6 | LD A,($B5DA) | IX = the instrument's record... | ||
| 94C9 | CALL $9B25 | |||
| 94CC | LD ($B5FA),IX | ...saved for the handlers | ||
| 94D0 | CALL $9686 | Is it within reach? | ||
| 94D3 | JR NZ,$94FB | No: stop | ||
| 94D5 | CALL $A100 | Is this one of the actions the instrument handles (PUT IN, TAKE OUT OF...)? | ||
| 94D8 | JR Z,$94DE | Yes: use the instrument's handlers (IX is still its record) | ||
| 94DA | LD IX,($B5F8) | Otherwise use the target's | ||
| 94DE | LD A,($B5D8) | A = the action | ||
| 94E1 | CALL $9ADC | Does the object have its own handler for it? | ||
| 94E4 | JR NC,$952C | No: use the default handler | ||
| 94E6 | LD L,(IX+$01) | HL = the handler... | ||
| 94E9 | LD H,(IX+$02) | |||
| 94EC | CALL $9AC7 | ...run it | ||
| 94EF | INC IX | Next entry in the list | ||
| 94F1 | INC IX | |||
| 94F3 | INC IX | |||
| 94F5 | SUB A | Is it action 0 (a chained handler)? | ||
| 94F6 | CP (IX+$00) | |||
| 94F9 | JR Z,$94E6 | Yes: run that too | ||
| 94FB | LD A,($B5EB) | Did the action really happen? | ||
| 94FE | CP $01 | |||
| 9500 | JR NZ,$9527 | No: done | ||
| 9502 | LD A,($B5DB) | Was it the player? | ||
| 9505 | CP $00 | |||
| 9507 | JR NZ,$950F | No: skip | ||
| 9509 | CALL $954D | If the player is in the dark, add "it is dark." | ||
| 950C | CALL C,$72D4 | |||
| 950F | LD A,($B5D8) | B = the action | ||
| 9512 | LD B,A | |||
| 9513 | LD A,($B5D9) | Let the target react (a character that was attacked, say) | ||
| 9516 | LD IX,($B5F8) | |||
| 951A | CALL $953F | |||
| 951D | LD A,($B5DA) | Let the instrument react too | ||
| 9520 | LD IX,($B5FA) | |||
| 9524 | CALL $953F | |||
| 9527 | POP BC | |||
| 9528 | POP IX | |||
| 952A | POP HL | |||
| 952B | RET | |||
| 952C | LD A,($B5D8) | DEFAULT HANDLER: look the action up in C61F | ||
| 952F | LD IX,$C61F | |||
| 9533 | CALL $9D12 | |||
| 9536 | CP $FF | Found? | ||
| 9538 | JR NZ,$94E6 | Yes: run it | ||
| 953A | CALL $72C5 | No: "I cannot do that." | ||
| 953D | JR $9527 | |||
| Prev: 9436 | Up: Map | Next: 953F |