| The Hobbit (v1.0) | Routines |
| Prev: 9606 | Up: Map | Next: 9686 |
|
Called once per turn after the player's command. First A8CA and 976C (via 9618 and 961B) let the other characters take their turns, then the timer table at C973 is processed.
Each 7-byte timer entry has: a reload value, the current count, the address of an 'expire' routine, a threshold, and the address of a 'tick' routine. A count of 0 means the timer is not running. For each running timer the count is decremented (963B). If it has just reached 0, the expire routine is called (9657). If it is still above 0 but at or below the threshold, the tick routine is called instead (966E).
Only one timer is allowed to expire per turn: the flag at $B5E1 records that one has already fired, and any other timer that reaches 0 in the same turn is given a count of 1 so that it fires next turn instead.
Timers are started by setting their count to their reload value, which various event routines do by copying byte 0 of the entry to byte 1 (for example C6CC).
|
||||
| 9611 | PUSH HL | Save the registers: the end of the turn must not disturb the caller | ||
| 9612 | PUSH IX | |||
| 9614 | PUSH IY | |||
| 9616 | PUSH BC | |||
| 9617 | PUSH DE | |||
| 9618 | CALL $A8CA | Has the game been won (treasure in the chest)? | ||
| 961B | CALL $976C | Let every other character take its turn | ||
| 961E | SUB A | No timer has expired yet this turn | ||
| 961F | LD ($B5E1),A | |||
| 9622 | INC A | From now on things really happen: set the "would work"... | ||
| 9623 | LD ($B5EC),A | |||
| 9626 | LD ($B5EB),A | ...and "really do it" flags | ||
| 9629 | LD IY,$C973 | IY = the first timer entry | ||
| 962D | LD A,(IY+$00) | Fetch its reload value | ||
| 9630 | CP $FF | $FF marks the end of the table | ||
| 9632 | JR Z,$9679 | All timers done: finish | ||
| 9634 | LD A,(IY+$01) | A = the timer's count | ||
| 9637 | CP $00 | Is the timer running? | ||
| 9639 | JR Z,$9671 | No: next timer | ||
| 963B | DEC A | Count down one turn | ||
| 963C | LD (IY+$01),A | |||
| 963F | CP $00 | Has it reached 0? | ||
| 9641 | JR NZ,$965C | Not yet: see whether it is time for the tick routine | ||
| 9643 | LD A,($B5E1) | It has expired. Has another timer already expired this turn? | ||
| 9646 | CP $01 | |||
| 9648 | LD (IY+$01),A | Set the count to 1 if so (so it fires next turn) or leave it at 0 | ||
| 964B | JR Z,$965C | Another timer has fired: wait until next turn | ||
| 964D | INC A | This is the first: note that a timer has fired this turn | ||
| 964E | LD ($B5E1),A | |||
| 9651 | LD L,(IY+$02) | HL = the expire routine... | ||
| 9654 | LD H,(IY+$03) | |||
| 9657 | CALL $9AC7 | ...and run it | ||
| 965A | JR $9671 | Next timer | ||
| 965C | LD A,(IY+$04) | A = the threshold for the tick routine | ||
| 965F | CP $00 | Is there one? | ||
| 9661 | JR Z,$9671 | No: next timer | ||
| 9663 | CP (IY+$01) | Is the count at or below the threshold? | ||
| 9666 | JR C,$9671 | No: next timer | ||
| 9668 | LD L,(IY+$05) | HL = the tick routine... | ||
| 966B | LD H,(IY+$06) | |||
| 966E | CALL $9AC7 | ...and run it | ||
| 9671 | LD DE,$0007 | Move on to the next 7-byte entry | ||
| 9674 | ADD IY,DE | |||
| 9676 | JP $962D | Loop | ||
| 9679 | LD A,$01 | Turn output back on for the player | ||
| 967B | LD ($B5F3),A | |||
| 967E | POP DE | Restore the registers | ||
| 967F | POP BC | |||
| 9680 | POP IY | |||
| 9682 | POP IX | |||
| 9684 | POP HL | |||
| 9685 | RET | |||
| Prev: 9606 | Up: Map | Next: 9686 |