Skip to main content

MGA.OVL, the VGA display driver

The game executable · Display drivers · File inventory

In brief​

MGA.OVL is the display driver the game loads for display mode 3, labelled "MCGA/VGA" by the setup program; the reference EOSPREFS.DAT selects this mode. It draws the game's 320 × 200 image with one byte per pixel. The byte is a colour number, and the card shows the 256 colours through the palette that the game sets with slot 48.

The driver draws shapes, plain and mirrored, lines, filled rectangles, single pixels and text. It copies whole pages and rectangles, saves and restores rectangles, and cuts and reduces shapes. It also builds and installs colour tables and sets the palette. It does not set the video mode, load files or decide what is drawn: the game does all of that. Twelve slots do nothing, slot 49 only returns a null pointer, and three slots hold pointers to tables rather than routines.

Addresses

Every address on this page is a driver image offset: the offset in MGA.OVL minus 0x200, which is also the offset in the driver's code segment once loaded. Game code is given as analysis addresses of START.EXE, game data as DS: offsets. See how addresses are written.

How the driver draws​

Pages​

The game numbers its image pages and keeps one segment per page in the page table at DS:0x62a7. It also keeps the current page at DS:0x62a5. To the driver a page is 64,000 bytes: 200 rows of 320 bytes, one byte per pixel. It finds the start of row y in its table of row offsets at 0x0233 (320 × y), to which slot 53 points. The memory behind a page is set by the game and need not have that size.

In mode 3 the game's display-mode routine sets the pages in pairs:

PagesMemory
0 and 1Video memory at segment 0xa000: the screen
2 and 3, 4 and 5, 6 and 7One buffer per pair, allocated by the game for the odd page: 64,500, 32,000 and 64,600 bytes
9, 11, 13, 15Buffers allocated by the game when it has a size for them; pages 8, 10, 12 and 14 are not set in this mode

The drawing routines write the page with bit 0 clear. The shape encoders read the page with bit 0 set, and the page copy copies from the page with bit 0 set to the page with bit 0 clear. For pages 0 to 7 both pages of a pair are the same memory in this mode: an encoder reads the image the game has just loaded into the odd page, and copying a page onto its pair does nothing.

The 32,000 bytes of pages 4 and 5 are enough for what the game does with them in this mode. It reads compressed containers to the end of page 5, at most 16,861 bytes with the original files (0x306d4), and the introduction saves a shape's rectangle on page 4 (overlay 255, 0x4d873). Its whole-page copies onto page 4 run only in other display modes (overlay 245, 0x41e5f, modes 0 and 1; overlay 250, 0x4827e, mode 5), and the sites of slot 14, which clears the current page, run with page 0 or 2 current.

Colours​

Only the shape drawers apply colour tables. A 16-colour shape is drawn through its own 16-entry table by slots 18 and 39, and through the replacement table that slot 11 sets by slots 15 and 38. A table entry of 0 leaves the pixel unchanged. Every colour drawn by a shape then goes level times through the current colour table at 0x250a, which slots 12 and 47 set. Lines, rectangles, single pixels and text write their colour unchanged.

Shapes​

The driver's encoders produce two codings. The game reads only the 4-byte header: format, height, width in 8-pixel columns, height.

FormatAfter the headerPixels of a row
116-byte colour table4 × width bytes, two pixels per byte, the left pixel in the high four bits; each pixel is an index into the table
0—Colour bytes 1–255, one pixel each; a 0 byte is followed by a count of transparent pixels

In format 0 a run of transparent pixels never goes past the end of its row, and a run longer than 255 is written as 00 ff 00 and the rest. For example, the row bytes 05 05 00 03 07 give two pixels of colour 5, three transparent pixels and one pixel of colour 7.

Driver state​

The driver keeps two clipping rectangles. The shape window (0x00e7–0x00ee: left column, right column, top row, bottom row; the right column and bottom row are excluded) limits the four shape drawers. The game sets it through slot 46 from the current text window, and it is empty until then. Before drawing the mouse cursor the game calls slot 41, which saves the window at 0x00de and opens it to the whole page, and afterwards slot 37, which puts it back. The line rectangle (0x021d–0x0224: 0, 0, 319, 199 in the file) limits lines. The other routines clip against the whole 320 × 200 page or not at all, as each entry says.

Two bytes change how the shape drawers write a pixel: the shape level at 0x00dd and the pixel-effect flag at 0x0215. The driver keeps no copy of the card's registers: apart from video memory, it reaches the card only through the palette ports of slot 48.

Image map​

RangeKindContent
0x0000–0x0002codeJump to the driver entry
0x0003–0x00dadataSlot table: 54 far pointers, segments 0 in the file
0x00db–0x00dcdataNumber of slots, 54
0x00ddvariableShape level (slot 21)
0x00de–0x00e5variableSaved shape window (slot 41)
0x00e6variableFill colour (slot 22)
0x00e7–0x00eevariableShape window: left column, right column, top, bottom
0x00ef–0x0112variableWork variables of the mirrored drawers; 0x010f is written and never read
0x0113–0x0212dataNibble swap: entry i is i with its two 4-bit halves exchanged; slot 40 points here
0x0213–0x0218variableShape x and pixel counter, pixel-effect flag, encoder pixel parity and byte count
0x0219–0x021cdataZero, not used
0x021d–0x0224variableLine rectangle: x min, y min, x max, y max
0x0225–0x022avariableRow loop of the replacement-table drawers, encoder result
0x022b–0x022cdataZero, not used
0x022d–0x0232variableEncoder row starts, row count, colour count
0x0233–0x03c4dataRow offsets: 201 words, 320 × y for y = 0–200; slot 53 points here
0x03c5–0x03d0dataZero, not used
0x03d1–0x072ccodeSlots 7, 10, 8, 9, 11 and most of 12
0x072d–0x0737variableWork variables of slot 12
0x0738–0x0ad3codeEnd of slot 12, slots 13, 14, 15, start of 17
0x0ad4–0x0af3data16 near pointers: line clipping helper for each outcode
0x0af4–0x0c39codeLine clipping helpers and line loops
0x0c3a–0x0c3bvariableLine colour
0x0c3c–0x1c75codeEnd of slot 17, slots 18–39, 41 and 42, the install routine and driver entry, page and encoder helpers, shape pixel writer
0x1c76–0x1c81variableWork variables of the scale step; 0x1c7f–0x1c80 not used
0x1c82–0x1f19codeSlots 43–51
0x1f1a–0x1f38variableText variables: row skip, glyph width and rows, colours, line start, line height, advance, font segment; 14 bytes in it are not used and 2 are only written
0x1f39–0x1f68data24 near pointers, one per glyph width 1–24
0x1f69–0x2310dataFor each width, 8 pointers and the masks of that many bits shifted by 0–7; only the unshifted mask is read
0x2311–0x2509codeGlyph drawer and slot 52

The image ends at 0x2509. The driver entry asks the game for 0x272 paragraphs, and the driver keeps its run-time tables in the memory after the image:

RangeContent
0x250a–0x2609Current colour table (slots 12 and 47)
0x260a–0x2709Colour-to-index map of the encoder
0x270a–0x2719Replacement colour table (slot 11; slot 16 points here)

Three 2-byte pop bp; retf sequences, at 0x0544, 0x0f99 and 0x1179, follow an unconditional jump and are never reached.

The file's MZ header lists 48 relocation items: the segment words of slots 7 to 53 and the segment that slot 12 returns. The game loads the driver with a relocation factor of 0, so these words stay 0 (loading a driver). The six bytes at file offsets 0x1c–0x21, after the header's standard fields, hold 01 00 fb 30 6a 72, followed by zeros up to the relocation table at file offset 0x3e. XGA.OVL and START.EXE hold the same bytes there. Neither DOS's loader nor the game uses them, so they have no effect on the driver (inferred: a mark of the linker).

Function list​

Every routine of the file, in address order. A slot appears once for each routine it points to; slots 0–6 belong to the game, and slots 16, 40 and 53 point to tables (see the image map).

RoutineAddressRangeSlotRole
Copy a rectangle given in pixels0x03d10x03d1–0x04f27Pixel rectangle copy
Copy a page0x04f30x04f3–0x052a1064,000 bytes
Restore a saved rectangle0x052b0x052b–0x05458Into the current page
Restore a saved rectangle0x05460x0546–0x05e39Into page 0
Set the replacement colour table0x05e40x05e4–0x06051116-entry table for slots 15 and 38
Build a colour table0x06060x0606–0x074512Colour table towards a colour
Copy a rectangle between pages0x07460x0746–0x080413Column rectangle copy
Clear the current page0x08050x0805–0x082014Page to colour 0
Draw a shape through the replacement table0x0a1c0x0821–0x0a331516-colour shape
Draw a line0x0a340x0a34–0x0c4517Clipped line
No clipping needed0x0af40x0af4–0x0af5—Line clipping helper
Clip to the top0x0af60x0af6–0x0aff—Line clipping helper
Clip to the bottom0x0b000x0b00–0x0b13—Line clipping helper
Cross a horizontal edge0x0b140x0b14–0x0b2c—Line clipping helper
Clip to the left0x0b2d0x0b2d–0x0b36—Line clipping helper
Clip to the right0x0b370x0b37–0x0b4a—Line clipping helper
Cross a vertical edge0x0b4b0x0b4b–0x0b5f—Line clipping helper
Classify a point0x0b600x0b60–0x0b8a—Line clipping outcode
Draw a shape0x0c460x0c46–0x0f9a18Shape in its own colours
Empty slot0x0f9b0x0f9b19Returns
Empty slot0x0f9c0x0f9c20Returns
Set the shape level0x0f9d0x0f9d–0x0fb121Darkening steps of the next shapes
Fill a rectangle0x0fb20x0fb2–0x105322Solid rectangle
Odd page of the current page0x10540x1054–0x1078—Page segment helper
Even page of the current page0x10790x1079–0x109a—Page segment helper
Odd page of a page0x109b0x109b–0x10a2—Page segment helper
Even page of a page0x10a30x10a3–0x10b4—Page segment helper
Read a pixel0x10b50x10b5–0x10ed23Colour at (x, y)
Install the driver's routines0x10ee0x10ee–0x1146—Exchange slots with the game
Driver entry0x11470x1147–0x1158—Size and install address
Empty slot0x11590x115924Returns
Empty slot0x115a0x115a25Returns
Save a rectangle0x115b0x115b–0x117a26From the current page
Encode a shape0x117b0x117b–0x12fb2716-colour shape from a page
Encode a shape with transparent runs0x12fc0x12fc–0x140d28Shape without colour table
Encoder helpers0x140e, 0x1429, 0x14380x140e–0x1447—Source, size, colour map
Empty slot0x14480x1448–0x144c29Returns
Write a shape pixel0x144d0x144d–0x149d—Level and pixel effect
Empty slot0x149e0x149e30Returns
Set the pixel effect0x149f0x149f–0x14b531Flag of the shape pixel writer
Empty slot0x14b60x14b632Returns
Empty slot0x14b70x14b733Returns
Empty slot0x14b80x14b834Returns
Empty slot0x14b90x14b935Returns
Write a pixel0x14ba0x14ba–0x14f136Colour at (x, y)
Restore the shape window0x14f20x14f2–0x151837After the mouse cursor
Draw a mirrored shape through the replacement table0x15190x1519–0x17e43816-colour shape, flipped
Draw a mirrored shape0x17e50x17e5–0x1c3139Shape in its own colours, flipped
Save and open the shape window0x1c320x1c32–0x1c7441Before the mouse cursor
Empty slot0x1c750x1c7542Returns
Scale a shape by one step0x1c820x1c82–0x1d6c43Two thirds of the shape
Save a rectangle0x1d6d0x1d6d–0x1e2d44From page 0; also the body of slot 26
Set the line rectangle0x1e2e0x1e2e–0x1e5045Line clipping bounds
Set the shape window0x1e510x1e51–0x1e7346Shape clipping bounds
Install a colour table0x1e740x1e74–0x1e9e47Current colour table
Set palette colours0x1e9f0x1e9f–0x1ed948VGA palette registers
Return no table0x1eda0x1eda–0x1ee249Returns 0:0
Empty slot0x1ee30x1ee350Returns
Size of a saved rectangle0x1ee40x1ee4–0x1f1951Buffer size for slots 26 and 44
Draw one glyph0x23110x2311–0x2435—One character of the font
Draw a line of text0x24360x2436–0x250952String in two colours

Game call sites​

The game calls a driver routine with call far [DS:0x6522 + 4 × slot], through the function table. A byte search of START.EXE for that instruction gives the sites below, which apply to XGA.OVL as well. Resident sites are analysis addresses; overlay sites are physical offsets, after the overlay's number. Arguments follow the order of each routine's entry on this page. The search finds no call of slots 0–6, 16, 24, 25, 29, 30, 40, 45, 50 and 53.

SlotSitesArguments and use
7255: 0x4d3ae, 0x4d3cdThe street scroll, in modes 3 and 6 only: (11, 8) to (8, 8), 301 × 128, page 0 to page 0, which scrolls 3 pixels to the left; then (x, 0) to (309, 8), 3 × 128, from a given page to page 0.
80x1bd44, 0x214dd, 0x27940; 247: 0x43aea; 249: 0x47495; 252: 0x4ba91In site order: (0, 0, 18, 168); a table's x / 8 and y, 2, 16; (9, 0, 4, 120); (0, 120, 22, 24); the current text window; (3, 0, 18, 104). No site uses a returned value.
90x215dc, 0x22302, 0x2a59f, 0x33991In site order: as 0x214dd; (8, 121, 14, 56); the text window's column, row and width with a computed height; the mouse cursor's area, kept within the page. All sizes are positive. No site uses a returned value.
100x19388, 0x1939c; 245: 0x41e5f, 0x41e94; 249: 0x46f54; 250: 0x4827e, 0x482ca; 255: 0x4d2a5; 256: 0x4f8c3Source page, destination page and a far pointer that both drivers ignore, 0:0 at the fixed sites: (3, 4) at 0x4827e and (3, 6) at 0x482ca.
110x1a9fe; 244: 0x3e4bd, 0x3e4de
12250: 0x48961, 0x48980, 0x4899f, 0x489be, 0x489fc; 255: 0x4d64b, in mode 3 onlyNo site uses the returned pointer.
130x2d9a8Inside the page-area copy, which limits widths to 40, heights to 200 and columns to below 40, and moves negative positions to 0, but does not limit y + height.
140x31473; 254: 0x4c77a, 0x4cbdf; 255: 0x4e0c7, 0x4e7a5, 0x4e83d, 0x4ec23, 0x4ec7d, 0x4ef07, 0x4ef2e, 0x4efe1; 256: 0x5054a, 0x50b83, 0x512cb, 0x51463
15, 18, 38, 3915: 0x2db30; 18: 0x2dab0, 0x33aac; 38: 0x2db70; 39: 0x2daf0The first site of each is in one of the four drawing wrappers, which push the page, the shape's far pointer, x and y plus the window's origin.
1730 resident sites, from 0x192f5 to 0x2da2cx1, y1, x2, y2, colour.
19, 2019: 0x30300, 0x3041f, 0x30547; 20: 0x3035d, 0x304ae, 0x305eaEmpty in both drivers.
210x1ea5e, 0x1ea9d, 0x29674, 0x29697, 0x296ba, 0x29733; 244: 0x3e1f1, 0x3e451, 0x3e9ac, 0x3f287, 0x3f2f9; 255: 0x4d80e, 0x4d904
220x197db, 0x1d657, 0x221fd, 0x22e31, 0x233d6, 0x29383, 0x293a8, 0x29f5f, 0x31d52, 0x321b3; 244: 0x3f732; 247: 0x4329d; 251: 0x4976b, 0x4981d; 252: 0x4a917; 254: 0x4c95ex1, y1, x2, y2, colour, always in order: (227, 65, 238, 69, 12) at 0x1d657, or (x, y, x + a, y + b) with a and b above 0 where they are computed.
230x22e3c, 0x232da, 0x232f2, 0x233e1, 0x23856, 0x2386c; 253: 0x4c0fd
260x278cf; 249: 0x471de; 252: 0x4b9b0
2737 sites; 249: 23 from 0x4678a to 0x46eac; 250: 0x47834, 0x479b5, 0x479f2, 0x47be6, 0x47e45, 0x47ee3, 0x47f7a; 252: 0x4a6b0, 0x4b8af, 0x4b8e2, 0x4b915, 0x4b94c; 255: 0x4d5a9; 256: 0x4fac6
28245: 0x3f8ef, 0x41dba, 0x41e24; 251: 0x49dfa, 0x49eab; 252: 0x4ae00; 254: 0x4c480; 255: 0x4d545; 256: 0x4fa54
31255: 0x4d804, 0x4d90dMode 3 only: 1, then slot 21 with 1, slot 47 with a fading table, a page-area copy and a shape, and at the end slot 21 with 0, then 0, so the flag is on only while the level is 1. Neither site uses the returned value.
32–35, 4232: 0x2dc39; 33: 0x2dbb3; 34: 0x2dc7c; 35: 0x2dbf6; 42: 0x2da70In five wrappers shaped like the drawing wrappers, with one word more. Empty in both drivers.
360x21e6e, 0x21ec4, 0x23181, 0x23364, 0x236a6, 0x238c8; 253: 0x4c116
41, 37Pairs: 0x327b0, 0x327bc; 0x32860, 0x32871; 0x3389a, 0x338a6; 0x33b5f, 0x33b6a; 0x33ba9, 0x33bb4; 0x33bd5, 0x33be0; 0x33c00, 0x33c0b; 0x33c79, 0x33c8aSlot 41 and then slot 37, around a resident call, in the mouse-cursor code.
43244: 0x3e20f, 0x3e915Both give the work area as destination. The first is in a loop in which each result is the source of the next step.
440x1d75b, 0x2147f, 0x21e34, 0x2a4bc, 0x33a91; 247: 0x43aba, 0x4484e; 248: 0x4626f
460x2dcdbThe current text window: left column, left column + width, top, top + height.
470x1ea53, 0x1ea93, 0x29669, 0x2968c, 0x296af, 0x29729; 255: 0x4d847
480x3112d, 0x3117e, 0x3153d, 0x3156e; 255: 0x4d724, 0x4dd29, 0x4def3; 256: 0x4fba1, 0x4ffa4, 0x50174Resident sites: (palette, 0, 255); (palette, i, i); in mode 5 the identity list with (0, 16); in mode 2 a list with (0, 16).
49250: 0x481c0, 0x481d3Mode 6 only.
510x2a46e, 0x33829, 0x33855
5265 sites: 40 resident, from 0x18e66 to 0x32286, and 25 in overlays 245, 247, 249, 251, 252, 254, 255 and 256At 254 0x4cb54 and 0x4cbb2 the x can be 6,103 or 11,030 (ANOMALY-91), and the routine then returns before reading the string.

Routines​

Copy a rectangle given in pixels​

AddressRangeSlot
0x03d10x03d1–0x04f27

Arguments: source x, y, destination x, y, width and height in pixels, source page, destination page. The rectangle is clipped to the page, then copied row by row, from the left, between the even pages of the two pages (0x04c9–0x04e5). A source or destination starting at x 320 or more or y 200 or more cancels the copy; a negative position is moved to 0 and the width or height reduced by the same amount; the width and height are then limited to what fits in both pages. The game's known calls scroll the street of the introduction, 3 pixels to the left, and copy a 3-pixel column into it.

Anomaly

Bug. When the source x is negative, the routine moves the source to 0 and reduces the width, but it also adds the negative x to the destination x (0x03fb), which moves the destination left instead of right. The rows and the destination y are treated the same way (0x040b), and so is a negative destination, which shifts the source (0x041b, 0x042b). The copy then puts its pixels, or takes them, twice the clipped distance away from where they belong; if that makes the other position negative, the copy is cancelled. The game's two calls use no negative position, so the bug has no known effect in play. A faithful reimplementation applies the shift in the wrong direction as described. (ANOMALY-110)

Anomaly

Bug. After clipping, the routine cancels the copy when the width is 320 or more or the height 200 or more (0x0491–0x04a3), although its own clipping has just limited them to 320 − x and 200 − y. A copy of the full width or the full height therefore does nothing. A height of 0, given or left by the clipping of a negative y, passes the test, and the row loop counts down before testing (0x04e4), so it copies 65,536 rows: both offsets wrap around their 64 KB segments, and the copy also writes the 1,536 bytes past the page's 64,000. A negative destination y moves the source y by the same amount, and the copy is cancelled if that makes it negative. The game's two calls avoid both cases. A faithful reimplementation copies nothing for a width of 320 or a height of 200 and treats a height of 0 as 65,536 rows. ( ANOMALY-111)

Used by: The introduction › Scroll the street, Anomalies and bugs

Copy a page​

AddressRangeSlot
0x04f30x04f3–0x052a10

Arguments: source page, destination page, and a far pointer that the driver ignores. It copies the 64,000 bytes of the source's odd page, the source page with bit 0 set, to the destination's even page, the destination page with bit 0 clear. It does nothing when the two segments are equal or when either is 0, which is the case for a page and its pair in this mode (pages). The game calls it after loading a picture into the odd page of a pair, for example in the scene loaders of the introduction and the ending.

Used by: The introduction › Load a scene, Load a scene

Restore a saved rectangle​

AddressRangeSlot
0x052b, 0x05460x052b–0x0545, 0x0546–0x05e38, 9

Slot 8 writes into the current page, slot 9 into page 0; both continue in the same code at 0x0553. Arguments: column, y, width in columns, height, far pointer to a buffer written by save a rectangle. The column is limited to 0–39 and y to 0–199, the width to 40 columns and the height to 200 rows; a width or height of 0 writes nothing. The buffer holds the rows one after the other, 8 bytes per column. The rectangle is not clipped to the end of the row or to the bottom of the page: a wider rectangle continues on the next row. The routine returns nothing.

Anomaly

Bug. The width and height limits compare without sign (0x058c–0x0591, 0x059a–0x05a0), so a negative width becomes 40 columns and a negative height 200 rows. The sign test that follows the width limit (0x0598) can never succeed. The save routine of the same driver returns without copying for any size of 0 or less. The game's calls always pass positive sizes, so the bug has no known effect in play. A faithful reimplementation restores 40 columns or 200 rows for a negative width or height. ( ANOMALY-112)

Used by: Camp menu and spells › Save and restore the strip below the view, Anomalies and bugs

Set the replacement colour table​

AddressRangeSlot
0x05e40x05e4–0x060511

Copies the 16 bytes at its far-pointer argument to 0x270a. The shape drawers of slots 15 and 38 read every pixel of a 16-colour shape through this table instead of the shape's own table, and leave a pixel unchanged where the entry is 0. The game's monster drawing sets it to the flash and stone tables, which turn every drawn pixel into colour 15 or 13, or to a colour variant, just before such a draw.

Used by: Draw a monster shape, Monsters in the view › Drawing a monster

Build a colour table​

AddressRangeSlot
0x06060x0606–0x074512

Takes a palette, a destination, a colour c and a weight w; a null palette makes it return at once. Entry 0 of the table is 0. For each colour i from 1 to 255, each component x becomes x − ((x − r) × 2⌊ w / 2⌋) / 256, rounded down, r being the same component of colour c. The entry is the palette colour 1–255 nearest to the result by the sum of squared differences, ties going to the later colour, colour i itself excluded unless it is c. The table becomes the current colour table at 0x250a and is copied to the destination unless it is null. Work variables are inside the routine, at 0x072d–0x0737. It returns the offset 0x250a with segment 0 (0x0741): the file marks that segment as a relocation, which the game's loader fills with 0. This is ANOMALY-101, described on the EGA driver page; no call uses the value.

Used by: Clipping, scaling and darkening › Darkening with distance, Load the level palette and colour tables, Fading tables (FADING.DAT), Anomalies and bugs

Copy a rectangle between pages​

AddressRangeSlot
0x07460x0746–0x080413

Arguments: source column and y, destination column and y, width in 8-pixel columns, height, source page, destination page. It copies the rectangle between the even pages of the two pages, 8 bytes per column and row (0x07e9–0x07f9). A column of 40 or more, a y of 200 or more, or a width of 0 or more than 40 copies nothing; a negative position becomes 0. The rectangle is not clipped to the end of the row, and the source is not checked against the bottom of the page. The game reaches this slot through its page-area copy.

When the destination y plus the height passes 200, the height becomes 199 − y (0x07d4–0x07e3), one row fewer than fits, and 0 when y is 199; a height of 0 copies 65,536 rows (0x07f8) and a negative height nothing (0x07e5–0x07e7). This is ANOMALY-103, shared with the EGA driver and described on its page.

Used by: Copy a page area, Anomalies and bugs

Clear the current page​

AddressRangeSlot
0x08050x0805–0x082014

Writes 64,000 zero bytes to the even page of the current page. The introduction and the ending use it to clear the screen.

Used by: The introduction › Play the introduction

Draw a shape through the replacement table​

AddressRangeSlot
0x0a1c0x0821–0x0a3315

Arguments: page, far pointer to a shape, x and y. Slot 15 enters at 0x0a1c, which sets the row loop to 0x098e and continues at 0x0821. The routine draws only 16-colour shapes; a shape of format 0 is not drawn (0x0865). Each 4-bit pixel goes through the replacement table, not through the shape's own table: an entry of 0 leaves the pixel unchanged, any other entry is drawn through the shape pixel writer. The shape is drawn into the even page of the given page, at any x, and clipped to the shape window. The rows above the window are skipped, and drawing stops at its bottom row or after the last row of the shape.

Anomaly

Bug. When the left edge of the shape window cuts the shape after an odd number of pixels and the right edge does not cut it, each row of the visible part starts with half a byte, and the byte count, half the visible width rounded down (0x094e), leaves the last byte of the row undrawn. The routine adds 2 to the step to the next row (0x0973), so the rows stay in place, but the last two pixels of every row of the shape are not drawn. When both edges cut the shape, or the left edge cuts an even number of pixels, every visible pixel is drawn. The three other shape drawers have the same code: slot 18 for 16-colour shapes (0x0ee0–0x0f07) and the mirrored slot 38 (0x16a0–0x16e0) and slot 39 (0x1af8–0x1b38), where the two pixels lost are the two the mirror puts at the right end. The pixels lost are often transparent padding of the shape's last column, so the effect is seen only when they are not (inferred). A faithful reimplementation leaves those two pixels undrawn in that case. (ANOMALY-113)

Used by: Draw a shape in a window, Draw a monster shape, Anomalies and bugs

Draw a line​

AddressRangeSlot
0x0a34, 0x0a5c0x0a34–0x0c4517

Arguments: x1, y1, x2, y2, and a colour. Slot 17 selects the even page of the current page and calls the near line routine at 0x0a5c. The line is clipped to the line rectangle: end points outside it are moved along the line onto its edges by the clipping helpers, and a line entirely on one outer side is not drawn (0x0a6c–0x0acc). The line is then drawn from the end with the smaller y: a horizontal line as a run of bytes (0x0bf4), a vertical one row by row (0x0c26), and the others one pixel per step of the longer axis (0x0bb2, 0x0bd4). The colour, kept at 0x0c3a, is written unchanged. The table at 0x0ad4 belongs to this routine.

Used by: Draw a framed box, Transfer: spells and items, Transferring a party from Eye of the Beholder I

Line clipping helpers​

AddressRangeSlot
0x0af4, 0x0af6, 0x0b00, 0x0b14, 0x0b2d, 0x0b37, 0x0b4b, 0x0b600x0af4–0x0b8a—

Near routines of the line drawer:

AddressRole
0x0af4Point inside: returns with the carry clear
0x0af6Moves the point onto the top edge
0x0b00Moves the point onto the bottom edge, by negating the coordinates and using the top-edge computation
0x0b14Computes where the line crosses a horizontal edge, by multiplying and dividing
0x0b2dMoves the point onto the left edge
0x0b37Moves the point onto the right edge, by negation
0x0b4bComputes where the line crosses a vertical edge
0x0b60Outcode of a point: 1 above, 2 below, 4 left, 8 right of the rectangle

The four edge routines return with the carry set, which makes the line drawer classify the point again. The line drawer calls them through the table at 0x0ad4, indexed by the outcode.

Used by: Draw a line

Draw a shape​

AddressRangeSlot
0x0c460x0c46–0x0f9a18

Arguments: page, far pointer to a shape, x and y. The shape is drawn in its own colours into the even page of the given page, clipped to the shape window; every drawn colour goes through the shape pixel writer. A 16-colour shape (0x0e09) is drawn as by slot 15, but through its own table, and skips its last two pixels in the same case. A shape of format 0 (0x0c9c) is read run by run: the rows above the window and the pixels left of it are skipped by counting (0x0cdd–0x0cf2, 0x0d84–0x0da0), and a run of transparent pixels that crosses the window edge continues past it (0x0dac). 0x0f99 is never reached.

Used by: Draw a shape in a window, Clipping, scaling and darkening › Darkening with distance, Wall decorations (DEC), Anomalies and bugs

Empty slots​

AddressRangeSlot
0x0f9b, 0x0f9c, 0x1159, 0x115a, 0x149e, 0x14b6, 0x14b7, 0x14b8, 0x14b9, 0x1c75, 0x1ee3one byte each19, 20, 24, 25, 30, 32, 33, 34, 35, 42, 50
0x14480x1448–0x144c29

Each of the first eleven is a single far return. Slot 29 sets up a stack frame, removes it and returns; the game never calls it, since no instruction refers to its entry DS:0x6596 of the driver function table. The game calls slots 19, 20, 32–35 and 42, which therefore do nothing. Slots 32–35 and 42 are reached through draw routines of the game shaped like draw a shape in a window, with one more argument.

Used by: Function list

Set the shape level​

AddressRangeSlot
0x0f9d0x0f9d–0x0fb121

Stores the low byte of its argument at 0x00dd and returns the previous value. The view calls it with the number of scale steps before reducing a shape and with 0 after drawing items, monsters and flying objects. The shape pixel writer uses it as the number of times each colour goes through the current colour table.

Comparative source: REF-SCUMM-016, setShapeFadingLevel.

Used by: Clipping, scaling and darkening › Scale steps, Clipping, scaling and darkening › Darkening with distance

Fill a rectangle​

AddressRangeSlot
0x0fb20x0fb2–0x105322

Arguments: x1, y1, x2, y2, both corners included, and a colour. A corner at x 320 or more or y 200 or more cancels the whole fill, and so does a first corner to the right of or below the second; negative values become 0. Each row is filled with the colour, unchanged, on the even page of the current page. The limits of the second corner to 319 and 199 at 0x100e–0x101d are never reached, since such corners are rejected before. The game's calls pass their corners in order.

Used by: Draw a framed box, Transfer: spells and items, Transferring a party from Eye of the Beholder I

Page segment helpers​

AddressRangeSlot
0x1054, 0x1079, 0x109b, 0x10a30x1054–0x10b4—

Near routines that return the segment of a page from the game's page table, which the driver reaches through slot 1, with the current page read through slot 2:

AddressReturns the segment ofCalled by
0x1054the current page with bit 0 set (its odd page)slots 27, 28
0x1079the current page with bit 0 clear (its even page)slots 14, 17, 22, 23, 36, the glyph drawer
0x109bpage AX with bit 0 setslot 10
0x10a3page AX with bit 0 clearslots 7, 8/9, 10, 13, 15, 18, 26/44, 38, 39

Used by: How the driver draws › Pages

Read a pixel​

AddressRangeSlot
0x10b50x10b5–0x10ed23

Arguments: x, y. Returns the byte at (x, y) of the current page's even page, or 0 outside 320 × 200. With write a pixel, the pixel dissolve copies a picture exactly.

Used by: Pixel dissolve

Install the driver's routines​

AddressRangeSlot
0x10ee0x10ee–0x1146—

The address returned by the driver entry. It walks the 54 slots together with the game's driver function table: where the game's slot holds a pointer, the driver copies it into its own table; otherwise it writes its own routine, with its code segment, into the game's slot. It stops with the carry flag set when a slot stays empty, and returns with the carry clear otherwise (0x1139–0x113c). The game's loader tests that flag.

Used by: Display drivers › Loading a driver

Driver entry​

AddressRangeSlot
0x11470x1147–0x1158—

Reached through the jump at image offset 0, which the game's loader calls first. It returns 0x272 in BX, the number of 16-byte paragraphs the driver needs with its run-time tables, and 0x10ee, the install routine, in AX. It does not touch the card.

Used by: Display drivers › Loading a driver

Save a rectangle​

AddressRangeSlot
0x115b, 0x1d6d0x115b–0x117a, 0x1d6d–0x1e2d26, 44

Slot 26 reads the current page and slot 44 page 0; both continue in the same code at 0x1d79. Arguments: column, y, width in columns, height, far pointer to a buffer. A width or height of 0 or less saves nothing and returns 0. Otherwise the column is limited to 0–39, y to 0–199, the width to 40 and the height to 200. The routine copies the rows into the buffer, 8 bytes per column, and returns the number of bytes written. As in restore a saved rectangle, the rectangle is not clipped to the row or the page. 0x1179 is never reached.

Used by: Camp menu and spells › Save and restore the strip below the view

Encode a shape​

AddressRangeSlot
0x117b0x117b–0x12fb27

The shape encoder. Arguments: column x and width w in 8-pixel units, row y and height h in pixels. It reads the odd page of the current page (pages) from offset 8 x + 320 y, the row part taken from the table of row offsets at 0x0233 (0x140e–0x1428), 8 w pixels per row for h rows, with no check against the page: past column 39 it continues on the next row, past row 199 it reads what follows the page, the offset wrapping at 65,536. It makes two passes. The first gives each colour an index in order of first appearance, at most 16, and counts the bytes. Between the passes it allocates the shape through the game's routine in slot 3, without testing the result. The second writes the header 1, h, w, h, the 16-byte colour table (unused entries 0xff) and the pixels, 4 bits each, high nibble first. A colour beyond the sixteenth is coded as index 0. It returns the shape's far address.

Comparative source: REF-SCUMM-011, Screen_EoB::encodeShape.

Used by: Monster decorations (DCR), Images (CPS), The introduction › Load a scene, Load a scene

Encode a shape with transparent runs​

AddressRangeSlot
0x12fc0x12fc–0x140d28

Takes the same arguments as the encoder, reads the same pixels and makes the same two passes. The shape has the header 0, h, w, h and no colour table. Each pixel of colour 1–255 is one byte; a run of pixels of colour 0 becomes a 0 byte and its length, up to the end of the row, split as 00 ff 00 and the rest when it is longer than 255 (shapes). Party creation cuts its button labels with it; the introduction and the ending use it for their shapes with negative numbers.

Used by: The introduction › Cut a scene's shapes

Encoder helpers​

AddressRangeSlot
0x140e, 0x1429, 0x14380x140e–0x1447—

Near routines of the two encoders: 0x140e points to the first source pixel, 0x1429 takes the width and height arguments, and 0x1438 marks every colour of the colour-to-index map at 0x260a as unused (0xff).

Used by: Encode a shape

Write a shape pixel​

AddressRangeSlot
0x144d0x144d–0x149d—

Called by the four shape drawers for each pixel they draw. When the level is not 0, the colour is replaced by table[colour] that many times, through the current colour table (0x147a–0x1498), before it is written. When the pixel-effect flag is set, the colour replaced in this way is not the shape's: with a level other than 0 it is the pixel already on the page (0x145d), so the shape recolours what lies under it through the current colour table; with level 0 it is the page pixel 0 to 7 positions to the right, the distance cycling with each pixel drawn (0x1462–0x1475). The game sets the flag only while the level is 1, so the second case is not reached.

Used by: Clipping, scaling and darkening › Darkening with distance, The introduction › Run an animation list

Set the pixel effect​

AddressRangeSlot
0x149f0x149f–0x14b531

Stores the low byte of its argument at 0x0215, the flag that makes the shape pixel writer recolour the page under a shape instead of drawing the shape's colours. The game sets it to 1, with level 1, around the shape draws of the introduction's animations that show a shape through a fading table, and back to 0 afterwards.

Anomaly

Bug. The routine loads the previous flag into AX (0x14a4–0x14a6), as set the shape level does to return it, but it saved AX on entry (0x14a2) and restores it before returning (0x14b3). The previous value is lost, and the caller gets back its own AX. No call uses the result, so the bug has no effect in play. A reimplementation does not need to return anything from this slot. (ANOMALY-115)

Used by: The introduction › Run an animation list, Anomalies and bugs

Write a pixel​

AddressRangeSlot
0x14ba0x14ba–0x14f136

Arguments: x, y, colour. Outside 320 × 200 it does nothing. Otherwise it writes the colour, unchanged, at (x, y) of the current page's even page.

Used by: Pixel dissolve

Restore the shape window​

AddressRangeSlot
0x14f20x14f2–0x151837

Copies the window saved by slot 41 at 0x00de back into the shape window. The game calls it after drawing the mouse cursor.

Used by: How the driver draws › Driver state

Draw a mirrored shape through the replacement table​

AddressRangeSlot
0x15190x1519–0x17e438

Slot 15 flipped left to right. The routine sets the row loop to 0x1729 and continues at 0x152d; its work variables are at 0x00ef–0x0112. It reads each row of the visible part from its right end leftwards and swaps the two pixels of each byte through the table at 0x0113 (0x174a, 0x1761), so the shape's right column is drawn first, at the left. Only 16-colour shapes are drawn, through the replacement table; clipping and the two pixels it can skip (0x16a0–0x16e0) work as in slot 15.

Used by: Draw a shape in a window, Draw a monster shape, Anomalies and bugs

Draw a mirrored shape​

AddressRangeSlot
0x17e50x17e5–0x1c3139

Slot 18 flipped left to right. A 16-colour shape (0x19f2) is drawn as by slot 38, through its own table. A shape of format 0 (0x1851) is read forwards and drawn from the right end of the visible part leftwards (0x19a6): the routine first skips the pixels beyond the right edge of the window, then draws, then skips those beyond the left edge.

Used by: Draw a shape in a window, Clipping, scaling and darkening › Darkening with distance, Anomalies and bugs

Save and open the shape window​

AddressRangeSlot
0x1c320x1c32–0x1c7441

Saves the shape window at 0x00de and sets it to the whole page: columns 0–40, rows 0–200. Its far-pointer argument is ignored. The game calls this slot before drawing the mouse cursor and restores the window afterwards.

Used by: How the driver draws › Driver state

Scale a shape by one step​

AddressRangeSlot
0x1c820x1c82–0x1d6c43

Copies a 16-colour shape, two pixels per byte, into a reduced shape: height (h + 1) × 2 / 3 rounded down, width in columns 2 w / 3 rounded up, the 16-byte colour table unchanged. The format byte is copied without being tested; every shape the game reduces is a 16-colour shape made by slot 27. Rows whose index is 2 modulo 3 are skipped. In each row, the near routine at 0x1d35 keeps pixels 0, 1, 3 and 4 of every six. One leftover byte is copied and followed by a byte of the blank colour pair; two leftover bytes give one byte of their high pixels and three blank bytes (0x1d5d–0x1d6b). The blank colour is the first colour-table index whose entry is 0, or 0. The source pointer is used as given (0x1c8c–0x1c9b), with no null test. The game reduces shapes step by step into a work buffer at DS:0xcbc4, each result becoming the source of the next step (shape reduction).

Anomaly

Bug. The row counter starts at h + 1 (0x1c9c–0x1c9e) and the loop decrements it after each row (0x1d0c–0x1d2a). Unless h is 2 modulo 3, the routine therefore reads one row past the source shape's rows and writes it after the reduced shape, beyond the height in its header. That row is not drawn, since the drawers stop at the header's height; it lands in the game's work buffer after the result. The buffer holds 5,120 bytes and the largest first reduction of a picture of the game, extra row included, about 1,700, so the row overwrites nothing else. A faithful reimplementation needs only the rows of the header. ( ANOMALY-28)

Anomaly

In every group of six pixels the routine drops the pixels whose index in the row is 2 modulo 3. When a row ends with two leftover bytes, which happens when the width is 2 modulo 3 columns, it keeps pixels 0 and 2 of those four (0x1d5d–0x1d64) instead of pixels 0, 1 and 3: it keeps the one the rule drops and drops two that it keeps. For a shape 2 columns wide, source pixels 12 and 14 are kept and 13 and 15 dropped. The reduced shape's right edge therefore differs slightly from a regular two-thirds reduction (inferred: not observed in play). A faithful reimplementation keeps the same two pixels. (ANOMALY-114)

Comparative source: REF-SCUMM-016, scaleShapeStep and scaleShapeProcessLine4Bit.

Used by: Doors, teleporters and temporary walls › Released shapes, Shape reduction, Driver function table, Anomalies and bugs, Spots and wall decorations

Set the line rectangle​

AddressRangeSlot
0x1e2e0x1e2e–0x1e5045

Stores its four arguments unchanged as the line rectangle: x min, y min, x max, y max. No call from the game is known, so the line rectangle keeps its initial value, 0, 0, 319, 199.

Used by: Function list

Set the shape window​

AddressRangeSlot
0x1e510x1e51–0x1e7346

Stores its four arguments as the shape window: left column, right column, top row, bottom row; the right column and bottom row are excluded. The game calls it when a draw goes to another text window than the last one. It passes the window's column, column plus width, row and row plus height.

Used by: Draw a shape in a window

Install a colour table​

AddressRangeSlot
0x1e740x1e74–0x1e9e47

Copies 256 bytes from its argument into the current colour table at 0x250a and returns that table's far address, with the driver's segment; a null argument only returns it.

Used by: Clipping, scaling and darkening › Darkening with distance, Fading tables (FADING.DAT)

Set palette colours​

AddressRangeSlot
0x1e9f0x1e9f–0x1ed948

Arguments: a palette of 3-byte entries, a first and a last colour number. It writes the first number to port 0x3c8 and the three values of each colour from the first to the last to port 0x3c9, the VGA palette registers. The game's palette setting passes colours 0 to 255, or one colour at a time.

Used by: Compressed containers (CPS) › Palette, Set the palette, Palettes (PAL, EGA, COL)

Return no table​

AddressRangeSlot
0x1eda0x1eda–0x1ee249

Returns the null far pointer 0:0. The game calls slot 49 only in display mode 6, so this routine is not reached.

Used by: Function list

Size of a saved rectangle​

AddressRangeSlot
0x1ee40x1ee4–0x1f1951

Arguments: width in columns, height. Returns 8 × w × h, with w limited to 1–40 and h to 1–200: the number of bytes that save a rectangle writes for that rectangle.

Used by: Save a rectangle

Draw one glyph​

AddressRangeSlot
0x23110x2311–0x2435—

A near routine called by draw a line of text with a character number from 0 to 127, x and y. The font is the one whose far pointer the game keeps at DS:0xf090, which the driver reads through slot 0. The glyph is read through the offset word at 2 × (number + 1) in the font, the layout of FONT6.FNT and FONT8.FNT: a word, 128 glyph offsets, the height and width bytes at 0x102 and 0x103, then the glyph rows. A glyph whose x is 320 or more, whose right edge passes x = 320, whose y is 200 or more, whose bottom passes row 200, or whose width is not 1 to 24 is not drawn. Each glyph row is one to three bytes, read against the unshifted mask of its width from the tables at 0x1f39: a set bit is drawn in the foreground colour, a clear bit in the background colour, and a colour of 0 is not drawn.

Used by: Initial items (ITEM.DAT) › Who uses it, Fonts (FNT)

Draw a line of text​

AddressRangeSlot
0x24360x2436–0x250952

Arguments: far pointer to a zero-terminated string, x, y, foreground colour, background colour; a background of 0 draws no background. A negative x or y becomes 0. An x of 320 or more or a y of 200 or more makes the routine return before it reads the string (0x2476, 0x248e). A byte 0x0d starts a new line at the starting x, one font height lower; a character whose advance would pass x = 320 also starts a new line, and drawing stops at row 200. Any other byte is masked with 0x7f (0x24ec) before the glyph drawer is called, so a byte from 0x80 up that reaches it is drawn as the glyph of its value minus 0x80. The game's text output expands such bytes before they get here (0x323b4). The font's byte 0x103 gives the advance of every character and byte 0x102 the line height. The string pointer is not checked: a null pointer makes the routine read from address 0000:0000 (0x24a2).

Used by: Initial items (ITEM.DAT) › Who uses it, Text output, Move the selection highlight, Transfer: spells and items, The introduction › Print a text, The end of the game › Print a text, Fonts (FNT), Transferring a party from Eye of the Beholder I

Sources​

The driver is identified by its SHA-256 hash in the file inventory. How the game loads it and the slot table are on the display drivers page, and the EGA driver, which takes the same arguments in the same slots, on the XGA.OVL page. The game's side of each call (page table, current page, palette setting, page-area copy, draw wrappers, display-mode set-up) is in the routines and data references. Comparative sources are listed in the technical references.