|★ APPLICATIONS ★ DIVERS ★ Double-dealing ★|
|RSX Background printing (Popular Computing Weekly)||Applications Divers|
Background printing at your fingertips with the aid of Brian Cadge
The machine code program presented here gives Ihe Basic programmer the facility for ‘Background Printing'. This is a feature usually found on the better
wordprocessors and the like. Basically, what it means is that the computer can be printing a document whilst the basic program continues to do something else. Using the printer usually hangs the computer up until printing has finished.
To use the program type in the Basic loader program, save and run it. If you have made any errors in the data statements the program will tell you and you should recheck your listing.
Several new commands are now available to be used in your own programs which can now be loaded or typed in. Alternatively, the Basic loader program could be merged with your own program. Line 90 would be changed to a Goto first line number, eg. 300. It is important that the code is only loaded once, so you should add to Line 5 as follows; 5 If Peek(41400) 201 Then 300L
The new printer driver uses channel 7, instead of channel 8, the normal printer stream. So instead of using List#8 to list a program to the printer, you can now use List# 7. Similarly, use Print#7, instead of Print#8. Channel 8 still operates as normal, but take care not to use it whilst #7 is active, or output will be mixed from both! The text window #7 cannot be used.
There are also four new RSX commands available. All RSX's start with the '|' character, obtained by Shift/@. These commands are;
|Hold Temporarily suspends background printing. Esc will no longer stop the printer.
|Release Restarts printing from the Held position.
|Kill Aborts all background printing immediately - any output waiting to go to the printer will be lost
|Lfchar,n Sets the Linefeed character to 'n' the default is 10. Note the comma immediately after the command and before the number.
If your printer leaves a blank line between each line printed then try typing Lfchar,0
A 2K buffer is used to store the characters to be output. If this ever fills up completely then the program will have to wait until room is available before continuing. In practice. 2K is enough for most output to be stored, so that the program is not halted.
To get the idea of what all this does, try listing the Basic loader program once it has run successfully, type; List#7. Instead of waiting for the printer, the 'ready' prompt should return almost immediately. You can now carry on using Basic as normal whilst the program is being listed on the printer. You can also send more output whilst this is happening try typing ?#7, "Amstrad". This will be stored and printed after the listing.
Now type Hold, the printer will stop, typing Release will restart printing. Typing Kill will halt the printer and all further output will be lost.
If you want to know whether the printer is active in a program you can use X Peek(41735) + Peek(41736) *256 to return the number of characters waiting to be printed.
You do not need to understand how the machine code program works to use the program, but the assembly language listing is included for anyone interested.
The normal VDU print vector is redirected so that each time a character is printed the program checks to see if channel 7 is being used. If it is then the character is stored in the next available
A 2K wrap-round buffer is used, with two pointers and one counter. The counter holds the number of items in the buffer. The Input Pointer points to the next available position, the Output Pointer points to the next character to be printed. By taking Modulo 204B a wrap-round buffer is created - this feature is important for the most efficient user of the buffer.
The actual printing is done by a ‘Fast Ticker Event'. This is a routine executed by the operating system 300 times a second. Ticker Events on the Amstrad are a very powerful form of interrupts under the complete control of the operating system. There are several speeds of ticker, 300 being the fastest.
This fast ticker event is set up in Lines 270 to 310 and starts at Line 1020. It firstly checks if there is anything to print and returns if not. It also returns if the Hold flag is set. If there is a character in the buffer, then the Centronics port is checked. If the printer is ‘Busy' the routine doesn't wait, it simply returns. Providing the printer is ready, the character is sent and the Output Pointer and Counter are adjusted.
The RSX commands are set up in Lines 240-260 and 330-460. and the command routines start at Line 1340. For a fuller explanation of RSX commands see Popular Vol 3, numbers 50 and 51.