Egghead.page Logo

How Sinclair ZX81 Differentiated Keyword and Text Input

The Sinclair ZX81 utilized a unique input system to conserve memory, distinguishing between programming commands and standard text through specific cursor states and shift key combinations. This article explores the technical mechanism behind the K and L cursors, explaining how users toggled between keyword mode and letter mode to write BASIC programs and string data efficiently on the iconic 1981 home computer.

Memory Constraints and Tokenization

The primary driver behind the ZX81’s input method was the severe limitation of hardware resources. With only 1KB of RAM in the base model, storing full text for programming commands like PRINT, GOTO, or LOAD would have been prohibitively expensive. To solve this, Sinclair Research implemented a tokenization system where every BASIC keyword was stored as a single byte in memory rather than as a string of characters. When a user typed a command, the computer needed to know whether to store a single byte token or individual ASCII character codes for text.

The K and L Cursor States

To manage this differentiation, the ZX81 employed two distinct cursor modes visible on the screen. When the computer was ready to accept a new line number or command, it displayed a flashing K cursor, standing for Keyword mode. In this state, pressing a key would trigger the ROM to search for a BASIC command associated with that key. For example, pressing the P key would immediately insert the token for PRINT. Conversely, when the computer needed to accept standard alphanumeric data, it displayed an L cursor, standing for Letter mode. In this state, keys produced standard characters rather than commands.

Toggling Input Modes with the Shift Key

Users manually controlled the differentiation between these modes using the SHIFT key. Pressing SHIFT while in Keyword mode would toggle the cursor to Letter mode, allowing the programmer to type variable names or arguments that were not commands. Pressing SHIFT again would return the cursor to Keyword mode. This toggle mechanism gave the user precise control over how the interpreter parsed their input, ensuring that variable names were not accidentally converted into system commands.

Automatic Mode Switching in Quotes

The ZX81 ROM also featured logic to automatically handle mode switching during string manipulation. When a user typed a quotation mark to begin a string literal, the system automatically switched from Keyword mode to Letter mode. This ensured that any text typed inside the quotes was treated as standard data rather than executable commands. Once the closing quotation mark was entered, the cursor would revert to Keyword mode, allowing the user to continue writing program logic without manually toggling the shift key.

Technical Implementation in the ROM

Under the hood, the differentiation process relied on lookup tables stored in the read-only memory. When a key was pressed in Keyword mode, the firmware scanned a table to match the keystroke with a reserved token value. If a match was found, the token was inserted into the program line. In Letter mode, the keystroke was processed as a standard ASCII code. This efficient parsing method allowed the ZX81 to maximize its available memory for program storage while maintaining a functional programming environment despite its minimal hardware specifications.