Personal Computer News


A-Z Of Atari Basic Part 1

 
Published in Personal Computer News #047

An A To Z Of Atari Basic

We start our introduction to Atari's Basic with a look at fifteen of the more commonly-used keywords from the range A-K. All keywords must be entered in upper case letters.

The fifteen included here are: FOR/NEXT, ENTER, INPUT, COLOR, INT, DRAWTO, IF/THEN, GOSUB, CLOAD/CSAVE, ASC, CHR$, GRAPHICS, DIM, ASC, CONT.

There are more than 80 keywords in Atari Basic; many are to handle mathematic functions. All keywords can be abbreviated to two letters and the most common ones can be shortened to just one letter followed by a full stop.

FOR/NEXT

The FOR/NEXT combination in Atari Basic is much the same as it is with most other variations of Basic and it includes the option of a STEP variable. The command FOR sets up a loop using a variable to name it and a variable or a number to tell the computer how many times to follow it.

The 'var' gives the loop a name and 'num1' tells the computer what number to start counting from. The 'num2' is where the computer has to count to before the loop is finished and the 'STEP num3' is an optional addition that can be used to alter the rate of counting from the default of 1.

The NEXT part of the combination tells the computer that the loop has completed one cycle and can add one to the counter and return to the start of the loop. If the counter reaches 'num2' then the loop will stop and the program will continue at the statement following the NEXT statement. (See program 1.)

IF/THEN

The IF/THEN combination tests for a given state to be present, it looks like this:

IF exp THEN lineno/keyword

The 'exp' will be an equation of some soft. If the result proves to be true then the keyword after the THEN statement will be acted upon. THEN can also be followed by a line number. If the equation is false then the program will continue at the line following that on which the IF/THEN combination occurs. An example is shown in program two.

CLOAD/CSAVE

Random Atari Art 1

These commands can be used either within a program or on their own to save or load programs using the program recorder. After entering CLOAD the computer will produce one beep. This is a signal to remind the operator to press PLAY on the recorder and then press RETURN on the keyboard. Providing that the tape is properly positioned the program on the tape will be transferred into memory.

Use of this command erases any program that may already be in memory.

A common use of this command within a program is to chain several Basic programs together (as used by Atari in their conversational language courses).

The CSAVE command operates in the same way except that the computer produces two beeps to remind you to press both PLAY and RECORD and then press RETURN. The program currently in memory will then be transferred to tape.

ENTER "C:

Random Atari Art 2

This command is used primarily to load information into the computer without erasing what was already in memory. Any information needed to be loaded in this way must have been saved with the LIST"C: or LIST"D: command. This command is mainly used to merge cassette or disk files but it could also be a way of verifying cassette-saved files before erasing them from memory. The 'C' is replaced by a 'D' for disk files.

INPUT

Normally only used within a program, the INPUT command accepts data from the user of a program. As with most computers the INPUT can accept numbers of letters though unlike some Basics the INPUT cannot be used to display information at the same time, e.g.:

INPUT "Hello, what is your name" A$

will not work. Instead you must use:

PRINT "Hello, what is your name";:INPUT A$

Also the INPUT command always prints a question mark ('?') to show where the text to be input will appear on the screen. If more than one input is required at the same point you can use INPUT A,C,X$. When this appears on the screen you can enter three variables separated by commas, or you can enter each variable separately. INPUT also allows you to INPUT from a filename. See program 3.

INT

This command will return the INTeger value, that is, the nearest whole number value to the number specified. For example X=INT(4.3367) will place the number 4 in the variable X. In effect it rounds numbers down to the nearest integer. When dealing with negative numbers, the reverse is true. INT(-3.62) will return -4.

DIM

The purpose of the DIM statement is to reverse space in memory for use with strings and numeric arrays. Unlike many other Basics, Atari Basic does not allow you to have an array or matrix of strings though other commands are available to help you around this problem. Atari Basic is also different from most others in that all strings must first be DIMensioned before they are be used.

Using DIM you can produce three types of reserved memory: a string; a simple array which reserves six bytes of memory at each position to hold a number, and a two-dimensional array called a matrix. See program 4.

GRAPHICS

Random Atari Art 3

On the Ataris, information can be displayed graphically or using text in a number of different ways according to the number of colours required and the amount of memory to be usd. The operating system already has a number of 'modes' defined to satisfy the different requirements. These modes are selected using the GRAPHICS command. On the XL range, this command will select one of the sixteen set of modes of display available (the 400 and 800 have twelve of these modes). The modes are numbered from 0 to 15.

Most of the modes on the Atari are 'split screen' modes. That means that at the bottom of each mode is a text display. This split-screen effect can be removed by adding 16 to the mode number when using the GRAPHICS command e.g. GRAPHICS 7+16. If you add 32 to the mode number when selecting a mode, then the computer will not clear the screen memory when displaying the new mode. This is good for switching from a screen with a text window (split screen) to one without. Program 5.

COLOR

The COLOR command is used within the drawing modes to select which colour the next point or line will be drawn in. With most modes, drawing with COLOR 0 will draw a line the same colour as the background. Use of the COLOR command is shown in program 5.

DRAWTO

Random Atari Art 4

The DRAWTO command is used to draw a line from the last point plotted with the PLOT or DRAWTO command to another specified point. (The command PLOT is described in a later Micropaedia). Before drawing any lines a colour must be selected. If no points have yet been drawn then the line drawn will start from the default value of 0,0. The command looks like this:

DRAWTO x,y

and its use is demonstrated in program 5.

GOSUB

The GOSUB command is used in conjunction with RETURN to branch a program temporarily away from its normal path. This sort of branching is used mainly where a certain function is to be used more than once. Rather than typing in the lines to perform that function as many times as it needs to be performed, the lines can be put into a subroutine.

When a program gets to a GOSUB command the current location is stored and the jump is executed. At the end of the routine there should be a RETURN statement that will send the program back.

This command is shown in program 2.

Random Atari Art 5

GOTO

GOTO is similar to the GOSUB command in that it diverts the execution of a program to another line number. The difference is that this command has no RETURN equivalent. This means that the program will move to the line number specified (see program 2) and will continue from there unless it is diverted again.

CHR$

Random Atari Art 6

Within the computer various codes are used for the transmission of characters from place to place. One of these codes is known as ASCII, short for the American Standard Code for Information Interchange. Using this code computers can talk to, and understand each other. The Atari uses a slight variation on this code called ATASCII (Atari ASCII). This code gives a number (0-255) for each character. As an example, the letter 'A' is represented in ATASCII by the number 65. The CHR$ command generally converts the ATASCII code number to its relevant character. Normally used with the PRINT command the CHR$ function look like this:

PRINT CHR$(65)

Atari 400 Branded Cassettes

The above command will print the letter 'A' on the screen. Using CHR$ you can send control codes and other odd sequences to printers and other machines that could not easily be sent or translated using the PRINT command alone.

ASC

ASC is basically the opposite of CHR$ and it looks like this:

PRINT ASC("A")

This command will produce the ATASCII code for the letter entered between the quotation marks, in this case 65 for the letter 'A'.

CONT

Pressing the BREAK key while a program is running, or if the program encounters a STOP command, will stop the program and produce the message STOPPED AT LINE X.

Typing CONT and pressing RETURN at this point will cause the computer to resume execution of the program at the next program line. A program can also be stopped in the middle by the command END. Any statements on the same line as the one where the program was stopped will be ignored when the program resumes at the following line.

Next Week

We examine the games and business software available for the Atari machines, and we delve further into Atari Basic.

The following week we look at the range of Atari peripherals, including their new line of printers and storage devices.

Geof Wheelwright