|★ APPLICATIONS ★ DIVERS ★ Background printing ★|
|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 the 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 300.
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 Listft?. Similarly, use Prints 7, instead of Printed. 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:
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 -ft 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 position in the buffer, if not then the character is passed to the normal ROM screen printing routine.
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.