Magic Pockets Demo Format
The attract demo in Magic Pockets uses autoplay.pin, a recording of control states rather than a video. The file has an RNC method 1 wrapper. Its decompressed size is 2000 bytes.
File format
There is no header. Read two-byte records until the pair FF FF:
| Data type | Name | Description |
|---|---|---|
| UINT8 | count | Number of main-loop iterations to apply the state; zero means 256 |
| UINT8 | state | Input bitmask |
| Bit | Mask | Meaning |
|---|---|---|
| 0 | 0x01 | Up |
| 1 | 0x02 | Down |
| 2 | 0x04 | Left |
| 3 | 0x08 | Right |
| 4-6 | 0x70 | Unused input bits |
| 7 | 0x80 | Fire |
The count comes first, then the state. The word 0xFFFF terminates playback and is not a 255-iteration input record. Multiple direction and fire bits can be combined in a state byte.
The supplied tape contains 314 records, covering 2342 loop iterations. Its terminator begins at byte 628, followed by zero padding to byte 2000. Padding is outside the recording and must not be treated as further runs.
One playback step corresponds to one call to Demo_PlaybackInput in the original main loop. It is not a video refresh, a fixed millisecond interval or one browser animation callback. The original playback counter decrements a byte, which is why a count of zero runs for 256 iterations.
The engine seeds its RNG with 0x3141 when starting the demo. This seed is executable behaviour, not part of the tape. Demo level events and tile layout are separate resources, level0.pin and pcmap.pap.
Source code
From re-magicpockets, the open-source browser port and reverse-engineering project:
- web/core/demo-tape.js – decoder and iteration-based playback cursor
- web/engine/input.js – input-state handling
- docs/formats/pin.md – autoplay correction and original consumers
- docs/open-questions-history.md – resolved demo-input investigation
Credits
This file format was reverse engineered by VorticonCmdr. Please credit this work in projects that use it; a link back to this wiki is appreciated.