Skip to content

Read a command on Amstrad CPC

Reuse the actual machine-specific reader, with its caller, state, ownership and a diagnosed input mistake.

Enter the complete demo.bas in Amstrad CPC BASIC and RUN. Submit GO, then Return. One accepted command advances the displayed turn; another gives two.

Amstrad CPC native caller after accepted input.
Captured from the running caller in the configuration below.

Take the reader

Copy read-command.bas into free line numbers, then call it with GOSUB 3000. It replaces A$; the caller checks that value before updating N. Keep N’s initialisation outside the repeated path. Renumber the GOSUB and routine together.

The reusable reader

read-command.bas
3000 INPUT A$
3010 RETURN

INPUT A$ waits for a complete line. The caller compares A$ with the exact uppercase string GO; reading a line does not validate it.

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.

Fit it into a program

The complete numbered program is caller.bas, draw.bas, sound.bas and read-command.bas together. The reader does not accept a move on its own; the IF in the caller does that.

Initialise once, read, validate, then update

caller.bas
10 MEMORY 39999:MODE 1
20 N=0:POKE 40000,0
30 CLS:PRINT "TURN";N
31 GOSUB 1000
40 GOSUB 3000
50 IF A$="GO" THEN N=(N+1) AND 255:GOSUB 2000
60 POKE 40000,N
70 GOTO 30

Change it and recognise a mistake

Replace GO with a short command or dispatch several strings after the reader. Keep the line-number range free.

This deliberately broken caller reuses an accepted command instead of reading another one. The world advances without you. Restore the GOSUB before the validation/update path; the working caller waits at zero until input arrives.

Deliberately broken input/update path

stale-command.bas
10 MEMORY 39999:MODE 1
20 N=0:POKE 40000,0
30 CLS:PRINT "TURN";N
31 GOSUB 1000
40 A$="GO"
50 IF A$="GO" THEN N=(N+1) AND 255:GOSUB 2000
60 POKE 40000,N
70 GOTO 30
1000 PRINT "XXX"
1010 PRINT "X X"
1020 PRINT "XXX"
1030 RETURN
2000 SOUND 1,100,10,15
2010 RETURN
3000 INPUT A$
3010 RETURN
Amstrad CPC deliberately broken input caller.
Observed fault; use the working caller to repair it.

The complete caller

Working setup and integration

demo.bas
10 MEMORY 39999:MODE 1
20 N=0:POKE 40000,0
30 CLS:PRINT "TURN";N
31 GOSUB 1000
40 GOSUB 3000
50 IF A$="GO" THEN N=(N+1) AND 255:GOSUB 2000
60 POKE 40000,N
70 GOTO 30
1000 PRINT "XXX"
1010 PRINT "X X"
1020 PRINT "XXX"
1030 RETURN
2000 SOUND 1,100,10,15
2010 RETURN
3000 INPUT A$
3010 RETURN

For more responsive controls, compare polling, buffering and press edges in input choices.

Verification and sources

Target: CPC464 PAL, Locomotive BASIC, MODE 1. 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.

Amstrad, CPC464 User Instructions: Locomotive BASIC entries INPUT, GOSUB, RETURN and SOUND, including channel/queue behaviour.