Other BASICs

A wealth of programs written in BASIC can be found in other books and computing magazines, but there are many versions of BASIC, and it is unlikely that a program written to run on another computer will work on the ATOM without some changes. The extent and nature of the alterations needed will depend on the structure of the program, and how it handles data, as well as the particular dialect of BASIC used, so you should understand how the original program works before attempting to convert it to ATOM BASIC, and be prepared to alter the program and data structures if necessary.

The following paragraphs list the differences between ATOM BASIC and the major dialects found on other machines.

Multiple-statement lines

Some BASICs don't allow more than one statement on a line, thus

10 LET B=B+C
15 PRINT B

could be written for the ATOM as;

10 LET B=B+C;PRINT B

but take care that the 'deleted' line (line 15 in this example) is not the target of a GOTO or GOSUB.

More importantly, those versions of BASIC which do allow multiple statements on a line usually use ':' or '\' to separate the statements, rather than the ';' used by the ATOM. Thus;

10 A=2:B=3

would become;

10 A=2;B=3

Note that most other BASICs use the semi-colon in a PRINT statement to indicate that the items on either side of it are to be printed without intervening spaces, thus;

10 PRINT "ABCD";"EFGH"

will usually give a print-out of;

ABCDEFGH

whereas ATOM BASIC would misinterpret this line as two statements;

	10 PRINT "ABCD"
and	"EFGH"

See the notes on PRINT statements for ways of replacing the ';' in these circumstances.

Numeric Variables

Many BASICs allow floating point decimal numbers (generally called 'real' numbers) such as 9.73 or -27.456. If your ATOM is not fitted with the Floating-Point extension ROM, then depending on the program it may be possible to 'scale' the values - by multiplying by say 10 or 1000 for the calculations so that a reasonable accuracy is obtained. The large range of values allowed by ATOM (approximately -2000 million to +2000 million) make this task relatively straightforward.

BASICs that allow real numbers usually do all operations in floating point mode, and only give integer results when specifically instructed to do so by a function such as INT (X); which gives the integer value of the real variable or expression X (e.g. INT (6.67) gives 6). This is different to the approach used by ATOM BASIC, which has separate commands for integer and floating point working (when the Floating Point ROM is fitted) e.g. PRINT and FPRINT, IF and FIF, and must be watched carefully when translating.

Some floating point BASICs allow the use of integer variables by giving them special names in much the same way as ATOM BASIC has different types of names for integer and real variables. Unfortunately, this can cause some confusion as opposite conventions are used, thus typically;

A is a floating point variable equivalent to ATOM's %A

%A or A% is an integer variable equivalent to ATOM's A

Many versions of BASIC allow you to use variable names longer than one character, such as A1, A2% or COUNTUP.

Single letter names will have to be allocated for ATOM.

Numeric Arrays

In most versions of BASIC, an array variable is distinguished from an ordinary variable only by the presence of the parentheses () after the name. For example A(7) is element 7 of the array A() and may be an integer or a floating point number depending on the type of BASIC, space for the array being reserved by a previous statement such as DIM A(99). ATOM BASIC, of course, uses the double letter form AA() for an integer array element, and %M() for a floating point array element - with space reserved by a DIM AA(99) or FDIM %AA(99).

Note that the expression DIM A(n) is used by ATOM BASIC to reserve space for n+1 bytes, which may then be used to hold a string variable or for byte or word vectors, and is therefore not equivalent to DIM A(n) In other BASICs (which don't allow for byte or word vectors). Also, note that in most BASICs the array variable A() and the ordinary variable A have no relation and may be used independently within a program. This differs from ATOM BASIC which uses the variable A to hold the RAM address of the first byte in the vector defined by a DIM A() statement.

As byte and word vectors are a unique ATOM BASIC feature, it may be worthwhile seeing if a program being translated can be simplified by their use.

Many versions of BASIC allow multi-dimensional arrays, such as DIM A(4,4,4) , which declares a three dimensioned array having a total of 125 (5x5x5) elements. Page 50 of 'Atomic Theory and Practice' shows how to convert multi-dimensional arrays so that the ATOM can handle them.

Note that in some BASICs the first element of an array has the subscript (1), rather than (0).

String variables

String variables are represented in most versions of BASIC by a variable name followed by the '$' sign, thus A$ is a string variable. Usually A and A$ are unrelated.

In ATOM BASIC, however, strings are handled as byte vectors, by using a DIM statement to set up a variable (say A) to point to the first RAM location where the string is to be stored. The string is then accessed by putting the string operator '$' in front of the variable name. Thus '$A' refers to a string starting at RAM location A.

Many versions of BASIC allow string variables of less than a certain length (for example 10 characters) to be used without having to specifically reserve space with a DIM statement. This is not allowed in ATOM BASIC.

When the length of a string has to be declared to reserve memory space, the various versions of BASIC differ in the details of how this is done, but the most common scheme is to use a statement of the form DIM A$(20) or DIM A$[20] to reserve space for a 20-character string. The latter form is most used by BASICs which allow arrays of strings; such that DIM A$(10)[20] declares a 10 (or 11) element string array, each string being up to 20 characters. Pages 62,63 of 'Atomic Theory and Practice' show how string arrays can be handled by the ATOM.

GOTO, GOSUB

Some BASICs do not allow a computed GOTO or GOSUB such as GOTO (A+100). It may therefore be possible to simplify a program by taking advantage of this ATOM BASIC facility.

Remember also that the use of a label associated with a line number is another ATOM BASIC feature that can be useful to speed up the execution of GOTO and GOSUB statements.

ON … GOTO

Sometimes found in other BASICs, these statements make the program GOTO (or GOSUB) one of a number of lines depending on the value of a variable. For example;

10 ON I GOTO 100,105,50

will jump to line 100 if I=1, 105 if I=2, or 50 if I=3.

Depending on the particular application, ON..GOTO or ON..GOSUB may be replaced by a 'computed' GOTO or GOSUB, or by a combination of IF- - GOTO lines.

IF … THEN

Most other versions of BASIC require that the 'THEN' is always included; a few memory bytes can usually be saved by leaving it out when translating to ATOM BASIC.

Some BASICs don't allow anything except a GOTO after the THEN. Programs written in these dialects may sometimes be simplified by taking advantage of ATOM's ability to have any statement or statements after a THEN. Thus;

10 IF X>0 THEN GOTO 40
20 PRINT "TOO LOW"
30 END
40 ...

could be re-written as;

10 IF X<l1 PRINT "T00 LOW"; END
40 ...

Note that BASICs differ in their interpretation of a value as being 'true' or 'false'. Thus;

10 IF A THEN PRINT "TRUE"

will print TRUE in ATOM BASIC if A is non-zero, whereas other versions of BASIC may use - for example - negative values to represent the Boolean value 'false' and zero or positive values for 'true'.

FOR TO STEP

ATOM BASIC's FOR ... NEXT loop function is similar to other BASICs, so usually no alteration will be needed when translating except - perhaps - to note that in some circumstances it may be better to take advantage of ATOM's DO . .UNTIL loop control function.

Be careful, however, if the program jumps out of a FOR . . NEXT loop. Some BASICs are able to do this repeatedly without harm, but as discussed in the section 'Programming Tips', ATOM BASIC may object.

INPUT

Some forms of BASIC don't allow a 'prompt' string to be included in the INPUT statement, so programs written in these dialects may be simplified slightly for use on the ATOM. For example;

10 PRINT "MONTH "
20 INPUT M

could be translated to;

10 INPUT "MONTH "M

PRINT

Print statements will often have to be amended to make best use of the ATOM's screen format. It should also be noted that in most versions of BASIC, items in a PRINT list must be separated by a comma (,) or a semicolon (;). The comma causes the next expression to be printed out in the next tabulation field - as in ATOM BASIC -the semicolon causes the next expression to be printed immediately following the previous one without any intervening spaces, and is equivalent to an ATOM BASIC PRINT statement with just a space between expressions. For example;

10 PRINT A,B;C;D

translates to the ATOM BASIC

10 PRINT A,B C D

Most versions of BASIC output a carriage return/line feed automatically at the end of a PRINT list, unless the last character in the list is a semicolon, and if an additional line feed is needed it has to be generated by another PRINT statement.

ATOM BASIC on the other hand, only outputs carriage return/line feed when specifically instructed by an apostrophe (') in the PRINT list. Thus;

10 PRINT "ABC";
20 PRINT "DEF"
30 PRINT "l23"
40 PRINT
50 PRINT "456"

will cause most BASICs to print out

ABCDEF
123

456

and is equivalent to the ATOM's

10 PRINT "ABC" ~DEF" '"123"' '"456"'

TAB

In most BASIC dialects, TAB(X) is used in a PRINT statement to cause the next character to be printed at position number X in the line. Thus PRINT TAB(25);"A" will print the letter A in the 25th column.

ATOM BASIC does not have the TAB() function, but does have a function COUNT which gives the number of characters already printed on that line, thus the example given above could be re-written as; DO PRINT " ";UNTIL COUNT=24; PRINT "A".

Programs written in other BASICs sometimes use the TAB function to simple graphs; in these cases it may be possible to produce the same result by use of ATOM's PLOT or DRAW statements.

PEEK, POKE, USR

PEEK and POKE statements are used in some BASICs to look at, and change, the values of specific memory locations. Equivalents of these are given in page 15 of 'Atomic Theory and Practice'.

USR(X) is a function which calls a machine language routine starting at memory location X - and sometimes it returns a value in a way that depends on the version of BASIC being used. As ATOM BASIC allows you to insert a section of machine code within a BASIC program, to pass values freely between the BASIC and machine code routines, and to run the machine code routine by using the LINK statement, it allows you to do all that USR() can, and more.

In any case, the effect of PEEK, POKE and USR(X) depends entirely an the particular computer being used, therefore to convert a program containing any of these to run on the ATOM, you must find out exactly what the command was intended to do, then write ATOM code to perform a similar function.

DATA, READ, RESTORE

DATA and READ statements are often used to handle a list of fixed numeric or string values. Thus if the lines;

100 DATA 7,2,5
110 DATA 12,13

appear in a program, then

200 FOR 1=1 TO 5
210 READ A(I)
220 NEXT I

will load the values 7,2,5,12,13 into the array variables A(1) to A(5); each READ statement executed taking the next value from the list. RESTORE sets the list 'pointer' back to the first item in the first DATA statement in the program.

Pages 63,64 of 'Atomic Theory and Practice' show how to perform similar functions in ATOM BASIC, and see the program "Buzz-Word" in this bock for an example with strings.

DEF, FN

A statement of the form

10 DEF FNA(X) = X+X*X

is acceptable to most BASICs, and defines a function FNA(X) which returns the value of X+X*X and can be called up with different parameters during the program, e.g.

20 LET A=3*FNA(2)

would give A the value 18.

Usually up to 26 functions; FNA() to FNZ(), are allowed.

ATOM BASIC does not allow functions to be defined in this way, so the expression would have to be written out in full each time it is used, thus the above example would require line 20 to be;

20 A=3*(2+2*2)

Arithmetic functions

The following functions are not available in the Integer form of ATOM BASIC, and if they occur in a program you wish to translate then some other way of calculating the required value must be found;

ATN(X) ; Arctangent of X
COS(X) ; Cosine of X
EXP(X) ; e raised to the Xth power
LOG(X) ; Logarithm of X to the base e
SGN(X) ; Returns -1,0 or +1 depending on whether X is negative, zero or positive.
SIN(X) ; Sine of X
SQR(X) ; Square root of X
TAN(X) ; Tangent of X

Trigonometric functions are usually expressed in radians. The Floating Point extension to ATOM BASIC uses the symbol ^ to mean 'raise to the power of' (e.g. 3^2 = 9). Some BASICs use the symbols up-arrow or ** instead.

RND

In most Integer BASICs, the expression RND(X) returns a random positive integer between 0 and X, and is equivalent to ATOM BASIC's ABSRND%(X+1).

In most Floating Point BASICs, RND(X) returns a random decimal fraction between 0 and 1, regardless of the value of X.

Joining strings

Most BASICs will let you join two strings to form a third ('concatenation' is the official word for this operation), thus;

10 LET AS = "ABC"
20 LET S$ = "DEF"
30 LET C$ = A$ & B$

gives C$ the value "ABCDEF". "+" or "!" symbols may sometimes be used instead of "&". ATOM's equivalent for this example is;

10 $A = "ABC"
20 $B = "DEF"
30 $C = $A; $C+LEN(A)=$B

LEFT$, MID$, RIGHT$

These functions occur in many versions of BASIC. They operate on a string (e.g. X$) to return a string which is a part of X$.

LEFT$(X$,Y) gives the first Y characters in X$. The statement;

10 LET X$ = LEFT$(X$,3)

translates to;

10 $X+3

and the ATOM BASIC equivalent of

10 LET A$ = LEFT$(X$,J)

is;

10 SA	$X ; $A+3=""

RIGHT$(X$,Y) gives the last Y characters from X$ and is equivalent to ATOM BASIC's $X+Y

MID$(X$,Y,Z) gives 7 characters from X$, starting at the Yth character, thus;

10 LET B$ = "ABCDEF"
20 LET A$ = MID$(B$,3,2)

will give A$ the value "CD". To perform a similar function in ATOM BASIC, a routine such as that given below is required;

10 $B = "ABCDEF"
20 $A = $B+3; $A+2 =""

Page 61 of 'Atomic Theory and Practice' gives further explanation of these techniques.

ASC CHR$

ASC(X$) qives the decimal value of the ASCII code for the first character in the string X$, the ATOM BASIC's equivalent is the function CH. Thus

10 LET B = ASC(C$)

translates to;

10 B = CH$C

CHR$(X) returns a string of one character corresponding to the ASCII code X. Thus;

10 LET B$ = CHR$(65)

gives B$ the value "A". To perform this function on the Atom, we first put the value of X in the first byte of the memory space reserved for the target string, then put the value 13 ('Return') in the second byte. Thus the example given above becomes;

10 B?0 = 65; b?1 = 13

Alternatively, if the CHR$() function is being used in a PRINT statement (usually to output a special control code or a graphics character), the $ operator may be used. Thus;

10 PRINT CHR$(12)

could be translated to run on the Atom as;

10 PRINT $12

as long as the value following the $ is between 0 and 255.

VAL

VAL(X$) gives the numeric value of the string (of digits) X$. Thus;

10 LET A = VAL( "12.34")

gives A the value 12.34

The function is available in the floating Point extension to Atom BASIC, but not in the integer form, where a special routine would have to be written to convert the string to it's equivalent numeric form, for example;

10 A = 0
20 FOR I = 1 TO LEN(X)
30 A = 10*A+X?I-CH"0"
40 NEXT I

STR$

In most versions of BASIC, the function STR$(X) gives a string of digits equal to the value X. Thus LET A$ = STR$(123) give A$ the value "123". The function is available in the Floating Point Extension to Atom BASIC, although in a slightly different form (see page 163 of 'Atomic Theory and Practice'), but not in integer BASIC.