ComLynx serial

The single-wire ComLynx port — the Mikey UART hardware and its quirks, the static lynx/serial.h library that drives it, and the historical Epyx “Redeye” round-robin protocol that the original multiplayer games ran on top of it.

1. Overview

Every Lynx carries a serial port — the four-pin ComLynx jack, driven by a UART inside the Mikey chip. It is how the original games linked up to eight (electrically up to 18) consoles into a single session. Unlike an ordinary RS-232 link it has exactly one data wire shared by everyone: transmit and receive are tied together, so it behaves like a party-line bus rather than a point-to-point cable.

ComLynx — one shared, open-collector data wire +5V R pull-up DATA (bi-directional) Lynx 0 Tx + Rx tied Lynx 1 Tx + Rx tied Lynx 2 Tx + Rx tied Lynx n up to 18
One idle-high, open-collector line pulled up to +5V. Any console can pull it low to send; every console — including the sender — hears the result.

The consequences of that one wire run through the rest of this page. Only one console may transmit at a time; there is no hardware arbitration, no handshaking, and no framing beyond the byte. If two consoles transmit at once the collision usually surfaces as a framing error on everyone. Any real multiplayer protocol — turn-taking, retransmission, player logon — has to be built in software (see the historical Redeye system in section 4).

lynxcc exposes the port through a small static library (section 3); this page first documents the hardware it sits on (section 2), because the library deliberately surfaces the hardware's quirks rather than hiding them.

2. The Mikey UART

The serial hardware is a fairly ordinary UART living in the Mikey chip, wired to the ComLynx (historically “REDEYE”) connector. It is controlled through the SERCTL/SERDAT registers and clocked by Mikey timer 4. The paragraphs below distil Mikey's own UART specification.

2.1. Connector and signals

The connector carries one bi-directional serial data pin, one ground and one VCC. The data pin idles in an open-collector state, held high by a pull-up resistor to +5V; a console sends by pulling it low. A fourth signal, NOEXP, indicates whether a plug is present in the socket.

There is a documented power-up defect: the output stage comes up as a TTL high rather than open-collector, so all code must set the TXOPEN bit to place the driver in its correct open-collector mode before the bus behaves. The lynxcc library does this for you as part of ser_open().

Any non-Lynx device sharing the socket needs its own intelligent protocol to distinguish itself from a genuine Redeye peer.

2.2. Baud-rate generation

The baud rate is generated by timer 4 (exposed in lynx/lynx.h as _UART_TIMER at $FD14). The bit rate is

baud = CLOCK4 ÷ (TIMER4 + 1) ÷ 8 CLOCK4 1–15625 µs tick ÷ (TIMER4+1) reload 1–255 ÷ 8 7.63 – 62500 baud
Timer 4 reload of 1–255 and a 1–15625 µs source clock give a maximum of 62.5 Kbaud and a minimum of about 7.63 baud.

With the fastest clock (1 µs) and the smallest reload, a handful of common rates come out as follows — the small residual error is well within a UART's tolerance:

Baud (nominal)CLOCK4TIMER4 reloadActual
625001 µs162500
96001 µs129615
24001 µs512404
12001 µs1031202
3002 µs207300.5

The two “native” Lynx speeds used by the linked games are 62500 and 31250 baud; the library exposes those plus the usual RS-232-style rates down to 75 baud (section 3.1).

2.3. Data format

The frame is the standard 11 bits and is not configurable in width: one start bit, eight data bits sent least-significant first, a ninth (parity) bit, and one stop bit.

The 11-bit ComLynx frame S D0 D1 D2 D3 D4 D5 D6 D7 P/9 St start = 0 8 data bits — LSB (D0) first parity or 9th bit stop = 1
Every byte on the wire is 11 bits. Data length (8) and stop bits (1) are fixed; only the parity/9th bit is programmable.

The ninth bit is where Mikey's UART departs from the rest of the world. On transmit the ninth bit is always sent: either the result of a parity calculation on the data byte or a fixed value taken from the parity-select bit, chosen by the parity-enable bit. On receive the state of the ninth bit is always readable, and the hardware always checks parity — receive parity checking cannot be disabled.

The catch, admitted in Mikey's own documentation, is that the parity calculation includes the parity bit itself. That makes the EVEN and ODD modes non-standard: they will not agree with a conventional UART. The two modes that behave predictably against outside equipment are MARK and SPACE (a fixed 1 or 0 in the ninth bit). For Lynx-to-Lynx traffic, where both ends share the same quirk, EVEN parity works fine.

2.4. Break

A break is a start bit followed by a data value of 0 and the absence of a stop bit at the expected time — effectively holding the line in its start state. Setting the transmit-break bit sends a break for as long as the bit stays set, so the sender controls its length directly. The receiver only recognises a break once the line has been held for at least 24 bit times; that is the specific threshold Mikey chose among the many “standard” break lengths.

2.5. Status, errors and the interrupt quirk

The transmitter exposes two status bits. TXRDY means the holding register has been copied into the shift register and can be reloaded with the next byte (it is also set after reset). TXEMPTY means both the holding and shift registers are empty and nothing more is going out on the wire — the stronger condition to wait on before, say, switching the line around or powering down.

There are three receive errors, all of them always enabled:

Parity error

The received parity did not match the parity-select setting. Because parity checking cannot be turned off, a link that disagrees about parity mode reports this constantly — the reason Lynx-to-PC links need MARK/SPACE.

Framing error

A non-zero character arrived without the expected stop bit. On the shared bus this most often means two consoles transmitted at once and their bits collided.

Overrun error

A new character arrived before the previous one had been read out of the receive buffer.

All three latch until cleared by writing the control byte with the reset-error bit set; the reset-error bit is not an enable, and writing with it clear leaves the errors untouched.

The sharpest edge is the interrupt behaviour. Both the transmit and receive interrupts are level-sensitive, not edge-sensitive: an interrupt is asserted continuously for as long as it is enabled and its buffer is ready. The software therefore has to disable the interrupt before it clears the condition, or the handler re-enters immediately. The lynxcc IRQ handler performs exactly this disable-before-clear dance, and it must be preserved byte-for-byte — it is load-bearing, not incidental.

3. The lynxcc serial library

There is no loadable serial driver in this tree. ComLynx is a static, smart-linked library declared in <lynx/serial.h>: five entry points, both directions interrupt driven through 256-byte ring buffers. Any use of the port pulls in the shared core and its interrupt handler; a program that never touches serial links none of it. See design/LYNX_JOY_SER_DESIGN.md for the de-driverisation design and the function reference for the per-call entries.

The five functions are ser_open, ser_get, ser_put, ser_status and ser_close.

3.1. Opening the port

ser_open() takes a struct ser_params, programs timer 4 and the frame format, fixes the TXOPEN power-up defect (section 2.1) and enables the serial interrupts. It is a __fastcall__ function, so a prototype must be in scope. Call it with interrupts enabled:

#include <lynx/serial.h>

static void initialize (void)
{
    struct ser_params params = {
        SER_BAUD_62500,   /* a Lynx-native rate for Lynx-to-Lynx links */
        SER_BITS_8,       /* only 8 is accepted                        */
        SER_STOP_1,       /* only 1 is accepted                        */
        SER_PAR_EVEN,     /* EVEN is fine between two Lynxes            */
        SER_HS_NONE       /* the wire cannot handshake                 */
    };
    CLI();
    if (ser_open(&params) != SER_ERR_OK) {
        /* unsupported baud, or init failed */
    }
}

The five fields map one-to-one onto the constants in <lynx/serial.h>. Only the values noted below are legal; a bad combination is reported at open time rather than silently accepted.

Baud rate (baudrate)

One of SER_BAUD_62500, SER_BAUD_31250, SER_BAUD_9600, SER_BAUD_7200, SER_BAUD_4800, SER_BAUD_3600, SER_BAUD_2400, SER_BAUD_1800, SER_BAUD_1200, SER_BAUD_600, SER_BAUD_300, SER_BAUD_150, SER_BAUD_134_5, SER_BAUD_110 or SER_BAUD_75. A rate the hardware cannot produce returns SER_ERR_BAUD_UNAVAIL. 62500 and 31250 are the speeds the original linked games used.

Data bits (databits)

SER_BITS_8 only — the frame is fixed at eight data bits (section 2.3).

Stop bits (stopbits)

SER_STOP_1 only — there is always exactly one stop bit.

Parity (parity)

SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK or SER_PAR_SPACE. SER_PAR_NONE is rejected: the hardware always sends a ninth bit, so there is no parity-less mode. Use EVEN between two Lynxes; use MARK or SPACE when talking to a standard PC, because the Lynx parity quirk (section 2.3) makes EVEN/ODD incompatible with ordinary equipment.

Handshake (handshake)

SER_HS_NONE only. The single-wire bus has no room for hardware handshake lines, and software (XON/XOFF-style) handshaking is impossible too since there is only one data wire shared by all parties.

3.2. Sending and receiving

ser_put(b) queues one byte in the transmit ring buffer and kicks the transmit interrupt; it returns SER_ERR_OVERFLOW if the buffer is full. ser_get(&b) pops one byte from the receive ring buffer and returns SER_ERR_NO_DATA when nothing is waiting — a normal, non-fatal condition you poll on:

char ch;

ser_put('A');                              /* broadcast one byte      */

while (ser_get(&ch) == SER_ERR_NO_DATA)
    ;                                      /* wait for a byte to land */
/* ch now holds the received byte */

Remember the open-collector loopback: on the shared wire every byte you transmit also comes back to you through ser_get(), which doubles as a simple self-test but means a real protocol must account for hearing its own traffic.

3.3. Status and error codes

ser_status(&s) returns the status bits the interrupt handler has accumulated since the port was opened — the Mikey error bits plus a software-detected receive-buffer overflow:

SER_STATUS_BREAK       0x02   break received
SER_STATUS_FE          0x04   framing error
SER_STATUS_OE          0x08   hardware overrun error
SER_STATUS_PE          0x10   parity error
SER_STATUS_RXOVERFLOW  0x80   receive ring buffer overflowed

A persistent SER_STATUS_FE usually means another console is transmitting at the same time (section 2.5). The call return values are a separate, contiguous set — always compare against the macros, never bare integers, because the static library renumbered them relative to stock cc65:

SER_ERR_OK            0x00   not an error — relax
SER_ERR_BAUD_UNAVAIL  0x01   baud rate not available
SER_ERR_NO_DATA       0x02   nothing to read
SER_ERR_OVERFLOW      0x03   no room in the send buffer
SER_ERR_INIT_FAILED   0x04   initialisation failed

3.4. Closing the port

ser_close() genuinely closes the port: it disables the serial interrupts, stops the baud timer (timer 4) and drops any buffered data. This is a deliberate behaviour change from the old cc65 driver, whose CLOSE was a stub that returned OK without touching the hardware — so code that closes and then expects to keep receiving must be revisited.

3.5. Quirks and limitations

Most of these follow directly from the hardware in section 2; the library surfaces them rather than papering over them:

4. The Redeye protocol (historical)

The lynxcc library gives you a byte pipe and stops there: “there is no protocol created for communication — you are on your own.” The original Epyx development kit shipped a complete multiplayer layer on top of that pipe, called Redeye (after the connector name). It is not part of this SDK and none of its routines are provided here, but understanding how the shipping Lynx games actually linked up is useful background if you are building your own protocol, so it is summarised below. The material comes from Epyx's own Redeye documentation (dated 15 October 1990); the names are theirs.

4.1. Round-robin communication frames

Redeye runs a round-robin, communication-frame based system. When all is well, player 0 (the master) sends its data, then player 1, then player 2, and so on around the ring. Acknowledgement is implicit: sending your next message tells everyone your previous receipts all arrived. Even a console with nothing new to say must still send a message each frame so the others know their data got through. If something goes wrong the master acts as director — prompting a late unit for its data, or retransmitting data another unit says it missed. All of this happens in the interrupt handlers; the game code only exchanges data through a few “glue” routines.

Redeye round-robin frame Player 0 master Player 1 Player 2 each unit sends once per frame — sending implies “all received”
Turn order flows from the master around the ring; the master re-prompts or retransmits when a unit is late or reports missing data.

Note that a Redeye “game frame” is one pass through the game's main loop, not the 60 Hz video frame or the 240 Hz audio frame; it is usually longer and is not tied to them.

4.2. Logon

Because the system needs to learn who is present, communication begins with a logon, using a scheme close to a two-wire Ethernet-style contention protocol. Each unit initially calls itself player 0, waits, then announces its identity. If it hears another unit claim the number it holds, it picks a new, unclaimed number. After any communication a unit waits a random interval — short if it holds the next sequential number, longer otherwise — and the randomness prevents two units that think they share a number from speaking in lock-step.

When every unit agrees on the system state and a player has requested that logon end, the request is acknowledged and logon completes; disagreement can delay or deny termination until another request. Crucially, once logon finishes Redeye shuts down its logon code entirely so the game can reclaim that memory before normal play begins.

4.3. Normal communication

After logon the game calls the system routine to re-install the interrupts for normal play. From then on each game frame the code writes its outgoing bytes into OutGoingData and signals the system that the data is ready. Incoming data is trickier: it is accumulated into two parallel buffers, PlayerData0 and PlayerData1, for the even and odd frame sequences. A Seq flag says which sequence to read this frame (counter-intuitively, zero means read the ODD buffer). Per-player flag arrays (PlayerFlag0/PlayerFlag1) go positive when a player's data has arrived; after consuming it the game sets the flag negative to acknowledge, at which point the system may immediately overwrite that slot. Receipt of the local console's own message must be handshaked exactly like everyone else's, even though the data is already known locally.

Redeye message — 3 overhead bytes + data size header player data checksum 1 B 1 B 0 – PLAYER_DATA_SIZE 1 B
Each Redeye message carries three overhead bytes around the payload. Shorter messages mean fewer interrupts, so variable-size data helps performance.

Redeye ships a ready-made “glue” layer for the common case of passing only joystick and button state: a handful of routines drive logon, start normal communication, and once per game frame swap current inputs into joystick/switch arrays (keeping the previous frame in oldjoystick/oldswitch) so a game can go multiplayer with very little code of its own. FLIP and RESET are handled by the glue during both logon and play.

4.4. Constants and switches

A game configures Redeye by defining these before including the system files:

SERIALPORT_USER

Declares that the program uses the serial (Redeye) port.

GAME_ID

A unique game identifier, 1–65534 (see section 4.5). Two different games must not try to link.

MAX_PLAYERS

The most players this game allows, 2–16.

PLAYER_DATA_SIZE

Maximum bytes in one player's message, 1–256/MAX_PLAYERS.

VAR_SIZE_DATA

Optional switch enabling variable-length messages — larger code, but better performance because only changed data need be sent.

REDEYE_SLOWNESS

Slows the link to survive heavy interrupt load (digitised sound, for example). Values 0–3 select 62500, 31250, 15625 or 7812.5 baud; each step halves the rate. At the maximum, communication runs eight times slower but still supports a four-player, two-byte-per-player game at about 15 frames per second. It does not change the logon baud rate.

The system also expects the game to supply variables — preferably in zero page — that it reads: NumberOfPlayers (players logged in, minus one) and PlayerNumber (this unit's assigned number), plus the logon-control pair EndLogonRequest and LogonInProgress.

4.5. Game ID numbers

Each linked game needed a unique GAME_ID so that only matching titles would communicate. The IDs Epyx listed as in use were:

IDGame
0test programs
1Gauntlet — The Third Encounter
2Zarlor Mercenary
3California Games
4Xenophobe
5Slime World
6RoboSquash
7Warbirds (Space Wars?)
83Shanghai
4949Rampage
65535test programs

4.6. Limitations and resource cost

The hardware can electrically support up to 18 connected consoles, but Redeye caps a session at 16 players (and the two per-sequence data buffers must each fit in a single page, so MAX_PLAYERS × PLAYER_DATA_SIZE cannot exceed 256). Players may only join or leave during logon; a game that needs drop-in/drop-out has to re-enter logon and re-sort who is who afterwards.

Redeye uses the serial port (timer 4) plus two general-purpose timers (timers 1 and 5) during logon, then shuts all three interrupts down; during normal play it uses timer 4 and one more timer, and with a single player no timers at all. A byte takes about 176 µs to send — slightly longer than one scan line — and each message adds three overhead bytes (size, header, checksum). Heavy or lengthy interrupts elsewhere raise the overhead sharply, which is what REDEYE_SLOWNESS exists to mitigate. As a synchronisation mechanism Redeye ties the game frame across consoles, but it does not guarantee a fixed frame rate, so it is not tight enough for sample-accurate events such as two consoles playing different voices of the same tune.

5. Further reading

The hardware details in section 2 are drawn from Mikey's UART specification, reproduced in 42Bastian's Lynx documentation (monlynx.de, chapter 11 — UART). The Redeye summary in section 4 follows Epyx's original “Documentation for Redeye (ComLynx) support code” (15 October 1990), transcribed at the Diary of an Atari Lynx developer. For the lynxcc library internals see design/LYNX_JOY_SER_DESIGN.md and the per-function pages in the function reference.

6. License

The Lynx runtime, like the rest of the package, is distributed under the cc65 zlib-style license. The full text, together with every other copyright notice in the distribution, is reproduced verbatim on the consolidated Licenses and copyright notices page.