Analysis model: gpt-5.5 xhigh, sol high Last edited: 2026-08-25

VectorDemo by Ultra Force - Technical Dissection

Scope

This covers VectorDemo by Ultra Force / UltraForce Development, released in October 1991 for MS-DOS. Pouet lists it as a DOS demo, and the archive examined here is the scene.org Hornet mirror copy of vectdemo.zip. The Hornet 1991 index rates the archive ****+, making it the strongest-ranked 1991 Hornet target in the current backfill queue.

The demo is interesting because it sits between two eras. The outer structure is still recognizably Turbo Pascal/Borland-style application code, with an installer shell, saved settings, menus, file names, and far calls. The fast parts are much closer to a hand-built demo engine: tweaked VGA pages, generated copy stubs, planar span writers, and a Sound Blaster DMA/IRQ path. The captured run looks like a simple sequence of logos, strips, scrollers, and shaded vector objects, but the executable underneath is already a fairly complete DOS demo framework.

Sources and artifact:

Hashes from the examined archive:

4202ff54b329e8296168c273661083c6185fd6ca11855bd512e7cb00dbe75da1  vectdemo.zip
11cda429044f680c5bd8b4991003d13da3f742a10163ed9207ac776f87b3c175  VECTDEMO.EXE packed
6b6c38cf4b5d93400c15821c48d64fb87207cf30ec45672412943feb89a1f2a5  VECTDEMO.EXE restored with UNP
e9028c04f008f02d99ad1577902e171d079fbd2bd600af4d5a5fffa6af9ffc96  VECT_000.U4C
8836aee8cf610716d973b27c05f048e4de7f80b292420b06d53440c534345889  VECT_001.U4C
5cb87995cc58a6e328c6cef3be19c433d1d1824e700ab6ec25cf0b1f622de08e  VECT_002.U4C
7939d8f9fad10bfdad7b559827f7f20f489e37c7d1a5b5868fd2a34083bacad0  VECT_003.U4C
7c48a75e9117c2d282f3fa79bb4a3244f209b9135023c56f7afe125f799030fe  VECT_004.U4C
72c7beb64935250b285818ee069ef92cf171c778038cf2e7656e498c36e4e836  VECT_005.U4C
2f911bdef064b8439a7b490e8a86f58c7cfd767422eb073e8f759e780e71c7e9  VECT_006.U4C
40856ede5abf8745c5d33e792ec8f06b7d78ba9a4819b46514db82df233587a2  VECT_007.U4C
b52ef98d357b66f7b05c0bd1391ab5c66f1b016bc15651b023f8008439f59513  VECT_008.U4C

The archive also contains an order form and an auxiliary TheDraw screen-save program with historical contact-era text. Those details are not reproduced here.

Archive Layout

The runtime is a packed EXE plus numbered .U4C resource files:

File Size Role
VECTDEMO.EXE 52,610 Packed main program, menu, VGA renderer, resource loader, Sound Blaster driver
VECT_000.U4C 24 Tiny install/config file marker and saved options
VECT_001.U4C 18,233 UltraForce VECTdemo resource payload
VECT_002.U4C 3,717 UltraForce VECTdemo resource payload
VECT_003.U4C 5,334 UltraForce VECTdemo resource payload
VECT_004.U4C 4,020 Text/screen payload; visible interleaved character/attribute data
VECT_005.U4C 789 UltraForce VECTdemo resource payload
VECT_006.U4C 10,423 UltraForce VECTdemo resource payload
VECT_007.U4C 574 Palette/coordinate-looking tables
VECT_008.U4C 143,626 JMUSIC file v1.1b, song AmnesiaQbass !!
DEMOSITE.COM 1,104 TheDraw COM screen-save helper
README.1ST 1,258 First-run notes
ORDER.FRM 1,846 Public-domain order list

The README says the demo wants an AT-class machine, VGA register compatibility, and optionally a Sound Blaster. It also explains the first-run installation step: the user chooses machine and sound settings, then the demo saves an install file so later runs can skip the menu. That saved marker is why the runtime capture below starts with a small setup detour instead of pretending the archive was already configured for a silent emulator run.

The restored executable contains its own runtime text. Safe technical facts from that text:

Runtime Capture

The seven older stills below come from a DOSBox-X 2026.01.02 capture made on 19 June 2026 with the internal mpegts-h264 recorder. A fresh verification run on 25 August 2026 used DOSBox-X 2024.03.01 and its ZMBV recorder. Both runs used a throwaway silent copy of VECT_000.U4C: its four option bytes after the UltraForce VECTdemo signature were changed from 01 01 01 02 to 01 00 00 00. The fresh run used machine=svga_s3, core=normal, cycles=auto, xms=true, ems=false, umb=false, nosound=true, sbtype=none, gus=false, speaker=false, and mididevice=none. No demo audio was loaded, auditioned, or published.

The fresh recorder split the launcher into a 720x400, 3.724-second stream and the main part into a 640x400, 130.525-second stream. Those private AVI files are analysis evidence, not site assets. The two new GIFs below are continuous, uncropped six-second pixel excerpts from the main stream, with the audio stream omitted. Their timestamps use the fresh main-part stream; the seven stills keep their older capture timestamps.

The run starts as an atmospheric logo intro, then establishes a persistent full-frame composition: the UltraForce masthead, dark blue gradient field, moving vector object, its lower reflected copy, and a bottom scroller. Calling that merely a "blue strip" understates how much of the frame remains stable while object-specific regions are repaired and replaced.

The sparse sequence below is built directly from the seven published 640x400 DOSBox-X frames. It is a part-overview GIF, not a fast motion clip: the value is seeing the logo intro give way to the strip/scroller section and then to the successive shaded vector objects discussed below.

VectorDemo sparse runtime sequence GIF showing logo intro and shaded vector object stages

At 00:06.000, the dusk/silhouette intro background is established:

VectorDemo runtime frame at 00:06.000 showing the dusk silhouette intro background

At 00:10.000, the red/yellow UltraForce logo has slid into the sunset scene:

VectorDemo runtime frame at 00:10.000 showing the UltraForce logo over the sunset background

At old-capture 00:26.000, two interlocked metallic forms occupy the object field, with a second inverted/reflected rendering below the bright horizon:

VectorDemo runtime frame at 00:26.000 showing two interlocked metallic forms and their lower reflection

At old-capture 00:36.000, a tower-like object stands on a checkerboard base, again with a lower reflected copy:

VectorDemo runtime frame at 00:36.000 showing a tower-like object on a checkerboard base and its reflection

At old-capture 00:48.000, a compact faceted metallic object replaces that larger construction:

VectorDemo runtime frame at 00:48.000 showing a compact faceted shaded object in the persistent logo and scroller stage

At old-capture 01:00.000, a larger shaded polyhedron dominates the frame and continues into the reflected region:

VectorDemo runtime frame at 01:00.000 showing a large shaded polyhedron

At old-capture 01:12.000, two blocky metallic objects share the field, with their lower copies cut by the scroller band. There is no defensible dotted trail in these pixels; the previous description was wrong:

VectorDemo runtime frame at 01:12.000 showing two blocky metallic objects and lower reflected copies

Fresh-stream 00:47..00:53 owns the renderer's metallic-gradient claim. The continuous excerpt shows a single faceted object rotating while it repeatedly grows toward the viewer and recedes. Bright and dark bands stay horizontal in screen space as different faces cross them; they do not rotate with the face. That is the visible fingerprint of the scanline-indexed stencil fill recovered below, not ordinary face-normal lighting:

VectorDemo continuous direct silent runtime excerpt showing a stencil-shaded polyhedron rotating and zooming

Fresh-stream 01:30..01:36 owns the separate vector-ball claim. Red shaded balls orbit the gold central object, pass over its silhouette, cross the logo and scroller regions, and continue off the frame edges. This is continuous motion, not seven unrelated stills or a reconstruction:

VectorDemo continuous direct silent runtime excerpt showing red vector balls orbiting a gold object

Restoring The Executable

The original EXE is an MZ file wrapped in an Ultra4C-style packer. That wrapper is only the first layer: before the menu, resources, and vector code make sense, the executable has to restore a conventional relocated body. The packed shape is:

packed size:       52,610 bytes
header size:           32 bytes
load image:        52,578 bytes
relocations:            0
entry:             CS:IP 0C8A:000E
stack:             SS:SP 2071:0080

The packed entry is not the demo. It is a small self-relocating depacker:

C8AE: std
C8AF: rep movsb          ; copy the depacker stub upward/backward
C8B1: retf               ; enter the moved copy
...
C91x: test bitstream
C92x: movsb              ; literal path
C94x: copy es:[bx+di]    ; backward-reference path
C98x: adjust ds/es       ; segment slide when output crosses a chunk boundary
C9Ax: patch relocation words after inflation

The useful point is that the executable body is not just compressed; the stub also recreates relocations and slides segments while expanding. UNP restores it to a normal MZ executable:

restored size:    134,528 bytes
header size:        3,184 bytes
load image:       131,344 bytes
relocations:          787
entry:             CS:IP 0000:0000
stack:             SS:SP 28BA:1770

The restored image has strong Turbo Pascal/Borland runtime fingerprints: Runtime error at, far-call-heavy procedure layout, stack-frame prologues, and string/data interleaving. The labels below are therefore behavioral labels from static analysis, not original symbols. That matters for readability: a lot of the high-level shape is real, but the exact original procedure names are not recoverable from this binary alone.

Startup Shape

The restored entry at load-image offset 00000h reads like an application startup path. It is a sequence of far calls into runtime initialization, menu setup, graphics setup, and resource code:

00000: lcall 1A8A:0000
00005: lcall 1A17:0000
0000A: lcall 19BF:03F0
0000F: lcall 1988:0353
00014: lcall 0E57:061F
00019: lcall 0E3A:01A7
0001E: lcall 0DBC:07CB
00023: lcall 0DBB:0000
00028: lcall 07BA:5F24
0002D: lcall 040F:3A46
00034: lcall 040F:32ED
00039: lcall 040F:0CCA

The fragment after the opening controller reads the BIOS timer at 40:006C and waits for a fixed tick delta:

00068: read 40:006C into [7778]
0008E: loop until current_ticks - [7778] >= 0085h

This is specifically the post-opening logo hold: 001C6h has already run the sunset/logo reveal, and the hold ends before the opening-to-vector palette bridge at load E227h. The 85h-tick limit is about 7.30 seconds, with a keyboard early-out. It is not the vector frame timer; later visual code uses retrace waits and CRTC start-address changes.

The local initializer at 001C6h is more interesting because it builds the VGA scratch environment:

001C6: push bp
001CE: les di,[bp+0A]       ; caller-supplied source block
001D8: compute segment -> cs:[055B]
001E6: les di,[bp+06]       ; second source block
001F0: compute segment -> cs:[055D]
00206: cli
00207: mov sp,0559h         ; temporary stack in code segment
0020A: mov ss,ax
0020E: call 08F5            ; load full DAC palette
00211: call 0567
00214: call 0CA4            ; set tweaked VGA addressing
00217: call 090F            ; image copy/packing pass
0021A: call 058F
0021D: call 092A            ; second image copy pass
00220: call 057E
00223: call 094A            ; planar expansion/mirroring pass
00226: call 08A0            ; palette fade/normalization
00229: call 09DA            ; scrolling/page routine
0022C: restore caller stack
00234: retf 8

001C6h therefore owns the opening only. The main stage is set up at D72Fh and dispatched by D57Dh; treating the opening's private-stack routine as the whole demo controller would merge two independently owned presentations.

Resource Naming And Install File

The executable has visible base names such as VECT_000.U4C, VECT_004.U4C, VECT_, and .U4C. The install reader starts at 4241h and builds a filename on the stack, opens it, and reads individual fields into runtime variables:

4241: sub sp,0080h
4247: xor ax,ax
4249: mov [9C05],ax
424C: lea di,[bp-80h]
4251: push cs:0123h         ; base filename string
4256: lcall 1A8A:18C6       ; string copy/constructor
4264: lcall 1A8A:18FD       ; append/normalize
4269: lcall 1A8A:026D       ; open/check file
426E: mov [9C05],ax
...
428D: lcall 1A8A:19E1       ; read 20 bytes to [3A6C]
42A4: lcall 1A8A:19E1       ; read 1 byte to [7AB6]
42BB: lcall 1A8A:19E1       ; read 1 byte to [778C]
42D2: lcall 1A8A:19E1       ; read 1 byte to [778D]
42E9: lcall 1A8A:19E1       ; read 1 byte to [777E]
42F3: lcall 1A8A:1975       ; close

The archive's VECT_000.U4C is only 24 bytes and begins with the common marker string plus a few option bytes. That makes it the saved-install marker, not a large art asset.

The numbered resource path at 433Dh has the same shape but uses a slightly larger local filename buffer. Later code around 73A2h contains the literal VECT_004.U4C; that part is entered from the menu/command-line path and loads screen text or setup resources before the main part runs.

JMUSIC Package Loader Core

The dispatcher at 18B36h belongs to the JMUSIC/package path reached for VECT_008.U4C. It is not the visual .U4C loader. It expects a runtime init flag, copies a Pascal-style length-prefixed filename to a temporary ASCIIZ buffer, opens it with DOS, calls a parser selected by an argument, and closes the handle. It is ordinary DOS file I/O wrapped around the music package parser.

18B36: push bp
18B42: cmp cs:[0657],1
18B4A: mov ax,1             ; not initialized
18B4F: mov ax,[bp+06]
18B52: cmp ax,4             ; parser index range
18B5C: lds si,[bp+08]
18B5F: mov cl,[si]          ; length byte
18B64: mov di,A4C4h
18B67: rep movsb            ; filename bytes
18B69: stosb                ; zero terminator
18B73: mov ax,3D00h
18B76: int 21h              ; open read-only
18B7F: mov cs:[B0F8],ax     ; DOS handle
18B83: call 18A17           ; clear loader tables
18B86: call 17E6A           ; memory/segment helper
18B93: call cs:[997F+bx]    ; selected parser
18BB1: mov ah,3Eh
18BB3: int 21h              ; close handle
18BC5: retf 6

The shared read helper is tiny and gets reused throughout the package parser:

191C2: mov dx,A676h
191C5: mov bx,cs:[B0F8]
191CA: mov ah,3Fh
191CC: int 21h              ; read CX bytes to CS:A676
191D0: or ax,ax
191D2: je short_read_error
191D4: ret

The parser around 19694h seeks into the package and detects a tracker-style M.K. marker:

19694: mov bx,cs:[B0F8]
19699: mov ax,4200h
1969C: xor cx,cx
1969F: mov dx,0438h
196A2: int 21h              ; seek to file offset 0438h
196A9: mov cx,4
196AC: mov dx,B120h
196AF: mov ah,3Fh
196B1: int 21h              ; read signature
196BA: cmp word cs:[B120],2E4Dh
196C3: cmp word cs:[B122],2E4Bh
196CC: mov word cs:[B173],001Fh

If that marker is not present, the entry count remains 000Fh; if it is present, the count changes to 001Fh. That is consistent with the large JMUSIC file being a music/sample container and not a normal graphics block.

Package Table Parser

The parser at 196E7h..19862h reads a table of asset records. The exact source labels are gone, but the record fields are clear enough from the code:

196E7: call 19694            ; set entry-count mode
196EA: mov cs:[A479],4
196F1: mov cs:[A47B],6
196F8: mov cs:[9DB5],FFFFh
196FF: mov cx,0014h
19702: mov dx,A493h
19705: call 191C5            ; read 20-byte package header
19708: mov cx,cs:[B173]      ; 0Fh or 1Fh entries
19710: mov bp,0002h
1971B: mov cx,001Eh
1971E: call 191C2            ; read 30-byte entry
19729: add di,0014h          ; empty entry slot
1972E: inc cs:[99B3]         ; non-empty entry count
19733: mov cx,0014h
19736: call 18BC8            ; copy entry name/string
19739: read big-endian fields from A68C/A68E/A690/A692
19744: store size/offset fields into 9Cxx/9Dxx tables
19783: next entry

Later it reads the payload index and expands per-item buffers:

197A2: mov cx,0080h
197A5: call 191C2            ; read 128-byte remap/index table
197AB: mov di,9DF9h
197B5: lodsb
197B6: cmp al,ah
197BA: mov ah,al             ; track max index
197BC: stosb
197BF: inc ah
197C1: mov cs:[9DF5],ah
...
19811: allocate 0400h-byte work chunk
19826: call 193DA            ; read object data
1982E: call 191E7            ; remap notes/indices
19831: call 19247            ; remap effect codes

The remappers are table-driven. 191E7h walks 256 four-byte records, searches a 37-entry period/frequency table at AD46h, and rewrites each record with a compact note/index form. 19247h maps effect nibbles: 0Fh, 0Ch, 0Dh, 0Bh, 01h, 02h, and 0Ah become internal codes; unknowns become zero.

This is a tracker/JMUSIC conversion pass, not a picture loader. That distinction fits the archive: VECT_008.U4C is the large JMUSIC file, while a different wrapper feeds the visual resources to 19880h.

Visual U4C Wrapper And Proven Destinations

The visual wrapper is 1988:016E, load-linear 199EEh. It constructs VECT_ plus a three-digit Pascal number and .U4C, opens the file, validates the 20-byte UltraForce VECTdemo signature, reads the mode byte at file offset 20, loads the remaining payload into the caller's source segment, installs the caller's 32-bit RNG seed at DS:C71E:C720, and invokes decoder 19880h. Modes above one are rejected.

Static decode with those exact call-site seeds gives these verified handoffs:

Resource Decoded bytes Destination / direct use
VECT_005 768 DS:7D60; main 256-entry RGB palette, patched before upload
VECT_001 22,083 segment DS:8F79; persistent main-stage image/background source
VECT_003 18,940 segment DS:9C0E; page/template data whose zero holes receive the generated gradient
VECT_002 8,500 A000:0000; additional prepared VGA strip/page source
VECT_006 25,142 segment DS:9C0E; parsed into font/sprite/shape atlas tables used by 8B22h
VECT_007 863 DS:7D60; first 768 bytes drive the opening-to-vector palette bridge

VECT_004 has mode byte 20h and belongs to install/menu checks; it is not passed to the confirmed visual decoder. This also bounds the model claim: polygon geometry is embedded in the EXE, while VECT_006 supplies the atlas consumed by point-marker rendering.

Payload Transform At 19880h

The most interesting loader inner loop is the transform at 19880h. It has two modes. In the first mode, each control byte is XORed with a pseudo-random byte, biased by -80h, and interpreted as a signed run token:

198A5: mov ax,0100h
198A8: push ax
198A9: lcall 1A8A:1162      ; pseudo-random byte in AX
198B3: push [bp+0A]          ; encoded source segment
198B4: mov di,[7AC2]         ; source cursor
198B9: mov al,es:[di]
198BC: xor ah,ah
198BE: xor ax,dx             ; undo random mask
198C0: sub ax,0080h          ; signed token centered at zero
198C3: mov [7ABB],ax
198C6: cmp [7ABB],0
198CB: jge fill_run

Negative tokens are literal copies from the encoded stream:

198CD: cmp [7ABB],FF81h      ; -127 terminates stream
198D4: mov byte [7ABD],1
198DB: source = input + [7AC2] + 1
198EC: dest   = output + [7AC0]
198F3: ax = -[7ABB]
198F9: lcall 19BF:0493      ; copy that many bytes
19901: sub [7AC0],[7ABB]     ; output += -token
19908: sub [7AC2],[7ABB]     ; source += -token

Positive tokens are fills. The byte after the token is the fill value:

1990E: dest = output + [7AC0]
19919: ax = [7ABB] + 2       ; run length
19923: read fill byte from input + [7AC2] + 1
19931: lcall 19BF:0556       ; memset(dest, fill_byte, length)
19939: ax = [7ABB] + 1
1993A: add [7AC0],ax         ; output cursor
1993E: inc [7AC2]            ; consume fill value
19942: inc [7AC2]            ; consume token
1994D: loop unless [7ABD] set

So the actual resource format here is a small RNG-keyed RLE stream:

for (;;) {
    token = (encoded[src] ^ rnd8()) - 0x80;
    if (token < 0) {
        if (token == -127) break;
        n = -token;
        copy(out + dst, encoded + src + 1, n);
        dst += n;
        src += n + 1;
    } else {
        n = token + 2;
        fill(out + dst, encoded[src + 1], n);
        dst += token + 1;
        src += 2;
    }
}

The dst += token + 1 in the fill case looks odd beside the token + 2 fill length. It matches the code. I am leaving that mismatch explicit rather than rounding it into a cleaner format description; either the called fill helper has one-less semantics, or this stream intentionally overlaps/reuses the last byte of a fill run.

The second mode is simpler. It uses the same pseudo-random byte stream, but only XORs a fixed-length input range into the destination:

19952: ax = [7C48] - 0015h   ; last index
19962: [7AC0] = ax           ; loop cursor
1996B: rnd = rand8()
1997A: al = input[[7AC0]]
19984: ax ^= rnd
1998B: output[base + [7AC0]] = al
19999: loop until cursor == last

The two modes explain why many .U4C payloads look neither plain RLE nor ordinary compressed data in a hex dump. The content is lightly transformed before the high-level parser sees it.

VGA Mode Setup

The graphics setup at DBBFh starts with BIOS mode 13h, then immediately tweaks the VGA away from plain BIOS defaults:

DBBF: push bp
DBC4: mov ax,0013h
DBC6: int 10h
DBC8: mov dx,03C4h
DBCB: mov al,04h
DBCD: out dx,al
DBCE: inc dx
DBCF: in al,dx
DBD0: and al,F7h
DBD2: or  al,04h
DBD4: out dx,al             ; sequencer memory mode
DBD5: mov dx,03CEh
DBD8: mov al,05h
DBDA: out dx,al
DBDC: in al,dx+1
DBDD: and al,EFh
DBDF: out dx+1,al           ; graphics mode
DBE1: mov al,06h
DBE5: in al,dx+1
DBE6: and al,FDh
DBE8: out dx+1,al           ; graphics misc
DBE9: mov dx,03C4h
DBEC: mov ax,0F02h
DBEF: out dx,ax             ; enable all map planes
DBF0: mov es,A000h
DBF9: mov cx,8000h
DBFD: rep stosw             ; clear 64 KiB
DBFF: tweak CRTC 14h/17h
DC16: retf

0CA4h repeats the same register family for local part setup:

0CA4: select sequencer index 04h
0CAB: read memory mode
0CAC: and al,F7h
0CAE: or  al,04h
0CB1: select graphics controller index 05h
0CB9: and al,EFh
0CBC: select graphics controller index 06h
0CC2: and al,FDh
0CC5: select CRTC index 14h
0CCD: and al,BFh
0CD1: select CRTC index 17h
0CD6: or  al,40h

The result is the classic early-1990s "tweaked VGA" style: still compatible with mode 13h entry, but with direct plane selection and byte-address control for fast page, span, and strip effects. The persistent logo/gradient/scroller stage in the capture is exactly the kind of scene that benefits from this: prepared regions can be repaired or copied while the vector object is drawn into the active page.

Palette Inner Loops

The full palette loader at 08F5h is straightforward and synchronized to vertical blank:

08F5: mov dx,03C8h
08F8: xor al,al
08FA: out dx,al             ; DAC index 0
08FB: mov cx,0300h
08FE: mov si,05A0h
0901: mov dx,03DAh
0904: in al,dx
0905: test al,08h
0907: je 0904h              ; wait vblank
0909: mov dx,03C9h
090C: rep outsb             ; 256 RGB triples
090E: ret

The fade/normalize routine at 08A0h first scans a 384-byte palette block, finds the maximum byte, subtracts that maximum from every byte, then increments the values back toward visible range while streaming DAC bytes:

08A0: mov cx,0180h
08A5: mov si,250Ah
08A8: lodsb
08A9: cmp al,ah
08AB: jb  08AEh
08AD: mov ah,al             ; AH = max channel
08B1: mov cx,0180h
08B4: mov si,250Ah
08B7: sub [si],ah           ; make channels negative/dim
08BB: inc si
08BC: loop 08B7h
08BE: mov dx,03C8h
08C1: mov al,10h
08C3: out dx,al             ; start at DAC entry 16
...
08E3: mov dx,03DAh
08E6: in al,dx
08E7: test al,08h
08E9: je 08E6h
08EB: mov dx,03C9h
08EE: rep outsb             ; stream 180h DAC bytes
08F0: dec bl
08F2: jne 08BEh

The non-obvious trick is that negative intermediate bytes are clamped into a temporary palette buffer. That gives a smooth "grow from black" palette ramp without multiplying every channel.

Generated Copy Stubs

The code at 0AC1h builds executable copy routines in one of the caller-owned source segments. This is not a normal decompressor: it emits 8086 opcodes into memory, saves far-call pointers to those emitted routines, and later calls them from the scroll/page code. It consumes exactly 0FF0h four-byte occupancy groups: 4,080 groups, 16,320 source bytes, or 51 rows of 320 pixels.

The token reader packs four nonzero source bytes into a nibble:

0B71: xor ah,ah
0B73: lodsb
0B74: or al,al
0B78: or ah,01h
0B7B: lodsb
0B7C: or al,al
0B80: or ah,02h
0B83: lodsb
0B84: or al,al
0B88: or ah,04h
0B8B: lodsb
0B8C: or al,al
0B90: or ah,08h
0B93: mov al,ah
0B95: ret

0A8Eh is the simpler static version of the same idea: read four source bytes, build a 4-bit occupancy mask, XOR it with BL, and store the result:

0A8E: cld
0A8F: shr cx,1
0A91: shr cx,1
0A93: xor ah,ah
0A95: lodsb
0A98: je  0A9Dh
0A9A: or ah,01h
0A9D: lodsb
0AA0: je  0AA5h
0AA2: or ah,02h
0AA5: lodsb
0AA8: je  0AADh
0AAA: or ah,04h
0AAD: lodsb
0AB0: je  0AB5h
0AB2: or ah,08h
0AB5: mov al,ah
0AB7: xor al,bl
0AB9: and al,0Fh
0ABB: stosb
0ABC: loop 0A93h
0ABE: ret

The code generator emits short instruction sequences depending on run length:

0B96: emit single-byte write sequence
      stores opcodes 078Ah, 24h, 26EEh, 43A4h

0BB6: emit nominal two-occupied-group sequence
      exact bytes need separate treatment below

0BE8: emit add/sub/adjust sequences for longer blank runs
      chooses 16-bit immediates when BH is nonzero, 8-bit otherwise

0C56: emit "inc di / inc si" style short skip

0C6B: close or pad generated routine when CX reaches zero

At the end, the generator writes a far return (CBh) and stores callable pointers:

0B4F: mov al,CBh
0B51: stosb
0B57: mov cs:[055F],0000h
0B5E: mov cs:[0561],es
0B63: mov cs:[0563],8000h
0B6A: mov cs:[0565],es

Every 80 groups the generator emits dec cx / jnz / retf, so runtime CX selects a row count. 09DAh drives that count through 1..50 and then 51 during a 196-step reveal: 8,721 generated-row executions in each of the two companions, with 196 retrace waits and surface handoffs. This belongs to the opening strip/stencil presentation, not the later polygon span loop.

One uncomfortable detail should not be normalized away. For two consecutive occupied groups, 0BB6h emits these exact main-routine bytes:

8B 07 25 lo hi 26 EE A4 88 A4 EE E0 A4 26 EB 01

On an 8086 the middle decodes into a malformed-looking sequence including mov [si-1F12h],ah, not a clean second mov al,ah / out dx,al. The companion gets two ordinary movsb bytes. Static evidence cannot decide whether the actual mask stream avoids this emitter or whether it is a genuine generator defect, so the article records the bytes rather than inventing idealized pseudocode.

The broad optimization is still clear: instead of interpreting occupancy masks for every row, the demo compiles them once into callable pointer-adjust and copy code.

Image Decode And Plane Packing

0CDAh is a plain RLE image decoder:

0CDA: cld
0CDB: lodsw
0CDC: mov dx,0140h
0CDF: mul dx               ; AX = row_count_or_height * 320
0CE1: mov cx,ax            ; output byte budget
0CE3: lodsb
0CE4: cmp al,C0h
0CE6: ja  run
0CE8: stosb                ; literal byte
0CE9: loop 0CE3h
0CEB: ret
0CEC: and al,3Fh           ; run length in low 6 bits
0CEF: mov cl,al
0CF5: lodsb                ; repeated value
0CF6: rep stosb
0CF9: sub outer_count,run_length
0CFD: jae 0CE3h
0CFF: ret

The plane-packing helper at 0C8Fh is stranger. It sets the sequencer map-mask register and then copies bytes while allowing DI to advance only once per four source bytes:

0C8F: cld
0C90: mov dx,03C4h
0C93: mov al,02h
0C95: out dx,al
0C96: inc dx
0C97: mov al,11h
0C99: out dx,al
0C9A: movsb
0C9B: rol al,1
0C9D: cmc
0C9E: sbb di,0
0CA1: loop 0C99h
0CA3: ret

Because movsb increments DI and the cmc/sbb di,0 cancels that increment on three of the four rotations of 11h, this is a fast one-in-four packing pass. It is used by:

090F: copy/decode 0FA00h bytes from cs:[055B] to A000:0000 via 0C8F
092A: copy/decode 03FC0h bytes from cs:[055D] to A000:BB80 via 0C8F

094Ah performs a related but more direct planar expansion. It selects A000h, cycles a plane mask, skips zero source bytes, writes nonzero bytes to VRAM, then uses graphics-controller mode bits and rep movsb to duplicate large screen ranges to A000:3E80 and A000:7D00. That is the static setup for the later mirrored/strip effects.

Address Convention For The Object Core

The restored file has a 0C70h-byte MZ header. Code labels such as AC0Eh, CC28h, and D28Eh below are linear offsets in the MZ load image, matching the convention used above. Runtime startup at load offset 1A8A0h establishes DS = load_segment + 1C45h, so an array such as DS:475A is not file/load offset 475Ah; initialized DS:x bytes live at load offset 1C450h+x, while later arrays can be BSS with no file bytes at all. Keeping those address spaces separate prevents a plausible-looking but wrong linear disassembly.

Embedded Polygon Models

Selections 0 through 11 are compiled into the executable's initialized DS image. They are not model payloads fetched from a numbered .U4C file. The constructor at load 99A5h copies selection-specific source blocks into one common working layout:

struct Vertex4 {              // DS:13B5 + 4*i
    uint8_t tag;              // preserved; recovered core never reads it
    int8_t x, y, z;           // DS:13B6/13B7/13B8 + 4*i
};

struct Face4 {                // DS:155D + 4*f
    uint8_t v0, v1, v2, v3;  // winding-order point indices
};

uint8_t base_color[f];        // DS:4686
uint8_t shade_phase[f];       // DS:46F0
int16_t point_max;            // DS:4680, inclusive
int16_t face_max;             // DS:4682, inclusive
int16_t far_limit, near_limit;// DS:467C, DS:467E

Every face occupies four bytes. A triangular face repeats one index in that fourth slot; it still enters the quad splitter, while culling uses only v0..v2. The recovered selection ledger is:

Selection Active points Active faces Near..far Construction note
0 80 72 170..600 explicit vertex, face, and 72-byte color blocks
1 8 6 130..600 cube-sized model; constant 80h color fill
2 74 42 185..650 articulated subrange; one-time generated colors
3 42 20 170..500 constant 80h color fill
4 36 + 16 dynamic 24 150..400 polygon body plus marker tail
5 24 18 140..800 constant 60h color fill
6 20 18 150..800 repeated indices encode triangles
7 52 53 118..400 explicit 53-byte color block
8 24 24 100..600 generated fill/ramp colors
9 25 35 80..600 randomized colors
10 20 12 150..600 explicit colors; constructor shifts Y by 20
11 48 7 140..600 18 polygon points plus 30 marker points

Selection 2 copies storage large enough for 80 points and 72 faces but activates only 74 and 42; the tail is dormant capacity. Its constructor at 96A4h cross-products and normalizes each face's first three source vertices, then writes a base palette byte once. That is preprocessing, not per-frame normal lighting. Selection 2 later rotates points 32..48 with an additional Y phase.

Q8 Rotation And Projection

The live state uses byte angles: 256 units per turn, or 1.40625 degrees per unit. DS:1920 is a signed-word sine table and DS:1B20 cosine, both with amplitude 256. Angular speeds at DS:4990..4992 normally stay within -9..9; the signed zoom rate at DS:4989 stays within -16..16 and is constrained by the selected model's near/far limits.

AC0Eh transforms polygon points, while C15Fh performs the same core on the procedural structure-of-arrays path. With hi(p) meaning the signed high byte of a 16-bit Q8 product, their arithmetic normalizes to:

x1 = hi(x*Cy - z*Sy);
z1 = hi(x*Sy + z*Cy);

neg_y2 = hi((-y)*Cx - z1*Sx);
depth  = hi(z1*Cx - y*Sx) + camera_distance;

num_x_q8 = x1*Cz - neg_y2*Sz;
num_y_q8 = x1*Sz + neg_y2*Cz;
num_x = signed_shift_right(num_x_q8, 1);
num_y = signed_shift_right(num_y_q8, 1);

screen_x[i] = DS:7775 + idiv(num_x,depth); // DS:475A + 2*i
screen_y[i] = DS:7777 + idiv(num_y,depth); // DS:482E + 2*i

The final Z-rotation products remain Q8 until the one-bit shift, giving an effective focal factor near 256/2 = 128. Signed IDIV truncates toward zero. There is no near-plane clip and no divide-by-zero guard: object limits and signed-byte coordinate extents keep the authored geometry in front of the camera. DS:776E records the minimum projected screen Y for repair logic; it is not a nearest-depth value.

The hot loop is also countable rather than merely describable. Every point, polygon or procedural, executes 12 signed IMULs: four for each of the three axis stages. The two final Q8 numerators each pass through the one-bit signed shift helper and then one signed perspective IDIV, so an N-point object costs exactly 12*N multiplies and 2*N divides before culling or stamping. The transform begins by clearing 512 depth-count words (1,024 bytes), then inserts every projected point into the eight-entry depth buckets described below. Selection 24's phase-shifted first 15 points take an alternate Y-angle lookup, but not a different arithmetic workload.

Painter Ordering And Backface Test

This engine does not sort faces by centroid or average depth. Transform setup clears depth counts for keys 1..1024. Each projected point enters a bucket with eight available entries; if its exact depth key is full, it moves to the first later key with room. A229h separately builds up to seven incident face bytes at DS:6E07 + vertex*8.

The generic painter walks point-depth keys from far to near, follows each point's face adjacency, and emits a face only while DS:699D[face] still marks it undrawn. A face is therefore normally triggered by its farthest incident vertex. Crowded keys can shift that trigger slightly farther. Selection 1 instead draws surviving faces in ascending index order; selections 2, 3, 4, 7, 10, and 11 have specialized range/hybrid dispatchers.

B1A8h performs backface culling after projection from the first three face vertices:

area = (x0-x1)*(y2-y1) - (y0-y1)*(x2-x1);
visible[face] = (area < 0);

Zero-area faces disappear. This is a 2-D screen-space winding test, not a 3-D normal test. Selection 4 bypasses it and initializes every face visible. The adjacency builder itself has no overflow check, another reason the built-in model bounds matter.

Procedural Points And The Vector Balls

Selections 12 through 24 take a distinct path. Their constructor writes structure-of-arrays point data, not polygon faces:

DS:71CF  inclusive point maximum
DS:71D1  marker size index[i], clamped to 1..10 by 8B22h
DS:723B  marker color/atlas bank[i]
DS:72A5  signed coordinate 0[i]
DS:730F  signed coordinate 1[i]
DS:7379  signed coordinate 2[i]

The call convention closes an earlier ambiguity in those two byte arrays: D28Eh pushes 71D1[i] as 8B22h's size argument and 723B[i] as its atlas bank. 8B22h clamps only the former, uses the latter in a 128-byte-stride atlas lookup, and selects one of four prebuilt masks from the marker's post-anchor horizontal alignment phase.

The 13 constructor results and their maximum per-frame transform work are:

Selection Points Size-index distribution IMUL IDIV Addressed stamp cells if all accepted
12 64 5:64 768 128 4,800
13 64 5:64 768 128 4,800
14 38 3:4, 5:2, 7:18, 8:4, 9:6, 10:4 456 76 1,630..1,784
15 41 3:4, 5:4, 7:18, 8:4, 9:7, 10:4 492 82 1,794..1,955
16 38 1:2, 2:1, 3:4, 5:3, 6:16, 8:4, 9:5, 10:3 456 76 2,190..2,591
17 64 5:64 768 128 4,800
18 16 4:16 192 32 1,632
19 8 1:8 96 16 1,288..1,472
20 64 6:64 768 128 3,328..4,160
21 41 7:41 492 82 1,804
22 66 5:66 792 132 4,950
23 27 1:27 324 54 4,347..4,968
24, detail 0/1/full 76 / 81 / 105 6:55, 7:2, 8:17, 9:2/7/31 912 / 972 / 1,260 152 / 162 / 210 3,435..4,317 / 3,505..4,422 / 3,841..4,926

Selection 22 is no longer an algebraic 3*N: the executable's 7x7 source mask has 22 occupied cells, so its three layers produce exactly 66 points. Selection 24 constructs all 105 typed records first, then changes the inclusive maximum to 75 or 80 at the two reduced detail levels. The table's stamp-cell ranges are caused only by that four-way horizontal alignment; clipping can reduce the number of stamps actually submitted.

The atlas builder makes the size index's inverse footprint explicit:

Size index Height Addressed bytes per row for alignment 0,1,2,3 Addressed cells per stamp
1 23 7, 7, 8, 8 161..184
2 21 7, 7, 7, 7 147
3 19 6, 6, 7, 7 114..133
4 17 6, 6, 6, 6 102
5 15 5, 5, 5, 5 75
6 13 4, 4, 5, 5 52..65
7 11 4, 4, 4, 4 44
8 9 3, 3, 3, 4 27..36
9 7 2, 3, 3, 3 14..21
10 5 2, 2, 2, 2 10

Thus a lower index means a larger marker. C15Fh rotates and projects every point whether or not it will survive screen clipping. D28Eh then traverses the depth buckets from far to near and makes at most one 8B22h call per accepted point; it never enters the polygon triangle/span path.

That makes the red balls in the continuous 01:30..01:36 excerpt precise: they are 3-D point-cloud coordinates transformed by the same Q8 camera, then stamped as shaded/masked 2-D marker tiles. They are not tiny tessellated spheres entering the quad rasterizer. Each stamp's mask byte is written to 03C5h before the corresponding VRAM byte, so the exact pixel cost is the sum of mask popcounts, not simply rectangle width times height times four.

The point path rejects centers outside 10 <= x <= 309 or y >= 180. A point above the local top boundary is anchored at that boundary rather than pixel-clipped; the low-level marker writer has no clip of its own. Selection 4 uses a polygon-plus-16-marker hybrid, and selection 11 a polygon-plus-30-marker hybrid, explaining how some stages combine filled objects with orbiting or attached marker forms without pretending both use the same primitive.

Why The Metallic Bands Stay Horizontal

DS:46F0 is a per-face phase into the scanline shade table, not a conventional lighting mode. The shaded quad path 7EFBh splits a face into (v0,v1,v2) and (v2,v0,v3). For every accepted scanline y, 7D52h asks the span writer for:

color = DS:378E[y + shade_phase[face]] + base_color[face];

A zero phase selects a vertex-Y-derived fallback. Thus geometry masks a global screen-Y gradient. The direct zoom GIF shows the consequence: dark and bright bands remain horizontal while faces rotate through them. “Metal shading” is a useful visual description, but a normal-based light rotating over each face would be the wrong algorithm.

Page Flips And Strip Copies

The relevant initialized tables make the memory geometry explicit:

DS:1778 words  0000,0050,00A0,...       line_offset[y] = 80*y
DS:1908 words  0000,4000,8000,C000      page byte offsets
DS:1910 bytes  00,40,80,C0               CRTC start high bytes
DS:1914 words  A000,A400,A800,AC00       equivalent CPU segments

One logical page is 4000h addressed bytes. A 320x200 planar picture uses 80*200 = 3E80h, leaving 0180h bytes of padding. The vector parts alternate pages zero and one; setup paths can also address pages two and three.

The presenting procedure begins at 7BA0h; 7B99h..7B9Fh are seven zero data bytes. Its argument identifies the page just rendered:

7BA8: bl = [1910 + completed_page] ; CRTC high start byte
7BB1: ax = [9C07] + 1
7BB4: and ax,1
7BB7: mov [9C07],ax
7BBB: di = ax * 2
7BC1: ax = [1914+di]
7BC5: mov [777A],ax          ; active page segment/base
7BC8: wait until 03DAh bit 3 is low
7BD0: write CRTC index 0Ch   ; low start byte remains zero
7BD9: wait until bit 3 becomes high
7BE4: ret 2

The handoff is one frame behind the state name: repair and draw into back page p, call 7BA0(p) to expose it, and return with [777A] and [9C07] already selecting 1-p for the next frame. There is one such handoff per completed frame in both recovered object loops. 7BE7h is a separate non-presenting selector; it changes the CPU page without touching the CRTC.

The visible update routines around 8776h..8B21h do not redraw the whole screen. They copy strips inside A000h, fill prepared bands, and repair the current page around the objects.

8776h copies descending strips from an off-screen area into the current page:

877C: set GC mode 05h = 41h
8786: set sequencer map mask = 0Fh
878A: next_page = ([9C07] + 1) & 1
8795: dest_base = [1908 + next_page*2]
87A2: for row_block = 1..34h:
87B3:     src = [1778 + (34h-row_block)*2] + C000h
87BD:     len = [1778 + row_block*2]
87CB:     es = ds = A000h
87D8:     rep movsb
87E5: copy 1040h bytes from A000:C000h to page base
8818: [7770 + page*2] = 0
881C: restore GC mode 05h = 40h

8860h is the inverse/alternate direction. It starts with a fixed copy from A000:E300h, then loops over the same 1778h row-offset table and copies small 80-byte pieces:

8886: src = E300h
888E: dst = page_base + 1040h
8894: len = 0140h
88AA: rep movsb
88AD: for row_block = 1..34h:
88B9:     src = page_base + 0050h
88C2:     dst = page_base
88D3:     len = [1778 + (34h-row_block)*2]
88DB:     rep movsb
88F9:     src = [1778 + (34h-row_block)*2] + D2C0h
8912:     dst = page_base + [1778 + (34h-row_block)*2]
8918:     len = 0050h
892E:     rep movsb

895Ch is specifically the pre-draw old-page repair, not a generic clear. It chooses row 56 when [7133]=FFh and row 52 when [7133]=33h, then rebuilds the full 320-pixel width through row 161 from the word table at [777F]:

897A: start_y = ([7133] == FFh) ? 38h : 34h
8992: lds si,[777F]
8996: es = [777A]
899B: di = [1778 + start_y*2]
89AD: repeat (162-start_y) rows:
89B0:     rep stosw with CX=0028h
89B5: set GC mode 05h = 41h
89D0: if growing strip active:
8A12:     rep movsb from A000:C000+offset to page+offset
8A25: copy A000:E580h -> page+32A0h, length 0280h ; rows 162..169
8A53: restore GC mode 05h = 40h

The fixed full-width repair costs are exact: 8,480 addressed bytes (33,920 pixel/plane writes) in the row-56 mode or 8,800 addressed bytes (35,200 pixel/plane writes) in the row-52 mode. Every call then restores the eight-row footer with 640 VRAM reads and 640 addressed writes. In the row-56 transition mode it can additionally restore rows n..55 from an off-screen template, costing 80*(56-n) reads and the same number of addressed writes.

8A5Eh has different ownership and timing. It runs after object drawing and immediately before 7BA0h, reconstructing exactly 30 lower-stage rows:

destination rows: 169..198
base source rows:  169,167,165,...,111
transfer per call: 30 * 80 = 2,400 addressed bytes
cost per call:     2,400 VRAM reads + 2,400 addressed writes
                  = 9,600 plane-byte writes

An animation phase can move the source selection back one extra row for a six-row window, but cannot alter the transfer count. The first row is a self-copy, so object scanline 169 survives. Thus 895Ch erases the previous object before rendering; 8A5Eh repairs the patterned lower stage after it. They are not interchangeable cleanup routines.

These routines are tuned around 80-byte scanline chunks, the 1778h line-offset table, and the current page base. Much of the persistent frame is being repaired and reused rather than redrawn from source assets every time.

Edge Tables And Filled Polygons

7C08h and 7CADh build per-scanline edge tables. They are almost identical; one writes to the far pointer at [3D9C], the other writes to [3DA0].

The earlier article had the axes reversed. The destination is indexed by Y and each record is an interpolated X. In normalized form the caller supplies edge(table, y1, x1, y0, x0) with y1 >= y0:

7C08: les di,[3D9C]
7C10: di += y0 * 2
7C16: bx = y1 - y0           ; number of scanline steps
7C1C: if bx == 0:
7C1E:     ax = max(x0,x1)
7C29:     goto store_last
7C30: [3DA6] = bx            ; denominator/error reset
7C34: cx = 0
7C36: dx = 1                 ; signed step
7C39: ax = x0 - x1
7C41: if ax < 0:
7C43:     cx = 1 - bx
7C48:     dx = -1
7C4A:     ax = -ax
7C4C: [3DA4] = dx
7C50: cmp ax,bx
7C56: if ax > bx:
7C58:     dx:ax / bx         ; integer X slope per Y
7C5A:     si = quotient
7C66:     ax = y1
7C69:     stosw
7C6A:     ax += si
7C6C:     cx += dx_remainder
7C70:     if cx > 0:
7C70:         ax += [3DA4]
7C74:         cx -= [3DA6]
7C78:     loop

The special cases avoid division when possible:

7C7D: vertical/equal-x case
      rep stosw with same X

7C86: equal-|dx|/dy case
      store, add signed 1 each step

7C91: |dx| < dy case
      Bresenham-style error accumulation without quotient slope

An edge of height H=y1-y0 writes exactly H+1 16-bit X records. The walkers do not clip: a bad negative or overly large projected Y indexes outside the tables before the later span-stage clip can help. Scene/projection limits are therefore part of memory safety, not just appearance.

That edge table feeds the shaded triangle function at 7D52h. It sorts three (Y,X) pairs, writes the long edge first, and rejects a collinear triangle if the middle X equals the long-edge X at the middle Y. Otherwise it writes both short edges, clamps only the span range, and passes two X records plus a color to 0DBC:009F:

7D52: sort three vertices by Y
7DD0: call 7CAD              ; one edge side
7DFD: call 7C08              ; edge A
7E0C: call 7C08              ; edge B
7E1B: top = max(ymin,(int8)[7133])
7E2B: bottom = min(ymax,00A9h)
7E37: [777C] = [1778 + (y_end+1)*2]
7E63: for y = top+1..bottom: ; top-exclusive, bottom-inclusive
7E7F:     push [43A8 + y*2]  ; edge table 1
7E88:     push [3FA8 + y*2]  ; edge table 2
7E94:     color = [378E + y + caller_bias] + caller_color
7E9E:     lcall 0DBC:009F

The active [7133] values are FFh (signed -1, allowing row 0) and 33h (allowing row 52 onward); the hard bottom is row 169. There is no horizontal clip. The exact accepted span count is:

S = max(0, min(ymax,169) - max(ymin,(int8)[7133]))

The branch at 7EADh swaps edge-table arguments according to orientation; it does not repair reversed or off-screen X values. A non-collinear un-clipped triangle of height H writes H+1 words on its long edge and H+2 across both short edges: 2H+3 edge words total. 7EFBh splits one shaded quad into two such triangles. 7F78h and 8105h are the flat-color triangle and quad counterparts with the same edge and clipping rules.

Planar Span Writer

The far procedure at 0DBC:009F, linear offset DC5Fh, draws horizontal spans in the tweaked VGA layout. Normalized, it receives span(x1,x0,color) and covers the half-open interval [x0,x1). It has two paths: wide spans and tiny spans.

For wide spans, it writes a left partial byte, a middle word-filled region, and a right partial byte:

DC65: ax = x1 - x0
DC6B: [bp-4] = width
DC6E: cmp width,7
DC74: color in BL/BH
DC79: es = [777A]           ; current page segment/base
DC7E: ax = [777C]           ; current row offset
DC81: cx = x0
DC86: di = x0 / 4 + rowoff
DC8C: cx &= 3               ; starting plane
DC92: dx = 03C5h            ; sequencer data port for map mask
DC95: cl = 4 - start_plane
DC9A: al = F0h >> cl
DC9E: out dx,al             ; left mask
DCA1: es:[di] = color
DCA2: inc di
DCA3: out dx,0Fh            ; all planes for middle
DCA6: ax = color duplicated
DCAB: cx = (width + start_plane) / 4
DCB6: rep stosw
DCBA: optional stosb
DCC0: cl = (width + start_plane) & 3
DCC5: al = F0h rol cl
DCC9: out dx,al             ; right mask
DCCA: es:[di] = color
DD18: [777C] += 0050h       ; next scanline offset

For tiny spans, it accumulates a bit mask one pixel at a time and emits only when the mask crosses a byte boundary:

DCD5: dx = 03C5h
DCDD: di = x0 / 4 + rowoff
DCE9: al = 0
DCEE: cl = x0 & 3
DCF1: bl = 1 << cl
DCF5: al |= bl
DCFA: si = width
DCFD: bl <<= 1
DCFF: if bl == 10h:
DD04:     out dx,al
DD09:     es:[di] = color
DD0C:     inc di
DD0D: al |= bl
DD0F: dec si
DD10: loop
DD14: out dx,al
DD15: es:[di] = color

For a valid width w=x1-x0, the exact addressed-byte count is:

B = ceil(((x0 & 3) + w) / 4)

The pixel/plane write count is exactly w. Tiny spans use B byte-store instructions and B map-mask port writes. Wide spans use one left-mask write, one all-plane write, and a third right-mask write only when the endpoint is not address-aligned. Width zero changes no pixels but still advances the row offset by 80. Negative widths are misread as large unsigned widths; there is no defensive reversal.

This is the classic planar span trick: one addressed VRAM byte represents four screen pixels and the map mask chooses which planes change. For a triangle, the traffic is therefore computable directly from its edge records:

addressed VRAM writes = sum_y ceil(((left[y]&3)+width[y])/4)
pixel/plane writes    = sum_y width[y]
edge-table reads      = 2*S words
shade-table reads     = S bytes for the shaded path

The filled objects are not chunky mode-13h polygons.

Text And Small Sprite Primitives

Several 0DBC routines are small low-level helpers that the Pascal-side code can far-call:

DC17: set GC mode 05h = 41h and map mask 0Fh
DC2C: restore GC mode 05h = 40h
DC3A: copy A000:[src] -> A000:[dst], length CX, bracketed by DC17/DC2C
DD23: fill 200 rows from [777F] to active page with 40 words per row
DD4B: select one VGA plane from caller argument
DD5F: copy one plane from source segment into active page, stepping source by 4
DDB2: rectangular A000-to-A000 copy, 80-byte row pitch
DDE7: masked rectangular copy; per-byte mask data is written to 03C5h
DE2D: read a pixel through GC read-map select and replace matching colors

DDE7h is worth spelling out because it is the small masked sprite/tile path:

DDF7: es = A000h
DDFF: dx = 03C4h
DE02: select sequencer index 02h
DE06: bx = 0                ; mask cursor
DE08: si = source offset
DE0B: ds = source segment
DE10: cx = width
DE13: al = [bx]             ; next mask byte
DE15: out 03C5h,al          ; choose planes to affect
DE16: al = es:[si]          ; source byte
DE19: stosb                 ; write through mask
DE1A: inc si
DE1B: inc bx
DE1C: loop
DE1E: di += row_skip
DE21: dec height
DE24: loop rows

Again, the byte stored to VRAM is only half the story. The preceding write to 03C5h controls which planar pixels in that byte are modified. For a marker with W addressed bytes per row and height H, the nested loop executes exactly W*H mask reads, W*H writes to 03C5h, W*H VRAM source reads, and W*H addressed VRAM destination writes. Its actual plane-pixel writes are sum(popcount(mask_byte)), bounded by 0..4*W*H. DDE7h performs no clipping or transparent-run skipping of its own.

Sound Blaster And CT-VOICE Path

The sound code is a compact Sound Blaster DSP/DMA driver. It has helper routines for DSP reads/writes, reset/detection, DMA programming, IRQ vector installation, and auto-init style chunk scheduling.

EC07h writes a DSP command byte by waiting for the write port to become ready:

EC07: mov ah,al
EC09: mov al,F0h
EC0B: in al,dx              ; DSP write status, base+0Ch
EC0C: or al,al
EC0E: js EC0Bh              ; wait while bit 7 set
EC10: mov al,ah
EC12: out dx,al
EC13: ret

EC14h reads a byte by waiting for read-ready at base+0Eh, then reading from base+0Ah:

EC14: push dx
EC15: mov dx,cs:[063F]
EC1A: add dl,0Eh
EC1F: in al,dx
EC20: or al,al
EC22: jns EC1Fh
EC24: sub dl,04h
EC27: in al,dx
EC28: pop dx
EC29: ret

DSP reset/detection at EC2Ah pulses base+6, waits for AAh, then sends a small echo-style probe:

EC2A: dx = [063F] + 6
EC32: out dx,1
EC35: in dx four times
EC39: out dx,0
EC3C: retry 10h times:
EC3E:     call read_dsp
EC41:     cmp al,AAh
EC4B: send E0h
EC5A: send AAh
EC61: read response
EC66: cmp al,55h

The DMA programmer at ED55h is for the 8-bit DMA channel used by early Sound Blasters:

ED55: push bx
ED58: mov al,05h
ED5A: out 0Ah,al            ; mask DMA channel 1
ED5E: out 0Ch,0             ; reset flip-flop
ED62: out 0Bh,dh            ; mode byte, e.g. 45h or 49h
ED66: out 02h,bl            ; address low
ED6A: out 02h,bh            ; address high
ED6E: out 03h,cl            ; count low
ED72: out 03h,ch            ; count high
ED76: out 83h,dl            ; page register
ED7A: out 0Ah,1             ; unmask channel 1
ED7D: ret

ED7Eh converts a real-mode segment:offset pair into a DMA physical address:

ED7E: rol dx,1 four times   ; segment << 4, with high bits in DX
ED87: cx = dx
ED89: dx &= 000Fh
ED8C: cx &= FFF0h
ED8F: ax += cx
ED91: adc dx,0

The IRQ installer at ED96h saves the old interrupt vector for IRQ+8, installs a CS-local handler, and unmasks the corresponding PIC bit:

ED9B: cli
EDA1: al = [0641] + 8
EDA8: bx = ax * 4
EDAB: es = 0000h
EDAF: save old offset from es:[bx] to [0646]
EDB6: es:[bx] = new handler offset
EDB9: save old segment from es:[bx+2] to [0648]
EDC1: es:[bx+2] = cs
EDD1: in al,21h
EDD3: save old PIC mask
EDD7: al &= ~(1 << irq)
EDD9: out 21h,al

There are two interrupt handlers. EE2Ah preserves registers and uses the current stack. EE69h switches to a private stack at CS:0DF4h before doing the same work, which is safer during high-level language calls:

EE69: push ds/es/ax/bx/cx/dx/di/si/bp
EE79: save ss:sp
EE83: ss = cs
EE86: sp = 0DF4h
EE89: read DSP status at base+0Eh
EE94: out 20h,20h           ; EOI
EE97: if bytes_left == 0:
EEA2:     call EEDD         ; begin next buffer
EEC0:     call F3B8         ; player/mixer update
EEC5: else:
EEC5:     call EF21         ; program next DMA fragment
EEC9: restore ss:sp
EEDC: iret

The playback setup at F080h validates the sample rate, calculates the Sound Blaster time constant from 1,000,000 / rate, stores the DMA start/end physical addresses, and starts the first fragment:

F089: cx = sample_rate
F08C: cmp cx,0FA0h          ; lower bound 4000 Hz
F095: cmp cx,59D8h          ; upper bound 23000 Hz
F0B9: install IRQ handler at 08BAh
F0C2: dx:ax = 000F:4240h    ; 1,000,000
F0C8: div cx
F0CC: cx = 0100h - ax       ; DSP time constant
F0DC: send DSP command 40h
F0E2: send time constant
F0E5: load buffer far pointer
F0EC: convert to DMA physical address
F0F8: store total byte count
F107: compute end address
F125: call EF21             ; program first block

EF21h is the recurring fragment scheduler. It computes the next DMA count, programs the DMA controller with ED55h, then tells the DSP to play a block with command 14h and a low/high count:

EF21: cx = FFFFh
EF24: if page_cross_pending:
EF31:     cx = [0655]
EF36: cx -= [064C]          ; fragment count
EF3B: [064E] = cx
EF43: subtract cx+1 from remaining byte count
EF55: dh = 49h              ; DMA mode
EF57: dl = [064B]           ; page
EF5C: ax = [064C]           ; address
EF60: cx = [064E]           ; count
EF65: call ED55             ; program DMA
EF79: cx = [064E]
EF86: send DSP command 14h
EF8B: send CL
EF90: send CH
EF95: ret

This is a conventional but clean early Sound Blaster loop: DMA moves the bytes, the DSP interrupt asks for the next fragment, and the music/player routine gets called from the IRQ path between fragment updates.

The service boundary is equally important. IRQ owner EE69h calls only DMA and tracker/mixer work; it never calls a polygon renderer, marker renderer, palette routine, page flip, or scroller. Visual frames remain in the foreground loops. Sound-enabled exit and fade state is exchanged through flags such as DS:7798 and DS:779A; silent mode follows the same visual path without that wait. The analysis did not execute or audition this audio path.

Main Vector Controller And Frame Contract

Load D57Dh is the real vector-stage controller. It waits for released input, selects and repairs page zero, constructs state zero through 99A5h, then dispatches DS:4980:

State Specialized owner Primitive mix
0/default below 11 B43Bh..B716h two-object depth merge, shaded quads
1 B2B2h..B43Ah one enabled face list, shaded quads
2 BB14h..C15Eh grouped shaded and flat quads
3..4 C793h..CC27h shaded quads plus two atlas/masked-marker calls
7..10 B717h..BB13h specialized polygon path
11 CC28h..D28Dh polygon-plus-marker hybrid
12..24 D28Eh..D57Ch procedural points and masked markers

Despite those inner-loop differences, each foreground frame has the same ownership sequence:

A524   update motion/transition state
AC0E or C15F   transform and project the active representation
895C   repair the previous object in the current back page
part owner   cull/order and raster quads, or clip/stamp markers
8A5E   reconstruct the fixed 30-row lower stage
7BA0   expose this completed page and select the opposite back page
A865   process edge-triggered live controls
A369   when cadence permits, consume one scroller/script item

State 11's CC28h loop mixes shaded quads and masked rectangles. The later D28Eh loop never calls 7EFBh, 7D52h, or the span rasterizer: it transforms points through C15Fh, stamps accepted markers through 8B22h, then makes the same 8A5Eh -> 7BA0h repair/present handoff. This closes the lifecycle gap between model data and pixels.

Scroller Script And Object Transitions

The scroller/object script begins at DS:1D20, with cursor DS:4981. Text bytes below 32h select glyphs. The first byte at least 32h terminates an item; values above C7h are object commands whose requested state is command-C8h.

A369h accepts at most one item when (BIOS_tick & C0h) changes, so accepted items are 64 BIOS ticks apart, about 3.516 seconds. The per-frame &38h test only limits when the callback is offered. The first object commands request states 0, 2, 1, 3, and 4, at script offsets 0026h, 0081h, 0124h, 0210h, and 029Ch.

A command is not an instant cut. A493h..A4B6h stores the next state, marks a slide-out, and leaves the current owner rendering while vertical position advances toward C7h. Only then does 99A5h construct the replacement and slide it back to the normal 6Bh position. Transition overlap can therefore move a visual boundary by several frames without changing its state order.

Exit And Failure Boundaries

Normal vector exit first calls the 63-pass retrace-paced palette fade at 0DBC:05F8 / load E1B8h; this is visual cleanup, not an audio-stop routine. The Turbo Pascal ExitProc registered at 4B07h then clears five work segments, restores INT 9, restores Sound Blaster DMA/IRQ state when initialized, disposes the dynamic block, and clears callback pointers.

The failure paths share that registered cleanup. Missing visual .U4C files report the constructed filename and call Halt(1); signature, mode, or read failures call Halt(2) after the stream is closed. Sound setup failures use separate Halt(3)/Halt(4) routes. These handoffs matter because an early resource failure does not simply strand tweaked VGA, keyboard, or DMA state.

What The Parts Are Doing

With the loader and primitives mapped, the demo becomes easier to read as a system rather than as a pile of effects. The EXE restores itself, initializes a Pascal-style runtime, and enters a menu/install shell. That shell reads or creates VECT_000.U4C, then builds numbered VECT_###.U4C resource names for the visual and music assets.

Two resource paths are the next layer down. The visual wrapper at 199EEh validates and decodes resources 001/002/003/005/006/007 through 19880h; the separate 18B36h JMUSIC parser remaps tracker data in resource 008. VGA mode 13h is only a starting point; the code quickly switches into a tweaked planar setup with direct map-mask control. Static picture data is decoded, packed, and in some cases compiled into generated copy routines.

The visible loop then works with those prepared pieces. It flips between two pages, copies only the changed strips, and uses 80-byte scanline tables instead of recalculating addresses. The vector core builds edge tables with Bresenham-like integer interpolation and fills horizontal planar spans through map-mask writes. Text, mirrored strips, status/control overlays, and small sprites are thin wrappers around the same VGA plane primitives.

The "fancy" part of VectorDemo is not one single trick. It is the combination: Pascal-level sequencing, hand-written VGA plane code, generated blitters, a proper resource package reader, and an interrupt-driven Sound Blaster path fed by the large JMUSIC payload in VECT_008.U4C. For 1991, that is a notably complete DOS demo engine.

Runtime-To-Code Concordance

The script's proven state order and cadence, combined with the corrected pixel audit, give a much tighter mapping than the old generic “strip scene” labels:

Older frame / fresh excerpt Visible ownership State and code owner
00:06 sunset/tree/star field opening controller 001C6h, before full reveal
00:10 sunset plus UltraForce logo generated reveal 09DAh inside 001C6h
00:26 two interlocked metallic objects state 0, two-object depth merge B43Bh..B716h
00:36 tower and checkerboard/plinth form state 2, mixed shaded/flat owner BB14h..C15Eh
00:48, 01:00 small then zoomed faceted object the same state 1 owner B2B2h..B43Ah
01:12 two blocky metallic objects state 3, hybrid owner C793h..CC27h
fresh 00:47..00:53 rotating/zooming stencil object polygon transform, winding, shaded quads and planar spans
fresh 01:30..01:36 red balls around a gold object procedural point transform C15Fh, marker owner D28Eh, atlas stamp 8B22h

State 2's alternate flat quad path explains why the checkerboard/plinth is not just another phase of the state-1 faceted object. State 3's two atlas calls explain masked details, but do not prove a trail; the old dotted-trail statement was a mismatch between prose and pixels and has been removed.

The continuous stencil clip also validates the screen-Y shade phase, while the continuous ball clip validates the point-to-marker path. Neither clip can by itself prove an instruction address, so the state correlations remain static concordance rather than a claim of instrumented runtime tracing.

The media sits over the visual loader at 199EEh/decoder 19880h, the page contract 895Ch -> part owner -> 8A5Eh -> 7BA0h, and an independently serviced audio path. That separation is the stronger point: this is a complete 1991 foreground demo engine, not one standalone vector routine or an IRQ-driven animation.

Interactive Controls

The restored text includes a live vector-control panel. The core controls are:

F1/F2       X rotation speed
F3/F4       Y rotation speed
F5/F6       Z rotation speed
F7/F8       zoom speed
F9/F10      object selection
SPACE       status
ENTER       defaults
BACKSPACE   zero speeds
X/Y/Z/D      reset individual axes/depth
C           center
M           music toggle
Alt         random rotation toggle
Scroll Lock pause scroll

That control list matches the code shape. Live state variables drive a reusable vector renderer, while the background and overlays are moved by strip/page helpers. The demo is not just playing one fixed object sequence; the renderer has enough exposed state to behave like a small live vector playground.

Static Analysis Notes

Some caveats: