Analysis model: gpt-5.5 xhigh

# Elements by Xography - Technical Dissection

## Scope

This is a static binary dissection of `Elements` by Xography, a PC/MS-DOS
mega-demo associated with Assembly 1993. The public production metadata places
it 3rd in the Assembly 1993 PC demo competition, while the archive text says
the released package is dated 28 October 1993.

Useful public references:

- Demozoo: https://demozoo.org/productions/6697/
- Pouet: https://www.pouet.net/prod.php?which=852
- Scene.org archive: https://files.scene.org/get/parties/1993/assembly93/demo/elements.zip
- Alternate Scene.org archive: https://files.scene.org/get/parties/1993/assembly93/demo/xgy_elem.zip

The usual caveat applies: this is not source code. The analysis is based on the
released archives, unpacked executables, resource inspection, and 16-bit x86
disassembly. Offset names such as `P1.bin:0x6eef` are offsets in the flattened
load image after stripping the MZ header from the unpacked executable.

## High-Level Shape

`ELEMENTS.COM` is not a small `.COM` program despite the extension. It is an MZ
executable with a PKLITE loader stub and a large appended self-extracting
archive. The outer file is a delivery shell:

1. The MZ/PKLITE stub starts.
2. The appended archive is unpacked to many smaller files.
3. Individual parts are launched through numbered executables and list scripts.
4. Each part owns its own VGA setup, timing, music calls, keyboard handling, and
   resource usage.

This is important because the demo is not one monolithic hand-written engine.
It is closer to a disk-magazine/mega-demo launcher: several packed DOS
executables, common support routines, shared music setup, and resource scripts.
Some inner loops recur across parts because they were probably linked from the
same C/assembly support code.

The archive credits extracted from the end part describe the intended sequence:

```text
Fire intro:          code Stefan/Uli, gfx Uli, music Chris Korte
Vector balls:        code Stefan, gfx Stefan, music Chris Korte
Cyber part:          code Uli, gfx Uli, music Stefan Brink
Water part:          code Yaka, gfx Phlegma, music Stefan Brink
Fractal/morph part:  code Uli, gfx Uli, music Stefan Brink
The tube:            code Yaka, gfx Phlegma, music Stefan Brink
End part:            code Patte, gfx Patte, music Stefan Brink
Music system:        Stefan and Uli
```

## Examined Files

The two public ZIPs both contain the same `ELEMENTS.COM` binary:

```text
33effaef152648c5caece8707996e512d9eae69fa7e3113229aadb5cd60cdf75  elements.zip
b3bea3936130498a7746e98f2be998ff368de2d5f79f5f1389a8ceb53c84b326  xgy_elem.zip
0a61855c3ad9a11c9991aecd96c5e582a89cd69e483491a9fb07aceb8d7250f5  ELEMENTS.COM
```

The useful payload is inside the MZ overlay:

```text
ELEMENTS.COM size:        1423107 bytes
Declared MZ image size:     17602 bytes
Overlay/archive size:     1405505 bytes
Header paragraphs:             10
Relocation count:               1
Initial CS:IP:          fff0:0100
Initial SS:SP:          044d:0200
PKLITE marker:          file offset 0x1e
```

The overlay starts with ARJ-style file headers (`60 ea`) rather than a normal
ARJ main header, so a stock `arj` tool does not list it directly. Prepending a
valid ARJ main header and then passing the resulting chain to `arj` recovered
108 files.

The extracted payload totals about 3.3 MB uncompressed:

```text
Numeric executables: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Support executables: _, __, &
Music modules:       AGAINST.MOD, SPHERE.MOD, HISTORY.MOD, MOVIN.MOD,
                     QUAECKY.MOD, THEEND.MOD, DANDLION.MOD
Major data files:    BALLS.DAT, SEQUENCE.000, FRACT005.RAW, TUNNEL.BMP,
                     BIGTUN.BMP, STARY.BMP, METFONT.BMP
Scripts:             LIST.000 through LIST.006
```

Most inner executables were PKLITE 1.14 packed. After unpacking:

| File | Packed bytes | Unpacked bytes | Role inferred from scripts/credits |
| --- | ---: | ---: | --- |
| `0` | 14381 | 213904 | Fire intro |
| `1` | 36463 | 90544 | Vector balls |
| `2` | 46215 | 205584 | Cyber/water resource-heavy part |
| `3` | 23427 | 42240 | Text/greetings using `METFONT.BMP` |
| `4` | 21605 | 33648 | Fractal/morph subpart |
| `5` | 42964 | 154240 | Fractal/morph subpart |
| `6` | 45827 | 164640 | Fractal/morph subpart |
| `7` | 21717 | 46160 | Tube/tunnel |
| `8` | 13282 | 49945 | End part with credits |
| `9` | 1769 | 4701 | Contact text helper |
| `_` | 23561 | 64928 | Music/config/support |
| `&` | 35322 | 85237 | Setup/menu/helper |
| `__` | 13216 | 13216 | Small uncompressed support executable |

The script files map the parts to music and resource sets. For example,
`LIST.001` runs executable `1` with `AGAINST.MOD` and `BALLS.DAT`; `LIST.005`
runs executable `7` with `HISTORY.MOD`, `BIGTUN.BMP`, `STARY.BMP`, and
`TUNNEL.BMP`.

## Resource Formats

The filenames are only partially honest.

Files named `.BMP` are not Windows BMP files. The useful ones begin with a
768-byte VGA palette followed by raw 8-bit pixels. `METFONT.BMP`, `STARY.BMP`,
and `BIGTUN.BMP` fit this pattern:

```text
palette: 256 entries * 3 bytes, 6-bit VGA RGB
pixels:  indexed 8-bit data
```

`TUNNEL.BMP` is larger and behaves like a texture atlas, approximately
256x512 pixels after the palette. `BIGTUN.BMP` is a 256x256 tunnel/star
texture. `STARY.BMP` is a star/nebula background.

Several `.RAW` files are custom `ROH` image files. `LOGO.RAW` and
`ELEMENTS.RAW` are 64062 bytes: a 62-byte header followed by 320x200 bytes of
indexed pixels. The header includes the string `(c) 1991 by Ulrich Walther` and
the marker `ROH`. Without the matching palette they render as grayscale masks,
but the image content is clearly the Xography/Elements title material.

`MODE13H.COM` is exactly the expected tiny helper:

```asm
mov ax,0013h
int 10h
int 20h
```

That helper only sets 320x200x256 mode and exits. The real parts do their own
VGA programming.

## Common Runtime Pattern

The unpacked numbered executables are mostly conventional real-mode DOS MZ
programs linked with compiler startup code. Several begin with a familiar
Borland-like prologue:

1. Query DOS version through `int 21h, AH=30h`.
2. Resize the current memory block with `int 21h, AH=4Ah`.
3. Probe or configure DOS allocation strategy/UMB linkage with `AX=5801h`,
   `AH=67h`, and `AH=48h`.
4. Save exception vectors such as 00h, 04h, 05h, and 06h.
5. Install local interrupt handlers.
6. Transfer to the part's actual main routine.

That startup code is easy to mistake for demo logic if the disassembly is read
from offset zero. The visual loops live much deeper in the flattened images,
usually around VGA setup, CRTC writes, `A000:` memory accesses, and retrace
polling.

The recurring hardware idioms are:

- `int 10h, AX=0013h` for base mode 13h.
- Direct writes to `A000:` for pixels.
- DAC writes through `3C8h/3C9h`.
- Retrace waits on status port `3DAh`, especially bit 3.
- Timer/PIT setup through ports `43h` and `40h`.
- Keyboard IRQ 9 handlers that read port `60h` and EOI the PIC with port `20h`.
- Sound Blaster/GUS support in the shared music system.

The support executable `_` contains strings for:

```text
SoundBlaster
SoundBlaster PRO
SoundBlaster ASP
ULTRASND
MPDEVICE
```

That makes `_` the strongest candidate for shared music/device support rather
than a visual part. It parses environment configuration and touches common SB
ports such as `220h`, `226h`, and `22Ch`.

## The Setup Helper `&`

The executable named `&` is best read as setup/menu/helper code, not as a demo
scene.

It enters BIOS mode `10h` rather than mode 13h, queries a ROM font pointer with
`int 10h, AX=1130h, BH=06h`, and draws text into planar VGA memory. The text
draw loop is a good example of early VGA support code:

1. Select the VGA plane with sequencer index 2 at `3C4h/3C5h`.
2. Fetch a character code from a string.
3. Multiply the character by 16 to locate a ROM font glyph.
4. Copy one glyph byte per scanline to `A000:DI`.
5. Advance `DI` by `0x4f` between rows, giving an 80-byte planar stride minus
   the byte already written.
6. Handle newlines by adding a larger screen-row delta.

The same helper reads keyboard scan codes and checks function keys/escape-style
inputs. This is launcher UI behavior, not a visual effect.

## Part 0 - Fire Intro

`LIST.000` loads:

```text
DANDLION.MOD
0
ELEMENTS.RAW
LOGO.RAW
```

The input set is small: one module and two title/logo raw images. The part is
packed much more aggressively than the later parts: 14381 bytes on disk becomes
213904 bytes unpacked. It also performs many DAC writes (`3C8h/3C9h`), which
fits a palette-driven fire/title effect.

The useful conclusion is not "this is one fire algorithm everywhere"; it is
that the first executable owns its own title image and palette phase. Unlike
the vector and tunnel parts below, the best static evidence here is the
resource pairing plus heavy DAC use. A true source-level reconstruction of its
fire recurrence would need a tighter dynamic trace around its frame loop.

## Part 1 - Vector Balls

`LIST.001` loads:

```text
AGAINST.MOD
1
BALLS.DAT
```

This is one of the clearest parts in the dump. It sets a non-standard VGA mode,
builds/draws projected objects, and uses a timer interrupt for music pacing.

### VGA Setup

The display setup at `P1.bin:0x6eef` starts with BIOS mode 13h and then
reprograms VGA into an unchained/Mode-X-like layout:

```asm
mov ax,0013h
int 10h

; Graphics Controller index 5: clear odd/even behavior.
out 3CEh,05h
in  al,3CFh
and al,0EFh
out 3CFh,al

; Graphics Controller index 6: clear odd/even addressing bit.
out 3CEh,06h
in  al,3CFh
and al,0FDh
out 3CFh,al

; Sequencer index 4: disable chain-4, keep extended memory enabled.
out 3C4h,04h
in  al,3C5h
and al,0F7h
or  al,04h
out 3C5h,al
```

Then it clears `A000:` with `rep stosw`, adjusts CRTC register `14h`, sets bit
6 in CRTC register `17h`, and writes CRTC offset register `13h = 0x2d`.

That is not ordinary linear mode 13h. The code is keeping 256-color VGA but
altering chain/word addressing and the CRTC stride. The immediate payoff is
page/stride control for fast clears and page flipping without using a full
320-byte conventional scanline layout in every operation.

### Retrace Helpers

The part has three tiny retrace/status helpers:

```asm
P1.bin:0x6f9c: wait while (in 3DAh & 08h) == 0
P1.bin:0x6fa7: wait while (in 3DAh & 08h) != 0
P1.bin:0x6fb2: wait for status bit 0
```

The first two form the normal "wait until vblank starts / wait until it ends"
pair. The third waits on the display-enable/status bit and is used for tighter
raster or palette timing.

### Palette Streaming

`P1.bin:0x6fbd` streams a palette packet:

```text
byte 0: starting DAC index
word 1: number of entries
then:   count * 3 RGB bytes
```

The loop writes the start index to `3C8h`, increments to `3C9h`, and sends RGB
triples. `P1.bin:0x6fe5` wraps this with a windowing rule that limits updates
to a palette range of `0x50` entries. `P1.bin:0x7059` writes a single DAC entry
but waits on `3DAh & 9` before the final component write, which is a raster-ish
timing trick: the code is not merely setting colors, it is trying to place part
of a color change at a repeatable beam position.

### Timer Calibration and Music IRQ

`P1.bin:0x71a0` measures a timer interval against vblank:

1. Wait for non-vblank.
2. Wait for vblank.
3. Program PIT channel 0, mode 3:

   ```asm
   out 43h,36h
   out 40h,0ffh
   out 40h,0ffh
   ```

4. Wait for another vblank transition.
5. Latch channel 0 with `out 43h,06h`.
6. Read low/high counter bytes from port `40h`.
7. Store `0xffff - counter` as the per-frame reload value.

The IRQ handler at `P1.bin:0x71e8` saves registers, switches `DS` to the part's
data segment, EOIs the PIC, calls two far music routines, reprograms the PIT
with the measured reload, restores registers, and returns with `iret`.

That gives the part an adaptive timer value derived from the current video
timing. It also explains why the demo is known to run badly on modern/fast
setups: timing is tightly tied to real VGA/PIT behavior.

### Projection and Rotation

The vector transform starts around `P1.bin:0x671b`. The code reads an object
record containing base coordinates, angles, point count, and per-point fields.
It uses sine/cosine tables at approximately `0x7417` and `0x7617`. Angles are
quarter-indexed:

```text
table_index = (angle >> 2) * 2
```

The rotation math is 16-bit fixed point:

1. Load a coordinate pair.
2. Fetch sine/cosine words.
3. `imul` each coordinate by a table word.
4. Add/subtract high halves.
5. Shift/rotate the combined result twice.
6. Keep the high word as the rotated coordinate.

The code repeats this pattern for multiple axes. It is a conventional
fixed-point Euler rotation pipeline, but the important detail is that it keeps
the intermediate products in 16-bit/32-bit pairs and aggressively discards low
precision. That is exactly what you expect in a real-mode 386-era vector loop:
enough precision for smooth balls, no floating point, no per-pixel divides
except the final projection.

The perspective projection at `P1.bin:0x6de7` is explicit:

```text
ztemp    = z + 250
x_screen = -((x * -250) / ztemp) + 160
y_screen =  ((y * -250) / ztemp) + 100
```

It clips when `z <= -50` or `y <= -95` and writes a sentinel value for clipped
records. Output records are stepped by `0x1e` bytes, so the projected record is
30 bytes.

### Z-Sort Insertion

Around `P1.bin:0x6d7e` the part builds a depth-ordered linked list. It walks a
list rooted near `0x781b`, compares the current depth against the stored depth
field at offset `+0x06`, and inserts the new record at the right point. The
sentinel depth is `0x8000`.

That means the balls are not simply drawn in input order. The code builds a
sorted list per frame, then renders through that list. On a vector-ball part
this matters because overlapping balls or line/sprite elements need stable
front-to-back/back-to-front ordering to look coherent.

### Line Drawing

`P1.bin:0x70b1` is a Bresenham-style byte plotter. It computes:

```text
screen_offset = y * 320 + x
```

Then it compares `abs(dx)` and `abs(dy)` to choose the major axis. Each plotted
pixel writes color `DL` to `ES:[DI]`. Depending on the error accumulator, `DI`
increments by either 1 or by `0x140` (320 decimal). The `0x140` stride tells us
this routine thinks in conventional 320-byte scanlines even though the VGA mode
has been tweaked elsewhere for paging/stride behavior.

### `BALLS.DAT`

`BALLS.DAT` is 327985 bytes and starts with:

```text
53 43 52 49 70
S  C  R  I  p
```

It is not just bitmap data. The code consumes structured records and scripts
from it: object fields, point counts, target values, and animation data. Later
logic in the `0x78xx` range repeatedly increments/decrements current values
toward targets, which is the characteristic shape of a scripted morph/sequence
driver.

## Part 2 - Cyber/Water Material Bank

`LIST.002` is the biggest script:

```text
SPHERE.MOD
2
ULI.3D
MOND.3D
FBUILD1.3D
FLOOR.3D
RULI001.3D
RULI002.3D
SHIPHST.3D
...
SEQUENCE.000
V.RAW
SEITE1.RAW
MOND.RAW
...
A01.RAW through A29.RAW
SKYSCR1.RAW
SKYSCR2.RAW
ADVERT1.RAW
ADVERT2.RAW
```

This part is not a tiny single-effect program. It is a resource-heavy 3D/raw
image part, probably covering the credited cyber/water material.

### Startup and Camera-Like State

The main visual setup around `P2.bin:0x951d` enters mode 13h, allocates a large
block, initializes state variables, and writes several fixed-point positions:

```asm
mov ax,0013h
int 10h

; allocate/init large buffer through far runtime call
push 01000000h
lcall ...

; initial position-ish values
10 * 0x00a8 -> stored at 0xb6ac and 0xb6b0
fixed-point copies shifted left by 8 into data segment fields
```

The code then initializes values such as `0x23`, `0x54`, and `0xff38`, calls
helper routines around `0x8867`/`0x8769`, and enters a longer frame sequence.
The exact semantic names are not recoverable from static code alone, but the
data shape is camera/object state: 16-bit coordinates expanded to fixed-point
longs, per-frame state variables, and references to many `.3D` resources.

### Shared Bitmask Sprite/Text Writer

The strongest inner-loop anchor in P2 is the writer at `P2.bin:0x4435` through
`0x44e7`. The same loop shape also appears in P5 and P6.

The loop consumes a zero-terminated stream of glyph/sprite bytes. Each source
byte describes an 8-pixel column/row mask. For each byte:

1. Read a signed byte from the source stream.
2. Multiply it by a BIOS/system value from the low-memory data area
   (`ES:010Ch/010Eh` are read through segment zero).
3. Resolve a bitplane/mask address.
4. Set `mask = 0x80`.
5. For eight bits:

   ```text
   if mask_bit_set(source_mask_byte):
       write foreground color to A000:[base + x + y*320]
   else:
       write background color to A000:[base + x + y*320]
   y += 1 scanline
   mask >>= 1
   ```

6. Advance the x coordinate by 1 for the next bit column.
7. After eight bits, advance the caller's x by 8.
8. Stop when the next source byte is zero.

The important instructions are:

```asm
P2.bin:0x4490  load bitmask source byte
P2.bin:0x4496  test mask bit
P2.bin:0x44a0  mov ax,0a000h
P2.bin:0x44a8  write foreground color
P2.bin:0x44b2  mov ax,0a000h
P2.bin:0x44ba  write background color
P2.bin:0x44be  add cx,0140h       ; next scanline
P2.bin:0x44c8  shr mask,1
```

This is a compact 1-bpp-to-8-bpp renderer. It is probably used for text, masks,
or small monochrome assets, not for the main 3D fill.

### Page/Window Control

P2 has helpers that shift a page index into a display address:

```asm
P2.bin:0x4540  page_index << 14
P2.bin:0x4579  page_index << 14, plus 0x0c
P2.bin:0xaad7  write CRTC start address high/low registers 0Ch/0Dh
```

That is page flipping or viewport scrolling through VGA memory. The code writes
the CRTC start address only when a flag at `0xb85e` is nonzero, then waits for
vertical retrace and reprograms the PIT.

### Scheduler/Timer

P2 has the same vblank/PIT timing idiom as P1:

```asm
P2.bin:0xaa35  wait until vblank bit set
P2.bin:0xaa3e  wait until vblank bit clear
P2.bin:0xaa47  calibrate PIT interval against vblank
P2.bin:0xaafa  wait vblank, set PIT reload, run scheduled callbacks
```

The callback scheduler at `P2.bin:0xab19` scans 32 slots:

```text
slot layout: 8 bytes
if slot enabled:
    if countdown == 0:
        far-call slot callback
        store returned delay
    else:
        countdown--
```

So P2 runs timed subtasks from a table rather than baking every animation into
one giant loop. That fits the script-heavy nature of `LIST.002`.

## Parts 4, 5, and 6 - Fractal/Morph Material

`LIST.004` loads three executables in a row:

```text
MOVIN.MOD
4
5
6
VIDEO.BMP
V.RAW
FRACT.3D
FRACT005.RAW
```

The resource set points at a fractal/morph sequence:

- `FRACT005.RAW` is 480800 bytes, much larger than a single 320x200 image.
- `FRACT.3D` is a small 3D description.
- `VIDEO.BMP` is a compact palette+pixel strip.
- `V.RAW` is a custom raw image.

### Shared Unchained VGA Setup

P5 and P6 both contain the same unchained VGA setup as P1:

```asm
mov ax,0013h
int 10h
GC index 5: clear 0x10
GC index 6: clear 0x02
SEQ index 4: clear chain-4, set extended memory
CRTC index 14h: clear 0x40
CRTC index 17h: set 0x40
SEQ map mask: 0x0f
clear A000 with rep stosd, CX=0x4000
```

That means the fractal/morph material also works in tweaked VGA, not plain BIOS
mode 13h.

### Sprite/Text Writer Reuse

P5 at `0xd3e5` and P6 at `0xdb1b` contain the same 1-bpp mask renderer described
for P2. The only differences are local base variables:

```text
P5 base variable: 0x2a90
P6 base variable: 0x2a8e
stride:           0x140 bytes per scanline
foreground arg:   stack +0x0e
background arg:   stack +0x10
```

This reuse is a good boundary marker: it is not proof that the visual effects
are identical, only that the same linked support routine is present in multiple
parts.

### Palette and Keyboard Support

P5 has a palette single-entry writer at `0x103c0`:

```asm
out 3C8h, index
out 3C9h, red
out 3C9h, green
wait until (in 3DAh & 1) != 0
out 3C9h, blue
```

It also has a palette block streamer at `0x103e6`, reading entries from a local
table at `0xaaa8`.

The keyboard IRQ handler at `P5.bin:0x10520` is conventional but useful:

1. Read scan code from port `60h`.
2. Store key state in a table.
3. Track modifier bits for shift/control/alt.
4. On make codes, map `(modifier,state)` pairs through a table.
5. Push translated values into a small circular key queue.
6. Toggle port `61h` bit 7 to acknowledge the keyboard controller.
7. EOI PIC with `out 20h,20h`.
8. Return with `iret`.

This is not visual logic, but it tells us the parts can react to keys without
calling BIOS keyboard services inside the frame loop.

### Partial Clear / Page Clear

P5 at `0xd539` clears a rectangular region in tweaked VGA:

```text
page_offset = page_index << 15
map mask    = 0x0f
rows        = 0x00a0
per row     = 0x28 dwords = 160 bytes
row delta   = 0x50 bytes in address space
```

Because unchained VGA stores four pixels per address across planes, 160 byte
addresses with all four planes enabled correspond to a 640-pixel-wide logical
coverage or a page-specific clear region depending on the CRTC layout. In
practice this is a fast page/area clear, not a pixel-by-pixel wipe.

## Part 7 - The Tube

`LIST.005` loads:

```text
HISTORY.MOD
7
BIGTUN.BMP
STARY.BMP
TUNNEL.BMP
```

This is the tunnel/tube part. It is the other very clear inner loop.

### Mode and Palette

P7 has simple mode setters at `0x3648` and `0x364e`:

```asm
mov ax,0013h
int 10h
lret
```

The palette streamer at `0x3654` writes a caller-selected start index and count
to the DAC. A count byte of zero is treated as 256 entries by setting `CH=1`
while leaving `CL=0`, a compact 16-bit loop trick.

P7 also contains two long palette fade routines:

- `0x3805`: fade from bright toward normal/dark by subtracting a decreasing
  bias.
- `0x386a`: fade in by increasing the bias from 0 to `0x40`.

Both write RGB components through `3C8h/3C9h` and wait on `3DAh & 1` between
some component writes, which paces the DAC stream against display status.

### Distance/Mapping Table Builder

`P7.bin:0x3990` builds a 120x200-ish lookup pattern into a buffer. The constants
are revealing:

```text
left margin / start offset: 0x28
active width:              0x78  (120)
active height half:        0x64  (100)
row padding:               0x50  (80)
```

The loop computes ratios using `mul`/`div` against the current row/column
distance and writes palette/lookup bytes. It writes one half of a symmetric
shape, inserts two solid rows (`0x40` and `0xbe`), then writes the other half.

This is not the final textured tunnel itself. It is a precomputed mapping or
distance/intensity table: a cheap per-frame renderer can later use it to look up
texture coordinates or colors without doing divides for every pixel.

### Main Tunnel Renderer

The renderer at `P7.bin:0x583a` writes directly to `A000:` and is heavily
unrolled. The structure is:

```asm
mov ds,0
mov es,0a000h
di = 0x1928
fs = table_segment_1
gs = table_segment_2
edx = base_pointer

limit1 = edx + 0x25d78
limit2 = edx + 0x10000
limit3 = limit2 + 0x0f600
texture_ptr = edx + 0x6200
background_ptr = edx + 0x68000
```

Then each pixel-ish step does:

```asm
si = fs:[ebx]                 ; 16-bit lookup index
al = [texture_ptr + si]       ; texture sample
if al == 0x70:
    al = [background_ptr + di]
es:[di] = al
di++
ebx += 2
```

The code repeats that exact body many times inline rather than using a small
loop. The sentinel color `0x70` acts as transparent tunnel texel: when the
sample equals `0x70`, the renderer falls back to the background/star byte at the
same screen position.

That is the core tube effect:

1. Precompute a lookup table that maps screen positions to texture offsets.
2. Animate the base pointer/phase so texture coordinates move.
3. For each visible pixel, fetch a texture sample by table index.
4. Treat color `0x70` as transparent.
5. Otherwise write the tunnel sample directly into `A000:DI`.

The start offset `0x1928` is screen position 6440 decimal. Dividing by 320 gives
row 20 with x offset 40. So the active tunnel area starts around `(40,20)`,
matching the earlier 120-wide centered mapping logic.

## Part 8 - End Part

`LIST.006` loads:

```text
THEEND.MOD
8
```

P8 is compact and unusually readable. It contains the final image, fade,
credit text, and a small projected particle/starfield.

### Startup and Keyboard Hook

At `P8.bin:0x0000`:

```asm
mov ah,4Ah
mov bx,0c35h
int 21h                  ; shrink memory block

mov ax,0052h
mov ds,ax
mov es,ax
```

It then saves the old IRQ 9 vector from the IVT entries at `0000:0024` and
`0000:0026`, installs its own handler at `0x00be`, and restores the old vector
on exit.

The handler itself is minimal:

```asm
in  al,60h               ; read scan code
mov [state],al
mov al,20h
out 20h,al               ; EOI PIC
iret
```

No BIOS keyboard call is used during the frame loop.

### Image Copy

At `P8.bin:0x00f8`:

```asm
mov ax,0013h
int 10h
call write_palette

mov ax,0a000h
mov es,ax
si = 0x0650
di = centered_screen_offset
cx = 0x003a rows
```

Each row copies `0x48` dwords, or 288 bytes, then advances `DI` by `0x20` to
skip from 288 copied pixels to the next 320-byte screen row. So the image block
is 288 pixels wide and 58 rows tall. It is horizontally centered by leaving
16 pixels unused on each side:

```text
320 - 288 = 32
32 / 2    = 16
```

### Vblank and Phase Update

`P8.bin:0x0124` is the frame wait:

```asm
wait until (in 3DAh & 08h) == 0
wait until (in 3DAh & 08h) != 0
phase += phase_delta
```

The phase state lives around `0x0be2/0x0be4`. This is the frame clock for the
end animation.

### Palette Fade

P8 keeps current and target DAC buffers. `0x0139` fades current toward target:

```text
for each DAC byte:
    if current < target: current++
    if current > target: current--
write current buffer to DAC
```

`0x016e` fades out by decrementing every nonzero DAC byte. `0x017e` is the
actual DAC stream:

```asm
mov dx,3c8h
xor al,al
out dx,al
inc dx
rep outsb                ; RGB bytes to 3c9h
```

The fade is bytewise, not color-entry based. RGB components converge
independently by one VGA DAC unit per call.

### Particle/Starfield Transform

`P8.bin:0x0186` is a 3D rotation helper using word tables at `0x0000` and
`0x0080`. It multiplies coordinates by table entries, combines the products,
and arithmetic-shifts the result down. The output rotated `x/y` values return
in `BX/CX`.

The transform loop at `P8.bin:0x01d5` walks 300 triples:

```text
for di = 0; di < 0x708; di += 6:
    source x,y,z = [0x0280 + di]
    rotate x/y through 0x0186
    store transformed x at [0x0be5 + di]
    store transformed y at [0x0be7 + di]
    store transformed z at [0x0be9 + di]
```

`0x708 / 6 = 300`, so the point count is exact.

The renderer at `P8.bin:0x0202` does the perspective projection:

1. If the old pixel slot contains a color >= `0x12`, erase it.
2. Require `z > 100`.
3. Project:

   ```text
   screen_x = ((transformed_x << 8) / z) + 160
   screen_y = ((transformed_y << 8) / z) + 100
   ```

4. Clip to `0 <= x < 320`, `0 <= y < 200`.
5. Convert `y` to a screen row offset through a scanline table at `0x12ed`.
6. Compute color as `(z >> 8) + 0x12`.
7. Plot only if the target screen byte is zero.
8. Store the new screen address in a table at `0x147d + bp` for next-frame
   erase.
9. If `z` is too small, wrap it to `0x1000`.

This is a classic sparse-particle loop: erase old positions, rotate/project,
plot new positions, and keep per-point previous screen addresses. It avoids
clearing the whole screen every frame.

### Credit Text Drawing

From `P8.bin:0x02a1` onward, the code steps through scripted credit text and
copies glyph blocks into the image area. The visible strings in the binary
include the part credits listed at the top of this file.

The glyph copy loops move four dwords per row and then add a row delta around
`0x130`. That is a block-font writer, not BIOS text. The end part is still
fully graphical mode 13h.

## Part 9 - Contact Helper

Executable `9` is not referenced by the visible `LIST.000` through `LIST.006`
scripts. It contains a contact screen:

- Switches to text mode 3.
- Reads the current first 16 DAC entries with `3C7h/3C9h`.
- Builds a white palette target.
- Fades the text palette with the same one-step component logic.
- Copies `0x3c0` dwords to `B800:` text memory.

It is probably called from an end/menu path or was left as an optional helper.
The content is contact information for Xography. I did not reproduce the phone
or address data here because it is not needed for the technical analysis.

## What the Demo Is Really Doing

`Elements` is a collection of independent DOS parts glued by archive/script
infrastructure. The most concrete visual loops are:

- P1 vector balls: fixed-point rotation, perspective division, z-sorted output
  records, Bresenham plotting, vblank-calibrated PIT music timing.
- P2/P5/P6 support rendering: reused 1-bpp mask-to-8-bpp VGA writer, page
  address helpers, timer callback scheduler, keyboard IRQ queue.
- P7 tube: precomputed mapping table, unrolled texture lookup, transparent
  sentinel color `0x70`, centered active viewport.
- P8 end: mode 13h image copy, bytewise DAC fade, 300-point rotated/projected
  particle field with previous-pixel erase.

The common mistake would be to describe it as one core 3D engine. The binary
shape argues against that. There are shared support routines, yes, but the
numbered parts are separately packed programs with their own setup and effect
loops. The commonality is pragmatic DOS demo infrastructure: VGA mode setup,
palette routines, interrupt/timer support, keyboard handlers, and small
rendering helpers.

## Timing Sensitivity

The demo's reputation for running too fast on modern machines is consistent
with the code. Multiple parts busy-wait on `3DAh`, calibrate PIT intervals
against vblank, and install their own timer handlers. That works on period VGA
hardware where the beam and PIT behavior are predictable. It is fragile under
emulation, Windows DOS boxes, fast CPUs, and non-VGA-compatible timing.

The inner loops are optimized for the assumptions of the time:

- Poll hardware directly instead of asking DOS/BIOS.
- Avoid full-screen clears when a previous-pixel erase table works.
- Use bytewise palette fades as animation.
- Use precomputed tables for tunnel projection.
- Use fixed-point integer math and one divide per projected point, not per
  pixel.
- Use unchained VGA and CRTC start-address changes for page/window control.

That is why `Elements` feels like a 1993 mega-demo rather than a later
protected-mode engine demo. It is a set of tight, direct, hardware-facing loops
with a lot of small local tricks, wrapped in a very file-heavy delivery format.
