Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 11, NO. 8 / AUGUST 1985 / PAGE 84

Legible listings; you can make your Basic program listings easier to read with on of these five programs. David H. Ahl.

Are your Basic program listings difficult to follow? At the end of a line, do you find it annoying to have words broken in the middle? When you try to debug a program, is it hard to find the beginning and end of each FOR loop? Well, help is on the way.

In the September 1983 issue of Creative Computing, we ran a short program to produce legible listings on the Tandy Model 100. At the end of the article, we challenged readers to write improved programs for other countries. The outpouring was overwhelming. We received nearly 100 programs for 20 different computers.

We chose the bets program for each of five computers--Apple, Atari, Commodore 64, TRS Model I/III/4, and Kaypro (MBasic)--to present here. A few notes are presented with each listing which explains how it works. Minimally, each program separates multiple statements on one line into separate lines, but, as a glance at the listings shows, some of them do far more than that.

Needless to say, these programs don't make a structured program out of an unstructured one, or make a convoluted program into a straightforward one. They do, however, make reading the program listing of any program far easier.


We receive many entries for the Apple, in both Basic and machine language. We felt that the ideal program should be fast, simple, and elegant. Thus, we eliminated several of the machine code programs, which were more than five pages long, and some of the Basic programs, which were very s-l-o-w.

The winning program was submitted by Rajiv P. Sarathy, a student in the Universty of Toronto Schools. You can either type in the machine language program and assemble it, or you can type in the memory dump. If you choose to go with the memory dump, type it as follows:

0300:A9 OB 85 36 A9 03 85 37


Like the Apple, the Atari saves programs as tokenized files. All of the Atari entries required that the program to be listed be converted to an untokenized (text) file, an inelegant but workable approach. To save a program in this format, you must load it into the computer and then LIST it back to the disk or cassette tape. You then execute the NEW command and load and run the program.


All of the Commodore entries also required that the program to be listed be saved as an untokenized file on disk or cassette tape. The instructions for doing this are included in the program notes.

TRS-80 Models I, II, III, and 4

We received more entries for the TRS-80 family of computers than for any other. Again, all of them require programs to be saved as untokenized files. On the TRS-80, this can be done with the command:

SAVe "filename/ext",A

Jean Phillippe Jobe of Panama submitted a particularly sophisticated program that allowed setting of printer codes for normal, condensed, or emphasized type; automatic insertion of a line END, RETURN or RUN; indention for each FOR loop; and a very fancy heading on each page. Unfortunately, the program was 180 lines long so we chose to print a shorter program by Sylvan Butler.

Microsoft Basic

Although Applesoft Basic and TRS-80 Basic are derivatives of Microsoft Basic, they have subtle differences between "standard" Microsoft Basic as found on the IBM PC (and clones) and CP/M systems such as the Kaypro. Hence, we lumped all the entries in Microsoft Basic together and chose as the winner the one from Walter Castles written for the Kaypro II.

Somewhat surprisingly, these programs were the least sophisticated of all those submitted. Could it be that owners of machines of this kind use mostly off-the-shelf software and aren't into programming?

Other Computers

We also received programs for the TRS-80 Color Computer, Epson HX-20, TI 99/4A, Timex Sinclair 1000, and several others. However, we think that if you have one of these machines, or any other computer, you can study the techniques in the program listings presented here and easily write a program for your computer. Good programming!

Apple Program Notes

Writing this program, I soon realized that it was not as easy as I originally thought it would be. This was because it was a cumbersome ordeal to save an Applesoft program in ASCII, since the computer saves it as tokens. I decided there should be an easier way. "Why not convert the tokens using the LIST routine?" I asked myself.

Lines 3 through 7 are just EQUates, telling the assembler where these locations are. CSWL and CWSH are pointers that tell DOS where to find the routine that disposes of output characters. $46 hex is where the computer stores the X-register when the IOSAVE routine is called. Lines 11 through 15 set up the CSWL and CSWH pointers. The assembler I used, Lisa 1.5, uses #LABEL and /LABEL for low and high bytes, respectively. Line 15 jumps to the routine where DOS reconnects the keyboard and screen streams.

When a character is to be output, DOS sends it to line 19. Line 19 checks to see if the character is a return/linefeed. If so, it branches to the routine that takes care of the return (line 34). Next, it checks to see if the character is a colon. If not, it prints the character. It ten prints the colon, and goes to the routine (line 34) that handles a return. Following the return, four spaces are sent to the printer. (In line 25, put the number of spaces minus 2.) Lines 32 and 33 are storage points within the program for various values.

Line 34 increments the number of lines printed, then checks to see if it is 65. This is for 66-line paper. If 65 lines have not been printed, the program sends a CRLF, and returns. If 65 lines have been printed, it prints the string and a CRLF, and returns.

Line 58 contains the length of the string; the string is placed in line 59 and onwards. (The Basic program shows how to enter a string.) This string will be printed on the first line of every page.

To use the program type the following from Basic:

CALL 768:CALL 823


This program can be used in Integer Basic and applesoft Basic and in your own programs that use either the simple PRINT statement or the monitor's COUT Subroutine.

Some assemblers, such as Lisa 1.5 equate characters in quotes (lines 21 and 27) with the high bit low, as in my listing. For the program to work, you need to change it to high bit on. After typing in the memory dump, or assembling the program, type:

CALL-151 (from Basic)



Atari Program Notes

This program is capable of listing either a disk or cassette file in LISTed format without merging. It also allows the use of a colon with a literal PRINT statement.

Lines 120 to 130 dimension variables and set up the page and flags. Line 140 determines if a disk or cassette file is to be used. If it is a cassette file, line 150 skips the directory search. Lines 160 to 200 open a file, read the specified disk directory, and print it to the screen for reference.

Lines 210 to 240 get the program name, the date, and page break information. Line 250 opens the specified file for input. This works for a cassette, even though cassettes don't have file names.

Line 260 prints the page heading, and 270 spaces it. Line 280 gets one character from the file. Line 290 checks to see if it is a quotation mark and updates the colon flag if needed. Line 300 checks for the Atari end of line marker CHR$(155). Line 310 adds the character to the line image string. Line 320 returns for another character if the present one is not a colon or if the colon flag indicates that it is in a literal PRINT statement. Line 330 prints the line image string and spaces the next line over four to produce the "fancy" listing.

Lines 340 and 350 check the line count and skip to the top of the next page if necessary. Finally, line 360 is the result of the trap on the end of file and closes the open file.

Commodore Program Notes

This program is for any Commodore computer with Basic 4.0, a disk drive, and a 4022 or 8023 printer. Unlike the original program, this version will not break a program line if the colon is in a literal string.

The program, unfortunately, must read the disk file and single character at a time. Commodore disk input is somewhat unusual, and a single-character GET is the only way to insure an accurate read when the file may contain commas, colons, or quotation marks.

Using this program requires that a text version of the program to be listed be stored in a disk file named list.file. The following code creates a list.file containing a listing of the program currently in memory:

SCRATCH "list.file"

DOPEN #1, "list.file",W



You should now load and run the formatting program. The program will prompt you for the date, the title to give the listing, choice between continuous or paged printing, and upper-or lowercase printout. Uppercase mode prints uppercase letters and graphics characters used in most game listings; lowercase mode prints lower-and uppercase letters. The program defaults to continuous printout and uppercase printout.

The reversed (white on black) characters in the listing are control codes. The reversed S represents clear screen, and the reversed right bracket represents cursor left. These codes are entered with the shifted CLR/HOME and shifted CRSR/left-ring keys, respectively.

To use this program with a Commodore 64, Vic 20, or Pet with Basic 2.0 change the file OPEN commands in line 180 and the printer lowercase control in line 177. The rest of the program can be used almost as-is. Similar changes allow the program to be used with a cassette system.

TRS-80 Model III Program Notes

To run this program, save the program to be listed in ASCII format on disk and then run the lister program.

Line 50 clears the screen and some string space, defines all variables as integers, and displays the title. Line 60 sets the page length (PL) and the minimum lines to print (LP). Lines 70 to 100 ask for a filename, open the file, and ask if you want a continuous listing or one separated into pages.

Lines 110 and 120 increment the pages printed (PG), print page title, skip the next line, and set the line counter (LC) for the two lines printed.

In line 130, one line of the program is read from disk, and the end of file is tested.

Lines 140 and 150 separate the line number from the remainder of the line, and set the print string (P$) equal to the line number.

In line 160 the search starting position (P) is set to zero to check the entire line. The loop in lines 170 to 190 finds a colon and checks whether it is between quotes or not. If so, the search starting position is incremented to the closing quotes, and the loop is repeated.

Line 200 adds the characters in the line, up to and including the colon, to the print string, and GOSUBS the print routine. On return, the print string is set equal to as many spaces as there are digits in the line number, plus one. What was printed is subtracted from the line in 210 and the line is tested for characters remaining.

Lines 220 and 230 test whether pagination is wanted and enough lines have been printed. If so, blank lines are printed to move the next page. Line 240 is executed when the end of file is reached. It then closes the file, clears the screen, and terminates program execution.

Line 250, a subroutine, prints the characters stored in the print string and increments the line counter.

FANCYLST/BAS will work with most programs, but a long print statement without colons will cause the line count in the program to be inaccurate.

Microsoft Basic Program Notes

The only requirement to run this program is that the program you want to list be saved on the disk in ASCII format. This is done at the time the program is saved by adding a comma and a capital A after the name of the program, i.e. SAVE"FORMLIST.BAS",A.

The only line that is machine specific is line 110. The "PRINT CHR$(26)" statement is used to clear the screen on the Kaypro.