Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PTM Peer Protocol

Wire protocol for a peripheral to exchange clock, gate, and timer-output state with a PTM device (config type ptm/6840) over an attached transport.

Connection semantics

Like the VIA Peer Protocol, the PTM supports multiple concurrent peripheral connections over a multipoint transport (tcp: or unix:); pty:/pipe: transports are rejected for ptm/6840 at instantiation time because they can’t tag messages per connected client.

When a peripheral connects, the PTM immediately sends it a full state dump covering all three timers’ clock, gate, and output state. After that, whenever any connected peripheral changes PTM state — or a 6502 program does — every connected peripheral is informed of the change.

Unlike the VIA, the PTM’s message set is asymmetric: the PTM only accepts messages designated as sent by the peripheral (clock and gate edge transitions), and a peripheral only receives messages designated as sent by the PTM (clock, gate, and output state updates). Any other received message is silently ignored; there is no error signaling in either direction.

Message encoding — ASCII or Binary — is chosen per device at configuration time via the protocol attribute (protocol = "ascii" or protocol = "binary"; default ascii), not negotiated per connection, exactly as for the VIA.

[[devices]]
type = "ptm/6840"
address = 0xA000
protocol = "binary"
transport = "unix:/path/to/ptm.sock"

The ASCII encoding is useful for interactive sessions from a terminal or socket utility, for education or debugging. The binary encoding is compact and efficient.

ASCII protocol

Short strings of printable ASCII characters. A receiver must ignore non-printable ASCII control characters (0x00–0x1F, 0x7F), spaces (0x20), and any byte with the high-order bit set, and must not distinguish upper case from lower case letters.

As an aid to human readability, the PTM separates distinct messages with a single space, and emits a canonical CR (0x0D) LF (0x0A) after every 72 characters of messages and spaces.

Message TypeSent ByFormatExampleDescription
Clock EdgePeripheralCnpC21Change the state of an input clock signal; n is the subject timer (1..3); p is the polarity (0=negative, 1=positive)
Gate EdgePeripheralGnpG30Change the state of an input gate signal; n is the subject timer (1..3); p is the polarity (0=negative, 1=positive)
Clock StateMC6840TxyzT010Clock input state; x, y, z are the state (0 or 1) of timers 1, 2, 3 respectively
Gate StateMC6840UxyzU101Gate input state; x, y, z are the state (0 or 1) of timers 1, 2, 3 respectively
Output StateMC6840VxyzV001Timer output state; x, y, z are the state (0 or 1) of timers 1, 2, 3 respectively

Binary protocol

Each message is a single bit-mapped byte with the high-order bit set; subsequent bits determine the message type and parameters. A receiver (peripheral or MC6840) must ignore any received byte whose upper nibble (bits 4–7) doesn’t match one of the recognized patterns below.

Message TypeSent Byb7b6b5b4b3b2b1b0Description
Clock EdgePeripheral1000PC3C2C1P is the polarity (0=negative, 1=positive); each Cx set to 1 signals a transition of clock input Cx
Gate EdgePeripheral1001PG3G2G1P is the polarity (0=negative, 1=positive); each Gx set to 1 signals a transition of gate input Gx
Clock StateMC684010100C3C2C1Each Cx is the current state of clock input Cx
Gate StateMC684010110G3G2G1Each Gx is the current state of gate input Gx
Output StateMC684011000O3O2O1Each Ox is the current state of timer output Ox

x ranges over 1..3, identifying one of the PTM’s three timers, in all rows above.