sercp
-----

https://vym.cz/sercp/


Sercp [stands for Serial copy] is brand new software for ZX Spectrum and PC intended to send/receive files of any kind between computers. On ZX side Sercp is designed to work as external command of Esxdos. It uses built-in serial port of Spectrum +128K, +2, +2A, +3 connected to internal sound chip’s I/O pins. Main motivation for this project was a need to share files between PC and ZX and sometimes between two ZXs using just standard built-in stock hardware.

News

    serial cables for ZX Spectrum 128/+2/+2A/+3 are available – send me e-mail
    .sercp is included in since Esxdos-0.8.7
    .sercp-v0.5
        improved hw data flow
        path support for receiving
        proper return to basic
    .sercp-v0.5EL – for eLeMeNt ZX
        works with element’s internal USB serial converter
        uses hw uart 115200Bd with 2048 B fifo

Main features

    fastest and most convenient way to send/receive any files to/from Speccy without additional communication hardware
    works well with USB-serial cables as well as standard COM ports (RS-232 standard)
    no need to frequently eject/insert card or disk no more carrying physical media from PC to ZX and vice versa
    transfer is also possible between two Speccys – no need to use PC
    Serial settings: 38400Bd, 8N1, RTS/CTS flow control*
    tested with USB-Serial converters on PC side with following chips: FTDI, PL2303, CP2102 and CH340
    file date/time transfer support**

*) flow control is used only between blocks – see the technical details.
**) latest sercp is ready to date/time handling. It requires latest Esxdos.

Limitations

    no re-initiate transfer of bad blocks
    uses Speccy’s RAM from 0xC000 to 0xFFFF – see technical information
    works well with files up to 300kB, larger files copy takes too long
    no LFN support*

*) support will be added after Esxdos gets this feature


Installation
------------

ESXDOS: copy (by the traditional way*) sercp to /bin folder and use as common external command by .sercp

For eLeMeNt ZX is required .sercp-v0.5EL.You need to replace original file /bin/sercp.

.sercp -h            ....is good starting point

PC: copy sercp (sercp.exe or sercp32.exe) to path where system finds command. On Linux suggested location is /usr/local/bin. On Windows there is no good place – you can copy sercp.exe to c:\Windows\system\ or similar suitable. Sorry I’m not Windows user.

sercp -h            ....is good starting point

*) traditional way for copying takes many steps: turn off the spectrum, remove CF/SD card, connect card to PC, (auto)mount filesystem, find target folder, find source folder, copy file, unmout card, remove card from pc, connect card to ZX, turn on the Spectrum…
Compiling from sources

make - compile sources to linux executable file
make install - install sercp  to /usr/local/bin
make windows - compile windows exe files - uses mingw

Add user to group „dialout“ – no need to run sercp as root (or sudo).

sudo usermod dialout -a -G "user"

On some Linux systems may be useful to remove modemmanager.

sudo apt-get remove modemmanager


Using sercp
-----------

Send file from Spectrum

.sercp filename.ext
.sercp /path/to/filename.ext

Receive file to Spectrum with optional path to file

.sercp -r
.sercp -r /path/to

Send file from PC

  ---Linux---
sercp -d /dev/ttyUSB0 filename.ext
sercp -d /dev/ttyUSB0 /path/to/filename.ext
  ---Windows---
sercp.exe -d com5 filename.ext
sercp.exe -d com5 \path\to\filename.ext

Receive file to PC to actual folder/directory

  ---Linux---
sercp -d /dev/ttyUSB0 -r
  ---Windows---
sercp.exe -d com5 -r


Technical information about sercp on Speccy

    Transfer is realized on block basis. Each transfer adds a structure called fileinfo which contains filename, length and checksum of each block.
    Hardware flow control is used between blocks not between bytes
    Block size is 16kiB. Last block may be shorter.
    Checksums of blocks is realized as XOR of all bytes and 8-bit SUM of all bytes (both together) – see fileinfo.
    Filename format is 8.3 DOS format, no LFN for Esxdos v0.8.x.
    sercp uses Speccy’s RAM from 0xC000 to 0xFFFF as 16kiB buffer for blocks
    The stack is saved in Esxdos’s RAM and after transfer the stack is recreated to its original place. No need to move RAMTOP.

Refinement of operation to eLeMeNt ZX

    Used internal FTDI USB Serial converter
    Serial settings: 115200Bd, 8N1, none
        There is no internal wires to control flow via RTS/CTS – requires the use of a pause while writing to the sd card. See the -w and -n switches of sercp on PC.
    TODO: add switch .sercp to change baudrate to 38400Bd for compatibility with other Speccy.
    to install on eLeMeNt ZX you have to do:
        download sercp-el.tar and copy to the sd card to /tmp
        .cd /tmp
        .mv /bin/sercp /bin/sercp-zx – backup original .sercp
        .tar -x sercp-el.tar – extraxct /bin/sercp
        .sercp

Technical information about sercp on PC

    converts long file names to 8.3 format – first 4 character plus last 8 characters (last 4 characters of name and 4 for suffix „.ext“). Example: longfilename.ext -> longname.ext
    works in command line
    tested on Linux (Fedora, Ubuntu, RPi-Raspbian) and Windows (7, 10, 11)
    waits until Speccy saves block on storage – waits about 800 ms and uses hardware flow control for testing when Speccy is ready to receive next block
    source code is available – see download section

Refinement of sercp settings for eLeMeNt ZX

    sercp-pc-0.3.7 or above is required
    use -n switch to disable RTS/CTS flow control
    use -b 115200 for change baudrate
    use waiting -w 1000 or more for writing blocks to the SD card. Time in milliseconds – 1000..1s
    on some SD cards, especially on gigabytes full filesystem, writing 16k blocks takes a long time – for example 6 seconds, use -w 6000

Example:
sercp.exe -d com6 -b 115200 -n -w 2000 file.tap


fileinfo – internal structure

Fileinfo structure is sent/received before actual file data. Fileinfo size is 1109 bytes. Fileinfo can hold information relevant for up to 256 blocks. Max. file length is 256 x 16kiB = 4MiB. Four megabytes ought to be enough for anyone…

typedef struct {
	uint16_t block_len;	// legth of block
	uint8_t  block_xor;	// xor of all bytes in block
	uint8_t  block_sum;	// 8-bit sum of all bytes in block
} __attribute__((packed)) fi_sum;// used as fi_blocks in fileinfo

typedef struct {
	uint16_t length;	// length of data in fileinfo
	uint8_t h_xor;		// xor of all bytes of fileinfo
	uint8_t h_sum;		// sum of all bytes of fileinfo
	uint8_t fi_numblocks;	// number of transfered blocks
	uint8_t fi_name[64];	// filename (8.3 format for now)
	uint8_t fi_reserved[12];// reserved
	uint16_t fi_time[1];	// fat file time
	uint16_t fi_date[1];	// fat file date
	fi_sum fi_blocks[256];	// blocks - see fi_sums above
} __attribute__((packed)) FILEINFO;



More information on the website https://vym.cz/sercp/

