Skip to content

Wait for a turn on Sinclair ZX81

Reuse an untimed command or press loop while retaining the machine’s actual display responsibilities.

Enter the complete demo.bas in Sinclair ZX81 BASIC and RUN. Submit 1, then Return. The number is added to the running total; entering 2 adds two.

Sinclair ZX81 native caller after accepted input.
Captured from the running caller in the configuration below.

Keep the world waiting

Initialise N once, show the state, read a submitted value, apply it, then return to the display/input path. Firmware activity does not mean the game world has taken a turn. No artificial frame timer is needed for this caller.

INPUT A is a blocking numeric reader. The caller performs N=N+A, so any valid numeric contribution is added; 0 leaves the total alone. It is not a one-key accept/reject routine.

The actual loop and its machine setup

demo.bas
10 LET N=0
20 CLS
30 PRINT N
31 PRINT "XXX"
32 PRINT "X X"
33 PRINT "XXX"
40 INPUT A
50 LET N=N+A
60 GOTO 20

Fit and adapt it

Copy the INPUT statement into a free numbered line in your own command flow. The complete caller shows where to initialise N and where to return after an update.

BASIC owns the keyboard buffer, line editor, return stack and variable storage. The global variable and line-number names belong to your program: reserve or rename them consistently. INPUT waits; no animation or deadline code in your main path can run during that wait.

Keep the normal display-serviced environment used here. FAST/SLOW choices change what the player sees while the CPU works; the sample does not add an artificial frame timer.

The broken update adds A twice. Submitting 1 reaches 2 immediately. INPUT read the right number; the update used it twice. Restore N=N+A. The caller also checks a nonzero start, so a lost initialiser cannot hide behind zero-filled state.

A repeated-path mistake to recognise

double-add.bas
10 LET N=0
20 CLS
30 PRINT N
31 PRINT "XXX"
32 PRINT "X X"
33 PRINT "XXX"
40 INPUT A
50 LET N=N+A+A
60 GOTO 20
Sinclair ZX81 faulty repeated path.
The fault fails the same rule-state guard as the working caller.

A timed turn is another policy: keep a deadline separately, decide how expiry competes with an arriving action, and service that clock while waiting. A blocking reader cannot provide that service from the same main path. A faster renderer or sound routine does not settle the rule.

See loop choices and the machine’s input entry for the reader’s complete contract.

Verification and sources

Target: stock PAL ROM, 1 KiB RAM, keyword entry. These callers were executed with released Emu198x 0.44.1; assembly uses Asm198x 0.0.71. The sample folder contains reproduction instructions and retained observations. The independent checker binds source, native captures and actual output; its rejection tests exercise wrong state, missing files and false audio claims.

This qualifies the named emulator/firmware path. Pitch accuracy, original hardware and other peripherals require their own observations.

Sinclair, ZX81 BASIC Programming: INPUT, arithmetic, FAST/SLOW and display-file memory; recorded 1 KiB ROM configuration.