Changes

Jump to: navigation, search

Locomotive BASIC

3,481 bytes added, 01:08, 27 January 2008
Started converting styles to match that of official Amstrad manuals. Use <code> instead of <pre> or <tt>.
=== Commands and operators ===
==== <code>AFTER I</code>‹time delay›[<code>,t</code>‹timer number›] <code> GOSUB Ln </code>‹line number› ====: Waits for i‹time delay›/50 seconds and then jumps to the subroutine at line Ln‹line number›. There are 4 delay timers from 0 to 3 which can be specified with ‹timer number›. If ommited ‹timer number› defaults to 0.
==== <code>AUTO </code>[Ln‹line number›][<code>,i</code>‹increment›] ====
: Automaticaly generates line numbers starting at line Ln with increment i between line numbers.
: Use [ESC to leave AUTO mode. Default value for Ln and i is 10.
</pre>
==== <code>BORDER color </code> ====
: Changes the color of the border.
==== <code>CALL add[,list of parameters] </code> ====
: Allows an externally developed subroutine to be called by BASIC
: Example:
</pre>
==== <code>CAT </code> ====
: Displays the names of all existing programes on the tape or disc.
: Examples:
<prett>CAT [ENTER] - lists all disc files in alpha-numeric (ASCII) order<br>|TAPE [ENTER]<br>CAT [ENTER] - lists names of all tape files in their storage order<br></prett>
==== <code>CHAIN "filename"[,ln]</code> ====
:Enables the specified program to be loaded and RUN automatically. If the optional parameters ln is specified, the program execution will commence from line ln.
==== <code>CHAIN MERGE "filename"[,ln][,DELETE1 nl - 1n2]</code> ====
:Loads the specified program from tape or disc, merges it into the program in memory, and starts execution of the merged program. The parameter DELETE1n1 - 1n2 is used to delete part of the original program before running it, if required.
==== <code>CLEAR </code> ====
: Clears all variables from memory, leaving the program in memory unchanged. All open files are abandoned.
==== <code>CLG [ink] </code> ====
: Clears the graphics screen to colour specified by ink. If parameter ink is not specified them the graphics screen is cleared to the colour specified by the GRAPHICS PAPER statement.
==== <code>CLOSEIN </code> ====
: Closes any input file (tape or disc).
==== <code>CLOSEOUT </code> ====
: Closes any output file (tape or disc).
==== <code>CLS </code> ====
: Clears the screen. The text cursor is moved to the upper left corner.
==== <code>CONT </code> ====
: CONTinues program execution interrupted either by [ESC] [ESC] or as a result of STOP within a program.
==== <code>CURSOR </code> ====
: [...]
==== <code>DATA x1[,x2,x3...]</code> ====
: Defines a data ''section'' to be used by <tt>READ</tt> calls.
: Data values can be of any type (integer, real or string) as long as the corresponding <tt>READ</tt> calls use a variable of the right type.
:''See also:'' <tt>READ</tt>, <tt>RESTORE</tt>
==== <code>DEF </code> ====
: [...]
==== <code>DEFINT letter range</code> ====
: Forces all variables(s) starting with the specified letter(s) to be string variables. The s does not need to be added to DEFSTR variable names.
</pre>
==== <code>DEFREAL </code> ====
: [...]
==== <code>DEFSTR </code> ====
: Sets the default for variable(s) with the specified first letter(s) to integer. The letter range could be an inclusive range A-Z
</pre>
==== <code>DEG </code> ====
: Switch to degrees mode for trigonometric functions (<tt>SIN</tt>, <tt>COS</tt>...).
''See also:'' <tt>RAD</tt>
==== <code>DELETE [first line][-[last line]] </code> ====
: Deletes the current program completely (without arguments) or only the given line or line range. Even
: <code>DELETE -</code>
: The lines specified do not have to exist, all lines matching the range will be deleted and having no matches does not cause an error.
==== <code>DI </code> ====
: Disables interrupts (but not[ESC]) until re-enabled by EI command or by RETURN at end of an interrupts service routine.
==== <code>DIM a[%|!|$](d1[,d2[,...]]) </code> ====
: Creates array <code>a</code> with single or multiple dimensions. You may optionally specify integer (<code>%</code>), real (<code>!</code>) or string (<code>$</code>) type otherwise it defaults to the current type set for the first letter of the array name. <code>d1</code> is size of first dimension-1, <code>d2</code> is size of second dimension-1 and so on. <code>DIM x(10)</code> will create an array with 11 elements, <code>x(0)</code> is the first element, <code>x(10)</code> is the eleventh and last. You can specify as many dimensions as will fit on one 255 character line, which is a maximum of 125. Trying to create an array that already exists will generate an <code>Array already dimensioned</code> error. If an array is not specified by <code>DIM</code> before being accessed, each dimension value defaults to 10. The maximum dimensions that can be created this way is three.
==== <code>DRAW x,y[,i1 | ,[i1],i2] </code> ====
: Draws a line from the current cursor position to position x,y. i1 specifies colour, i2 is the drawing style.
</code>
==== <code>DRAWR xr, yr, [[i1][,i2]] </code> ====
: Draws a line from current graphics cursor position to current cursor x position + xr, current cursor y position + yr. i1 and i2 as DRAW.
</pre>
==== <code>EDIT line </code> ====
: Copies one program line to screen in edition mode.
==== <code>EI </code> ====
: Enable interrupts which have been disabled by DI
==== <code>END </code> ====
: Indicates end of program
==== <code>ENT </code> ====
: [...]
==== <code>ENV </code> ====
: [...]
==== <code>ERASE v1[% | ! | $][,v2[% | ! | $][,...]] </code> ====
: Erases the specified array(s) and frees the memory used. Must specify existing array(s) or an <code>Improper argument</code> error will be generated.
==== <code>ERL </code> ====
: Returns the line number of the last error encountered.
==== <code>ERROR i </code> ====
: Returns the error message whose error code number is i.
==== <code>EVERY i[,t] GOSUB ln </code> ====
: BASIC branches to the subroutine at line ln every i/50 seconds.
==== <code>FILL i </code> ====
: Fills an area of a graphics screen i colour i (0-15). Default value of i is the current graphics pen colour. Only available in Basic 1.1.
==== <code>FN </code> ====
: [...]
==== <code>FOR TO STEP NEXT </code> ====
: [...]
==== <code>FRAME </code> ====
: Smooths character and graphics movement and reduces flicker (waits for a VSYNC signal). Only available in Basic 1.1. On a CPC 464 you can use CALL &BD19 instead.
==== <code>GOSUB i </code> ====
: Jumps to subroutine which is given as argument.
</pre>
==== <code>GOTO i </code> ====
: Jumps to the line number which is given as argument.
: ''Example:''
</pre>
==== <code>GRAPHICS </code> ====
: [...]
==== <code>IF THEN ELSE </code> ====
: [...]
==== <code>INK </code> ====
: [...]
==== <code>INPUT </code> ====
: [...]
==== <code>KEY </code> ====
: [...]
==== <code>LET </code> ====
: Used to define variables. You don't need to use the ''LET'' command because it is just a command which was added for compatibility reasons.
: ''Example:''
</pre>
==== <code>LINE INPUT </code>‹variable›[<code>,</code>‹variable›] ====
: [...]
==== <code>LIST </code>[‹line number›][<code>-</code>[‹line number›]] ====
: [...]
==== <code>LOAD ‹file name›[<code>,</code>‹address›] ====
: [...]
==== <code>LOCATE x,y </code> ====
: Moves the text cursor to the x,y location.
: y starts at 1 at the top and ends at 25 at the bottom.
==== <code>MASK [i1][,i2]</code> ====
: Sets bits in each adjacent group of 8 pixel on (1) or off (0) according to binary value of i1 (0-255). i2 determines whether the first point of the line is to plotted (1) or not (0).
</pre>
==== <code>MEMORY add</code> ====
: Allocates the amount of memory to be used by BASIC by setting the address of the highest byte it may use.
==== <code>MERGE </code> ====
: [...]
==== <code>MID$ </code> ====
: [...]
==== <code>MODE </code> ====
: Changes the screen mode: MODE 0 is 160x200 in 16 colors, MODE 1 is 320x200 4 colors and MODE 2 is 640x200 2 colors.
==== <code>MOVE x,y [[,i1][,i2]]</code> ====
: Moves the graphic cursor to position x,y. The parameter i1 may be used to change the pen (drawing) colour. The parameter i2 specifies the logical colour, as in DRAW.
==== <code>MOVER </code> ====
: [...]
==== <code>NEW </code> ====
: [...]
==== <code>ON BREAK CONT </code> ====
: Prevents the interruption of program execution by the ESC key.
==== <code>ON BREAK GOSUB ln </code> ====
: Passes control to subroutine at line ln when ESC ESC pressed.
==== <code>ON BREAK STOP </code> ====
: Restores normal function of ESC key during program execution.
==== <code>ON ERROR GOTO ln </code> ====
: Passes the control to line ln if an error is detected in the program.
: ON ERROR GOTO 0, Turns of the error trap, and restores normal error processing.
==== <code>OPENIN "datafile" </code> ====
: Opens the specified data file for reading.
==== <code>OPENOUT "datafile" </code> ====
: Opens the specified data file for writing.
==== <code>ORIGIN </code> ====
: [...]
==== <code>OUT add,i </code> ====
: Outputs the value of i (0-255) to the I/O address add.
==== <code>PAPER </code> ====
: [...]
==== <code>PEN </code> ====
: [...]
==== <code>PLOT </code> ====
: [...]
==== <code>PLOTR </code> ====
: [...]
==== <code>POKE add </code> ====
: Alters contents of memory location add to value i (0-255)
==== <code>PRINT </code> ====
: [...]
==== <code>RAD </code> ====
: Switch to radians mode for trigonometric functions (<tt>SIN</tt>, <tt>COS</tt>...).
: ''See also:'' <tt>DEG</tt>
==== <code>RANDOMIZE [seed] </code> ====
: Resets the pseudo-random generator to the given seed. What is strange is that if no seed is given, one is interactively prompted for.
</pre>
==== <code>READ variable </code> ====
: Gets the next data item (from <tt>DATA</tt> commands), stores it in the given variable and moves to the next item.
The variable must be of the correct type.
''See also:'' <tt>DATA</tt>, <tt>RESTORE</tt>
==== <code>RELEASE </code> ====
: [...]
==== <code>REM [any text]</code> ====
: Introduces a comment.
==== <code>RENUM </code>[newLine‹newLine›][<code>,oldLine </code>‹oldLine› | <code>,</code>[oldLine‹oldLine›]<code>,step</code>‹step›] ====
: Renumbers the lines of the current program.
</pre>
==== <code>RESTORE [line] </code> ====
: Resets the data pointer used by <tt>READ</tt>. When used without parameters, resets the pointer to the first data in the program. Otherwise, resets the pointer to the given line number.
: ''See also:'' <tt>DATA</tt>, <tt>READ</tt>
==== <code>RESUME </code> ====
: [...]
==== <code>RETURN </code> ====
: Terminates a subroutine and returns control to the line following the GOSUB call (see GOSUB)
==== <code>RUN [line] </code> ====
: Runs the current program, optionally starting at a given line. If no line number is given, starts at the first line.
==== <code>SAVE </code> ====
: [...]
==== <code>SOUND </code> ====
: [...]
==== <code>SPC </code> ====
: [...]
==== <code>SPEED </code> ====
: [...]
==== <code>SQ (channel) </code> ====
: Returns a bit significant integer showing state of the sound queue for specified channel where channel 1,2,3, = A, B, C
:Bit 7 Channel is currently active
==== <code>STOP </code> ====
: Breaks program execution at line containing the STOP statement. The message '''BREAK in''' is output with the line number.
==== <code>SUB </code> ====
: [...]
==== <code>SWAP </code> ====
: [...]
==== <code>SYMBOL n,i1[,i2,i3,i4,i5,i6,i7,i8] </code> ====
: Redefines the appearance of the character at index n.
: See also <tt>SYMBOL AFTER</tt> to allow redefinition of arbitrary characters.
==== <code>SYMBOL AFTER n </code> ====
: Allows the redefinition of character symbols from index n included.
: Initially, only symbols from index 240 to 255 can be redefined. This initial situation can be restored with <tt>SYMBOL AFTER 240</tt>. Symbol previously redefined are restored to their original appearance.
==== <code>TAB </code> ====
: [...]
==== <code>TAG [#st] </code> ====
: Allows text to print at graphics cursor position.
: see TAGOFF
==== <code>TAGOFF [#st] </code> ====
: Directs text to stream st printing it at previous text cursor position.
==== <code>TROFF </code> ====
: Turns off the program flow trace (see TRON)
==== <code>TRON </code> ====
: Turns on the program flow trace for debugging. Causes the line number of each statement executed to be displayed.
==== <code>USING </code> ====
: [...]
==== <code>WAIT add, i1[,i2] </code> ====
: Waits until the I/O port at add returns a value (0-255). The value returned is XORed with i2 and the ANDed with i1. This is repeated until a non-zero result occurs.
==== <code>WHILE WEND </code> ====
: [...]
==== <code>WIDTH </code> ====
: [...]
==== <code>WINDOW </code> ====
: [...]
==== <code>WRITE [#st,] v[$], v[$] </code> ====
: Writes the values of the specified variable to the specified stream.
</pre>
==== <code>ZONE i</code> ====
: Changes the width of the print zone. Default is 13.
=== Operators ===
==== <code>AND </code> ====
: [...]
==== <code>MOD </code> ====
: [...]
==== <code>NOT </code> ====
: [...]
==== <code>OR </code> ====
: [...]
==== <code>XOR </code> ====
: [...]
=== Functions ===
==== <code>ABS (n) </code> ====
: Returns the absolute value of n by ignoring the sign value.
</pre>
==== <code>ASC (s) </code> ====
: Returns ASCII code number of first character of string s
==== <code>ATN (n) </code> ====
: Returns the arctangent of n.
==== <code>BIN$ (i1,[i2]) </code> ====
: Returns binary representation of i1 between -32768 and 65535. The number of binary digits (0s and 1s) is specified by i2 (0-16)
: Example:
</pre>
==== <code>CHR$ (n)</code> ====
: Returns the character for a given index n. For instance CHR$(65) returns the character 'A'. Valid indices range from 0 (zero) to 255.
: It will draw a random maze with characters 208 and 209, which are an horizontal and a vertical bar.
==== <code>CINT (n) </code> ====
: Returns rounded up integer value of n between -32768 and 32767.
</pre>
==== <code>COPYCHR$ (st) </code> ====
: Copies character from current position in specified stream.
==== <code>COS (n) </code> ====
: Returns cosine of n in degrees or radians (se DEG and RAD)
==== <code>CREAL (n) </code> ====
: Converts integer n to real numeric variable.
==== <code>DEC$(n, format) </code> ====
: Retruns the decimal string representation of n, according to the specified format (see PRINT USING)
==== <code>DERR </code> ====
: Gives the most recent error code number returned by [[Amsdos]].
==== <code>EOF </code> ====
: Checks to see if end of specified file has been reached during input. Returns 0 (false) until the end of file, then -1 (true)
==== <code>ERR </code> ====
: Returns the error code number of the last error encountered.
==== <code>EXP (i) </code> ====
: Returns the result of calculating e to the power i.
</pre>
==== <code>FIX (n) </code> ====
: Removes the fractional part of n (see INT)
==== <code>FRE (n/se) </code> ====
: Returns the amount of unused memory, irrespective of the nature or value of the dummy argument inside the bracket.
</pre>
==== <code>HEX$ (i1, i2) </code> ====
: Returns a string hexadecimal digit representation of i1 (0-65535). The number of hex digits in the string is given by i2 (0-15)
==== <code>HIMEM </code> ====
: Returns address of the highest memory address used by BASIC.
==== <code>INKEY (i) </code> ====
: Checks to see if key number i is being pressed.
</pre>
==== <code>INKEY$ </code> ====
: Checkts the keyboard and returns the string character of the key pressed. The string character returned is normally assigned to a string variable. If no key pressed, a null string is returned.
==== <code>INP (add) </code> ====
: Returns value read from the I/O address add
==== <code>INSTR </code> ====
: [...]
==== <code>INT (n) </code> ====
: As in FIX if n is positive; if n is negative, it rounds it down.
</pre>
==== <code>JOY (i) </code> ====
: Returns bit-significant value from specified joystick. i = 0 or 1.
</pre>
==== <code>LEFT$ (se, i) </code> ====
: Returns a substring of se. The substring begins at the left-most character of se and contains i characters.
</pre>
==== <code>LEN (se) </code> ====
: Returns the number of characters in se (0 - 255)
==== <code>LOG (n) </code> ====
: Returns the natural logarithm (to base e) of n.
==== <code>LOG10 (n) </code> ====
: Returns the logarithm to base 10 of n.
==== <code>LOWER$ (se) </code> ====
: Returns a copy of se in which all alphabetical characters are converted to lower case (see also UPPER)
</pre>
==== <code>MAX (list of n) </code> ====
: Returns the maximum value from the given list.
</pre>
==== <code>MIN (list of n) </code> ====
: Returns the minimum value from the given list (see MAX)
==== <code>PEEK (add) </code> ====
: Returns the contents of the specified memory location (0-65535)
==== <code>PI </code> ====
: Returns value of PI (3.14159265)
==== <code>POS (#st) </code> ====
: Returns column number of print position relative to left edge of text window on stream st. st must be specified.
</pre>
==== <code>REMAIN (i) </code> ====
: Returns count remaining in delay timer i (0-3) then disables it.
==== <code>RIGHT$ (se,i) </code> ====
: Returns a substring of length i (0-255) characters from se, ending at the rightmost character of se.
</pre>
==== <code>RND [(n)] </code> ====
: Generates the next random number in the current squence if n is positive or omitted. If n = 0, the random number generated will be the same as the last random number generated.
==== <code>ROUND (n[,i1]) </code> ====
: Rounds n to a number of decimal places or to the power of ten specified by i. If i is negative, the n is rounded to give an absolute integer with i zeros before the decimal point.
</pre>
==== <code>SGN (n) </code> ====
: Returns 1 if n is positive, 0 if n = 0, -1 if n is negative.
==== <code>SIN (n) </code> ====
: Returns sine of n in degree or radian mode (see DEG and RAD)
==== <code>SPACE$(i) </code> ====
: Creates a string containing i spaces (0-255)
==== <code>SQ (channel) </code> ====
: Returns a bit significant integer showing state of the sound queue for specified channel where channel 1, 2, 3 = A, B, C.
<pre>
</pre>
==== <code>SQR (n) </code> ====
: Returns the square root of n.
==== <code>STR$(n) </code> ====
: Returns the string representation of number n.
==== <code>STRING$ </code> ====
: Returns i copies of the string character specified by s.
</pre>
==== <code>TAN (n) </code> ====
: Returns the tangent of n. The DEG and RAD commands can be used to force the result to either mode.
==== <code>TEST (x,y) </code> ====
: Moves the graphics cursor by x and y and returns the value of the ink at that position.
==== <code>TESTR (x,y) </code> ====
: Moves the graphics cursor by x and y relative to its current position and returns the value of ink at that position.
==== <code>TIME </code> ====
: Returns time elapsed since the computer was switched on or reset.
: One second = TIME/300.
==== <code>UNT (add) </code> ====
: Returns an integer(-32768 to 32767) which is the two's complement of add.
</pre>
==== <code>UPPER$(se) </code> ====
: Gives copy of se with all alphabetic characters in upper case.
==== <code>VAL(se) </code> ====
: Returns the numeric value (including signs) of first numeric character(s) in se. Returns 0 if se starts with a non-number.
</pre>
==== <code>VPOS (#st) </code> ====
: Reports the current row (line) position of the text cursor relative to the top of the text windows of the specified stream.
==== <code>XPOS </code> ====
: Returns the current horizontal (x) position of the graphics cursor.
==== <code>YPOS </code> ====
: Returns the current vertical (y) position of the graphics cursor.
== Error codes ==
* 1 '''Unexpected NEXT''' - Occurs when the <code>NEXT</code> encountered without matching <code>FOR of a FOR .. NEXT loop is missing</code>.
* 2 '''Syntax Error''' - Typing error or incorrect punctuation.
* 3 '''Unexpected RETURN''' - Caused by entering a subroutine other than with <code>RETURN</code> encountered when there was no active <code>GOSUB</code>.* 4 '''DATA exhaused''' - Trying to <code>READ </code> data when data pointer has reached end of data.* 5 '''Improper argument''' - The argument for a function is not legal (ege. g. <code>PRINT SQR(--10)</code>).* 6 '''Overflow''' - The computer cannot handle a number integers smaller than -32768 (signed) or larger than 65535 (unsigned) or floating point numbers greater than &plusmn;1.7E38.* 7 '''Memory full''' - All Not enough free RAM available RAM is being used or has been reservedto complete the operation. Program to too big or control structures too deeply nested.* 8 '''Line does not exist''' - Attempt to <code>RUN</code>, <code>GOTO </code> or <code>GOSUB </code> a non-existent line number.* 9 '''Subsript Subscript out of range''' - Value of a subscript in an array is greater than outside of range specified by <code>DIM </code> declarationor wrong number of dimensions supplied.* 10 '''Array already dimensioned''' - Arrays can only be DIMensioned <code>DIM</code>ensioned once within a program.
* 11 '''Division by zero''' - Trying to divide a number by zero.
* 12 '''InvalidDirect Invalid direct command''' - Using a statement as a direct command it which is not allowd allowed outside a program, e.g. <code>DEF FN</code>.* 13 '''Type mismatch''' - Trying to assign Wrong data type encountered, string data to a instead of numeric variable value or vice versa.
* 14 '''String space full''' - String memory area is full.
* 15 '''String to too long''' - String may not exceed 256 characters.* 16 '''String expression too complex''' - A string expression need needs to be broken down into smaller expressions.* 17 '''CannotCONTinueCannot CONTinue''' - <code>CONT </code> can only be used if program was stopped by [ESC] or a <code>STOP </code> in program - not after END. If the program is modified before issuing <code>CONT</code> you will also get this error.* 18 '''Unknown user function''' - A <code>DEF FN </code> must be executed before calling an <code>FN </code> function.* 19 '''RESUMEmissing:RESUME missing''' - End of program has been reached while in error processing mode. Use <code>ON ERROR GOTO</code> before <code>RESUME</code>.* 20 '''UnexpectedRESUMEUnexpected RESUME''' - <code>RESUME </code> is only used in error processing mode, <code>ON ERROR GOTO </code> statement must be used first.
* 21 '''Direct Command found''' - A line without a line number has found while loading a file.
* 22 '''Oprand Operand missing''' - An incomplete expression has been found.* 23 '''Line too long''' - The line contains to too many statements.
* 24 '''EOF met''' - Trying to input data beyond end of data file.
* 25 '''FILE type error''' - Using a program file instead of a data file to read or write (or vice versa).
* 26 '''NEXT missing''' - The <code>NEXT </code> of a <code>FOR </code> ... <code>NEXT </code> loop is missing.* 27 '''File already open''' - Trying to open an open file. Use <code>CLOSEIN </code> or <code>CLOSEOUT </code> first.* 28 '''Unknown command''' - Given when an unknown command follows a masterspace<code>|</code>. e.g. <code>|DISC</code> on a CPC464 without AMSDOS installed.* 29 '''WEND missing''' - The <code>WEND </code> part of the <code>WHILE </code> ... <code>WEND </code> loop is missing.* 30 '''UnexpectedWENDUnexpected WEND''' - <code>WEND </code> encountered without a corresponding active <code>WHILE</code>.* 31 '''File not open''' - Attempting to read from or write to a file without OPENing <code>OPEN</code>ing it first.* '''Unknown error''' - Executing <code>ERROR</code> command with any other legal error code number (up to 255).
== Other Basic Dialects available for the CPC ==
13
edits