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

Sonic Demo A by Sonic Inc. - Technical Dissection

Scope and correction boundary

This is a binary- and runtime-led pass over Sonic Demo A by Sonic Inc., released for MS-DOS in December 1991. The archive sits in Hornet's 1992 tree, but Demozoo and Pouet both identify it as a December 1991 production.

The earlier article correctly recognized a packed MZ, appended resources and banked SVGA output, but stopped before the active machinery and made several important mistakes. This pass corrects them:

No demo audio was monitored or auditioned. Runtime capture kept every host audio backend disabled; the sound code below is a static ownership and lifecycle analysis only. Historical personal contact text in the internal script is not reproduced.

Sources and exact artifacts

The examined archive and executable are:

3652753e91f3b8b754ac8859246295d8da465cabe06c6f27ebbace67811f93f1  sonic_a.zip
8e5a88fb31d64d890ebc389c11b7b3d5f0d171416cb80c9c927955e302d621dc  intro.exe

The ZIP also contains demosite.com. An Escape CD copy has a different ZIP wrapper and Scene.org sidecar, but the same INTRO.EXE hash.

Direct silent runtime and the compatibility result

I ran the untouched packed release under DOSBox-X 2024.03.01 with a 386 prefetch core, fixed 25,000 cycles and all host audio disabled. DOSBox-X was started with -silent, with diagnostics redirected to an ignored log. Capture timestamps begin at the first AVI frame, not at an inferred demo cue.

The video backend changes the result:

DOSBox-X SVGA device Observed result Code-level reason
S3 / VBE 231.47-second black 720x400 capture, repeated writes into the ROM area VBE success returns backend FFh, indexes beyond the callback table and executes unrelated text bytes
S3 with the VBE information-buffer compatibility toggle invalid-opcode / INT 6 path it still does not select a valid VBE renderer
ET4000 native 640x480 presentation succeeds vendor fallback selects backend 16, setup 002Eh, callback 1632h

The successful full ET4000 capture is 242.674 seconds. A queued Escape did not end it because the program does not recognize Escape semantically; it compares the raw port-60h byte with a startup snapshot, and a matching or already drained scan code can be missed. The run was stopped externally.

This continuous 00:03-00:12 excerpt owns exactly the transition discussed below: the LOAD/G full frame is followed by the M640/G column reconstruction. It is not being used as evidence for the later scroller compositor.

Direct silent ET4000 runtime transition from LOAD/G to the M640/G banked column reveal

At 00:15 the main M640/G image is stable and the separately composited rolling strip has begun at the upper-right text rectangle.

Direct silent ET4000 runtime at 00:15 with the M640 background and live rolling-strip rectangle

The public Demozoo still shows the same main 640x480 composition more fully. It is retained as a public visual reference, not as timing evidence.

Public Demozoo screenshot of Sonic Demo A's main M640 composition

Packed carrier and restored address model

The original MZ declares only a 14,366-byte load file while physically containing 404,596 bytes:

declared MZ size       00381Eh = 14,366
physical file size     062C74h = 404,596
appended bytes         05F456h = 390,230
header                 32 bytes
relocations            0
CS:IP                  0368h:000Eh
physical entry         0036AEh

Its TBS!-marked stub moves the compressed load image upward and expands it downward. The bit reader uses a 16-bit reservoir in BP; a set control bit copies one literal, while a clear bit enters one of two backward-match forms. The long form derives a negative distance and a short or extended length:

3728  lodsw
3729  mov  bx,ax
372B  mov  cl,03h
372D  shr  bh,cl
372F  or   bh,E0h       ; sign-extend backward distance
3732  and  ah,07h       ; short length code
3735  je   extended
3737  mov  cl,ah
3739  inc  cx
373A  inc  cx

373B copy:
      mov  al,es:[bx+di]
      stosb             ; overlap is intentional
      loop copy

Extended length zero ends the stream. Extended length one rebases DS:SI and ES:DI across a 64 KiB boundary. The tail restores SS:SP and jumps through the reconstructed far entry.

UNP produces this useful static-analysis image:

restored size           066D1Eh = 421,150
SHA-256                 1749b9495a9c342fb6d16775e02f45ac6f74b1a38ccae0618fdbbf4872c106fe

000000h..00007Fh        128-byte MZ header
00001Ch..000077h        23 relocation records
000080h..0078C7h        30,792-byte file-backed load image
0078C8h..066D1Dh        unchanged 390,230-byte appended container

header SHA-256          61b8c29507bef91b03384bdc99fe40a43824e35b5bd918ad42b7fa1a7386b148
load-image SHA-256      e74bbf57821cd299ea077bc5a8d111f99e713039390cfddcbbf99f67a5ba31f1
overlay SHA-256         66fb18812defbed7842789016e19b722f06004b71f3ac19a0d505ccf340d7dee

The main resident data segment is DS = CS + 0179h. In restored-file coordinates:

CS:x  -> file 0080h + x
DS:x  -> file 1810h + x

Logical segment 0785h starts eight bytes beyond the file-backed image and therefore denotes DOS-provided zero-fill storage, not bytes in the EXE.

Why the restored EXE is not runnable

0818h reconstructs its pathname from the PSP environment, opens itself and reads MZ fields e_cblp/e_cp. It calculates:

overlay_base = (e_cp - 1) * 512 + e_cblp;

It does not implement the normal e_cblp == 0 convention, validate the MZ signature or require a full four-byte header read.

This calculation does find the moved first descriptor:

packed first descriptor    00381Eh
restored first descriptor  0078C8h
movement delta             0040AAh

But each descriptor's +06 field is an absolute physical next-record offset. UNP does not add 40AAh to those links:

V001 stored next pointer   012EBEh
actual restored M640       016F68h

The restored program consequently reaches its first descriptor, then seeks into payload data for the second. The packed file must be used for runtime.

Resource grammar and complete ownership map

V001 is the key of the first record, not a container header. Every record begins with this 12-byte descriptor:

+00  char[4]  case-sensitive key
+04  byte     class: V, G or M
+05  byte     subtype
+06  dword    absolute physical offset of next descriptor
+0A  word     member count

A member is:

+00  word     packed byte count P
+02  word     unpacked/allocation byte count U
+04  byte[P]  payload

P == U is raw; otherwise the payload has the compressed-stream header described next. The accounting closes exactly:

5 descriptors * 12          60
44 member tuples * 4       176
member payloads         389,994
total                   390,230

There are 21 raw and 23 compressed members:

Key/class Packed descriptor Restored descriptor Stored next Members Expanded role
V001/V0 00381E 0078C8 012EBE 12 four repeated segmented-voice service groups
M640/G1 012EBE 016F68 03244C 7 metadata, 768-byte palette, five 61,440-byte pixel bands
LOAD/G1 03244C 0364F6 035A6F 7 metadata, 384-byte palette, five 61,440-byte pixel bands
SND1/M0 035A6F 039B19 05DE67 17 music/player state, code and sample resources
ASTA/V0 05DE67 061F11 062C74 1 final segmented voice

M640 metadata begins SONICS-BIG-VGAS and explicitly contains 640, 480, 8. Its five bands total exactly:

5 * 61,440 = 307,200 = 640 * 480

LOAD has the same five-band geometry. Four bands are highly repetitive; the middle band owns most of its substantial central artwork. SND1 does not have image geometry or a palette, and ASTA is a framed, near-centred byte stream rather than indexed pixels.

The execution order is not directory order:

LOAD/G -> V001/V -> M640/G -> SND1/M -> ASTA/V

Allocation paths and failure boundaries

0875h allocates each unpacked member with:

paragraphs = (unpacked_size + 15) >> 4;
int21_AH48(paragraphs);

The addition is 16-bit and can wrap for malformed sizes.

Raw members use one DOS read and require both clear carry and the exact byte count. Compressed reads are weaker: 0C4Ah discards DOS carry and the actual AX, forces carry clear and reports the requested size, so truncated input can consume stale buffer bytes.

Resource decoder inner loop

Every compressed member begins with a 46-byte structure:

+00  word   header length, always 002Eh
+02  word   0201h
+04  word   000Bh
+06  word   000Ah
+08  word   flags, zero in all 23 streams
+0A  word   method, 0006h in all 23 streams
+0C  dword  varying metadata
+10  dword  expected expanded CRC-32
+14  dword  compressed stream bytes
+18  dword  stated expanded bytes
+1C..2D     fixed/reserved fields

For every release member, outer packed size is 46 + inner packed size and outer unpacked size equals the inner expanded size, although the loader itself does not verify those equalities.

The decoder:

  1. clears 16 KiB of stack scratch at SS:0014;
  2. reads the variable header at SS:041E;
  3. builds the reflected CRC-32 table with polynomial EDB88320h;
  4. expands run-length-coded lengths into two 64-symbol canonical Huffman alphabets;
  5. optionally builds a 256-symbol literal tree when flag bit 2 is set;
  6. consumes the payload least-significant bit first;
  7. dispatches one-bit literal/backreference tokens;
  8. copies a match from DI - decoded_distance - 1 with overlapping REP MOVSB;
  9. flushes output chunks while retaining history and folding every emitted byte into CRC-32;
  10. inverts and compares the final CRC, executing INT 3 on mismatch.

All release flags are zero, so literals are raw eight-bit values and the active window is:

4 KiB retained history + 8 KiB output chunk

Flag bit 1 would swap that to 8 KiB history plus a 4 KiB output chunk, but no shipped member selects it.

The decoder does not enforce the inner expanded-size field. Header short reads, Huffman impossibilities and CRC failure do not converge on normal cleanup; several malformed states deliberately execute INT 3.

Top-level controller and hand-offs

The restored loader's important entry points are:

Address Role
0000:001D startup and fixed resource/effect schedule
0000:0139 CPU classification and speed calibration
0000:0214 / 0254 palette transitions
0000:02E0 text/music controller and silent fallback
0000:0346 fixed far visual callback
0000:038A / 03FA transparent strip compositor / script producer
0000:05B9 / 05E8 five-bank clear / main column transform
0000:0753 segmented image-to-SVGA copy
0000:090F resource lookup/type dispatcher
0000:118E / 15EE SVGA detection / backend selection
0000:15DA selected SVGA bank-switch wrapper only
04BF:0B9F segmented-voice command dispatcher
060D:0069 music-side visual service wrapper
060D:00A0 lower point-field service
060D:08FD sound query or synchronous music/controller runner

The complete normal schedule is:

open own packed executable; decode resident script
query Sound Blaster ownership
detect video backend; select bank callback and 640x480 setup
save current BIOS mode; enter selected mode; classify CPU

load LOAD/G
linear bank-copy its five pixel segments
free LOAD/G segments
run the first palette transition

load V001/V
configure/start segmented voice when hardware exists

load M640/G
clear five apertures
install M640 palette
run the 640x480 column transform
free M640/G pixel segments

load SND1/M only on the 386-class path
stop and free V001/V
run music/text controller, or fixed silent visual loop on failure/pre-386

load ASTA/V; start final segmented voice
fade toward black and poll until its status clears
free ASTA/V without a final explicit voice-stop command

restore saved mode; close self; terminate

Broken VBE path and real vendor fallback

118Eh first performs legacy VGA checks, then calls INT 10h AX=4F00h. Counterintuitively:

if (AX == 0x004F && buffer_starts_with("VESA"))
    return 0xFF;

No 4F01h, 4F02h or 4F05h call follows. 15EEh then zero-extends backend FFh and indexes a 21-entry table:

table address = 1586h + 00FFh * 4 = 1982h
interpreted callback = 5345h
interpreted setup    = 4449h

Those are text bytes beyond the table. The resulting path attempts BIOS mode 49h with BX=44h and later calls unrelated memory as the bank switcher. That is the direct explanation for the failed S3/VBE capture.

The fallback probes ATI, Everex, Trident, Paradise, Chips & Technologies, Tseng, Ahead, Oak, Genoa and Video7-style interfaces. Only ten backend IDs have populated four-byte callback,setup records:

ID Family Callback Setup
2 Ahead B 1692h 0061h
6 Chips & Technologies 16DBh 0079h
7 Everex 165Ch 3070h
8 Genoa 16B6h 002Eh
11 Paradise 163Fh 005Fh
12 Trident 1 16EEh 005Dh
13/14 Trident 2/3 1740h 005Dh
15 ET3000 1621h 002Eh
16 ET4000 1632h 002Eh

On ET4000, 1632h packs the same logical 64 KiB bank into both nibbles:

out8(0x03CD, bank | (bank << 4));

15DAh merely preserves ordinary registers, loads the bank byte from CS:1580 and calls this selected near callback. It is not the visual, music or voice service function.

Exact framebuffer geometry and clear

The visible surface is:

640 * 480 * 1 = 307,200 = 4B000h bytes

banks 0..3       all 65,536 bytes visible
bank 4           offsets 0000h..AFFFh visible

05B9h clears five complete apertures:

for (bank = 0; bank < 5; bank++) {
    select_bank(bank);
    memset16(A000_0000, 0, 0x8000);
}
select_bank(0);

This writes 50000h bytes. Bank 4 offsets B000h..FFFFh, the final 5000h bytes, are outside the visible frame.

The simpler 0753h blitter consumes segment,count pairs terminated by FFFFh. Each source starts at offset zero. It splits a record once if DI + count wraps, increments the software bank, calls 15DAh, and copies the remainder. A 16-bit record cannot cross more than one boundary, so that single split is sufficient. The routine leaves the final bank selected.

The 640x480 column transform

M640/G supplies five segments of 96 rows:

5 * 96 * 640 = 5 * F000h = 4B000h

05E8h traverses columns first, not rows. The active normalized loop is:

configure_cpu_scaled_helper();

for (x = 0; x < 640; x++) {
    wait_until_vertical_retrace_is_high();

    for (y = 0; y < 480; y++) {
        chunk = y / 96;
        src = segment_table[chunk].segment
            + (y % 96) * 640 + x;

        linear = y * 640 + x;
        bank = linear >> 16;
        di = linear & 0xFFFF;

        select_bank(bank);              // all 307,200 primary pixels
        A000[di++] = *src++;
        emit_cpu_scaled_trail(src, di, x, y);
    }
}

There are 640 retrace-high waits, one before each column. The wait does not first wait for an existing retrace to end, so a call made while bit 3 is already high returns immediately.

The primary write paints the source's next vertical column. The helper then lays source-derived pixels to its right. Later primary columns overwrite much of that trail, so the visible result is a progressive reconstruction rather than 307,200 independent distortion kernels.

CPU-scaled trail helper

CPU class DS:02D8 selects:

Class Initial trail Source lead Taper starts Pattern bytes
0 helper patched to RET - - -
1 16 32 x > 605 16
2 32 64 x > 573 32

The helper is:

if (di == 0) {
    bank++;
    select_bank(bank);
}

if (x > taper_threshold && y == 479) {
    source_lead--;
    if (toggle)
        trail_count--;
    toggle ^= 1;
}

si += source_lead;

for (i = 0; i < trail_count; i++) {
    A000[di++] = DS[si];

    if (di == 0) {
        bank++;
        select_bank(bank);
    }

    si -= pattern[i];       // values 0, 1 or 2
}

Class 1 uses:

01 01 00 02 01 01 00 02 01 01 00 02 01 01 01 01

Class 2 uses:

01 02 00 02 00 00 02 02 00 01 01 01 01 01 01 01
01 01 01 01 01 01 01 00 01 02 01 00 00 02 02 01

Deterministic final-pixel overrun

Both nonzero classes taper to zero, then underflow on the final two columns:

x=638: source lead 0000h -> FFFFh; trail count remains 0000h
x=639: source lead FFFFh -> FFFEh; trail count 0000h -> FFFFh

The final primary pixel correctly lands at linear 4AFFFh, bank 4 offset AFFFh. The helper then performs 65,535 unintended writes:

bank 4 B000h..FFFFh      20,480 bytes
bank 5 0000h..AFFEh      45,055 bytes

It also reads beyond the 16- or 32-byte pattern because the loop has no pattern wrap. Total writes are:

class 0      307,200
class 1    5,091,823
class 2    9,630,687

The successful ET4000 run survives because those extra writes go through the banked aperture rather than conventional RAM, but this is a real deterministic logic error, not an emulator artifact.

Palette transitions are asymmetric

059Ch streams DS:02DC RGB triplets from DS:02FE through 03C8h/03C9h.

0214h, the fade toward black, waits for retrace high and then low, uploads the current palette, and decrements every nonzero component. It exits when the post-decrement buffer is all zero. The exact zero buffer is never uploaded; the final visible components are therefore zero or one. It then executes an unconditional STI.

0254h is stranger than the earlier “increment toward target” description:

copy target 02FEh -> 05FEh
zero current 02FEh

upload 0,1,2,...,62 as 63 fast unsynchronised full palettes
disable interrupts
upload from value 63 downward, one retrace-paced decrement per component
stop each component when it reaches its saved target

The visible lifecycle is therefore black to near-white as quickly as DAC writes permit, then a retrace-paced descent from 63 to the actual target. The target palette is eventually uploaded exactly.

Rolling strip: exact pixels and one callback

The fixed far visual callback is 0000:0346:

select bank 2
run one compositor/script step
select bank 4
RETF

02E0h first snapshots this clean rectangle from the stable M640 image:

screen source       bank 2, A000:33CD
coordinates         x=333..638, y=225..240
geometry            306 * 16 = 4,896 bytes
background cache    DS:1E10..312F
rolling strip       DS:0AF0..1E0F

038Ah draws all 16 rows, 153 words per row. For each byte, zero in the rolling strip means “use the corresponding cached M640 byte”; a set glyph pixel is palette index FFh. The head == 305 case explicitly joins the last byte of a row to its first byte in low/high order. Every callback therefore:

reads  4,896 background bytes
reads  4,896 rolling-strip bytes
writes 4,896 bank-2 pixels

There is no retrace wait in the compositor. Drawing happens before the ring head advances and before the next glyph column is staged, so new columns become visible one callback later.

This is the exact owner of the narrow upper-right moving text seen in the 00:15 direct-runtime still. It does not own the full screen or the lower blue panels.

Script grammar and glyph producer

02CAh XOR-decodes DS:3151..344F with an incrementing key beginning at AEh. The consumed script is DS:3155..344E, 762 bytes, with 725 printable characters.

20h..5Ah       printable glyph
00h 01h rate   horizontal repeat count
00h 02h hold   freeze for hold * 16 callbacks
00h 03h mode   choose glyph producer mode
00h other      skip second byte

The script wraps after reading the decoded sentinel at 344Fh. One complete cycle is:

13,248 active column updates
   512 frozen hold callbacks
13,760 visual callbacks total

For each printable character, the producer indexes the 59-glyph, eight-row font at DS:0918 using 8 * (character - 20h). Bits are emitted most-significant first. A character occupies exactly 8 * rate callback columns.

Mode zero writes four transparent rows, eight glyph rows, then four transparent rows. Mode one duplicates each of eight glyph rows and advances the row start by 307 bytes, creating a two-pixel slant through the 306-byte ring. A triangular 0..16..0 phase advances the color selection. The path inherits DF=0 from the compositor's CLD; it does not establish that state itself.

During a hold the full 4,896-byte rectangle is still redrawn, but the head, glyph bit, cadence and script pointer remain frozen. The callback that lowers the hold counter to zero is still frozen; motion resumes on the next one.

Music-owned lower point field

On the 386 path, 060D:0069 preserves all registers, restores loader DS=ES=0179h, far-calls 0000:0346, and then conditionally calls 060D:00A0. The latter owns a different object in bank 4.

It rotates through four phases. Each phase restores 60 saved pixels, draws 60 new index-FFh points and saves the overwritten values for its next visit. After warm-up the four phases own 240 positions:

bank             4
x ranges         359..418, 423..482, 487..546, 551..610
y range          420..451
updated/callback 60
phase positions  240

These points occupy the lower-right panel region. They are not glyphs, trail pixels or part of the 306x16 scroller. Restoring bank 4 at the end of 0346h is the hand-off that makes the point service's direct aperture writes land in the correct bank.

Keyboard, music and voice ownership

The silent fallback calls 0000:0346, waits until VGA status bit 3 is high, reads port 60h, and repeats while it equals the startup snapshot.

The music path calls the same fixed visual callback from its DMA-block service boundary, then performs its own retrace gate. Its later stop test also compares raw port 60h; any changed byte exits. Escape is not special, make and break codes are not distinguished, and the BIOS key buffer is not drained.

Static code separates two audio systems:

The voice dispatcher command-3 initialization self-modifies its BX-6 table entry at 04BF:0017 from 2776h to the selected Sound Blaster start entry 0D11h. The loader ignores returned voice errors. SND1/M is skipped below the loader's 386 CPU class; probe/setup failure also falls back to the silent visual loop.

Normal music cleanup stops DMA/DSP operation, restores the IRQ vector and low-memory DMA words, and frees its resource segments. V001/V is explicitly stopped and freed before that controller begins. Final ASTA/V is freed after natural completion but is not followed by another explicit stop command.

Exit and failure edges

Video “restoration” is not reliably restoration of the entry state. 058Ch saves only the mode byte AL, losing page and column information, and detection runs before the snapshot:

Other sharp boundaries:

What the inner loops establish

The 1991 achievement is narrower and more concrete than a generic “SVGA demo”:

That also explains its brittleness. The abstract-looking callback table is only a thin layer over card-specific port programming; its VBE-success case is broken, detection can alter the mode before it is saved, resource links are physical file offsets, and several failure paths bypass balanced cleanup. Those are not side details around the presentation: they are the exact machinery that decides whether its ambitious 640x480 frame appears at all.