ROM Copier

This file is part of and Timex Sinclair Public Domain Library Tape 1004. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Utility

This program copies the ZX81/TS1000 ROM into RAM and then saves the resulting memory image to tape. It uses RAND USR 16514 at line 20 to execute a machine code routine (stored or located at address 16514) that performs the ROM-to-RAM copy operation. The user is instructed to flip a hardware switch to select RAM before the SAVE is performed. After the NEW command clears BASIC variables, the program saves a file and restarts, suggesting a two-stage bootstrap process.


Program Analysis

Program Structure

The program is short and linear, running through seven active lines in sequence. Its purpose is to invoke a machine code ROM-copy routine, prompt the user to perform a hardware action, then save the resulting memory state to tape.

LineStatementRole
10REMContains embedded data or a machine code routine header; the REM body includes tokenised keywords, suggesting packed data.
20RAND USR 16514Calls machine code at address 16514 (decimal), which is within the system variables / display file area — likely the start of a routine embedded in the REM line or pre-POKEd elsewhere.
25–40PRINTUser instructions: informs that the ROM has been copied and directs the user to set a physical RAM/ROM selector switch.
50INPUT Z$Pauses execution, waiting for the user to press ENTER after performing the hardware step.
60NEWClears BASIC program and variables from RAM so only the copied ROM image remains in the lower address space.
70SAVE "1018%5"Saves the memory image to tape; the filename encodes addressing information (1018 and 5 in inverse video), likely interpreted by a loader.
80RUNRestarts from line 10 if execution somehow returns (defensive tail).

Machine Code Usage

RAND USR 16514 transfers control to address 16514 (0x4082), which on the ZX81/TS1000 falls in the region just above the system variables (which end at 0x4009). Address 16514 is only 9 bytes into user RAM, strongly suggesting that the machine code entry point is packed inside the REM statement at line 10. The REM body contains what appear to be tokenised BASIC keywords used as opcode bytes — a classic ZX81 technique for hiding Z80 machine code inside a REM line, where the interpreter never executes the content but the bytes are present in memory at a known address.

Hardware Context

The message “SET BOTTOM SWITCH TO RAM POS” refers to a hardware modification common on ZX81/TS1000 machines: an aftermarket or home-built board that allows the 8 KB ROM address space (0x0000–0x1FFF) to be remapped so that RAM is visible there instead. After the machine code at line 20 copies the ROM contents into a RAM bank, the user physically flips a switch to make that RAM respond to the low address space, effectively creating a writable ROM shadow. This allows patching of the operating system.

Key BASIC Idioms and Techniques

  • REM as data store: Line 10’s REM contains what is almost certainly Z80 opcodes disguised as tokenised keyword bytes, a well-known ZX81 technique for self-contained machine code programs.
  • RAND USR for ML entry: RAND USR is the standard ZX81/TS1000 idiom for calling machine code; the return value is discarded by RAND, avoiding a type-mismatch error.
  • NEW before SAVE: Issuing NEW before SAVE clears the BASIC program from RAM, ensuring only the ROM image occupies the relevant address range and is not overwritten by the BASIC listings during the save operation.
  • INPUT Z$ as a pause: Using INPUT Z$ rather than PAUSE provides an indefinite wait that requires deliberate user confirmation — appropriate here since a physical hardware action must be completed before proceeding.

Anomalies and Notes

After NEW at line 60 clears the program, lines 70 and 80 no longer exist in memory, so execution cannot reach them under normal circumstances. This means the SAVE and subsequent RUN must be triggered by the machine code routine itself, or the NEW is expected to be intercepted/patched. Alternatively, the machine code called at line 20 may set up a deferred execution path. This apparent dead-code after NEW is a known two-stage loader pattern rather than a bug.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10176 – 10210.

Related Products

Related Articles

Related Content

Image Gallery

ROM Copier

Source Code

  10 REM \'  4"VAL VAL LPRINT SGN GOSUB %STAN 
  20 RAND USR 16514
  25 PRINT "ROM NOW COPIED INTO RAM "
  30 PRINT "SET BOTTOM SWITCH TO RAM POS"
  40 PRINT "PRESS ENTER"
  50 INPUT Z$
  60 NEW 
  70 SAVE "1018%5"
  80 RUN 

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

People

No people associated with this content.

Scroll to Top