CPC-POWER : CPC-SOFTS - CPCArchives 
Options de Recherche :
 
 
 

ARTICLES

18 / 43

Technical information about Locomotive BASIC

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

a$="A":|DRIVE,@a$

BASIC v1.1:

|DRIVE,"A"
 

Additional keywords and variables in BASIC v1.1

  • BASIC v1.1 has the following additional keywords:
    • COPYCHR$
    • CURSOR
    • DEC$
    • FILL
    • FRAME
    • GRAPHICS
    • MASK
  • BASIC v1.1 has the following additional predefined variables:
    • DERR

    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:

    OffsetSizeDescription
    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)

    Notes:

    • This 16-bit value has two functions:
      • if "0" it signals the end of the BASIC program. In this case, there is no furthur BASIC program lines or data.
      • otherwise, this value defines the length of the tokenised BASIC program line in bytes, and includes the 2 bytes defining this value, the 2 bytes defining the program line number, and the end of line marker. This number is stored in little endian notation with low byte followed by high byte.
    • This 16-bit value defines the line number and exists if the length of line data in bytes is not "0". A line number is a integer number in the range 1-65535. This number is stored in little endian notation with low byte followed by high byte.
    • This data defines the tokenised BASIC program line and exists if the length of line data in bytes is not "0". The length is dependant on the BASIC program line contents.
    • This value defines the end of the tokenised BASIC line data and exists if the length of line data in bytes is not "0". The BASIC interpreter looks for this token during the processing of this line, and if found, will stop execution and continue to the next line.

    BASIC tokens

    This table list the BASIC tokens with no prefix byte.

    Code
    (hexidecimal)
    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)
    &05var?
    &06var?
    &07var?
    &08var?
    &09var?
    &0avar?
    &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
    &80AFTER
    &81AUTO
    &82BORDER
    &83CALL
    &84CAT
    &85CHAIN
    &86CLEAR
    &87CLG
    &88CLOSEIN
    &89CLOSEOUT
    &8aCLS
    &8bCONT
    &8cDATA
    &8dDEF
    &8eDEFINT
    &8fDEFREAL
    &90DEFSTR
    &91DEG
    &92DELETE
    &93DIM
    &94DRAW
    &95DRAWR
    &96EDIT
    &97ELSE
    &98END
    &99ENT
    &9aENV
    &9bERASE
    &9cERROR
    &9dEVERY
    &9eFOR
    &9fGOSUB, GO SUB
    &a0GOTO, GO TO
    &a1IF
    &a2INK
    &a3INPUT
    &a4KEY
    &a5LET
    &a6LINE
    &a7LIST
    &a8LOAD
    &a9LOCATE
    &aaMEMORY
    &abMERGE
    &acMID$
    &adMODE
    &aeMOVE
    &afMOVER
    &b0NEXT
    &b1NEW
    &b2ON
    &b3ON BREAK
    &b4ON ERROR GOTO, ON ERROR GO TO
    &b5SQ
    &b6OPENIN
    &b7OPENOUT
    &b8ORIGIN
    &b9OUT
    &baPAPER
    &bbPEN
    &bcPLOT
    &bdPLOTR
    &bePOKE
    &bfPRINT
    &c0"'" symbol (same function as REM keyword)
    &c1RAD
    &c2RANDOMIZE
    &c3READ
    &c4RELEASE
    &c5REM
    &c6RENUM
    &c7RESTORE
    &c8RESUME
    &c9RETURN
    &caRUN
    &cbSAVE
    &ccSOUND
    &cdSPEED
    &ceSTOP
    &cfSYMBOL
    &d0TAG
    &d1TAGOFF
    &d2TROFF
    &d3TRON
    &d4WAIT
    &d5WEND
    &d6WHILE
    &d7WIDTH
    &d8WINDOW
    &d9WRITE
    &daZONE
    &dbDI
    &dcEI
    &ddFILL (v1.1)
    &deGRAPHICS (v1.1)
    &dfMASK (v1.1)
    &e0FRAME (v1.1)
    &e1CURSOR (v1.1)
    &e2(note 2)
    &e3ERL
    &e4FN
    &e5SPC
    &e6STEP
    &e7SWAP
    &e8(note 2)
    &e9(note 2)
    &eaTAB
    &ebTHEN
    &ecTO
    &edUSING
    &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)
    &faAND
    &fbMOD
    &fcOR
    &fdXOR
    &feNOT
    &ff(prefix for additional keywords)

    Notes:

    • The &ff code is used as a prefix for more keywords. See the table below for the list of keywords using this prefix.
    • &e2,&e8 and &e9 are not used
    • &7c ("|") is a character prefix used to identify a RSX command.

      e.g. "|DIR".

      An RSX is encoded in a BASIC program using the following structure:

      OffsetCountDescription
      01"|" character prefix
      118-bit byte offset to tokens following RSX name.
      2xRSX name. (Last character of name has bit 7 set to "1", all other characters have bit 7 set to "0")

    • This token identifies a integer (16-bit) number. The two bytes following this token is the number, stored low byte then high byte. e.g. &19,&2d,&00 represents the integer number "&002d"="45".
    • This token (&0B) is changed at run-time to &0D
    • This token identifies a integer variable. 02,00,00,var name offset to number in program setup when program RUN. The variable name is stored directly, with bit 7 of the last character set.
    • This token identifies a string variable. offset to string in program string stored AS IS with quotes around it.
    • This token identifies a floating point number. Immediatly following the token are 5 bytes which define the number.

      OffsetCountDescription
      01&1f (note 1)
      15Floating point number (note 2)

      1. This byte is the BASIC token identifying a floating point number
      2. These 5 bytes define the floating point number.
    • The space symbol is used as a command seperator
    • Variable definitions:
      • The variable definition has the following structure:
        OffsetCountDescription
        01Token defining variable type
        2216-bit Byte offset to variable value within tokenised BASIC program.
        4xVariable name

        The 16-bit byte offset is initially set to 0, but is setup when the program is RUN. The offset is stored in little-endian format, with low byte followed by high byte.

      • The token byte defines the variable type (i.e. string, floating point, integer) and the suffix ("$", none and "%").
      • The variable name is stored in the program, with bit 7 of the last character set to "1". e.g. The variable named "abc" will be encoded as 'a','b','c'+&80
    • String values:
      • Each string value is prefixed with &22 token.
      • All strings must be enclosed by double quote symbols ("). This symbols define the start and end of the string value.
      • The string value can contain any symbol except the quote ("). i.e. 0-&21, and &23-&ff can be used.
    • After running a program, Tokens of "1d" with 16-bit BASIC program line pointers are changed to token "1e" with the 16-bit memory address of the BASIC line number in memory.

     

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

    Code
    (hexidecimal)
    BASIC keyword
    &00ABS
    &01ASC
    &02ATN
    &03CHR$
    &04CINT
    &05COS
    &06CREAL
    &07EXP
    &08FIX
    &09FRE
    &0aINKEY
    &0bINP
    &0cINT
    &0dJOY
    &0eLEN
    &0fLOG
    &10LOG10
    &11LOWER$
    &12PEEK
    &13REMAIN
    &14SGN
    &15SIN
    &16SPACE$
    &17SQ
    &18SQR
    &19STR$
    &1aTAN
    &1bUNT
    &1cUPPER$
    &1dVAL
     (note 2)
    &40EOF
    &41ERR
    &42HIMEM
    &43INKEY$
    &44PI
    &45RND
    &46TIME
    &47XPOS
    &48YPOS
    &49DERR (v1.1)
     (note 3)
    &71BIN$
    &72DEC$ (v1.1)
    &73HEX$
    &74INSTR
    &75LEFT$
    &76MAX
    &77MIN
    &78POS
    &79RIGHT$
    &7aROUND
    &7bSTRING$
    &7cTEST
    &7dTESTR
    &7eCOPYCHR$ (v1.1)
    &7fVPOS
     (note 4)

    NOTES:

    • These codes are prefixed by &FF. e.g. The keyword "ABS" is stored as the following sequence:
      &FF,&00
    • Codes &1e...&3f inclusive are not used
    • Codes &4a...&6f inclusive are not used
    • Codes &80...&ff inclusive are not used

    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

    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

    Sign

    The sign is represented by bit 7 of byte 3.

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

    • If the sign bit is "1", then the number is negative.
    • If the sign bit is "0", then the number is positive.

    Mantissa

    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.

    Exponent

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

    It is stored with a bias of 128.

    • 128-255 are positive exponents,
    • 0-127 are negative exponents.

    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.

    • A integer variable is defined with a "!" character postfix.

      e.g.

      a! = 3.141592654 
    • A real number uses 5 bytes of memory as storage. The format is described above.
    • The address of a real variable can be found in BASIC by:
      PRINT @a! 

    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.

    NOTES:

    • A integer variable is defined with a "%" character postfix.

      e.g.

      a% = 3 
    • A integer variable has a range of -32768 to 32767
    • A integer variable always uses two bytes of memory as storage with the following format:

      Offset Length Description
      02Integer number

    • The address of the integer variable can be found in BASIC by:
      PRINT @a% 

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


    BASIC string variables

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

    NOTES:

    • A string variable is defined in BASIC with a "$" character postfix.

      e.g.

      a$ = "hello" 
    • A string variable is described internally by a "string descriptor block" which has the following structure:

      Offset Length Description
      01Length of string in bytes/characters
      12Location of start of string

    • The address of the "string descriptor block" for the string variable can be found in BASIC by typing:
      PRINT @a$ 

      replacing "a$" with the name of the string variable.

    • A string uses a minimum of 3 bytes of storage (a 0 character length string) and a maximum of 258 bytes of storage. 3 bytes are used by the "string descriptor block")
    • A string variable can contain any ASCII character code in the range 0-255.
    • A string variable can store a minimum of 0 characters and a maximum of 255 characters.
    • The length of the string in characters is defined in the string descriptor block. The string does not have a termination character.
  •  

    Article créé le : Samedi 23 Janvier 2010 à 17 h 26
     
     

    CPC-POWER/CPCArchives, projet maintenu par Fredouille.
    Programmation par Kukulcan © 2007-2024 tous droits réservés.
    Reproduction sans autorisation interdite. Tous les titres utilisées appartiennent à leurs propriétaires respectifs.