|★ APPLICATIONS ★ DIVERS ★ FILTER ★|
|Filter (Amstrad Computer User)||Applications Divers|
Mrs Mop meets the program listing — a program for the CPC in Basic and machine code by Paul S. Jenkins.
Let us suppose that you have been given a Basic program and think it might be interesting or instructive to list it to your printer. It looks fine on the screen, apart from one or two strange characters, so you switch on the trusty Epson compatible printer and type LIST#8. Then you nip off to make a cup of tea while you wait for the completed listing.
But something's wrong, what are those gaps in the printout? Why is some of the listing printed in condensed typeface and some in double width, and where did all those blank lines come from?
The reason for the twisted listing is a problem known as embedded control characters. To save time and memory some programmers use these codes for screen formatting, PEN, PAPER and INK changes.
Here is a simple example of how it's done. Type PRINT" on your Amstrad, and before pressing the Enter key hold down the letter X, then press Enter. If you have done this correctly you should find that the pen and paper inks have been swapped.
What you have just typed is the equivalent of PRINT CHR$(24), and if you look in the User Instructions for your CPC you will find a list of Basic control characters to enable many different effects to be obtained using the PRINT CHR$() command. All these characters can be entered directly into print statements using the control key.
Try typing PRINT" and then Control G. If the volume control is turned up you should hear a beep from the internal speaker. A Basic program which includes embedded control characters will work as expected, but when it is listed on the screen the computer will translate the characters into those strange symbols.
Worse, when you attempt to list the program on paper, the printer interprets the symbols as printer control codes and changes its typeface, prints a form feed, turns on underlining, or one of a number of unwanted features.
All the foregoing is a very strong argument against using embedded control characters in your programs. It is certainly something which will cause your listing to be rejected by ACU's Liz Ting. A problem which cannot be solved by good practice involves the use of the PRINT USING command. Refer again to the user instructions and you will see that to print formatted numbers with a preceding pound sign the PRINT USING template must consist of a combination of hash and pound signs. This will print correctly on the screen, but not on an Epson compatible printer.
Depending on whether your printer has the English or American character set in operation, the print using template will appear as all pound signs or all hashes. It is impossible to tell which is which if what you see is:
tal_1/2__USING__########,. ##_; t
An Epson compatible printer can be switched between American and English character sets by means of the aforementioned printer control codes. The Basic program listed here provides a way of switching between character sets during printing.
The program will also filter out all embedded control characters and convert them into a pair of square brackets enclosing an up-arrow (") and a key character. This means that the two examples given above would appear as [^X] (Control - x), and f [^G] (Control - G).
Any graphics characters or other codes whose Ascii value is more than 127 will also be converted, to square brackets enclosing a g- and the Ascii value of the character which might otherwise cause the printer to go haywire.
The only restriction on the use of the Filter utility is that the program to be listed must be in Ascii format. If the name of your program is YOURPROG, then before using Filter type: LOAD"YOURPROG" and then SAVE "YOURPROG",A. This will create a version of your program in Ascii format. Then you can run Filter.
You will be asked for the name of your program and whether you want the listing sent to the screen, the printer, cassette or disc. If you select either of the last two you will be asked for the name of your program and whether you want to give the filtered listing. If you select the disc when no disc drive is present you will be asked again.
The program is quite simple in operation, and meaningful variable names have been used so that it can be adapted as necessary for a non-Epson standard printer. Error trapping is included for all disc and tape operations, so although the program was written on a CPC6128 it should work on a 664 and 464 with or without disc drive.
The screen dump of DEMO1 in Figure I shows how a program contains embedded control characters, a pound sign, a hash sign, and graphics characters appear on the screen. Don't list this program directly to your printer unless you want to waste a lot of paper.
If you want to enter DEMO1 into your CPC so that you can test the Filter program then refer to the Filtered listing of Demo 1, which was produced using the Filter program.
Whenever control codes appear in the filtered listing you should hold down the Control key and press the character shown after the up arrow (don't type in the square brackets).
To type in the graphics characters you first need to re-define some keys. For instance, to re-define the 7 key as the character whose code is 135 type KEY 128 + 7,CHR$(135) and press Enter. Now when you press 7 an inverted L shape will be printed.
When you have typed in the complete DEMO1 listing it should look like the screen dump shown in Figure I. When run, DEMO1 produces a simple demonstration title screen in Mode 0 and waits for you to press the spacebar.
Save the program by typing SAVE"DEMO1",A and press Enter. The A will cause the program to be saved in Ascii. Filter will only work with programs saved in this way. If you try to use Filter with a normally saved program it will not accept the file name and will ask for another.
It is a good idea to save the program in normal format as well as the Ascii; it will load faster and a control Z in the Ascii listing will stop it from loading.
It is best to avoid using embedded control characters, but at least Filter makes your programs readable.