Skip to content

Locomotive BASIC reference ​

Every command, function and operator in Locomotive BASIC, the full-featured BASIC of the Amstrad CPC — with real structured keywords such as IF … THEN … ELSE, WHILE … WEND and the AFTER/EVERY interrupt timers.

Three machines run it here: the CPC 464 with BASIC 1.0, and the CPC 664 and CPC 6128 with BASIC 1.1, which adds eleven keywords to the same language.

In this reference: Hardware · Escape codes · File formats · Argument notation

Notes and caveats ​

  • ' opens a comment as REM does, and is shown beside it in the table below; the search box finds the keyword by it.
  • Line numbers 1–65535, strictly ascending; multiple statements per line with :. ? is shorthand for PRINT, ' for REM, and LET is optional.
  • Variable names are up to 40 characters, all significant, with $ (string), % (integer) and ! (real) type suffixes.
  • Numbers may be written in decimal, hex (&7F00) or binary (&X1010); operators include ^ (power, folding left to right so 2^3^2 is 64), \ (integer divide), MOD and XOR. AND, OR and NOT are bitwise, and a true comparison is -1.
  • Read the keyboard in games with INKEY(n) — it returns -1 while a key is up. The cursor keys are INKEY(0) up, INKEY(2) down, INKEY(8) left and INKEY(1) right. JOY(0) returns the joystick as a bit mask (bit 0 up, 1 down, 2 left, 3 right, 4 fire 2, 5 fire 1).
  • Entries tagged BASIC 1.1 only are the additions Locomotive BASIC 1.1 (the CPC 664 and CPC 6128) brings; the BASIC 1.0 464 rejects them. Everything untagged works on all three machines and produces the same program on each, so a listing that avoids the tagged entries moves between them unchanged.

Command Function Operator

Syntax & description
-<number> - <number> | -<number>
Subtraction / negation.
''
Comment shorthand (same as REM).
*<number> * <number>
Multiplication.
/<number> / <number>
Division.
\<number> \ <number>
Integer division.
^<number> ^ <number>
Exponentiation.
+<number> + <number> | <string> + <string>
Addition / concatenation.
<<number> < <number> | <string> < <string>
Less than.
<=<number> <= <number> | <string> <= <string>
Less than or equal.
<><number> <> <number> | <string> <> <string>
Not equal.
=<var> = <expr> | <expr> = <expr>
Assignment / equality.
><number> > <number> | <string> > <string>
Greater than.
>=<number> >= <number> | <string> >= <string>
Greater than or equal.
ABSABS(<number>)
Absolute value.
AFTERAFTER <number>[, <timer>] GOSUB <line>
Call a subroutine after a delay (1/50s units).
AND<number> AND <number>
Bitwise/logical AND.
ASCASC(<string>)
Character code of the first character.
ATNATN(<number>)
Arctangent.
AUTOAUTO [<line>][, <number>]
Automatic line numbering (editor command).
BIN$BIN$(<number>[, <number>])
Number as a binary string.
BORDERBORDER <colour>[, <colour>]
Set the border colour (two colours flash).
CALLCALL <addr>[, <arg>]…
Call a machine-code routine.
CATCAT
Catalogue the cassette/disc.
CHAINCHAIN <filename>[, <line>]
Load and run another program.
CHAIN MERGECHAIN MERGE <filename>[, <line>]
Load and merge another program, then run.
CHR$CHR$(<number>)
Character with code n.
CINTCINT(<number>)
Round to a 16-bit integer.
CLEARCLEAR
Clear all variables.
CLEAR INPUTBASIC 1.1 onlyCLEAR INPUT
Discard pending keyboard input.
CLGCLG [<pen>]
Clear the graphics screen.
CLOSEINCLOSEIN
Close the input file.
CLOSEOUTCLOSEOUT
Close the output file.
CLSCLS [#<stream>]
Clear the screen (or a window).
CONTCONT
Continue after break or STOP.
COPYCHR$BASIC 1.1 onlyCOPYCHR$(#<stream>)
Character under the text cursor.
COSCOS(<number>)
Cosine.
CREALCREAL(<number>)
Convert to a real number.
CURSORBASIC 1.1 onlyCURSOR [<number>][, <number>]
Switch the text cursor on or off.
DATADATA <constant>[, <constant>]…
Inline data for READ.
DEC$BASIC 1.1 onlyDEC$(<number>, <string>)
Number formatted to a template.
DEFDEF FN<name>[(<param>[, <param>]…)] = <expr>
Define a function.
DEFINTDEFINT <letter>[-<letter>]
Default listed initial letters to integer type.
DEFREALDEFREAL <letter>[-<letter>]
Default listed initial letters to real type.
DEFSTRDEFSTR <letter>[-<letter>]
Default listed initial letters to string type.
DEGDEG
Degrees mode for trigonometry.
DELETEDELETE <line>-<line>
Delete a range of lines (editor command).
DERRBASIC 1.1 onlyDERR
Disc error number of the last error.
DIDI
Disable timer interrupts.
DIMDIM <var>(<number>[, <number>]…)
Dimension an array.
DRAWDRAW <x>, <y>[, <pen>]
Draw a line to graphics point x,y.
DRAWRDRAWR <dx>, <dy>[, <pen>]
Draw a line relative to the graphics cursor.
EDITEDIT <line>
Edit a program line (editor command).
EIEI
Enable timer interrupts.
ELSEIF <number> THEN <statement> ELSE <statement>
Alternative branch of IF…THEN.
ENDEND
End the program.
ENTENT <envelope>[, <section>]…
Defines a tone envelope, numbered 1 to 15, that SOUND can use to sweep a note in pitch. Takes up to five sections, each of a step count, a step size and a pause; a negative envelope number makes the sweep absolute rather than relative.
ENVENV <envelope>[, <section>]…
Defines a volume envelope, numbered 1 to 15, that SOUND can use to shape a note over time. Takes up to five sections, each of a step count, a step size and a pause.
EOFEOF
True at end of the input file.
ERASEERASE <var>[, <var>]…
Erase arrays.
ERLERL
Line number of the last error.
ERRERR
Error number of the last error.
ERRORERROR <number>
Raise an error.
EVERYEVERY <number>[, <timer>] GOSUB <line>
Call a subroutine repeatedly (1/50s units).
EXPEXP(<number>)
e to the power n.
FILLBASIC 1.1 onlyFILL <pen>
Flood-fill from the graphics cursor.
FIXFIX(<number>)
Truncate towards zero.
FNFN<name>[(<arg>[, <arg>]…)]
Call a user-defined function.
FORFOR <numvar> = <number> TO <number> [STEP <number>]
Start a counted loop.
FRAMEBASIC 1.1 onlyFRAME
Wait for a display frame flyback.
FREFRE(0) | FRE("")
Free BASIC memory.
GOSUBGOSUB <line>
Call a subroutine by line number.
GOTOGOTO <line>
Jump to a line number.
GRAPHICSBASIC 1.1 onlyGRAPHICS PEN [<pen>][, <number>]
GRAPHICS PEN / PAPER prefix.
GRAPHICS PAPERBASIC 1.1 onlyGRAPHICS PAPER <pen>
Set the graphics background ink.
GRAPHICS PENBASIC 1.1 onlyGRAPHICS PEN [<pen>][, <number>]
Set the graphics drawing ink.
HEX$HEX$(<number>[, <number>])
Number as a hex string.
HIMEMHIMEM
Top of BASIC memory.
IFIF <number> THEN <statement> [ELSE <statement>]
Conditional execution.
INKINK <pen>, <colour>[, <colour>]
Assign a colour to a pen (two colours flash).
INKEYINKEY(<key>)
Test a key by key number (-1 if up).
INKEY$INKEY$
Read a key as a string ("" if none).
INPINP(<port>)
Read a byte from an I/O port.
INPUTINPUT [#<stream>,] [<prompt>;] <var>[, <var>]…
Read values from the keyboard or a file.
INSTRINSTR([<start>,] <string>, <string>)
Find b$ within a$.
INTINT(<number>)
Round towards minus infinity.
JOYJOY(<number>)
Read a joystick (bit mask).
KEYKEY <number>, <string>
Define an expansion (function-key) string.
KEY DEFKEY DEF <key>, <number>[, <number>[, <number>[, <number>]]]
Redefine a key of the keyboard.
LEFT$LEFT$(<string>, <length>)
Leftmost n characters.
LENLEN(<string>)
String length.
LETLET <var> = <expr>
Assignment (LET is optional).
LINELINE INPUT [#<stream>,] <strvar>
LINE INPUT reads a whole line of text.
LINE INPUTLINE INPUT [#<stream>,] <strvar>
Read a whole line of text.
LISTLIST [<line>-<line>][, #<stream>]
List the program.
LOADLOAD <filename>[, <addr>]
Load a program.
LOCATELOCATE [#<stream>,] <col>, <row>
Move the text cursor.
LOGLOG(<number>)
Natural logarithm.
LOG10LOG10(<number>)
Base-10 logarithm.
LOWER$LOWER$(<string>)
Lower-case copy of a string.
MASKBASIC 1.1 onlyMASK [<mask>][, <number>]
Set the line-drawing dot pattern.
MAXMAX(<number>[, <number>]…)
Largest of its arguments.
MEMORYMEMORY <addr>
Set the top of BASIC memory (HIMEM).
MERGEMERGE <filename>
Merge a program from tape/disc.
MID$MID$(<string>, <start>[, <length>])
Substring (also assignable as a statement).
MINMIN(<number>[, <number>]…)
Smallest of its arguments.
MOD<number> MOD <number>
Integer remainder.
MODEMODE <mode>
Select screen mode 0-2.
MOVEMOVE <x>, <y>
Move the graphics cursor.
MOVERMOVER <dx>, <dy>
Move the graphics cursor relatively.
NEWNEW
Erase the current program.
NEXTNEXT [<numvar>]
End of a FOR loop.
NOTNOT <number>
Bitwise/logical NOT.
ONON <number> GOTO <line>[, <line>]… | ON <number> GOSUB <line>[, <line>]…
Jumps to the line at the given position in the list, counting from 1; falls through to the next statement when the value is 0 or past the end of the list.
ON BREAKON BREAK GOSUB <line>
Trap the ESC (break) key.
ON BREAK CONTBASIC 1.1 onlyON BREAK CONT
Ignore the ESC (break) key.
ON BREAK GOSUBON BREAK GOSUB <line>
Call a subroutine when ESC breaks.
ON BREAK STOPON BREAK STOP
Restore normal ESC (break) handling.
ON ERROR GOTOON ERROR GOTO <line>
Trap runtime errors.
OPENINOPENIN <filename>
Open a file for input.
OPENOUTOPENOUT <filename>
Open a file for output.
OR<number> OR <number>
Bitwise/logical OR.
ORIGINORIGIN <x>, <y>[, <left>, <right>, <top>, <bottom>]
Set the graphics origin (and window).
OUTOUT <port>, <byte>
Write a byte to an I/O port.
PAPERPAPER [#<stream>,] <pen>
Set the text background pen.
PEEKPEEK(<addr>)
Read a byte of memory.
PENPEN [#<stream>,] <pen>
Set the text foreground pen.
PIPI
The constant π.
PLOTPLOT <x>, <y>[, <pen>]
Plot a graphics point.
PLOTRPLOTR <dx>, <dy>[, <pen>]
Plot relative to the graphics cursor.
POKEPOKE <addr>, <byte>
Write a byte of memory.
POSPOS(#<stream>)
Text cursor column.
PRINTPRINT [#<stream>,] [<expr>][;|,]…
Print to the screen or a stream.
RADRAD
Radians mode for trigonometry.
RANDOMIZERANDOMIZE [<number>]
Seed the random number generator.
READREAD <var>[, <var>]…
Read the next DATA item(s).
RELEASERELEASE <mask>
Release held sound channels.
REM'REM <comment>
Comment line.
REMAINREMAIN(<timer>)
Read and disable a delay timer.
RENUMRENUM [<line>][, <line>][, <number>]
Renumber the program.
RESTORERESTORE [<line>]
Reset the DATA pointer.
RESUMERESUME [<line> | NEXT]
Resume after an error.
RETURNRETURN
Return from a GOSUB.
RIGHT$RIGHT$(<string>, <length>)
Rightmost n characters.
RNDRND[(<number>)]
Random number 0..1.
ROUNDROUND(<number>[, <number>])
Round to a number of decimals.
RUNRUN [<line> | <filename>]
Run the program (or load and run).
SAVESAVE <filename>[, <letter>]
Save the program.
SGNSGN(<number>)
Sign of n (-1, 0, 1).
SINSIN(<number>)
Sine.
SOUNDSOUND <channel>, <period>[, <duration>[, <volume>[, <volenv>[, <toneenv>[, <noise>]]]]]
Make a sound.
SPACE$SPACE$(<number>)
A string of n spaces.
SPCSPC(<number>)
Print n spaces.
SPEEDSPEED WRITE <number>
SPEED WRITE / INK / KEY settings.
SPEED INKSPEED INK <number>, <number>
Set the flash rate of flashing colours.
SPEED KEYSPEED KEY <number>, <number>
Set the keyboard auto-repeat rates.
SPEED WRITESPEED WRITE <number>
Set the cassette write speed (0 or 1).
SQSQ(<channel>)
Sound-queue state of a channel.
SQRSQR(<number>)
Square root.
STEPFOR <numvar> = <number> TO <number> STEP <number>
Loop increment in FOR.
STOPSTOP
Stop with a break report.
STR$STR$(<number>)
Number as a string.
STRING$STRING$(<length>, <number> | <string>)
A character repeated n times.
SWAPWINDOW SWAP <stream>, <stream>
WINDOW SWAP - exchange two streams.
SYMBOLSYMBOL <number>, <byte>[, <byte>]…
Redefines the shape of one character, given its code and up to eight bytes — one per pixel row, most significant bit leftmost. Only characters at or above the SYMBOL AFTER threshold can be redefined.
SYMBOL AFTERSYMBOL AFTER <number>
Reserve memory for redefined characters.
TABTAB(<col>)
Position the cursor within PRINT.
TAGTAG [#<stream>]
Write text at the graphics cursor.
TAGOFFTAGOFF [#<stream>]
Return text to the text cursor.
TANTAN(<number>)
Tangent.
TESTTEST(<x>, <y>)
Ink at graphics point x,y.
TESTRTESTR(<dx>, <dy>)
Ink at a relative graphics point.
THENIF <number> THEN <statement>
Follows the condition in IF.
TIMETIME
Elapsed time (1/300s units).
TOFOR <numvar> = <number> TO <number>
Loop limit in FOR.
TROFFTROFF
Turn off line tracing.
TRONTRON
Trace line numbers as they execute.
UNTUNT(<addr>)
Address as a signed integer.
UPPER$UPPER$(<string>)
Upper-case copy of a string.
USINGPRINT USING <string>; <expr>
Format printed values.
VALVAL(<string>)
Numeric value of a string.
VPOSVPOS(#<stream>)
Text cursor row.
WAITWAIT <port>, <mask>[, <number>]
Wait for an I/O port state.
WENDWEND
End of a WHILE loop.
WHILEWHILE <number>
Loop while a condition holds.
WIDTHWIDTH <number>
Set the printer line width.
WINDOWWINDOW [#<stream>,] <left>, <right>, <top>, <bottom>
Define a text window.
WINDOW SWAPWINDOW SWAP <stream>, <stream>
Exchange two text streams.
WRITEWRITE [#<stream>,] <expr>[, <expr>]…
Write values to the screen or a file.
XOR<number> XOR <number>
Bitwise/logical exclusive OR.
XPOSXPOS
Graphics cursor x position.
YPOSYPOS
Graphics cursor y position.
ZONEZONE <number>
Set the print comma-column width.
Argument notation

Anything in <angle brackets> is a value you supply; everything else is typed exactly as shown. [square brackets] mark an optional part, | separates alternatives, and … means the part before it can repeat. The arguments on this page are:

<number>
a numeric expression
<string>
a string expression
<expr>
a value of either type, where the keyword takes both
<byte>
a value from 0 to 255
<constant>
a literal number or string, not an expression
<var>
a variable of either type
<numvar>
a numeric variable
<strvar>
a string variable
<letter>
a single letter
<line>
a line number
<statement>
one BASIC statement
<comment>
free text, to the end of the line
<name>
a name the program defines for a function or procedure
<param>
a parameter, where the definition introduces it
<arg>
a value, where the call passes it
<start>
the position something starts at, counting from 1
<length>
how many characters
<x>
a horizontal graphics coordinate
<y>
a vertical graphics coordinate
<dx>
a horizontal distance from the current position
<dy>
a vertical distance from the current position
<col>
a text column
<row>
a text row
<mode>
a screen mode
<colour>
a colour, by number
<channel>
a sound channel
<duration>
how long a sound lasts
<envelope>
an envelope, by number
<prompt>
text shown before the input; a literal, not an expression
<filename>
the name of a file on tape or disc
<addr>
a memory address
<port>
an input/output port, by number
<mask>
a bit mask, one bit per item
<pen>
a pen number in the current palette
<stream>
one of the eight screen windows, #0 to #7
<timer>
one of the four delay timers, 0 to 3
<key>
a key, by its key number
<period>
a tone period: 62500 divided by the frequency
<volume>
how loud a sound is
<volenv>
a volume envelope, by number, as defined by ENV
<toneenv>
a tone envelope, by number, as defined by ENT
<noise>
a noise period, 0 to 31
<section>
one envelope section: step count, step size and pause
<left>
the left edge of a window or clipping area
<right>
the right edge of a window or clipping area
<top>
the top edge of a window or clipping area
<bottom>
the bottom edge of a window or clipping area

Showing 192 of 192 keywords

Released under GNU GPL v3.0. Some ROM images are third-party copyrighted works, separate to this project, strictly for personal/educational purposes.