--- title: "ROM Copier" id: 57337 type: "computer_media" slug: "copies-rom-into-ram" url: "http://localhost/computer_media/copies-rom-into-ram/" markdown_url: "http://localhost/computer_media/copies-rom-into-ram.md" published_at: "2024-10-04T08:25:37+00:00" modified_at: "2026-03-30T21:18:30+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/09/185_Rom.png" excerpt: "A clever two-stage bootstrap that copies the ROM into RAM via machine code, then saves the result to tape — hardware switch required." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Utility" slug: "utility" taxonomy: "genre" url: "http://localhost/type/utility/" media_contents: - id: 56735 title: "Timex Sinclair Public Domain Library Tape 1004" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1004/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/09/185_Rom.png" media_type_tags: "Utility" --- # ROM Copier 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. | Line | Statement | Role | | --- | --- | --- | | 10 | `REM` | Contains embedded data or a machine code routine header; the REM body includes tokenised keywords, suggesting packed data. | | 20 | `RAND USR 16514` | Calls 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–40 | `PRINT` | User instructions: informs that the ROM has been copied and directs the user to set a physical RAM/ROM selector switch. | | 50 | `INPUT Z$` | Pauses execution, waiting for the user to press ENTER after performing the hardware step. | | 60 | `NEW` | Clears BASIC program and variables from RAM so only the copied ROM image remains in the lower address space. | | 70 | `SAVE "1018%5"` | Saves the memory image to tape; the filename encodes addressing information (1018 and 5 in inverse video), likely interpreted by a loader. | | 80 | `RUN` | Restarts 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. ## 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 ```