Function of PEEK and POKE in Sinclair ZX81 BASIC
The Sinclair ZX81 was a pioneering home computer that relied heavily on direct memory manipulation for advanced programming. This article explores the specific roles of the PEEK and POKE commands within ZX81 BASIC, explaining how they allowed users to read from and write to specific memory addresses. By understanding these functions, programmers could access system variables, modify display characteristics, and interact with hardware features that were otherwise inaccessible through standard BASIC commands.
The ZX81 operated with a very limited amount of memory, often just 1KB internally, with an optional 16KB RAM pack. Because the built-in BASIC interpreter was designed to be compact, it did not include high-level commands for every hardware function. To bridge this gap, Sinclair implemented PEEK and POKE, commands borrowed from earlier systems like the Altair and popularized by the Apple II and Commodore PET. These commands provided a direct window into the machine’s memory map, allowing the CPU to interact with specific bytes of data stored in RAM or mapped hardware registers.
The PEEK command was used to read the value stored at a specific
memory address. When a user executed a command like
PRINT PEEK 16384, the computer would return the decimal
value of the byte found at that location. This was essential for
checking the status of system flags, reading keyboard input buffers
directly, or analyzing the contents of the display file. Since the ZX81
generated its video output dynamically from a specific area of memory
known as the display file, PEEK allowed programmers to inspect exactly
what was being sent to the television screen without relying on the
standard text output methods.
Conversely, the POKE command was used to write a value to a specific
memory address. The syntax typically followed the format
POKE address, value. This function was far more powerful
and dangerous than PEEK. By poking values into specific addresses, a
programmer could change system variables, alter the behavior of the
BASIC interpreter, or create graphics by manipulating the display file
directly. For example, poking specific values into the memory range
reserved for the display could create custom characters or simple pixel
graphics, bypassing the standard character-based screen limitations.
However, using POKE carried significant risks. The memory map of the ZX81 contained critical system data, including the program itself and the system variables that controlled the machine’s operation. Writing incorrect data to the wrong address could easily crash the computer, corrupt the running program, or cause the system to freeze, requiring a power cycle. Despite the danger, these commands were indispensable for creating games and utilities that pushed the hardware beyond its intended design. They enabled developers to optimize code speed, manage memory manually, and access hardware features that Sinclair did not expose through standard BASIC keywords.
In summary, PEEK and POKE served as the low-level interface between the ZX81 BASIC language and the underlying hardware. They transformed the ZX81 from a simple learning machine into a platform capable of complex software development. By granting direct access to memory addresses, these commands empowered users to overcome the limitations of the minimalistic BASIC interpreter, making them fundamental tools for any serious ZX81 programmer during the early 1980s home computing boom.