Skip to main content

Dialogue screen

SCRIPT_DIALOGUE · opcode 0xe3 · 2 to 22 bytes

Script virtual machine · Opcode list · Scripted dialogue

Drives the illustrated dialogue screen: it opens and closes that screen, draws pictures, shows texts and asks the player to choose an answer.

Encoding​

Offsets count from the opcode byte. Words are little-endian. The signed byte at offset 1 is a ScriptDialogueCommand and decides what follows. Sizes include the opcode and the selector.

SelectorByteOperands after the selectorSize
SCRIPT_DIALOGUE_BITMAP0xd3name_raw: 13 bytes, frame: s8, source_x: u16le, source_y: u16le, flags: u16le22 bytes
SCRIPT_DIALOGUE_RESTORE0xd4None2 bytes
SCRIPT_DIALOGUE_INITIALIZE0xd5None2 bytes
SCRIPT_DIALOGUE_BOX0xd6None2 bytes
SCRIPT_DIALOGUE_CHOICE0xd8text_id: u16le, option_1: u16le, option_2: u16le, option_3: u16le10 bytes
SCRIPT_DIALOGUE_TEXT0xf8text_id: u16le, prompt: u16le6 bytes
Any other value—None; the handler returns after the selector2 bytes

Two kinds of text are involved. A text_id selects a text of TEXT.DAT, loaded when the screen opens. prompt and the option_* words are indices of strings in the level's message table, the one that Print a message uses. The handler does not check that the commands come in a sensible order; what happens when they do not is described under edge cases.1

Example (constructed, not from a level): e3 f8 14 00 05 00 shows text 20 of TEXT.DAT with message 5 of the level as the prompt label.

Opening and closing the screen​

SCRIPT_DIALOGUE_INITIALIZE forgets the last drawn picture, sets the prompt label to the built-in string MORE, marks the dialogue screen as active and reads up to 32 000 bytes of TEXT.DAT into the dialogue-text buffer. It then makes the dialogue text window the active one, with its cursor at the top left, and turns page waits on, with the dialogue's own wait prompt as the routine that waits. It also closes the inventory panel and the spell book and plays sound 0, which stops the sound in progress.2

SCRIPT_DIALOGUE_RESTORE marks the screen as inactive, forgets the last picture, turns page waits off, makes the message area at the bottom of the screen the active text window again, rebuilds the play screen (wall graphics, view and portraits), plays sound 2, and requests a scene update, as Move the party, monsters or items also does.2

SCRIPT_DIALOGUE_BOX takes no operand. It draws a framed box over the lower part of the screen, the full width from row 121 to row 199, and clears the text window, whose cursor returns to the top left.3

Drawing a picture​

OperandMeaning
name_rawZero-terminated resource base name. In all 237 reference instructions it is at most 8 characters and names an existing .CPS file.
frameA ScriptDialogueBitmapFrame: index into the destination tables below.
source_xLeft edge of the source region, in 8-pixel columns.
source_yTop edge of the source region, in pixels.
flagsScriptDialogueBitmapFlags; only SCRIPT_DIALOGUE_BITMAP_KEEP_BACKGROUND and SCRIPT_DIALOGUE_BITMAP_TRANSITION are tested.

The bytes after the name's terminator are not read. In the reference files they hold unrelated leftover bytes, so an editor must preserve the whole 13-byte field rather than regenerate it.4

The destination and size of the copied region come from two-entry tables in the executable, indexed by frame; other values read neighboring data, as described under edge cases:

frameDestination (pixels)Size (pixels)
SCRIPT_DIALOGUE_FRAME_PICTURE (0)x 8, y 8160 × 96
SCRIPT_DIALOGUE_FRAME_FULL (1)x 0, y 0320 × 121

The picture is then drawn in these steps:4

  1. Choose the target page: the visible screen if flags has SCRIPT_DIALOGUE_BITMAP_TRANSITION or frame is nonzero, otherwise a work page.
  2. If no picture is remembered, or name_raw differs from the remembered name (case-sensitive):
    • for frame 0 only, draw the 184 × 121 frame area from the BORDER picture, or keep the current screen content if flags has SCRIPT_DIALOGUE_BITMAP_KEEP_BACKGROUND;
    • load the named picture and remember it.
  3. Copy the region at (source_x × 8, source_y) of the table's size to the table's destination. With SCRIPT_DIALOGUE_BITMAP_TRANSITION, the pixel dissolve performs the copy directly to the screen, one pixel at a time in a shuffled order.
  4. If the work page was used, copy its 184 × 121 area to the screen.

The handler remembers a pointer to the name inside the script buffer, not a copy of it. SCRIPT_DIALOGUE_INITIALIZE and SCRIPT_DIALOGUE_RESTORE clear it, so the first picture after either is always loaded.

The reference scripts use only source_x 0 or 20 and source_y 0 or 96. With frame 0 these select one of four 160 × 96 regions of a 320 × 192 area of the picture. Every picture drawn with frame 0 is a full-screen image holding such a 2 × 2 grid; its last eight rows are not used. In some files the four pictures are variants of one scene that differ in small parts, as in KHELBEN or STONEGIA; in others they are unrelated pictures, as in SOUT1. The bottom-right picture of TANGLOR is empty and never drawn, that of SOUT4 is never drawn, and that of SUICIDE, a plain colour-12 area, is drawn. DARKMOON, the only picture drawn with frame 1, is used from its top 121 rows.

Text window and pages​

Texts appear in a window of 304 × 64 pixels whose top left corner is at x 8, y 125, below the picture area. With the 6 × 6 font the game uses during play (inferred: the game installs that font when play starts and the dialogue routines do not change it), the window holds 10 lines of 50 characters. Letters are drawn in colour 15 on the interface's background colour. A text starts where the window's cursor is: at the top left after SCRIPT_DIALOGUE_INITIALIZE, SCRIPT_DIALOGUE_BOX or a wait, and otherwise just after the previous text, so two texts shown without a prompt or box between them run on.5

Three control bytes occur in the texts of TEXT.DAT:

ByteEffect
0x01Page break: wait for the player at once, then go on at the top of the cleared window.
0x06 nDraw the rest of the text in colour n; the texts use 9 (the colour of a highlighted answer) and 15.
0x0dStart a new line.

The colour returns to 15 when the text ends. The game's text printer knows a few other control bytes, listed in the executable reference; the reference texts do not use them.

Words are wrapped at spaces. The printer collects characters until they would pass the right edge, then cuts the line:

when the pending characters do not fit in the room left on the line:
cut after the last space that fits
if there is no such space:
if the line already holds text: move all of them to the next line
else: cut at the right edge, in the middle of the word
drop the space at the cut, and one more if it is doubled

On the last three lines of each page (lines 8 to 10) the room is seven characters shorter, 43 characters with the 6-pixel font.

A text that needs more lines than the window holds is shown in pages: when a line would fall below the bottom, the game waits for the player with the current prompt label, normally MORE, then clears the window and goes on at the top. A page therefore shows ten new lines. A text that just fits does not wait; only its prompt, if any, does.

Waiting for the player​

A wait shows one button below the text window: a framed box of 95 × 9 pixels at x 221, y 189, with the prompt label centered in colour 15. The mouse pointer stays visible (inferred from the pointer bookkeeping around the wait). Keys pressed before it appears are discarded. The wait then ends on:

  • Space, Enter (either key) or M, with or without Shift, Ctrl or Alt;
  • a press of either mouse button with the pointer inside the button.

Every other key, a click elsewhere and button releases are ignored, and there is no time limit. The button is then erased and the text window cleared. The same wait serves page breaks and the prompt that follows a text.6

The wait does nothing but read the input queue. The script runs inside the step of the game loop that started it, so neither monsters nor the game's timed updates advance while the player reads: they resume when the script ends, each overdue update running once.6

Displaying a text​

OperandMeaning
text_idOne-based entry of the offset table at the start of the dialogue-text buffer.
promptMessage used as the label of a wait prompt after the text; an empty string shows no prompt.

The text routine reads entry text_id − 1 of the table and prints the text at that offset in the same buffer, as described under text window and pages. If the prompt string exists and is not empty, the routine copies it to the prompt label, waits for the player, then resets the label to MORE. The index −1 gives no string and therefore no prompt. A text_id of zero or beyond the table is not checked.7

In the reference TEXT.DAT, the table has 122 entries and every reference text_id lies between 1 and 122. The most frequent value, 20 (86 of the 168 text instructions), selects an entry consisting of a single space: such instructions mainly display their prompt. Thirty-four of the 168 instructions use an empty prompt string.

Asking for a choice​

OperandMeaning
text_idText displayed first, as for SCRIPT_DIALOGUE_TEXT but without a prompt.
option_1, option_2Messages labelling the first two answers.
option_3Third answer, or −1 for a two-answer question.

The game shows the text, then two answers when the third message does not exist and three otherwise. The answer chosen by the player, numbered 1, 2 or 3, is stored in the run variable read by SCRIPT_EXPR_RUN_VARIABLE of ScriptExpressionToken.8

A two-answer question works because the lookup gives no string for −1. Only the third answer is tested this way. −1 as the first or second answer still gives a button whose label is a null pointer. The label's length counts as zero, so the text starts at the middle of the button, but the text routine does not check the pointer: it draws the bytes found at the very start of memory, the processor's interrupt table, up to the first zero byte, and wraps at the right edge of the screen. What appears therefore depends on the machine. The reference scripts never do this.

In the reachable scripts of the 16 reference INF files, 21 of the 25 choices have two answers and four have three. The conditions that follow a choice compare the run variable with 1 (15 times), 2 (7 times) and 3 (once).

Answer buttons​

The answers are buttons like the wait button, 95 × 9 pixels, on one row whose top is 4 pixels below the line after the text's last line: y = 125 + (cursor line + 1) × 6 + 4 with the 6-pixel font. Two answers start at x 59 and 166; three at x 4, 112 and 220. The highlighted answer has its label in colour 9, the others in colour 15; the first answer is highlighted at the start.9

The game then reads one input at a time. Before acting on it, if the mouse pointer lies on an answer, that answer becomes the highlighted one; the highlight therefore follows the pointer only when a key or a mouse button is used. Then:

InputEffect
Enter (either key), Space or keypad 5Chooses the highlighted answer.
Press of either mouse button on an answerChooses that answer. A press elsewhere does nothing.
Left arrow or keypad 4Highlights the previous answer; from the first, the last.
Right arrow or keypad 6Highlights the next answer; from the last, the first.
Up and Down arrows, keypad 8 and 2Move by rows of three answers; with two or three answers they do nothing.
Anything else, including EscapeNothing; the question cannot be dismissed.

The grey arrow keys and the keypad arrows give the same result, and so do the two Enter keys. Once an answer is chosen the game draws the dialogue box again, as SCRIPT_DIALOGUE_BOX does, which also clears the text window. As for a wait, the game loop does not run while the question is displayed.9

Anomaly

ANOMALY-81 — Arrow keys in a menu of more than three entries. The same menu routine serves the character menus of special events, which can have more than three entries, laid out in rows of three. Entries are numbered from 0; the four keys apply these rules:

left(sel): sel = sel - 1; if sel < 0: sel = min(count - 1, 2)
right(sel): sel = sel + 1; if sel > 2 or sel > count - 1: sel = 0
up(sel): if sel - 3 > 0: sel = sel - 3
else if sel + 3 < count: sel = sel + 3
down(sel): if sel + 3 < count: sel = sel + 3
else if sel - 3 > 0: sel = sel - 3
then apply up(sel) as well

Right therefore returns to entry 0 from entry 2 or any later entry, Up treats entry 3 as if it were on the first row, and Down, which ends with the Up rule, usually undoes its own move. With seven entries, Up takes 0 to 3, 1 to 4, 2 to 5, 3 to 6, 4 to 1, 5 to 2 and 6 to 3, while Down moves only from entry 0, to entry 6. With two or three entries, as in every dialogue question, these rules give the expected Left and Right and leave Up and Down without effect. A faithful reimplementation must apply them as written.

Consequences (inferred from the rules): up to seven entries, every entry can still be highlighted with the keys, by indirect paths. With eight or more, which the resurrection menu can produce (it has no limit on its length), the keys never reach entry 7 or any later one; only the mouse can choose them.9

Edge cases and unknowns​

A text or question without SCRIPT_DIALOGUE_INITIALIZE. Nothing checks that the screen is open:10

  • The text is read from the dialogue-text buffer, whatever it last received: TEXT.DAT if nothing has used the buffer since the last dialogue or parchment, otherwise unrelated data, such as the level data that the buffer holds while a level loads. The bytes found are used as the offset table and the text, up to the first zero byte.
  • The text goes to the active text window at its current cursor, normally the message area at the bottom of the screen, where page waits are off: a long text scrolls through it without waiting.
  • A prompt still shows the wait button and waits, and a question still places its answers below the active window's cursor line, at the bottom edge of the screen for the message area. After the answer, the dialogue box is drawn over the lower part of the screen.
  • The screen is not marked as active, so a level change made later in the same run does not restore the normal view first, as it does during a dialogue.

The reference scripts never do this. Every text and every question follows a SCRIPT_DIALOGUE_INITIALIZE of the same dialogue, with one apparent exception: the temple entrance of level 4 skips the initialization when level flag 6 is set, and that flag is set only by a script that has just opened the screen and then moves the party onto the entrance, which runs the entrance script inside that open dialogue.

frame outside 0–1. The value is not checked. The four tables (width in 8-pixel columns, height, x in 8-pixel columns, y) lie one after the other, each two words long, between tables of pointers; the picture routine reads, in each, the word frame places after its first entry, which for other values falls in the next table or in the pointers around them. Any nonzero frame also draws directly on the screen without the BORDER frame. For the nearest values the words read are:11

frameWidthHeightxy
−2566920961
−1address401210
296185709
312100address

"Address" marks a word that the DOS loader adjusts to the program's load address, so its value differs between runs. Further values reach other pointer tables. Without SCRIPT_DIALOGUE_BITMAP_TRANSITION, none of these values draws anything. The picture is still loaded and remembered, but the copy rejects the destination column of −2 and −1 and the video driver the destination row of 2 and 3. For 3 the "address" word holds the location of the program's data, which stays above row 200 (inferred for any memory configuration that can run the game). With SCRIPT_DIALOGUE_BITMAP_TRANSITION, the pixel dissolve receives the region without its size being limited. For 2 and 3 it draws nothing visible. For −2 it writes 45,352 column numbers into a 5,120-byte work area and overwrites program code (inferred consequence: the game stops working). For −1 the size depends on where the program is loaded. The reference scripts use only 0 and 1.

Other cases. For an unrecognized selector, the handler returns after the selector; this does not establish that such selectors are valid. Malformed TEXT.DAT data is not characterized.

Observed use​

The 782 reachable instructions of the 16 reference INF files use SCRIPT_DIALOGUE_BITMAP 237 times, SCRIPT_DIALOGUE_TEXT 168, SCRIPT_DIALOGUE_BOX 143, SCRIPT_DIALOGUE_RESTORE 110, SCRIPT_DIALOGUE_INITIALIZE 99 and SCRIPT_DIALOGUE_CHOICE 25 times. Pictures use 24 distinct names, frame 0 in 236 instructions and 1 once, and flags 0 (208), SCRIPT_DIALOGUE_BITMAP_KEEP_BACKGROUND (20) or SCRIPT_DIALOGUE_BITMAP_TRANSITION (9).

Sources​

Footnotes​

  1. Handler for 0xe3, which reaches the overlay dialogue routines. Comparative source: EoBInfProcessor::oeob_dialogue (script/script_eob.cpp, lines 1554–1590) in REF-SCUMM-012. Statistics come from decoding the scripts reachable in the 16 reference INF files. ↩

  2. Overlay routines for initialization, restore, the TEXT.DAT read and the text window setup; the page-wait switch, the window selection, the dialogue-text buffer, the file-name strings and the scene-update flag. Comparative source: initDialogueSequence and restoreAfterDialogueSequence (engine/eobcommon.cpp, lines 1718–1766) in REF-SCUMM-012. ↩ ↩2

  3. Overlay dialogue box, the framed box and the window clear. ↩

  4. Overlay picture routine; the destination tables, the remembered name, the string compare and the CPS loader. The name observations come from the reference INF files and the file inventory. Comparative source: drawSequenceBitmap (engine/eobcommon.cpp, lines 1768–1818) in REF-SCUMM-012. ↩ ↩2

  5. Text window setup and the window table; the text output, its line output and wrapping and its page wait, with the page-wait routine pointer; the font installer. The control bytes were counted in the reference TEXT.DAT. ↩

  6. Overlay wait prompt and button drawing, with the button positions and the prompt label; the input queue, the keyboard handler and the rectangle test. ↩ ↩2

  7. Overlay text routine; the prompt label, the string lookup and the string length helper. The TEXT.DAT observations concern the reference file in the file inventory. Comparative source: TextDisplayer_rpg::printDialogueText (text/text_rpg.cpp, lines 551–572) in REF-SCUMM-012. ↩

  8. Handler for 0xe3, the overlay choice routine and the shared choice menu. Comparative source: runDialogue (engine/eobcommon.cpp, lines 1820–1845) in REF-SCUMM-012. ↩

  9. The shared choice menu, which carries the location of the Up and Down rules, with the answer positions, the button drawing, the input queue and the keyboard handler. ↩ ↩2 ↩3

  10. The text routine and the shared buffer; the page-wait switch, the window table, the dialogue-active flag and the level-load handler. The use by the reference scripts comes from a path search over the reachable instructions of the 16 reference INF files. ↩

  11. The picture routine and the destination tables and their neighbors. ↩