RPAPI 1: the RETRO-PORT serial API

Version 1, for RETRO-PORT firmware 0.5.5 and later. N9TAX RetroLAB, November 2026.

RETRO-PORT is a serial gateway that puts a vintage terminal or computer on the internet. Normally it talks to a person: menus, a web browser, telnet and so on. This document is for programmers. It describes a second way in: a simple protocol that a program on the vintage machine can use over the same serial line. With it, a program can list, copy, write and delete files on RETRO-PORT's SD card, have RETRO-PORT download files from the internet, and read its clock and status.

The protocol is built for slow machines and simple languages. Commands and replies are short lines of plain ASCII. The program is always in charge: RETRO-PORT sends one reply per command and never more data than the program asked for, so a BASIC program on a 4.77 MHz PC keeps up without any flow control.

Ready-made clients are at the end of this document: RPX for the IBM PC and PC/XT (Turbo Pascal, with source), a short QBasic / GW-BASIC example, and a Python reference client with a test suite.

The serial line

Use the line exactly as you use it with RETRO-PORT's menus: the same speed, 8 data bits, no parity, 1 stop bit, no flow control. RETRO-PORT's speed is set in its Configuration menu; 9600 is common.

Binary data needs an 8-bit clean line. If your line or machine only passes 7 bits, use hex mode (MODE HEX), which keeps every byte printable.

RETRO-PORT's line delay setting (for terminals that scroll slowly) doesn't apply to the API.

Getting in

Send the wake string: two SYN characters, the letters RPAPI, and a carriage return. In hex:

16 16 52 50 41 50 49 0D

In BASIC:

PRINT #1, CHR$(22); CHR$(22);
PRINT #1, "RPAPI"; CHR$(13);

RETRO-PORT answers with a blank line and the sign-on:

OK RPAPI 1 RETRO-PORT 0.5.5 BLOCK=1024

The 1 is the protocol version. BLOCK is the largest block READ and WRITE accept. More words may be added at the end of this line in later versions; ignore any you don't know.

The wake works whenever RETRO-PORT is showing one of its own screens: the terminal type question at power-on, the menus and every prompt in them, the file browser, the web and Gopher viewer, the Meshtastic screens and the screen saver. It doesn't work inside a telnet, SSH or IRC session, because there the bytes go to the remote computer, and it doesn't work during a transfer or a game. If RETRO-PORT is busy for a moment (fetching the weather, say), it answers when it next waits for a key.

Whatever was on the screen is put back when the program leaves with BYE.

A reliable start

A client should get in like this:

The last step matters. If a wake was answered late or twice, a second sign-on may still be on its way, and it would be taken for the reply to your next command.

A slow program (BASIC on an 8-bit machine, say) may not keep up with a screen that is being redrawn. It can do this instead: send the wake, wait 2 seconds, throw away everything that arrived, then send HELLO with its word and look for that reply. The QBasic example does this.

Commands and replies

A command is one line: words separated by spaces, ended by a carriage return. A line feed after it is fine. Command names may be in either case. Put a name that contains spaces in double quotes:

STAT "My Letter.txt"

Lines can be up to 299 characters. Use plain ASCII. Backspace or DEL removes the last character, and CAN (hex 18) throws away the line typed so far.

Every command gets exactly one status line back, ending with CR LF:

OK [more]
ER code text

Before the status line, some commands send data lines, which start with "=" and a space:

= F 41216 2026-11-02 10:15 ZORK1.COM ZORK1.COM

READ answers with a DATA line instead of OK. WRITE, XGET and XPUT send a GO line first, then the status line once the data has moved.

Ignore blank lines, and ignore data lines you don't understand: later versions may add some. RETRO-PORT never sends anything unasked.

Error codes

400  bad command, arguments, name
     or data
404  not found (or not a folder,
     or a folder)
405  no such handle, or open for
     reading
409  exists, not empty, denied, or all
     4 handles in use
412  WRITE data damaged: send it again
413  count is larger than BLOCK
499  cancelled
500  card or transfer failure
502  network: the server could not be
     reached or didn't send the file
503  not available: no SD card, no
     network, or the clock isn't set
504  WRITE data stopped coming
507  card full

The text after the code says more, in English. Programs should act on the code.

Data blocks

File data moves in blocks of up to BLOCK bytes (1024 in this version), each checked with a CRC.

From RETRO-PORT: READ

READ handle offset count

RETRO-PORT replies:

DATA n crc

then exactly n bytes. n is the number of bytes read: fewer than count at the end of the file, and 0 at or after the end. crc is the CRC of those n bytes as 4 hex digits. If the CRC doesn't match, send the same READ again. Because the offset is in every READ, repeating one is always safe.

To RETRO-PORT: WRITE

WRITE handle offset count crc

RETRO-PORT checks the command first. If something is wrong, it answers ER and wants no data. Otherwise it answers:

GO

Then send exactly count bytes. RETRO-PORT writes them and replies with the file's new size:

OK 41216

If the data arrived damaged, the reply is ER 412: send the same WRITE again. If you would rather not work out the CRC (a BASIC program, say), send - in its place and RETRO-PORT won't check it. If the data stops coming for 10 seconds, RETRO-PORT gives up with ER 504, after waiting until the line has been quiet for half a second.

offset can't be past the end of the file: files are written from the start, or appended to. A WRITE with a count of 0 changes nothing and gets OK with the size, without GO. Each WRITE reaches the card before OK, so a power cut loses at most the block being sent.

Binary and hex

In binary mode (MODE BIN, the default) a block is the bytes themselves.

In hex mode (MODE HEX), each byte is two hex digits, 0-9 and A-F. RETRO-PORT sends 64 digits (32 bytes) per line, each line ending CR LF. When you send in hex, line breaks and spaces are up to you: RETRO-PORT skips them and counts digits. Hex mode doubles the size, but it gets through 7-bit lines and is easy to read with LINE INPUT.

The CRC

The CRC is CRC-16/XMODEM, the same one XMODEM-CRC uses: polynomial 1021 hex, starting value 0. The 9 bytes "123456789" give 31C3. In C:

unsigned crc16(unsigned char *p,int n)
{
  unsigned c = 0;
  int i;
  while (n--) {
    c ^= (unsigned)*p++ << 8;
    for (i = 0; i < 8; i++)
      c = c & 0x8000 ?
          (c << 1) ^ 0x1021 : c << 1;
    c &= 0xFFFF;
  }
  return c;
}

In QBasic (long integers):

CR& = 0
FOR I = 1 TO LEN(D$)
 CR& = CR& XOR ASC(MID$(D$,I,1))*256&
 FOR J = 1 TO 8
  CR& = CR& * 2
  IF CR& AND 65536 THEN
   CR& = (CR& XOR &H1021) AND 65535
  END IF
 NEXT J
NEXT I

A table of 256 values makes it much faster; RPX.PAS has one.

Commands

HELLO [word]

The sign-on, and a fresh start: all files are closed, the mode goes back to BIN, echo goes off and the current folder is the root. With a word, the word is added to the end of the reply:

HELLO X42
OK RPAPI 1 RETRO-PORT 0.5.5 BLOCK=1024 X42

The wake string, sent while already in the API, is answered like HELLO.

BYE

BYE
OK BYE

Closes all files and goes back to the screen RETRO-PORT was showing, which it redraws. Three Ctrl-C characters in a row do the same, without a reply.

MODE BIN | MODE HEX

How blocks are sent, in both directions. The reply names the mode: OK BIN or OK HEX. MODE alone shows it.

ECHO ON | ECHO OFF

With ECHO ON, RETRO-PORT echoes what is typed, so you can try the API by hand from a terminal program. It is off by default, and programs should leave it off.

HELP

The commands, as data lines.

STATUS

Data lines with what RETRO-PORT knows about itself:

= VERSION 0.5.5
= NET UP 10.1.2.152
= WIFI MyNetwork
= CARD YES
= TIME 2026-11-25 14:02:33 CST
= POWER BATTERY 78 3950
= TERM VT100
= BAUD 9600
OK

NET is UP with the address, or DOWN. CARD is YES or NO. TIME is NONE until the clock is set. POWER is USB, or BATTERY with the percent and the cell's millivolts; there is no POWER line on boards without a battery gauge. Ignore lines you don't know.

TIME

OK 2026-11-25 14:02:33 3 -0600 CST

The local time, as RETRO-PORT's Configuration menu sets the zone. The fields are always in the same columns: the date in 1-10, the time in 12-19, the day of the week in 21 (0 is Sunday), and the offset from UTC in 23-27, then the zone's name. RETRO-PORT gets the time from the internet; before it has, the reply is ER 503. RPX's SETTIME command uses this to set a PC's clock.

FREE

OK 7580160 3101024

The card's size and its free space, in kilobytes (1024 bytes). The first time on a large FAT32 card it may take a minute or more to count. Meanwhile RETRO-PORT sends progress lines (= COUNTING 30%), and a CAN or Ctrl-C stops it with ER 499. After that the card remembers the count.

CD [folder]

CD /GAMES
OK /GAMES

Sets the current folder: other commands' paths start there unless they begin with /. CD alone shows it. ER 404 if there is no such folder.

DIR [path [start [count]]]

DIR /GAMES
= D 0 2026-11-02 10:14 SAVES SAVES
= F 41216 2026-11-02 10:15 ZORK1.COM ZORK1.COM
= F 5120 2026-11-03 09:00 READ_M~1.TXT read me first.txt
OK 3

Lists a folder, the current one if path is left out. The last part of path may hold the wildcards * and ?, as in DIR *.COM. Each data line has six fields, separated by single spaces:

The status line gives the number of entries sent. To read a long folder a page at a time, give start (how many entries to skip) and count (how many to send). The status ends with MORE if entries are left:

DIR /GAMES 0 20
...
OK 20 MORE
DIR /GAMES 20 20

Use . as the path for the current folder. A path that names a file lists just that file. Entries come in the card's own order, not sorted. Files are dated by RETRO-PORT's clock; files written before firmware 0.5.5 show 2026-06-01.

STAT path

STAT ZORK1.COM
OK F 41216 2026-11-02 10:15 ZORK1.COM ZORK1.COM

One entry, in the same six fields as DIR. ER 404 if it doesn't exist.

MKDIR folder, DEL path, REN old new

MKDIR makes a folder. DEL deletes a file, or a folder if it is empty (ER 409 if it isn't). REN renames a file or folder, and also moves it when new is in another folder:

REN ZORK1.COM /GAMES/ZORK1.COM

All three answer OK.

OPEN path mode

OPEN /GAMES/ZORK1.COM R
OK 1 41216

Opens a file and answers with a handle (1 to 4) and the file's size. mode is:

A is how to resume an upload that was cut off: the size in the reply is where to carry on. Up to 4 files can be open at once. Don't open the same file twice for writing.

CLOSE [handle]

Closes a file, or all of them with no handle. Always close a file you have written.

READ handle offset count

See Data blocks. count can be up to BLOCK.

WRITE handle offset count crc

See Data blocks. The handle must be open with W or A.

XGET path [X | 1K | Y]

XGET /GAMES/ZORK1.COM 1K
GO
(an XMODEM transfer to your program)
OK

Sends a file by XMODEM, for programs that already have XMODEM code. X is XMODEM with 128-byte blocks (the default), 1K is XMODEM-1K, Y is YMODEM. After GO, start your XMODEM receive. As usual for XMODEM, the receiver repeats its C (or NAK) every few seconds until the first block arrives, and RETRO-PORT waits up to a minute for it. The status line comes after the transfer: OK, or ER 500 if it failed.

XPUT path

XPUT /GAMES/MYPROG.COM
GO
(an XMODEM transfer from your program)
OK 4096

Receives a file by XMODEM (checksum or CRC, 128- or 1024-byte blocks). The reply gives the size of the stored file, which XMODEM pads to a whole number of blocks with Ctrl-Z characters. Use WRITE when the exact size matters.

FETCH url [path]

FETCH http://example.com/zork.zip
= 16384 51210
= 40960 51210
OK 51210 /DOWNLOAD/zork.zip

RETRO-PORT downloads the URL to its SD card, by itself. The URL can be http://, https:// or gopher://, and redirects are followed. Without a path, the file goes in /DOWNLOAD, named after the last part of the URL. Every 2 seconds a progress line gives the bytes so far, and the total when the server says it. Send CAN or Ctrl-C to stop; the reply is then ER 499 and the partial file is deleted. The reply is ER 502 if the server can't be reached or doesn't send the file; the text says why, such as HTTP 404. Put a URL that contains spaces in quotes.

HTTPS certificates are not checked: RETRO-PORT has no certificate store.

Paths and names

Paths use / between folders; \ works too. A path that starts with / starts at the card's root; any other path starts at the current folder (see CD). . is the current folder and .. the one above.

The card is FAT32 or exFAT, so names may be long and contain spaces. Upper and lower case are the same. On FAT cards every file also has an 8.3 name, which DIR and STAT show and which works in every command. That suits DOS and CP/M, which can't use long names.

An example

The program's lines are marked >, RETRO-PORT's <. The binary data after each DATA line is not shown, and the CRCs are made up.

> (wake)
< OK RPAPI 1 RETRO-PORT 0.5.5
  BLOCK=1024
> HELLO X42
< OK RPAPI 1 RETRO-PORT 0.5.5
  BLOCK=1024 X42
> DIR /GAMES/*.COM
< = F 41216 2026-11-02 10:15
    ZORK1.COM ZORK1.COM
< OK 1
> OPEN /GAMES/ZORK1.COM R
< OK 1 41216
> READ 1 0 1024
< DATA 1024 7A3F
> READ 1 1024 1024
< DATA 1024 0B12
  ...
> READ 1 40960 1024
< DATA 256 51C0
> READ 1 41216 1024
< DATA 0 0000
> CLOSE 1
< OK
> BYE
< OK BYE

(Long lines are broken here to fit. On the serial line, each is one line.)

Writing a client

The clients

Download: RPX.EXE | RPX.PAS | RPGET.BAS | rpapi.py | RPAPI.TXT (this page as text)

The files are at http://n9taxretrolab.net/api/

Versions

RPAPI 1 came with RETRO-PORT firmware 0.5.5 (November 2026), and retro-ports servers built from it.

Later versions may add commands, data lines and words at the end of replies. Clients written for version 1 keep working. A change that would break them gets a new version number in the sign-on.

73 de N9TAX