Classic Computer Magazine Archive COMPUTE! ISSUE 50 / JULY 1984 / PAGE 130

Applesoft Lister

David Dobrin

"Applesoft Lister" will give you more readable program listings, along with printer-oriented output, translated control characters, and indention of nested FOR-NEXT loops.

Would you like your Applesoft programs to look like this:

10 REM BASIC LISTING WITH APPLESOFT LIST
20 HOME
22 PRINT   "ANT SCRAM[G] [G] [G]"
30 FOR J=0 TO 35
31 VTAB 2
   : HTAB J+l
40 PRINT   "   ;=;@"
50 NEXT
60 PRINT   "[G][G][G]THAT   IS   ALL"

instead of this:

10 REM BASIC LISTING WITH APPLESOFT LIST
20 HOME
22 PRINT "ANT SCRAM"
30 FOR J = 0 TO 35
31 VTAB 2: HTAB J + l
40 PRINT " ; = ;@"
50 NEXT
60 PRINT "THAT IS ALL"

Applesoft programs are usually very difficult to read. The standard LIST function built into Applesoft is unsophisticated, having only the minimum logic necessary to list programs. Here's a program for the Apple that will list Applesoft programs in a nicely formatted fashion. Five major features distinguish "Applesoft Lister" from the standard format:

  • There is intelligent spacing between keywords, variables, and operands.
  • Multiple statements with a single line number are listed one per line.
  • FOR-NEXT constructs are nested.
  • Output is oriented for a printer. This listing will not simply "wrap" when it runs out of space on a line.
  • Control characters are shown with printable characters.

How Applesoft Lister Works

The program translates the Applesoft intermediate language (IL) into statement numbers and keywords. The keywords are taken from ROM at $D0D0. If this program is to be used with Applesoft in RAM, this value must be changed.

The high byte of the keyword table address is at location $812C. The low byte is at $8130.

When a colon (:) is encountered in the text, the lister starts a new line, indenting appropriately. No action is taken on colons inside double quotes or REM statements. FORs and NEXTs are observed to calculate a nest level.

If you would like to change the indentation of your FOR-NEXT constructs or multiple statements you can change the value at location 32771 with the POKE command. Putting a 0 there will turn indenting off, a 3 will indent three spaces per nest level, a 10 will indent ten spaces per nest level, and so on.

If you want to change the column width, change the value at 32772 with the POKE command. Putting a 39 there will give a screen width. You can also use 80, 132, or whatever your printer width is.

These POKEs can, of course, be made permanent by saving the program to disk or tape after changing.

Control characters are printed inside brackets; for example, CTRL-G appears as [G].

Loading The Program Into Your Apple

The lister program is written entirely in machine language. Program 1 is a BASIC program which READs the machine language from DATA statements and POKEs it into memory.

The program was assembled to load at location $8000. If your machine has less than 48K, the program will have to be relocated.

If you wish to enter the machine language, you can do so by using the Apple monitor (CALL -151). Enter the hex values as shown in Program 2. The Apple Reference Manual, Chapter 3, details the use of the resident monitor.

Once the program is entered into the Apple either by the loader or from the monitor, it should be saved to disk or tape before going any farther. This can be done by typing:

JBSAVE ALIST,A$8000,L$2F0

or

*8000.82F0W

Running Applesoft Lister

After the program has been stored, it can be utilized by loading the Applesoft program to be listed in the usual manner. The list program can then be loaded with:

JBLOAD ALIST

or

JCALL-155
*8000.82FOR
*(CTRL-C)

The listing program can then be run by typing:

JPR#x (where x is the slot for your printer interface, if you want the output to go to a printer)
JCALL 32768