Classic Computer Magazine Archive COMPUTE! ISSUE 46 / MARCH 1984 / PAGE 60

The Automatic Proofreader

For VIC, 64, And Atari

Charles Brannon, Program Editor

At last there's a way for your computer to help you check your typing. "The Automatic Proofreader" will make entering programs faster, easier, and more accurate.

We all know it's hard to type in a program correctly the first time. Seemingly trivial typing errors can cause dreaded ERROR messages, or even a system crash (the keyboard will not respond to RUN/ STOP—RESTORE or BREAK keys). Usually, the only way to recover from such a crash is to reset the computer by turning it off, then on again—wiping out the memory (and all your typing) in the process.

Even when you locate and correct the mistyped lines, there always seem to be more, lurking in the hundred-odd lines of the program. Sometimes you feel like giving up.

Elusive Errors

Some errors are almost impossible to spot, especially for beginners who know little or nothing about programming. For instance, can you spot the mistake in this line?

100 C = C + LEN(STR$(VAL(L$)) + 1

Here's how it should read:

100 C = C + LEN(STR$(VAL(L$))) + 1

Did you catch the difference? A right parenthesis was missing before the +1. (A left parenthesis must always have a matching right parenthesis. If you add up all the parentheses in a statement, you should get an even number.)

An Impossible Dream?

The strong point of computers is that they excel at tedious, exacting tasks. So why not get your computer to check your typing for you?

With "The Automatic Proofreader" nestled in your VIC-20, Commodore 64, or Atari computer, every line you type in will be verified. It displays a special code, called a checksum, at the top of the screen. The checksum, either a number (VIC/64) or a pair of letters (Atari), corresponds to the line you've just typed. It represents every character in the line summed together. A matching code in the program listing lets you compare it to the checksum which the Proofreader displays. A glance is all it takes to confirm that you've typed the line correctly.

The Automatic Proofreader is a small machine language program that resides in a normally unused area of memory. On the Atari, the program is stored in Page 6 ($0600), where it will safely remain until you turn your machine off, or run another program that uses Page 6. The Proofreader goes into the cassette buffer on the VIC and 64. Putting the Proofreader here does not use any of your BASIC program memory, but it can cause problems, which we'll cover a little later.

Entering The Automatic Proofreader

Commodore (VIC/64) owners should type in Program 1. Program 2 is for Atari users. Since the Proofreader is a machine language program, be especially diligent. Watch out for typing extra commas, or a letter O for a zero, and check every number carefully. If you make a mistake when typing in the DATA statements, you'll get the message "Error in DATA statements" when you RUN the program. Check your typing and try again.

When you've typed in The Automatic Proofreader, SAVE it to tape or disk at least twice before running it for the first time. If you mistype the Proofreader, it may cause a system crash when you first run it. By SAVEing a copy beforehand, you can reLOAD it and hunt for your error. Also, you'll want a backup copy of the Proofreader because you'll use it again and again—every time you enter a program from COMPUTE!.

When you RUN the Proofreader, the program will be POKEd safely into memory, then it will activate itself. If you ever need to reactivate it (RUN/STOP—RESTORE or SYSTEM RESET will disable it), just enter the command SYS 886 (VIC/64) or PRINT USR(1536) for the Atari.

Using The Proofreader

Now, let's see how it works. LIST the Proofreader program, move the cursor up to one of the lines, and press RETURN. If you've entered the Proofreader correctly, a checksum will appear in the top-left corner of your screen.

Try making a change in the line and hit RETURN. Notice that the checksum has changed. All VIC and 64 listings in COMPUTE! now have a number appended to the end of each line, for example, :rem 123. Don't enter this statement. It is just for your information. The rem is used to make the number harmless if someone does type it in. It will, however, use up memory if you enter it, and it will cause the checksum displayed at the top of the screen to be different, even if you entered the rest of the line correctly.

The Atari checksum is found immediately to the left of each line number. This makes it impossible to type in the checksum accidentally, since a program line must start with a number.

Just type in each line (without the printed checksum), and check the checksum displayed at the top of the screen against the checksum in the listing. If they match, go on to the next line. If they don't, there's a mistake. You can correct the line immediately, instead of waiting to find the error when you RUN the program.

The Proofreader is not picky with spaces. It will not notice extra spaces or missing ones. This is for your convenience, since spacing is generally not important. Occasionally proper spacing is important, but the article describing the program will warn you to be careful in these cases.

Nobody's Perfect

Although the Proofreader is an important aid, there are a few things to watch out for. If you enter a line by using abbreviations for commands, the checksum will not match up. This is because the Proofreader is very literal: It looks at the individual letters in a line, not at tokens such as PRINT. There is a way to make the Proofreader check such a line. After entering the line, LIST it. This makes the computer spell out the abbreviations. Then move the cursor up to the line and press RETURN. It should now match the checksum. You can check whole groups of lines this way. Atari users should beware of using ? as an abbreviation for PRINT—they're not the same thing in the Proofreader's eyes.

The checksum is a sum of the ASCII values of the characters in a line. VIC and 64 owners may wonder why the numbers are so small, never exceeding 255. This is because the addition is done only in eight bits. A result over 255 will roll over past zero, like an odometer past 99999. On the Atari, the number is turned into two letters, both for increased convenience and to make the Proofreader shorter. For the curious, the letters correspond to the values of the left and right nybbles added to 33 (to offset them into the alphabet). This number is then stored directly into screen memory.

Due to the nature of a checksum, the Proofreader will not catch all errors. Since 1 + 3 + 5 = 3 + 1 + 5, the Proofreader cannot catch errors of transposition. In fact, you could type in the line in any order, and the Proofreader wouldn't notice. Anytime the Proofreader seems to act strange, keep this in mind. Since the ASCII values of the number 18 (49 + 56) and 63 (54 + 51) both equal 105, these numbers are equal according to the Proofreader. There really is no simple way to catch these kinds of errors. Fortunately, the Proofreader will catch the majority of the typing mistakes most people make.

If you want the Proofreader out of your way, just press SYSTEM RESET or RUN/STOP—RESTORE. If you need it again, enter SYS 828 (VIC/64) or PRINT USR(1536) (Atari). You must disable the Proofreader before doing any tape operations on the VIC or 64.

Hidden Perils

The Proofreader's home in the VIC and 64 is not a very safe haven. Since the cassette buffer is wiped out during tape operations, you need to disable the Proofreader with RUN/STOP—RESTORE before you SAVE your program. This applies only to tape use. Disk users or Atari owners have nothing to worry about.

Not so for VIC and 64 owners with tape drives. What if you type in a program in several sittings? The next day, you come to your computer, LOAD and RUN the Proofreader, then try to LOAD the partially completed program so you can add to it. But since the Proofreader is trying to hide in the cassette buffer, it is wiped out!

What you need is a way to LOAD the Proofreader after you've LOADed the partial program. The problem is, a tape load to the buffer destroys what it's supposed to load.

After you've typed in and RUN the Proofreader, enter the following lines in direct mode (without line numbers) exactly as shown:

A$="PROOFREADER.T" : B$="{10 SPACES}": FOR
   X = 1 TO 4 : A$=A$+B$ : NEXTX
FOR X = 886 TO 1018: A$=A$+CHR$(PEEK(X)) :
   NEXTXOPEN 1, 1, 1, A$ : CLOSE1

After you enter the last line, you will be asked to press record and play on your cassette recorder. Put this program at the beginning of a new tape. This gives you a new way to load the Proofreader. Anytime you want to bring the Proofreader into memory without disturbing anything else, put the cassette in the tape drive, rewind, and enter:

OPEN1:CLOSE1

You can now start the Proofreader by typing SYS 886. To test this, PRINT PEEK(886) should return the number 173. If it does not, repeat the steps above, making sure that A$ ("PROOFREADER. T") contains 13 characters and that B$ contains 10 spaces.

You can now reload the Proofreader into memory whenever LOAD or SAVE destroys it, restoring your personal typing helper.

Incidentally, you can protect the cassette buffer on the Commodore 64 with POKE 178,165. This POKE should work on the VIC, but it has caused numerous problems, probably due to a bug in the VIC operating system. With this POKE, the 64 will not wipe out the cassette buffer during tape LOADs and SAVEs.

Program 1: VIC/64 Proofreader

100 PRINT"{CLR}PLEASE WAIT…" : FORI=886TO
    1018 : READA : CK=CK+A : POKEI, A : NEXT
110 IF CK<>17539 THEN PRINT"{DOWN}YOU MAD
    E AN ERROR" : PRINT" IN DATA STATEMENTS.
    " : END
120 SYS886 : PRINT"{CLR}{2 DOWN}PROOFREADER
     ACTIVATED." : NEW
886 DATA 173, 036, 003, 201, 150, 208
892 DATA 001, 096, 141, 151, 003, 173
898 DATA 037, 003, 141, 152, 003, 169
904 DATA 150, 141, 036, 003, 169, 003
910 DATA 141, 037, 003, 169, 000, 133
916 DATA 254, 096, 032, 087, 241, 133
922 DATA 251, 134, 252, 132, 253, 008
928 DATA 201, 013, 240, 017, 201, 032
934 DATA 240, 005, 024, 101, 254, 133
940 DATA 254, 165, 251, 166, 252, 164
946 DATA 253, 040, 096, 169, 013, 032
952 DATA 210, 255, 165, 214, 141, 251
958 DATA 003, 206, 251, 003, 169, 000
964 DATA 133, 216, 169, 019, 032, 210
970 DATA 255, 169, 018, 032, 210, 255
976 DATA 169, 058, 032, 210, 255, 166
982 DATA 254, 169, 000, 133, 254, 172
988 DATA 151, 003, 192, 087, 208, 006
994 DATA 032, 205, 189, 076, 235, 003
1000 DATA 032, 205, 221, 169, 032, 032
1006 DATA 210, 255, 032, 210, 255, 173
1012 DATA 251, 003, 133, 214, 076, 173
1018 DATA 003

Program 2: Atari Proofreader

100 GRAPHICS 0
110 FOR I=1536 TO 1700 : READ A : POKE I,
    A : CK=CK+A : NEXT I
120 IF CK<>19072 THEN ? "Error in DA
    TA statements. Check typing" : END
130 A=USR(1536)
140 ? : ? "Automatic Proofreader now
    activated."
150 END
1536 DATA 104, 160, 0, 185, 26, 3
1542 DATA 201, 69, 240, 7, 200, 200
1548 DATA 192, 34, 208, 243, 96, 200
1554 DATA 169, 74, 153, 26, 3, 200
1560 DATA 169, 6, 153, 26, 3, 162
1566 DATA 0, 189, 0, 228, 157, 74
1572 DATA 6, 232, 224, 16, 208, 245
1578 DATA 169, 93, 141, 78, 6, 169
1584 DATA 6, 141, 79, 6, 24, 173
1590 DATA 4, 228, 105, 1, 141, 95
1596 DATA 6, 173, 5, 228, 105, 0
1602 DATA 141, 96, 6, 169, 0, 133
1608 DATA 203, 96, 247, 238, 125, 241
1614 DATA 93, 6, 244, 241, 115, 241
1620 DATA 124, 241, 76, 205, 238, 0
1626 DATA 0, 0, 0, 0, 32, 62
1632 DATA 246, 8, 201, 155, 240, 13
1638 DATA 201, 32, 240, 7, 72, 24
1644 DATA 101, 203, 133, 203, 104, 40
1650 DATA 96, 72, 152, 72, 138, 72
1656 DATA 160, 0, 169, 128, 145, 88
1662 DATA 200, 192, 40, 208, 249, 165
1668 DATA 203, 74, 74, 74, 74, 24
1674 DATA 105, 161, 160, 3, 145, 88
1680 DATA 165, 203, 41, 15, 24, 105
1686 DATA 161, 200, 145, 88, 169, 0
1692 DATA 133, 203, 104, 170, 104, 168
1698 DATA 104, 40, 96