Three Pet Tricks
John F. Garst
Department of Chemistry
The University of Georgia
This magazine and others have published numerous PET programming methods that are not evident from reading the documentation provided by Commodore. Sometimes there is a subtle way of using what Commodore tells about. Then there are those things Commodore forgot to mention. Here are three tricks that I use.
On-line Remarks
With a PET, on-line remarks are made as follows, according to Commodore.
200 GOSUB 500 : REM OUTPUT
Both the statement-delimiting colon and the REM statement must precede the remark. Other implementations of BASIC allow the use of an apostrophe in the place of both of these, making programs more readable.
200: GOSUB 500 'OUTPUT
The PET actually allows the construction just given! However, the PET does not use the apostrophe as an abbreviation for REM. In fact, the PET allows the following construction.
200: GOSUB 500 OUTPUT
Nonnumeric character strings that follow the target line number of a GOTO, GOSUB, or THEN statement are ignored. This is not true for all other kinds of statements. Nonetheless, it is convenient to be able to tag GOSUB statements with labels reminding the reader of the nature of the target subroutine.
Flashing Cursor For Get
Several notes have appeared showing how GET can be used to advantage instead of INPUT. Deal's recent article (COMPUTE, vol. 1, issue 6, p. 98) illustrates a routine related to some I have used.
Deal uses a BASIC method to flash the cursor. According to C. S. Donahue and J. K. Enger, "PET/CBM Personal Computer Guide," OSBORNE-McGraw-Hill, Berkely, CA, 1980, p. 106, there is a POKE address and a value that turns on the PET's cursor under control of its OS. The location is 548 for the "old" ROM set (version 2.0) and 167 for the "new" ROMs (version 3.0). I assume that the newest (4.0) ROMs use the same address as the 3.0.
The values to be POKEd are 0 to enable the flashing cursor and 1 to disable it.
100 POKE 167, 0 (turn on cursor) 110 GET A$ 120 IF A$ = "" GOTO 110 130 POKE 167,1 (turn off cursor)
This seems to work fine. I have had no problem with its actual operation, but I have had a few "flying cursor" residues (reverse blanks) left here and there at unexpected places after having used these POKEs. I don't know whether these were from my program bugs or from something in the operating system that was upset by the POKEs.
Pretty Printing
The PET system gobbles up spaces that may be left between the line number and the first character of a statement being entered, with the result that all statements in a PET BASIC program are left-justified. One of the features of a readable program is the use of blank lines and statement indentation to emphasize the logical structure of the program. This is "pretty printing" (see P. Nagin and H. F. Ledgard, "BASIC With Style", Hayden Book Company, Rochelle Park, NJ, 1978, or J. M. Nevison, "The Little Book of BASIC Style," Addison-Wesley, Reading, MA, 1978).
By now it is well known that spaces can be inserted at the beginning of a PET BASIC line if a colon (":") is typed in the first or second space following the line number.
100: FOR I = 1 TO 10 110: X = X + 1 120: NEXT I
What may not be so well known is that there is at least one restriction on this usage. A DATA statement that is not preceded immediately by a colon is ignored! Thus, the following will not work.
110: READ X, Y 110: DATA 1, 2
Instead, this can be used:
100: READ X, Y 110: :DATA 1, 2