Changes

Jump to: navigation, search

Locomotive BASIC

9,386 bytes added, 20:45, 30 June 2021
/* MOD */
==== <code>LOAD ‹file name›[,‹address›] </code>====
: [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> ====
</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=(6562,000500/frequency)'''
: (e.g. the note "A" with the frequency 440 Hz has the period 142 on the CPC)
</pre>
==== <code>SPEED INK <n1,n2> </code> ====: ...in conjunction with the SPEED INK command SPEED 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> ====
: 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> ====
=== Functions ===
==== <code><big><big>ABS (n)</bignumeric expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the ABSolute value of the given numeric expression (n). This means that negative numbers are returned as positive.
</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).
120
</pre>
==== <code><big>ATN (n<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 the value specified.
0.785398163
</pre>
==== <code><big>BIN$ (i1<unsigned integer expression>,[i2<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.
01000000
</pre>
==== <code><big>CHR$ (n<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.
: '''Associated keywords''': ASC, LEFT$, RIGHT$, MID$, STR$
: '''Example''':
<pre>
10 FOR X=32 to 255
===============================================================================
</PRE>
 ==== <code><big>CINT (n<numeric expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the value of the <numeric expression> (n), Converting it to a rounded INTeger in the range -32768 to 32767.
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.
60 PRINT a$
</pre>
==== <code><big>COS (n<numeric expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Calculates the COSinus of the <numeric expression> (n).
0.707106781
</pre>
==== <code><big>CREAL (n<numeric expression>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the value of the <numeric expression> (n), Converting it to REAL.
3.14159265
</pre>
==== <code><big>DEC$(n<numeric expression>, <formattemplate>)</big></code> ====
: ''BASIC 1.1''
: '''FUNCTIION''': Returns a DECimal string representation of the <numeric expression> (n), using the specified <format template> to control the print format of the resulting string.
£10,000,000.00
</pre>
==== <code><big>DERR</big></code> ====
: ''BASIC 1.1''
: '''FUNCTION''': Reports the last error code returned by 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.
===============================================================================
</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).
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.
========================================================================================
</pre>
: '''Example for ERR 31 / 32''':
<pre>
10 ON ERROR GOTO 1000
1050 END
</pre>
==== <code><big>EXP (i<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.
968.743625
</pre>
==== <code><big>FIX (n<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.
9
</pre>
==== <code><big>FRE (n<numeric expression>/st<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.
PRINT FRE("")
</pre>
==== <code><big>HEX$ (i1<unsigned integer expression>, i2<field width>)</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Produces a $tring of HEXadecimal digits representing the value of the <unsigned integer expression>, using the number of hexadecimal digits instructed by the <field width> (in 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.
00FF
</pre>
==== <code><big>HIMEM</big></code> ====
: ''BASIC 1.0 & 1.1''
: '''FUNCTION''': Returns the address of the Highest byte of Memory use by BASIC, (which may altered by e.g. the MEMROY command).
42619
</pre>
==== <code><big>INKEY (i<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.
==============================================================================
</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.
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>.
Ready
</pre>
==== <code><big>INSTR ([‹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.
run
</pre>
==== <code><big>INT (n<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.
3 -4
</pre>
==== <code><big>JOY (i<integer expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': Returns '''FUNCTION''': The JOY function reads a bit-significant value result from specified the joystick. i = in the <integer expression> (either 0 or 1)
<pre>
================================|Bit | Value returneddecimal |================================|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 the minimum value from the given list (see MAX) ==== <code>PEEK (add)</code> ==== '''Example''': Returns the contents of the specified memory location (0-65535) ==== <codepre>PI</code> ==== : Returns value of PRINT PI ( 3.14159265)</pre>==== <code><big>POS (#st<stream expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': Returns column number '''FUNCTION''': Reports the current horizontal POSition of print position the text cursor relative to the left edge of the text window on stream st. st must The <stream expression> MUST be specified, and does NOT default to #0.: POS(#8) reports the current horizontal carriage position for the printer, where 1 is the extreme left hand edge.: Example: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) - prints 1:GOTO 50run
</pre>
==== <code><big>REMAIN (<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.
==== <code>REMAIN (i)</code> ====: '''Associated keywords''': AFTER, DI, EI, EVERY
: Returns count remaining in delay timer i (0-3) then disables it.
: 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.
: a 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 40
20 AFTER 100,2 GOSUB 50
30 PRINT "program running":GOTO 30
40 REM this GOUSB-Routine will not be called as it is disabled in line 80
50 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><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.
==== <code>RIGHT$ (se,i)</code> ==== : Returns a substring of length i (0-255) characters from se, ending at the rightmost character of se. '''Associated keywords''': ExampleLEFT$, MID$
: '''Example''':
<pre>
10 MODE 1:a$="AMSTRAD computer"20 FOR n=1 TO 16:LOCATE 41-n,n30 PRINT RIGHT$("ABCDEFG"a$,3n) - prints EFG40 NEXT
</pre>
==== <code><big>RND [(<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.
==== <code>RND [(n)]</code> ====: Generates the next random number between 0 and 1 (exklusiv) in the current squence if n is positive or omitted.'''Associated keywords''': RANDOMIZE
: If n = 0, the random number generated will be the same as the last random number generated'''1.: Example''':
<pre>
PRINT RND(0)
Ready
</pre>
: '''2. Example''':: Exampel Example for generating an integer random number between 1 and 1000
<pre>
10 A=INT((RND(1)*1000)+1)
30 GOTO 10
</pre>
: '''3. Example''': : Exampel for For generating a random number between a lower and higher border
<pre>
10 INPUT "Low border",low
30 A=INT(RND(1)*(high-low))+low
40 PRINT A
</pre>
: '''4. Example''':
<pre>
10 RANDOMIZE
20 FOR x=1 TO -1 STEP -1
30 PRINT "rnd parameter=";x
40 FOR n=1 TO 6
50 PRINT RND(x)
60 NEXT n,x
run
</pre>
==== <code><big>ROUND (n<numeric expression>[,i1<integer expression>])</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Rounds n <numeric expression> to a number of decimal places or to the power of ten specified by i<integer expression>. If i is negative<integer expression> less than zero, the n <numeric expression> is rounded to give an absolute integer with i <integer expression> number of zeros before the decimal point.: Example:
: '''Associated keywords''': ABS, CINT, FIX, INT
: '''1. Example''':
<pre>
PRINT ROUND(1562.357,2):PRINT ,ROUND(1562.375,-2) - prints 1562.36 1600
</pre>
: '''2. Example''':
<pre>
10 FOR n=4 TO -4 STEP -1
20 PRINT ROUND (1234.5678,n)
30 PRINT "with integer expression";n
40 NEXT
run
</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>SGN (n)</code> ====: Returns 1 if n is positive, 0 if n = 0, -1 if n is negative.'''Associated keywords''': ABS
: '''Example''':<pre>10 FOR n=255 to -200 STEP -2020 PRINT "SGN returns";30 PRINT SGN(n);"for a value of";n40 NEXT nrun</pre>==== <code><big>SIN (n<numeric expression>)</big></code> ====: Returns sine ''BASIC 1.0 & 1.1'': '''FUNCTION''': Calculates the Real value for the Sine of n in degree or radian mode <numeric expression>, defaulting to the Radian (see DEG and RAD)measure mode unless otherwise declared by a DEG command.
==== <code>SPACE$(i)</code> ====: '''Associated keywords''': ATN, COS, DEG, RAD, TAN
: '''Example''':<pre>10 CLS:DEG:ORIGIN 0,2020 FOR n=0 to 72030 y=SIN(n)40 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 containing i of spaces of the given length, (in the range 0-to 255)specified in the <integer expression>.
==== <code>SQ (channel)</code> ====: Returns a bit significant integer showing state of the sound queue for specified channel where channel 1'''Associated keywords''': SPC, 2STRING$, 3 = A, B, C.TAB : '''Example''':
<pre>
Bits 0,10 MODE 1 and 2 number of free entries in the queueBits 3,4 and 5 redezvous state at head of the queue20 PRINT "Put 9 spaces between me";Bit 6 head of the queue is held30 PRINT SPACE$(9);40 PRINT "and you!"Bit 7 channel is currently activerun
</pre>
==== <code><big>SQ (<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.
==== <code>SQR (n)</code> ====: Returns the square root of n.'''Associated keywords''': ON SQ GOSUB, SOUND
: '''Example''':<pre>10 SOUND 65,100,10020 PRINT SQ(1)run 67</pre>==== <code>STR$<big>SQR (n<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns the SQuare Root of the specified <numeric expression>.
: Returns '''Associated keywords''': none : '''Example''':<pre>PRINT SQR(9) 3</pre>==== <code><big>STR$ (<numeric expression>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Converts the string <numeric expression> to a decimal STRing representation of number n.
: Useful for converting a number to a string in case of string manipulation. E.g. after converting a figure to a string then the most left character holds the sign: a minus in case the figure is negative and a space in case the figure is positiv.
 : '''Associated keywords''': BIN$, DEC$, HEX$, VAL : '''1. Example''':
<pre>
10 FIGURE=-1599
30 PRINT FIGURE$
-1599
</pre>: '''2. Example''':<pre>
10 FIGURE=1769
20 FIGURE$=STR$(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.
: '''3. Example''':<pre>10 a=&FF:REM 255 hex20 b=&x1111:REM 15 binary30 c$="***"40 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>.
: Returns i copies of the string character specified by s.'''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><big>TAN (<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.
: '''Associated keywords''': ATN, COS, DEG, RAD, SIN
 
: '''Example''':
<pre>
PRINT STRING$TAN(3,"*"45) - prints *** 1.61977519
</pre>
==== <code>TAN <big>TEST (n<x co-ordinate>,<y co-ordinate>)</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Moves the 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.
: Returns the tangent of n. The DEG and RAD commands can be used to force the result to either mode.'''Associated keywords''': MOVE, MOVER, TESTR, XPOS, YPOS
: '''Example''':<pre>10 CLS20 PRINT "Your are using pen number";30 PRINT TEST(10,386)40 PRINT "Try changing PENs and MODEs";50 PRINT "....then RUN again."run</pre>==== <code>TEST <big>TESTR (<xoffset>,<yoffset>)</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.
: Moves the graphics cursor by x and y and returns the value of the ink at that position.'''Associated keywords''': MOVE, MOVER, TEST, XPOS, YPOS
: '''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>TESTR (x,y)<big>TIME</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the elapsed time since the computer was last switched-on or reset, (excluding periods when reading or writing to disc).: Each second of real time is equal to the returned value = TIME/300.
: Moves the graphics cursor by x and y relative to its current position and returns the value of ink at that position.'''Associated keyword''': AFTER, EVERY, WEND, WHILE
: '''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>TIME<big>UNT (<address expression>)</big></code> ====: Returns time elapsed since the computer was switched on or reset''BASIC 1.0 & 1.1'': One second = TIME/300'''FUNCTION''': Return an integer in the range -32768 to +32767 which is the twos-complement equivalent of the unsigned value of the <address expression>.
==== <code>UNT (add)</code> ====: '''Associated keywords''': CINT, FIX, INT, ROUND
: Returns an integer'''Example''':<pre>PRINT UNT(&FF66)-32768 to 32767154</pre>==== <code><big>UPPER$(<string expression>) </big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Returns a new string expression which is the two's complement a copy of addthe specified <string expression> but in which all alphabetic characters in the range A to Z are converted to upper case. The function is useful for processing input which may come in mixed upper / lower case.
: Example'''Associated keywords''':LOWER$
: '''Example''':
<pre>
10 CLS: a$="my, how you've grown!"20 PRINT UNTUPPER$(&FF66a$) - prints -154run
</pre>
==== <code><big>VAL(<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.
==== <code>UPPER: '''Associated keywords''': STR$(se)</code> ====
: Gives copy of '''1. Example''':<pre>PRINT VAL("-12.34x"),VAL("A-12") -12.34 0</pre>: '''Exception''': if <se > starts with all alphabetic characters "&amp;" + character (and it's between "A" and "F") the whole character will be handled like a hexadezimal numeric character (...often used in upper caseDATA Loaders). The returning numeric value is a &nbsp;signed&nbsp;integer (16-Bit Word). : '''2.Example''':<pre>PRINT VAL("&amp;A") 10
==== <code>PRINT VAL(se"&amp;7FFF")</code> ====32767
:Returns the numeric value (including signs) of first numeric character(s) in se. Returns 0 if se starts with a non-number. :Example:<pre>PRINT VAL("-12.34x&amp;8000"),VAL("A-12") - prints -12.34 032768
</pre>
:Exception'''3. Example''': if <sepre> starts with 10 CLS: PRINT "&amp;I know my times tables!" + character (and it's between "A20 PRINT:PRINT " and "F") the whole character will be handled like Press a hexadezimal numeric character key (...often used in DATA Loaders1 to 9). The returning numeric value is "30 a &nbsp;signed&nbsp;integer $=INKEY$:IF a$="" THEN 3040 n=VAL(16-Bit Worda$). :if n<pre1 or n>9 then 3050 FOR x=1 to 1260 PRINT&nbspn;VAL("&ampX";x;A"=";n*x70 NEXT:GOTO 20run</pre>==== <code><big>VPOS (#<stream expression>) - returns a 10</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the current vertical POSition of the text cursor relative to the top of the text window. The <stream expression> MUST be specified, and does NOT default to #0.
PRINT&nbsp;VAL("&amp;7FFF") - returns a 32767: '''Associated keywords''': POS, WINDOW
: '''Example''':<pre>10 MODE 1:BORDER 0:LOCATE 8,220 PRINT&nbsp"use cursor up/down keys"30 WINDOW 39,39,1,25:CURSOR 1,140 LOCATE 1,350 IF INKEY(0)<>-1 THEN PRINT CHR$(11);VAL60 IF INKEY(2)<>-1 THEN PRINT CHR$(10);70 LOCATE #1,3,2480 PRINT #1,"text cursor "&amp;800090 PRINT #1,"vertical position =";100 PRINT #1,VPOS(#0) - returns a -32768:GOTO 50run</pre>==== <code><big>XPOS</big></code> ====: ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the current horizontal (X)POSition of the graphics 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, YPOS
: '''Example''':<pre>10 MODE 1:DRAW 320,20020 PRINT "graphics cursor X position = ";30 PRINT XPOS</pre>==== <code>XPOS<big>YPOS</big></code> ====: Returns ''BASIC 1.0 & 1.1'': '''FUNCTION''': Reports the current horizontal vertical (xY) position POSition of the graphics graphic cursor.
==== <code>YPOS</code> ====: Returns the current vertical (y) position of the graphics cursor.'''Associated keywords''': MOVE, MOVER, ORIGIN, XPOS
==== <code>Error codes </code> ====# : '''Unexpected NEXTExample''' - <code>NEXT</code> encountered without matching <code>FOR</code>.:# '''Syntax Error''' - Typing error or incorrect punctuation.# '''Unexpected RETURN''' - <code>RETURN</code> encountered when there was no active <code>GOSUB</codepre>.# '''DATA exhaused''' - Trying to <code>READ</code> data when data pointer has reached end of data.# '''Improper argument''' - The argument for a function is not legal (e.g. <code>PRINT SQR(-10)</code>).# '''Overflow''' - The computer cannot handle integers smaller than -32768 (signed) or larger than 65535 (unsigned) or floating point numbers greater than &plusmn;MODE 1.7E38.# '''Memory full''' - Not enough free RAM available to complete the operation. Program too big or control structures too deeply nested.# '''Line does not exist''' - Attempt to <code>RUN</code>:DRAW 320, <code>GOTO</code> or <code>GOSUB</code> a non-existent line number.200# '''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.20 PRINT "graphics cursor Y position = ";# '''Array already dimensioned''' - Arrays can only be <code>DIM</code>ensioned once within a program.30 PRINT YPOS# '''Division by zero''' - Trying to divide a number by zero.# '''Invalid direct command''' - Using a statement as a direct command which is not allowed outside a program, e.g. <code>DEF FN</code>.# '''Type mismatch''' - Wrong data type encountered, string data instead of numeric value or vice versa.# '''String space full''' - String memory area is full.# '''String too long''' - String may not exceed 256 characters.# '''String expression too complex''' - A string expression needs to be broken down into smaller expressions.# '''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.# '''Unknown user function''' - A <code>DEF FN</code> must be executed before calling an <code>FN</code> function.# '''RESUME missing''' - End of program has been reached while in error processing mode. Use <code>ON ERROR GOTO</code> before <code>RESUME</code>.# '''Unexpected RESUME''' - <code>RESUME</code> is only used in error processing mode, <code>ON ERROR GOTO</code> statement must be used first.# '''Direct Command found''' - A line without a line number has found while loading a file.# '''Operand missing''' - An incomplete expression has been found.# '''Line too long''' - The line contains too many statements.# '''EOF met''' - Trying to input data beyond end of data file.# '''FILE type error''' - Using a program file instead of a data file to read or write (or vice versa).# '''NEXT missing''' - The <code>NEXT</code> of a <code>FOR</code> ... <code>NEXT</code> loop is missing.# '''File already open''' - Trying to open an open file. Use <code>CLOSEIN</code> or <code>CLOSEOUT</code> first.# '''Unknown command''' - Given when an unknown command follows a <code>|</code>. e.g. <code>|DISC</code> on a CPC464 without AMSDOS installed.# '''WEND missing''' - The <code>WEND</code> part of the <code>WHILE</code> ... <code>WEND</code> loop is missing.# '''Unexpected WEND''' - <code>WEND</code> encountered without a corresponding active <code>WHILE</code>.# '''File not open''' - Attempting to read from or write to a file without <code>OPEN</code>ing it first.# '''Broken in''' - During handling with files (read, write, change etc.) different problems could appear. BASIC reacts with Error code 32 due to it. You have to mask the DERR code with AND &7F (mask Bit 7) and compare the result with the following table to get explained what happened::Decimal (binary) number:*14 (0000 1110) Stream in an unclear condition*15 (0000 1111) reached End of File (hard eof*16 (0001 0000) > unknown command or filename*17 (0001 0001) > there's already a file existing with the same name*18 (0001 0010) > there's no file with that name*19 (0001 0011) > full directory20 (0001 0100) > full disc*21 (0001 0101) > disc was removed during reading*22 (0001 0110) > only readable*26 (0001 1010) > reached End of File (soft end):Does AMSDOS has already given out a failure then Bit 7 will be set. That means add 128 decimal to DERR code.* '''Unknown error''' - Executing <code>ERROR</codepre> command with any other legal error code number (up to 255).
== Other Basic Dialects available for the CPC ==
205
edits