Skip to main content

XGA.OVL, the 256K EGA display driver

The game executable · Display drivers · File inventory

In brief​

XGA.OVL is the display driver the game loads for display mode 5, labelled "256K EGA" by the setup program. It has the same 54 slots as the VGA driver MGA.OVL, takes the same arguments in the slots the game uses, and draws the same 320 × 200 game image. It draws it on an EGA card in its 640 × 200, 16-colour planar layout: each game pixel becomes two screen pixels, and each of the game's 256 colours becomes a fixed pair of the card's 16 colours.

The driver draws shapes, lines, filled rectangles, single pixels and text. It copies and saves rectangles, converts whole images into video memory, and cuts and reduces shapes. It also builds colour tables and turns the level palette into colour pairs. It does not set the video mode, load files or decide what is drawn: the game does all of that. Eleven slots are empty, and three slots hold pointers to tables rather than routines.

Addresses

Every address on this page is a driver image offset: the offset in XGA.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. In mode 5 the driver gives even and odd pages different roles:

PagesWhereLayoutWritten by
0, 2, 4, 6 (any page with bit 0 clear)Video memory, segments 0xa000, 0xa400, 0xa800, 0xac00Four planes of 16,000 bytes: 200 rows of 80 bytes, 8 screen pixels per byteThe driver's drawing routines, and the game's own tile drawing
3, 5, 7, … (any page with bit 0 set)Buffers allocated by the game, of the sizes set at start-upOne byte per game pixel, 320 per row, 64,000 bytes for a whole pageThe game only (for example the CPS loader); the driver only reads them

Page 0 is the screen. Every drawing routine draws into the even page of the page it is given, or of the current page. The byte page next to it does not change when the driver draws, so it keeps the last image the game put there. The driver reads a byte page in two cases: it converts the page into the even page, and it cuts shapes from it. The game's display-mode routine sets no buffer for page 1 in this mode.

Pages 4 and 6 of video memory also hold the level's wall blocks, which the game stores there when the level is loaded (display modes).

Colours​

The pair table has one byte per game colour. Its high four bits give the EGA colour of the left screen pixel and its low four bits the colour of the right one. The card's 16 palette registers hold the standard EGA colours: the game sets them through slot 48 with the identity list when it enters mode 5.

When the game sets a palette, the driver looks up each of its 256 colours in a fixed list of 256 candidate pairs at 0x2c2b. It keeps the nearest candidate by the sum of squared differences of the three 6-bit components. Only the 136 pairs whose left colour number is not greater than the right one are candidates; the other 120 entries are marked 0xff and skipped. Each candidate is the per-component root mean square of the two EGA colours, rounded: black and blue, (0, 0, 0) and (0, 0, 42), give (0, 0, 30).

Only the shape drawers use the replacement table and the darkening level. Lines, rectangles, pixels and text go straight through the pair table.

Shapes​

The driver codes shapes in its own way. The game reads only the 4-byte header: format, height, width in 8-pixel columns, height. Format 1 follows the header with a 16-byte colour table; other formats have none. Then come the pixels, row by row and 8-pixel column by column. Each column is a list of groups. A group is a mask of the column's 8 pixels and the colour of those pixels. The list ends when the masks together cover all 8 pixels. In format 1 the colour is a 4-bit index into the shape's table, and two groups share 3 bytes: mask, both indices, mask. In other formats a group is 2 bytes, mask and colour. A colour that the tables turn into 0 is not drawn.

Driver state​

Between calls the driver leaves the card with all four planes enabled, write mode 2 and every bit of the bit mask set. Most drawing routines count on this. It keeps a copy of every sequencer and graphics register it writes in a 16-byte block at 0x00de, and updates the copy and the register together with interrupts disabled. When it is installed, it gives the game the address of that block. The game's mouse-cursor code passes it to save the display state, calls its own drawing, and then restores the state; that drawing is the mouse pointer, the shape stored by resident 0x337d0 drawn at the mouse position minus its hot spot (0x338ba, 0x339a5).

The driver keeps two clipping rectangles. The shape window (0x0124–0x012b: left column, right column, top row, bottom row; the right column and bottom row are excluded) limits the shape drawers. The game sets it through slot 46 from the current text window, and it is empty until then. The line rectangle (0x011c–0x0123: 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.

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–0x00edvariableDisplay state: copies of the sequencer index and registers 0–4 and of the graphics index and registers 0–8
0x00ee–0x00fdvariableSaved display state (slot 41)
0x00fe–0x0105variableSaved shape window
0x0106–0x0107dataZero, not used
0x0108–0x0109variableRight limit of text, 320
0x010a–0x0119variableWork variables of the rectangle copy
0x011a–0x011bdataZero, not used
0x011c–0x0123variableLine rectangle: x min, y min, x max, y max
0x0124–0x012bvariableShape window: left column, right column, top, bottom
0x012c–0x022bdataBit-reversal table, 256 bytes; slot 40 points here
0x022c–0x042bdata256 words: bit k of the index moved to bit 2k + 1, turning a mask of game pixels into a mask of left screen pixels
0x042c–0x0437dataSingle-bit masks 0x80…0x01, and right-pixel masks 0x40, 0x10, 0x04, 0x01
0x0438–0x05c9dataRow offsets: 201 words, 80 × y for y = 0–200; slot 53 points here
0x05ca–0x09a1codeSlots 7, 10, 8, 9, 11 and most of 12
0x09a2–0x09acvariableWork variables of slot 12
0x09ad–0x0e78codeEnd of slot 12, slots 13, 14, 15, start of 17
0x0e79–0x0e98data16 near pointers: line clipping helper for each outcode
0x0e99–0x10a0codeLine clipping helpers and line loops
0x10a1–0x10b4variable, dataLine variables, pixel masks 80 20 08 02, 4 near pointers to the line loops, colour pair
0x10b5–0x114fcodeSlots 18–21, start of 22
0x1150–0x1175variable, dataRectangle-fill variables and edge masks; the 4-byte tables at 0x115e and 0x116a are not used
0x1176–0x20b8codeEnd of slot 22, page helpers, slots 23–39 and 41–43
0x20b9–0x21b8dataMask table of the scale step
0x21b9–0x2474codeSlots 44–51
0x2475–0x2485variableText variables: colour pairs, mask pointers, background flag, line start, advance, line height, font segment
0x2486–0x24b5data24 near pointers, one per glyph width 1–24
0x24b6–0x285ddataFor each width, 8 pointers and the masks of that many bits shifted by 0–7; only the unshifted mask is read
0x285e–0x2c2acodeGlyph drawer and slot 52
0x2c2b–0x2f2adataCandidate colour of each of the 256 pairs (3 bytes each)

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

RangeContent
0x2f2b–0x302aPair table: the pair byte of each game colour
0x302b–0x312aInverse pair table: for each pair byte, the highest game colour that has it, or 0
0x312b–0x322aCurrent colour table (slots 12 and 47)
0x322b–0x332aReplacement colour table (slot 11; slot 16 points here), also the work area of the encoders
0x332b–0x352aWork area of the scale step
0x342b–0x352aColour-to-index map of the encoder, inside the previous area
0x352bNumber of colours indexed by the encoder

Four 2-byte pop bp; retf sequences, at 0x0705, 0x10bb, 0x14a9 and 0x1d15, 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). As in MGA.OVL, the bytes at file offsets 0x1c–0x21 hold 01 00 fb 30 6a 72, which nothing uses.

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 pixels0x05ca0x05ca–0x06227Pixel rectangle copy, rounded to columns
Convert an image page into video memory0x06230x0623–0x06ee10Byte page to planar page
Restore a saved rectangle0x06ef0x06ef–0x07068Into the current page
Restore a saved rectangle0x07070x0707–0x083e9Into page 0
Set the replacement colour table0x083f0x083f–0x087a1116-entry table for slots 15 and 38
Build a colour table0x087b0x087b–0x09ba12Colour table towards a colour
Copy a rectangle between pages0x09bb0x09bb–0x0af413Column rectangle copy in video memory
Clear the current page0x0af50x0af5–0x0b1414Planar page to colour 0
Draw a shape0x0b150x0b15–0x0ddd15Through the replacement table; also the body of slot 18
Draw a line0x0dde0x0dde–0x10b417Clipped line
No clipping needed0x0e990x0e99–0x0e9a—Line clipping helper
Clip to the top0x0e9b0x0e9b–0x0ea4—Line clipping helper
Clip to the bottom0x0ea50x0ea5–0x0eb8—Line clipping helper
Cross a horizontal edge0x0eb90x0eb9–0x0ed1—Line clipping helper
Clip to the left0x0ed20x0ed2–0x0edb—Line clipping helper
Clip to the right0x0edc0x0edc–0x0eef—Line clipping helper
Cross a vertical edge0x0ef00x0ef0–0x0f04—Line clipping helper
Classify a point0x0f050x0f05–0x0f2f—Line clipping outcode
Draw a shape0x10b50x10b5–0x10bc18Entry into the shape drawer without replacement table
Empty slot0x10bd0x10bd19Returns
Empty slot0x10be0x10be20Returns
Set the shape level0x10bf0x10bf–0x10d321Darkening steps of the next shapes
Fill a rectangle0x10d40x10d4–0x12c122Solid rectangle
Byte page of the current page0x12c20x12c2–0x12dc—Page segment helper
Planar page of the current page0x12dd0x12dd–0x12f4—Page segment helper
Byte page of a page0x12f50x12f5–0x12fc—Page segment helper
Planar page of a page0x12fd0x12fd–0x130e—Page segment helper
Read a pixel0x130f0x130f–0x13ae23Colour at (x, y)
Enable every bit0x13af0x13af–0x13c8—Bit mask to 0xff
Install the driver's routines0x13c90x13c9–0x142e—Exchange slots with the game
Prepare the card0x142f0x142f–0x1461—Initial register state
Driver entry0x14620x1462–0x1476—Size and install address
Select write mode 20x14770x1477–0x1490—Restores the drawing mode
Empty slot0x14910x149124Returns
Empty slot0x14920x149225Returns
Save a rectangle0x14930x1493–0x14aa26From the current page
Encode a shape0x14ab0x14ab–0x16202716-colour shape from the byte page
Encode a shape with 8-bit colours0x16210x1621–0x170528Shape without colour table
Write colour pairs into video memory0x17060x1706–0x17d229Pairs from a buffer
Empty slot0x17d30x17d330Returns
Return 00x17d40x17d4–0x17da31Ignores its argument
Empty slot0x17db0x17db32Returns
Empty slot0x17dc0x17dc33Returns
Empty slot0x17dd0x17dd34Returns
Empty slot0x17de0x17de35Returns
Write a pixel0x17df0x17df–0x185f36Colour at (x, y)
Restore the display state0x18600x1860–0x1a2437After the mouse cursor
Draw a mirrored shape0x1a250x1a25–0x1d0e38Through the replacement table; also the body of slot 39
Draw a mirrored shape0x1d0f0x1d0f–0x1d1639Entry without replacement table
Save the display state0x1d170x1d17–0x1e5941Before the mouse cursor
Empty slot0x1e5a0x1e5a42Returns
Scale a shape by one step0x1e5b0x1e5b–0x20b843Two thirds of the shape
Save a rectangle0x21b90x21b9–0x229944From page 0; also the body of slot 26
Set the line rectangle0x229a0x229a–0x22c045Line clipping bounds
Set the shape window0x22c10x22c1–0x22e346Shape clipping bounds
Match the palette to colour pairs0x22e40x22e4–0x23ca48Pair table, or the EGA palette
Install a colour table0x23cb0x23cb–0x23f547Current colour table
Install a pair table0x23f60x23f6–0x243d49Pair table and its inverse
Empty slot0x243e0x243e50Returns
Size of a saved rectangle0x243f0x243f–0x247451Buffer size for slots 26 and 44
Draw one glyph0x285e0x285e–0x2b08—One character of the font
Draw a line of text0x2b090x2b09–0x2c2a52String in two colours

The places where the game calls each slot, with their arguments, are the same for both drivers: see game call sites.

Routines​

Copy a rectangle given in pixels​

AddressRangeSlot
0x05ca0x05ca–0x06227

Arguments: source x, y, destination x, y, width and height in pixels, source page, destination page. It turns the rectangle into 8-pixel columns and calls the rectangle copy. The source column is the source x / 8, the destination column the destination x / 8, and the number of columns covers the width plus the source's offset x mod 8. The destination's offset x mod 8 is dropped. A copy to a position fewer than 8 pixels away, in the same row and the same column, therefore copies the area onto itself. The VGA driver copies such rectangles pixel by pixel. The game's known calls scroll the street of the introduction, in display modes 3 and 6 only; mode 5 scrolls it with the page-area copy.

Used by: The introduction › Scroll the street

Convert an image page into video memory​

AddressRangeSlot
0x06230x0623–0x06ee10

Arguments: source page, destination page, and a far pointer that the driver ignores. It reads the byte page next to the source page, the source page with bit 0 set. It writes the even page of the destination, the destination page with bit 0 clear. For each of the 64,000 game pixels it looks up the pair table and sets the two screen pixels in the four planes (0x064b–0x06e5). It does nothing when the two pages have the same segment or when either segment is 0. The game uses it after loading a picture into a byte page, for example in the introduction's scene loader, and to store the level's coloured wall blocks in video memory (display modes). The VGA driver copies 64,000 bytes instead.

Used by: Display modes › The three modes, The introduction › Load a scene, Load a VCN file

Restore a saved rectangle​

AddressRangeSlot
0x06ef, 0x07070x06ef–0x0706, 0x0707–0x083e8, 9

Slot 8 writes into the current page, slot 9 into page 0; both continue in the same code at 0x0710. Arguments: column, y, width in columns, height, far pointer to a buffer written by save a rectangle. The rectangle is clipped to the page: the column goes to byte 79 at most, y to 0–199, the width to the end of the row and the height to the last row. A width or height of 0 or less writes nothing. The buffer holds the four planes one after the other, each width × 2 bytes per row. The routine returns the number of bytes it read.

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

Set the replacement colour table​

AddressRangeSlot
0x083f0x083f–0x087a11

Copies the 16 bytes at its far-pointer argument to 0x322b. It then builds 15 more copies after them, copy k with k × 16 added through a bitwise OR (0x085d–0x0870). Entry c of the 256-byte result is thus the table entry of c's low four bits, with c's high four bits added. The shape drawers of slots 15 and 38 read every colour through it. Encoding a shape overwrites this table (encoders), so it holds only until the next shape is cut. The VGA driver keeps only the 16 bytes.

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

Build a colour table​

AddressRangeSlot
0x087b0x087b–0x09ba12

The same routine as the VGA driver's build a colour table: from a palette, a destination, a colour c and a weight w, it builds the table that moves each colour towards c. The table becomes the current colour table at 0x312b and is copied to the destination. Its work variables are inside the routine, at 0x09a2–0x09ac. It returns the offset 0x312b with segment 0.

Anomaly

Slot 12 returns its table as a far pointer whose segment is 0 (0x09b3–0x09b8), while slot 47 returns the same table with the driver's own segment. The segment word, at 0x09b7, is one of the file's relocation items, which a loader fills with the driver's segment; the game loads the driver with a relocation factor of 0 (loading a driver), which leaves it 0. The VGA driver does the same (0x0741). No game call uses the returned value, so nothing follows from it in play. A reimplementation does not need to return anything from this slot. (ANOMALY-101)

Used by: Anomalies and bugs

Copy a rectangle between pages​

AddressRangeSlot
0x09bb0x09bb–0x0af413

Arguments: source column and y, destination column and y, width in columns, height, source page, destination page. It copies the rectangle between the two even pages through the card's latches, all four planes at once, row by row (0x0aa7–0x0ada). A negative position becomes 0, and a y of 200 or more copies nothing. The source rectangle is not checked against the bottom of the page. The game reaches this slot through its page-area copy, which keeps columns below 40 and widths up to 40. The pixel version calls it too.

Anomaly

Bug. The routine rejects a column of 80 or more and a width of more than 80, and only then doubles both into bytes (0x09cf–0x09fe, 0x0a29–0x0a3b). Rows are 80 bytes, so the limits belong to the doubled values. The rectangle restore and save routines of the same driver double first and then clip. Columns 40–79 and widths 41–80 are therefore accepted and run past the end of the row into the next rows. The game's only call path keeps both below these values, so the bug has no known effect in play. A faithful reimplementation treats such arguments as copying from and to the bytes that follow in video memory. (ANOMALY-102)

Anomaly

Bug. When the destination y plus the height exceeds 200, the height becomes 199 − y (0x0a44–0x0a59): one row fewer than fits, 0 when y is 199, and negative, copying nothing, when y is 200 or more (0x0a55–0x0a57). The row loop counts down before testing (0x0ad9), so a height of 0, given or produced, copies 65,536 rows: the offset wraps around the 64 KB segment of video memory, so the copy writes into all four planar pages, 0, 2, 4 and 6, the last two holding the level's wall blocks. On a page other than 0, whose segment starts above 0xa000, the wrapped offsets also pass the end of the card's 64 KB window at linear 0xb0000; what such a read leaves in the latches on real hardware is unknown. The VGA driver's slot 13 has the same clipping and the same row loop (0x07d4–0x07f9). None of the calls with fixed arguments, nor those that copy a text window, reaches it; whether window 8, whose height is 0, reaches the copy is unknown. A faithful reimplementation copies 199 − y rows when the rectangle crosses row 200, and treats a height of 0 as 65,536 rows. (ANOMALY-103)

Used by: Copy a page area, Anomalies and bugs

Clear the current page​

AddressRangeSlot
0x0af50x0af5–0x0b1414

Sets every pixel of the current page's even page to EGA colour 0 by writing 16,000 zero bytes in write mode 2. The byte page next to it is not cleared. The VGA driver fills 64,000 bytes of the page.

Used by: The introduction › Play the introduction

Draw a shape​

AddressRangeSlot
0x0b150x0b15–0x0ddd15 (and 18 through 0x10b5)

Arguments: page, far pointer to a shape, x and y in game pixels. The shape is drawn into the even page of the given page, at any x: each 8-pixel column of the shape covers two bytes of a row, shifted by x mod 8. Entered at 0x0b15 (slot 15), every colour goes through the replacement table. Entered at 0x0b21 from slot 18, a 16-colour shape is drawn through its own colour table: the routine copies that table over the first 16 bytes of the replacement table and puts the old bytes back at the end (0x0dbb–0x0dd0). Other shapes are drawn with their colours unchanged.

The shape is clipped to the shape window. The rows above it are read and skipped, and drawing stops at its bottom row or after the last row of the shape. A colour that has become 0 is not drawn (0x0c9f). When the level is not 0, the colour is replaced by its entry in the current colour table that many times (0x0ca6–0x0cb5). Then it is turned into its colour pair, and each pixel of the group is drawn as two screen pixels: left colour first, then right (0x0cca–0x0d88). The VGA driver's shape pixel writer applies the level in the same way.

Anomaly

Bug. When the whole shape lies above the top of the shape window, the routine leaves through 0x0be7 and skips the step that puts back the first 16 bytes of the replacement table. A 16-colour shape drawn through slot 18 then leaves its own colour table there. The mirrored drawer does the same (0x1af7). A later draw through slot 15 or 38 uses that table, unless the game sets the replacement table again first. The game's monster drawing sets it just before each such draw, so no visible effect is known (inferred). A faithful reimplementation leaves the shape's colour table as the first 16 entries of the replacement table after such a call. (ANOMALY-104)

Used by: Draw a shape in a window, Draw a monster shape, Wall decorations (DEC), Anomalies and bugs

Draw a line​

AddressRangeSlot
0x0dde0x0dde–0x10b417

Arguments: x1, y1, x2, y2 in game pixels, and a colour. 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 (0x0e49–0x0e76). The line is then drawn from the end with the smaller y, one pixel per step of the longer axis. One of four loops is chosen through the table at 0x10ab (0x0f30–0x108c). Each game pixel is drawn as its two screen pixels. The table at 0x0e79, the masks, deltas and colour pair at 0x10a1–0x10b4 belong to this routine.

Used by: Function list, Transfer: spells and items, Transferring a party from Eye of the Beholder I

Line clipping helpers​

AddressRangeSlot
0x0e99, 0x0e9b, 0x0ea5, 0x0eb9, 0x0ed2, 0x0edc, 0x0ef0, 0x0f050x0e99–0x0f2f—

Near routines of the line drawer:

AddressRole
0x0e99Point inside: returns with the carry clear
0x0e9bMoves the point onto the top edge
0x0ea5Moves the point onto the bottom edge, by negating the coordinates and using the top-edge computation
0x0eb9Computes where the line crosses a horizontal edge, by multiplying and dividing
0x0ed2Moves the point onto the left edge
0x0edcMoves the point onto the right edge, by negation
0x0ef0Computes where the line crosses a vertical edge
0x0f05Outcode 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 0x0e79, indexed by the outcode.

Used by: Draw a line

Draw a shape (slot 18)​

AddressRangeSlot
0x10b50x10b5–0x10bc18

Sets up the stack frame and jumps to 0x0b21 in the shape drawer. Shapes are drawn with their own colours, without the replacement table.

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

Empty slots​

AddressRangeSlot
0x10bd, 0x10be, 0x1491, 0x1492, 0x17d3, 0x17db, 0x17dc, 0x17dd, 0x17de, 0x1e5a, 0x243eone byte each19, 20, 24, 25, 30, 32, 33, 34, 35, 42, 50

Each is a single far return. The VGA driver's slots are empty too. The game calls slots 19, 20, 32–35 and 42, which therefore do nothing in either driver. 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
0x10bf0x10bf–0x10d321

Stores the low byte of its argument at 0x00dd and returns the previous value: the number of times the shape drawers pass each colour through the current colour table. The same routine as the VGA driver's set the shape level.

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

Fill a rectangle​

AddressRangeSlot
0x10d40x10d4–0x12c122

Arguments: x1, y1, x2, y2, both corners included, in game pixels, and a colour. A corner at x 320 or more or y 200 or more cancels the whole fill; negative values become 0, and the corners may come in either order. Each row is written as a left partial byte, full bytes and a right partial byte. The masks come from the tables at 0x1162–0x1175; the alternating masks 0xaa and 0x55 take the left and the right colour of the pair. The current colour table and level are not applied.

Anomaly

Bug. When both corners fall in the same 4-pixel group of a row (x1 / 4 = x2 / 4), the routine writes the byte twice, for the left and then the right screen pixels, in the left colour of the pair both times (0x1293); every other path writes the right colour there (0x11ef, 0x1213, 0x1249). The mask of the second write is built from the right corner alone (0x127a, ANOMALY-139), so only the last game pixel's right screen pixel is written. Such a fill shows the pair's left colour in the left screen pixel of each game pixel and keeps the old right pixel, except for the last game pixel, which is in the left colour twice; a one-pixel fill is in the left colour. That changes what is seen only for colours whose two halves differ (inferred: not observed in play). A faithful reimplementation draws such fills this way. (ANOMALY-105)

Anomaly

Bug. For the second write of a fill inside one 4-pixel group, the routine builds the right-pixel mask with the index still holding the right corner (0x127a, mov al, cs:[bx+0x1166]), whereas the first write reloads the left corner's index (0x1252–0x125a). The second mask therefore covers only the right screen pixel of the last game pixel instead of every game pixel from the left corner. A faithful reimplementation builds that mask from the right corner alone. (ANOMALY-139)

Used by: Function list, Transfer: spells and items, Transferring a party from Eye of the Beholder I, Anomalies and bugs

Page segment helpers​

AddressRangeSlot
0x12c2, 0x12dd, 0x12f5, 0x12fd0x12c2–0x130e—

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
0x12c2the current page with bit 0 set (its byte page)slots 27, 28
0x12ddthe current page with bit 0 clear (its even page)slots 14, 17, 22, 23, 36, the glyph drawer
0x12f5page AX with bit 0 setslot 10
0x12fdpage AX with bit 0 clearslots 8/9, 10, 13, 15/18, 26/44, 38/39

Used by: How the driver draws › Pages

Read a pixel​

AddressRangeSlot
0x130f0x130f–0x13ae23

Arguments: x, y. It returns 0 outside 320 × 200. Otherwise it reads the two screen pixels of (x, y) from the four planes of the current page's even page. It joins their EGA colours into a pair byte and returns the inverse pair table entry: the highest-numbered game colour that has this pair, or 0 if no colour has it. The colour read back can therefore differ from the colour written. Written again through write a pixel, it gives the same screen pixels whenever the pair belongs to a colour of the current palette, so the pixel dissolve copies such a picture exactly.

Used by: Pixel dissolve

Enable every bit​

AddressRangeSlot
0x13af0x13af–0x13c8—

Sets the graphics controller's bit mask to 0xff, leaving the bit-mask register selected. Called by prepare the card.

Used by: How the driver draws › Driver state

Install the driver's routines​

AddressRangeSlot
0x13c90x13c9–0x142e—

The address returned by the driver entry. It exchanges pointers with the game's driver function table as the VGA driver's install routine does (0x13e7–0x1412). It then calls the game routine of slot 6 with the far pointer to its display state at 0x00de. The game keeps that pointer at DS:0x6650 and passes it to save the display state.

Anomaly

Bug. The routine sets or clears the carry flag to report whether a slot stayed empty (0x1414, 0x1417), then makes the slot-6 call and removes its arguments with an addition (0x1422), which sets the carry again from the stack arithmetic. The game's loader tests the carry after the call, so it never sees a failure from this driver. A failure needs one of the game's slots 0–6 to be empty, since the driver fills every other slot, and the game's table has all seven set. The bug therefore has no effect with the original program. A reimplementation can treat this install as always successful. (ANOMALY-106)

Used by: Display drivers › Loading a driver, Anomalies and bugs

Prepare the card​

AddressRangeSlot
0x142f0x142f–0x1461—

Clears sequencer register 3, enables writing to all four planes, selects write mode 2 and enables every bit: the state the drawing routines count on. Called by the driver entry.

Used by: How the driver draws › Driver state

Driver entry​

AddressRangeSlot
0x14620x1462–0x1476—

Reached through the jump at image offset 0, which the game's loader calls first. It prepares the card and returns 0x353 in BX, the number of 16-byte paragraphs the driver needs with its run-time tables. It returns 0x13c9, the install routine, in AX. The VGA driver's entry returns the same two values without touching the card.

Used by: Display drivers › Loading a driver

Select write mode 2​

AddressRangeSlot
0x14770x1477–0x1490—

Sets the graphics mode register to write mode 2, in which a written byte gives the colour of every pixel enabled by the bit mask. Called at the end of the routines that change the mode (slots 8/9, 10, 13) and by prepare the card.

Used by: How the driver draws › Driver state

Save a rectangle​

AddressRangeSlot
0x1493, 0x21b90x1493–0x14aa, 0x21b9–0x229926, 44

Slot 26 reads the current page and slot 44 page 0; both continue in the same code at 0x21c2. Arguments: column, y, width in columns, height, far pointer to a buffer. The rectangle is clipped as in restore a saved rectangle. The routine copies plane 0, then planes 1, 2 and 3, each width × 2 bytes per row, into the buffer and returns the number of bytes written. That is 8 bytes per column and row, the same size as in the VGA driver, so the game's buffers fit both drivers.

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

Encode a shape​

AddressRangeSlot
0x14ab0x14ab–0x162027

The shape encoder. Arguments: column x, row y, width w in 8-pixel units and height h in pixels. It reads the byte page of the current page from offset 8x + 320y, 8w pixels per row for h rows. Like the VGA driver's encoder, it does not check the rectangle against the page. It makes two passes. The first gives each colour an index in order of first appearance, at most 16, and counts the bytes. The second writes the header 1, h, w, h, the 16-byte colour table (unused entries 0xff) and the groups of each column. The groups come in increasing colour order, colour 0 included. A colour beyond the sixteenth is coded with index 0. Between the passes it allocates the shape through the game's routine in slot 3 and returns it; the result is not tested.

The routine builds each column's colour masks in the memory of the replacement table at 0x322b, so cutting a shape replaces that table. Slot 28 does the same.

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

Encode a shape with 8-bit colours​

AddressRangeSlot
0x16210x1621–0x170528

Takes the same arguments as the encoder and makes the same two passes. The shape has the header 0, h, w, h and no colour table. Each group is 2 bytes, mask and colour, from colour 255 down to colour 0. The VGA driver's slot 28 also writes format 0, in its own coding.

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

Write colour pairs into video memory​

AddressRangeSlot
0x17060x1706–0x17d229

Arguments: far pointer to a buffer, a video-memory segment, a byte count. Starting at offset 0 of the segment, each buffer byte gives two screen pixels, its high four bits the left one, through the bit mask in write mode 2. Four buffer bytes fill one byte of the planes. The VGA driver's slot 29 does nothing. The game never calls slot 29: no instruction refers to its entry DS:0x6596 of the driver function table.

Used by: Function list

Return 0​

AddressRangeSlot
0x17d40x17d4–0x17da31

Returns 0 and ignores its argument. In the VGA driver this slot sets a flag read by its shape pixel writer and returns the previous one. The game calls it only in display mode 3, in the introduction's animations.

Used by: The introduction › Run an animation list

Write a pixel​

AddressRangeSlot
0x17df0x17df–0x185f36

Arguments: x, y, colour. Outside 320 × 200 it does nothing. Otherwise it writes the colour's pair into the two screen pixels of (x, y) on the current page's even page. The current colour table and level are not applied.

Used by: Pixel dissolve

Restore the display state​

AddressRangeSlot
0x18600x1860–0x1a2437

Undoes save the display state. It puts back the shape window and reads the byte at A000:FFFF to reload the card's latches. Then, for the map mask, the sequencer index, graphics registers 0–8 and the graphics index, it writes the saved value wherever it differs from the current one. The game calls it after drawing the mouse cursor.

Used by: How the driver draws › Driver state

Draw a mirrored shape​

AddressRangeSlot
0x1a25, 0x1d0f0x1a25–0x1d0e, 0x1d0f–0x1d1638, 39

The shape drawer flipped left to right: it draws the columns from the right end of the shape leftwards, and reverses each mask through the table at 0x012c (0x1b80). Slot 38 enters at 0x1a25 and draws through the replacement table. Slot 39 sets up its frame at 0x1d0f and enters at 0x1a31, drawing 16-colour shapes through their own table. Clipping, the level (0x1bd7–0x1be6) and the colour pairs work as in the unmirrored drawer, and so does the skipped table restore (0x1af7).

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

Save the display state​

AddressRangeSlot
0x1d170x1d17–0x1e5941

Argument: far pointer to a 16-byte display state. The game passes the one it received at install, the driver's own block at 0x00de. The routine saves the shape window and opens it to the whole page (columns 0–40, rows 0–200). It copies the 16 bytes into the saved state at 0x00ee, and also into the current state when the pointer is elsewhere. It sets the card to all planes, no rotation, read plane 0 and write mode 2. With the bit mask at 0 it writes a byte at A000:FFFF, which stores the latches there, and sets the bit mask back to 0xff. That byte lies outside the four pages and the stored wall blocks. The game calls this slot before drawing the mouse cursor and restores the state afterwards.

Used by: How the driver draws › Driver state

Scale a shape by one step​

AddressRangeSlot
0x1e5b0x1e5b–0x20b843

Makes the same selection as the VGA driver's scale step: rows whose index is 2 modulo 3 are dropped, and in each row every pixel whose index is 2 modulo 3. The 16-byte colour table is copied, and the blank colour is the first entry equal to 0. The height becomes h − ⌊h / 3⌋, equal to the VGA driver's. The width becomes 2 × ⌈w / 3⌉ columns (three source columns give two), one more than the VGA driver's when w is 1 modulo 3. It reads exactly h rows.

The driver's groups are collected per colour in the work area at 0x332b, through the mask table at 0x20b9. When a row ends with one or two source columns, the blank colour is set in the output pixels they do not cover (0x1ef6–0x1f10), so that every output column covers its 8 pixels. The source pointer is used as given (0x1e71–0x1e7d), with no null test.

Anomaly

The routine also accepts shapes without a colour table. For them it skips the blank-colour step (0x1eea–0x1eef): when w is not a multiple of 3, the last one or two output columns of each row do not cover all 8 pixels, or are empty, while the header still gives 2 × ⌈w / 3⌉ columns. The shape drawers read a column's groups until all 8 pixels are covered, so drawing such a reduced shape would take groups from the following row. Every shape the game reduces (items, flying objects, monsters and their decorations) is made by the 16-colour shape encoder, which writes a colour table; only the null monster shape of ANOMALY-88, read from the start of memory, could reach this case, depending on the computer. A faithful reimplementation does not need it. (ANOMALY-107)

Used by: Clipping, scaling and darkening › Scale steps, Doors, teleporters and temporary walls › Released shapes, Anomalies and bugs

Set the line rectangle​

AddressRangeSlot
0x229a0x229a–0x22c045

Stores its four arguments as the line rectangle: 2 × a, b, 2 × c, d as 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.

Anomaly

The routine doubles the two x bounds (0x229e–0x22b3), but the line drawer compares them with x in game pixels, and the initial bounds are in game pixels (319). The VGA driver's slot 45 stores the four values unchanged. Called with the page's bounds, this slot would let lines reach x = 638, beyond the right edge of the page. The game never calls it. A reimplementation of the game does not need the slot. (ANOMALY-108)

Used by: Function list, Anomalies and bugs

Set the shape window​

AddressRangeSlot
0x22c10x22c1–0x22e346

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

Match the palette to colour pairs​

AddressRangeSlot
0x22e40x22e4–0x23ca48

Arguments: far pointer to a palette, first colour, last colour. When the last colour is 16, the argument is a list of 16 EGA palette values instead. The routine writes them to the card's 16 palette registers, adding 8 to values above 7 to select the bright colours (0x2385–0x23be). The game does so with the identity list when it enters mode 5.

Otherwise the routine ignores the colour range and maps all 256 colours of the palette, 3 bytes each. It picks for each the nearest candidate pair, by the sum of squared differences, ties going to the lower pair byte (0x2303–0x2374). It then installs the result through install a pair table. The game's palette setting calls it with the level palette, an .EGA file in this mode, and colours 0 to 255. Setting one colour also recomputes all 256 pairs.

Used by: Display modes › The three modes, Palettes (PAL, EGA, COL)

Install a colour table​

AddressRangeSlot
0x23cb0x23cb–0x23f547

Copies 256 bytes from its argument into the current colour table at 0x312b and returns that table's far address; a null argument only returns it. The same as the VGA driver's install a colour table.

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

Install a pair table​

AddressRangeSlot
0x23f60x23f6–0x243d49

Copies 256 bytes from its argument into the pair table at 0x2f2b. It then rebuilds the inverse table at 0x302b: cleared, then for each colour from 0 to 255 the entry of its pair byte set to that colour. A pair shared by several colours thus gives back the highest one. It returns nothing. Match the palette calls it with its own result. The game calls slot 49 only in display mode 6, so this routine is not reached from the game.

Used by: Read a pixel

Size of a saved rectangle​

AddressRangeSlot
0x243f0x243f–0x247451

Arguments: width in columns, height. Returns 4 × 2w × h, with 2w limited to 1–80 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
0x285e0x285e–0x2b08—

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. It has the layout of the VGA driver's glyph drawer: glyph offset at 2 × (number + 1), height at 0x102, width at 0x103. A glyph whose x is 320 or more, whose y is 200 or more, or whose bottom passes row 200 is not drawn. Each glyph byte is spread to screen pixels, shifted to the position, and written in the foreground pair. When a background colour is set, the glyph's width is first filled with the background pair through the unshifted mask of the tables at 0x2486.

Anomaly

Bug. The right-edge test compares x plus the glyph width with 640 (0x2897–0x289c), while x is in game pixels: the routine tests x against 320 and takes x / 4 as the byte in the row. The VGA driver compares with 320. A glyph that starts before x = 320 and ends after it is drawn, and its right part lands at the start of the next row. The text routine moves to a new line at the right edge but draws the first glyph of a line without testing again, so a line that starts within one glyph width of the right edge reaches this case. A faithful reimplementation draws such a glyph and wraps its overflow to the left edge one row down. (ANOMALY-109)

Used by: Anomalies and bugs

Draw a line of text​

AddressRangeSlot
0x2b090x2b09–0x2c2a52

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, and an x of 320 or more or a y of 200 or more draws nothing. 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. Drawing stops at row 200. Every other byte is masked with 0x7f (0x2c0d) before the glyph drawer is called, as in the VGA driver's draw a line of text. The advance and the line height are the font's bytes 0x103 and 0x102. The string pointer is not checked: a null pointer makes the routine read from address 0000:0000 (0x2bc2).

Used by: Initial items (ITEM.DAT) › Who uses it, Transfer: spells and items, Transferring a party from Eye of the Beholder I

Sources​

The driver and its VGA counterpart are identified by their SHA-256 hashes in the file inventory. How the game loads the driver and the slot table are on the display drivers page, and the VGA driver's routines on the MGA.OVL page. The game's side of each call (page table, current page, palette setting, page-area copy, draw wrappers) is in the routines and data references.