TRACE is a machine-code debugging utility for the Sinclair BASIC environment that intercepts program execution to display each line number as it runs. The BASIC loader checks whether the machine code has already been loaded by PEEKing address 23681 (a system variable area), and if not, branches to line 9999 which saves both the BASIC and a 700-byte code block starting at address 64608. The machine code is activated with RANDOMIZE USR 65298 and deactivated with RANDOMIZE USR 65305, providing two distinct entry points seven bytes apart in the code block. The program warns users to disable the tracer while writing code, as the trace hook would interfere with normal editing, and notes that UDG character definitions are preserved by the routine.
Program Structure
The program is split into two functional phases: an interactive loader/setup (lines 10–80) and a save/load block (lines 9000–9999). On first run, if the machine code is not yet resident, the program falls through to line 9010 to load it from tape. On subsequent runs with code already loaded, it activates the tracer directly.
| Lines | Role |
|---|---|
| 10 | REM banner (title, author, copyright) |
| 20 | CLEAR to protect machine code area; print banner |
| 30 | Presence check via PEEK; branch to save routine if not loaded |
| 40–80 | User instructions and activation |
| 9000–9010 | Tape load entry point for the machine code block |
| 9999 | Save both BASIC and code files, then verify |
Machine Code Usage
The utility relies entirely on a 700-byte machine code block loaded to address 64608 (just above the CLEAR 64600 boundary). Two entry points are documented:
RANDOMIZE USR 65298— activates the trace hookRANDOMIZE USR 65305— deactivates the trace hook
The 7-byte offset between entry points suggests a short header or jump table at the start of the routine. The code likely patches the BASIC line-execution vector or uses the error/event handler mechanism to intercept control before each statement, printing the current line number. The author explicitly states UDG definitions are not disturbed, implying the routine carefully preserves or avoids the UDG area at the top of RAM.
Presence Detection
Line 30 uses PEEK 23681 to determine whether the machine code is already in memory. Address 23681 falls within the system variables region (CHANS area boundary) but is here repurposed as a flag byte written by the machine code on initialisation. A value of zero indicates the code has not yet run, so the program lists line 9999 (triggering the save sequence) and halts.
Key BASIC Idioms
CLEAR 64600— sets RAMTOP to protect the machine code workspace from BASIC’s memory allocator.LIST 9999followed bySTOPin line 30 is an unusual idiom;LIST 9999causes the editor to jump to that line, effectively redirecting the user to trigger the save block manually — thoughGO TO 9999would be more conventional.RANDOMIZE USRis the standard method to call machine code and discard any return value harmlessly.- Triple apostrophes after the PRINT in line 20 (
''') emit three blank lines, providing visual spacing in the output.
Save and Distribution Strategy
Line 9999 saves the BASIC loader as "TRACE" with auto-start at line 9000 (the tape-load entry), then saves exactly 700 bytes of machine code from address 64608 as "TRACE CODE", and verifies both files. This two-file tape layout is the conventional approach for distributing machine code utilities: the BASIC file auto-runs and loads the companion code block.
Content
Source Code
10 REM TRACE WRITTEN BY ERIC BOISVERT COPYRIGHT 1986 BYTE POWER
20 CLEAR 64600: PRINT "TRACE WRITTEN BY ERIC BOISVERT COPYRIGHT BYTE POWER 1986"'''
30 IF PEEK 23681=0 THEN LIST 9999: STOP
40 PRINT "TRACE IS NOW ON"
50 PRINT '"RANDOMIZE USR 65298 TO START RANDOMIZE USR 65305 TO STOP"
55 PRINT ''"UDG'S ARE NOT AFFECTED."
60 PRINT ''"DELETE LINE 10,9999 (DELETE 1,)"
70 PRINT '"WHEN PROGRAMMING TRACE SHOULD BEOFF!"
80 RANDOMIZE USR 65298: STOP
9000 REM LOAD CODES
9010 LOAD "TRACE CODE"CODE
9020 GO TO 1
9999 SAVE "TRACE" LINE 9000: SAVE "TRACE CODE"CODE 64608,700: VERIFY "TRACE": VERIFY "TRACE CODE"CODE
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
