Classic Computer Magazine Archive COMPUTE! ISSUE 70 / MARCH 1986 / PAGE 91

The New Automatic Proofreader For Commodore

Philip I. Nelson, Assistant Editor

Now it's easier than ever to type in Commodore programs published in COMPUTE!. This completely new version of the Automatic Proofreader is a significant improvement over the old Proofreader and catches almost any typing mistake that can be made. A single version now works on the Commodore 64, 128, V1C-20, Plus/4, and 16. Starting with this issue, all BASIC programs published in COMPUTE! for these computers are listed in the new Proofreader format. They cannot be checked with the old Proofreader.

"The New Automatic Proofreader" is a short error-checking program that helps you type in COMPUTE! program listings without typing mistakes. The Proofreader conceals itself in memory and doesn't interfere with the program you're typing. Each time you press RETURN to enter a program line, the Proof-reader displays a two-character value called a checksum in reverse video at the top of your screen. If you've typed the line correctly, the checksum on the screen matches the one in the printed listing—it's that simple. You don't have to use the Automatic Proofreader to enter computers printed listings, but doing so greatly reduces your chances of making a typo.

Getting Started

First, type in the Automatic Proof-reader program below exactly as it appears in the listing. Since the Proofreader can't check itself before it exists, type carefully to avoid mistakes. Don't omit any lines, even if they contain unfamiliar commands or you think they don't apply to your computer.

When you're finished, save at least two copies on disk or tape before running it for the first time. This is very important because the Proofreader erases the BASIC portion of itself when it runs, leaving only the machine language (ML) portion in memory.

When that's done, type RUN and press RETURN. After announcing which computer it's running on, the Proofreader installs the ML routine in memory, displays the message PROOFREADER ACTIVE, erases the BASIC portion of itself, and ends. If you type LIST and press RETURN, you'll see that no BASIC program remains in memory. The computer is ready for you to type in a new program listing.

Entering Programs

Once the Proofreader is active, you can begin typing in a BASIC program as usual. Every time you finish typing a line and press RETURN, the Proofreader displays the two-letter checksum in the upper-left corner of the screen. Compare this checksum with the two-letter checksum printed next to the corresponding line in the COMPUTE! program listing. If the letters match, you can be pretty certain the line is typed correctly. Otherwise, check for a mistake and correct the line. The Proofreader ignores space characters that aren't enclosed in quotation marks, so you can omit spaces (or add extra ones) between keywords and still see a matching checksum. For example, these two lines generate the same checksum:

10 PRINT"THIS IS BASIC"
10 PRINT      "THIS IS BASIC"

However, since spaces inside quotation marks are generally significant, the Proofreader pays attention to them. For instance, these two lines generate different checksums:

10 PRINT"THIS IS BASIC"
10 PRINT"THIS ISBA           SIC"

A common typing mistake is transposition—typing two successive characters in the wrong order, like PIRNT instead of PRINT or 64378 instead of 64738. The old Commodore Proofreader couldn't detect transposition errors. Because the new Proofreader computes the checksum with a more sophisticated formula, it is sensitive to the position of each character within the line and thus catches transposition errors.

The Proofreader does not accept keyword abbreviations (for example, typing? instead of PRINT). If you prefer to use abbreviations, you can still check the line with the Proofreader: Simply LIST the line after typing it, move the cursor back onto the line, and press RETURN. LISTing the line substitutes the full keyword for the abbreviation and allows the Proofreader to work properly. The same technique works for rechecking a program you've already typed in: Reload the program, LIST several lines on the screen, and press RETURN over them.

If you are using the Proofreader on the Commodore Plus/4, 16, or 128 (in 128 mode), do not perform any GRAPHIC commands while the Proofreader is active. When you perform a command like GRAPHIC 1, the computer moves everything at the start of BASIC program space—including the Proofreader—to another memory area, causing the Proofreader to crash. The same thing happens if you run any program that contains a GRAPHIC command. The Proofreader deallocates any graphic areas before installing itself in memory, but you are responsible for seeing that the computer remains in this configuration.

Though the Proofreader doesn't interfere with other BASIC operations, it's always a good idea to disable it before running any other program. Some programs may need the space occupied by the Proofreader's ML routine, or may create other memory conflicts. However, the Proofreader is purposely made difficult to dislodge: It's not affected by tape or disk operations, or by pressing RUN/ STOP-RESTORE. The simplest way to disable it is to turn the computer off, then on again.

A gentler method to disable the Proofreader is to SYS to the computer's built-in reset routine. Here are the SYS statements required for various Commodore computers:

Computer Reset Command
64 SYS 64738
128 SYS 65341
VIC-20 SYS 64802
Plus/4 SYS 65S26
16 SYS 65526

Inside The Commodore Proofreader

Writing a machine language program that works on five different computers is no small task. The first hurdle is finding a safe place to put the code. Though the cassette buffer is an obvious choice, it's located in different places on various machines, and putting ML there creates problems for tape users. Instead, the Proofreader uses 256 bytes of BASIC programming space.

Before it installs the routine in memory, the Proofreader checks which computer you're using. Then it stores the ML at the bottom of BASIC memory and protects itself by moving the computer's start-of-BASIC pointer to a spot 256 bytes higher in memory. Once that's done, the Proofreader activates the ML routine and erases itself with NEW. Note that because the Proof-reader overwrites its first few BASIC lines, it's critical not to delete anything from the first portion of the program.

The ML portion of the Proof-reader wedges into one of the operating system's built-in routines (CRUNCH). The system calls CRUNCH every time you enter a line from the keyboard (it can be a numbered program line or a direct command without a line number). Before the computer digests the line, it uses CRUNCH to convert BASIC keywords like PRINT into tokens—one- or two-byte numbers that represent the keyword. By changing the CRUNCH vector to point to the ML checksum routine, we can make the computer figure the checksum before it tokenizes the line with CRUNCH.

The checksum routine initially sets the checksum to equal the low-byte and high-byte values of the current line number. Then it scans the line, multiplying the ASCII value of each character by its position in the line and adding the result to the two-byte checksum as it moves down the line. After scanning the whole line, the Proofreader performs an exclusive or operation on the two bytes of the checksum and displays the final result as two alphabetic characters in reverse video. Though the final checksum could have been displayed as a two-digit hexadecimal number, the Proofreader uses letters so that no harm will be done if you accidentally press RETURN over the line containing the checksum.

Once this is done, the Proof-reader restores everything to normal and jumps to CRUNCH, which handles the line as usual.

Commodore Compatibility

If you own a Commodore 64, you may already have wondered whether the Proofreader works with other programming utilities. The answer is generally yes, if you are using a 64 and if you activate the Proofreader after installing the other utility. There's no way to promise, of course, that the Proof-reader will work with any and every combination of utilities you might want to use. Any program that disturbs the CRUNCH vector or the memory area where the Proofreader resides will probably crash the system without delay.

When using the Proofreader with another utility, you should disable both programs before running a BASIC program.

The New Automatic Proofreader For Commodore

10 VEC = PEEK(772) + 256 * PEEK(773): 1,0 = 43 :HI = 44
20 PRINT "AUTOMATIC PROOFREADER FOR ";:IF VEC = 42364 THEN{SPACE}PRINT "C-64"
30 IF VEC = 50556 THEN PRINT "VC-20"
40 IF VEC = 35158 THEN GRAPHIC CLR:PRINT "PLUS/4 & 16"
50 IF VEC = 17165 THEN L0 = 45:HI = 46:GRAPHIC CLR:PRINT"128"
60 SA = (PEEK(LO) + 256 * PEEK(HI)) + 6:ADR = SA
70 FOR J = 0 TO 166:READ BYT:POKE ADR,BYT:ADR = ADR + 1:CHK = CHK + BYT:NEXT
80 IF CHK<>20570 THEN PRINT " * ERROR * CHECK TYPING IN DATA STATEMENTS":END
90 FOR J = 1 TO 5:READ RF,LF,HF: RS = SA + RF:HB = INT(RS/256) :LB = RS-(256 * HB)
100 CHK = CHK + RF + LF + HF:POKE SA + L F,LB:P0KE SA + HF,HB:NEXT
110 IF CHK<>22054 THEN PRINT " * ERROR * RELOAD PROGRAM AND {SPACE}CHECK FINAL LINE":END
120 POKE SA + 149,PEEK(772):POKE SA + 150,PEEK(773)
130 IF VEC = 17165 THEN POKE SA + 14,22:POKE SA + 18, 23:POKESA + 29,224:POKESA + 139,224
140 PRINT CHR$(147);CHR?(17);" PROOFREADER ACTIVE":SYS SA
150 POKE HI,PEEK(HI) + l:POKE (PEEK(LO) + 256 * PEEK(HI))-1,0:NEW
160 DATA 120, 169, 73, 141, 4, 3, 169, 3, 141, 5, 3
170 DATA 88, 96, 165, 20, 133, 167,165, 21, 133, 168, 169
180 DATA 0,141,0,255,162,31,181, 199, 157, 227, 3
190 DATA 202, 16, 248, 169, 19, 32,210, 255, 169, 18, 32
200 DATA 210, 255, 160, 0, 132, 180,132,176,136,230,180
210 DATA 200, 185, 0, 2, 240, 46, 201, 34, 208, 8, 72
220 DATA 165, 176, 73, 255, 133, 176, 104, 72, 201, 32, 208
230 DATA 7, 165, 176, 208, 3, 104, 208, 226, 104, 166, 180
240 DATA 24, 165, 167, 121, 0, 2, 133, 167, 165, 168, 105
250 DATA 0, 133, 168, 202, 208, 239, 240, 202, 165, 167, 69
260 DATA 168, 72, 41, 15, 168, 185, 211, 3, 32, 210, 255
270 DATA 104, 74, 74, 74, 74, 168, 185, 211, 3, 32, 210
280 DATA 255, 162, 31, 189, 227, 3, 149, 199, 202, 16, 248
290 DATA 169, 146, 32, 210, 255, 76, 86, 137, 65, 66, 67
300 DATA 68, 69, 70, 71, 72, 74, 75, 77, 80, 81, 82, 83, 88
310 DATA 13, 2, 7, 167, 31, 32, 151, 116, 117, 151, 128, 129, 167, 136, 137