Skip to main content

Timing routines

Routines · Data · Address index

Waits, timed callbacks, character timers and the timer interrupt. The routines page explains how the entries are written.

0x19242 — Wait​

  • Range: 0x19242–0x19274
  • Role: Waits until the free-running counter has advanced by the number of ticks given, in a busy loop; the game loop does not run meanwhile. The spell animations call it with 2 (0x213e4, 0x21598), as does the spell routine at 0x23bba.
  • Used by: —

0x2d9b3, 0x2d9d1, 0x34059, 0x2f7a3 — Wait for screen refreshes​

  • Ranges: 0x2d9b3–0x2d9d0, 0x2d9d1–0x2d9df, 0x34059–0x34084; 0x2f7a3–0x2f86a
  • Status: the duration in seconds depends on the refresh rate of the display mode, about 70 per second in the VGA 320 × 200 mode (inferred).
  • Role: 0x2f7a3, at start-up (0x315ac), reads that bit 10,000 times and sets DS:0xf16c to 1 when it finds it set more often than clear. 0x34059(mode) polls bit 3 of the video status port 0x3da: with mode 1 it waits until a vertical retrace starts, otherwise until the current or next one ends. 0x2d9b3(n) calls it n times with the word DS:0xf16c as mode, so it waits n screen refreshes, without the game's clock; 0x2d9d1 waits one. Button presses wait 5 (camp menus, slot menus, party creation); the message box waits at most 120 single refreshes; the ending's palette routines wait for a retrace before sending colours (0x500e0).
  • Used by: Message box, Fade one colour to black, Press a button, Choose a slot, Camp menus

0x28116 — Timed callbacks​

0x283ab — End a hand's wait​

  • Range: 0x283ab–0x283f4
  • Role: 0x283ab(character, mode, hand) clears the result of that hand, slot_status at +0x14e, and redraws the character. Modes 0 and 2 first toggle the hand's bit in disabled_slots at +0x20; mode 1 does not. The character timer events 0 to 5 call it.
  • Used by:

0x28194, 0x281dd — Set a timed callback​

  • Role: Set an entry of the timed-callback table: 0x28194 writes the enabled flag, argument and byte +0xe; 0x281dd writes the enabled flag only. Both set the deadline to the current counter plus the entry's interval. 0x281dd enables and disables the character-exchange blink (entry 0) and enables the door animation (entry 12) when a door operation starts. 0x28194 is never called: no far or near call and no stored pointer reaches it.
  • Used by: Timed updates › The table of timed updates, Scripted walls and doors

0x28218, 0x27b7f, 0x283f5, 0x2807e, 0x2893f, 0x2899c — Timed-callback handlers​

0x28227 — Set a character timer​

  • Range: 0x28227–0x283aa
  • Role: Arguments: character, duration (dword, ticks), event code and a replace flag. The deadline is the shared counter plus the duration, and the character's entry is entry 6 + character of the timed-callback table. When that entry is off (0x2826e–0x282b1), its interval becomes the duration, the timer goes in pair 0 of the character record and the entry is switched on through set a timed callback. Otherwise the entry's deadline is lowered to the new one when that is earlier (0x282b4–0x282d8); then, with flag 0, the timer takes the first free pair or is dropped (0x282e4–0x2832d), and with any other flag it takes the pair holding the same event, or else the first free pair (0x2832f–0x283a0). The timer handler runs the event when the deadline passes; the character timers list the event codes.
  • Anomaly: with flag ≠ 0, ten pairs in use and none holding the event, the index stays −1: nothing tests it after the search (0x2837f), and the writes at 0x2838a–0x283a0 put the deadline at +0x10f (inventory slots 25 and 26) and the event at +0x13a (the top byte of the tenth deadline).
  • Callers: all pass flag 1. 0x1daaf (event 7) and 0x1dbb0 (event 12), 546 × (1d4 + 4) ticks, two cases of the eight-way switch at 0x1da63 that set strength 22 (0x1da7f) and spell_effects bit 16 (0x1db83); 0x1ff40, 18 ticks, event hand + 2, or hand for a result below −2 (use a weapon slot); 0x20b1a, 18 ticks, event 6 (damage a character); 0x20c04, 546 × the duration argument, with the event argument (afflict); 0x20f33, the spell timer, event − definition, passing its own flag; 0x21031, 18 ticks, event hand + 2, after a spell cast from a held item (0x20fff); 0x22a60, 72 ticks, event 11, after setting bit 2 of the caster's disabled_slots (0x22a4a); 0x2851e and 0x28575, events 4 and 5, 9 ticks under Haste or 36; 0x2867e, 546 ticks, event 8.
  • Comparative source: REF-SCUMM-022, setCharEventTimer.
  • Used by: Character record › Character timers, Character timers › Setting and running a timer, Timed updates › The table of timed updates, Anomalies and bugs

0x287e5 — Re-arm the character timer updates​

0x33e1e, 0x33e63 — Timer interrupt​

0x31879, 0x318ad — Restart and stop a counter​