17. Key codes carry an event type, and slot 10 holds the action lists¶
Both of these started as claims in harmony-decompiler discussions 5 and 6, which by decision 7 of
docs/plans/002-the-roadmap.md are hypotheses rather than facts to adopt. Both were tested against our own
corpus with our own parser, and both survive. Neither is quoted here as evidence: the numbers
below are ours, and where upstream reports a figure it is noted as an independent second opinion
rather than as the source.
An event code is an event type plus a scan code¶
This corrects a claim this project published. docs/config-format.md and section 8 above
stated that key codes encode 0x80 | (row << 3) | col, with bit 7 marking a matrix key. They do
not. The top two bits are the event type and the rest is the keypad scanner's own scan code:
| Bits 7,6 | Event |
|---|---|
00 |
not a keypad event |
01 |
release |
10 |
press |
11 |
repeat |
Three agreements, and each comes from somewhere different:
The count closes exactly. Decomposed this way, the Harmony 600's 162 records are scan codes 1 to 54, contiguous, appearing once in each of release, press and repeat. 54 times 3 is 162 with nothing left over. The Harmony 700's 163 are the same 162 plus one code with no event bits at all. Under the old reading the same table was 108 "matrix" codes against 54 "non-matrix" ones, and 108 matrix codes cannot describe a 56 position keypad, which is why section 8 above ends by warning that the table could not be the remote's keypad. It is the remote's keypad. The warning was a symptom of the wrong split.
The scan codes fit the scanner's own range, and that comes from the firmware rather than from
the config. Section 13 records that the arch 14 keypad scanner at 0x190A6 returns a linear
index from 1 to 56. The table uses 1 to 54 of exactly that range. The old reading produced rows 0
to 6 and 8 to 14, which is not a range at all, and required a translation layer between the
scanner and the config that nobody could find. No such layer needs to exist.
The three event classes carry an identical scan code set, all 54 shared, in both arch 14 samples. If bit 7 were part of the address then a code and that code with bit 7 set would be different keys, and there would be no reason for the sets to coincide, let alone coincide exactly three times over.
Arch 12 and arch 8 come out differently and cleanly: presses only, 52 on the One and 53 on the
arch 8 remote, with no release or repeat entries, plus the three codes with no event bits (0x06,
0x07, 0x2D) that both share. The One's safe mode config is press of scan 47 and scan 46, which
is the two key recovery combination. So the difference between the architectures is real rather
than an artefact: arch 14 enumerates every event type per key and the older architectures record
only presses.
The earlier finding that arch 8 and arch 12 share a canonical ordering survives unchanged: 47
(event, scan) pairs in common, in identical order once press of scan 14 is dropped. Worth stating
explicitly, since that finding was originally derived under the wrong reading and could easily have
been an artefact of it. It is not.
Section 315: the sharing survives and the word canonical does not. The order is a hash table's bucket order, which is why it survives any reading of the tag's bits.
Upstream's own words for this, from discussion 6, are "Bit 7 was never part of the matrix address",
with the same three event flags. They reached it by reading their architecture's firmware at
0x07160; we reached it by counting our own tables. Two routes, one answer.
What this changes in the code. KeyRecord.is_matrix, .row and .col are gone from
src/harmony/gspm.py, replaced by .event_type, .event_name, .scan_code and .is_keypad.
They were removed rather than deprecated: a wrong reading left available is a wrong reading that
gets used.
A lead that died within the hour, recorded because the way it died is the point. Upstream
describes the arch 9 scanner as a binary search for a column over 8 columns using a single sense
line, driven by exactly 14 masks:
0x0F 0x03 0x01 0x02 0x0C 0x04 0x08 0xF0 0x30 0x10 0x20 0xC0 0x40 0x80. Fourteen is what a binary
search over two nibbles costs, seven per nibble. Since section 13 describes the arch 14 keypad as
14 rows by 4 columns, the obvious suspicion was that "14 rows" was a misreading of a 14 entry mask
table and that the real geometry was 7 by 8, matching their (row << 3) + column.
It is not. Arch 14 computes the index arithmetically and the code says so plainly:
19282: 01 07 DECF 0xd01,F ; row, one based
19288: 04 0d MULLW 0x04 ; times four
1928a: f3 50 MOVF PRODL,W
1928e: 00 25 ADDWF 0xd00,W ; plus column, 1 to 4
MULLW 0x04 settles it: (row - 1) * 4 + column, 14 rows of 4, 1 to 56. The two architectures
have genuinely different keypad hardware and genuinely different scanners, which is unsurprising
given one has a touchscreen and the other does not.
The lesson is the one this project's own doctrine already states and I still walked past: the
answer was in this document, 500 lines above, in a disassembly listing that had been sitting there
since the first Ghidra pass. Reaching for an upstream analogy before re-reading our own code is
exactly the failure decision 7 of docs/decisions.md exists to prevent. The scan codes are
unaffected either way, since those are the scanner's linear index in both readings.
Base slot 10 is the action list address table¶
Each entry addresses an action list, and a list is a u8 count followed by that many three byte
instructions, each a u16 operand and an opcode byte.
The reading is carried by a closure, not by the shape fitting. A list occupies 1 + 3 * count
bytes, and the lists are packed back to back, so consecutive table entries should sit exactly that
far apart. The addresses come from the pointer table and the counts come from the lists themselves,
which are unrelated parts of the file:
| Sample | lists | instructions | consecutive pairs packed |
|---|---|---|---|
| 700 user config, arch 14 | 8037 | 19651 | 8032 of 8036 |
| 600 user config, arch 14 | 4955 | 12194 | 4950 of 4954 |
| One user config, arch 12 | 4277 | 11640 | 4272 of 4276 |
| 88x class config, arch 8 | 1318 | 3311 | 1313 of 1317 |
| 525 config, arch 9 | 487 | 1043 | 482 of 486 |
Exactly four exceptions per config, in every one of them. That regularity is itself the explanation: the lists are packed into five contiguous runs, so four times the next list is somewhere else. Each of those four gaps is tens of kilobytes, never an off by one. On the 700 the runs are four in the region ahead of slot 0 and one inside base slot 9, which accounts precisely for the 7656 and 381 split of where the table's entries point.
The 525 numbers, 487 lists and 482 of 486 packed, are the same numbers harmony-decompiler reports for that file. Reproducing them through our own slot numbering also cross checks the alignment in section 16: their "section 10" and our base slot 10 are the same section.
Opcode meanings are deliberately not adopted. Upstream publishes a partial table (0x7F run
an action list, 0x7E select a record, 0x7D send a command, 0x7C queue a flag, 0x7A down to
0x77 as an accumulator machine's load, add, multiply and divide) derived from the arch 9
firmware. Our data says that table does not transfer as it stands, and that is worth knowing
before anyone leans on it: arch 14's third most common opcode is 0x6C, 2832 occurrences in the
700, and 0x6C does not appear in the 525 sample at all. The inventories do overlap, so this is
one instruction set with per architecture extensions rather than two encodings, but the meanings
have to be read out of the arch 14 firmware. That is now the most valuable thing to look for while
in there.
Section 16 | the archive | section 18. Section 17 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.