Tape to Tape Backup

Developer(s): Larry Kenny
Date: 1986
Type: Program
Platform(s): TS 2068
Tags: Tape

This program implements a tape-to-tape backup utility that uses the TS2068 as a signal reconditioner between two cassette recorders. A 20-byte machine code routine is loaded into RAM at address 60000 via POKE and executed with RANDOMIZE USR. The machine code reads the EAR port (IN 254), extracts the tape signal bit, and re-outputs it to the MIC port (OUT 254), effectively relaying the audio signal in real time. The user is instructed to connect the original tape deck to the EAR input and the backup recorder to the MIC output, adjusting playback volume to minimise border interference during silent sections.


Program Analysis

Program Structure

The program is organised into three phases: machine code loading (lines 10–30), user instructions (lines 35–60), and execution (line 70). The DATA statement at line 100 holds the 20-byte machine code payload. Line 10 uses CLEAR 60000 to protect the target memory area from BASIC, and the FOR loop at lines 20–30 POKEs each byte into place before clearing the screen and printing instructions.

Machine Code Routine

The 20 bytes at address 60000 form a tight real-time relay loop. Disassembling the DATA values:

  1. 243 — DI (disable interrupts, preventing interference during tight loop)
  2. 219, 254 — IN A,(254) — read the keyboard/EAR port
  3. 31 — RRA (rotate right through carry)
  4. 31 — RRA
  5. 31 — RRA (three rotations shift bit 6, the EAR bit, into the carry flag area)
  6. 48, 10 — JR NC, +10 (jump forward if carry clear — signal low)
  7. 203, 95 — BIT 3,L (tests a register bit — used here as a timing/filler instruction)
  8. 40, 2 — JR Z, +2 (conditional branch)
  9. 246, 4 — OR 4 — set bit 2 (MIC bit) in accumulator
  10. 211, 254 — OUT (254),A — write to the border/MIC port
  11. 24, 239 — JR -17 (loop back to the IN instruction — offset 239 = -17 signed)
  12. 251 — EI (re-enable interrupts — reached only on exit)
  13. 201 — RET

The routine continuously samples the EAR input and drives the MIC output accordingly, acting as a hardware-level signal relay. Interrupts are disabled for the duration via DI to ensure timing consistency; EI and RET at the end cleanly return control to BASIC, though in normal operation the loop is exited only if the author intended a specific break condition (the JR NC path does not output and loops back, while the taken path outputs the MIC bit).

Key BASIC Idioms

  • CLEAR 60000 — sets RAMTOP below the machine code area, protecting it from BASIC’s memory allocation.
  • RANDOMIZE USR 60000 — standard idiom for calling a machine code subroutine; the return value from USR is discarded by RANDOMIZE.
  • The FOR/READ/POKE/NEXT pattern (lines 20–30) is the canonical self-installing machine code loader in Sinclair BASIC.

Relocatability

The REM header at line 4 notes the routine is relocatable. Inspection confirms this: the machine code contains only relative jumps (JR) and I/O instructions with fixed port numbers. There are no absolute JP or CALL instructions, so the 20-byte block can be POKEd to any address and called with the corresponding USR value without modification.

Hardware Usage

PortDirectionPurpose
254 (0xFE) INReadEAR input — tape signal from original cassette deck
254 (0xFE) OUTWriteMIC/border output — relayed signal to backup recorder

Both input and output share port 254, which is the standard ULA port. Bit 6 of the read value carries the EAR signal; bit 2 of the write value drives the MIC output. The border colour bits are also affected by the OUT instruction, which is why the user is advised to adjust volume to minimise border flickering during silent tape sections.

Notable Techniques

  • Disabling interrupts ensures the relay loop runs without the 50 Hz interrupt breaking the timing, which could cause dropout artefacts in the copied signal.
  • The use of three consecutive RRA instructions to extract the EAR bit is an efficient alternative to masking with AND.
  • The tight 10-instruction loop minimises latency between sampling and output, which is critical for accurate waveform reproduction.

Content

Appears On

The foundation of Tony Willing's numbered library series — play Breakout, write documents in a 64-column word processor, morph a triangle into a square with flicker-free animation, or run a complete fig-FORTH system. Fifty programs covering every category.

Related Products

Related Articles

Program to backup any 2068 program on cassette with two tape recorders.

Related Content

Image Gallery

Source Code

    1 REM "Tape to Tape Backup"
    2 REM By Larry Kenny
    3 REM SUM Magazine June 1986
    4 REM Routine is relocateable
   10 CLEAR 60000
   20 FOR a=60000 TO 60019
   25 READ x: POKE a,x
   30 NEXT a: CLS 
   35 PRINT : PRINT "Tape to Tape Backup by          Larry Kenny of Larken Electronic"
   40 PRINT : PRINT "  This program is for making    tape to tape copies using the   2068 as a signal reconditioner": PRINT 
   50 PRINT "  Using 2 tape recorders, play  the original tape into the      input of the 2068 (ear) and     record your backup tape from    the output of the 2068 (mic).   Adjust the play volume so the   border doesn't flicker too much on the silent periods of the    tape."
   60 PRINT : PRINT "  Rewind both tape recorders andstart them both at the same time",,"TYPE 3 to stop"
   70 RANDOMIZE USR 60000
  100 DATA 243,219,254,31,31,31,48,10,203,95,40,2,246,4,211,254,24,239,251,201

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top