Technical information about Locomotive BASIC

The are two versions of Locomotive BASIC used in the Amstrad CPC and CPC+ computers. v1.0 is used by the CPC464, and v1.1 is used by the CPC664, CPC6128, CPC464+ and CPC6128+.

Passing parameters to a RSX (Resident System Extension) command or binary function

A RSX (Resident System Extension) command is accessed through BASIC with a "|" character prefix. e.g. The "DIR" RSX, is accessed by "|DIR".

A binary function is accessed through BASIC using the "CALL" command.

Passing a string parameter:

BASIC v1.0


BASIC v1.1:


Additional keywords and variables in BASIC v1.1

  • BASIC v1.1 has the following additional keywords:
  • BASIC v1.1 has the following additional predefined variables:

    Entering BASIC programs

    A maximum of 255 characters can be entered for a single BASIC line.

    This is converted into the tokenised BASIC program which is more compact than the line entered. The BASIC keywords are converted into "tokens", or 1-2 byte sequences which uniquely identify each keyword.

    Structure of a BASIC program

    A BASIC program is stored in a tokenised format. Here the keywords are represented by 1 or 2 byte unique sequences.

    Each line of the BASIC program has the form:

    02Length of line data in bytes (note 1)
    2216-bit decimal integer line number (note 2)
    4nBASIC line encoded into tokens (note 3)
    n+11"0" the end of line marker (note 4)


    BASIC tokens

    This table list the BASIC tokens with no prefix byte.

    BASIC keyword
    &00end of tokenised line marker
    &01":" statement seperator
    &02integer variable definition (defined with "%" suffix)
    &03string variable definition (defined with "$" suffix)
    &04floating point variable definition (defined with "!" suffix)
    &0bvariable definition (no suffix)
    &0cvariable definition (no suffix)
    &0dvariable definition (no suffix)
    &0enumber constant "0"
    &0fnumber constant "1"
    &10number constant "2"
    &11number constant "3"
    &12number constant "4"
    &13number constant "5"
    &14number constant "6"
    &15number constant "7"
    &16number constant "8"
    &17number constant "9"
    &18number constant "10"
    &198-bit integer decimal value
    &1a16-bit integer decimal value
    &1b16-bit integer binary value (with "&X" prefix)
    &1c16-bit integer hexadecimal value (with "&H" or "&" prefix)
    &1d16-bit BASIC program line memory address pointer
    &1e16-bit integer BASIC line number
    &1ffloating point value
    &20" " (space) symbol
    &21ASCII "!" symbol
    &22quoted string value
    &23-7bASCII printable symbols
    &7c"|" symbol; prefix for RSX commands
    &9fGOSUB, GO SUB
    &a0GOTO, GO TO
    &b3ON BREAK
    &c0"'" symbol (same function as REM keyword)
    &ddFILL (v1.1)
    &deGRAPHICS (v1.1)
    &dfMASK (v1.1)
    &e0FRAME (v1.1)
    &e1CURSOR (v1.1)
    &e2(note 2)
    &e8(note 2)
    &e9(note 2)
    &ee> (greater than)
    &ef= (equal)
    &f0>=, > =, => (greater or equal)
    &f1< (less than)
    &f2<>, < > (not equal)
    &f3=<, <=, < = (less than or equal)
    &f4+ (addition)
    &f5- (subtraction or unary minus)
    &f6* (multiplication)
    &f7/ (division)
    &f8^ (x to the power of y)
    &f9\ (integer division)
    &ff(prefix for additional keywords)


    This table list the BASIC tokens with a &ff prefix byte.

    BASIC keyword
     (note 2)
    &49DERR (v1.1)
     (note 3)
    &72DEC$ (v1.1)
    &7eCOPYCHR$ (v1.1)
     (note 4)


    Floating Point data definition

    A floating point number represents a number with both an integer and fractional part.

    In Amstrad BASIC, a floating point number is stored in base-2 in a normalized form:

    1 x 2<exponent>

    The representation uses 5 bytes and is stored using the following structure:

    Byte 0 1 2 3 4
    Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
    Function mantissa (bits 23-16) mantissa (bits 15-8) mantissa (bits 7-0) sign mantissa (bits 30-24) exponent


    The sign is represented by bit 7 of byte 3.

    The value of the sign bit indicates the sign of the floating point number.


    The mantissa holds the normalized number. The exponent is manipulated so that the most significant bit is always 1. Since it is always 1, it is not stored. It's value is implied by the representation.


    The exponent is 8-bit and is stored in byte 4.

    It is stored with a bias of 128.

    To obtain the signed exponent, you must subtract 128 from the stored exponent.

    The minimum exponent is 0 and this describes a number of 2^-127.

    The maximum exponent is 255 and this describes a number of 2^128.

    BASIC floating-point/real variables

    A floating point (real) variable describes a number with integer and fractional parts.

    Where "a" should be replaced with the name of the variable.

    BASIC integer variables

    A integer variable describes a whole number. i.e. a number without any fractional part.


    BASIC string variables

    A string is a variable which contains a group of characters.