ARTICLES
18 / 43 |
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+.
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"
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.
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:
Offset | Size | Description |
---|---|---|
0 | 2 | Length of line data in bytes (note 1) |
2 | 2 | 16-bit decimal integer line number (note 2) |
4 | n | BASIC line encoded into tokens (note 3) |
n+1 | 1 | "0" the end of line marker (note 4) |
Notes:
This table list the BASIC tokens with no prefix byte.
Code (hexidecimal) | BASIC keyword |
---|---|
&00 | end of tokenised line marker |
&01 | ":" statement seperator |
&02 | integer variable definition (defined with "%" suffix) |
&03 | string variable definition (defined with "$" suffix) |
&04 | floating point variable definition (defined with "!" suffix) |
&05 | var? |
&06 | var? |
&07 | var? |
&08 | var? |
&09 | var? |
&0a | var? |
&0b | variable definition (no suffix) |
&0c | variable definition (no suffix) |
&0d | variable definition (no suffix) |
&0e | number constant "0" |
&0f | number constant "1" |
&10 | number constant "2" |
&11 | number constant "3" |
&12 | number constant "4" |
&13 | number constant "5" |
&14 | number constant "6" |
&15 | number constant "7" |
&16 | number constant "8" |
&17 | number constant "9" |
&18 | number constant "10" |
&19 | 8-bit integer decimal value |
&1a | 16-bit integer decimal value |
&1b | 16-bit integer binary value (with "&X" prefix) |
&1c | 16-bit integer hexadecimal value (with "&H" or "&" prefix) |
&1d | 16-bit BASIC program line memory address pointer |
&1e | 16-bit integer BASIC line number |
&1f | floating point value |
&20 | " " (space) symbol |
&21 | ASCII "!" symbol |
&22 | quoted string value |
&23-7b | ASCII printable symbols |
&7c | "|" symbol; prefix for RSX commands |
&80 | AFTER |
&81 | AUTO |
&82 | BORDER |
&83 | CALL |
&84 | CAT |
&85 | CHAIN |
&86 | CLEAR |
&87 | CLG |
&88 | CLOSEIN |
&89 | CLOSEOUT |
&8a | CLS |
&8b | CONT |
&8c | DATA |
&8d | DEF |
&8e | DEFINT |
&8f | DEFREAL |
&90 | DEFSTR |
&91 | DEG |
&92 | DELETE |
&93 | DIM |
&94 | DRAW |
&95 | DRAWR |
&96 | EDIT |
&97 | ELSE |
&98 | END |
&99 | ENT |
&9a | ENV |
&9b | ERASE |
&9c | ERROR |
&9d | EVERY |
&9e | FOR |
&9f | GOSUB, GO SUB |
&a0 | GOTO, GO TO |
&a1 | IF |
&a2 | INK |
&a3 | INPUT |
&a4 | KEY |
&a5 | LET |
&a6 | LINE |
&a7 | LIST |
&a8 | LOAD |
&a9 | LOCATE |
&aa | MEMORY |
&ab | MERGE |
&ac | MID$ |
&ad | MODE |
&ae | MOVE |
&af | MOVER |
&b0 | NEXT |
&b1 | NEW |
&b2 | ON |
&b3 | ON BREAK |
&b4 | ON ERROR GOTO, ON ERROR GO TO |
&b5 | SQ |
&b6 | OPENIN |
&b7 | OPENOUT |
&b8 | ORIGIN |
&b9 | OUT |
&ba | PAPER |
&bb | PEN |
&bc | PLOT |
&bd | PLOTR |
&be | POKE |
&bf | |
&c0 | "'" symbol (same function as REM keyword) |
&c1 | RAD |
&c2 | RANDOMIZE |
&c3 | READ |
&c4 | RELEASE |
&c5 | REM |
&c6 | RENUM |
&c7 | RESTORE |
&c8 | RESUME |
&c9 | RETURN |
&ca | RUN |
&cb | SAVE |
&cc | SOUND |
&cd | SPEED |
&ce | STOP |
&cf | SYMBOL |
&d0 | TAG |
&d1 | TAGOFF |
&d2 | TROFF |
&d3 | TRON |
&d4 | WAIT |
&d5 | WEND |
&d6 | WHILE |
&d7 | WIDTH |
&d8 | WINDOW |
&d9 | WRITE |
&da | ZONE |
&db | DI |
&dc | EI |
&dd | FILL (v1.1) |
&de | GRAPHICS (v1.1) |
&df | MASK (v1.1) |
&e0 | FRAME (v1.1) |
&e1 | CURSOR (v1.1) |
&e2 | (note 2) |
&e3 | ERL |
&e4 | FN |
&e5 | SPC |
&e6 | STEP |
&e7 | SWAP |
&e8 | (note 2) |
&e9 | (note 2) |
&ea | TAB |
&eb | THEN |
&ec | TO |
&ed | USING |
&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) |
&fa | AND |
&fb | MOD |
&fc | OR |
&fd | XOR |
&fe | NOT |
&ff | (prefix for additional keywords) |
Notes:
e.g. "|DIR".
An RSX is encoded in a BASIC program using the following structure:
Offset | Count | Description |
---|---|---|
0 | 1 | "|" character prefix |
1 | 1 | 8-bit byte offset to tokens following RSX name. |
2 | x | RSX name. (Last character of name has bit 7 set to "1", all other characters have bit 7 set to "0") |
Offset | Count | Description |
---|---|---|
0 | 1 | &1f (note 1) |
1 | 5 | Floating point number (note 2) |
Offset | Count | Description |
---|---|---|
0 | 1 | Token defining variable type |
2 | 2 | 16-bit Byte offset to variable value within tokenised BASIC program. |
4 | x | Variable 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.
This table list the BASIC tokens with a &ff prefix byte.
Code (hexidecimal) | BASIC keyword |
---|---|
&00 | ABS |
&01 | ASC |
&02 | ATN |
&03 | CHR$ |
&04 | CINT |
&05 | COS |
&06 | CREAL |
&07 | EXP |
&08 | FIX |
&09 | FRE |
&0a | INKEY |
&0b | INP |
&0c | INT |
&0d | JOY |
&0e | LEN |
&0f | LOG |
&10 | LOG10 |
&11 | LOWER$ |
&12 | PEEK |
&13 | REMAIN |
&14 | SGN |
&15 | SIN |
&16 | SPACE$ |
&17 | SQ |
&18 | SQR |
&19 | STR$ |
&1a | TAN |
&1b | UNT |
&1c | UPPER$ |
&1d | VAL |
(note 2) | |
&40 | EOF |
&41 | ERR |
&42 | HIMEM |
&43 | INKEY$ |
&44 | PI |
&45 | RND |
&46 | TIME |
&47 | XPOS |
&48 | YPOS |
&49 | DERR (v1.1) |
(note 3) | |
&71 | BIN$ |
&72 | DEC$ (v1.1) |
&73 | HEX$ |
&74 | INSTR |
&75 | LEFT$ |
&76 | MAX |
&77 | MIN |
&78 | POS |
&79 | RIGHT$ |
&7a | ROUND |
&7b | STRING$ |
&7c | TEST |
&7d | TESTR |
&7e | COPYCHR$ (v1.1) |
&7f | VPOS |
(note 4) |
NOTES:
&FF,&00
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 |
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.
A floating point (real) variable describes a number with integer and fractional parts.
e.g.
a! = 3.141592654
PRINT @a!
Where "a" should be replaced with the name of the variable.
A integer variable describes a whole number. i.e. a number without any fractional part.
NOTES:
e.g.
a% = 3
Offset | Length | Description |
---|---|---|
0 | 2 | Integer number |
PRINT @a%
where "a" should be replaced with the name of the variable.
A string is a variable which contains a group of characters.
NOTES:
e.g.
a$ = "hello"
Offset | Length | Description |
---|---|---|
0 | 1 | Length of string in bytes/characters |
1 | 2 | Location of start of string |
PRINT @a$
replacing "a$" with the name of the string variable.
Article créé le : | Samedi 23 Janvier 2010 à 17 h 26 |