PROGRAMMING THE TI
Answers To Common Questions
I have appreciated your comments and feedback. Your letters help me in several ways to write a better column. I thought this month I would try to answer some general questions that I frequently see. Most of the questions concern peripherals or debugging, so I'll discuss these two main topics this month.
Do You Really Need Peripherals?
Peripherals are anything extra that you add on to your computer. To use your TI-99/4A, all you really need is the computer itself, a television or monitor so you can see what you're doing, the cord to connect the television and the computer, and the power cord (these cords are included with the computer). If you are writing your own programs, purchasing programs on cassette, or typing programs from magazines, you will need a cassette recorder and a cassette cable. You can use just about any kind of cassette recorder, but the TI Program Recorder is more reliable. The TI-99/4A console seems quite sensitive to the setting of the volume control. Your recorder does need to have a volume control and a tone control. Your User's Reference Guide tells how to use the cassette recorder.
To save a program you've written or typed in, use the command SAVE CS1 then press ENTER and follow the cassette instructions. To load a purchased program or a previously saved program, use OLD CS1 and follow the instructions. After you have pressed STOP on the cassette and ENTER on the keyboard, wait for the cursor to return (it may take a few seconds on longer programs), then type RUN to start the program.
By the way, as you are typing in a program, it's a good idea to SAVE your program every 20 minutes or so. It's a disaster to have a program all typed in after hours of effort, then have a sudden power failure that wipes out your program. I always use two cassettes and alternate them during the SAVE procedure just in case the power fails while I'm saving the program.
Most of my writing is for unexpanded computers with no peripherals other than the cassette. TI computers are very powerful machines just as they are, and I like to show readers how much they can do without investing any more money. The TI has many nice features and a very powerful built-in BASIC. The average household or educational user will not need any peripherals to enjoy and use the TI.
What Do You Buy First?
Many computer users soon want to do even more with their computers and begin to add peripherals. Many readers ask what peripherals to buy, and I can't really answer that because it depends on what you want to do with the computer. I added a printer first because I needed (wanted) listings of the programs I was writing. Other people can't live without a disk drive, so that's their first purchase.
There are many, many brands of printers available. To use a printer with the TI you need the RS-232 Interface; just make sure your printer is RS-232 compatible. My first printer was an old teletype. If you need to make a cable to connect the printer to the RS-232, the RS-232 manual has the pin connections and all the configuration information. My next printer included the cable – so work with your dealer to make sure you have everything you need.
It is still possible to use just the RS-232 without the peripheral box (known as the "old-style" peripheral system). If the only peripheral you will need is the RS-232, it is unnecessary to buy the Peripheral Expansion Box plus the RS-232 Interface Card. In fact, if you have the Peripheral Box, you can use the old-style RS-232 or the RS-232 card. If you have the old-style RS-232, just plug the Peripheral Box flex cable into the side of the RS-232.
Using the Peripheral Expansion Box is the present method of adding on peripherals to the TI. Inside the box are slots for various cards. There is also room for one disk drive to be inside the box. You may add cards as they become available (or as you can afford them or need them).
A disk drive can be used in many ways. To add a disk drive you also need the Disk Controller box or the Disk Controller card and the Peripheral Expansion Box. The main advantage of a disk system over a cassette system is speed. You may SAVE programs on disk just as on cassette. A full-memory program may take about 3 minutes to load with cassette but only about 20 seconds with the disk system. The disk system is also much faster on any file processing, and thus practically a necessity for business programs. Many business programs require two disk drives. One disk controller can control up to three disk drives. Disk systems are possibly undesirable for some home use or for use in elementary schools because the cassette system is easier for children to use, less expensive, and not as fragile.
The 32K Memory Expansion is available either as a separate box or as a card to go in the Peripheral Expansion Box. One irate reader wrote that in my January column I did not mention that to add the Memory Expansion you also have to buy the Peripheral Expansion Box. The answer is that the Memory Expansion is still available separately in a box that attaches to the side of the computer. The Peripheral Expansion Box is the best way to go if you are adding several peripherals, but if you need only one unit the "old-style" still works. The 32K Memory Expansion does require a command module that can access it. You cannot use the Memory Expansion with the built-in BASIC. TI Extended BASIC and Logo are examples of two of the modules that can use the Memory Expansion.
A modem allows telecommunication – you can connect your computer through telephone lines to another computer such as a large data base or a mainframe "host" computer. Your home computer thus acts as a terminal. To use a modem you'll need the RS-232 Interface and the Terminal Emulator command module. The RS-232 has two ports so you can interface with both a printer and a modem. There are two terminal emulator command modules, and either one will work. They contain the software necessary to set up the communications. Terminal Emulator II also contains speech capabilities, so it is a dual-purpose module. There are many brands of modems and telephone couplers; you just need to make sure the one you use is RS-232 compatible.
The Speech Synthesizer is the peripheral that makes the computer talk. With the "free speech" offer (buy six command modules and get the Speech Synthesizer free), every home with young children should get one. The speech feature adds an extra touch to educational programs. To enable the computer to talk, you need a command module that has speech capabilities.
To program your own speech, you'll need Terminal Emulator II. Words are pronounced phonetically, or you can use numbered allophones, so programming speech takes some experimentation. You can also use the TI Extended BASIC module, but this module has limited speech –only a certain vocabulary (and variations of those words) can be used.
Wired Remote Controllers are available for games or for educational programs. The TI version comes as a pair of joysticks for two-player games.
With a Hex-Bus adapter you can save a program with the Texas Instruments Compact Computer 40 (CC-40) onto wafertape, then load it onto the TI-99/4A.
Alternatives To BASIC
Several languages are available for the TI-99/4A. TI Extended BASIC is probably the first one I would get for someone who likes to program. Extended BASIC comes as a command module, and no extra peripherals are required. Extended BASIC allows multistatement lines, actual subprograms, and complex IF-THEN-ELSE logic. If you like to convert programs from other versions of BASIC, Extended BASIC makes it a little easier. Another feature of Extended BASIC is the DISPLAY AT command to print at a specific location on the screen – and the PRINT USING command allows formatting, which makes it easier to print reports or line up numbers in a column of numbers.
Another main feature of Extended BASIC is sprite capability. You may custom design your own objects just like in TI BASIC, but then you can place the sprite on the screen, designate a color, and put the sprite in motion (all in one statement). For people who like to design games, Extended BASIC is a must. The sprites are a lot of fun to work with.
Logo and Logo II are command modules which are popular in introducing children to programming. The TI version of Logo allows all the common turtle commands, and you can define your own characters and choose colors. The Logo II version has music capabilities. To use Logo or Logo II, you need the memory expansion. If you are a teacher using Logo, be sure to get the Logo Curriculum Guide. It is a manual of excellent ideas for using Logo in the classroom. It also includes sample programs.
For machine language, you can get the Editor/Assembler cartridge. The 32K Memory Expansion, Disk Drive, and Disk Controller are required. A less expensive way to try machine language is to use the Mini-Memory module (no peripherals required).
Another language available to TI users is Pascal. Peripherals required are the P-Code Card, 32K Memory Expansion, Disk Drive, Disk Controller, and Peripheral Expansion Box.
I'm sorry I cannot answer your questions about machine language or Pascal. My programming so far has been in BASIC (for several computers) and TI Extended BASIC.
Why Won't The Program Run?
Now to the second main topic – debugging. Debugging is a computer term which means finding what's wrong with a program that doesn't work correctly. This month I'd like to give you some tips on how you might pinpoint errors in a program you've typed in but won't run correctly.
Syntax errors are the easiest to find and correct. If you RUN the program, it will stop at any syntax error and tell you exactly what's wrong and in which line. Syntax usually refers to a typing error such as a word spelled incorrectly, a comma in the wrong place, unmatched parentheses or quotes, or the wrong number of parameters in a CALL command. The TI catches a lot of typing errors as you are typing in the lines. Others are detected as the program is RUN. Remember that you can type the line number then the down arrow (with FCTN on the TI-99/4A and SHIFT on the TI-99/4) to edit a particular line, then use the arrow keys to move the cursor to the error.
Check line numbers in program transfer statements – GOTO, GOSUB, ON-GOTO, ON-GOSUB, and IF-THEN-ELSE statements. One digit can make a difference in the proper program control. For example, my coordinate geometry program in the February 1983 issue had a typesetting error. Line 760 should have been GOSUB 1860 instead of GOSUB 1850. That one digit caused an error. Several people wrote in very complex solutions to a problem I didn't know existed until I compared line numbers and noticed that one digit. This was one case where there really was a printing error. Now COMPUTE! has the listings printed directly from the computer to avoid such errors.
Check Your DATA Statements
Check to make sure DATA statements are typed correctly. If your program has DATA statements and doesn't run properly, the most likely place for a typing error is in a DATA statement. You may want to review the description of DATA statements in your User's Reference Manual or my August 1983 column on DATA and READ statements so you can follow the logic of the READ statements and corresponding DATA statements.
If you get a DATA ERROR, you may not have enough data items to fulfill the READ requirements. The line number given in the error message is the READ statement, so you'll have to find the corresponding DATA statement. Check the DATA statements for the proper placement of commas. It is possible there are commas together with nothing between them – this indicates a null string or " ", and every comma is necessary. Also, make sure you do not have a comma at the end of a DATA statement.
Another type of DATA error is that the computer is trying to read a numeric value but gets a string (letters). Again, check the commas. Also make sure you haven't mistyped the number zero and the letter O.
If you have a lot of DATA statements, your eyes may get tired trying to compare printed statements with your typed statements. To try to pinpoint the trouble spot, LIST the lines around the READ statement referred to in the DATA error message. Remember you can list specific lines, such as LIST 640–660. Now PRINT the variables you are reading to find the last good values that were accepted. If you are reading within a FOR-NEXT loop, you can PRINT the index counter to see how far along the loop you are.
Anytime the program stops (BREAK), in this case with an error message, and as long as you don't do any editing, you may PRINT the value of any variable. For example, you may type PRINT B and press ENTER, and the present value of B will be printed. You can then look in the DATA statements to see where that particular value is. The value printed will be the last acceptable value for B, so the next couple of items may contain the error.
An error in a DATA statement may actually cause a problem in a statement other than a READ statement. For example, suppose you have this section of a listing:
650 FOR I = 1 TO N 660 READ X, Y, G 670 CALL HCHAR(X, Y, G) 680 NEXT I
You could get the error message BAD VALUE IN 670. This means X, Y, or G is not acceptable. X must be a number from 1 to 24 for the row number, Y must be from 1 to 32 for the column number, and G must be an ASCII code number. You can PRINT X;Y;G to see what the values for X, Y, and G are. The next step is to see how you got the bad value. In this case, line 660 READs the values from DATA, so you can search through the DATA statements to find a sequence of the three numbers the computer printed. The error will probably be a typing error just before those numbers.
Other Common Errors
There are also errors unrelated to DATA statements. FOR-NEXT errors are usually not difficult to find. Every FOR statement must have a corresponding NEXT statement. Once in a while, however, you can search and search and everything seems matched up correctly. The most likely cause for the error is that a line just before a FOR statement or just before a NEXT statement has 28 characters (or a multiple of 28), so the cursor goes to the next line. You need to press ENTER, but the cursor makes you think you have already pressed ENTER, and you may go ahead and type the next line. The result is a run-together line. If you list that line among several others, they all look right because the numbers line up properly.
To see if this is the problem, LIST only the line containing the FOR or the NEXT to see if it's really there. Warning: The FOR-NEXT error message may list a line number that is really OK; the run-together FOR or NEXT statement may occur before the one listed in the error message. If you use the automatic numbering feature as you type in programs, this problem is less likely to occur.
The run-together line problem may occur anytime you are typing lines that have 28 characters and could cause other problems.
A "glitch" type problem may occur in ON-GOTO and ON-GOSUB statements. The line should be typed in the following example form:
200 ON A GOTO 340, 550, 760, 800
where there are no spaces between the line numbers. If you happen to type a space in between line numbers then later LIST the line, the space will not be there but it could still be causing an error. If you suspect you are having trouble with an ON-GOTO or ON-GOSUB statement, retype the whole statement. By the way, don't try to second-guess the author. The line numbers do not have to be in numerical order, and you can use the same line number in several of the positions.
These are answers to the most common questions I've been asked. If you still have problems getting a program to run, you may write to me. Be sure to tell me which program you are typing, which computer you are using, the exact error message with the line number, and what happens plus whatever other conditions may contribute to the problem. I want you to be able to use and enjoy these programs; however, it is difficult for me to help you debug if I don't know the exact conditions and line numbers. Please do not ask me how to solve problems with programs written by other authors.
Also, please do not ask me to debug one of your programs or to write a program (or convert a program) for you. It isn't your project if I do it for you, and the joy of programming is accomplishing your own goals. I also am not set up to review programs for you. You may submit them to COMPUTE! directly. I do welcome comments or suggestions for future columns that will interest the general TI user.
Since I haven't written about a specific programming technique this month, here's a short graphics display program to try this time. I'll try to have a Christmas present for you in my December column.
100 DEF R = INT(16 * RND + 1) 110 RANDOMIZE 120 FOR 1 = 1 TO 16 130 CALL SOUND(-50,R * 110, 4) 140 CALL COLOR (I, R, R) 150 CALL SCREEN(R) 160 CALL HCHAR(R + 4, R * 2, R * R / 2,R * R) 170 CALL VCHAR (R + 4, R * 2, R * R / 2,R*R) 180 NEXT I 190 GOTO 110 200 END
Line 100 defines a function R to be a random integer from 1 to 16. Every time R is used in later lines, R will be a random integer from 1 to 16 – a lot less typing by using the DEFinition function.