Inside the exe ↓

64 KB, eleven objects and a 212-line script

“The Kaleidoscopic Circus” is Kaleido's 64k intro for the Takeover 2001 compo. Code by mnemonix and the yeti, music by silence, models by wosh. The exe was linked on 24 June 2001 at 03:02 UTC, during the party, and the nfo apologises: “no time for loading screen”. Everything above was rebuilt from that exe. The music plays from the embedded XM through a port of the replayer. Every texture is generated by the exe's own texture scripts, and every mesh, camera and event comes from the disassembly. A video capture was used only to check the result.

Below the player you can read the timeline against the music, walk the unpacked image, take any frame apart into its draw calls next to the capture, step through the texture scripts, and switch one of the intro's habits off.

Packed exe
65,144 B
Unpacked image
188 KB
Song
109.7 s
Timeline records
212

The score

The intro has no scene list. A table at 0x424110 holds 212 records of 40 bytes: {row, order, type, object, param, a, b, c, done, keep}. Every frame, the main loop (0x403846) asks MiniFMOD for the order and row being heard and fires every record that matches. Next it clears the screen, then it renders each of the eleven objects that are switched on, in table order. The lanes show when each object is on; the ticks are its events (hover for the decoded value); the bottom lane is the clear colour. The white line follows the player. Click to jump.

Hover the score.

TypeCountEffect
2 enable · 3 disable57switch an object's render on or off. Cuts are made with a disable and an enable in the same row
5 set time12sets the object's local clock obj+8. Because records re-fire, the clock is held there for the whole row
6 event132calls the object's fourth virtual method with (a, b, c): flash colour and fade, credit text slot and size, urchin twist, flame texture
7 clear colour11the Clear colour from now on: night blue (20,40,60), black, or the green-grey (68,87,80) of the hall

Time inside the objects is timeGetTime()/70: one unit is 70 ms. Song time runs at speed 3, 124 BPM, so a row is 60.5 ms and a 64-row pattern 3.87 s. Pattern 0 has 96 rows. On the capture the picture is 0.53 s behind the start of the recording, and the rendered song lines up with the captured audio at that offset.

Eleven objects

Each object is a C++ class with a four-slot vtable: destructor, init, render and event. WinMain creates all eleven up front (no loading screen) and keeps them in the table at 0x426450, which is also the draw order. Several objects are often on together: the flash is drawn after every 3D object and before the credits, so a credit fades in over the white.

#ObjectWhat it drawsRenderTexture slotsOn forFirst seen

Unpacking UPX 0.71

The exe is packed with UPX 0.71 (1999), which current UPX refuses to unpack. tools/unupx.py maps the three sections into Unicorn, gives the stub fake LoadLibraryA and GetProcAddress, and runs it until it jumps to the original entry point at 0x411158. The fake functions return recognisable handles, so the stub's own import loop leaves every IAT slot labelled, and the 75 imports come out by name.

The same trick checked the ports. The texture generator, the face mesh, the urchin, the letters and the timeline were each run as the exe's own code under Unicorn, with D3D, GDI and the C runtime stubbed, and compared with the JavaScript.

DLLImportsUsed for
msvcrt.dll35maths, rand/srand, new, startup
user32.dll15the window, the message loop, a hidden cursor
gdi32.dll11Arial into a bitmap, read back with GetPixel: credits, “kaleido”, “|KALEIDO|”
winmm.dll8waveOut for MiniFMOD, and timeGetTime
kernel32.dll5the mixer thread
d3d8.dll1Direct3DCreate8; the rest goes through COM vtables

Where the bytes go

The unpacked image is 0x2f000 bytes. Code is 66 KB; the song, 44,822 bytes, is the biggest single thing in it. Hover or tab through the map: the upper bar is the whole image, the strip below zooms into .text with one tick per function the disassembler found, coloured by subsystem.

Hover a region or a function.

Strings in the image: the window title “The Kaleidoscopic Circus”, the engine's name “KDTK Direct 3D”, “Device creation failed.” and “lock failed”, and the font names “Wingdings” and “whatever”. In the XM, the instrument names read “silence”, “kaleido”, “takeover2k+1”, “sixtyfour-k intro”.

A small fixed-function engine

The engine at 0x40b340–0x40e750 calls itself “KDTK Direct 3D”. A mesh owns a vertex buffer (FVF 0x152: position, normal, colour, one UV) and an index buffer. It is refilled with Lock every time it changes, and drawn with one DrawIndexedPrimitive. Meshes use the world matrix Rz·Rx·Ry plus translation. The camera uses T·Rx·Ry·Rz or a left-handed look-at, and a projection with two fields of view and no aspect ratio.

Lighting is switched on but no light is ever set, so a lit mesh is flat: emissive plus ambient times the white material, 0.1 + 0.6·240/255 = 0.665 of the texture. Fog is per-vertex linear range fog. The environment map reflects camera-space normals into the texture. The WebGL port keeps D3D's row vectors and 0..1 depth, and does all of this in one shader.

PartBuilt fromAddress
Hallan arch module of 157 vertices and a 9-vertex floor tile, both stored as float blobs, repeated along the camera path0x406cf6
Face553 vertices and 994 triangles at 0x41fbec, twisted per vertex every frame0x402093
Urchina cube subdivided onto a sphere; each of 24 faces is extruded into a spike of 8 rings, every frame0x401820
Gears16 teeth, radius 9 to 14, a hole of 8, ten on a circle of 320x402d67
Letters10 blobs on a 128×64 field, marching squares on a 64×32 grid mapped onto a cylindrical shell0x403e5f
Flamesa 16-ring tube of sheets with phase-shifted rings0x408516
Particlescamera-facing quads in view space, additive, Z test without write0x40cce0

Inside one frame

A second copy of the intro and the renderer, so the player above is left alone. Pick a moment: on the left is the reconstruction, on the right the nearest still from the capture, and below is every draw call that frame makes, in order. The jump buttons are the moments with capture stills, at capture time.

–

reconstruction, 640×480
Capture still
capture

Stepping backwards replays the intro from the start, because particles and the rand() stream carry state from frame to frame.

Twenty-three texture slots

Textures are uploaded to a running counter, so the order of calls in WinMain decides the slot. Slots 0–7, 21 and 22 come from six scripts for the texture generator at 0x40e750. Each script works on four 256×256 layers with 28-byte records: an op, a source and a destination layer, and six parameters. The caller picks which layer to keep. Slots 8–20 are the credit names, drawn with GDI. Pick a slot, then a step, to see the four layers after that step; the kept layer is outlined. The port matches the exe's own code bit for bit, apart from GDI text. That includes the x87 running at 24-bit precision, because Direct3D switched the FPU before the first texture.

    Slot 4 is the logo. Its RGB is layer 1 of the script and its alpha is the blurred text mask from layer 0, added as dword + (mask << 24). Slots 21 and 22 shift every pixel left by 25 bits, keeping only an alpha of scanline static for a credit “flicker” flag that no event ever sets. Every noise op calls srand with its own seed, so the textures never disturb the rand() stream the particles use.

    The music: MiniFMOD and “k-two”

    The replayer is Firelight's MiniFMOD, linked in at 0x4085dd–0x40b340. It plays a 44,822-byte FastTracker 2 module from memory at 0x414cd4. It mixes 44.1 kHz stereo into a looping waveOut buffer, refilled by its own thread.

    js/xmplayer.js is the port written for “Spiral Staircase”, Kaleido's next intro, which uses the same replayer. It renders the whole song before the intro starts. Against the audio of the capture it correlates at 0.93, at a constant offset.

    The exe asks for the order and row that are audible, not the ones being mixed, so the timeline follows what you hear. It quits with PostQuitMessage once order 19 passes row 48, mid-pattern: the last 15 rows are never heard.

    ModuleValue
    Title“k-two”
    Channels32
    Tempospeed 3, 124 BPM: a row is 60.5 ms
    Order list0 1 2 3 4 5 5 6 7 6 7 8 9 1 2 3 4 5 5 10
    Length20 orders; the intro ends at 109.7 s
    The rendered song, one band per order, pattern numbers below. Click to jump.

    Quirks

    Most of what follows is reproduced as is. Two of the quirks depend on how the exe was run, and you can change that here. These controls change both the player above and the frame inspector.

    Deviations and sources