NEW OWNERS COLUMN
Lesson II: BASIC commandsby DAVID PLOTKIN
New Owners Column, which began in our last issue, will teach you bow to program in BASIC on Atari 8-bit computers like the 800XL and the 130XE. To start out, you don't need to know anything more than how to turn on your computer. David Plotkin, the author of this series, is a chemical engineer and a longtime Antic author/programmer-ANTIC ED
In this month's lesson, you will start to learn the essential concepts you must understand before you can write your own programs in BASIC. Now is a good time to take a look at a BASIC program listing, if you have never done so. You will find quite a few BASIC listings in the Software Library section of Antic, including the demonstration program that is part of this month's column. Just as a reminder, when you see "D:FILENAME" in reference to a file on your disk, you should replace the word FILENAME with the name you picked for your file when you SAVEd it.
Probably the first thing you will notice about any BASIC listing is that each line begins with a line number. (NOTE: The BASIC listings published in Antic also have TYPO II code letters which we'll ignore for now. These TYPO II codes are highlighted in white, just to the left of the line numbers.) BASIC line numbers are absolutely necessary. Each program line must start with a line number, which can be any number between 0 and 32767. Good programming practice is to normally number your lines by 10s. That is, follow line number 10 with 20, then 30, then 40, etc.
The line number is more than just a way of directing various commands to a specific line. The line numbers also tell BASIC in what order the lines are supposed to go. For example, suppose you have two lines such as the following. (Use the [BREAK] key to get out of this program after you are done.)
10 PRINT "HELLO THERE, READER!!"
20 GOTO 10
After entering these two lines (don't forget to press [RETURN] at the end of every program line), you add another line such as the following:
15 PRINT "OF THE NEW OWNER'S COLUMN"
If you LIST your program, you will find that line 15 has been included between lines 10 and 20, just as you would expect. By choosing line numbers which begin every 10, you will have room to add in-between lines later-when you remember something that must be included.
Line numbers are also important when using the editing keys discussed in last month's column. You've already used the LIST command to put your program on the screen. But you can just LIST a single line by typing the line number you want to LIST after the command. For example, LIST 15 [RETURN] will put line number 15 on the screen.
To change a line, all you need to do is put the cursor on that line, type in the changes over the existing characters, and press [RETURN]. If you change only the line number and press [RETURN], you will have two lines-one with the original line number and one with the new line number. To erase a line from your program altogether, simply type the line number and press [RETURN].
Finally, a warning about line numbers. You cannot have two different program lines with the same line number. If you give a new line the same line number as one already in your program, the old line will disappear and be replaced by the new line! So be careful.
Each line which requires a line number can be up to 120 characters long, including all commands and spaces. Since your screen can only display 40 characters on each line, each BASIC line can be up to 3 screen lines long.
When you are typing a BASIC line and you reach the end of a screen line, your cursor will automatically jump down to the next line. Near the end of the third screen line from where the line number is, a warning buzzer will sound. (Don't forget to turn up your volume.) Your Atari will allow you to type past the end of the third screen line, but everything past that line will be ignored-probably generating an error. A full program line, from line number to [RETURN], is called a logical line and can be as much as three physical lines long. A physical line is a row of characters from one side of the screen to the other.
As mentioned earlier, a BASIC program consists of many commands. Line 10 above (the PRINT statement) is an example. Line 10 contains only one command, but you may put more than one command on each line. To put additional commands on a line, they must be separated by a colon [:] as in this example:
10 GRAPHICS 0:PRINT "HELLO
THERE, READER":PRINT "THIS IS
Last month we talked about LIST, which will display your program on the screen. However, there are additional tasks you can accomplish with LIST besides LISTing your whole program or LISTing a single line. You may also LIST a range of line numbers by specifying both ends of the range:LIST 0,100 [RETURN] will display all lines with line numbers between 0 and 100. Note that it isn't actually necessary to have lines with numbers 0 or 100!
If your Atari is connected to a printer, you can send a listing of your program to the printer by typing the following:
LIST "P:" will list the whole program.LIST "P:"0,100 just lists the lines with line numbers between 0 and 100.
Finally, you can LIST your program to the disk drive by typing:LIST "D:FILENAME" or LIST "D:FILENAME",0,100. A program LISTed to the disk instead of SAVEd (see last month) can be read with a word processor or sent easily to another computer.
An even bigger advantage comes when you reload a LISTed program back into your Atari. To do this, you type ENTER "D:FILENAME" instead of LOAD. This will merge the program you are ENTERing with the one already in the computer. After ENTERing the new program, the program in the computer will consist of all the lines from BOTH programs. If the two programs had any lines with the same line numbers, only the line from the ENTERed program will be kept.
The RUN command was also introduced last month. This command will cause the program in the computer to execute. You can RUN a program which was SAVEd to disk without LOADing it first by typing: RUN "D:FILENAME". Make sure the disk containing this program is in the disk drive when you type this command. If the computer cannot find the file on disk, you will see an ERROR 170 message which means "file not found." Perhaps you misspelled the filename. Try again.
To clear out all the information that is currently in the computer, you will type NEW Be very careful about the use of NEW-there is no going back. Make sure you have SAVEd a copy of the program to disk if you are going to need it again!
One of the most useful BASIC commands is REM, which is short for REMark. It tells BASIC to ignore everything after the REM statement on that line. Programmers use the REM statement to put comments into their programs, usually explaining how the program works. This can be very useful for teaching others, and also for making changes to your own program six months later! While REM statements do not execute, they do use up memory, so you don't want to get long-winded with your explanations.
DEMO PROGRAM II
This month's demo program Is another demonstration of the sound and graphic capabilities of your Atari. You still won't be able to understand a lot of the programming commands, but the program has many REM statements to explain what is going on.
When the program asks for your name, type it in and press [RETURN]. Then it will give you a message using your name in the colorful display. When you are done looking at the message, press [RESET] to get out of the program. If you use the [BREAK] key, the program will stop, but the sound will continue.
Next month, I will teach you how to use variables, and how to get the computer to make decisions and perform loops during the execution of the program.
New Atari Owners will find additional details about topics covered by this series In Lon Poole's excellent book, Your Atari Computer, $17.95 from Osborne/McGraw-Hill Publishing Berkeley CA. - ANTIC ED
Listing 1 NEWOWN2.BAS Download