Analysis model: gpt-5.5 xhigh, sol high, GPT-6 (reasoning level not recorded)
Last edited: 2026-09-17

Revision attribution: GPT-6, called Astra in this session, verified the original
plotter and corrected the earlier VOC codec and duration interpretation.

# Vector Balls by Toddl - Technical Dissection

`Vector Balls` / `vecballs.zip` is a 1991 MS-DOS MCGA/VGA demo by Thorsten
`Toddl` Drewes. The Hornet 1991 index lists it as `Vector Balls by Toddl`, and
the executable identifies itself as `VECTOR-BALLS V1.0`.

Release year: 1991

This is a compact but well-structured Turbo Pascal-era vector-ball demo. The
main program is not packed. It loads a raw logo, a VGA palette, a 4 KB ball
sprite bank, a text object-definition file, and eight Creative VOC samples.
The notable inner loop is a hand-shaped 16-row ball blitter: it does not scan a
transparent 16x16 sprite. Instead, it uses one precomputed horizontal span per
visible row and calls the runtime block mover only for the nonzero part of the
ball.

![Decoded Vector Balls logo](images/vecballs-logo-raw.png)

![Decoded Vector Balls ball tiles](images/vecballs-ball-tiles.png)

The images above are decoded from `vecballs.log`, `vecballs.dat`, and
`vecballs.pal`. They are not emulator screenshots. `vecballs.log` is a direct
320x82 indexed logo strip. The tile sheet shows the twelve meaningful 16x16
ball sprites: three object colors, each with four shade variants.

The original documentation and executable contain historical address/contact
details. Those are intentionally omitted here.

Front-page media note: the card now uses the continuous 3x3x3 cube runtime GIF,
which directly demonstrates the recovered perspective and painter order. The
decoded logo and ball-tile sheets remain separate article evidence for the
asset loader, shade bank, plot spans, and zero-tile erase path.

## Direct Silent Runtime

The original `vecballs.exe` was run in DOSBox-X 2024.03.01 with a normal CPU
core, fixed 8,000 cycles, 16 MiB RAM and `machine=svga_s3`. The command was
`VECBALLS N`, which takes the program's own no-sound route. DOSBox-X mixer
output was disabled as a second boundary and the host used a dummy audio
driver; no demo audio was auditioned, recorded or published.

The native 640x400 capture started with the first object already rotating.
Scripted Space presses at capture `00:10`, `00:20`, and `00:30` advanced
through all four records in `vecballs.3dd`:

```text
00:00..00:10  19-point PC-logo object, rotation increments (2,5,3)
00:10..00:20  27-point 3x3x3 cube, increments (4,4,4)
00:20..00:30  19-point three-axis object, increments (3,6,9)
00:30..00:40  13-point compact object, increments (4,-3,7)
```

These are observed capture-stream boundaries, not inferred durations. The
first fullscreen Escape at `00:40` was consumed by the emulator, so this run
is not used as runtime evidence for the demo's exit path. Three later
DOSBox-X `-silent` probes tried built-in `addkey` and timed `autotype` Escape
routes under the dummy backend; all produced live graphics, but none reached
the post-process marker before timeout. They are negative key-delivery tests,
not exit evidence. Space-driven object changes, continuous rotation,
changes in projected point spacing and overlap order are directly observed.
Each ball's sprite footprint stays fixed; depth changes its shade and projected
position, not the sprite dimensions. The original executable's Escape and
cleanup path is closed instruction-by-instruction below; the later direct
exit check now verifies the observable result as well.

### Direct Exit Check, 17 September 2026

A separate 30-second FFV1 recording uses the original executable, the same
normal-core fixed-8,000-cycle profile, and `VECBALLS N`. DOSBox-X runs in a
window on an isolated X11 display with dummy host audio. XTest delivers an
initial Space through the startup gate, three more Spaces to visit the
remaining objects, then Escape. No executable patch or resident keyboard
helper is used in this run.

The recording shows the four object displays in order. At capture
`00:27.000`, the window is in text mode and DOS has executed the command
placed after the demo, printing `ASTRA_EXIT_RETURNED` and returning to the
prompt. This proves the guest process returned before the capture supervisor
closed DOSBox. The full-root diagnostic recording is retained as working
evidence; existing article animations continue to illustrate the renderer.
The result closes the earlier input-delivery gap without attributing the
failed fullscreen and dummy-backend tests to an Escape-handling bug.

## Sources

- Hornet 1991 demo index:
  https://ftp.scene.org/mirrors/hornet/demos/1991/00_index.txt
- Scene.org archive:
  https://ftp.scene.org/mirrors/hornet/demos/1991/vecballs.zip
- Scene.org file page:
  https://files.scene.org/view/mirrors/hornet/demos/1991/vecballs.zip

## Archive

The examined archive is `vecballs.zip` from the Hornet mirror:

```text
vecballs.zip  235205 bytes
```

ZIP contents:

```text
ct-voice.drv      2377 bytes   1989-11-27 10:26
demosite.com      1129 bytes   1992-10-26 05:23
vb1.voc          40029 bytes   1991-05-23 16:21
vb2.voc          19936 bytes   1991-05-23 16:17
vb3.voc          19938 bytes   1991-05-23 16:18
vb4.voc          20164 bytes   1991-05-23 16:18
vb5.voc          20162 bytes   1991-05-23 16:18
vb6.voc          39884 bytes   1991-05-23 16:18
vb7.voc          40123 bytes   1991-05-23 16:19
vb8.voc          39773 bytes   1991-05-23 16:19
veadthis.doc      4104 bytes   1991-07-25 21:00
vecballs.3dd      1240 bytes   1991-05-23 15:57
vecballs.dat      4096 bytes   1991-05-23 15:53
vecballs.exe     38813 bytes   1991-07-25 21:00
vecballs.log     26240 bytes   1991-05-23 15:49
vecballs.pal       768 bytes   1991-05-23 15:46
```

Hashes:

```text
5c071b08b36fe7a3a2d726f17cae09fe50352463ce0460514a76913cf77026ac  vecballs.zip
54723241137a184d177cb22eca5a17b16c562bcdc18daa330643f41bb95476ae  vecballs.exe
63b9ee3aa25d2d2fcc9113cc83b7f1e8c63d95dbaebcf547537fbbdfddee3ad0  ct-voice.drv
53de648dc13a13feeaaf69dfa3d50181a2be8607dc9d332c35396146b85523a7  vecballs.3dd
494cbd8c56a3f5a5b21b24da2e8e048d08ac8128338e0c790184ee1dbc88802d  vecballs.dat
2313e9f4e7db422d8568539e2b6792e0a28c5c93167abe4e75b6dda27abf2fd1  vecballs.log
1bb2e2865d00be43af85c8f2c7e606425dbfe153212fbc61641d64e093e83ae3  vecballs.pal
```

The eight VOC files are not hashed individually in the main list above, but
they are all standard Creative Voice File version `1.10` blocks with one 8-bit
sound-data block and a terminator.

## MZ And Overlay Layout

`vecballs.exe` is a normal MZ executable:

```text
file size        38813 bytes
MZ image size    24192 bytes
MZ header         1408 bytes
relocations        342
entry           0000:14CF -> load offset 14CF
stack           0935:4000
```

The load image is `24192 - 1408 = 22784` bytes. The remaining `14621` bytes are
not part of the normal MZ image. They contain Turbo Pascal overlay/debug-style
metadata, including useful unit and symbol names:

```text
SOURCES\PD\VECBALLS\VECBALLS.PAS
READNEXTOBJECT
PALETTE
ROTATE
FASTPLOTVECBALL
BALLQUEUE
TRANSFORM
ZDELTA
VOCPLAY
VGA256.PAS
VGA256XT.PAS
T_RILBM.PAS
```

Those names are not source code, and they are not enough by themselves to map
every procedure address. They do confirm the broad organization seen in the
binary: object-file parser, palette loader, rotate/transform pass, ball queue,
fast ball plotter, VGA mode helpers, and VOC playback unit.

The main filename cluster appears in the loaded image as Pascal-style strings:

```text
0C "vecballs.dat"
0C "vecballs.log"
0C "vecballs.pal"
0C "vecballs.3dd"
```

## Runtime Files

### `vecballs.pal`

`vecballs.pal` is exactly 768 bytes:

```text
256 entries * 3 channels = 768 bytes
```

Each channel is a normal VGA DAC value in `0..63`. The PNGs in this article
scale channels with:

```text
display_channel = dac_channel * 255 / 63
```

The palette starts with common EGA-like colors, then ramps and ball colors.
The meaningful ball tile colors are in high palette ranges such as `c8..cf`,
`e0..e7`, `e8..ef`, and `f0..f7`.

### `vecballs.log`

`vecballs.log` is exactly:

```text
26240 bytes = 320 * 82
```

The program loads it as a raw indexed image strip. The code path around load
offset `1980h` opens `vecballs.log` and copies `0x6680` bytes to A000:

```asm
; file offset 1f6f, runtime load offset 19ef
1f74  mov ax,a000h       ; destination segment
1f7a  xor di,di          ; destination offset 0
1f7d  mov ax,6680h       ; 26240 bytes
1f85  call runtime_read  ; read file bytes into A000:0000
```

So the logo file is not compressed and not interpreted as a bitmap format. It
is already screen memory.

### `vecballs.dat`

`vecballs.dat` is `4096` bytes. The visible ball bank occupies the first
`12 * 256 = 3072` bytes:

```text
tile size    16 * 16 = 256 bytes
tile count   12 visible ball tiles
layout       three colors * four shade/depth variants
```

The remaining 1024 bytes occupy four additional 16x16 slots. Tile index `0Ch`
is 256 zero bytes, and every recovered erase call passes exactly that index to
the normal plotter. The final three slots contain nonzero residual data but no
recovered plotter call can select indices `0Dh..0Fh`; they are not a fourth
visible color family and should not be described as support artwork.

The first tile's nonzero spans are:

```text
row  x0  x1  width
 0    5   9     5
 1    3  11     9
 2    2  12    11
 3    1  13    13
 4    1  13    13
 5    0  14    15
 6    0  14    15
 7    0  14    15
 8    0  14    15
 9    0  14    15
10    1  13    13
11    1  13    13
12    2  12    11
13    3  11     9
14    5   9     5
15  empty
```

That span pattern is exactly what the unrolled plot routine uses.

### `vecballs.3dd`

`vecballs.3dd` is a text object-definition file. Its grammar is simple:

```text
% comment
xrot,yrot,zrot
x,y,z,color
x,y,z,color
...
#
next object...
#
#
```

Parsed objects:

```text
object  rotations   points  color counts       bounds
1       2,5,3       19      0:4 1:5 2:10      x -21..21, y -14..14, z -2..2
2       4,4,4       27      0:9 1:9 2:9       x -7..7,   y -7..7,   z -7..7
3       3,6,9       19      0:6 1:6 2:7       x -21..21, y -21..21, z -21..21
4       4,-3,7      13      0:6 1:6 2:1       x -14..14, y -14..14, z -14..14
```

The parser at `00D9h` converts that text directly into the renderer's 1-based
tables. Its outer line reader at `0040h` skips every line whose first byte is
`%`. When the read reaches DOS text EOF, it resets the text stream and returns
the first non-comment line, which is why the trailing double `#` loops directly
from object four to object one.

Normalized parser flow is:

```text
header = next_non_comment_line()
if header[1] == '#': reset_stream(); restart parser

(x_step,y_step,z_step) = split_three_signed_integers(header, ',')
i = 1
while i <= 100:
    line = next_non_comment_line()
    if line[1] == '#': break
    (x,y,z,color) = split_four_signed_integers(line, ',')
    point[i] = (x<<7, y<<7, z<<7)
    base_tile[i] = (color idiv 3 remainder) << 2
    i++
point_count = i - 1
```

Each authored coordinate is shifted left seven and stored as a signed 32-bit
Q7 value. For 1-based point `i`, the component addresses are
`3748h+12*i`, `374Ch+12*i`, and `3750h+12*i`; those are compiler-adjusted
bases, so point 1 physically begins at `3754h`. The count at `3D68h` is written
as a word, although most renderer loops consume its low byte. The color field
uses signed `IDIV 3` and stores the remainder times four in the sidecar byte
table at `3C03h+i`. Authored colors 0, 1 and 2 therefore produce base tile
indices `0`, `4` and `8`; negative or larger malformed values are not
validated.

The 100-point limit is a stop condition, not a robust record skipper. Point
100 is stored, then the routine exits without consuming any remaining lines of
an overlong object. A later call would interpret point 101 as the next rotation
header and desynchronize the grammar. The four shipped objects stay safely at
13, 19 or 27 points.

The first object is the "PC-logo" shape. Its point list is:

```text
-21, 14,  2, 2
-14, 14,  1, 2
 -7, 14,  0, 2
  7, 14,  0, 2
 14, 14,  1, 2
 21, 14,  2, 2
-21,  7,  1, 1
 -7,  7, -1, 1
  7,  7, -2, 1
-21,  0,  0, 0
-14,  0, -1, 0
 -7,  0, -2, 0
  7,  0, -2, 0
-21, -7,  1, 1
  7, -7, -1, 1
-21,-14,  2, 2
  7,-14,  0, 2
 14,-14,  0, 2
 21,-14,  2, 2
```

### VOC Samples

Every VOC file has one type-1 sound block with time constant `156`, codec `1`,
and a 10 kHz playback rate. Codec 1 is Creative 4-bit ADPCM, not unsigned
8-bit PCM (codec 0), as confirmed by the
[FFmpeg VOC codec table](https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/voc.c).
The previous duration table incorrectly treated each compressed byte as one
sample and consequently understated the lengths by about half.

```text
file      encoded payload bytes   decoded samples   duration at 10 kHz
vb1.voc          39996                  79991               7.9991 s
vb2.voc          19903                  39805               3.9805 s
vb3.voc          19905                  39809               3.9809 s
vb4.voc          20131                  40261               4.0261 s
vb5.voc          20129                  40257               4.0257 s
vb6.voc          39851                  79701               7.9701 s
vb7.voc          40090                  80179               8.0179 s
vb8.voc          39740                  79479               7.9479 s
total           239745                 479482              47.9482 s
```

The payload excludes the time-constant and codec bytes. Its first byte is
the reference sample; each remaining byte supplies two 4-bit codes. Thus
`L` encoded bytes produce `1 + 2*(L-1)` decoded samples. Each file ends
with a single block-0 terminator; there are no continuation or repeat blocks.
All eight counts were checked by decoding to a memory pipe with FFmpeg 6.1.1
and counting signed-16 output samples. No sound was played or published.
Container duration estimates can differ slightly, so the table uses the
decoded counts rather than the demuxer's estimated duration.

The executable loads `CT-VOICE.DRV` and uses the Creative Labs VOC driver path
when sound is enabled. Command-line option `N` disables sound, and option `F`
sets the fast path flag.

## Startup And File Load

The entry at load offset `14cfh` is high-level Pascal code around runtime calls.
It initializes the runtime, parses command-line arguments, and sets two flags:

```text
sound enabled flag   cleared by command-line N / NOSOUND
fast flag            set by command-line F / FAST
```

The parser reads each command-line argument, uppercases the first character, and
checks:

```asm
; file offset 1ac8, load offset 1548
mov  al,[3d73h]      ; first character of parsed argument buffer
cmp  al,4eh          ; 'N'
jne  not_n
mov  byte [3d6fh],0  ; disable sound
jmp  next_arg
not_n:
cmp  al,46h          ; 'F'
jne  next_arg
mov  byte [3d70h],1  ; fast path
```

The load sequence then reads the external files:

```text
vecballs.dat  -> program data area at offset 0884h, 4096 bytes
vecballs.log  -> A000:0000, 26240 bytes
vecballs.pal  -> program data area at offset 1984h, 768 bytes
vecballs.3dd  -> opened as text and parsed object-by-object
```

The hard-coded file lengths are visible in the caller:

```text
vecballs.dat  length 1000h
vecballs.log  length 6680h
vecballs.pal  length 0300h
```

That makes the data design unusually transparent for an early 1991 PC demo.
The disk files are already in the exact formats the runtime wants.

## Recovered Function Map

The deeper revision maps the previously unresolved transform path. Offsets are
relative to the MZ load image (file offset minus the `0580h` header):

| Load offset | Recovered role |
| --- | --- |
| `0000h` | assign/open the `.3dd` Turbo Pascal text stream |
| `0040h` | read the next non-comment line and rewind on EOF |
| `00D9h` | `READNEXTOBJECT`: parse the next `.3dd` header and point set |
| `03B1h` | unrolled fifteen-span 16x16 ball plotter |
| `06B7h` | build 360-entry sine and cosine tables |
| `0756h` | rotate every object point through the three axis stages |
| `0B1Dh` | perspective transform to screen coordinates |
| `0C16h` | build depth order and choose color/shade tile |
| `14CFh` | Turbo Pascal program entry |
| `1A75h..1A7Fh` | assign/open `vecballs.3dd` and call the first parser pass |
| `1AF1h` / `1D53h` | fast and paced versions of the visible object loop |
| `2041h` | retrace-coupled palette installation/fade helper |

These labels describe behavior recovered from the instructions. The surviving
overlay names corroborate several of them, but the addresses do not come from
a linker map.

## Ball Plotter Inner Loop

The interesting routine begins at file offset `0931h`, which is load offset
`03b1h` after subtracting the `0x580` MZ header. It takes Pascal stack
arguments that behave as:

```text
bp+04  y
bp+06  x
bp+08  tile number / color-shade tile index
```

The routine selects a 256-byte tile by shifting the tile number left by eight:

```asm
0934  mov al,[bp+08]
0937  xor ah,ah
0939  mov di,ax
093b  mov cl,08h
093d  shl di,cl          ; tile_index * 256
093f  add di,0889h       ; first nonzero span of row 0
```

For every visible row, it recomputes:

```text
destination = A000:(y + row) * 320 + x + x_offset
source      = DS:(tile_index * 256) + source_offset
length      = row_span_width
```

Then it calls the Turbo Pascal runtime block mover at `037e:17b8`. A typical
row looks like this:

```asm
0973  add di,0897h       ; source span for row 1
0979  mov ax,a000h
097d  mov ax,[bp+04]
0980  inc ax             ; y + 1
0981  mov dx,0140h
0984  mul dx             ; (y + 1) * 320
0986  add ax,[bp+06]     ; + x
0989  add ax,0003h       ; row x offset
0991  mov ax,0009h       ; row width
0995  call 037e:17b8     ; move 9 bytes
```

The full unrolled span table is:

```text
row  source offset  dest x offset  length
 0   tile+0005      x+5             5
 1   tile+0013      x+3             9
 2   tile+0022      x+2            11
 3   tile+0031      x+1            13
 4   tile+0041      x+1            13
 5   tile+0050      x+0            15
 6   tile+0060      x+0            15
 7   tile+0070      x+0            15
 8   tile+0080      x+0            15
 9   tile+0090      x+0            15
10   tile+00a1      x+1            13
11   tile+00b1      x+1            13
12   tile+00c2      x+2            11
13   tile+00d3      x+3             9
14   tile+00e5      x+5             5
15   empty          none            0
```

This is not a masked sprite loop in the usual sense. The sprite's mask has
already been compiled into the row spans. The payoff is that no transparent
pixels are tested or copied, and no branch runs inside a row. The cost is code
size: fifteen near-identical row blocks instead of one loop.

The design matches the decoded tile data exactly. For the first tile, row 5 is:

```text
x offset 0, width 15
e4 e3 e2 e1 e0 e1 e1 e2 e2 e3 e3 e4 e5 e6 e6
```

The routine copies precisely those fifteen bytes to A000 and skips the zero at
the right edge. Across one ball it makes 15 block-mover calls and writes 177
bytes; row 15 performs no call. The routine uses unsigned `mul 0140h` and
16-bit destination addition with no clipping, rejection, or scanline-wrap
repair. A bad projected X/Y would therefore wrap within `A000h`; the object and
camera bounds are part of the renderer contract.

Erase calls use this identical 177-byte footprint with tile `0Ch`, whose 256
source bytes are all zero. Corners outside the compiled spans were never
written by the visible ball, so the erase does not need a full 16x16 clear or a
mask pass.

### The runtime mover copies bytes and may reverse each span

The actual helper at `037E:17B8h` uses `REP MOVSB`, not word copies. It
loads the source and destination far pointers from the Pascal stack, clears
the direction flag, and compares their **offsets**. If `SI < DI`, it advances
both offsets to their final byte, executes `STD`, and copies backwards.
It does not compare the segment values before making that decision.

For the authored ball region, all source offsets, including zero tile 12,
are below the destination offsets. Each horizontal span is therefore copied
right-to-left, while the fifteen row calls still run top-to-bottom. Direction
does not change the final sprite because the data and VGA segments are
distinct. It does explain the order of partial writes if a capture catches
a row being copied. The helper restores DS and returns with `RETF 10`;
it leaves the direction flag as selected, and the next mover call explicitly
clears it before its own comparison.

An independent execution check applied the original MZ relocations and ran
both the plotter and this original helper for all twelve visible tiles plus
the zero erase tile at three screen locations: 39 cases. It compared every
VRAM write's address, value and order, then checked the complete 64 KiB VGA
segment to detect unintended changes. All cases produced the expected 177
bytes and preserved the rest. The origin case also exercises forward-copy
decisions outside the normal object region.

## The Trigonometry Tables Have Exactly 360 Entries

Initialization calls `06B7h` before entering the object loop. The routine
iterates index `0..359` (`0167h`) and writes two signed-word tables at `30DAh`
through `33A9h` and `33AAh` through `3679h`. Startup uses Turbo Pascal's
software Real48 path to compute:

```text
radians = (Real48(degree) / 180.0) * pi
sin[degree] = trunc(sin(radians) * 16384.0)
cos[degree] = trunc(cos(radians) * 16384.0)
```

The conversion routine takes the non-rounding path, so each table contains Q14
words with `+1.0 = 4000h` and no interpolation. Runtime angles can therefore be
wrapped by adding or subtracting `0168h`.

That exact wrap occurs in the frame loop. The three current angles live at
`367Ch`, `367Eh`, and `3680h`; signed byte increments from `3682h..3684h` are
added after each rendered frame. Values above 359 lose 360 and negative values
gain 360. These three bytes are the `xrot,yrot,zrot` values parsed from the
current `.3dd` object, so the text file's first line is a literal per-frame
degree increment rather than a vague speed setting.

## Object Transform Path

The object file gives each object a per-frame rotation increment in degrees:

```text
xrot,yrot,zrot
```

The overlay names show the intended Pascal structure:

```text
SINUS
COSINUS
RADIANT
ROTATE
TRANSFORM
VECBALL
BALLQUEUE
ZDELTA
FASTPLOTVECBALL
```

The new disassembly pass closes the earlier evidence gap. `0756h` walks points
`1..[3D68h]`; each point occupies a 12-byte record of three signed 32-bit Q7
coordinates. It combines those values with Q14 sine/cosine words, uses the
Turbo Pascal signed long multiply/divide helpers, and divides every pair by
`4000h`. In normalized form, with truncation after each pair, the exact stages
are:

```text
x1 = x
y1 = (sin(ax)*z  + cos(ax)*y) / 16384
z1 = (cos(ax)*z  - sin(ax)*y) / 16384

x2 = (sin(ay)*z1 + cos(ay)*x1) / 16384
y2 = y1
z2 = (cos(ay)*z1 - sin(ay)*x1) / 16384

x3 = (sin(az)*y2 + cos(az)*x2) / 16384
y3 = (cos(az)*y2 - sin(az)*x2) / 16384
z3 = z2
```

Every base below is indexed as `base + 12*i`:

| Stage | X base | Y base | Z base |
| --- | ---: | ---: | ---: |
| source | `3748h` | `374Ch` | `3750h` |
| after X | `1C7Eh` | `1C82h` | `1C86h` |
| after Y | `212Eh` | `2132h` | `2136h` |
| after Z | `25DEh` | `25E2h` | `25E6h` |

The scratch banks are therefore ordered handoffs, not three unrelated
transformed copies. The third coordinate is carried through each stage rather
than discarded, so this is a real ordered X-then-Y-then-Z rotation and not
independent 2D logo motion.
The subtraction order is significant: the code computes `cos*z - sin*y` (and
its Y/Z-stage equivalents), so zero angles preserve `(x,y,z)` exactly.

The projection at `0B1Dh` is especially explicit, and it corrects an earlier
scale error in this article. Data segment `0507h` places the camera word
`0002h` at load-image offset `5072h` (raw file `55F2h`); its exact value is
`16300`, or `127.34375` in the same Q7 units as the authored coordinates. For
every transformed point the code subtracts the full 32-bit `z3`, but stores
only the low result word before division:

```text
den16 = int16((16300 - z3) & 0xffff)
if den16 == 0: den16 = 1
```

The divisor is then sign-extended from that 16-bit temporary. The shipped
objects keep `z3` within `-3241..3241`, so their denominator is positive and
the truncation does not change their result. A malformed or much larger object
could wrap the divisor without hitting the exactly-zero guard. With the
authored data, the code executes:

```text
qx = signed_divide(16300 * x3, den16)
qy = signed_divide(16300 * y3, den16)

screen_x_long = 153 + logical_shift_right(qx, 6)
screen_y_long = 130 + logical_shift_right(qy, 6)
```

The helper at runtime `037E:09F8h` is a 32-bit right shift, so the scale is
division by 64, not multiplication by 64. For the bounded coordinates used by
the demo, the low words consumed by the blitter behave as signed projected
offsets; the high-word fill produced by a logical shift of a negative value is
stored but never used as a screen coordinate. The results live in 32-bit X/Y
banks at `2A96h` and `2C26h`, while draw calls pass only their low words.

The top-left origin `(153,130)` is also deliberate: the plotted ball occupies
span columns 0..14 around that point, putting its visible center at about
`(160,137)`. It is not an unexplained eight-pixel screen margin. The projection
has no near-plane or behind-camera rejection beyond the exactly-zero
denominator guard, and the plotter has no X/Y clipping. The authored object
bounds, Q7 camera and screen center are responsible for keeping all visible
span writes inside the 320x200 page.

### All-angle footprint proof

That safety claim can be closed without depending on the four captured
trajectories. The Q14 sine/cosine coefficients are truncated toward zero, so
each axis pair has magnitude no greater than the corresponding unit rotation;
the signed Q14 divisions also truncate toward zero. The three rotation stages
therefore do not increase a point's source-space radius.

For camera distance `C=16300`, a point constrained to a sphere of Q7 radius
`R<C` has maximum perspective displacement along either screen axis bounded by:

```text
pixel_displacement <= ceil(C*R / sqrt(C*C - R*R) / 64)
```

Applying that bound to the most distant source point in each object, then
including the plotter's last written x/y offset 14, gives:

| Object | Maximum Q7 radius | Screen x footprint | Screen y footprint |
|---|---:|---:|---:|
| PC sign | `sqrt(641)*128 < 3241` | `101..219` | `78..196` |
| 3x3x3 cube | `sqrt(147)*128 < 1552` | `128..192` | `105..169` |
| three-axis set | `21*128 = 2688` | `110..210` | `87..187` |
| compact object | `14*128 = 1792` | `124..196` | `101..173` |

These are conservative all-orientation bounds, so they remain valid when an
object inherits arbitrary current angles at a key-triggered handoff. Every
compiled span stays inside the 320x200 page, every perspective denominator
stays positive, and no 16-bit `y*320+x` destination wraps.

The PC sign does technically enter the logo allocation: its top-left y can be
78 while `vecballs.log` occupies rows 0..81. Direct inspection of the decoded
asset resolves the apparent collision. Logo rows 77 through 81 are entirely
index zero; row 76 is the last row containing any nonzero pixel. The ball and
its tile-12 erase can therefore touch only the logo's authored black tail.
“Below the logo” is visually true, but the exact storage contract is a
five-row zero guard inside the 82-row logo file.

`0C16h` then prepares the draw queue. It initializes byte indices `1..N` at
`3685h` and performs `N` complete adjacent-swap passes of `N-1` comparisons.
It swaps only when the current signed 32-bit Z is greater than the next Z, so
the result is a stable ascending-depth order: equal-depth points retain source
order. The main loop dereferences this table before fetching screen X/Y. Since
larger Z reduces the perspective denominator and is nearer the camera, drawing
ascending Z is back-to-front painter order without a z-buffer.

The same routine converts depth to artwork. It begins with base tile `0`, `4`,
or `8` from `3C03h`, then applies exact signed 32-bit bands:

```text
z < -1000          base + 3
-1000 <= z <= 0    base + 2
0 < z <= 1000      base + 1
z > 1000           base + 0
```

Thus the twelve visible tiles are proved as three color families times four
depth/shade bands, including the boundary ownership, not merely inferred from
the decoded tile sheet.

![The first object rotating in the original executable; flattening toward a line and opening back into the PC-shaped point set proves the three-axis transform is live.](images/vecballs-runtime-pc-object.gif)

The first object has only shallow z values (`-2..2`), so it behaves like a
rotating PC-shaped sign. The cube object has 27 points in a full 3x3x3 grid,
which is the canonical vector-ball test for depth order.

## One Frame, In Instruction Order

Both main-loop variants execute the same visual pipeline. The `F` option
selects the duplicated fast loop at `1AF1h`; the normal route enters the paced
copy at `1D53h`, whose call at `1D99h` occurs after transform/sort and before
the first erase. The far wait at `02B6:0000h` reads the CRTC base from BIOS
data `0000:0463h`, adds six to reach the status port, waits for retrace bit 3 to
clear, then waits for it to set. Drawing starts at retrace entry, but fifteen
runtime block moves per ball are not guaranteed to finish before active display
resumes. `F` removes that pacing only; it does not select a different renderer.

```text
      service the optional VOC lane when enabled; N bypasses it
0756  rotate all source points through X/Y/Z stages
0B1D  perspective-project them around screen center (153,130)
0C16  stably sort point indices by ascending Z and assign one of twelve tiles
      paced route only: wait after the queue is complete
03B1  erase every previous draw slot with all-zero tile 12
03B1  draw in the new sorted order and save X/Y by draw slot
      add the object's three signed angle increments
      poll keyboard: Esc takes the immediate cleanup/Halt path;
                     any other available character advances object
      wrap every angle into 0..359
```

The old-position banks at `2DB6h` and `2F46h` are initialized to `(0,100)` and
updated from the newly projected coordinates after the erase pass. They are
indexed by draw slot, not persistent point identity: slot `i` saves the X/Y of
`queue[i]` after all old slots have already been cleared. That is sufficient
because the next frame erases every saved footprint before drawing anything.
The first frame consequently performs one redundant black erase at `(0,100)`
for every point.

This is why the program can draw directly into `A000h` without a 64 KB
backbuffer: it copies zero spans over every prior ball and then paints the newly
depth-sorted frame. There is no background reconstruction because the object
area below the fixed 82-row logo is black.

### Paced Versus Fast Publication, Measured

The duplicated loops differ at one visually consequential point: the normal
route calls the retrace waiter after transform/sort and before old-slot erase,
while command-line `F` omits that call. A matched direct-capture probe measures
the result instead of treating `F` as a vague speed switch.

Both runs used the untouched archived executable at the article's existing
fixed 8,000-cycle DOSBox-X profile, with `N` in both cases and `F` added only
to the fast run. A temporary resident keyboard probe preloaded the startup
Space and inserted Escape through the BIOS keyboard ring on the 200th main-loop
`KeyPressed` poll. It did not patch the executable, point tables, framebuffer,
VGA ports, or timing code. Native ZMBV capture remained at
`2,190,197 / 31,250`, or 70.086304 frames per second.

Both mode-13h streams have the same 16-capture-frame black lead before the
first ball frame. After that common boundary:

```text
normal paced route: 398 captured frames, 199 hash runs
                     every run is exactly two identical frames
                     visible cadence = 70.086304 / 2 = 35.043152 Hz

F fast route:       212 captured frames, 212 hash runs
                     every captured framebuffer state is distinct
```

The paced result closes the code-to-runtime handoff: at this CPU profile the
`02B6:0000h` wait makes each completed object state persist for exactly two
native capture frames. It does not change the angle increments, transform,
queue, erase, or draw routines. The fast route executes those same routines as
soon as the preceding iteration ends, so capture can land inside the direct
VRAM transaction.

![Five consecutive fast-loop framebuffer snapshots: residual old-ball spans, the fully erased gap, partial new-ball spans, and completed redraw](images/vecballs-fast-loop-erase-redraw.png)

The five panels are consecutive fast-route source frames 54 through 58 at
`00:00.770`, `00:00.785`, `00:00.799`, `00:00.813`, and `00:00.828`. Frame 54
contains residual horizontal pieces while zero-tile calls are clearing the old
slots. Frame 55 catches the exact gap after all old balls are gone. Frame 56
catches the new painter queue partway through its fifteen-span calls; frames 57
and 58 show that draw filling out. This is direct visual evidence for the
article's `erase all old slots -> draw all new queue slots` order, and it is why
the fast loop can expose intermediate framebuffer states despite using exactly
the same object arithmetic.

The keyboard helper is instrumentation, not part of the release. Its resident
DOS bookkeeping is therefore not used as new cleanup evidence; the original
instruction path remains the authority for mode restoration and `Halt(0)`.
The cadence result is also profile-specific: it establishes behavior at the
documented 8,000-cycle run, not a universal frame rate for every period PC.

### Exact Per-Frame Vector Cost

The formulas and fixed-span plotter make the object cost countable rather than
qualitative. Per point, the three ordered rotation stages perform twelve signed
32-bit multiplies and six Q14 divisions; projection adds two more multiplies,
two signed perspective divisions, and two 32-bit right shifts. The sorter then
does exactly `N * (N - 1)` signed 32-bit adjacent comparisons because it always
runs `N` complete passes of `N-1` pairs—there is no early-out flag.

Erase and draw each call the fifteen-span mover once per point. Their combined
payload is `30*N` mover calls, `354*N` sprite-bank reads, and `354*N` direct
A000 byte writes. Half of the reads come from all-zero tile `0Ch`; half come
from the depth-selected visible tiles:

```text
object             N   long mul  long div  shifts  depth compares  mover calls  source reads  A000 writes
PC sign           19      266       152       38          342            570         6,726        6,726
3x3x3 cube        27      378       216       54          702            810         9,558        9,558
three-axis set    19      266       152       38          342            570         6,726        6,726
compact object    13      182       104       26          156            390         4,602        4,602
```

This ledger excludes parser work, angle updates, queue initialization, shade
tests, retrace waiting, and Pascal call overhead, but it includes every long
rotation/projection arithmetic operation, every fixed bubble comparison, and
every ball-footprint byte written in the hot visual path. It explains why the
27-ball cube is the strongest stress scene even though all four objects use the
same renderer.

The table is the ordinary no-key steady state. A non-Escape key is tested only
after the newly sorted object has been drawn. That handoff frame then erases
all `N_old` just-saved slots a second time before parsing the next object:

```text
steady frame:        2N plotter calls, 30N mover calls,
                     354N sprite reads + 354N A000 writes
object-change frame: 3N plotter calls, 45N mover calls,
                     531N sprite reads + 531N A000 writes
```

The new object's point count does not enter that frame's raster cost. It takes
ownership only after `READNEXTOBJECT` and the slot reset, then determines the
transform, sort, erase and draw bounds on the following frame.

Screen ownership is correspondingly simple:

```text
A000:0000h..603Fh   logo rows 0..76; last nonzero logo data is on row 76
A000:6040h..667Fh   five all-zero logo-tail rows 77..81; PC-sign guard overlap
A000:6680h..F9FFh   BIOS-cleared index-0 field used by the moving balls
ball footprint      direct 177-byte span writes and zero-tile erases
```

There is one framebuffer, no hidden page, page flip, saved background, or
clipping layer. If an invalid projected ball reached a nonzero logo row, tile
`0Ch` would punch black spans into it; the all-angle bounds and five-row black
tail are what prevent that.

![The 27-point cube continuously changes projected spacing and overlap order; this is the direct runtime counterpart to the perspective equation and byte-index painter queue.](images/vecballs-runtime-cube.gif)

## Escape And Cleanup, Not A Held Graphics Process

The fast and paced loops duplicate the same keyboard branch at
`1C46h..1C6Ch` and `1EB4h..1EDAh`. `KeyPressed` is tested once per completed
draw. If it reports a key, `ReadKey` supplies one byte:

```text
if KeyPressed:
    key = ReadKey
    if key == 1bh:
        call 01fd:0044h       # load offset 2014h
        Halt(0)               # runtime 037e:00e9h; does not return
    erase all saved slots with tile 0ch
    READNEXTOBJECT
    reset old-position slots
```

Thus Escape leaves before the object-change erase pass and before angle wrap.
The program does not fade the palette or individually erase the last object.
Mode restoration makes that unnecessary.

The helper at load offset `2014h` constructs an interrupt-register packet with
`AX=0003h` and dispatches interrupt `10h` through the Turbo Pascal interrupt
bridge at `377Bh`. This is an explicit BIOS 80x25 text-mode restore. It then
calls the graphics-unit finalizer at `2251h`, marks the local video-mode state
`ffh`, and returns to the immediate `Halt(0)`. The visible main path has no
separate `.3dd` close or Sound Blaster shutdown call after this point; those
remaining process resources belong to Turbo Pascal's registered runtime/unit
finalizers during `Halt`.

This static path resolves the old “capture held after Escape” ambiguity. The
old run failed to deliver the key to the DOS program; it did not reveal a demo
loop that intentionally ignores Escape.

## Audio Path

The sound side is classic Sound Blaster sample playback through Creative's
`CT-VOICE.DRV`:

```text
driver file     ct-voice.drv
sample files    vb1.voc ... vb8.voc
sample format   Creative VOC v1.10, 4-bit Creative ADPCM, codec 1
sample rate     10000 Hz
```

The program prints a non-fatal error if the driver cannot be installed. If the
user supplied `N` or `NOSOUND`, it skips the Sound Blaster path.

The eight VOC blocks decode to 47.9482 seconds of 10 kHz sample data. That
is why the archive is large compared with the executable: the audio files alone
are much larger than the program.

## Runtime Sequence And Interaction

The direct run resolves the old structural-only timeline. Startup reads the
external ball bank, logo, palette and object text, then keeps the 320x82 logo
fixed while the point object rotates beneath it. The scripted run used Space,
but the code accepts any non-Escape character. In either duplicated loop the
handoff order is exact:

```text
erase slots 1..old_count with tile 0ch
READNEXTOBJECT at 00d9h
initialize old-position slots 0..new_count inclusive to (0,100)
continue with the existing angle words
```

Slot zero is harmless queue slack; ordinary drawing remains 1-based. The next
object therefore comes from the `.3dd` stream rather than a hard-coded selector.
The three scripted Space presses produced the four objects in file order,
including the negative Y increment of the final record. The accumulated angles
are not reset during this handoff, so the new point set inherits the current
orientation. An extended key can advance twice because Turbo Pascal `ReadKey`
returns a zero prefix and leaves the scan code for the next poll; both bytes are
non-Escape here. The line reader rewinds at EOF, and the final double `#` sends
the sequence from object four back to object one.

No automatic duration was observed: each object remained active until the next
scripted Space press. The runtime therefore supports an interaction timeline,
not a claim that each object is authored to last ten seconds. The ten-second
windows above were deliberately chosen capture intervals.

## Asset-To-Code Concordance

This page uses both decoded asset stills and two direct runtime GIFs. The bridge
from the static sheets to the executable is direct because the files are loaded
in raw runtime-ready formats:

- `images/vecballs-logo-raw.png` is decoded from `vecballs.log` with
  `vecballs.pal`. The file size is exactly `320 * 82`, and the executable reads
  `0x6680` bytes straight into `A000:0000`. That makes the logo strip a direct
  framebuffer asset, not a converted picture format or a generated recreation.
- `images/vecballs-ball-tiles.png` is decoded from `vecballs.dat` with the same
  palette. The first `3072` bytes hold twelve visible `16x16` ball tiles:
  three object colors times four shade/depth variants. The main loop proves
  that tile `0Ch`, in the 1024-byte tail, is used for old-position erasure.
- The unrolled plotter at load offset `03b1h` proves how the tile sheet is used.
  It selects `tile_index * 256`, skips transparent padding by construction, and
  copies only the fifteen nonempty row spans into `A000h`.
- The span table in the code matches the decoded first tile: rows widen from
  5 to 15 bytes, hold the wide center, then narrow back to 5 bytes, with the
  final row empty. No per-pixel transparency test is needed in the hot path.
- `vecballs.3dd` proves the 3D object source for the runtime ball positions.
  The text grammar supplies rotation increments and `x,y,z,color` point
  records; the decoded tile colors then become the visible projected points.
- The overlay/debug names (`READNEXTOBJECT`, `ROTATE`, `TRANSFORM`,
  `BALLQUEUE`, `FASTPLOTVECBALL`) independently match the observed data flow:
  parse object, rotate/project points, queue depth/color, choose a tile, and
  call the span blitter.
- The two runtime GIFs are continuous excerpts from the original executable in
  its own `N` mode. They prove that the decoded point definitions become moving
  perspective objects; the scripted capture used Space to exercise the code's
  any-non-Escape object transition.
- The VOC files and `CT-VOICE.DRV` are orthogonal runtime assets. They explain
  the optional Sound Blaster path, but the decoded logo and ball sheets do not
  depend on sound being enabled.

Evidence boundary: the decoded logo/tile images prove asset content but not
motion. The two continuous runtime GIFs and the 40-second scripted no-sound run
prove the live transform, painter order and interactive object progression;
the ten-second windows are operator-chosen capture intervals, not authored
durations. Those frames still do not prove cleanup because the fullscreen
Escape was consumed by the emulator. Cleanup is separately proved by the
original executable's `1C46h`/`1EB4h` key branches, explicit BIOS mode-3 helper
at `2014h`, graphics finalizer at `2251h`, and immediate Pascal `Halt(0)`.

## Why This One Matters

`Vector Balls` is not a huge trackmo, but it is a clean snapshot of early PC
demo engineering:

- It exposes its asset pipeline: palette, raw logo, sprite bank, text objects,
  and VOC samples are all external files.
- The object format is editable and simple enough to reconstruct.
- The 16x16 ball artwork is pre-shaded, avoiding per-pixel lighting.
- The hot plotter is unrolled around the actual nonzero span shape of the ball.
- The sound path uses the period-correct Creative VOC driver rather than a
  custom mixer.

The result is very 1991: Pascal runtime and external data files at the top,
direct A000 writes in the hot path, and enough preprocessing in the assets to
keep the frame loop simple.
