Automatic proof reading for ST BASIC type-ins
There are few things as frustrating as typing in a long program listing from a magazine and then finding that the program won't RUN because some character was mistyped. Consider this statistic. A 50-line program with 40 characters per line has 2,000 characters in it. Even if your typing is 99.9% correct, you would still have two mistyped characters somewhere in your file.
But if computers are so smart, they should find the mistakes for you, right? What you need is to teach the computer to look at the program you just typed in, and have it tell you if you typed in any characters which aren't supposed to be there.
TYPO ST (Type Your Program Once ST), written in Atari ST BASIC, is the latest in the Antic tradition of providing automatic proofreading programs for checking our published BASIC listings. TYPO II currently does the job for the 8-bit listings.
How does the ST know when you've made a typing mistake? It can't, really.
What it does is read your program line-by-line and add up the ASCII values
for all the characters in each line. TYPO ST then prints out the line number
it was looking at, and the sum of the values of all the characters
in that line. This sum is called a checksum. You compare this checksum
against the line-number entry in the TYPO Table we will print at the end
of each ST BASIC program.
your saved ST BASIC
listings and generates
If the two values match, you've almost certainly typed the line correctly. (At present, TYPO ST can't tell if you transposed two characters that belong in the line.) If the values don't match, carefully check each character in the line and re-type as needed.
USING TYPO ST
To get started, type Listing 1, TYPOST.BAS, carefully into your ST and then SAVE it to disk. Feel free to use either the ST BASIC editor or the word processor of your choice. Me? I use 1st-Word Plus.
TYPO ST may now be used to check itself. When you have TYPO ST stored on disk, activate ST BASIC, (if you aren't using it already) and LOAD TYPO ST into memory. Either type RUN or go up to the file menu and click on RUN. In the output window, TYPO ST will ask for the name of the file to check. To have TYPO ST check itself, type in TYPOST.BAS and press [RETURN]. Next, TYPO ST will ask if you want the TYPO Table printed on the video Screen or the Printer. Type in S for the Screen or P for the Printer and press [RETURN].
TYPO ST will read through your saved TYPO ST program and generate the line-by-line TYPO codes for you to match against our TYPO Table. Remember, if the numbers don't match, check your typing on that line again.
Let's take a look at the TYPO ST program itself, just to see how it works. Starting at the top, Lines 1000-1050 are comments. Everything on a line after an apostrophe ['] is ignored by BASIC when the program is RUN. They are here to let us give the program a title, and author/copyright information.
Lines 1060 and 1070 set default values for variables, which here are easily-remembered names for different values, such as the word DISK standing in for the value 1. Line 1090 will print out the question asking which file to check, and then wait until you input (by typing) the desired filename. Lines 1100-1150 will stop and await your decision on which device (Screen or Printer) you wish the TYPO Table to be printed on. Lines 1140-1150 will re-confirm and print out your filename choice on the TYPO Table listing.
Line 1180 will open the disk file your program is saved in. This command is made up of four parts:
1. open, which is the command itself.
2. "I",, which stands for "input". Other choices here are "O" for output or "A" for append.
3. #DISK,, denoting the logical number of the device we want to communicate with. It's a good idea to keep this number between 1 and 31. Remember, we already told BASIC to set the variable DISK equal to 1.
4. FILENAME$, the variable where we previously told BASIC to store the letters making up the filename we want TYPO ST to check.
Lines 1200 through 1280 make up a collection of instructions to be executed only while a condition is TRUE. Here the condition is CHECKSUMMING, which was set TRUE back in line 1060. So we will be CHECKSUMMING, and control drops down to line 1210 where two variables, LINENUMBER and CHECKSUM, are reset to zero.
Why? Since the program will examine each line in turn and generate a checksum for it, we need to start off each line with a blank current LINE-NUMBER and blank CHECKSUM. If we didn't, the program might get confused and try to add in the last known CHECKSUM to the next line.
At line 1230, we instruct the computer to read in and process another line of your BASIC program. We call this process here GETALINE. Eventually we will have processed the current line, and the program will return and drop down to line 1250, where we transfer this line's CHECKSUM to a variable called DECIMAL, and then gosub to a routine called DECTOHEX, which will convert the base-10 decimal number in the variable DECIMAL into a base-16 number contained in the variables HI$ and LO$.
Line 1260 will build our final OUTPUT string of characters Out of the current LINENUMBER, a space character followed by a colon character, and then the four characters HI$ and LO$ make up. Line 1270 will print the results on the device (video Screen or Printer) we asked for earlier in line 1110.
Line 1280 closes the while... wend loop we started in line 1200. Line 1300 will close the channel we opened earlier in line 1180 to the DISK, and line 1310 is the logical end of the program.
Line 1340 is a label. ST BASIC allows the programmer to reference other lines by name, not just by number. Giving meaningful names to different subroutines helps the programmer remember what they do better than just referencing by line numbers. After all, GETALINE tells you what should happen better than just the number 1340.
Below, in line 1350, we erase BLINE$ by setting the variable to nothing (""). BLINES is where we will keep the entire line of BASIC code we will be summing up. We want to erase it so that we are sure to start with a fresh, clean line. After we erase BLINE$ we instruct BASIC what to do if we should encounter some sort of error while trying to read in each line of program from the disk. This instruction says, "If an error happens, transfer control to line number 1300."
Next, in line 1360, since we haven't quite yet gotten a line in from disk yet, we need to remember that by setting GOTALINE to FALSE. Line 1380 starts another while... wend loop which will indeed start while we have not GOTALINE. Below, in line 1390, we will line Input a complete line from the disk file and put the lie into the variable called BLINE$. We use line input instead of just input, because line input will accept every character until the next carriage return, and we need to capture all the commas and punctuation contained in each line.
Line 1400 tests to see if BLINE$ has more than one character in it. If it does then we set GOTALINE to TRUE, because if BLINE$ has length, we have just GOTALINE. Line 1410 will force a loop until we have indeed GOTALINE.
Line 1430 will extract the current line number from BLINE$ by getting the VALue of BLINE$. The function val() will accept all numeric characters in a row until it hits an alphabetic-or rather non-numeric- character. It then changes these numeric characters into a numeric value, which we place into LINENUMBER.
Line 1440 starts a for... next loop that will last for as many characters as the string BLINE$ has in it. This will allow us to examine each character in the string one after another. Line 1450 reminds us that we assume it's OK to add the value of CHARACTER$ into CHECKSUM. We then pull then next CHARACTER$ off BLINE$ and examine it. We test, in line 1470, to see if the character we just examined is a space character. If it is a space character we set OK to FALSE, meaning we do not want to add in the value to our CHECKSUM.
We do this because many people will want to type in BASIC programs with a word processor, and when ST BASIC gets its hands on the program it will strip away all the spaces between the line number and the first instruction. So we throw all spaces away. Finally, in line 1480, if the current CHARACTER$ is OK, we add in the ASCII value of CHARACTER$ to CHECKSUM, and then look for the next character in the line.
The last routine here is DECTOHEX, which will convert a base-10 number in DECIMAL to a base-16 number contained in HI$ and LO$. First, line 1540 makes sure we never slip DECTOHEX a negative number by forcing DECIMAL to its absolute value, which is positive. Line 1550 will break up the value DECIMAL into its HI and LO halves, and lines 1560-1570 further break down HI and LO into their own HI and LO halves.
Lines 1580-1590 do the hard work. These two lines change the base-16 value now in HH, HL, LH, and LL to their ASCII characters, and pair them off into two groups called HI$ and LO$
Listing 1: TYPOST.BAS Download