From Within a Program
There are 2 ways of sending data to the printer from within a program. The first involves the use of the Command Line Interpreter and the second used the BBCBASIC(Z80) command, PRINT#. The former echoes characters sent to the screen to the printer. It provides all the normal BBCBASIC(Z80) print control features, but it is more complicated to set up. The latter sends characters to the printer only. It is simple to set up, but it becomes more difficult to use as the complexity of the printed line increases.
Using the CLI
The use of the Command Line Interpreter is explained in Section Seven of your Z88 manual https://cambridgez88.jira.com/wiki/x/RAAkAg and in the `Operating System Interface’ section of this manual.
Using CLI commands to send data to the printer has the advantage that the screen format is duplicated on the printer and all BBCBASIC(Z80)‘s print format controls work. You do not, however, have access to the special print controls provided by the Z88’s Printer Filter and you are left with a suspended CLI command file (explained in the ‘Operating System Interface’ section). Consequently, this is the least favoured method unless you especially want to echo screen output to the printer.
It is possible to emulate pressing the key sequences □+P and □-P from within BBCBASIC(Z80) by sending these key sequences to the CLI. At first glance, the following program line should work. Remember that the `#’ symbol is interpreted as □ by the CLI.
*CLI #+PThis does not achieve the desired effect within a program because the CLI command does not become active until the next attempt to read a character from the keyboard. In order to activate the CLI command, the line needs to have an INKEY command at the end. Since a star command must be the last (or only) command in a program line, you need to use the OSCLI command to pass the CLI command to the operating system. Thus, the line becomes;
OSCLI("CLI #+P"):dummy=INKEY(0)Try this line out on the Z88. You will see the CLI indicator in the status panel flash on and off again indicating that a CLI command sequence is momentarily active. Unfortunately, the print echo is only active whilst the CLI indicator is present, so this is not a lot of use to us!
In order to keep print echo active, we need to suspend the CLI command sequence after we have issued the print echo command. Unfortunately, this needs 2 command lines and must be done using a CLI command file.
You will need to use PipeDream to create the following CLI command file. Save it as ‘plain text’ to a file named pon.cli.
#+P
.SRemember to save it as ‘plain text’ - you will get all sorts of interesting error messages if you don’t.
Once you have created this file, you can turn the printer on and off from within your program with the following program lines:
Printer On
OSCLI("CLI .*:RAM.0/pon.cli"):dummy=INKEY(0)All subsequent PRINT statements will print to the screen and the printer.
The first line of the CLI file turns printer echo on by sending the command □+P to the CLI. In order to stop the printer echo being turned off at the end of the CLI command file, the CLI is suspended with the ‘.S’ command on the next line. Without the INKEY(0) command at the end of the program line, print echo would not be turned on until the program attempted to read from the keyboard or the program terminated and BBCBASIC(Z80) returned to the immediate mode.
Remember, you cannot cancel a suspended CLI command file from within a program. The only way is to press the SHIFT/ESC or ◇ESC keys on the keyboard. Consequently, you should avoid using this method of sending characters to the printer unless you really need to.
The use of CLI command files is explained more fully in the ‘Operating System Interface’ section of the manual.
Printer Off
OSCLI ("CLI #-P"):dummy=INKEY(0)Subsequent PRINT statements will now only print to the screen.
This line sends □-P to the CLI and turns printer echo off. Unfortunately, this leaves the CLI suspended and there is no way to reactivate it from within your program. You can, however, reactivate the CLI manually by pressing SHIFT/ESC when your program has terminated. You may not initially notice the effect of having a suspended CLI command file. However, when you list a program you will find that the listing no longer pauses automatically after every page.
Using PRINT#
You can also send output to the printer using the devices (hardware names) :PRT.0 and :COM.0. The :PRT.0 device filters output through a ‘filter’ (device driver), the :COM.0 device sends output direct to the printer (serial port).
This method of printing does allow you to make use of the ‘Printer Filter’, but as the complexity of the line to be printed increases, this method becomes more difficult.
To send data to the printer in this way, you first open a file to the device and then use the PRINT# statement to send the characters to be printed to the printer. Characters printed in this way do not appear on the screen.
When you send characters to the printer device :PRT.0 in this way, they are processed by the Printer Filter and all the codes described in the ‘Print Filter’ sub-section are recognised and acted upon.
If you are using the :PRT.0 device, you must send the printer-on Escape sequence ENQ [ (ASCII codes 5 & 91) to turn printing on before you send anything you want printed. Remember to turn the printer off with the Escape sequence ENQ ] (ASCII codes 5 & 93) when you have finished.
The following example opens a file and prints to it via the Printer Filter. It uses some printer Escape sequences which are discussed in the ‘Printer Escape Sequences’ sub-section and it assumes that the Printer Editor has been used to set ‘Off at CR’ to `No’ for bold and underline.
10 REM Open the printer file
20 prntr=OPENOUT ":PRT"
30 :
40 ENQ$=CHR$(5):LF=10
50 REM Send the Print Filter On Escape sequence
60 PRINT#prntr,ENQ$+"["
70 :
80 REM Set bold print on
90 PRINT#prntr,ENQ$+"B"
100 :
110 REM Set underline on
120 PRINT#prntr,ENQ$+"U"
130 :
140 REM Print 'Hello World' and send a line-feed
150 PRINT#prntr,"Hello World":BPUT#prntr,LF
160 :
170 REM Send the Print Filter Off Escape sequence
180 PRINT#prntr,ENQ$+"]"
190 :
200 REM Close the printer file
210 CLOSE#prntr
220 ENDPRINT# is intended for sending data to a file. Consequently, it works in a different way to PRINT. Items separated by commas or spaces are treated as different data fields and a carriage-return is sent between each field. Consequently, you need to build and send a complete line at a time. In addition, you must explicitly send the line-feed character at the end of the line.
If you are using the :COM.0 device, everything is sent to the printer and you don’t need to turn it on and off. However, you must send the printer specific control codes for underline, etc since the Printer Filter is not being used.