This program is a memory inspection utility that sequentially reads and displays the contents of any address in the ZX81/TS1000’s 64KB address space, showing both the decimal PEEK value and the corresponding CHR$ representation for each byte. It runs in SLOW mode and uses SCROLL to continuously advance through memory one byte at a time. Keyboard controls allow the user to input a new start address (A), return to BASIC (B), pause the display (M using PAUSE 4E4 for approximately 60 seconds), save memory (S), or jump to a main program menu (P). The SAVE routine at line 9992 defaults to the filename “PEEK” if no name is entered, and USR 8297 is called after saving to report remaining free memory bytes.
Program Analysis
Program Structure
The program occupies lines 9967–9999, clearly designed as a subroutine module at the top of the line-number space within a larger BASIC program. It begins with a STOP at line 9967 (a guard against falling into the help screen from above), then displays a help/instruction screen before entering the main memory-display loop. There are three functional sections:
- Help screen and setup (9967–9978): Prints instructions and inputs the starting address into variable
P. - Main display loop (9980–9988): Scrolls through memory one byte at a time, polling
INKEY$for control keys. - Save routine (9992–9999): Prompts for a filename, defaults to “PEEK”, performs
SAVE, and reports free memory.
Main Display Loop
The core loop at lines 9980–9988 prints the current address value P, a tab, the result of PEEK P, and CHR$ PEEK P on one line, then calls SCROLL and increments P before re-entering the loop. This produces a continuously advancing listing of memory contents. Because there is no PAUSE or delay in the base loop, the display scrolls at full SLOW-mode speed.
Key BASIC Idioms and Techniques
SLOWat line 9975 switches to SLOW mode to make the scrolling readable, as the ZX81 display would otherwise be suppressed during FAST-mode computation.PAUSE 4E4at line 9985 uses scientific notation for the pause duration (40000 frames ≈ 10 minutes) as a “freeze” function.GOTO MENUat lines 9986 and 9999 targets a named (non-numeric) label — this is a GO TO targeting a variable whose value is a line number, a common technique for integrating sub-modules into a larger program without hardcoding jump targets.- The
INPUT Pat line 9978 with a bounds checkIF P>65535 THEN GOTO 9978prevents addressing beyond the 16-bit address space. - Line 9997 calls
USR 8297to obtain the number of free memory bytes. Address 8297 is a machine code entry point in the ZX81 ROM or a resident utility routine that returns a value usable in BASIC.
Save Routine
Lines 9992–9999 implement a simple save sub-module. If the user presses Enter without typing a filename, S$ is set to "PEEK" by default (line 9995). After saving, the program checks at line 9998 whether S$="PEE%K" — the %K escape denotes an inverse-video K character, making this an exact-match test for the specific auto-saved filename and returning to the help screen in that case; otherwise control passes to GOTO MENU.
Notable Anomalies
- The
INKEY$checks at lines 9983–9987 are sequential single-line tests with no debounce delay. Because the loop iterates very rapidly in SLOW mode, a single keypress may or may not be caught, and multiple tests within one pass of the loop will each see a freshINKEY$sample, meaning only the first matching test in sequence will fire per pass. - Line 9998 compares
S$to"PEE%K"(with an inverse-K) rather than plain"PEEK". This means the post-save branch back to line 9968 will only trigger for that specific encoded string, which would never match a user-typed filename, effectively making the branch dead code unless the default save path setsS$to that exact internal value. - Lines 9989–9991 clear the screen, list from line 9967 (displaying the module’s own code), and stop — this is the “return to BASIC” path accessed via key B.
Variable Summary
| Variable | Purpose |
|---|---|
P | Current memory address being inspected (0–65535) |
S$ | Filename for SAVE operation; defaults to “PEEK” |
MENU | Numeric variable holding the line number of the main program menu |
Content
Source Code
9967 STOP
9968 PRINT AT 7,4;"PEEK PROGRAM RJV 4/25/85"
9969 PRINT ,,"A TO INPUT NEW ADDRESS"
9970 PRINT "B TO RETURN TO BASIC"
9971 PRINT "M TO PAUSE "
9972 PRINT "P TO RETURN MAIN PROGRAM MENU"
9973 PRINT "S TO SAVE "
9974 PRINT ,,"AFTER PAUSE PRESS ANY KEY EXCEPT A/B/M/P OR S TO CONT "
9975 SLOW
9976 PRINT AT 18,0;" INPUT START ADDRESS "
9977 PRINT AT 20,0;"ADDRESS DEC","CHR$ "
9978 INPUT P
9979 IF P>65535 THEN GOTO 9978
9980 PRINT P;TAB 9;PEEK P,CHR$ PEEK P
9981 SCROLL
9982 LET P=P+1
9983 IF INKEY$="A" THEN GOTO 9978
9984 IF INKEY$="B" THEN GOTO 9989
9985 IF INKEY$="M" THEN PAUSE 4E4
9986 IF INKEY$="P" THEN GOTO MENU
9987 IF INKEY$="S" THEN GOTO 9992
9988 GOTO 9980
9989 CLS
9990 LIST 9967
9991 STOP
9992 CLS
9993 PRINT TAB 9;"START RECORDER"," INPUT FILE NAME",TAB 15;" OR ","ENTER TO SAVE PEEK"
9994 INPUT S$
9995 IF S$="" THEN LET S$="PEEK"
9996 SAVE S$
9997 PRINT USR 8297;" BYTES OF MEMORY LEFT"
9998 IF S$="PEE%K" THEN GOTO 9968
9999 GOTO MENU
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

