Analysis model: gpt-5.5 xhigh, sol high
Last edited: 2026-08-25
Meaculpa by The Brain Slayer - Technical Dissection
Meaculpa is a 1991 MS-DOS VGA/Sound Blaster intro by The Brain Slayer. It is
part of the same Brain Slayer family as Classic, Collapse, and Coma Demo,
but this one is interesting because the restored executable contains the whole
resource and sound engine internally instead of reopening itself to stream a
large appended overlay.
The visible result is short but dense: a starfield/triangle title sequence, Brain Slayer/raytraced-ball screens, framed rectangle reveals, a small text and glyph-script layer, bottom scrolling text, and a Sound Blaster music path that does a lot of the real work. The binary itself says the sound is the biggest part of the intro, and the recovered code backs that up: the visual code is a set of compact VGA kernels, while the sound side contains a custom sequencer, resampler, four-lane sample buffer, SB DSP setup, DMA programming, IRQ handling, and a frame-synchronized wait loop.
Release year: 1991
Sources And Artifacts
- Hornet 1991
meaculpa.zipmirror - Scene.org browser copy SHA-256 identities:
9655d16d53bbc006db3d78f4ae59f67cc1844f988711b235ea30f94c950a42a1 meaculpa.zip
21b64070a1ded5c04e2b306b3b9f7bc5ea79b167d7cd6ab3ca7dccde88898fcc original MEACULPA.EXE
c52092b26ce72cbfe71125475dab7d6edee04566ef53159af7d67ae465002e10 UNP-restored executable
e6bbade55365b6b58b93cb8ae2b06ebc3e235fa23459b1a5c85178172d4ae420 restored load image
The ZIP contains two files:
demosite.com 1104 bytes 1992-10-21 18:43
meaculpa.exe 280249 bytes 1991-07-01 12:56
The small demosite.com sidecar is a 1992 demo-site advert. I did not use its
contact details in the public writeup; the technical analysis below is about
meaculpa.exe.
Direct Runtime And Keyed Exit
I reran the original packed MEACULPA.EXE, not the restored UNP copy, under
DOSBox-X 2026.01.02. The guest used an emulated SB16 at base 220h, IRQ 7,
DMA 1. A 70-second direct run follows the repeating star/title/framed-ball
route without input; a second captured run presses Esc after the animation
is established and reaches a clean DOS prompt at about 00:16.55.
| Capture time | Directly observed runtime state |
|---|---|
00:00–00:06.15 |
Black emulator/program startup interval in the long source capture. |
about 00:06.15 |
The sparse starfield becomes visible. |
about 00:06.9 |
A large red triangle and diagonal title text enter over the stars. |
about 00:08.4 |
The BRAIN SLAYER framed checker/ball scene takes over; the bottom scroller and side strips move continuously. |
00:13.6–00:14.35 |
A brief black transition separates phases before the title/ball loop continues. |
through 01:10 |
The title and framed-ball states repeat with changing ball positions, checker phases, side strips, stars, and scroller text. |
keyed run, about 00:16.55 |
Esc restores text mode and returns to the DOS prompt. |
The full no-input run is available as a directly playable silent video:
The separate keyed run records the exit boundary rather than leaving it as a text-only observation:
The front-page GIF remains one continuous excerpt from the same long run, replacing the old tiled contact sheet. Both new 640x400 H.264 videos and the GIF have no audio stream. Sound Blaster emulation kept the guest sequencer, DMA, IRQ, and pacing paths active while SDL used a dummy host driver; no audio was monitored or published.
The visible alternation is one music-paced state machine, not a collection of
unrelated pictures. The ball scene, title phase, and returns between them show
the dispatcher advancing while the same Sound Blaster wait loop remains in
control. Unlike nearby Brain Slayer binaries that hit emulator or card-probe
caveats, this one accepts the emulated SB setup, runs the long route, and exits
normally on Esc.
Runtime-To-Code Concordance
The direct run is evidence for one music-paced runtime, not a gallery of
unrelated screens. The first visible starfield maps to the always-running
0413h dot updater, which owns 14-byte records, erases only pixels still
matching the star's color, and is reached from the 047Ah dispatcher during
the 10D0h foreground tick.
The recurring red triangle/title frames are the title-state branch of that
same dispatcher.
Startup has already selected mode 13h at 01B4h..01B6h, uploaded the DAC
table through 03F6h, and prepared picture blocks through the internal
inflater at 036Eh/09F1h; the visible triangle/text state is then advanced
by the script/table path around 071Fh, the glyph blitter at 07DEh, and the
RLE frame step at 011Ah.
The repeated Brain Slayer/raytraced-ball frames map to the picture-copy/reveal
side of the same state machine:
0891h copies 7080h words into the mode-13h page, 08B0h performs the
shrinking rectangle reveal by copying prepared borders, and 1106h advances
the four moving side/bar strips after every 10D0h tick. The bottom scroller
and framed area stay in sync because this is not a free-running visual timer;
the Sound Blaster wait loop repeatedly calls 10D0h while waiting for the DMA
IRQ/refill handshake.
The direct animation also bounds what is not being claimed. It proves the packed original reaches the SB path in DOSBox-X and shows the dispatcher alternating between star/title and framed-ball states. It does not prove a separate 3D renderer for the ball scene; the code evidence points to preprepared picture blocks, segment-listed RLE spans, rectangle copies, script/glyph overlays, and small per-frame strip/star kernels.
Container Shape
The original EXE is a normal MZ file with almost no useful plain strings. Its entry point sits near the end of the file, which is typical of an EXEPACK-style wrapper:
original length 280249 bytes
MZ-reported image 280249 bytes
header paragraphs 0002h ; 32-byte header
load image 280217 bytes
relocations 0000h
entry raw offset 279758
CS:IP 444A:000E
SS:SP 51D4:0080
overlay bytes 0
UNP expands it to a larger relocatable MZ:
restored length 332741 bytes
MZ-reported image 332741 bytes
header paragraphs 0028h ; 640-byte header
load image 332101 bytes
relocations 0096h
entry raw offset 996
CS:IP 0000:0164
SS:SP 7162:E000
overlay bytes 0
That overlay bytes 0 detail matters. Classic and Collapse are structured
around self-opening file-backed resource records. Meaculpa is different after
UNP restoration: the executable image already contains the packed data blocks,
animation command streams, sound tables, and sample/music material. The loader
still uses a serious inflater, but the source stream is memory-resident rather
than appended-file I/O.
For all offsets below, raw offset means offset in the restored load image
(MEACULPA.unp.img), with the initial program CS treated as zero unless a far
call explicitly says otherwise.
Startup Skeleton
The restored entry at 0164h first repairs the stack and segment registers:
0164 mov sp, e000h
0167 mov ax, 0276h
016a mov ds, ax
016c mov es, ax
016e call 0000h
The 0000h routine is a tiny XOR decoder:
0000 mov cx, 1239h
0003 mov si, 0b68h
0006 sub cx, si
0008 mov di, si
000b lodsb
000c xor al, 0efh
000e stosb
000f loop 000bh
0011 ret
It decodes the span 0B68h..1238h, or 06D1h bytes. That range includes
script tables and routines used by the early visual/sound scaffolding. The
decoder is deliberately small: no relocation, no dynamic destination, just
in-place transformation inside the executable image.
The entry code then performs a VGA display-combination query:
0173 mov ax, 1a00h
0176 int 10h
017a cmp al, 1ah
If VGA is not present, it prints a text-mode error. The visible strings are direct and match the runtime requirement: VGA is mandatory; Sound Blaster is optional but expected for the full experience.
The successful VGA path sets up mode 13h, palette data, and the first graphics blocks:
01ab mov word [000e], 0140h ; line pitch = 320
01b1 call 03bdh ; save current video mode
01b4 mov al, 13h
01b6 call 03c8h ; set mode 13h, clear partial A000 area
01ba mov word [0000], 0020h ; upload 32 DAC entries first
01c0 call 03f6h
01c3 call 00b2h ; preprocess text/script records
Later startup calls the internal inflater and graphics copy helpers:
01df mov word [001a], 001ch
01e5 call 036eh ; unpack/copy one graphics block
01f4 mov word [0016], a000h
0200 call 0891h ; copy 7080h words to A000
0203 call 03f6h ; refresh palette
0206 call 0012h ; draw RLE A000 frame from segment list
After additional block setup, it performs timed waits, reveals, and then enters the full sound path if a 386-class CPU check passes:
0247 mov cx, 0028h
024a call 007ah ; 40 retrace waits
0255 ; ten animation steps, each followed by five retrace waits
0265 ; long 120-retrace wait
0274 call 02fch ; wipe/reveal helper
0287 call 03f6h ; full DAC upload
028a call 08b0h ; rectangle reveal
02a6 call 09a6h ; CPU check
02a9 cmp ax, 0386h
02b0 lcall 00fbh:0936h ; sound/music initializer and runtime
The far call target is linear 18E6h (00FBh * 16 + 0936h). That target is not
a library thunk. It is the intro's sound engine entry.
VGA Timing And DAC Loops
The retrace wait helper at 007Ah loops CX times over two small polling
routines. One waits for vertical retrace bit 3 in port 3DAh to become set,
the other waits for it to clear:
007a call 0085h ; wait for 3DAh bit 3 set
007d call 008eh ; wait for 3DAh bit 3 clear
0080 loop 007ah
0082 ret
That gives the transition code a crude but stable frame clock without installing a timer ISR for the visual side.
The palette table lives at 001Ch. The uploader at 03F6h writes from that
table to VGA DAC ports 3C8h/3C9h:
03f6 mov cx, [0000] ; number of palette entries
03fa lea si, [001c]
03fe mov dx, 03c8h
0401 out dx, al ; starting DAC index, usually 0
0402 inc dx ; 03c9h
0403 lodsb
0404 out dx, al ; red
0405 lodsb
0406 out dx, al ; green
0407 lodsb
0408 out dx, al ; blue
0409 loop 0403h
The fade-out loop uses 0097h to decrement 768 palette bytes. It counts how
many entries have reached zero or one, then the main shutdown loop keeps
uploading the palette until all 0300h bytes are effectively black:
0097 mov cx, 0300h
009a lea si, [001c]
009e lodsb
009f cmp al, 01h
00a1 jbe already_dark
00a3 dec byte [si-1]
...
02dd call 0097h
02e0 call 03f6h
02e3 cmp dx, 0300h
02e7 jne 02ddh
This is simple per-channel subtraction, not a gamma-aware fade. On a CRT VGA it still works well because the DAC steps are small and the scenes are mostly high-contrast.
The Internal Inflater
The block inflater starts at 09F1h. Its surrounding loader at 036Eh sets up
source/destination state, calls the inflater, then copies decompressed graphics
data into its final location.
The high-level flow:
036E call 09F1 inflate a packed block into scratch/destination
read metadata from the inflated header
copy small side tables
rep movsw 7D00h copy 64000 bytes worth of screen-like data
The inflater itself is the same general family as the Brain Slayer file-backed
inflaters, but its source reader pulls bytes from the in-memory executable
image. 09F1h clears a scratch range, stores input/output pointers, reads the
initial header, builds a CRC table, dispatches stored or compressed blocks, and
verifies the CRC.
09f1 ; clear scratch area and install stream pointers
0a32 ; read initial block header
0ad3 ; build CRC table using polynomial EDB88320h
0afe ; block dispatcher / CRC verification
0b70 ; compressed-block path begins
0c51 ; code-length table expander
0e54 ; literal output
0ec5 ; match copy
0ee2 ; bit getter
0f02 ; sliding-window flush
0f73 ; output copy plus CRC update
The literal path is direct:
0e54 stosb
; update output counters/window state around it
The match path uses the x86 string instruction as the overlapping LZ copy primitive:
0ec5 ; source = output position - decoded distance
0ec8 ; length = decoded length
0ecd rep movsb
Because rep movsb copies forward, it naturally supports the common LZ case
where source and destination overlap. That is cheaper than manually
special-casing repeated bytes.
The important architectural point is that Meaculpa did not need DOS file
reads after startup for its packed visual blocks. The loader style survives
from the file-backed Brain Slayer tools, but the restored binary is a single
self-contained executable image.
A000 RLE Frame Interpreter
The early animation frame helper at 011Ah is a compact RLE interpreter for
mode-13h video memory. It reads a segment list from [1270h]. Each segment
contains records of:
word destination_offset
byte count_or_control
bytes payload_or_fill_value
FFFFh as a destination marks end of that segment. FFFFh in the segment list
wraps the animation pointer back to 1272h.
Core loop:
011a mov ax, a000h
011d mov es, ax
0120 mov si, [1270h] ; pointer to segment list
0124 lodsw
0125 cmp ax, ffffh
0128 jne have_segment
012a mov si, 1272h ; wrap animation
...
0134 mov ds, ax ; DS = frame segment
0136 xor si, si
0138 lodsw ; destination offset
0139 cmp ax, ffffh
013c je frame_done
013e mov di, ax
0140 lodsb ; count/control
0141 or al, al
0143 js fill_run
0145 xor ah, ah
0147 inc ax ; literal length = al + 1
0148 mov cx, ax
014a rep movsb ; copy literal bytes to A000
014c jmp 0138h
014e neg al
0150 inc ax ; fill length = -al + 1
0151 mov cx, ax
0153 lodsb ; fill value
0154 rep stosb
0156 jmp 0138h
This is exactly the kind of loop one expects in a tiny 1991 VGA intro: all destination addresses are precomputed by the packer, and the runtime only chooses between literal and fill spans.
The segment list contains exactly 100 frame-segment words followed by
FFFFh. Parsing those streams with the interpreter's signed-control rules
gives this complete cycle ledger:
frames 100
records per frame 255..407
literal records per frame 135..265
fill records per frame 55..175
literal bytes written per frame 525..1,381
fill bytes written per frame 149..644
total A000 writes per frame 765..1,757 bytes
records in one 100-frame cycle 31,976
literal bytes in one cycle 91,140
fill bytes in one cycle 32,078
total A000 writes in one cycle 123,218 bytes
encoded stream bytes in cycle 197,738
Every record supplies its own absolute destination, so the gap between the lowest and highest touched address is not a copied rectangle and skipped screen areas consume no VGA traffic. The average is 1,232.18 written bytes per visual tick—about 1.93% of a 64,000-byte mode-13h page. The stream achieves motion by replacing only authored runs; it neither saves old pixels nor clears the complete ball/title region before the next frame.
Starfield And Moving Dots
The star/dot update at 0413h draws through A000h, using exactly 44 records
of 14 bytes each at 07F4h. It tracks previous screen positions so it can
erase only the old pixels it owns:
per record, simplified:
if old pixel still has this star's color:
clear old pixel
update x/position accumulator
decrement per-star delay/counter
when the counter expires:
reload it and update velocity
wrap negative x by adding 319
if destination pixel is zero:
draw new pixel
The inner behavior is conservative. It does not blindly clear whatever is at the old location; it checks the stored color first. That keeps the starfield from erasing the triangle/title or frame graphics if layers overlap.
The workload is fixed even when no write is accepted: each of the 44 records reads the old destination once and the candidate destination once. A tick therefore performs exactly 88 VGA byte reads and between zero and 88 VGA byte writes. The upper bound is one ownership-validated erase and one black-pixel draw per star. Record updates and wrap arithmetic happen regardless of whether either write succeeds.
The frame-synchronized visual tick at 10D0h calls this through a far call:
10d0 push ds
10d1 push es
10d2 pusha
10d3 mov ax, 0276h
10d6 mov ds, ax
10d8 mov es, ax
10da lcall 0000h:047ah ; visual dispatcher
10df call 1106h ; four moving side/bar strips
10e2 popa
10e3 pop es
10e4 pop ds
10e5 ret
This same 10D0h tick is called from the Sound Blaster wait loop, which is why
the music engine and visuals stay coupled even though the DMA refill is IRQ
driven.
The 1106h side/bar helper is another bounded live kernel. It walks exactly
four eight-byte state records. A growing strip moves its boundary by 03C0h,
three 320-byte rows, and writes a fixed nine-byte motif on each exposed row:
27 A000 bytes. A shrinking strip retreats by 0140h, clears one nine-byte row,
and therefore writes nine bytes. An endpoint-clamped strip writes nothing.
There are no VGA reads or saved-background copies in this helper; per tick its
four strips contribute 0..108 direct bytes according to their directions and
endpoint state.
Visual Dispatcher
The dispatcher at 047Ah is a small state machine. The state byte at 0AB4h
selects between:
- initial script records from the
071Fh/07C9hpath; - text/shape table dispatch through
04D2h; - a timed phase counter at
0B66h; - the always-running starfield update at
0413h; - the RLE frame step at
011Ah.
The result is not a general scene graph. It is a phase sequencer where each phase points at a small routine or prepacked frame list. That matches the captured runtime: triangle/title cards and framed raytrace screens recur, but their movement is driven by small tables and state counters, not by one large renderer.
Glyph And Script Blitter
071Fh is the text/shape script interpreter. It walks a pointer list, wraps at
FFFFh, and uses each record to choose position, duration, flags, and bitmap
source. It stores continuation state in variables near 07D8h, 07DAh, and
07DCh, then calls 07DEh.
07DEh is the actual bitmap/glyph blitter. It works from bit-pattern bytes,
tests one bit at a time, and writes colors selected through a tiny cyclic color
table. A flag can make it draw a second row 320 bytes below, effectively
doubling part of the glyph vertically.
Representative inner loop:
0807 mov cx, 8 ; eight rows/bit tests in this slice
080c lodsb ; bitmap pattern byte
0810 shr ax, cl
0816 or ax, ax
0818 jz clear_pixel
081a call 0862h ; select color from 16-byte cyclic table
081d mov es:[di], al
0825 add di, 0140h ; optional second-row write
...
084a add di, 0140h ; next screen row
084e loop 080ch
0857 inc di ; next column
The helper at 0862h indexes a 16-byte color cycle using state around 0B4Ah
and 0B4Ch. That gives the script layer palette motion without changing the
whole VGA DAC.
The loop dimensions are exact. DH walks eight source columns and the inner
CX=8 walks eight rows. Flag bit 0 changes the horizontal repetition factor
from one to two; flag bit 1 changes the vertical write factor from one to two.
Thus one glyph consumes 64 or 128 source-pattern bytes and writes exactly 64,
128, or 256 A000 bytes. Zero bits are explicit zero writes, not transparency,
and the color-cycle helper is still called for them before AX is cleared.
The doubled forms are nearest-neighbour replication performed inside the
plotter, not separately enlarged artwork.
Before a new script effect, 087Eh clears a 0FA0h word scratch buffer. That
is 8000 words, or 16000 bytes, enough for a compact offscreen/staging area but
much smaller than a full 64000-byte framebuffer.
Rectangle And Screen Copy Effects
The large copy at 0891h copies 7080h words, or 57600 bytes:
0891 ; copy from [12:10] to [16:14]
mov cx, 7080h
rep movsw
That is not a full 64000-byte mode-13h page. It leaves part of the screen under separate control, which matches the bottom strip/scroller style seen in the capture.
The rectangle reveal at 08B0h starts with a full-screen-ish rectangle and
shrinks it in 16-pixel steps:
left = 0
top = 0
right = 320
bottom = 199
repeat:
copy top edge
copy right edge
copy bottom edge
copy left edge
left += 16
top += 16
right -= 16
bottom -= 16
The edge copier at 08F5h uses the fixed 0140h scanline stride. It does not
draw geometric lines in the usual sense; it copies rectangular borders from an
already prepared source image into A000.
02FCh and 0364h are wipe helpers. They use 320-byte spans and the same
0140h pitch, filling or clearing rows with rep stosb. These are
screen-transition kernels, not independent art generators.
Sound Blaster Entry And Probe
The main visual startup calls 00FB:0936, which maps to linear 18E6h in the
restored image. That routine installs the sound world:
18e6 mov ax, 5b0ah
18e9 mov ds, ax
18eb call 1213h ; clear/init sound workspace
18ee call 1375h ; save low interrupt vectors
18f1 call 13adh ; build tables
18f4 push ds
18f5 call 1728h ; probe SB base ports
18f8 call 134bh ; reset/test selected DSP
18fb je 1900h
18fd pop ds
18fe stc
18ff lret ; no SB accepted
1901 call 18dfh ; probe + IRQ/vector/DMA setup
1904 in al, 60h
1906 mov cs:[0009], al ; save keyboard port value
190a call 118fh ; install sample/instrument tables
1912 call 128dh ; choose DMA buffers
1915 call 12f9h ; set DSP time constant
191e call 14b1h ; hook IRQ vector
The base-port probe tries the classic Sound Blaster range:
1728 mov word cs:[0013], 0220h
172f call 134bh
1732 je found
1734 mov word cs:[0013], 0230h
173b call 134bh
1740 mov word cs:[0013], 0240h
174c mov word cs:[0013], 0250h
1758 mov word cs:[0013], 0260h
1764 mov word cs:[0013], 0210h
176b call 134bh
The reset/test routine at 134Bh writes to DSP reset port base+6, waits for
DSP data at base+0Eh, and expects the AAh response:
134b mov dx, cs:[0013]
1350 add dl, 06h
1353 mov al, 01h
1355 out dx, al ; reset high
1356 in al, dx ; delay by repeated reads
135a sub al, al
135c out dx, al ; reset low
135d mov bl, 10h
135f call 132ch ; read DSP byte with timeout
1362 cmp al, 0aah
1364 je ok
1366 dec bl
1368 jne 135fh
136a mov ax, 0002h
136d stc
1370 xor ax, ax ; ok
The DSP writer at 12F9h waits for the write port to become ready, then sends
command D1h and command 40h with the time-constant byte from cs:[0017].
That byte is D3h, giving the original Sound Blaster rate
1,000,000 / (256-D3h) = 22,222.22 samples/second. A 512-sample block therefore
requests about 43.40 IRQ refills per second, one every 23.04 ms. These are
code-derived intended values; host audio remained dummy and was not measured
or auditioned. Later playback writes 14h plus a transfer length to start
single-cycle 8-bit DMA output.
IRQ And DMA Handling
The IRQ vector hook starts at 14B1h. It converts the configured IRQ number in
cs:[0015] into an interrupt vector by adding 8, saves the old vector through
DOS function 35h, installs the new handler with DOS function 25h, and
unmasks the corresponding PIC bit.
The hook operand needs the same segmented-address accounting as the far player
entry. The player code segment is load-image segment 00FBh, so live
CS:047Ch maps to raw load-image offset
00FB0h + 047Ch = 142Ch, exactly where the handler below begins. It is not a
generated handler or an unrelated address.
14b1 mov al, cs:[0015]
14b5 add al, 08h
14b7 mov ah, 35h
14b9 int 21h ; get old vector
...
14ca mov dx, 047ch
14d3 mov ah, 25h
14d5 int 21h ; set new vector
14dd mov ah, 01h
14df shl ah, cl
14e1 not ah
14e3 in al, 21h
14e5 and al, ah
14e7 out 21h, al ; unmask IRQ
The IRQ routine acknowledges the PIC, reads the DSP acknowledge port, programs
DMA channel 1 with the next buffer, starts DSP command 14h, writes the low
and high length bytes, then sets cs:[0007] = FFh as a handshake to the main
sound loop.
142c pusha
142d mov al, 20h
142f out 20h, al ; PIC EOI
1431 mov dx, cs:[0013]
1436 add dx, 000eh
1439 in al, dx ; DSP ack
...
1448 mov al, 05h
144a out 0ah, al ; mask DMA channel 1
144e out 83h, al ; page register
1452 out 02h, al ; base low/high
146e out 03h, al ; count low/high
1476 out 0ah, al ; unmask DMA channel 1
1486 mov al, 14h
1488 out dx, al ; DSP single-cycle DMA command
1496 out dx, al ; length low
14a6 out dx, al ; length high
14a9 mov byte cs:[0007], 0ffh
14af popa
14b0 iret
The complete handler is 133 bytes. Its no-carry, no-wait path executes 53
instructions, makes 11 port writes, and makes at least four port reads: one DSP
interrupt acknowledge plus three write-ready polls. Each additional poll adds
one in, one or, and one conditional jump. An address-add carry adds two
instructions, but its CS:0006h=FFh marker is immediately overwritten with
zero at 1466h, so no persistent boundary flag survives. The 111-byte
programming body at 143Ah..14A8h is byte-for-byte identical to the inline
initial-start body at 1667h..16D5h; startup and refill use one exact hardware
recipe.
That recipe has a count asymmetry. It writes value N directly to the 8237
DMA count register, whose meaning is N+1 bytes, then decrements CX and sends
N-1 to the DSP, whose single-cycle command means N samples. At the normal
N=0200h, DMA is armed for 513 bytes while the DSP requests 512. DSP completion
normally leaves the extra DMA count latent rather than playing a 513th sample.
The Sound Workspace
The workspace initializer at 1213h clears 0000h..6570h in the sound data
segment, then initializes tables and flags:
121a lea di, [0000h]
121e lea cx, [6571h]
1222 sub cx, di
1224 xor ax, ax
1226 rep stosb
1228 lea di, [6469h]
122c mov cx, 0020h
122f xor ax, ax
1231 stosw
1232 add ax, 001eh
1235 loop 1231h
1237 lea di, [640eh]
123b lea si, [001fh]
123f mov cx, 004ah
1242 rep movsb
126Dh builds a pitch/step table at 572Ch:
1271 lea di, [572ch]
1275 mov cx, 0010h
1278 xor bx, bx
127a mov si, 00fah
127d mov ax, cs:[0019]
1281 mul bx
1283 div si
1285 and ax, 0fffeh
1288 stosw
1289 inc bx
128a loop 127dh
The fixed divide by FAh and even alignment mask show that this table is used
for cheap stepping/rate values, not arbitrary floating-point music math.
13ADh builds a 65-by-256 volume table at 1604h. It multiplies a centered
sample byte by a volume value, shifts down by six, and recenters around 80h:
13bc mov al, [64abh] ; sample value
13bf sub al, 80h
13c1 mov dl, [64a9h] ; volume 0..40h
13c5 imul dl
13c7 shr ax, 6
13ca add al, 80h
13cc mov [bx+1604h], al
That table is later used by xlat, which makes the per-sample resampler much
cheaper: sample scaling becomes one indexed byte lookup.
Sequencer Event Records
The main music loop around 1931h handles four channels. For each channel it
loads a 16-byte event/control record from an instrument/pattern segment:
195c xor bx, bx
195e mov bl, [645ch] ; pattern/order index
1962 mov bl, [634ah+bx] ; map to segment table index
1966 shl bx, 1
1968 mov es, [64adh+bx] ; event segment
196c mov bl, [645eh] ; row index
1972 shl bx, 4 ; 16-byte record per row
1975 mov bp, es:[bx+0]
1978 mov ax, es:[bx+2]
...
1b05 mov bp, es:[bx+4]
1b09 mov ax, es:[bx+6]
...
1c95 mov bp, es:[bx+8]
1c99 mov ax, es:[bx+0ah]
...
1e25 mov bp, es:[bx+0ch]
1e29 mov ax, es:[bx+0eh]
So the 16-byte row record is really four 4-byte channel entries. The code masks
the lower 12 bits as a note/sample position (bp & 0FFFh) and folds high bits
from DX/AX into a command/instrument byte:
197c mov dx, bp
197e and bp, 0fffh
1982 mov cl, al
1984 and cl, 0fh
1987 mov ch, ah
1989 shr al, 4
198c and dh, 0f0h
198f or al, dh
1991 mov [63cch], al
When a new instrument/sample value is nonzero, it indexes tables at 6469h
and then reads sample metadata from offsets such as 5F9Ah, 5F9Ch, and
5FA0h. Those metadata fields feed loop boundaries, source segments, and
initial volume.
The command nibble in CL dispatches through a tiny jump table:
1a30 mov al, cl
1a32 shl ax, 1
1a36 jmp word cs:[0a49h+si]
The repeated channel handlers do the same through analogous tables at 0BD9h,
0D69h, and 0EF9h. Some commands:
- set positive or negative pitch/position deltas into
5724h,5726h,5728h,572Ah; - set volume deltas into
656Dh..6570h; - set an early pattern/order jump by writing
6460h = FFhand a delta at6458h; - update direct channel volumes
6464h..6467h; - update the global rate/step table selection at
574Ch.
The repeated handlers look verbose in disassembly, but structurally they are four copies of the same channel logic. This is a speed choice: no per-channel index math in the hot resampling section, and no function-call overhead inside the row walker.
Four-Lane Resampler
After event decoding, the loop renders each channel into one of four adjacent
512-byte lanes. Channel 0 starts at [5722h] + 0000h, channel 1 at +0200h,
channel 2 at +0400h, and channel 3 at +0600h.
Channel 0 representative setup:
20f6 mov dl, [5f6ch] ; fractional accumulator low
20fa mov si, [5f6dh] ; sample pointer
20fe mov bx, [5764h] ; pitch/note index
2102 shl bx, 1
2104 mov ax, [576ch+bx] ; step table entry
2108 mov dh, al
210a mov al, ah
210c xor ah, ah
210e mov bp, ax ; high part of fixed-point step
2110 mov di, [5722h] ; destination base
211b mov cx, [574ch] ; run length
The two active resampler modes differ by direction. In forward mode:
2172 lodsb ; read source byte at DS:SI
2173 dec si ; undo lodsb's byte increment
2174 xlat es:[bx] ; volume table lookup
2176 mov ah, al
2178 add dl, dh ; fractional step
217a adc si, bp ; integer step
217c lodsb
217d dec si
217e xlat es:[bx]
2180 xchg ah, al
2182 add dl, dh
2184 adc si, bp
2186 stosw ; two output samples
2187 loop 2172h
In reverse mode, the stepping instructions change sign:
21f6 lodsb
21f7 dec si
21f8 xlat es:[bx]
21fa mov ah, al
21fc sub dl, dh
21fe sbb si, bp
2200 lodsb
2201 dec si
2202 xlat es:[bx]
2204 xchg ah, al
2206 sub dl, dh
2208 sbb si, bp
220a stosw
220b loop 21f6h
If neither active stepping mode is selected, it falls back to a fast fill:
2227 mov al, [5704h]
222a mov ah, al
222c shr cx, 1
2230 stosb ; odd byte, if needed
2231 rep stosw ; constant output
The same three-mode shape repeats for channels 1, 2, and 3, with the lane base and state variables shifted:
channel 0 lane +0000h state 5F6C/5F6D volume 6464h output state 5704h
channel 1 lane +0200h state 5F70/5F71 volume 6465h output state 5705h
channel 2 lane +0400h state 5F74/5F75 volume 6466h output state 5706h
channel 3 lane +0600h state 5F78/5F79 volume 6467h output state 5707h
This explains the later mixer layout. The resampler produces four independent 512-byte mono lanes, then the DMA mixer averages corresponding bytes from those lanes into the actual Sound Blaster buffer.
Four-Stream Mixer
The classic inner loop starts at 1539h. It exits if fewer than two bytes are
ready, picks one of the rotating DMA buffers, and mixes the four lane buffers.
The fast path is the important part:
1539 cmp word [63f8h], 0001h
153e ja 1543h
1540 jmp 1727h
1543 mov bx, [63fch] ; buffer selector
1547 mov di, [6406h+bx] ; destination DMA buffer
154b mov si, [63fah] ; source lane offset
154f mov cx, [63f8h]
1553 shr cx, 1 ; words
155a mov bp, cx
1569 mov ax, [si+0200h] ; channel/lane 1, two samples
156d mov cl, al
156f add dx, cx ; low-byte accumulator
1571 mov cl, ah
1573 add bx, cx ; high-byte accumulator
1575 mov ax, [si+0400h] ; lane 2
1579 mov cl, al
157b add dx, cx
157d mov cl, ah
157f add bx, cx
1581 mov ax, [si+0600h] ; lane 3
1585 mov cl, al
1587 add dx, cx
1589 mov cl, ah
158b add bx, cx
158d lodsw ; lane 0 and advance SI by two
158e mov cl, al
1590 add dx, cx
1592 mov cl, ah
1594 add bx, cx
1596 shr dx, 2 ; average four low samples
1599 shr bx, 2 ; average four high samples
159c mov al, dl
159e mov ah, bl
15a0 stosw ; write two mixed output samples
15a1 xor dx, dx
15a3 xor bx, bx
15a5 dec bp
15a6 jne 1569h
The clever detail is that it mixes two time-adjacent samples per iteration. Low
bytes from four channels accumulate in DX; high bytes from four channels
accumulate in BX. One stosw emits two averaged 8-bit samples.
There is also a clipped/error-feedback path at 15AAh..1625h, selected when
[6400h] == FFh. It clamps accumulators to 0000h..03FCh, rotates the low
two bits through carry, emits two bytes, then subtracts the emitted value times
four from the accumulator. That preserves some fractional residue rather than
throwing it away completely:
15d7 cmp dx, 03fch
15db jg clamp_dx_high
15dd or dx, dx
15df js clamp_dx_low
...
15eb xor ax, ax
15ed ror dx, 2
15f0 adc al, dl
15f2 ror bx, 2
15f5 adc ah, bl
15f7 stosw
15f8 rol dx, 2
15fb rol bx, 2
15fe mov cl, al
1600 shl cx, 2
1603 sub dx, cx
For the full 0200h block, CX >> 1 gives 256 iterations. Both branches read
four words per iteration—2,048 source bytes across the four lanes—and write
one word, totaling 512 output bytes. The fast branch performs eight
byte-to-word accumulations and two right shifts per iteration. The alternate
branch has the same memory traffic plus four bounds tests, possible clamps,
and residual-error carry between output pairs. The silent video does not reveal
which branch was active; this distinction comes from the recovered code.
DMA Buffer Rotation And Visual Sync
After mixing, 1539h computes a physical DMA address from DS:buffer_offset
and stores the DMA page/base/count values in low CS variables used by the IRQ
handler:
1627 mov bx, [63fch]
162b mov ax, [6406h+bx] ; current buffer offset
162f mov bx, ds
1633 shl bx, 1 ; four shifts with carry into DX = segment * 16
...
1643 add bx, ax
1645 adc dx, 0
1648 mov dh, 49h ; DMA mode/count context
164a mov cx, [63f8h] ; byte count
1650 mov cs:[0000h], ax
1654 mov cs:[0002h], bx
1659 mov cs:[0004h], cx
Then it waits for the SB interrupt handshake while continuing to advance the visual tick and synchronizing to vertical retrace:
16e6 call 10d0h ; visual update
16eb mov dx, 03dah
16ee in al, dx
16ef and al, 08h
16f1 jz 16eeh ; wait for retrace
16f5 add cx, 1
16f8 adc ax, 0
16fb cmp byte cs:[0007h], 0ffh
1701 jne 16e6h
1703 mov byte cs:[0007h], 00h
Once the IRQ says the DMA block was consumed, the code rotates to the next buffer:
1709 mov bx, [63fch]
170d add bx, 2
1710 and bx, 3
1713 mov [63fch], bx
1717 mov ax, [6402h+bx]
171b mov [63fah], ax
171e mov [5722h], ax
1721 mov word [63f8h], 0000h
That add bx,2 / and bx,3 is a two-entry rotation over word offsets 0 and
2, selecting among the buffer pointer words initialized around 6402h.
The successful exit reaches a bounded sound teardown at 2730h..275Ah. It
restores the previous sound IRQ vector through DOS, sends DSP commands D3h
(pause 8-bit DMA) and D0h (continue 8-bit DMA), restores the low exception
vectors temporarily replaced by IRQ probing, resets the DSP, and far-returns
to the visual fade/BIOS-mode cleanup. It does not restore the master-PIC mask
after 14B1h unmasked the selected sound IRQ. The intro can therefore return
with that line still unmasked despite restoring its former vector—a small
hardware-state leak present on the successful path captured here.
Why The Visuals And Audio Stay Together
The program does not install a visual timer interrupt. Instead:
- The music sequencer produces enough channel-lane data.
- The mixer fills a Sound Blaster DMA buffer.
- The SB IRQ starts or refills hardware playback.
- The foreground wait loop repeatedly calls
10D0h. - Each
10D0hcall advances the visual dispatcher and strip animation. - The loop also waits on VGA retrace.
- The next music/render chunk begins only after the SB IRQ handshake.
So the audio hardware becomes the master pacing device for the long run, while VGA retrace prevents the foreground visual updates from free-running between DMA interrupts.
This is why the intro can be simple visually but still feel synchronized: the same tight wait loop is responsible for both animation progress and audio block turnover.
The continuous runtime excerpt reflects that structure directly: the title
card, ball scene, and strip animation do not come from separate timing systems. They appear
because each 10D0h call can hand off a different visual kernel before the SB
IRQ release lets the next audio block proceed.
Relation To Other Brain Slayer Intros
Compared with Classic, Collapse, and Coma Demo, Meaculpa reuses several
ideas:
- VGA mode 13h with direct A000 writes.
- DAC-table fades and retrace waits.
- Scripted text/shape phases rather than a general object system.
- A custom CRC/table inflater.
- Sound Blaster probing around base
220h. - DMA channel 1 setup and IRQ-driven refills.
- A four-source sample mixer.
The main difference is packaging and emphasis. The other Brain Slayer analyses
had to spend more time on self-opening containers and appended resource
records. Meaculpa spends more of its restored code image on sound sequencing
and internal sample generation. The visual side is still real, but it is built
from small fixed-purpose kernels around a music-driven foreground loop.
Reconstruction Notes
A close recreation should preserve these constraints:
- Use mode 13h, 320-byte pitch, and direct A000-style byte addressing.
- Treat the bottom/side strip and the main picture area as separate regions;
the big copy is
7080hwords, not a full 64K page copy. - Drive early frames from segment-listed RLE spans with
FFFFhwrap markers. - Use vertical retrace polling for startup transitions.
- Keep the starfield conservative: erase only if the old pixel still matches the star's color.
- Recreate the glyph/script layer as bit-pattern writes with cyclic color lookup, not as proportional text rendering.
- Model the audio as four independently resampled 512-byte lanes mixed into an SB DMA buffer.
- Let the foreground visual tick run from the audio wait loop, with retrace polling inside that loop.
The last point is the key behavioral one. If the visuals are timed from a separate wall-clock timer, the intro will look similar in still frames but will not have the same 1991 hardware rhythm.