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
- Role: Sets the record gate to
0xffff, runs the record runner on the party's block and facing, then calls0x20247. - Used by: Block events › Wall activation and the 0xffff mask, Events that start scripts › Activating walls
0x1c43a, 0x1c515, 0x1c55f — Keyboard character and hand selection
- Ranges:
0x1c43a–0x1c50c;0x1c515–0x1c55e;0x1c55f–0x1c58e - Role: Select a character (DS:
0x9317) and a hand slot (DS:0xe5a4) with the keyboard.0x1c55f(direction), 0 to 3 for W, S, Z and A, calls0x1c43awhile the character panel is closed and0x1c515on its first page, and nothing on its second.0x1c43a(jump tablecs:0x9dd): W and Z go to the other hand, then to the row above or below, skipping rows until the character is present (0x1c465–0x1c48c,0x1c4c0–0x1c4e7); S and A switch to the other character of the row after testing only the character being left (0x1c495–0x1c4aa,ANOMALY-143).0x1c515follows the slot table. - Used by: The play screen › Keyboard commands, Events that start scripts › Events from the keyboard, Anomalies and bugs
0x1c8de — Keyboard command dispatch
- Role: Maps IBM key numbers for W, S, Z, A, U, D, T, G and M to party
actions. It is gated by the control-state byte, DS:
0xcb76and the transfer control byte. M is not gated by the panel state; W, S, Z, A, U, D, T and G are skipped when the panel state is 2. - Used by: The game loop › One pass of the game loop, The play screen › Keyboard commands, Events that start scripts › Events from the keyboard, How input works › Mouse control and keyboard control
0x1c9b7 — Read and dispatch a key
- Role: Reads a key through the key reader and passes it to the keyboard command dispatch.
- Used by: The play screen › Keyboard commands, Events that start scripts › Events from the keyboard
0x2f8ae — Key reader
- Range:
0x2f8ae–0x2f904 - Role: Reads a pending key, if any (code 0 otherwise). When the code has
the Shift bit
0x100and its key number is in0x11–0x1a,0x1f–0x27or0x2e–0x34, the three rows of letters, it clears that bit (0x2f8c5–0x2f8ee), so a letter reads the same with or without Shift. It then passes the code with the active button list to the button processing and returns the resulting code. - Comparative source: REF-SCUMM-014,
runLoop(checkInput(_activeButtons, true, 0)). - Used by: The game loop › One pass of the game loop, The play screen › Keyboard commands, How input works › The active button list, Events that start scripts › Events from the keyboard
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 routines0x1bfe0,0x1c018,0x1c0a5and0x1c0ed, which move the party, and the front-block action pointer are laid out as such callbacks in0x3c-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 is0x3cbytes:+0x00far pointer to the next record,+0x04button code (returned with bit 15 set),+0x06and+0x08two key codes,+0x0ca byte that, when non-zero, sets state bit0x04when a mouse button is pressed or released (0x2fd20and five more reads; 0 in every record of the main lists; the role of that bit is unknown),+0x0eflags (bit 3 skips the button;0x0f00mouse button 1,0xf000button 2; the game's records use only0x1100and0x1000: a button answers to either mouse button with0x1100and to the right one only with0x1000, which only the six name strips (0x3df0–0x3ea4,0x4d2c,0x4d68) have among the 96 recordsDS:0x39b8–DS:0x5038; other bits unknown),+0x1cwindow number,+0x1e/+0x20x and y relative to the window (negative from its right or bottom edge),+0x22/+0x24width and height,+0x2estate bits,+0x30callback, called with the record,+0x34a far pointer passed to a hook (DS:0xf04c,0x2fa6a–0x2fa83) that the game never installs (its only setter0x305fcis called once, at start-up, with a null pointer), so it has no effect,+0x38a 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 at0x1e00f; the old anchorr-1e02f, inside its first loop, is kept for links. - Role:
0x1dfee(button)makes a button the whole active list.0x1e09dand0x1e12bdo what0x1e00fdoes for the two pages of the character panel, with or without an open spell book (DS:0x51a8, 47 entries, andDS:0x52b0, 60;DS:0x5264, 19, andDS:0x53a0, 33);0x20e26calls the one for the current state.0x1ed9bcloses the panel and the spell book.0x1e00frebuilds the active button list from entry 0 of the arrayDS:0x5038, then appends entries 1 to 37 with0x2d3d9, or fromDS:0x50d0(entries 1 to 53) while a spell book is open (DS:0xe441).0x2d3d9walks 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
- Role: Detects the mouse and sets the mouse and control-state bytes.
- Used by: The play screen › Keyboard commands, How input works › Mouse control and keyboard control, Events that start scripts › Events from the keyboard
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
0x32f20would skip (releases, key numbers0x7aand above and the nine codes atcs:0x20d). It returns the character of the first remaining event, translated by0x32b67, 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
0x7for0xad): 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.
- a character from space to
-
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, installsFONT8, selects window and prints string number string of the list at file offset0x2c170in 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 atDS: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
- Role: The keyboard and mouse handlers append input events to a
256-byte ring buffer in the code segment
0x2295(cs:0x70, headcs:0x170, tailcs:0x172).0x32fbdwaits, doing nothing else, until an event is queued and returns it (0x32fbd–0x32fda); for a mouse-button code (0x41or0x42, release bit0x800) it also stores the event's position inDS:0x6622andDS:0x6624(0x32e95–0x32ed3).0x32e57tells whether an event is waiting and0x32e66empties the queue. The current pointer position is kept inDS:0x661aandDS:0x661c.0x32f20reads the next key press as a character code. - Used by: Dialogue screen › Waiting for the player, Dialogue screen › Answer buttons, How input works › Keys and mouse presses, Transferring a party from Eye of the Beholder I, Transfer: spells and items, Camp menus, The ending
0x32f20, 0x32b67 — Read a key as a character
-
Ranges:
0x32f20–0x32f70;0x32b67–0x32c3d -
Role:
0x32f20waits for an event of the input queue, skipping releases (bit0x800), key numbers0x7aand above and the nine codes atcs: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 through0x32b67and returns the character with the high byte cleared.0x32b67gives0x1bfor key 110 (Escape). Key numbers below 62 go through one of four 62-byte tables chosen by Shift and Caps Lock (cs:0x2efplain,cs:0x32dShift,cs:0x36bShift with Caps Lock,cs:0x3a9Caps Lock): the US layout in ASCII, with Backspace0x08, Tab0x09, Enter0x0dand Space0x20. With Ctrl, a letter key (bitmapcs:0x1d3) gives its code AND0x1f.Keypad numbers 75–109 use
cs:0x40a(digits,.,/,*,-,+, Enter) when Num Lock is on, and otherwisecs:0x3e7:0xb8up,0xb0down,0xb5left,0xb3right,0xb9home,0xb1end,0xb7page up,0xafpage down,0xaeinsert,0xaddelete,0xb4keypad 5. Caps Lock and Num Lock are read from the BIOS keyboard flags (0x331b3–0x331d4).F1–F10 give
0xc5down to0xbc, or from0xacwith Shift,0xa2with Ctrl and0x98with Alt. Key numbers 62–64 give the number with bit 7 set and 65–74 the number plus0x85.0x32f71is the same loop without the release test. The last picture of the ending waits with it for0x1b. -
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 atcs:0x8whose 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 atcs:0x3cis unknown. - Key numbers: 1
`, 2–131to=, 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
0x332e5and0x332f8test the key's bitmap withCH, which the non-E0path never loads (ANOMALY-135); the translator0x32b67tests 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 at0x32aca(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 anE0prefix use the tables atcs:0x40andcs:0x50; while bit 1 of the option wordDS:0x65feis clear (its initial value0x0110; the only writers change bit 0), a second table atcs:0x60gives 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).0x334f9queues mouse button 1 as0x41and button 2 as0x42, with0x800added 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
- Role: Returns 1 when the point (x, y) lies inside the rectangle (x1, y1)– (x2, y2), edges included, signed comparisons; 0 otherwise.
- Used by: Dialogue screen › Waiting for the player, Dialogue screen › Answer buttons
0x19847, 0x328a3 — Test a position against a rectangle
- Role: Both take (x1, y1, x2, y2) and return 1 inside it, edges included.
0x19847tests the position of the last event taken from the input queue through0x193ef; the force-door and door-switch handlers and the wall-click hit test use it (0x253f3,0x25609,0x2507a).0x328a3tests the position of the pointer under the lockDS:0x6610; the no-force door handler (0x258e0) and overlays 245 (0x4199e) and 247 (0x4431c) use it. - Used by:
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 atDS:0x1e2c: x in columns, y, width, line count, current line, colour (15) and highlight colour (6), then empties the input queue.0x28cfetakes 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:0xef4efor 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 routines0x28bddand0x28cfecall them (0x28c1f,0x28f02,0x28fe8); overlay 245 calls0x28b8fdirectly (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
- Role: Each replaces the active button list with seven
buttons of an array of far pointers, like the
main list:
0x1e1b9the arrayDS:0x5424, while a character is being swapped (0x1bde0), and0x1e1ffthe arrayDS:0x5440, after the question "Cast spell on which character?" (0x212d5). - Used by: The play screen › Waiting for a character, Choosing a spell in the book, How input works › The active button list
0x32dea, 0x32fdb, 0x335dc, 0x33587, 0x32bd8, 0x32e73, 0x2d5a2 — Input queue and key state
- Role:
0x32e73takes the next word of the queue, and for the events41hand42hthe two position words.0x2d5a2(list, code)finds a button of a list by its code.0x33587appends a mouse event, three words with the position, to the queue.0x32bd8is the part of the key reader that turns a key number into a character with its tables.0x32deareturns the next event of the input queue without taking it, or 0.0x32fdb(key)returns nonzero when a key is held, from the bits atcs:0x1f3; unless bit0x2ofDS:0x65feis set it also accepts the key's alias in a table of 14 pairs (cs:0x711,cs:0x71f).0x335dcsets or clears one of those bits. The button processor calls0x32fdb(0x2f934,0x2f951). - Used by: Process the button list
0x33bbf, 0x33bea, 0x338ba, 0x339a5, and others — Mouse pointer
-
Role:
0x33bbfand0x33beahide and show the pointer, around a drawing. They take the lockDS:0x6610and call0x338ba, which counts one more hide inDS:0x6628and takes the pointer off the screen, and0x339a5, 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, and0x33b7aends such a region.0x323f9(window)and0x3245cdo the same for a text window.0x337d0stores the shape and hot spot.0x33c16moves the pointer to a position, kept inside the limitsDS:0x662a–0x6630, and0x33cb0(dx, dy)moves it by an offset.0x328fband0x3293astore 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
+0x2eand its three style bytes:+0x0aat rest,+0x0bwith state0x01,+0x0cwith state0x04. A style draws a shape (1), a text (2), a block through driver slotDS: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 anIRET, resets the mouse and, when the driver reports a position other than 160, doubles x from then on. It setsDS:0x6654,DS:0x6655, and installs the event handler0x32735, which the mouse driver calls for all events: it records the position, passes button changes to0x334f9and 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,
0x33602writes each input event to the file handleDS:0x6601, with the time counterDS:0x667aand, for events41hto44h, the position. With mode 2 it reads them back, and0x33711delivers an event only onceDS:0x667areaches its stored time; the input routines then ignore live input (0x327cf,0x32d7f,0x32e81,0x32f2b). At the end of the file it setsDS:0x660b. - Used by: none known