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.
| Type | Count | Effect |
|---|---|---|
2 enable · 3 disable | 57 | switch an object's render on or off. Cuts are made with a disable and an enable in the same row |
5 set time | 12 | sets the object's local clock obj+8. Because records re-fire, the clock is held there for the whole row |
6 event | 132 | calls 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 colour | 11 | the 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.
| # | Object | What it draws | Render | Texture slots | On for | First 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.
| DLL | Imports | Used for |
|---|---|---|
msvcrt.dll | 35 | maths, rand/srand, new, startup |
user32.dll | 15 | the window, the message loop, a hidden cursor |
gdi32.dll | 11 | Arial into a bitmap, read back with GetPixel: credits, “kaleido”, “|KALEIDO|” |
winmm.dll | 8 | waveOut for MiniFMOD, and timeGetTime |
kernel32.dll | 5 | the mixer thread |
d3d8.dll | 1 | Direct3DCreate8; 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.
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.
| Part | Built from | Address |
|---|---|---|
| Hall | an arch module of 157 vertices and a 9-vertex floor tile, both stored as float blobs, repeated along the camera path | 0x406cf6 |
| Face | 553 vertices and 994 triangles at 0x41fbec, twisted per vertex every frame | 0x402093 |
| Urchin | a cube subdivided onto a sphere; each of 24 faces is extruded into a spike of 8 rings, every frame | 0x401820 |
| Gears | 16 teeth, radius 9 to 14, a hole of 8, ten on a circle of 32 | 0x402d67 |
| Letters | 10 blobs on a 128×64 field, marching squares on a 64×32 grid mapped onto a cylindrical shell | 0x403e5f |
| Flames | a 16-ring tube of sheets with phase-shifted rings | 0x408516 |
| Particles | camera-facing quads in view space, additive, Z test without write | 0x40cce0 |
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.
–

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.
| Module | Value |
|---|---|
| Title | “k-two” |
| Channels | 32 |
| Tempo | speed 3, 124 BPM: a row is 60.5 ms |
| Order list | 0 1 2 3 4 5 5 6 7 6 7 8 9 1 2 3 4 5 5 10 |
| Length | 20 orders; the intro ends at 109.7 s |
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.
- Every event fires for a whole row. Each record has a
donebyte and akeepbyte, andkeepis 1 in all 212. So a record fires on every frame while its row is heard, about 60 ms. A “set time” holds an object's clock still for that row, and a flash stays at full strength until the row ends. Tick the box to fire each record once, as thedonebyte was presumably meant to do. - Particles move per frame, not per unit of time. The particle systems advance one step per rendered frame. The exe presents immediately with no frame limiter, so sparks moved faster on faster PCs. The port runs at a fixed 60 fps; change the rate above to see the hall's sparks and the letters' rays speed up.
rand()per vertex. Refilling a vertex buffer callsrand()once for every vertex, and the result is thrown away. The urchin's spikes alone burn 864 calls a frame. The port makes the same calls, because the particles draw from the same stream.- Slot 6 is slot 5 again. WinMain uploads the “|KALEIDO|” buffer twice, so the counter moves on and every later script texture lands one slot further than its call suggests.
- A sphere nobody sees. The urchin builds a radius-6 subdivided sphere, uploads it and updates its matrices every frame, but never draws it. Its upload still uses 216
rand()calls. - Uninitialised fields. The letters' second spark emitter and every particle system's world offset are never written. They hold whatever
newreturned, and the port assumes zero. The logo copies 65,535 pixels, not 65,536, so the last texel is left as heap garbage. - Unused credits. “Greetings To” and “JAL” are rendered into slots 19 and 20 at start-up, but no event ever selects them.
- No lights. Lighting is on, the material is set, and no light is ever created. Every lit mesh comes out at 0.665 of its texture.
- Flames hit the vertex cap. The flame tube is allocated for 2,048 vertices and 1,024 faces. The engine drops whatever does not fit, so the last rings are cut off.
Deviations and sources
- The simulation runs at a fixed rate, 60 Hz unless changed above, so that seeking is repeatable. The exe ran one step per displayed frame at whatever rate the PC managed.
rand()is the exe's: MSVC's LCG, seeded 1, consumed in the exe's order by object init, vertex uploads and particles.- Text uses the browser's Arial, so glyph edges differ from GDI's.
- Keys: space pauses, ←/→ seek 5 s, L toggles native 640×480. URL:
?t=26freezes at 26 s,?fps=30. - Analysis notes are in
work/notes/(engine, objects, texgen). Tools:unupx.py,disasm.py,exemap.py,timeline.py,texgen_emu.py.