Skip to main content

Input routines

Routines · Data · Address index

Keys, mouse and buttons: reading input, the button lists, menus, text fields and input recording. The routines page explains how the entries are written.

0x1c3fd — Key M​

0x1c43a, 0x1c515, 0x1c55f — Keyboard character and hand selection​

0x1c8de — Keyboard command dispatch​

0x1c9b7 — Read and dispatch a key​

0x2f8ae — Key reader​

0x2f905 — Process the button list​

  • Range: 0x2f905–0x30124
  • Role: Walks the active button list and, at 0x3006a, calls an entry's callback stored at offset +0x30, after setting the button trigger. A callback that returns 0 lets the walk go on to the next entry (0x30071–0x300eb); any other value ends it. The far pointers to the four party-move routines 0x1bfe0, 0x1c018, 0x1c0a5 and 0x1c0ed, which move the party, and the front-block action pointer are laid out as such callbacks in 0x3c-byte records. The main button list holds, in this order, the front-block action (0x259e1), the six character boxes (0x1c289), the camp button (overlay 247 entry 0), the four floor quarters (0x1c135), the inventory and hand buttons (0x1bb6d), the swap buttons (0x1bd9c), the six movement buttons (0x1bfe0) and the throw buttons (0x1bf7b). A record is 0x3c bytes: +0x00 far pointer to the next record, +0x04 button code (returned with bit 15 set), +0x06 and +0x08 two key codes, +0x0c a byte that, when non-zero, sets state bit 0x04 when a mouse button is pressed or released (0x2fd20 and five more reads; 0 in every record of the main lists; the role of that bit is unknown), +0x0e flags (bit 3 skips the button; 0x0f00 mouse button 1, 0xf000 button 2; the game's records use only 0x1100 and 0x1000: a button answers to either mouse button with 0x1100 and to the right one only with 0x1000, which only the six name strips (0x3df0–0x3ea4, 0x4d2c, 0x4d68) have among the 96 records DS:0x39b8–DS:0x5038; other bits unknown), +0x1c window number, +0x1e/+0x20 x and y relative to the window (negative from its right or bottom edge), +0x22/+0x24 width and height, +0x2e state bits, +0x30 callback, called with the record, +0x34 a far pointer passed to a hook (DS:0xf04c, 0x2fa6a–0x2fa83) that the game never installs (its only setter 0x305fc is called once, at start-up, with a null pointer), so it has no effect, +0x38 a word argument (zone or character) read by the callbacks.
  • Used by: The game loop › One pass of the game loop, The inventory › The selected character, How input works › The active button list, The play screen

0x1dfee, 0x1e00f, 0x2d3d9, 0x1e09d, 0x1e12b, 0x20e26, 0x1ed9b — Build the main button list​

  • Ranges: 0x1dfee–0x1e00e; 0x1e00f–0x1e09c; 0x1e09d–0x1e1b8; 0x20e26–0x20e51; 0x1ed9b–0x1edc7; 0x2d3d9 (entry). The routine starts at 0x1e00f; the old anchor r-1e02f, inside its first loop, is kept for links.
  • Role: 0x1dfee(button) makes a button the whole active list. 0x1e09d and 0x1e12b do what 0x1e00f does for the two pages of the character panel, with or without an open spell book (DS:0x51a8, 47 entries, and DS:0x52b0, 60; DS:0x5264, 19, and DS:0x53a0, 33); 0x20e26 calls the one for the current state. 0x1ed9b closes the panel and the spell book. 0x1e00f rebuilds the active button list from entry 0 of the array DS:0x5038, then appends entries 1 to 37 with 0x2d3d9, or from DS:0x50d0 (entries 1 to 53) while a spell book is open (DS:0xe441). 0x2d3d9 walks a list to its last entry and links the new entry there, so the list keeps the array order.
  • Used by: The inventory › The selected character, Choosing a spell in the book › The book, How input works › The active button list, Casting a spell, The play screen

0x326c0 — Mouse initialization​

0x32d6e — Look at the next key​

  • Range: 0x32d6e–0x32de9
  • Role: The non-waiting form of read a key as a character. It walks the input queue from its read position and removes the events that 0x32f20 would skip (releases, key numbers 0x7a and above and the nine codes at cs:0x20d). It returns the character of the first remaining event, translated by 0x32b67, without removing it, or 0 when the queue holds nothing else. The introduction's skip test, the text input and several menus call it.
  • Used by: Edit a text field

0x18d74 — Edit a text field​

  • Range: 0x18d74–0x19241

  • Role: 0x18d74(text, column, y, length, colour, background, cursor colour) lets the player edit the string text in place, at most length characters, shown from 8-pixel column column at row y. It hides the mouse, cuts a longer string to length, saves the field (length + 2 columns, 9 rows) into page 2 at row 191, and prints the text as shadowed text. The cursor starts after the last character (on it when the field is full) and blinks every two ticks, drawn as the character under it, or a space, on the cursor colour. Keys (look at the next key, then read it):

    • a character from space to ~: converted to upper case (0x168f3) and inserted at the cursor, the rest moving right, the last character lost when the field is full; a space is refused in the first position;
    • backspace: removes the character before the cursor;
    • delete (code 0x7f or 0xad): removes the character under it;
    • left and right (codes 0xb5, 0xb3): move the cursor, not past the text or the last position;
    • Return ends and returns the length; Escape ends and returns −1, leaving the text as edited.

    With Num Lock on, the keypad and the grey cursor keys type digits and the full stop instead of moving the cursor or deleting.

    After each key the field is restored from page 2 and redrawn. The mouse is shown again at the end.

  • Used by: Save menu, Create a character, Creating a party › Creating the party, The start menu, questions and text › Typing text, How input works › The pointer and the item it carries

0x1f0c3 — Message with one button​

  • Range: 0x1f0c3–0x1f266
  • Role: 0x1f0c3(window, string, label, keys, label colour) keeps the active text window and the current font, installs FONT8, selects window and prints string number string of the list at file offset 0x2c170 in it. It draws one button box 14 pixels high in the window's lower right corner, sized to label (8 pixels per character + 7), and prints the label in it. It then waits for a mouse press inside the button or for a key whose number is in the string keys, shows the button pressed for five vertical retraces, draws it again, and puts the window and font back. The save menu uses it with the label OK; its keys are the list at DS:0x2554: Space, Enter and O.
  • Used by: Save menu, Camp menus, The start menu, questions and text › Questions and messages

0x32fbd, 0x32e57, 0x32e66 — Input queue​

0x32f20, 0x32b67 — Read a key as a character​

  • Ranges: 0x32f20–0x32f70; 0x32b67–0x32c3d

  • Role: 0x32f20 waits for an event of the input queue, skipping releases (bit 0x800), key numbers 0x7a and above and the nine codes at cs:0x20d (30, 44, 57, 58, 60, 62, 64, 90, 128: Caps Lock, the Shift, Ctrl and Alt keys, Num Lock), then translates the key number through 0x32b67 and returns the character with the high byte cleared.

    0x32b67 gives 0x1b for key 110 (Escape). Key numbers below 62 go through one of four 62-byte tables chosen by Shift and Caps Lock (cs:0x2ef plain, cs:0x32d Shift, cs:0x36b Shift with Caps Lock, cs:0x3a9 Caps Lock): the US layout in ASCII, with Backspace 0x08, Tab 0x09, Enter 0x0d and Space 0x20. With Ctrl, a letter key (bitmap cs:0x1d3) gives its code AND 0x1f.

    Keypad numbers 75–109 use cs:0x40a (digits, ., /, *, -, +, Enter) when Num Lock is on, and otherwise cs:0x3e7: 0xb8 up, 0xb0 down, 0xb5 left, 0xb3 right, 0xb9 home, 0xb1 end, 0xb7 page up, 0xaf page down, 0xae insert, 0xad delete, 0xb4 keypad 5. Caps Lock and Num Lock are read from the BIOS keyboard flags (0x331b3–0x331d4).

    F1–F10 give 0xc5 down to 0xbc, or from 0xac with Shift, 0xa2 with Ctrl and 0x98 with Alt. Key numbers 62–64 give the number with bit 7 set and 65–74 the number plus 0x85.

    0x32f71 is the same loop without the release test. The last picture of the ending waits with it for 0x1b.

  • Used by: Play the ending, Test for a skip key, The interface

0x331aa, 0x334f9 — Keyboard and mouse-button handlers​

  • Hot keys: Alt+S toggles the Sounds option and Alt+M the Tunes option as the key is queued (0x33350–0x33379); Ctrl+Alt+Delete goes to the BIOS without being queued (0x33314–0x33322). After a key is queued, the BIOS also receives the modifier and lock keys, releases and Ctrl+Alt+Delete. Of the other keys it receives only those of a table at cs:0x8 whose bit is set in the option word (0x33399–0x333a2): with its initial value, Ctrl+Alt with -, =, keypad + or keypad −, and Ctrl+Break; Ctrl+S, Ctrl+C, Scroll Lock and Ctrl+Num Lock are kept from it, and the Pause key is ignored (0x331f9–0x33216). Whether anything sets the Escape callback at cs:0x3c is unknown.
  • Key numbers: 1 `, 2–13 1 to =, 15 Backspace, 16 Tab, 17–28 Q to ], 29 \, 30 Caps Lock, 31–41 A to ', 43 Enter, 44 left Shift, 46–55 Z to /, 57 right Shift, 58 left Ctrl, 60 left Alt, 61 Space, 62 right Alt, 64 right Ctrl, 75 Insert, 76 Delete, 79 Left, 80 Home, 81 End, 83 Up, 84 Down, 85 Page Up, 86 Page Down, 89 Right, 90 Num Lock, 91 keypad 7, 92 keypad 4, 93 keypad 1, 95 keypad /, 96 keypad 8, 97 keypad 5, 98 keypad 2, 99 keypad 0, 100 keypad *, 101 keypad 9, 102 keypad 6, 103 keypad 3, 104 keypad ., 105 keypad −, 106 keypad +, 108 keypad Enter, 110 Escape, 112–123 F1 to F12, 124 Print Screen, 125 Scroll Lock; unassigned scan codes give 127. With the default replacement table the grey keys, keypad Enter, keypad /, right Ctrl and right Alt give the numbers of their keypad or main-block counterparts and never get the Shift bit (0x332c4).
  • Anomaly: the Caps Lock and Num Lock tests at 0x332e5 and 0x332f8 test the key's bitmap with CH, which the non-E0 path never loads (ANOMALY-135); the translator 0x32b67 tests the same bitmap with a mask it loads (0x32bb5–0x32bc5).
  • Role: 0x331aa, installed as the keyboard interrupt handler (0x33184), turns scan codes into IBM key numbers through the table at 0x32aca (cs:0x17a): for example Enter 43, Space 61, M 52, Esc 110 and keypad 4, 8, 2, 6 and 5 = 92, 96, 98, 102 and 97. Keys after an E0 prefix use the tables at cs:0x40 and cs:0x50; while bit 1 of the option word DS:0x65fe is clear (its initial value 0x0110; the only writers change bit 0), a second table at cs:0x60 gives the grey arrows the keypad numbers and the keypad Enter key the number of Enter (0x332a8–0x332c7). The high byte carries Shift (0x01), Ctrl (0x02) and Alt (0x04); key releases are not queued (0x3331e). 0x334f9 queues mouse button 1 as 0x41 and button 2 as 0x42, with 0x800 added for a release, followed by the position.
  • Used by: Dialogue screen › Waiting for the player, Dialogue screen › Answer buttons, Learning and memorizing spells › Memorizing and praying, Choosing a spell in the book › The book, The play screen › Keyboard commands, How input works › Keys and mouse presses, Events that start scripts › Events from the keyboard, The creation screen, Transferring a party from Eye of the Beholder I, Transfer: spells and items, Casting a spell, Camp menus, The start menu, questions and text, Anomalies and bugs

0x193ef — Point in a rectangle​

0x19847, 0x328a3 — Test a position against a rectangle​

0x28bdd, 0x28cfe, 0x28a88, 0x28b8f, 0x28af9 — Menus​

  • Ranges: 0x28bdd–0x28cfd; 0x28cfe–0x2900b; 0x28a88–0x28b64; 0x28b8f–0x28bdc

  • Role: 0x28bdd(menu, strings, mask, base, spacing) draws a menu from its 16-byte description at DS:0x1e2c: x in columns, y, width, line count, current line, colour (15) and highlight colour (6), then empties the input queue. 0x28cfe takes one input event per call and returns the entry chosen, or −1:

    • Keypad 8 and 2 move the highlight, wrapping; keypad 7 and 9 go to the first line and keypad 1 and 3 to the last. The grey arrows act as the keypad.
    • Enter, Space and keypad 5 choose the highlighted line.
    • A press of either mouse button chooses the line under the pointer, inside the menu's rectangle. Outside it, the press counts as another key.
    • In mouse control the highlight follows the pointer.
    • Any other key goes to DS:0xef4e for the caller.

    The choice flashes before the routine returns. The current line stays in the description (0x29000). A menu shows only the entries whose bit is set in a 32-bit mask; a mask of −1 shows them all. 0x28a88(line, mask, base) gives the entry of a line: the position of the line-th set bit counted from bit base. 0x28b8f(entry, mask, base) gives the line of an entry: the bits set below it. 0x28af9(text, x, y, colour, colour, background) draws the text in one colour and then the other, with a wait of two screen refreshes after each drawing, three times. The menu routines 0x28bdd and 0x28cfe call them (0x28c1f, 0x28f02, 0x28fe8); overlay 245 calls 0x28b8f directly (0x418d3, 0x41a9c).

  • Used by: Race, class and alignment menus, Start menu, The start menu, questions and text › Line menus

0x1e1b9, 0x1e1ff — Character-choice button lists​

0x32dea, 0x32fdb, 0x335dc, 0x33587, 0x32bd8, 0x32e73, 0x2d5a2 — Input queue and key state​

  • Role: 0x32e73 takes the next word of the queue, and for the events 41h and 42h the two position words. 0x2d5a2(list, code) finds a button of a list by its code. 0x33587 appends a mouse event, three words with the position, to the queue. 0x32bd8 is the part of the key reader that turns a key number into a character with its tables. 0x32dea returns the next event of the input queue without taking it, or 0. 0x32fdb(key) returns nonzero when a key is held, from the bits at cs:0x1f3; unless bit 0x2 of DS:0x65fe is set it also accepts the key's alias in a table of 14 pairs (cs:0x711, cs:0x71f). 0x335dc sets or clears one of those bits. The button processor calls 0x32fdb (0x2f934, 0x2f951).
  • Used by: Process the button list

0x33bbf, 0x33bea, 0x338ba, 0x339a5, and others — Mouse pointer​

  • Role:

    • 0x33bbf and 0x33bea hide and show the pointer, around a drawing. They take the lock DS:0x6610 and call 0x338ba, which counts one more hide in DS:0x6628 and takes the pointer off the screen, and 0x339a5, which counts one fewer and draws the pointer when the count reaches 0.
    • 0x33ab6(x1, y1, x2, y2) hides the pointer only if it lies over that rectangle, and 0x33b7a ends such a region. 0x323f9(window) and 0x3245c do the same for a text window.
    • 0x337d0 stores the shape and hot spot. 0x33c16 moves the pointer to a position, kept inside the limits DS:0x662a–0x6630, and 0x33cb0(dx, dy) moves it by an offset.
    • 0x328fb and 0x3293a store and return the driver's state block, DS:0x6650: slots 6 and 5 of the driver function table.

    The pointer is not drawn at all in keyboard control (DS:0x6655).

  • Used by: Mouse and control state, How input works › The pointer and the item it carries

0x30135 — Draw a button​

  • Range: 0x30135–0x305fb
  • Role: Draws a button record according to its state bits +0x2e and its three style bytes: +0x0a at rest, +0x0b with state 0x01, +0x0c with state 0x04. A style draws a shape (1), a text (2), a block through driver slot DS:0x656e (3), through a callback (4), or an outline (5); the styles of the other states use similar forms. With all three bytes zero it returns at once (0x3016d). All the records of the main lists and of the character-choice lists have them at zero, so the button processor's calls (0x2fa4c, 0x30049) draw nothing for them.
  • Used by: Process the button list, How input works › The active button list

0x32698, 0x33102 — Install the mouse and keyboard handlers​

  • Ranges: 0x32698–0x32734; 0x33102–0x331a9
  • Role: 0x32698 (0x31314) tests the INT 33h vector, which must be set and not point at an IRET, resets the mouse and, when the driver reports a position other than 160, doubles x from then on. It sets DS:0x6654, DS:0x6655, and installs the event handler 0x32735, which the mouse driver calls for all events: it records the position, passes button changes to 0x334f9 and redraws the pointer. 0x33102 (0x31869) takes the shift and lock states from the BIOS, then saves and replaces INT 09h and INT 23h. The shutdown undoes both.
  • Used by: Mouse and control state

0x33602, 0x33711 — Record and replay input​

  • Ranges: 0x33602–0x33704; 0x33711–0x33743
  • Status: that this code never runs is inferred: no instruction found writes DS:0x6600, which is 0 in the image.
  • Role: With mode 1, 0x33602 writes each input event to the file handle DS:0x6601, with the time counter DS:0x667a and, for events 41h to 44h, the position. With mode 2 it reads them back, and 0x33711 delivers an event only once DS:0x667a reaches its stored time; the input routines then ignore live input (0x327cf, 0x32d7f, 0x32e81, 0x32f2b). At the end of the file it sets DS:0x660b.
  • Used by: none known