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 at0x23bba. - 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 setsDS:0xf16cto 1 when it finds it set more often than clear.0x34059(mode)polls bit 3 of the video status port0x3da: 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 wordDS:0xf16cas mode, so it waits n screen refreshes, without the game's clock;0x2d9d1waits 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
- Range:
0x28116–0x28193 - Role: Walks the timed-callback table in entry order.
Each enabled entry whose deadline is strictly below the
shared counter has its handler called with
its argument; if the entry is still enabled afterwards, its deadline
becomes the current counter plus its interval. It then calls the
step trigger (
0x28181), the script timers (0x28186) and the temporary-wall expiry (0x2818c). Its only literal caller is0x1ca35, in the game loop. - Comparative source: REF-SCUMM-014,
runLoop(_timer->update,updateScriptTimers,updateWallOfForceTimers). - Used by: The engine › How the systems connect, The game loop › One pass of the game loop, Timed scripts › Step-triggered script, Timed scripts › Timed block scripts, Timed updates › The table of timed updates
0x283ab — End a hand's wait
- Range:
0x283ab–0x283f4 - Role:
0x283ab(character, mode, hand)clears the result of that hand,slot_statusat+0x14e, and redraws the character. Modes 0 and 2 first toggle the hand's bit indisabled_slotsat+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:
0x28194writes the enabled flag, argument and byte+0xe;0x281ddwrites the enabled flag only. Both set the deadline to the current counter plus the entry's interval.0x281ddenables and disables the character-exchange blink (entry 0) and enables the door animation (entry 12) when a door operation starts.0x28194is 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
- Role: Handlers named in the timed-callback table,
besides the flying-object mover and the
door animation:
0x28218calls the monster update for the update group given as its argument;0x27b7falternately draws and hides the portrait of the character being exchanged;0x283f5processes the ten character timers of the character given as its argument: an expired timer is cleared, and a negative event code − n calls end a spell's effect(n, character, 1) at0x28469–0x2848c; codes 0 to 12 go through a jump table atcs:0xc5b(analysis0x287cb, file offset0x1b9cb), whose entries are0x284a9,0x284ba,0x284ce,0x28527,0x2857e,0x28592,0x285a7,0x285bd,0x28643,0x2869a,0x28704(code 10, no effect),0x286e0and0x2860f: 8, poison, deals 5 points of damage with flag0x400and comes back in 546 ticks while the character stays poisoned; 9 ends paralysis; 12 ends Haste; the character timers list the other codes. A timer is processed once its deadline is at or below the counter (0x28439–0x2844d). Afterwards (0x2870d–0x287c2) the entry's interval becomes the earliest remaining deadline minus the counter, so that the walk schedules it for that deadline, or the entry is switched off when no timer is left;0x2807etoggles an animation phase and requests a redraw when one of the 18 visible blocks showsWALL_REFERENCE_TELEPORTERorWALL_REFERENCE_TEMPORARY_WALL(SpecialWallReference);0x2893fdecrements the food byte+0x25of each present character whose food is not zero and whose hit points are above −10. It calls the ring search with value 2 but skips a character only on a negative result, which that routine never returns (0x2895c–0x28966);0x2899cgives every monster slot outside modes 7 and 10 and withoutMONSTER_RUNTIME_TURNED_TO_STONE, on a 1d2 roll, a newidle_offset(+0x17) made of two 1d2 rolls, one per four-bit half, and requests a redraw of its block; it tests no hit points.
- Comparative source: REF-SCUMM-014,
timerProcessMonsters,timerProcessCharacterExchange,timerSpecialCharacterUpdate,timerUpdateTeleporters,timerUpdateFoodStatusandtimerUpdateMonsterIdleAnim; REF-SCUMM-020,timerUpdateMonsterIdleAnim; REF-SCUMM-021,timerSpecialCharacterUpdate. - Used by: Character conditions › How a character gets a condition, Character record › Character timers, Character record › Portrait, Damage flags › Effects, Lasting spell effects, Lasting spells › The timer, Lasting spells › What lasting effects do, Monster behavior modes › How each mode behaves, Monster behavior modes, Melee attacks › Effects on characters, Monsters › How a monster acts, Modes and provocation › What a monster's state changes, Monster state flags › Alternating melee attacks, Monster state flags › Turned to stone, Spell definition › How the game uses it, Character timers › Setting and running a timer, Timed updates › Food, Timed updates › The table of timed updates, Timed updates › The table of timed updates, Wall references with built-in effects, Attributes and classes, Anomalies and bugs
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 at0x2838a–0x283a0put 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) and0x1dbb0(event 12), 546 × (1d4 + 4) ticks, two cases of the eight-way switch at0x1da63that set strength 22 (0x1da7f) andspell_effectsbit 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'sdisabled_slots(0x22a4a);0x2851eand0x28575, 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
- Range:
0x287e5–0x288df(file offsets0x1b9e5–0x1badf) - Role: For each present character, finds the earliest nonzero timer deadline and sets that character's entry of the timed-callback table to fire at that moment, through set a timed callback; a character without a pending timer has its entry switched off. Called after the character timers have been converted back into deadlines.
- Used by: Character record › Character timers, Character record › Portrait, Formation › Changing the formation, Loading, failures and the end of the game › Loading a saved game, Recruiting and dismissing characters
0x33e1e, 0x33e63 — Timer interrupt
- Addresses:
0x33e1e,0x33e63(file offsets0x2701e,0x27063); restore at0x33e46 - Role:
0x33e1e, called at0x3186eduring start-up, saves the INT 1Ch vector and installs0x33e63;0x33e46, called at0x31610, puts the saved vector back. INT 1Ch is raised by the BIOS on each system timer tick, 18.2 times per second whatever the sound driver. On each one,0x33e63adds 1 to DS:0x6680when bit 0 of the counter switches is set and to the shared counter when bit 1 is set (0x33e6a–0x33e84); adds 1 to the word DS:0x667a, to the free-running counter and to the dword DS:0x6688; takes 1 from the flash countdown when it is not zero; then jumps to the previous handler. - Comparative source: REF-SCUMM-022,
_tickLength. - Used by: The game clock › Ticks and the two counters, Timed scripts › Timed block scripts, Wait › Behavior, Level data (INF)
0x31879, 0x318ad — Restart and stop a counter
- Ranges:
0x31879–0x318ac,0x318ad–0x318e2 - Role: With argument n,
0x31879sets and0x318adclears bit n − 1 of the counter switches, so that the timer interrupt advances or leaves the counter; they are the only writers of DS:0x6690. Each returns whether bit n was set. Every caller passes 2, the shared counter, and ignores the result. The calls, stop then restart:0x1a1dc,0x1a2a3in the close-range action;0x1a9e5,0x1aa34in flash a damaged monster;0x21416,0x215f2in the spell animations;0x22f43,0x233a3in draw an explosion;0x2348b,0x23906in the Cone of Cold vortex;0x4449d,0x44c7cin the camp menu;0x48d51,0x48f51in the INF level loader;0x491b8,0x49259and0x4932d,0x4935bin pack and unpack a level record. Each pair is balanced: no path leaves between the two calls without the restart, except the close-range action, which skips both when the monster is not in front of the party. - Anomaly: the result is computed with a shift by n
(
0x31884,0x318b8) while the change uses a shift by n − 1 (0x3189a,0x318ce), so it reports bit n, not the bit changed. - Comparative source: REF-SCUMM-022,
disableSysTimerandenableSysTimer. - Used by: The game clock › Pauses, Anomalies and bugs