Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 9, NO. 9 / SEPTEMBER 1983 / PAGE 249

Legible listings with the TRS-80 Model 100. David H. Ahl.

If you read our review last issue of the TRS-80 Model 100 and the essentially similar NEC PC-8201, you know we were enthusiastic about both computers. However, one area in which they fell down was in their ability to produce formatted output.

As a small step in overcoming this, Radio Shack included a "Fancy Program Listing" program on page 204 of the Model 100 manual. Unfortunately, the program doesn't work. Not only are several lines of code missing, but some of the logic is just plain wrong.

Listing 1 is a corrected and improved version of the Radio Shack program. It is instructive to examine just how it works.

Lines 120 to 140 do some housekeeping and set initial values to the page counter (PG=0) and lines per page (Z=65). Depending upon the printer you use, Z might have to be set to either 65 or 66.

Line 150 simply displays all the files currently in the computer. However, only document files (suffix .DO) may be listed with this program. There are several ways to convert a basic program int a document file for printing. The easiest is to select the program from the menu, break into Basic, and hit function Key 3. The screen will then display: Save " Type whatever you want the program to be named, followed by a close quote, comma, and A. For example, Save "Lines", A This saves the program in ASCII format as Lines.DO, i.e., as a document file.

Lines 160 and 170 request the name of the file and whether you want a continuous listing or a paginated one. The document (.DO) file that you specify is opened for input in Line 180.

Lines 190 and 200 print a page header (program name, date, and page number), skip a line, and increment the line counter by two.

A single character (IN$) is read from the file in Line 210. If the character is an end of file market (EOF(1) is true) then the program branches to Line 290 where the last character (the end of file marker) is deleted from the end of the print string (PR$) before this string is printed out in Line 300.

If the character read in Line 210 is not an end of file marker, it is added to the print string in Line 220.

The next few lines test if the last character read was a carriage return. If so, the last two characters are deleted from the print string. Pressing the ENTER key in Basic actually produces two characters, a linefeed and a carriage return; both must be deleted from the print string since the LPRINT command (Line 250) automatically sends a linefeed/carriage return to the printer and we don't want the printer getting this pair of instructions twice.

If the last character was a colon (:) or statement separator, the line to that point is printed, and four spaces are added to the beginning of the new print string (Line 260). Hence, when the next statement is printed, it will be indented four spaces, and, assuming three-digit line numbers, will line up with the numbered statements.

If the listing is to be continuous, Line 270 skips the routine that tests for the end of a page (56 or more lines printed). If the output is to be in pages, Line 310 skips the 9 or 10 lines to the top of the next page, and branches back up to the page header routine.

On the other hand, if the end of file indicator has been set (X=1) in Line 210, the program ends.

While this program produces nice looking listings of most programs (see Listings 2a and 2b), it creates a mess if a colon is used for anything other than separating statements on a single line. For example, if you set time or date in a program (not likely) or use a colon in a print string (more likely), the listing will skip to a new line and insert four spaces. A Challenge to Readers

This general procedure will work for computers other than the TRS-80 Model 100 and NEC 8201. For cassette-based systems, the procedure will probably have to be a subroutine with high line numbers that coexists with the program to be listed. To combine the two programs without having to retype the lister each time will require a merge procedure.

For disk systems, the approach is somewhat easier. However, since it is undesirable to read a single character at a time from the disk (much too slow), a line or the entire file would have to be brought into a buffer at one time, and the listing routine applied to that.

We would like to see such a program for every small computer and will pay $25 to the first submission for each different machine. Submissions should include the program, one or two sample runs, and a short explanation of how it works and description of how to use it (typed, double space). Listings should be made with a dark ribbon that can be reproduced in the magazine.