Changes

Locomotive BASIC

55,149 bytes added, 20:58, 25 November 2022
/* CHR$ () */
If you are interested in more information about the different versions of the CPC's BASIC and the technical details, you can have a look at the article "[[Technical information about Locomotive BASIC]]".
 
Another helpful and further resource of information about BASIC and a similar comprehension to this is Grimware's Website about the CPC http://www.grimware.org/doku.php/documentations/software/locomotive.basic/start
== History ==
Some parts of 'BASIC' were actually housed in the firmware ROM, but were not officially accessible to other programs. This included the line editor.
The 'pure BASIC' parts of Locomotive BASIC - i.e. those not concerned with CPC-specific firmware and hardware features - were upgraded to become [[Mallard BASIC]], the CP/M language shipped with the [[PCW]]. This also featured exceptionally advanced random-access file handling, a feature missing from the CPC. == Variables == === Real (Floating Point) Numbers === This is the default type for a Locomotive BASIC variables, but can be clarified using <code>!</code> after the variable name, e.g., <code>real!=500.0</code>. You can force all variables starting with specific letters to be this type by using the <code>DEFREAL</code> keyword. In many cases you don't want to use these, as they are slower than using the integer type, and use more memory (5 bytes, as opposed to 2). === Signed 16-bit Integers === Defined using <code>%</code> after the variable name, e.g., <code>integer%=500</code>. You can force all variables starting with specific letters to be this type by using the <code>DEFINT</code> keyword. These can store values between -32,768 and 32,767.To assign a 16-bit value to a signed integer directly, you should give the number in a hexadecimal format, e.g., <code>uint=&c0000</code>.  === Strings === These are defined by using <code>$</code> after the variable name, e.g., <code>str$="Hello"</code>. You can force all variables starting with specific letters to be this type by using the <code>DEFSTR</code> keyword. A String can be up to 255 characters long. == Type Conversions == The BASIC functions <code>ROUND</code>, <code>INT</code>, <code>CINT</code> and <code>FIX</code> can be used to convert real numbers into integers taking some care about rounding. The difference is in rounding mode - <code>ROUND</code> rounds to nearest, <code>FIX</code> rounds to zero, <code>INT</code> always rounds down, and <code>CINT</code>rounds up. e.g., <code>value%=INT(3.14)</code>. Note that if you don't specify the % you will actually get a real number still. To convert an integer to a real number, you can use the <code>UNT</code> function which will take the value supplied and return the two's complement number. e.g., <code>real=UNT(&ABCD)</code>. <pre>w=UNT(50000)ReadyPRINT w-15536Ready</pre> If you want an integer result from division, use the <code>\</code> integer division operator. e.g., <code>int=value\divisor</code>. This is as opposed to the standard <code>/</code> division operator, that can create a real number.
== Command list ==
=== Commands and operators ===
==== <code>AFTER </code>‹time delay›[<code>,</code>‹timer number›]<code> GOSUB ‹line number› </code>‹line number› ====: Waits for ‹time delay›/50 seconds and then jumps NON-RECURRING to the subroutine at ‹line number›. There are 4 delay timers from 0 to 3 which can be specified with ‹timer number›. If omitted ‹timer number› defaults to 0.: In the case of parallel task has 3 the highest and 0 the lowest priority.: With DI or EI you can disable or enable the timing interrupt. With REMAIN (see also <timer numbercode> you can also disable an AFTER or "EVERY construct and stores the i[,t] GOSUB line"remaining" time (</code> REMAIN).
==== <code>AUTO </code>[‹line number›][<code>,‹increment›] </code>‹increment›] ====
: Automatically generates line numbers starting at ‹line number› with ‹increment› after each entered line number. Use '''[ESC]''' to leave AUTO mode. Default values for ‹line number› and ‹increment› are 10.
: Example:
<pre>AUTO 100,5 :REM generates line numbers 100, 105, 110...</pre>
: <code>AUTO 100,5 :REM generates line numbers 100, 105, 110...</code> ==== <code>BORDER </code>‹colour›[<code>,‹colour›] </code>‹colour›] ====
: Changes the colour of the border. If the second argument is supplied the border flashes between the two colours.
==== <code>CALL </code>‹address expression›[<code>,</code>‹list of: parameter›] </code>====
: Allows a machine code routine to be called by BASIC. Variables, string values and constants can be passed to the routine. Values of any supported type can be passed back by supplying a variable with <code>@</code> in front of it. This passes the address of the variable to the routine although it doesn't implicitly know the data type.
: Example:
 : <codepre>CALL 0 :REM resets the computer completely</codepre>
==== <code>CAT</code> ====
: Displays the names of the files on the tape or disc. Tape files are displayed in the order they are encountered. Disc files are sorted alphabetically by ACSII code. Only files matching the current user are displayed. Files marked as system are not displayed.
: Examples:
<pre>CAT :REM lists all disc files in alpha-numeric (ASCII) order</pre>
: <code>CAT :REM lists all disc files in alpha-numeric (ASCII) order</code>: <codepre>|TAPE :CAT :REM lists names of all tape files in their storage order</codepre>
==== <code>CHAIN </code>‹file name›[<code>,‹line number expression›] </code>‹line number expression›] ====
:Enables the specified program to be loaded and RUN automatically. If the optional parameter ‹line number expression› is specified, the program execution will commence from that line.
==== <code>CHAIN MERGE </code>‹file name›[<code>,</code>‹line number expression› | [<code>,</code>[‹line number expression›]<code>,DELETE</code> ‹line number range›]] </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 <code>DELETE</code> ‹line number range› 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.
: The command clear inside a subroutine (<code>GOSUB</code>... <code>RETURN</code>) will also clear the "stack pointer" address of the gosub heap. That means that a RETURN won't work and a GOTO has to be used instead.
==== <code>CLG </code>[‹masked ink›] </code>====: Clears the graphics screen to colour specified by <code>‹masked ink›</code>. If parameter <code>‹masked ink› </code> is not specified then the graphics screen is cleared to the colour specified by the GRAPHICS PAPER statement.
==== <code>CLOSEIN</code> ====
: Closes any output file (tape or disc).
==== <code>CLS</code> [<code>#‹stream expression›]</code>‹stream expression›]====
: Clears the window specified by ‹stream expression›. If ‹stream expression› is omitted it defaults to #0 (usually the whole screen). The text cursor of the stream is moved to the upper left corner.
: CONTinues program execution interrupted either by [ESC] [ESC] or as a result of STOP within a program. A program cannot be continued after being modified.
==== <code>CURSOR ‹expression›</code> ====: <code>‹expression› </code> must be either 0 or 1.
==== <code>DATA x1[,x2,x3...]</code> ====
==== <code>DEF</code> ====
: [DEF means "define" and comes along with defining a function in case of DEF FN or defining variables in case of DEFREAL, DEFINT or DEFSTR.: DEF FN must come before using the statement FN.: DEF with a variable declaration should come before using a variable.]: (see also FN)
==== <code>DEFINT letter range‹letter range›</code> ==== : Forces all variables(s) starting with the specified letter(s) to be string integer variables. The s does not need to Singular letters could be added to DEFSTR variable namesdefined or a range by a minus symbol between two letters: Example:
:Examples:
<pre>
10 DEFSTR N 20 DEFINT a- z:' sets all variables starting with letter N an A until Z as stringsinteger.
</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 : Example:or
<pre>
10 DEFINT F,S ..... (or 10 DEFINT A-Z)
20 FIRST=111.11:SECOND=22.2
30 PRINT FIRST,SECOND - :' prints out 111 22
</pre>
 
==== <code>DEFREAL ‹letter range›</code> ====
: Sets the default for variable(s) with the specified first letter(s) to a floating point figure.
 
==== <code>DEFSTR ‹letter range›</code> ====
 
: Sets the default for variable(s) with the specified first letter(s) to string(s) variables.
==== <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> ====
==== <code>DI</code> ====
: Disables interrupts (but not[ESC]) until re-enabled by EI command or by RETURN at end of an interrupts service routine.
: This means that DI (if it's activated in a subroutine) is useful helping a low-priority-interrupt not to be stopped by a higher-priority-interrupt. RETURN then re-enable the interrupt without EI.
==== <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.
: 4 drawing styles:
<pre>
i2 = 0 normal colour i2 = 2 AND 1 XOR colouri2 = 1 XOR 2 AND colour i2 = 3 OR colour</pre>: Example:<pre>CLG 2DRAW 500,400,0 :REM draws a line from 0,0 to 500,400
</pre>
Example: <code>: CLG 2: DRAW 500,400,0 :REM draws a line from 0,0 to 500,400</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‹line›</code> ====: Copies one Display 1 program line to screen for editing.  The following keys can be used in edition editing mode, or during typing in BASIC:  CTRL+TAB - toggle overwrite/insert mode CTRL+CURSOR LEFT or CTRL+CURSOR UP - go to start of line CTRL+CURSOR RIGHT or CTRL+CURSOR DOWN - go to end of line CURSOR LEFT - move left one character CURSOR RIGHT - move right one character ESC - quit editing and do not accept changes ENTER/RETURN - quit editing and accept changes SHIFT + CURSOR UP/DOWN/LEFT/RIGHT - enter copy mode. You can move the cursor to where you want to copy from. Hold SHIFT and cursors to move copy cursor. COPY - copy character covered by copy cursor. DEL - delete character and go back a char CLR - delete character under cursor CTRL + CAPS LOCK - toggle shift lock.
==== <code>EI</code> ====
: Indicates end of program
==== <code>ENT‹tone envelope number›[,‹tone env. section›][,‹tone env. section›][,‹tone env. section›][,‹tone env. section›][,‹tone env. section›]</code> ====: [The ENT command define the TONE shape of a sound which means manipulating the frequency in a certain range.:The command could looks like:<pre>ENT NUMBER,STEPS?,VERTICAL?,HORIZONTAL?</pre>:It is possible to define 15 different envelope shapes.So '''NUMBER''' could be 1-15.]
:Each '''?''' stands for up to five sections (1-5), where each STEP<>VERTICAL<>HORIZONTAL with the same '''?''' are belong together. :'''STEP:''' means how many steps in each section (0-127) > one step is 1/100 of a second!:'''VERTICAL''': means how big is the step size from bottom to top (-128 to 127):'''HORIZONTAL''': means how big is the step size from left to right (0-255) ==== <code>ENV‹volume envelope number›[,‹volume env. section›][,‹volume env. section›][,‹volume env. section›][,‹volume env. section›][,‹volume env. section›]</code> ====: [The ENV command define the VOLUME shape of a sound which means manipulating the loudness in a certain range.:The command could looks like:<pre>ENV NUMBER,STEPS?,VERTICAL?,HORIZONTAL?</pre>:It is possible to define 15 different envelope shapes.So '''NUMBER''' could be 1-15.] :Each '''?''' stands for up to five sections (1-5), where each STEP<>VERTICAL<>HORIZONTAL with the same '''?''' are belong together. :'''STEP:''' means how many steps in each section (0-127) > one step is 1/100 of a second!:'''VERTICAL''': means how big is the step size from bottom to top (-128 to 127):'''HORIZONTAL''': means how big is the step size from left to right (0-255)
==== <code>ERASE v1[% | ! | $][,v2[% | ! | $][,...]]</code> ====
==== <code>EVERY i[,t] GOSUB ln</code> ====
: BASIC branches to the subroutine at line ln every EVERY (reccuring) i/50 seconds. (see also "AFTER i[,t] GOSUB line") : There are 4 delay timers from 0 to 3 which can be specified with ‹timer number›. If omitted ‹timer number› defaults to 0.: In the case of parallel task has 3 the highest and 0 the lowest priority.: With DI or EI you can disable or enable the timing interrupt. With REMAIN <timer number> you can also disable an AFTER or EVERY construct and stores the "remaining" time (> REMAIN): Interrupts run as long as the main loop / program runs, even the main programm is paused > press ESC only '''once''' not twice for a break.: It is important to know or realise that low-priority-interrupts which occurs simultanously to higher-priority-interrupts are not lost. Their task remains or handled again after finishing the higher-prio interrupt. <pre>10 REM > interrupts20 EVERY 50,0 GOSUB 100: REM > lowest priority30 EVERY 100,1 GOSUB 20040 EVERY 200,2 GOSUB 300:50 AFTER 1000,3 GOSUB 400: REM > highest priority60 WHILE flag=070 a=a+1:print a80 WEND90 END100 REM #0110 PEN 2:PRINT "timer 0":PEN 1120 RETURN200 REM #1210 PEN 2:PRINT "timer 1":PEN 1220 RETURN300 REM #2310 PEN 2:PRINT "timer 2":PEN 1320 RETURN400 REM #3410 flag=1:PEN 2:PRINT "no more interrupts..."420 RETURN</pre> : Hint: Timing with interrupts is important, especially if more than one interrupts run. If the interval of a subroutine driven by an interrupt is too long than the processor can never get back to deal the main program again. Work out timing by measuring the subroutine or by trial and error.: There are system internal interrupts (highest level) which cannot be influenced by BASIC interrupts (e.g. keyboard scan > BREAK key.): The next level of sytem internal interrupts CAN be influenced by BASIC interrupts. For example the sound queue which will be created by "ON SQ <chanel> GOSUB <line>". Those sound interrupts have an independent time tricker but their priority is parallel to the second priority times of BASICs interrupts. Therefore interrupts with timer 3 could "interrupt" them.
==== <code>FILL i</code> ====
==== <code>FN</code> ====
:BASIC allows the program to define and use simple value returning functions. DEF FuNction is the definition part of this mechanism and creates program-specific function which works within the :program in the same way as a function such a COS operates as a built-in function of BASIC. It may be invoked throughout the program. Variable types must be consistent and the DEF FN :command should be written in part of the program outside the execution loop.
:Syntax : <code>DEF FN<name>[(<formal parameters>)]=<general expression></code>
:Example: ''"with the definition of..."''
<pre>
10 gn=9.80665
40 PRINT "...after";t;"seconds your dropped stone falls";FNgrv;"metres"
</pre>
:''"the results are..."''
<pre>
:...after 5 seconds your dropped stone falls 122.58315 metres
</pre>
==== <code>FOR TO STEP NEXT</code> ====
: Creating a counting loop (control strucutre) with a starting condition. Inside the counting loop one or more commands will be executed.: The loop consists of of following specifications: : 1. FOR: 2. ''a control variable'': 3. =: 4. ''starting value'': 5. TO: 6. ''target value'': 7. STEP [optional]: 8.''increment / step size'': ''... instructions between'': 9. NEXT: 10. ''control variable'' [optional: You have to use the command STEP if you wish to count backwards. It's good to name the ''control variable'' after NEXT for readability and better program style.: After each loop the computer checks internaly if the ''target value'' has been reached (like an IF ... THEN ... ELSE instruction). If the target value is reached NEXT closes the loop and calculates another step, so the ''control variable'' will be changed last time.: The default STEP value - if not specified - is one (1). : Example:<pre>10 FOR I=1 TO 1020 PRINT I;30 NEXT I40 PRINT IRUN1 2 3 4 5 6 7 8 9 10 11READY</pre>
==== <code>FRAME</code> ====
20 PRINT I
30 I=I+1
40 IF I<25 THEN GOTO 1020
50 END
</pre>
==== <code>GRAPHICS</code> ====
: [...]works only in combination with the command <code>PEN</code> or <code>PAPER</code> to set the plotting/drawing pen or background colour.: If the <code>TAG</code> command is used to set text at the graphics cursor <code>GRAPHICS PEN</code> or <code>GRAPHICS PAPER</code> instead of the regular <code>PEN</code> or <code>PAPER</code>is necessary to colour the text.
==== <code>IF THEN ELSE</code> ====
:Other nested structures like IF...THEN...'''ELSE...ELSE''' won't work first because the Locomotive Basic only looks after the first ELSE instruction found and can't execute more single commands as a block for a certain condition in comparision to e.g. "PASCAL" > begin...end-block, "C" > {...}-block.
==== <code>INK‹pen›,‹colour›,[‹second colour›]</code> ====: [Used to set the colour palette for each of the 16 available inks.: pen specifies the pen slot to use.: colour specifies the system colour to use (0.].27.): if the second colour is provided, Locomotive Basic will blink between the colour and second colour.: In MODE 0, all 16 pens are available. In MODE 1, only 4 pens are available (0..3). In MODE 2, only 2 pens are available (0..1.): By default, pen 0 is the background colour and pen 1 is the foreground/text colour.: Examples:<pre>10 MODE 220 INK 0,3: REM Set background colour to red30 INK 1,26: REM Set foreground/text colour to white</pre>
==== <code>INPUT[#‹stream expression›][,]</code> ====
: [...]
</pre>
==== <code>LINE INPUT </code>[#‹stream expression›][,]‹variable›[<code>,‹variable›] </code>‹variable›] ====
: [...]
==== <code>LIST </code>[‹line number›][<code>-</code>[‹line number›]] , [#‹stream expression›]</code>====: [A command for listing the Basic program code.: Possibility for manipulating display is using line numbers with a minus symbol.: Example:<pre>LIST 100-</pre>: List every line after line number 100.]<pre>LIST -100</pre>: List every line until line number 100 has reached.<pre>LIST 100-200</pre>: List every line between line number 100 and 200 included
: With the help of separate window definitions it is possible to print out long listings, better differentiate parts / slices of it into different window predefined: Example:<pre>LIST 1000-1100,#1LIST 3000-3100,#2</pre>: ...prints out two parts of one program out into two windows (if they are defined well) ==== <code>LOAD ‹file name›[<code>,‹address›] </code>‹address›] ==== With this directive you may load any file in memory Basic files (extension .BAS) are loaded in Basic memory, you cannot choose loading address Binary files are loaded to the default address location stored in the AMSDOS header but you may force loading address (&C000 for a screen) TAPE convention: [ When loading tape files, the basic display a message every block which may cause trouble.Message output may be disabled by using prefix "!" before the filename..] It's also possible to load the next file disregarding his name using only "!" => <code>LOAD "!"</code>
==== <code>LOCATE [#‹stream expression›][,] x,y</code> ====
: Moves the text cursor to the x,y location.
</pre>
==== <code>MEMORY add‹memory address›</code> ====
: Allocates the amount of memory to be used by BASIC by setting the [[Locomotive_BASIC#HIMEM|address of the highest byte ]] it may use.
==== <code>MERGE</code> ====
: [...]
==== <code>MID$(‹string›,‹start position›[,‹length of substring›])</code> ====: [With the MID$ command there are two applications possible: : 1.MID$ creates a new substring out of the give ‹string› and starts at the defined position ‹start position› and print the number of given characters by ‹length of substring›.: If no length is defined every character from ‹start position› will be printed out.]: If a higher value of ‹start position› or ‹length of substring› than the real length of the initial string is defined a blank string will be printed.: The range of ‹start position› or ‹length of substring› is from 0 up to 255 characters. : 2. With MID$ you're able to manipulates given strings by inserting a new string.: Take care of the two different applications and using in BASIC.  : Example for the 1. application:<pre>10 a$="Hello"20 PRINT MID$(a$,2,2)runelReady</pre>:: Example for the 2. application<pre>10 a$="Hello"20 MID$(a$,2,3)="ipp"30 PRINT a$runHippoReady</pre>
==== <code>MODE</code> ====
: Changes the screen mode: MODE 0 is 160x200 160×200 in 16 colorscolours, MODE 1 is 320x200 320×200 4 colors and colours, MODE 2 is 640x200 640×200 2 colorscolours and MODE 3 is 160×200 in 4 colours.
==== <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.
: 4 drawing styles: <pre>i2 = 0 normal colouri2 = 1 XOR colouri2 = 2 AND colouri2 = 3 OR colour</pre> ==== <code>MOVERxr,yr[,[i1][,i2]]</code> ====: [moves the graphic cursor (relative) from current position to current cursor x position + xr, current cursor y position + yr.i1 and i2 as in MOVE..]
==== <code>NEW</code> ====
: [Clears BASIC RAM which means program and variables.Keeps symbol defintion (if defined) and screen mode without clearing..]
==== <code>ON BREAK CONT</code> ====
:In case that the variable ''choice'' won't fullfil the condition (in a range between line 0 and 65535) the next instruction will be executed (here: Line 40). If "choice" is smaller than 0 an error will occur.
==== <code>OPENIN "datafile"ON SQ(x) GOSUB ln x1, x2, x3, x4, ...</code> ====:ON SQ(x) can trigger an interrupt when e.g. a space or free channel in queue.:Using that command is a one way interrupt trigger and shouldn't be mixed with <code>EVERY</code> or <code>AFTER</code> commands.
: Opens See also the specified data file for reading. It have to be an ASCII file. <code>SQ( The x)</code> command closein closes reading data filefor more details. )
==== <code>OPENIN ‹filename›</code> ====: Opens the specified data file for reading. It has to be an ASCII file. ( The command <code>CLOSEIN</code> closes reading data file. ): Read from the file using <code>INPUT #9</code> ==== <code>OPENOUT "datafile"‹filename›</code> ====
: Opens the specified data file for writing. It writes an ASCII file. (To close writing use the command closein.)
==== <code>ORIGINx,y[,l,r,t,b]</code> ====: [The command defines the origin ('world reference point') for the graphics coordinate system.Normally the reference origin is in the left, bottom corner of the default screen and has 0,0.So the most left coordinate value could be by default 639 and the most top value 399.]Independent from the actual modus (2, 1 or 0) the range for the x coordinate are always 640 points and for the y coordinate 400 points. In theory you are able to address 256,000 pixel but only 128,000 are visible due to the maximal resolution of the hardware.: <code>x,y</code> are the the new coordinates for the 'world reference '.: <code>l,r,t,b</code> are optional and set the borders for the new graphical window (works in the same way like the <code>WINDOW</code> command for a text window). l,r,t,b means left, right, tob and bottom coordinates.: If a new graphical window (borders) is defined every point or drawn line won't be plotted (clipped internally).
==== : Example (the line drawn will be cutted):<codepre>OUT addORIGIN 320,i200,250,450,100,300DRAW 0,200</codepre> ====
: Outputs the value of i (0-255) to the I==== <code>OUT ‹address›,‹value›</O address add.code> ====
: Outputs a value (range of 0-255) to a specific I/O address.: Watch out http://cpcwiki.eu/index.php/I/O_Port_Summary ==== <code>PAPER[#‹stream expression›][,]</code> ====
: [...]
==== <code>PEN[#‹stream expression›][,]</code> ====
: [...]
: Alters contents of memory location add to value i (0-255)
==== <code>PRINT[#‹stream expression›][,]</code> ====
: [...]
==== <code>RAD</code> ====
: Switch to radians mode for trigonometric functions (<ttcode>SIN</ttcode>, <ttcode>COS</ttcode>...).
: ''See also:'' <ttcode>DEG</ttcode>
==== <code>RANDOMIZE [seed]</code> ====
: Resets the pseudo-random generator to the given seed(starting value of the 'random' series). What is strange is that if no seed is given, one is interactively prompted for.
: A common idiom to have a ''random'' random seed is to do:
</pre>
: <code>RANDOMIZE TIME</code> isn't still a 'real' random number but to hit the same series again is pretty hard due to the time elapsed.: The algorithm used for randomizing is the following: the generator starts with the seed, adds 1, multiplies by 75 (fiddle factor), divides by 65537 and then uses the remainder -1.
==== <code>READ variable</code> ====
''See also:'' <tt>DATA</tt>, <tt>RESTORE</tt>
==== <code>RELEASEchanel</code> ====: [Releases a sound which was hold on (by a SOUND command) before...]It uses the same bit matrix like the SOUND command for the first parameter# (&x00000001) releases chanel A# (&x00000010) releases chanel B# (&x00000011) releases chanel A and B# (&x00000100) releases chanel C# (&x00000101) releases chanel A and C# (&x00000110) releases chanel B and C# (&x00000111) releases chanel A, B and C :Example:<pre>10 SOUND 65,1000,10020 PRINT"PRESS R TO LET IT SOUND"30 IF INKEY(50)=-1 THEN 3040 RELEASE 1</pre>
==== <code>REM [any text]</code> ====
: Introduces a comment.
==== <code>RENUM </code>[‹newLine›][<code>,</code>‹oldLine› | <code>,</code>[‹oldLine›]<code>,‹step›] </code>‹step›] ====
: Renumbers the lines of the current program.
: ''See also:'' <tt>DATA</tt>, <tt>READ</tt>
==== <code>RESUME[line] or NEXT</code> ====: [Command causes the program to resume after an error code and if it is interrupted by an '''ON ERROR GOTO''' jump: So it can either resume*(if there's no line number stated) at the same line after error code (and if there are more statements in one line)or* at the line number stated (optional)or* with the NEXT parameter (optional) ...]at the line followed by the error line
==== <code>RETURN</code> ====
: Terminates a subroutine and returns control to the line following the GOSUB call (see GOSUB)
==== <code>RUN [line]or "filename"</code> ====: Runs the current program, optionally starting at a given line. If no line number is given, starts at the first line.
:If a string is used after RUN command a programm will be loaded and executed from storage medium (e.g. Tape, Disc). With that command protected BASIC programs can be executed. :Exampel:<pre>RUN"disc"</pre> ==== <code>SAVE"filename" [,filetype][,paramter1,parameter2,parameter3]</code> ====: [Command saves the current BASIC program / content from RAM onto a storage medium (e.g.Tape, Disc) : Filetype could be:* ''',A''' for a ASCII file* ''',B''' for a binary file (store RAM content as it is)* ''',P''' for a regular, ''protected'' BASIC file: without that parameter the content will be stored as a regular BASIC file :The three parameters after filetype could be used in combination with the binary filetype (,B).]* '''''parameter1''''' defines the starting address of memory range* '''''parameter2''''' defines the length (range of memory)* '''''parameter3''''' defines the entry point (optional)
==== <code>SOUND</code> ====
: [...]the SOUND command has following shape:: SOUND '''C'''hannel,'''P'''eriod,'''D'''uration,'''V'''olume,Volume-'''Env'''elope,'''T'''one-'''En'''velope,'''N'''oise
==== <code>SPC</code> ====: [...]'''C:''' Selecting channel is done bitwise (combinations are possible of course):
<pre>(Bit 0) &x00000001 = 1 = channel A (middle)(Bit 1) &x00000010 = 2 = channel B (left)(Bit 2) &x00000100 = 4 = channel C (right)</pre>:more function about channel are<pre>(Bit 3) &x00001000 = 8 = Rendezvous with channel A(Bit 4) &x00010000 = 16 = Rendesvous with channel B(Bit 5) &x00100000 = 32 = Rendesvous with channel C(Bit 6) &x01000000 = 64 = Hold(Bit 7) &x10000000 = 128 = Flush</pre>:'''P:''' the period number can be a figure between 0 and 4095 (2^12-1... 12 means that we have 12 tones (inclusive half-tones) in nine octaves on the CPC in sum and their distance between is the twelves square root of two), where 8 octaves are available. E.g. Octave 0 starts on middle C with number 478.: To calculate the period you can use following formula: '''period=1,000,000/(16*frequency)''' or in short '''period=(62,500/frequency)''': (e.g. the note "A" with the frequency 440 Hz has the period 142 on the CPC) :'''D:''' the duration of the note is measured in 1/100th of a second and can be any positive number in the range 1-32,767. 0 and negative number are in combination with ENT and ENV commands usefull. A negative number means repititions. :'''V:''' the volume number range from 0-7 on a CPC 464 (BASIC 1.0) or 0-15 on a CPC664/6128 (BASIC 1.1) :'''ENV:''' and '''ENT:''' For shaping the sound ENV (Volume) and ENT (Frequency) commands are available. The relation between SOUND and those commands comes with a figure between 1 to 15 for ENV (5th parameter) and 1 to 15 for ENT (6th parameter). :'''N:''' the seventh parameter can be used for blending in noise between the range of 0-15 (BASIC 1.0) or 0-30 (BASIC 1.1). The higher the number the 'deeper' or 'dirty' is the noise. ==== <code>SPC <n></code> ====: in conjunction with PRINT the SPC command prints out a certain number (n) of spaces.: Example:<pre>PRINT "Hello";SPC(10);"World";Hello World</pre> ==== <code>SPEEDINK <n1,n2> </code> ====: [SPEED INK command defines the frequency of colour changes if a colour change was defined.The duration is calculated by n1=... or n2 =duration/50 seconds. ==== <code>SPEED KEY <start,repeat> </code> ====: SPEED KEY command defines the delay after which a key repeat (for keys that do repeat). The first parameter is the delay before the first repeat and the second parameter is the delay between further repeats. Delay is in 1/50th of seconds. :When using it with low values, it is common to associate a key to reset the default speed of 30,2.:For example to associate the key 0 from the numpad:<pre>KEY 0,"SPEED KEY 30,2"+CHR$(13)</pre> ==== <code>SPEED WRITE <n> </code> ====: SPEED WRITE defines the speed at which data is to be saved or written to a cassette unit. n=1 means 2000 baud, n=0 (default) means 1000 baud.When reading from the tape, the correct speed is automatically selected.]
==== <code>SQ (channel)</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> ====
: [SWAP works only in combination with the window command.Every error or status messages from the operating system will be displayed normaly on WINDOW#0 (=''main'' window).WINDOW SWAP changes the ''main'' window to the desired target window.]: Example (if a window with number 4 was defined before...):<pre>WINDOW SWAP 0,4</pre>
==== <code>SYMBOL n,i1[,i2,i3,i4,i5,i6,i7,i8]</code> ====
: [...]
==== <code>WINDOW[#‹stream expression›],[L],[R],[T],[B]</code> ====: [It is possible to define in BASIC eight (8) independent windows for text output.Overlapping is possible: #STREAM: eight window are possible.]No. zero (0) is the main window where error or status messages were put out by default.: each position is included inside the window: L = left column / R = right column (dependent of the mode 0 = 20 / 1 = 40 / 2 = 80): T = top row / B = bottom row (always from 1 to 25) : Example:<pre>MODE 1WINDOW#1,1,40,1,6</pre>: ...defines the first top quarter of the screen for window No. 1
==== <code>WRITE [#st,] v[$], v[$]</code> ====
: Changes the width of the print zone. Default is 13.
: Example:
<pre>
10 MODE 2
20 PRINT"normal zone (13)"
30 PRINT 1,2,3,4
RUN
normal zone(13)
1 2 3 4
READY
20 PRINT"now with different zone(5)"
30 ZONE 5
40 PRINT 1,2,3,4
RUN
now with different zone(5)
1 2 3 4
READY
</pre>
=== Operators ===
: A logical status in Locomotive Basic will be represented by a "-1" for TRUE and by a "0" for FALSE.: Example:<pre>PRINT (1=1)-1PRINT (1=2)0</pre>
==== <code>AND</code> ====
: [Possible combinations with the AND Function:<pre>NPUT1 INPUT2 OUTPUT======================TRUE TRUE TRUEFALSE FALSE FALSETRUE FALSE FALSEFALSE TRUE FALSE</pre>: Example:<pre>PRINT 128 AND 640</pre>: looking at the BIT combination for a better understanding:<pre> 10000000AND 01000000================= 00000000</pre>: even in BASIC it is possible to manipulate single BITs although there are no special commands but AND, OR and XOR...]: first an example for a loop with an increasing counter WITHOUT an AND:<pre>10 counter=020 counter=counter+130 IF counter=32 THEN counter=040 GOTO 20</pre>: then a shorter example WITH and AND:<pre>10 counter=020 counter=(counter+1) AND 3130 GOTO 20</pre>: in the second example all more significant BITs will be deleted (a common method in assembler programming): Beware: it only works here with BIT/number conditions one figure smaller than 1, 3, 7, 15, 31, 63 and 127
==== <code>MOD</code> ====
: ['''MOD''' returns a (rounded) rest (Modulos) after dividen has been devided by the devisor...]::'''Example:'''<pre>32767 mod 256255</pre>: Note: only works with numbers in the range -32768 and 32767 (&8000 < 0 < &7FFF)
==== <code>NOT</code> ====
==== <code>OR</code> ====
: [...]Possible combinations with the OR Function:<pre>NPUT1 INPUT2 OUTPUT======================TRUE TRUE TRUEFALSE TRUE TRUETRUE FALSE TRUEFALSE FALSE FALSE</pre>
==== <code>XOR</code> ====
: [...]Possible combinations with the XOR Function:<pre>NPUT1 INPUT2 OUTPUT======================TRUE TRUE FALSEFALSE TRUE TRUETRUE FALSE TRUEFALSE FALSE FALSE</pre>
=== Functions ===
==== <code><big>ABS (n<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns the absolute ABSolute value of n by ignoring the sign valuegiven numeric expression (n).This means that negative numbers are returned as positive.: '''Associated keywords''': SGN
: '''Example''':
<pre>
PRINT ABS(-367.598) - prints 3 67.598
</pre>
==== <code><big>ASC (s<string expression>)</big></code> ====: ''BASIC 1.0 & 1.1'' : '''FUNCTION''': Returns the numeric value of the first character in the <string expression> (s).: '''Associated keywords''': CHR$
: Returns ASCII '''Example''':<pre>PRINT ASC("x") 120</pre>==== <code ><big>ATN (<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Calculates the Arc-TaNgent of the <numeric expression> (n) to a real number ranging from -PI/2 to +PI/2 of first character the value specified.: Note that DEG and RAD can be used to force the result of string sthe below calculation to degrees or radians respectively.
==== <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'''Associated keywords''':COS, DEG, RAD, SIN, TAN
: '''Example''':
<pre>
PRINT BIN$ATN(66,81) - prints 010000100.785398163
</pre>
==== <code><big>BIN$ (<unsigned integer expression>,[<integer expression>])</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Produces a string of BINary digits respresenting the value of the <unsigned integer expression>, using the number of binary digits instruced by the second <integer expression> (in the range of 0 to 16). If the number of digits instructed is too great, the resulting expression will be filled with leading zeros; if the number of digits instructed is too small, the resulting expression will NOT be shortened to the instructed number of digits, but will produced in as many digits as are required.
: The <unsigned integer expression> to be converted into binary form must yield a value in the range -32768 to 65535.
: '''Associated keywords''': DEC$, HEX$, STR$
: '''Example''':
<pre>
PRINT BIN$(66,8)
01000000
</pre>
==== <code><big>CHR$ (<numeric expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Converts an <integer expression> in the range 0 to 255, to its CHaRacter $tring equivalent, using the AMSTRAD character set shown in the ASCII table or e.g. in the manual part 3.
: Note that 0 to 31 are control characters; hence the below example prints CHR$(x) in the range 32 to 255
: '''Associated keywords''': ASC, LEFT$, RIGHT$, MID$, STR$
==== : '''Example''':<codepre>10 FOR X=32 to 25520 PRINT X;CHR$ (nX);30 NEXT</codepre> ====: Returns the character for a given index n. For instance CHR$(65) returns the character 'A'. Valid indices range from 0 (zero) to 255. : As an further example, try the following basic program : 
<pre>10 print chr$(208+rnd(2));:goto 10</pre>
: It will draw a random maze with characters 208 and 209, which are an horizontal and a vertical bar.
: Control Codes Table:<pre>==== <code>CINT ===========================================================================| VALUE | NAME | PARAMETERS | EFFECT |===============================================================================| DEC | HEX | | | |===============================================================================| 0 | &00 | NUL | NONE | DOES NOTHING || 1 | &01 | SOH | 0-255 | PRINTS CHARACTER TO SCREEN || 2 | &02 | STX | NONE | TURNS TEXT CURSOR OFF || 3 | &03 | ETX | NONE | TURNS TEXT CURSOR ON IN IMMEDIATE MODE || 4 | &04 | EOT | 0-2 | SET SCREEN MODE || 5 | &05 | ENQ | 0-255 | PRINT CHARACTER AT GRAPHICS CURS. || 6 | &06 | ACK | NONE | TURNS ON TEXT SCREEN (SEE ALSO CHR$(n21)</code> )|| 7 | &07 | BEL | NONE | MAKE A SHORT BEEP || 8 | &08 | BS | NONE | MOVES TEXT CURSOR BACK ONE CHARACTER || 9 | &09 | TAB | NONE | MOVES TEXT CURSOR FORWARD ONE CHARACTER || 10 | &0A | LF | NONE | MOVES TEXT CURSOR DOWN ONE CHARACTER || 11 | &0B | VT | NONE | MOVES TEXT CURSOR UP ONE CHARACTER || 12 | &0C | FF | NONE | CLEARS SCREEN OR WINDOWS (=CLS) || 13 | &0D | CR | NONE | MOVES CURSOR TO LEFT EDGE OF WINDOW ON || | | | | CURRENT LINE || 14 | &0E | SO | 0-15 | SETS PAPER COLOUR || 15 | &0F | SI | 0-15 | SETS PEN COLOUR || 16 | &10 | DLE | NONE | DELETES CHARACTER UNDER TEXT CURSOR || 17 | &11 | DC1 | NONE | CLEARS LINE FROM LEFT OF WINDOW UP TO || | | | | AND INCLUDING CURRENT CHARACTER || 18 | &12 | DC2 | NONE | CLEARS FROM CURRENT CHARACTER TO RIGHT || | | | | EDGE OF THE WINDOW || 19 | &13 | DC3 | NONE | CLEARS FROM START OF WINDOW UP TO AND || | | | | INCLUDING CURRENT CHARACTER || 20 | &14 | DC4 | NONE | CLEARS FROM CURRENT CHARACTER TO END OF || | | | | WINDOW || 21 | &15 | NAK | NONE | TURNS OFF TEXT SCREEN (SEE ALSO CHR$(6))|| 22 | &16 | SYN | 0 AND 1 | TURNS TRANSPARENT OPTION OFF AND ON || 23 | &17 | ETB | 0-3 | SET GRPAHICS PLOTTING MODE || 24 | &18 | CAN | NONE | CHANGE TO INVERSE CHARACTER DISPLAYING || 25 | &19 | EM | NINE PARAM. | DEFINES A CHARACTER (=SAME AS SYMBOL) || | | | EACH 0-255 | || 26 | &1A | SUB | FOUR PARAM. | DEFINES A TEXT WINDOW (=SAME AS WINDOW) || | | | 1-80, 1-80 | FROM LEFT, RIGHT, TOP TO BOTTOM || | | | 1-25, 1-25 | FROM LEFT, RIGHT, TOP TO BOTTOM || 27 | &1B | ESC | NONE | DOES NOTHING ON SCREEN (PRINTER SIGNAL) || 28 | &1C | FS | THREE PARAM. | SETS INK COLOUR TO FLASH BETWEEN TWO || | | | 0-15, 0-32 | INK NO, COLOUR 1, COLOUR 2 || | | | 0-32 | || 29 | &1D | GS | TWO PARAM. | SETS BORDER COLOUR TO FLASH BETWEEN TWO || | | | 0-31, 0-31 | COLOURS || 30 | &1E | RS | NONE | HOMES CURSOR TO TOP LEFT OF SCREEN || 31 | &1F | US | TWO PARAM. | MOVES CURSOR TO CELL SPECIFIED BY TWO || | | | 1-80, 1-25 | PARAMETERS (=SAME AS LOCATE) |===============================================================================</PRE>
==== <code><big>CINT (<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns rounded up integer the value of the <numeric expression> (n between ), Converting it to a rounded INTeger in the range -32768 and to 32767.
: Example'''Associated keywords''':CREAL, FIX, INT, ROUND, UNT
: '''Example''':
<pre>
10 n=1.999920 PRINT CINT(3.8n) - print 4run 2
</pre>
==== <code><big>COPYCHR$ (#stream)</big></code> ====
: : ''BASIC 1.1''
: '''FUNCTION''': COPies a CHaRacter from the current position in the stream (which MUST be specified). The below program copies a character from location 1,1 (top left), and reproduces it at location 1,20.
: If the character read is not recognized, a null string is returned.
==== <code>COPYCHR$ (st)</code> ====: '''Associated keywords''': LOCATE
: Copies character from current position in specified stream'''Example''':<pre>10 CLS20 PRINT "top corner"30 LOCATE 1,140 a$=COPYCHR$(#0)50 LOCATE 1,2060 PRINT a$</pre>==== <code><big>COS (<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Calculates the COSinus of the <numeric expression> (n).: Note that DEG and RAD can be used to force the result of the below calculation to degrees or radians respectively.
==== <code>COS (n)</code> ====: '''Associated keywords''': ATN, DEG, RAD, SIN
: '''Example''':<pre>DEGPRINT COS(45) 0.707106781</pre>==== <code><big>CREAL (<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns cosine the value of n in degrees or radians the <numeric expression> (se DEG and RADn), Converting it to REAL.
==== <code>CREAL (n)</code> ====: '''Associated keywords''': CINT
: Converts integer '''Example''':<pre>10 a=PI20 PRINT CINT(a)30 PRINT CREAL(a)run 3 3.14159265</pre>==== <code><big>DEC$(<numeric expression>, <format template>)</big></code> ====: ''BASIC 1.1'': '''FUNCTIION''': Returns a DECimal string representation of the <numeric expression> (n ), using the specified <format template> to real numeric variablecontrol the print format of the resulting string.: The format template may contain ONLY the characters:
==== <code>DEC: + - $(n£ * # , format)</code> ====. ^
: Retruns the decimal string representation The use of n, according to these 'format field specifiers' is described under the specified format (see keyword PRINT USING).
==== <code>DERR</code> ====: '''Associated keyword''': BIN$, HEX$, PRINT USING, STR$
: Gives '''Example''':<pre>PRINT DEC$(10^7,"££########,.##") £10,000,000.00</pre>==== <code><big>DERR</big></code> ====: ''BASIC 1.1'': '''FUNCTION''': Reports the most recent last error code number returned by [[Amsdos]]the disc filing system. The value of DERR may be used to ascertain the particular Disc ERRor that occurred. See the listing of error messages below.
==== <code>EOF</code> ====: '''Associated keywords''': ERL, ERR, ERROR, ON ERROR GOTO, RESUME
: '''Example''':<pre>LOAD "xyz.abc" XYZ .ABC not foundReadyPRINT DERR 146</pre>: '''Table of Disc ERRor codes''':: If AMSDOS has already reported an error, then bit 7 is set, hence the value of DERR is offset by 128.<pre>===============================================================================| VALUE | DERR value | DESCRIPTION |===============================================================================| 0 | 0 or 22 | [ESC] has been pressed || 14 | 142 (128+14) | The stream is not in a suitable state. || 15 | 143 (128+15) | Hard end of file has been reached. || 16 | 144 (128+16) | Bad command, usually an incorrect filename. || 17 | 145 (128+17) | File already exists. || 18 | 146 (128+18) | File does not exists. || 19 | 147 (128+19) | Directory is full. || 20 | 148 (128+20) | Disc is full. || 21 | 149 (128+21) | Disc changed while file were open. || 22 | 150 (128+22) | File is Read/Only. || 26 | 154 (128+26) | Soft end of file has been detected. || | | |===============================================================================</pre>: Other values returned by DERR originate from the disc controller and are bit significant, always with bit 6 set.: The significance of each bit is as follows:<pre>===============================================================================| BIT | Significance |===============================================================================| 0 | Address mark missing. || 1 | Not writable - disc is write protected. || 2 | No data - can't find the sector. || 3 | Drive not ready - no disc in the drive. || 4 | Overrun error. || 5 | Data error - CRC error. || 6 | Always set to 1 to indicate error from disc controller. || 7 | Set to 1 if error has already been reported by AMSDOS. |===============================================================================</pre>==== <code><big>EOF</big></code> ====: ''BASIC 1.1'': '''FUNCTION''': Checks to see if end of specified file has been reached during input. Returns 0 (false) until the end of file, then -1 (true).
: '''Associated keywords''': OPENIN, CLOSEIN
: This '''example ''' reads a file from disc and print it out on screen. Like the "TYPE" command in CP/M or "|TYPE,file" of the UTOPIA-ROM.
<pre>
10 OPENIN "text.txt"
60 CLOSEIN
</pre>
==== <code><big>ERR</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Reports the number of the last ERRor encountered. See the table below of error messages. In the example below you will see that ERRor number 8 is a 'Line does not exist' error.
: '''Example''':<pre>GOTO 500Line does not existReadyPRINT ERR 8</pre>: NOTE: BASIC 1.0 (officially) describes error codes until 30 (without an attached floppy disc controller). 31 & 32 are floppy disc error codes.: '''Table of ERRor codes''':<pre>==== ====================================================================================| VALUE | NAME | DESCRIPTION |========================================================================================| 1 |Unexpected NEXT |A NEXT command has been encountered while not in a || | |FOR loop, or the control variable in the NEXT || | |command does not match that in the FOR. || 2 |Syntax Error |BASIC cannot understand the given line because || | |a construct within it is not legal. || 3 |Unexpected RETURN |A RETURN command has been encountered when not in a || | |subroutine. || 4 |DATA exhausted |A READ command has attempted to read beyond the end || | |of the last DATA. || 5 |Improper Argument |This is a general purpose error. The value of a || | |function's argument, or a command parameter is || | |invalid in some way. || 6 |Overflow |The result of an arithmetic operation has over- || | |flowed. This may be a floating point overflow, in || | |which case some operation has yielded a value || | |greater than 1.7E^38 (approx.). Alternatively, this || | |may be the result of a failed attempt to change a || | |floating point number to a 16 bit signed integer. || 7 |Memory full |The current program or its variables may be simply || | |too big, or the control structure is too deeply || | |nested (nested GOUSBs, WHILEs or FORs). || | |A MEMORY command will give this error if an attempt || | |is made to set the top of BASIC's memory too low, or|| | |to an impossible high value. Note that an open file || | |has a buffer allocated to it, and that may restrict || | |the values that MEMORY may use. || 8 |Line does not exist |The line referenced cannot be found. || 9 |Subcript out of range |One of the subscripts in an array reference is too || | |big or too small. || 10 |Array already dimensioned|One of the arrays in a DIM statement has already || | |been declared. || 11 |Division by zero |May occur in real division, integer division, || | |integer modulus or exponentiation. || 12 |Invalid direct command |The last command attempted is not valid in direct || | |mode. || 13 |Type mismatch |A numeric value has been presented where a string || | |value is required or vice versa, or an invalidly || | |formed number has been found in READ or INPUT. || 14 |String space full |So many strings have been created that there is no || | |further room available, even after 'garbage || | |collection'. || 15 |String too long |Strings exceeds 255 characters in length. May be || | |generated by appending strings together. || 16 |String expression too |String expressions may generate a number of || |complex |intermediate string values. When the number of these|| | |values exceeds a reasonable limit, this error || | |results. || 17 |Cannot CONTinue |For one reason or another the current program || | |be restarted using CONT. Note that CONT is intended || | |for restarting after a STOP command, [ESC][ESC], || | |or an error, and that any alteration of the || | |program in the meantime makes a restart impossible. || 18 |Unknown user function |No DEF FN has been executed for the FN just || | |invoked. || 19 |RESUME missing |The end of the program has been encountered while || | |in error processing mode (i.e. in an ON ERROR GOTO || | |routine). || 20 |Unexpected RESUME |RESUME is only valid while in error processing mode || | |(i.e. in an ON ERROR GOTO routine). || 21 |Direct command found |When loading a file, a line without a line number || | |has been found. || 22 |Operand missing |BASIC has encountered an incomplete expression. || 23 |Line too long |A line when converted to BASIC internal-form becomes|| | |too big. || 24 |EOF met |An attempt has been made to read past end of the || | |file input stream. || 25 |File type error |The file being read is not of a suitable type. || | |OPENIN is only prepared to open ASCII text files. || | |Similarly, LOAD, RUN, etc, are only prepared to || | |deal with file types produces by SAVE. || 26 |NEXT missing |Cannot find a NEXT to match a FOR command. A line || | |number accompanying this message indicates the FOR || | |command to which this error applies. || 27 |File already open |An OPENIN or OPENOUT command has been executed || | |before the previously opened file has been closed. || 28 |Unknown command |BASIC cannot find a taker for an external command, || | |i.e. a command preceded by a bar |. || 29 |WEND missing |Cannot find a WEND to match a WHILE command. || 30 |Unexpected WEND |Encountered a WEND when not in a WHILE loop, or a || | |WEND that does not match the current WHILE loop. || 31 |File not open |(see 'Disc ERRors above). || | |If access attempted when no file was open. || 32 |Broken in |(see 'Disc ERRors above). || | |If access attempted when no file was open. || | | || | |If value 31 or 32 are stated, DERR could be || | |interrogate to give more detailed information. || | |(see example below.) |========================================================================================<code/pre>: '''Example for ERR31 / 32''':<pre>10 ON ERROR GOTO 100020 OPENOUT "myfile.asc"30 WRITE #9,"test-data"40 CLOSEOUT50 END1000 amsdoserr=(DERR AND &7F):REM mask off bit 71010 IF ERR<31 THEN END1020 IF ERR=31 THEN PRINT "are you sure you've typed line 20 correctly?":END1030 IF amsdoserr=20 THEN PRINT "disc is full, suggest you use a new data disc":END1040 IF amsdoserr=&X01001000 THEN PRINT "put a disc in the drive, then press a key":WHILE INKEY$="":WEND:RESUME1050 END</pre>==== <code><big>EXP (<integer expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Calculates 'E' to the power given in the <numeric expression> (i), where 'E' is approximately 2,7182818-the number whose natural logarithm is 1.
: Returns the error code number of the last error encountered.'''Associated keywords''': LOG
: '''Example''':<pre>PRINT EXP(6.876) 968.743625</pre>==== <code>EXP <big>FIX (i<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Unlike CINT, FIX merely removes the part of the numeric expression, to the right of the decimal point, and leaves an integer result, rounding towards zero.
: Returns the result of calculating e to the power i. : Example'''Associated keywords''':CINT, INT, ROUND
: '''Example''':
<pre>
PRINT EXPFIX(1) - prints 29.7182818399999) 9
</pre>
==== <code><big>FRE (<numeric expression>/<string expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Establishes how much FREe memory remains unused by BASIC. The form FRE("") forces a 'GARBAGE COLLECTION' before returning a value for available space.
: NOTE: BASIC uses only the first 64K of the memory.
==== <code>FIX (n)</code> ====: '''Associated keywords''': HIMEM, MEMORY
: Removes '''Examples''':<pre>PRINT FRE(0) or PRINT FRE("hello")PRINT FRE("")</pre>==== <code><big>HEX$ (<unsigned integer expression>, <field width>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Produces a $tring of HEXadecimal digits representing the fractional part value of n the <unsigned integer expression>, using the number of hexadecimal digits instructed by the <field width> (see INTin the range 0 to 16). If the number of digits instructed is too great, the resulting expression will be filled with leading zeros; if the number of digits instructed is too small, the resulting expression will NOT be shortened to the instructed number of digits, but will be produced in as many digits as are required.: The <unsigned integer expression> to be converted into hexadecimal form must yield a value in the range -32768 to 65535.
==== <code>FRE (n/se)</code> ====: '''Accociated keywords''': BIN$, DEC$, STR$, UNT
: '''Example''':<pre>PRINT HEX$(255,4)00FF</pre>==== <code><big>HIMEM</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns the amount address of unused memory, irrespective the Highest byte of Memory use by BASIC, (which may altered by e.g. the nature or value MEMROY command).: Before resetting the highest byte of available memory using the dummy argument inside MEMORY command, it is advisable to issue the bracket'command mm=HIMEM'. You will thereafter be able to return to the previous memory capacity by issuing the command: 'MEMORY mm': NOTE: BASIC uses only the first 64K of memory.
: ExamplesAssociated keywords:FRE, MEMORY, SYMBOL, SYMBOL AFTER.
: '''Example''':
...on a CPC464
<pre>
PRINT FRE(o) or PRINT FRE("hello")HIMEM43903
</pre>
...on a CPC6128
<pre>
PRINT HIMEM
42619
</pre>
==== <code><big>INKEY (<integer expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': INterrogates the KEYboard to report which keys are being pressed. The keyboard is scanned every 0.02 (1/50) second.
: The function is useful for spotting whether a certain key is down or up, by detecting the returned value of -1 (which occurs regardless of [SHIFT] and [CONTROL] key status).
: The example below detects when [SHIFT] and V (key number 55) are pressed together, then ends the program. Refer the manual for the key numbers.
==== <code>HEX: '''Associated keywords''': CLEAR INPUT, INKEY$ (i1, i2)</code> ====JOY
: Returns a string hexadecimal digit representation of i1 '''Example''':<pre>10 IF INKEY(0-6553555). <>32 THEN 1020 PRINT "You've pressed [SHIFT] and V"30 CLEAR INPUTrun</pre>: The number state of hex digits [SHIFT] and [CONTROL] in conjunction with the string key specified in the <integer expression> is given by i2 (0identified as follows:<pre>==============================================================================|Value returned |[SHIFT] |[CTRL] |Specified key |==============================================================================|-15)1 |ignored |ignored |up ||0 |up |up |down ||32 |down |up |down ||128 |up |down |down ||160 |down |down |down |==============================================================================</pre>==== <code><big>INKEY$</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': INterrogates the KEYboard, returning the current $tring reflecting any key that is pressed. It provides operator interaction without hitting [ENTER] after every answer. If there is a key pressed, then the function responds. If no key is pressed, INKEY$ returns an empty string.: In the example below, lines 40 and 70 tell the program to loop back to line 30 after interrogating the keyboard string.
==== <code>HIMEM</code> ==== : Returns address of the highest memory address used by BASIC. ==== <code>INKEY (i)</code> ===='''Associated keywords''': Checks to see if key number i is being pressed.CLEAR INPUT, INKEY
: '''Example''':
<pre>
Value returned [SHIFT] [CTRL] Specified key10 CLS-1 ignored ignored up20 PRINT "Select Yes or No (Y/N)?"0 up up down30 a$=INKEY$32 down up down40 IF a$="" THEN 30128 up down down50 IF a$="y" OR a$="Y" THEN 80160 down down down60 IF a$="N" OR a$="n" THEN 9070 GOTO 3080 PRINT "You have selected YES": END90 PRINT "You have selected NO":run
</pre>
==== <code><big>INP (‹port number›)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the INPut value from the I/O address specified in the <port number>.
==== <code>INKEY$</code> ====: '''Associated keywords''': OUT, WAIT
: Checkts the keyboard and returns the string character of the key pressedWatch out http://cpcwiki. The string character returned is normally assigned to a string variable. If no key pressed, a null string is returnedeu/index.php/I/O_Port_Summary
: '''Example''':<pre>PRINT INP(&FF00)255Ready</pre>==== <code>INP <big>INSTR (add[‹startposition›,]‹searched string›, ‹searched for string›)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Searches the first <searched string> expression to find the first occurance of the <searched for string expression<, and reports the position of its occurance within the <searched string>. If the <searched for string> does not occur within the <searched string>, then 0 is reported.: The position at which to start searching the <searched string> is optionally specifiable using the <start position> parameter which must yield an integer number in the range 1 to 255.
: Returns value read from the I/O address add ==== <code>INSTR</code> ==== :INSTR ([startposition,]explored string, seeking string)<blockquote>This function looks inside "explored string" after "seeking string" and return a number where the found string appear for the first time. Returns zero if not successfull. Startposition could be a figure between 1 and 255. </blockquote><pre>a$="ABCD":PRINT INTR(a$,"C") - returns with "3"</pre> ==== <code>INT (n)</code> ==== : As in FIX if n is positive; if n is negative, it rounds it down. : Example'''Associated keywords''':none
: '''1. Example''':
<pre>
a$="ABCD":PRINT INTINSTR(3.99)a$, INT(-3.99"C") - prints 3 -4Ready
</pre>
: '''2. Example''':
<pre>
a$="Hello":IF INSTR(a$,"i")<>0 THEN PRINT "no" else a$
no
Ready
</pre>
: '''3. Example''':
<pre>
10 CLS
20 alphabet$="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
30 INPUT "Enter a letter";a$
40 b$=UPPER$(a$)
50 PRINT b$;" is number";
60 PRINT INSTR(alphabet$,b$);
70 PRINT "in the alphabet.":PRINT
80 GOTO 40
run
</pre>
==== <code><big>INT (<numeric expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Rounds the number to the nearest smaller INTeger, removing any fractional part. Returns then same value as FIX for positive number, but returns one less than FIX for negative numbers which are not already integers.
==== <code>JOY (i)</code> ==== : Returns bit-significant value from specified joystick. i = 0 or 1.'''Associated keyword''': CINT, FIX, ROUND
: '''Example''':
<pre>
Bit Value returned0PRINT INT(up3.99) 11, INT(down-3.99) 22(left) 43(right) 8 -4(fire 2) 165(fire 1) 32
</pre>
==== <code><big>JOY (<integer expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': The JOY function reads a bit significant result from the joystick in the <integer expression> (either 0 or 1).
<pre>
================================
|Bit | Value decimal |
================================
|0(up) | 1 |
|1(down) | 2 |
|2(left) | 4 |
|3(right) | 8 |
|4(fire 2) | 16 |
|5(fire 1) | 32 |
================================
</pre>
==== <code><big>LEFT$ (<string expression>, <required length>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the number of characters (in the range 0 to 255) specified in the <required length> parameter (<integer expression>), after extracting them from the LEFT of the <string expression>. If the <string expression> is shorter than the <required length>, the whole <string expression> is returned.
==== <code>LEFT$ (se, i)</code> ==== : Returns a substring of se. The substring begins at the left-most character of se and contains i characters. : Example'''Associated keywords''':MID$, RIGHT$
: '''1. Example''':
<pre>
A$="ABCDEFG":PRINT LEFT$(A$,3) - prints ABC
</pre>
: '''2. Example''':
<pre>
10 CLS
20 a$="AMSTRAD"
30 FOR n=1 to 7
40 PRINT LEFT$(a$,n)
50 NEXT
run
</pre>
==== <code><big>LEN (<string expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the total number of characters (i.e. the LENgth) of the <string expression>.
==== <code>LEN (se)</code> ====: '''Associated keywords''': none
: Returns the number of '''Example''':<pre>10 LINE INPUT "Enter a phrase";a$20 PRINT "The phrase is";30 PRINT LEN(a$);"characters in se long."run</pre>==== <code><big>LOG (<numeric expression>)</big></code> ====: ''BASIC 1.0 - 255& 1.1'': '''FUNCTION''': Calculates the natural LOGarithm (base of ''e'')of <numeric expression> which mustbe greater than zero.
==== <code>LOG (n)</code> ====: '''Associated keywords''': EXP, LOG10
: '''Example''':<pre>PRINT LOG(9999) 9.21024037</pre>==== <code><big>LOG10 (<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns the natural logarithm (to base e) 10 of n<numeric expression> which must be greater than zero.
==== <code>LOG10 (n)</code> ====: '''Associated keywords''': EXP, LOG
: '''Example''':<pre>PRINT LOG10(9999) 3.99995657</pre>==== <code><big>LOWER$ (<string expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns a new string expression which is a copy of the logarithm specified <string expression> but in which all alphabetic characters in the range A to base 10 of nZ are converted to lower case. Useful for processing input where the answers may come in mixed upper/lower case.
==== <code>LOWER: '''Associated keywords''': UPPER$ (se)</code> ====
: Returns '''1. Example''':<pre>A$="AMSTRAD":PRINT A$="AMSTRAD":PRINT LOWER$(A$)Amstrad</pre>: '''2. Example''':<pre>10 a copy of se in which all alphabetical characters are converted to lower case $="SEE HOW THE LETTERS CHANGE TO ... NUMBERS 1234 NOT..."20 PRINT LOWER$(a$+"LOWER CASE") see also UPPERhow the letters change to ... numbers 1234 not... LOWER CASE</pre>==== <code><big>MAX (<list of: numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns the MAXimum value from the <list of: numeric expression>s.
: Example'''Associated keywords''': MIN
: '''Example''':
<pre>
10 n=6620 PRINT LOWER$MAX("A1B2c3"1,n,3,6,4,3) - print a1b2c3run 66
</pre>
==== <code><big>MIN (<list of: numeric expression>)</big></code> ====
''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the MINimum value from the <list of: numeric expression>s.
: '''Associated keywords''': MAX
==== : '''Example''':<codepre>MAX PRINT MIN (list of n3,6,2.999.8,9,) 2.999</codepre> ====
==== <code><big>PEEK (<address expression>)</big></code> ====: Returns ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the maximum value from contents of the given listZ80 memory location specified in the <address expression> which should be in the range &0000 to &FFFF (0 to 65535).In all cases PEEK will return the value at the RAM address specified (not the ROM), and will be in the range &00 to &FF (0 to 255)
: Example'''Associated keywords''':POKE
: '''Example''':
<pre>
PRINT MAX(310 MODE 1: ZONE 720 WINDOW 1,840,1,2:WINDOW #1,1,40,3,2530 PRINT "memory-address"40 LOCATE 20,1:PRINT "memory-contents"50 FOR n=1 to 6553560 p=PEEK(n)70 PRINT #1,2n,9"(&";HEX$(n) - prints 25;")";80 PRINT #1,TAB(20);p,"(&";HEX$(p);")"90 NEXTrun
</pre>
==== <code><big>PI</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': The value of the ratio between the circumference and the diameter of a circle.
==== <code>MIN (list of n)</code> ====: '''Associated keywords''': DEG, RAD
: Returns '''Example''':<pre>PRINT PI 3.14159265</pre>==== <code><big>POS (#<stream expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the minimum value from current horizontal POSition of the given list text cursor relative to the left edge of the text window. The <stream expression> MUST be specified, and does NOT default to #0.: POS(see MAX#8)reports the current horizontal carriage position for the printer, where 1 is the extreme left hand edge.: POS(#9) reports the logical position in the disc file stream, i.e. the number of printing characters sent to the stream since the last carriage return.
: '''Associated keywords''': VPOS, WINDOW: '''Example''':<pre>10 MODE 1: BORDER 0:LOCATE 8,220 PRINT "use cursor left/right keys"30 WINDOW 1,40,12,12:CURSOR 1,140 FOR n=1 TO 19:PRINT CHR$(9);:NEXT50 IF INKEY(1)<>-1 THEN PRINT CHR$(9);60 IF INKEY(8)<>-1 THEN PRINT CHR$(8);70 LOCATE #1,2,2480 PRINT #1,"text cursor ";90 PRINT #1,"horizontal position = ";100 PRINT #1,POS(#0):GOTO 50run</pre>==== <code>PEEK <big>REMAIN (add<integer expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns count REMAINing count from the delay timer specified in <integer expression> (= timer number in the range 0 to 3), and disable it. If the delay timer was not enabled zero will be returned.
: Returns the contents of the specified memory location (0-65535)'''Associated keywords''': AFTER, DI, EI, EVERY
: For the reason that REMAIN is no normal command but a "function" it is necessary in case of a proper functionality to link the command.: an '''example''' in combination with an interrupt delay timer 1:<pre>PRINT REMAIN(1)</pre>: or to stop several/all interrupts at the same time...<pre>A=REMAIN(0)=REMAIN(1)=REMAIN(2)=REMAIN(3)</pre>: Hint: Take care of interrupts due to parallel working (the same cycle time) or if they are stopped with the BREAK key. Interrupts which were disabled for a certain time will be stored in buffer (for a maximum of 128 entries) and made up their task afterwards in the priorisation as declared.: further '''example''':<pre>10 AFTER 500,1 GOSUB 4020 AFTER 100,2 GOSUB 5030 PRINT "program running":GOTO 3040 REM this GOUSB-Routine will not be called as it is disabled in line 8050 PRINT:PRINT "Timer 1 will now be ";60 PRINT "disabled by REMAIN."70 PRINT "Time-units remaining were:";80 PRINT REMAIN(1)run</pre>==== <code>PI<big>RIGHT$ (<string expression>, <integer expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns the number of characters (in the range 0 to 255) specified in the <integer expression> (=required length) parameter, after extracting them from the RIGHT of the <string expression>. If the <string expression> is shorter than the <integer expression>, the whole <string expression> is returned.
: Returns value of PI (3.14159265)'''Associated keywords''': LEFT$, MID$
: '''Example''':<pre>10 MODE 1:a$="AMSTRAD computer"20 FOR n=1 TO 16:LOCATE 41-n,n30 PRINT RIGHT$(a$,n)40 NEXT</pre>==== <code>POS <big>RND [(#st<numeric expression>)]</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns the next RaNDom number in sequence if the <numeric expression> has a positive value or is not specified. : If the <numeric expression> yields a value of zero, RND returns a copy of the last random number generated.: If the <numeric expression> yields a negative value, a new random number sequence is started, the first number of which is returned.
: Returns column number of print position relative to left edge of text window on stream st. st must be specified. : Example'''Associated keywords''':RANDOMIZE
: '''1. Example''':
<pre>
PRINT POSRND(#0) 0.536703827ReadyPRINT RND(1) 0.271940658ReadyPRINT RND(0) 0.271940658Ready</pre>: '''2. Example''':: Example for generating an integer random number between 1 and 1000<pre>10 A=INT((RND(1)*1000)+1)20 PRINT A30 GOTO 10</pre>: '''3. Example''': : For generating a random number between a lower and higher border<pre>10 INPUT "Low border",low20 INPUT "High border",high30 A=INT(RND(1)*(high- prints low))+low40 PRINT A</pre>: '''4. Example''':<pre>10 RANDOMIZE20 FOR x=1TO -1 STEP -130 PRINT "rnd parameter=";x40 FOR n=1 TO 650 PRINT RND(x)60 NEXT n,xrun
</pre>
==== <code>REMAIN <big>ROUND (i<numeric expression>[,<integer expression>])</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Rounds <numeric expression> to a number of decimal places or to the power of ten specified by <integer expression>. If <integer expression> less than zero, the <numeric expression> is rounded to give an absolute integer with <integer expression> number of zeros before the decimal point.
: Returns count remaining in delay timer i '''Associated keywords''': ABS, CINT, FIX, INT: '''1. Example''':<pre>PRINT ROUND(01562.357,2),ROUND(1562.375,-32) then disables it 1562.36 1600</pre>: '''2. Example''':<pre>10 FOR n=4 TO -4 STEP -120 PRINT ROUND (1234.5678,n)30 PRINT "with integer expression";n40 NEXTrun</pre>==== <code><big>SGN (<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': FUNCTION: Determines the SiGN of the <numeric expression>. Returns -1 if <numeric expression> is less than 0, returns 0 if <numeric expression> = 0, and returns 1 if <numeric expression> is greater than zero.
==== <code>RIGHT$ (se,i)</code> ====: '''Associated keywords''': ABS
: Returns '''Example''':<pre>10 FOR n=255 to -200 STEP -2020 PRINT "SGN returns";30 PRINT SGN(n);"for a substring value of length i ";n40 NEXT nrun</pre>==== <code><big>SIN (0-255<numeric expression>) characters from se, ending at </big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Calculates the rightmost character Real value for the Sine of se<numeric expression>, defaulting to the Radian (RAD) measure mode unless otherwise declared by a DEG command.
: Example'''Associated keywords''': ATN, COS, DEG, RAD, TAN
: '''Example''':
<pre>
PRINT RIGHT$("ABCDEFG"10 CLS:DEG:ORIGIN 0,32020 FOR n=0 to 72030 y=SIN(n) - prints EFG40 PLOT n*640/720,198*y:NEXT50 GOTO 50run
</pre>
==== <code><big>SPACE$(<integer expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Creates a string of spaces of the given length, (in the range 0 to 255) specified in the <integer expression>.
==== <code>RND [(n)]</code> ====: Generates the next random number in the current squence if n is positive or omitted. If n = 0'''Associated keywords''': SPC, STRING$, the random number generated will be the same as the last random number generated.TAB
: '''Example''':<pre>10 MODE 120 PRINT "Put 9 spaces between me";30 PRINT SPACE$(9);40 PRINT "and you!"run</pre>==== <code>ROUND <big>SQ (n[,i1]<channel>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the state of the Sound Queue for the specified <channel> which must be an integer expression, yielding one the values:: 1: for channel A: 2: for channel B: 4: for channel C: The SQ function returns a bit significant integer, comprising the following bit settings:: Bit 0,1 and 2: the number of free entries in the queue: Bit 3,4 and 5: the rendezvous state at the head of this queue: Bit 6 : the head of the queue is held: Bit 7 : the channel is currently active: ... where Bit 0 is the least significant bit, and Bit 7 is the most significant bit.: It can be seen, that if Bit 6 is set, Bit 7 cannot be set at the same time, and vice versa. Similarly if Bits 3, 4, or 5 are set, Bit 6 and 7 cannot be set.
: Rounds n to a number of decimal places or to the power of ten specified by i. If i is negative'''Associated keywords''': ON SQ GOSUB, the n is rounded to give an absolute integer with i zeros before the decimal point.: Example:SOUND
: '''Example''':
<pre>
PRINT ROUND(1562.35710 SOUND 65,2):100,10020 PRINT ROUNDSQ(1562.375,-21) - prints 1562.36 1600run 67
</pre>
==== <code><big>SQR (<numeric expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the SQuare Root of the specified <numeric expression>.
==== <code>SGN (n)</code> ====: Returns 1 if n is positive, 0 if n = 0, -1 if n is negative.'''Associated keywords''': none
: '''Example''':<pre>PRINT SQR(9) 3</pre>==== <code>SIN <big>STR$ (n<numeric expression>)</big></code> ====: Returns sine ''BASIC 1.0 & 1.1'': '''FUNCTION''': Converts the <numeric expression> to a decimal STRing representation.: Useful for converting a number to a string in case of n string manipulation. E.g. after converting a figure to a string then the most left character holds the sign: a minus in degree or radian mode (see DEG case the figure is negative and RAD)a space in case the figure is positiv.
==== <code>SPACE: '''Associated keywords''': BIN$(i)</code> ====, DEC$, HEX$, VAL
: Creates a string containing i spaces '''1. Example''':<pre>10 FIGURE=-159920 FIGURE$=STR$(0FIGURE)30 PRINT FIGURE$-2551599</pre>: '''2. Example''':<pre>10 FIGURE=176920 FIGURE$=STR$(FIGURE)30 PRINT FIGURE$ 1769</pre>: '''NOTE''': (there's a blank on the left-hand of the number "1769"): If you want to add e.g. zero before the figure in case of a high score with fix digit-number then you're able to add zero(s) in front of a string instead of a figure.
==== <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.Example''':
<pre>
Bits 0,1 and 2 number of free entries in the queue10 a=&FF:REM 255 hexBits 3,4 and 5 redezvous state at head of the queue20 b=&x1111:REM 15 binaryBit 6 head of the queue is held30 c$="***"Bit 7 channel is currently active40 PRINT c$+SR$(a+b)+c$run*** 270***
</pre>
==== <code><big>STRING$ (<length>,<character specifier>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns a string expression consisting of the <character specifier> repeated the number of time (in the range 0 to 255) specified in the <length>.
==== <code>SQR (n)</code> ====: Returns the square root of n.'''Associated keywords''': SPACE$
: '''1. Example''':<pre>PRINT STRING$(40,"*")****************************************</pre>: '''2. Example''':<pre>PRINT STRING(40,42)****************************************</pre>: '''NOTE''': the <character specifier> 42 refers to the ASCII value of the character '*' and is also equivalent to PRINT STRING$(40,CHR$(42))==== <code>STR$<big>TAN (n<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Calculates the TANgent of the <numeric expression>, which must be in the range -200,000 to +200,000.: '''NOTE''': DEG and RAD can be used to force the result of the calculation to degrees or radians respectively.
: Returns the string representation of number n.'''Associated keywords''': ATN, COS, DEG, RAD, SIN
==== : '''Example''': <codepre>STRING$PRINT TAN(45) 1.61977519</codepre> ====
==== <code><big>TEST (<x co-ordinate>,<y co-ordinate>)</big></code> ====: Returns i copies of ''BASIC 1.0 & 1.1'': '''FUNCTION''': Moves the string character graphics cursor to the absolute position specified by the <x> and <y co-ordinate>s, and reports the value of the ink at the new location.
: Example'''Associated keywords''':MOVE, MOVER, TESTR, XPOS, YPOS
: '''Example''':
<pre>
10 CLS20 PRINT STRING$"Your are using pen number";30 PRINT TEST(310,386)40 PRINT "*Try changing PENs and MODEs") - prints ***;50 PRINT "....then RUN again."run
</pre>
==== <code><big>TESTR (<x offset>,<y offset>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Moves the graphics cursor by the amount specified in the <x> and <y offset>s relative to its current position, and reports the value of the ink at the new location.
==== <code>TAN (n)</code> ====: '''Associated keywords''': MOVE, MOVER, TEST, XPOS, YPOS
: Returns the tangent of '''Example''':<pre>10 MODE 0:FOR x=1 TO 15:LOCATE 1,x20 PEN x:PRINT STRING$(10,143);:NEXT30 MOVE 200,400:PEN 140 FOR n=1 TO 23:LOCATE 12,n50 PRINT "pen";TESTR(0,-16):NEXTrun</pre>==== <code><big>TIME</big></code> ====: ''BASIC 1. The DEG and RAD commands can be used to force 0 & 1.1'': '''FUNCTION''': Reports the result elapsed time since the computer was last switched-on or reset, (excluding periods when reading or writing to either modedisc).: Each second of real time is equal to the returned value = TIME/300.
==== <code>TEST (x: '''Associated keyword''': AFTER,y)</code> ====EVERY, WEND, WHILE
: Moves '''Example''':<pre>10 CLS:REM clock20 INPUT "hour";hour30 INPUT "minute";minute40 INPUT "second";second50 CLS:datum=INT(TIME/300)60 WHILE hour<1370 WHILE minute<6080 WHILE tick<6090 tick=(INT(TIME/300)-datum)+second100 LOCATE 1,1110 PRINT USING "## ";hour,minute,tick120 WEND130 tick=0:second=0:minute=minute+1140 GOTO 50150 WEND160 minute=0:hour=hour+1170 WEND180 hour=1190 GOTO 60run</pre>==== <code><big>UNT (<address expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Return an integer in the graphics cursor by x and y and returns range -32768 to +32767 which is the twos-complement equivalent of the unsigned value of the ink at that position<address expression>.
==== <code>TESTR (x: '''Associated keywords''': CINT,y)</code> ====FIX, INT, ROUND
: Moves '''Example''':<pre>PRINT UNT(&FF66)-154</pre>==== <code><big>UPPER$(<string expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns a new string expression which is a copy of the graphics cursor by x and y relative to its current position and returns specified <string expression> but in which all alphabetic characters in the value of ink at that positionrange A to Z are converted to upper case. The function is useful for processing input which may come in mixed upper / lower case.
==== <code>TIME</code> ====: Returns time elapsed since the computer was switched on or reset.'''Associated keywords''': One second = TIME/300.LOWER$
: '''Example''':<pre>10 CLS: a$="my, how you've grown!"20 PRINT UPPER$(a$)run</pre>==== <code>UNT <big>VAL(add<string expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns the numeric VALue, (including any negative sign and decimal point) of the first character(s) in the specified <string expression>. :If the first character is not a number, then 0 is returned. If the first character is a negative sign or decimal point followed by non-numeric characters, a 'Type mismatch' error (13) will be reported.
: Returns an integer(-32768 to 32767) which is the two's complement of add. : Example''Associated keywords''':STR$
: '''1. Example''':
<pre>
PRINT UNTVAL(&FF66"-12.34x") ,VAL("A- prints 12") -15412.34 0
</pre>
: '''Exception''': if <se> starts with "&amp;" + character (and it's between "A" and "F") the whole character will be handled like a hexadezimal numeric character (...often used in DATA Loaders). The returning numeric value is a &nbsp;signed&nbsp;integer (16-Bit Word).
: '''2. Example''':
<pre>
PRINT VAL("&amp;A")
10
==== <code>UPPER$PRINT VAL(se"&amp;7FFF")</code> ==== 32767
PRINT VAL("&amp;8000") -32768</pre>: Gives copy '''3. Example''':<pre>10 CLS: PRINT "I know my times tables!"20 PRINT:PRINT "Press a key (1 to 9)"30 a$=INKEY$:IF a$="" THEN 3040 n=VAL(a$):if n<1 or n>9 then 3050 FOR x=1 to 1260 PRINT n;"X";x;"=";n*x70 NEXT:GOTO 20run</pre>==== <code><big>VPOS (#<stream expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the current vertical POSition of the text cursor relative to the top of se with all alphabetic characters in upper casethe text window. The <stream expression> MUST be specified, and does NOT default to #0.
==== <code>VAL(se)</code> ====: '''Associated keywords''': POS, WINDOW
:Returns the numeric value (including signs) of first numeric character(s) in se. Returns 0 if se starts with a non-number. :'''Example''':<pre>10 MODE 1:BORDER 0:LOCATE 8,220 PRINT VAL("-12.34xuse cursor up/down keys")30 WINDOW 39,VAL39,1,25:CURSOR 1,140 LOCATE 1,350 IF INKEY("A0)<>-12"1 THEN PRINT CHR$(11) ;60 IF INKEY(2)<>- prints -12.34 1 THEN PRINT CHR$(10);70 LOCATE #1,3,2480 PRINT #1,"text cursor ";90 PRINT #1,"vertical position =";100 PRINT #1,VPOS(#0):GOTO 50run
</pre>
:Exception: if ==== <secode> starts with "&amp;" + character (and it<big>XPOS</big></code> ====: 's between "A" and "F") the whole character will be handled like a hexadezimal numeric character ('BASIC 1...often used in DATA Loaders). The returning numeric value is a &nbsp;signed0 &nbsp;integer (16-Bit Word)1. 1''<pre>PRINT&nbsp;VAL: '''FUNCTION''': Reports the current horizontal ("&amp;A"X) - returns a 10POSition of the graphics cursor.
PRINT&nbsp;VAL("&amp;7FFF") - returns a 32767: '''Associated keywords''': MOVE, MOVER, ORIGIN, YPOS
: '''Example''':<pre>10 MODE 1:DRAW 320,20020 PRINT&nbsp;VAL("&amp;8000graphics cursor X position = ") - returns a -32768;30 PRINT XPOS</pre>==== <code><big>YPOS</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the current vertical (Y)POSition of the graphic cursor.
==== <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.'''Associated keywords''': MOVE, MOVER, ORIGIN, XPOS
==== : '''Example''':<codepre>XPOS</code> ====10 MODE 1:DRAW 320,200: Returns the current horizontal (x) position of the 20 PRINT "graphics cursor.Y position = ";30 PRINT YPOS==== <code>YPOS</codepre> ==== : Returns the current vertical (y) position of the graphics cursor.
''(Please, fill in. Looks like a lot of work ;-) ...)''
 
== Error codes ==
 
* 1 '''Unexpected NEXT''' - <code>NEXT</code> encountered without matching <code>FOR</code>.
* 2 '''Syntax Error''' - Typing error or incorrect punctuation.
* 3 '''Unexpected RETURN''' - <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 (e.g. <code>PRINT SQR(-10)</code>).
* 6 '''Overflow''' - The computer cannot handle integers smaller than -32768 (signed) or larger than 65535 (unsigned) or floating point numbers greater than &plusmn;1.7E38.
* 7 '''Memory full''' - Not enough free RAM available to complete the operation. Program 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 '''Subscript out of range''' - Value of a subscript in an array is outside of range specified by <code>DIM</code> declaration or wrong number of dimensions supplied.
* 10 '''Array already dimensioned''' - Arrays can only be <code>DIM</code>ensioned once within a program.
* 11 '''Division by zero''' - Trying to divide a number by zero.
* 12 '''Invalid direct command''' - Using a statement as a direct command which is not allowed outside a program, e.g. <code>DEF FN</code>.
* 13 '''Type mismatch''' - Wrong data type encountered, string data instead of numeric value or vice versa.
* 14 '''String space full''' - String memory area is full.
* 15 '''String too long''' - String may not exceed 256 characters.
* 16 '''String expression too complex''' - A string expression needs to be broken down into smaller expressions.
* 17 '''Cannot 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 '''RESUME missing''' - End of program has been reached while in error processing mode. Use <code>ON ERROR GOTO</code> before <code>RESUME</code>.
* 20 '''Unexpected 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 '''Operand missing''' - An incomplete expression has been found.
* 23 '''Line too long''' - The line contains 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 <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 '''Unexpected 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 <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 ==
*[[C BASIC Compiler|CBASIC]]
*[[BASIC-E]]
 
== Technical Information ==
 
* [[Technical_information_about_Locomotive_BASIC]]
== Web links ==
* [http://www.cpctech.org.uk/docs/bastech.html Technical information at the Unofficial Amstrad WWW Resource]
* [http://www.sean.co.uk/books/amstrad/bforbasic.shtm Locomotive Basic Tutorial by Sean McManus]
* [http://rosettacode.org/wiki/Category:Locomotive_Basic Code examples at Rosetta Code]
 
* [http://cpctech.cpc-live.com/docs/basic.asm Disassembly of Locomotive BASIC v1.1]
[[Category:Programming]]
897
edits