Atari Strings and Text Handling
Apples, Oranges, TRS-80s and the Atari
The Atari, unlike the Pet, TRS-80, Apple, and Heathkit computers, does not have a Basic by Microsoft. This is a mixed blessing, or mixed curse, as you choose to look at it. The graphics and music handling abilities of Atari Basic are a true joy, while the string handling is difficult. Since most programs published in computer magazines like this one are not in Atari Basic, an understanding of the differences is helpful if you wish to convert the programs for your own use. Here are some of the differences between the Atari and the TRS-80, the most common Microsoft Basic computer.
In Atari Basic DIM A$(50) means reserve 50 bytes of memory for a single variable named A$. You cannot store a single letter in a string variable unless you dimension it first. One advantage of this is that you can control the length of a string just by the DIM statement, something you cannot do in Microsoft Basic. For example, if you put:
10 DIM ANSWER$(1)
Then the computer will store only the first letter in the string even if it receives a whole sentence as a reply. This makes it easy to test an answer:
20 PRINT "ANSWER";:INPUT AN5WER$:IF ANSWER$="N" THEN 50
In the TRS-80, memory for all string variables is reserved by a single CLEAR statement, with a default value of 50 bytes reserved automatically even without a CLEAR statement. In the TRS-80, DIM A$(50) means create an array of 51 string variables from A$(0) through A$(50).
In the TRS-80, the maximum length of a string ranges from 241 to 256 bytes, depending on circumstances. The Atari is limited only by memory available. This means that the Atari can make up for the lack of string arrays through a process of storing substrings in a very long string. One advantage of the Atari is that string sorting is potentially faster, as the TRS-80 has to pause and reorganize its string space.
Related to the string length is the restriction of a TRS-80 program line to 241 to 255 characters, while the Atari observes a different approach and limits you to 120 characters. Since some TRS-80 programmers like to put a whole subroutine in a single line, you would have to do a bit of reshuffling to translate their programs to an Atari. The lack of an ELSE command further restricts this approach in the Atari.
Neither the Atari nor the TRS-80 have a built-in speaker, as does the Apple II. The Atari sends sound effects through a television set speaker. If you are using a monitor that does not have a speaker, you do not have sound. Common practice with the TRS-80 is to connect an amplifier to the cassette output port.
The real difference in sound is that the Atari has a built-in sound capability allowing four completely separate voices at the same time with over 20,000 sound options, including a wide range of musical notes for each voice, while TRS-80 Basic can only alternate voltages at the cassette output port with OUT statements or machine language subroutines. Harmony is very difficult with the TRS-80, but easy in the Atari.
It is not really fair to compare TRS-80 graphics to the Atari, as the TRS-80 is strictly medium resolution black and white while the Atari has high resolution color. To fairly represent Microsoft Basic, the Apple should be included in the discussion. One advantage the TRS-80 does enjoy is easy mixing of text and graphics on the screen, which is more difficult with the Apple and the Atari. Also, the TRS-80 has a built-in video memory that does not require user memory, while the Apple and Atari require user memory and, in high resolution, lots of it.
The Atari has 16 different graphics modes, and some of the graphics in the Atari ROM cartridges, including the motion through space in Star Raiders and the ability of the basketball players to overlay each other in Basketball, promise more graphics power than any other popular home computer. Right now, a side-by-side comparison of Apple and Atari graphics seems a standoff because the Atari graphics are not yet documented and explained, but if this kind of graphics ability becomes accessible to the end user, the Atari will be the obvious choice.
A common problem in high resolution graphics is that it requires a lot of memory to store a detailed image. The normal sacrifice limits the number of colors available in hi-res so you need less memory to store color information. The Atari limits you to two colors in high resolution, while the Apple gives you four. However, the Atari allows you to choose your color and tint and even allows you to change the color of an image on the screen instantly by changing a color register that tells the computer what color to make the image. The Apple cannot match this ability.
My personal favorite among the graphics commands of the Atari is the DRAWTO statement, which draws a line from the last plotted point on the screen to any other point. More or less the same ability is present in the HLIN and VLIN commands in the Apple, though not as easily, nor as fast. In the TRS-80, it is necessary to write a subroutine to plot each point individually.
Text handling in the Atari is not as convenient as the Microsoft Basics. The TRS-80 is particularly good at text formatting and printing. Microsoft Basic allows you to include text in an INPUT statement, like this:
10 INPUT "What is your answer";A$
Atari Basic requires a separate print statement:
10 PRINT "What is your answer";:INPUT A$
The TRS-80 allows you to print directly at any point on the screen with PRINT @:
10 PRINT @ 572,"X MARKS THE SPOT"
The Atari requires you to position the cursor first, then print your message:
10 POSITION 8,12:PRINT "X MARKS THE SPOT"
Still another difference in text handling is the power of Microsoft Basic's PRINT USING command, allowing you to specify automatic print formatting with a fixed number of decimal points, floating dollar signs, fixed spacing, and other conveniences. These things have to be done by manipulating a string in Atari Basic.
I have begun to experiment with a whole new approach to text in the Atari that may be even more convenient. The Atari allows you to treat the keyboard, the video memory, and any other I/O device as a file. I suspect that once I get used to this, I will not really mind giving up PRINT USING.
There is a more definite limitation to the Atari in one of the key text handling areas, and that is in word processing. Forty columns per line is simply not as convenient as the longer lines on some other computers. The problems here are color and expense. It is much easier and cheaper to give text processing ability and sharp resolution to a computer which does not use a video modulator and does not use color. The Heathkit H-89 with 24 lines of 80 characters has much sharper letters than the Atari, yet the Atari limits you to a mere 38 to 40 characters. A lot of this problem could be overcome by designing the Atari to be used only with a high quality color monitor, but that would price it right out of the consumer market. My own solution is to use a different computer for word processing, including the writing of these columns.
Jumps and Subroutines
One of the areas in which Atari Basic enjoys an advantage over Microsoft Basic is in the ability to transfer control to another line through a variable. This has a lot of potential. Look at these comparisons:
10 GOSUB TIMEOUT
20 GOSUB BASKET
20 GOTO RATING
10 GOSUB 500
20 GOSUB 600
20 ON RA GOTO 900,920,940
The above example illustrates another difference. In Atari Basic, a variable name may be up to 120 characters long, while the TRS-80 allows only 6 and tests only the first two. In the Atari, VALUE1 and VALUE2 are different variables. In the TRS-80, they are the same.
However, the advantage here is not altogether to the Atari. Radio Shack's Level II Basic allows an ELSE statement, while the Atari does not.
10 IF A=5 THEN 50
20 GOTO 100
10 IF A=5 THEN 50
A major strength of Atari Basic over Microsoft Basic is in its generalized output routines. This is due to a feature known to mainframe programmers as device orientation. In Atari Basic, PRINT is a generalized output command. While the default device is the video screen, the computer doesn't really care whether it is printing to a line printer, a modem, a cassette tape, a disk file, or the screen. You can even use a variable to shift from one to another in your program, virtually at will. The general format of an OPEN statement hints at the power here:
10 OPEN (Reference number), (input/output/both), extra printer code), device type), device number): (file name). (extension)
Disk file opening might look like this:
10 OPEN #2,8,0,"D3:LESSON.BAS"
Chapter 5 in the Atari reference manual gives a more detailed explanation.
What do all these differences mean? My answer is: "Not a whole lot!" Nearly anything that can be done in one Basic can be done in any other Basic, even a limited one like IBM Basic. It just takes extra effort, a little understanding of what the other program is trying to accomplish, and a little creative ingenuity.