Binary Format¶
This page documents the Click clipboard binary format as reverse-engineered from native captures. All offsets are hexadecimal.
Buffer layout¶
The clipboard buffer has these regions:
0x0000 +-----------------------+
| Global header | Fixed template data. Not modified by the encoder.
0x0254 +-----------------------+
| Program header | Row count word at +0x00.
0x0260 +-----------------------+
| Rung 0 preamble | Comment flag +0x30, length +0x34.
0x0298 +-----------------------+
| Payload region | Comment RTF body (variable length, may be empty).
| | When empty, this region is zero-length and the
| | grid starts immediately at 0x0A60.
0x0A60 +-----------------------+ <-- grid start (in no-payload buffer)
| Cell grid | 32 cells/row. Wire-only rows: 0x800 bytes/row.
| | Instruction rows are larger (variable-length cells).
| | Pushed forward by payload_len when a comment exists.
+-----------------------+
| Page padding | Zero-filled to next 0x1000 (4096) boundary.
+-----------------------+
Global header (0x0000–0x0253)¶
The encoder copies this region from the scaffold binary and does not change it. The decoder checks the magic and reads nothing else in this region.
| Offset | Size | Field |
|---|---|---|
| 0x00 | 8B | Magic: CLICK and three spaces |
| 0x0A | 2B | A u16 LE that CLICK writes when you copy. CLICK v4.00 writes 0x0400, and CLICK v3.92 writes 0x035A. An older CLICK version, not identified, writes 0x0346. The encoder writes 0x0346 too. CLICK ignores this field when you paste. CLICK v3.92 pastes a buffer that holds 0x0400 without an error. |
| 0x0C | var | A project path, as UTF-16LE text that ends in a NUL. CLICK writes a path here when you copy. It is not always the path of the project that is open. CLICK ignores the path when you paste. The encoder writes the path that the scaffold holds. |
In CLICK's copies, the bytes after the path can differ from one copy to the next.
Program header (0x0254–0x025F)¶
A 12-byte structure immediately before the rung 0 preamble:
| Offset | Size | Field | Value |
|---|---|---|---|
| +0x00 | 4B | row_word | total_grid_rows * 0x20, uint32 LE (carries into the third byte past 2047 rows) |
| +0x04 | ... | (other) | GUI state, not load-bearing for paste |
total_grid_rows includes data rows for all rungs, preamble rows for rungs 1+, and one terminal row. For a single N-row rung: total_grid_rows = N + 1.
Rung preamble¶
Every rung has a 0x40-byte preamble that holds its comment data:
| Rung | Location |
|---|---|
| Rung 0 | Fixed at 0x0260 (between program header and cell grid) |
| Rung N>0 | Cell 0 of the preamble row preceding the rung's data rows |
Comment fields within the preamble:
| Offset | Size | Field |
|---|---|---|
| +0x30 | 1B | Comment flag (1 = has comment) |
| +0x34 | 4B | Comment body length (uint32 LE) |
| +0x38 | var | Comment body (RTF) |
Payload region and the push model¶
When rung 0 has a comment, the RTF body is inserted at 0x0298 (preamble +0x38). This pushes the cell grid forward by payload_len bytes — everything after the insertion point shifts.
The encoder builds the grid as a byte blob (concatenated cell objects) appended to the header. The insertion at 0x0298 pushes the grid bytes forward by payload_len, so everything lands at the correct absolute addresses in the final buffer.
The final buffer is padded to the next 0x1000 boundary. For wire-only rungs, the pre-padding size is GRID_FIRST_ROW_START + rows * GRID_ROW_STRIDE + payload_len. Instruction cells are variable-length, so rows with instructions exceed the 0x800-byte baseline.
Comment sizing¶
- Maximum comment body: 1400 bytes (enforced by the encoder)
- The practical limit per row count depends on where
minimal_end + payload_lencrosses a page boundary - Example: 2-row rung — body up to 1324 bytes stays at 0x2000 total; 1325+ bumps to 0x3000
RTF envelope¶
Comments are stored as RTF with a fixed prefix and suffix:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}
\viewkind4\uc1\pard\fs20 <body>
\par }
Body encoding:
- Plain text: the body is ASCII. An ASCII character is written as itself, except that
\,{and}are written as\\,\{and\}. A character that code page 1252 holds is written as\'hh, in lowercase hex. Any other character is written as\uN?, with N unsigned. A character above U+FFFF is written as the two escapes of its surrogate pair. - Bold:
{\b text} - Italic:
{\i text} - Underline:
{\ul text} - Multi-line:
\parbetween lines (not\line)
Cell grid¶
The cell grid starts at 0x0A60 (before any payload push). Each row has 32 cells. Wire-only rows are 0x800 bytes (32 x 0x40). Rows with instruction cells are larger because instruction cells are variable-length. Columns 0–30 are condition columns (A–AE); column 31 is the AF (output) column.
Cell structure (wire/blank cells)¶
Wire and blank cells are exactly 0x40 bytes: a 0x25-byte header, 0x0B bytes of padding, and a 16-byte tail.
Header (0x25 bytes):
| Offset | Size | Field |
|---|---|---|
| +0x00 | 1B | Always 0x00 |
| +0x01 | 4B | Column index (uint32 LE) |
| +0x05 | 4B | Row byte (uint32 LE, global_row + 1) |
| +0x09 | 1B | Row span (0x01 for single-row, 0x02+ for multi-row AF) |
| +0x0A | 1B | Visual sub-rows (0x01 for wire cells and most single-row instructions, 0x02+ for tall boxes; 0x03 in a Math cell the editor creates, 0x01 under a row span of 3 in an Email/Home/Position/Velocity cell pasted at 1 row and then saved by its dialog) |
| +0x0B–0x0C | 2B | A u16 LE. In rung 0's preamble, CLICK writes a u16 that is not 0 at 0x026B. Every copy from one CLICK session was observed to hold the same value, and the value differs between sessions. In the other cells, long runs of neighbouring cells share one value, often 0x0000. The decoder reads neither byte. The encoder writes 0x00 at +0x0B, except in rung 0's preamble, where it writes the scaffold's 0x40 (at 0x026B). At +0x0C it writes 0x01 in a preamble cell and in each cell of a rung that has no instruction (a NOP does not count), and 0x00 in every other cell. |
| +0x0D | 4B | Instruction index (int32 LE; 0xFFFFFFFF for data cells) |
| +0x11 | 4B | Structural flag (always 0x00000001) |
| +0x15 | 4B | Row-start flag: stored row bit 0 at column A, zero elsewhere (uint32 LE) |
| +0x19 | 4B | Segment flag (uint32 LE) |
| +0x1D | 4B | Right flag (uint32 LE) |
| +0x21 | 4B | Down flag (uint32 LE) |
Tail (16 bytes, at +0x30):
| Offset | Field |
|---|---|
| +0x08 | Marker (0x01 for condition cells and non-last-row AF data cells) |
| +0x09 | Rung index, little-endian, carrying into +0x0A past 255 |
| +0x0C | A count in the last AF cell. See The last AF cell. The encoder writes 0x00 in every other cell. |
| +0x0D | Row hint (condition: local_row + 1; AF last rung: local_row + 2). The last AF cell holds other values. See The last AF cell. |
The last AF cell¶
The last AF cell is the cell in column AF on the last row of the last rung. Whatever the cell holds, CLICK writes these values in its tail when you copy:
| Offset | CLICK writes |
|---|---|
| +0x08 | 0x00 |
| +0x0C | The number of distinct addresses in the copied rungs |
| +0x0D | 0x00 |
CLICK's copies were observed to count addresses this way:
- Each distinct address in the copied rungs counts once.
- Every address inside a range counts, as well as its two ends.
- The index address of a pointer does not count.
A few copies hold a lower count than this rule gives. The reason is not known.
CLICK v4.00 ignores all three bytes when you paste. It pastes, checks and saves the rung the same way whether +0x0C holds 0, 4 or 0x63. When you copy the pasted rung, CLICK writes its own count.
The encoder writes other values in this tail:
| The last AF cell | +0x08 | +0x0C | +0x0D |
|---|---|---|---|
| One rung, an instruction in the cell | 0x01 | 0x00 | local_row + 2 |
| One rung, no instruction in the cell | 0x00 | The number of contacts and instructions in the rung. A NOP does not count. | 0x00 |
| Several rungs, an instruction in the cell | 0x00 | 0x01 | 0x00 |
| Several rungs, no instruction in the cell | 0x00 | The number of contacts and instructions in the last rung. A NOP does not count. | 0x00 |
Cell structure (instruction cells)¶
Instruction cells are composite: they carry wire flags (right=1 for contacts, right+down for T-junction contacts) with instruction data layered on top. The cell is variable-length: 0x25-byte header + instruction blob + 16-byte tail. See instruction blobs for the blob format.
Cell boundary detection¶
To walk a variable-length grid, detect cell boundaries by signature:
+0x00 == 0x00+0x01 == col(expected column index)+0x05 == row_byte(expected row)+0x09 == 0x01+0x0A == 0x01
Do not use +0x0D for detection — it varies between 0x00, 0x01, and 0xFF across cell types.
A row starts where the row before it ends, so the decoder finds each row by walking the rows in order. The walk stops in these cases:
- a row before the last one that
row_wordcounts can't be walked (no cell with the expected signature follows an instruction cell) - such a row has no cell 0
- such a row is cut off
- a rung has no data rows
When the walk stops, the rungs before it decode. One undecoded marker stands for that rung and every rung after it. The decoder never scans ahead for a later row to resume at, because a cell 0 signature can also turn up inside an instruction blob.
A preamble row's cell 0 must carry the signature, with its +0x05 one past the row before it. Its cell 1 must have +0x30 set too. Every cell of a preamble row has it, and a data row's cell 1 has it clear.
Multi-rung format¶
Multi-rung buffers are not concatenated single-rung buffers. They share a single global header and program header, with interleaved data and preamble rows in one cell grid:
[rung 0 data rows] [rung 1 preamble row] [rung 1 data rows] [rung 2 preamble row] ... [terminal row]
The program header's row_word reflects the total grid row count across all rungs.
Only rung 0's comment payload lives in the payload region (pushed at 0x0298). Rung N>0 comments are stored inline in their preamble row's cell 0, at the same +0x30/+0x34/+0x38 offsets.
Page alignment¶
All buffers are padded with zero bytes to the next 0x1000 (4096 byte) boundary. The minimum buffer size for a 1-row rung with no comment is 0x2000 (8192 bytes).
Empty multi-row synthesis¶
Empty rung buffers for N rows (1..32) are synthesized deterministically from a minimal scaffold binary. Payload length formula:
This produces the correct buffer for any row count without needing 32 separate template files.
Instruction blob tag wire types¶
Instruction blobs use tagged fields where each tag is a 2-byte LE value. The tag's high byte encodes the wire type — i.e. how many bytes follow the tag and how to interpret them:
| High byte | Wire type | Payload |
|---|---|---|
| 0x11, 0x12 | flag | No payload (tag presence is the signal) |
| 0x20, 0x21, 0x22 | byte | 1 byte |
| 0x32 | u16 | 2 bytes (uint16 LE) |
| 0x3A | variant_u16 | Sequence of [uint16 index, uint16 value] pairs, terminated by 0xFFFF |
| 0x60, 0x61, 0x62 | string | [length][UTF-16LE value] in SCR (see SCR strings) |
| 0x68 | variant_string | Sequence of [uint16 index, length, UTF-16LE value] entries in SCR, terminated by 0xFFFF |
This rule applies identically to both clipboard and SCR instruction blobs — the tag IDs, wire types, and operand values are the same in both formats. Only the framing differs (see below).
Clipboard vs SCR framing¶
The instruction blob content (tag IDs, operand values, wire types) is identical between clipboard and SCR formats. The difference is how blobs are framed:
Clipboard: blobs are embedded in the cell grid. Each instruction cell is a 0x25-byte cell header + blob + 16-byte cell tail. The blob boundary is found by scanning tagged fields (no explicit length). The 4-byte sentinel FFFFFFFF precedes each string value.
SCR (Scr*.tmp): blobs are stored in instruction sections with explicit framing. Each blob has six bytes after the type code, the part rows and an end_offset pointer:
[class_name as an SCR string][2B type_code]
[2B zero][2B opaque][2B zero][1B part_count]
[part_count part-row bytes][4B end_offset]
[tagged fields...]
In all 1600 blobs of the SCR fixtures, the first, second, fifth and sixth bytes after the type code are zero. The third and fourth bytes are an opaque u16 LE. In the fixtures it runs from 0 to about 0x0EFF (the third byte takes every value 0-255, the fourth 0-14). The box's row span and sub-rows are not in the blob. They are in the entry header (see SCR rung records). part_count is the clipboard blob's part count. Each part-row byte is that part's 1-based rung row, where the clipboard blob stores the rows below the main part. The end_offset is an absolute file pointer to the blob boundary — the same boundary that clipboard's find_blob_boundary() derives by scanning tags. A string tag holds an SCR string. No FFFFFFFF sentinel comes before it.
The byte at end_offset is a 1-byte trailer length (observed 0 or 1): the next structure starts at end_offset + 2 + data[end_offset]. Certain instruction encodings (RD/SD always; Copy/Math/Out/Drum sometimes) emit a 1-byte trailer whose value is opaque.
From a program file to the clipboard¶
A program file stores fewer tags than the clipboard:
- It stores a tag only when its value differs from the default (
tag_default). - It stores a set flag with no payload and leaves a clear flag out. RD's flags
0x1209,0x120A,0x120B,0x121A,0x121B,0x121Eand0x121Fare the other way round. They are set by default, and the program file stores one only when it is clear. - It stores the func code,
0x3218, for some instructions, such as an Out's latch (8195) or reset (8196). It leaves out a Copy's func code, even a one-shot's (8961). - It leaves out some entries of a variant array, even entries that are not zero, such
as those of a Timer's
0x3A05. It stores a0x3Aentry as an unsigned u16.
The clipboard stores every tag of the instruction, in a fixed order for its class. It
writes a clear flag as 0. It writes a set flag as -1 in a Copy, Drum, Math or Search,
and as 1 in a contact, an Out, a For, an RD or an SD. It writes a 0x3A entry as a
signed 16-bit number.
decode_program() builds the clipboard blob of an entry from a form. The form is an
instruction of the entry's class, read from the entry's tags. Its blob gives the order of
the tags, the func code when the entry leaves it out, and the variant entries that the
program file leaves out. The form is read from the same tags, so its func code agrees
with the entry's flags. CLICK reads a Copy's one-shot from the func code (8961, where a
plain Copy of DS into DS has 8960). Then the entry's values are written over the form's
blob:
- A value tag takes the value that the entry stores, as CLICK saved it, or its default.
- A flag keeps the form's value when the form and the entry agree on whether the flag is
set. Otherwise it is written
0when clear, and as its class writes a set flag when set. - A variant entry takes the entry's value when the entry stores it.
- The part rows are the entry's.
Where the encoder's own blob differs from CLICK's, this blob differs too. An RD or SD blob leaves out the empty entries of its arrays, and a Math blob holds 500 reserved slots where CLICK v4 writes more.
For an entry that decodes as RawInstruction, the form is built by the class's parser
without its checks. If no parser builds a form, or the form's blob lacks a tag that the
entry stores, the blob holds only the stored tags. A stored RD flag that is set by default
is written 0, because it is clear. Any other stored flag is written as its class writes a
set flag. For a class that laddercodec does not read, that is 1.
SCR strings¶
The program name, each class name, each string tag and each variant-string entry in an SCR file have the same form. A byte count comes first, then the UTF-16LE text and one NUL byte. The count includes the NUL byte.
TXT1 is stored as 09 54 00 58 00 54 00 31 00 00. A count of 0xFF or more needs the long form, because a first byte of 0xFF marks the long form. A Compare text of 130 characters is stored as ff 05 01, then 261 bytes.
CLICK writes the one-byte form for a count up to 0x7F (63 characters), and the long form for a count of 0x105 (130 characters). Which form it writes for 64 to 126 characters is untested. decode_program() reads either form for any count.
SCR header¶
After the SC-SCR magic and opaque header bytes, offset 0x40 holds the u16 program index: 1 for the main program, 2 and up for subroutines. Offset 0x42 holds the program name as an SCR string. Immediately after the name:
[u16 column_count]
column_count x [u16 numeric column_width] -- includes AF
[u8 display_flags]
[u16 rung_count]
rung_count x RUNG
Widths resembling UTF-16 letters are numeric widths, not condition-family codes. The final width belongs to AF; it is not a file marker. The display byte contains independent settings:
| Mask | Setting |
|---|---|
0x01 |
Nicknames |
0x02 |
Address Comments |
0x04 |
Rung Comments |
0x08 |
Freeze Pane Coil Area |
The common value 0x0D enables nicknames, rung comments, and the frozen coil area. It is not a delimiter. Header parsing retains the byte internally without requiring a particular setting; the public Program model exposes the name, index, and semantic rungs, not editor display settings.
SCR rung records¶
Every rung, including rung zero, has the same framing:
RUNG = [u16 rung_index] -- zero-based ordinal, asserted sequential
[u32 rtf_len][rtf body]
TOPOLOGY
[u16 instr_count] -- 0 = no instruction section
[u32 section_marker] -- only when instr_count > 0; opaque
instr_count x ENTRY
ENTRY = [u8 stored_row][u8 col][u8 row_span][u8 sub_rows][u8 entry_seq][3B opaque] + blob
row_span and sub_rows are the bytes a clipboard cell holds at +0x09 and +0x0A: 01 01 for a condition, the box's height for an AF instruction (02 02 for a Copy, 02 03 for a timed Out, 01 03 for a Math box). They match the clipboard copy at every AF cell of the native SCR/clipboard pairs.
Instruction rows start at one because stored row zero is the special comment/preamble row. Blob pointers and trailer lengths determine the next entry position (see above). The apparent old u32 rung count was the u16 count followed by rung zero's u16 index.
The main program's file (prog_idx == 1) has a two-byte tail after the last rung. Subroutines end at the last record. The parser enforces the declared count, sequential indices, and final cursor.
Malformed framing ends the walk. The rungs before it decode, and one undecoded marker stands for that rung and every rung after it. The marker's error gives the offset.
Only the next record's prefix confirms where a record ends. For the last record, only the file's end confirms it. A section count that is one too low ends a record early and leaves its later bytes to be read as the next prefix. So the marker starts at the record before in these cases:
- a prefix is cut off
- a prefix holds the wrong index
- the file does not end after the last record
Trailing content-less records before the marker are dropped, as in a clean file. The parser never searches for a later rung to resume decoding.
CLICK keeps trailing content-less editor rungs, sometimes fully wired. The decoder parses them and then omits trailing records with neither instructions nor a raw comment. This existing semantic-output policy is separate from structural parsing.
SCR row-topology blocks¶
[u16 stored_row_count] -- includes the special first row
stored_row_count x ROW
[u16 down_column_count] -- normally 32; a count, not an end marker
down_column_count x DOWN_LIST
ROW = [u8 row_flags][u16 entry_count]
entry_count x [u8 segment][u8 column]
DOWN_LIST = [u16 count][count x u8 stored_row_index]
The first stored row is the comment/preamble row. CLICK initializes it with flags 3 and the next ordinary row with flags 1. 03 00 00 means flags 3 and zero entries; 03 20 00 means flags 3 and 32 entries. Both are ordinary instances of the counted grammar. The latter occurs in tumbler/subroutines/Rotate.scr, where the former decoder incorrectly invoked recovery.
Rows retain their flags and placement-ordered entries in the internal parser. Native column orders include [6,1,0,3,2,4,5]; order must not be required to ascend. The semantic rung builder uses the column set for wire presence.
| SCR data | Clipboard field | Meaning established by native writer |
|---|---|---|
| Ordinary row flags bit 0 | +0x15 |
Set only in column A when the row bit is set |
| Entry segment bit 0 | +0x19 |
Copy the persisted bit for that column |
| Column occurs in row entries | +0x1D |
Right wire is present |
| Row occurs in column's down list | +0x21 |
Down wire is present |
The row flag is not the AF segment flag. Row flags bit 1 is also serialized; the special first row has this bit set, but its complete editing semantics remain uncharacterized. The parser accepts both low row bits. Entry flags currently support bit 0.
Down lists refer to stored row indices starting at one. The decoder subtracts one to obtain ordinary grid coordinates, and rejects zero or out-of-range references. These lists include down wires carried by contact cells, so they cover more than visible T/| wire tokens.
Stored rows and canonical output¶
Ordinary stored rows map directly to grid rows. The decoder preserves their positions and horizontal and vertical connections. Row and segment flags do not determine whether a row exists.
Instruction placement is separate from stored wire entries: an instruction can occupy a cell without a right-wire entry. An AF right-wire becomes a NOP only when no instruction occupies or covers that cell. Covered NOPs are omitted from the decoded instructions; the surrounding wiring remains.
The public Rung model retains instructions and wire geometry, but does not retain raw row or segment flags. Re-encoding constructs flags using the conventions in wire rendering, so it does not preserve every byte of native editor state. Trailing records without instructions or comments are omitted from the decoded program.
CLICK's serializers¶
What CLICK's own writers do:
- Program writer: numeric widths with their scaling, display bits, the u16 rung count backpatched after the rungs, and u16 rung indices.
- Display toggle handlers toggle the four serialized fields.
- Rung serializer: stored row count, row flags, u16 entry counts, pair bytes and the down-column count.
- Clipboard writer: row-bit and column-A tests, entry bit, right presence and down-list matching. Native record origins are eight bytes before this document's clipboard cell origins.
A drum occupies a four-row instruction footprint. When CLICK removes rows is not settled.