Classic Computer Magazine Archive COMPUTE! ISSUE 88 / SEPTEMBER 1987 / PAGE 95

Applesoft Line Lister

Bruce E. Howell, D.D.S.

If you find yourself wading through a difficult-to-decipher BASIC program listing, take the time to type in this short and very useful utility which unravels even the most complex program lines. The program works with any Apple II-series computer.

It's understandable that programmers want to write programs that are as fast and compact as possible. In BASIC programming, it is common to place several statements on a single line, separating each with a colon. Unfortunately, this can lead to dense programs that can be difficult to debug. "Applesoft Line Lister" alleviates this problem. It's a short and simple machine language program that makes any Applesoft BASIC program listing easier to read and understand.

Instead of completely rewriting BASIC's LIST routine, Line Lister simply intercepts the output from the routine and reformats it. Programs are still stored in their most compact form, but, when they are listed, each statement is placed on its own line for maximum readability.

Typing It In

Applesoft Line Lister is a short machine language program. To create it, type in and save a copy of the BASIC listing found below. Since the BASIC program creates a machine language file named LISTER, do not use that name for the BASIC program itself. To create a copy of the Line Lister machine language program, load the BASIC program, insert the disk on which you want a copy of Line Lister, and type RUN. The machine language program, LISTER, is saved to the disk. Once the Line Lister program is created, you won't need the BASIC program again except to make additional copies of Line Lister.

When you're ready to use Line Lister, type one of the following lines, depending on the version of DOS that you are using.

For DOS:
For ProDOS:

This loads and installs—but does not activate—the machine language routine. To enable the new listing mode, type &.

Here's how a sample BASIC program line is listed by Applesoft's built-in routine:

100 PRINT : PRINT : FOR A = 100
TO 1 STEP - 1 : B = B + 1 : NEXT

Line Lister displays this instead:

: FOR A = 100 TO 1 STEP - 1
: B = B + 1

Line Lister works best in 80-column mode or on a printer. Long display lengths insure that the entire statement fits on a single line. In the case of a very long statement, such as a long PRINT command or a complex formula, the output will wrap around to the next output line.

To turn off the enhanced listing mode, type PR#0 (or'PR#3 if you're using 80 columns) or press Ctrl—Reset. Be sure to turn off Line Lister before changing a line or entering a new one. ProDOS users should also turn off Line Lister before requesting a disk catalog. The program can be restarted simply by typing & again.

How It Works

When executed, Line Lister sets up the ampersand vector to point to the enhanced listing routine. That routine works by intercepting characters on their way to the output device (such as the video display or printer), deleting or inserting spaces and new lines as required. Since the output routine vector is in different locations for DOS 3.3 and ProDOS, it is necessary to determine which operating system is in effect.

If ProDOS was booted, a group of file-manipulating subroutines called the Machine Language Interface will be found in memory beginning at location $BF00, so a machine language JMP instruction ($4C) at that location indicates that ProDOS is being used. Within ProDOS, location $BE30 (known as VECOUT) contains the address of the current output device. Line Lister first saves the current contents of the output vector so that it can send characters to the correct output device. Next, it stores the address of its own listing routine in the vector, rerouting all output through the new routine.

If no JMP instruction is found in the test location, Line Lister assumes that DOS 3.3 is being used. The output vector for DOS 3.3 is called CSW and is found at location $36. Line Lister changes the vector address as for ProDOS, then jumps through the vector at $3EA to update the DOS output routines.

In either case, control is then returned to Applesoft. Now, all characters sent to the current output device will be processed by Line Lister.

One of the program's jobs is to keep track of whether or not characters being output are enclosed in quotation marks. When a quotation mark (") is detected, the program passes the characters through, unformatted, until the next quotation mark is found, or until the end of the line is reached. This prevents Line Lister's special formatting from affecting text within quotation marks, such as the text of PRINT statements.

The program's most important task is to scan the outgoing text for colons. If the character to be printed is a colon, and if it's now within quotation marks, the program sends a carriage return character followed by a colon and several blank spaces.

For other characters, the program checks to see if the current and previous characters are spaces. If both are spaces not enclosed in quotation marks, then the program moves on without sending the last space. This causes superfluous spaces outside of quotation marks to be discarded.

Applesoft Line Lister

For instructions on entering this program, please refer to "COMPUTE!'s Guide to Typing In Programs" elsewhere in this issue.

42 7 FOR X = 1 TO 1500 : NEXT
D1 10 C = 0 : FOR I = 768 TO 897
A5 20 READ A : POKE I, A :C = C + A
A6 30 NEXT
70 40 IF C < > 15288 THEN PRINT "BAD DATA" : END
15 50 PRINT CHR$ (4) "BSAVE LISTE R, A$300, L$81"
F1 60 END
AF 100 DATA 169, 76, 141, 245, 3, 169, 16, 141, 246, 3, 169
EE 110 DATA 3, 141, 247, 3, 96, 173, 0, 191, 201, 76, 240
86 120 DATA 23, 173, 83, 170, 141, 125, 3, 173, 84, 170, 141
27 130 DATA 126, 3, 169, 69, 133, 54, 169, 3, 133, 55, 76
53 140 DATA 234, 3, 173, 48, 190, 141, 125, 3, 173, 49, 190
A5 150 DATA 141, 126, 3, 169, 69, 141, 48, 190, 169, 3, 141
B8 160 DATA 49, 190, 96, 201, 162, 208, 10, 173, 127, 3, 73
6D 170 DATA 255, 141, 127, 3, 169, 162, 44, 127, 3, 48, 33
20 180 DATA 201, 186, 208, 20, 32, 142, 253, 169, 186, 32, 124
5B 190 DATA 3, 162, 3, 169, 160, 32, 124, 3, 202, 208, 248
68 200 DATA 240, 9, 201, 160, 208, 5, 205, 128, 3, 240, 203
D1 210 DATA 141, 128, 3, 76, 255, 255, 0, 0, 3