Your Spectrum
Issue 9, November 1984 - Spectrum Spooler
Home Contents KwikPik
S   P   O   O   L   E   R
Having problems interfacing? Peripherals won't talk to you any more? Simon Goodwin has a solution for QL and Spectrum owners throughout the land ...
This project sets out to cure two major weaknesses of the Sinclair Research QL: first the unorthodox RS232 printer port, and second the lack of multi-tasking when printing (the computer stops dead while data is being printed). The solution costs precisely nothing, so long as you've already got a Spectrum with Interface 1 and a printer. Needless to say large numbers of QL users fall into that category. If you haven't got a Spectrum, perhaps now's the time to mend your ways!
Many QL users own Centronics printers which are incompatible with the new machine's cheap general-purpose RS232 printer port. The Centronics system uses seven or eight data lines, sending 'parallel' data a byte at a time, whereas the RS232 standard uses only one data line, sending characters bit by bit (literally). Obviously this saves transistors for Sinclair Research, but it's also landed many QL users in the unfortunate position of having a posh printer and a posh computer, with no means of making the two talk to one another.


There are two ways of getting around this problem. You can either adapt your printer to accept RS232 signals - which usually means that you lose the Centronics interface - or you can buy a 'black box' to go between the QL and the printer thus converting the RS232 data into its parallel equivalent.
Both solutions would be expensive, except that many QL users have already got the right kind of 'black box' languishing in the attic or the garden shed. All you need to convert the data is a trusty Spectrum (16K or 48K) plus Interface 1.
After spending a few weeks poring over the QL manual, I finally persuaded the computer to talk to a Spectrum via the Sinclair Research network. This may not sound like a major feat, but it has apparently defeated hordes of software houses and computer journalists. Indeed, one guru with a 'spy' at Sinclair Research told me there was a 'hardware fault' which prevented the network from working. Luckily, I persevered!


The programs were tested on version 'AH' of the QL and the network is potentially very fast. A 100K listing can be
transferred in about eight seconds giving an extra feature; you can use the Spectrum as a 'slave processor', so that the QL can be used for something else while the file is being printed. This is called 'spooling', an acronym for Simultaneous
10 CLEAR #
20 CLEAR 24999
30 OPEN #4;"n";1
40 LET m=25000
50 LET a$=INKEY$#4
55 IF a$="" THEN GO TO 50
60 POKE m,CODE a$: LET m=m+1
70 GO TO 50
80 REM End of File
90 PRINT m-25000;" bytes received."
100 FOR i=25000 TO m-1
110 LET m=PEEK i
120 IF m=10 THEN LET m=13
130 LPRINT CHR$ m;
140 NEXT i
An early attempt to read data from the QL. The program's very slow as the Basic reads the network character by character.
10 CLEAR #
20 CLEAR 24949
30 FOR i=24950 TO 24982
40 READ m
50 POKE i,m
60 NEXT i
80 LET m=PEEK 24983+256*PEEK 24984
90 PRINT m-25000;" bytes received."
100 FOR i=25000 TO m-1
110 LET m=PEEK i
120 IF m=10 THEN LET m=13
130 LPRINT CHR$ m;
140 NEXT i
200 DATA 62, 1, 50, 214, 92, 207, 45, 33, 168
210 DATA 97, 34, 151, 97, 221, 34, 81, 92, 205
220 DATA 230, 21, 183, 40, 250, 42, 151
230 DATA 97, 119, 35, 34, 151, 97, 24, 240
Using machine code, the printing loop can be accelerated to more than 1K per second - a slight improvement over my first program!

Peripheral Operation On-Line (SPOOL).
The problem now resolves itself into two parts - first we must move the data from the QL to the Spectrum and store it in the Spectrum's memory, then it must be output, character by character, to the printer.
Use a network or cassette lead (two
3.5mm jack plugs connected together) to join the computers - it doesn't matter which network socket you use. On the QL, three simple statements are needed to send a program listing down the network:

OPEN #3,neto_1

The first statement opens a channel for output to network Device 1 and then the listing is directed to that channel - you could use PRINT #3 to send text or numbers instead of LIST. Finally, the network channel is closed which ensures that the last few characters of the file are sent. Those keen enough can bundle the three statements into a PROCedure called, say, LLIST to save typing them repeatedly. You can output individual lines, or part of a listing, with commands like:

LIST #3,10 TO 50
LIST #3,20,310,400

At the Spectrum end, things are a little more tricky. You can't use INPUT to read lines from the QL, because the QL uses CHR$ 10 (line feed) to mark the end of each line, rather than the Spectrum's CHR$ 13 (carriage return). This means you have to resort to INKEY$ to read characters, one by one, from the network.


The first listing shows my early successful attempts at reading data from the QL. An OPEN is used, as normal, to associate channel 4 with data from the network. Then, INKEY$ fetches characters one by one. These are then POKEd into reserved memory - about 40K of data can be stored on a 48K Spectrum, and 7K on a 16K machine. In the interests of speed, there's no check for overflow.
Once all of the data has been received, the Spectrum stops with an 'End of file' report. You could trap this error, but personally I chose not to, since I use the ZX LPRINT printer interface which requires that you throw a switch to select it in place of the Interface 1. When you're ready to print, type GO TO 80 and the Spectrum prints out the characters it's received, while the QL can get on with other things. If you have trouble typing 'blind' you can add this line to the program:



25 LET g=80

Then, use 'GO TO g' (all on one key) to start printing. In the printing loop an IF statement is used to convert CHR$ 10 into CHR$ 13. Some printers don't require this.
That listing worked, but it was irritatingly slow - the Basic program read the network character by character, taking ages to read the entire file. The slow speed of the printing loop didn't matter so much, since the QL could get on with other things by that time; anyway, it didn't have much trouble keeping up with the 80 characters per second (with a following wind) of my printer.


The solution is shown in the second listing, which does exactly the same thing as the first except that it uses machine code to read the network, consequently working much faster. This code reads the network at a rate of more than 1K per second. It keeps the next data address at 24983 and 24984, so that line 80 can locate the end of the data when it has all been
received. Once again, you should use GO TO 80 to start printing once the QL cursor has re-appeared.
The machine code assumes that the QL is Net Device 1 (the default). Change the second item of DATA on line 200 if this is not the case, or if you are using a network containing a group of QLs or Spectrums with a variety of device numbers.
If you store the Spectrum program on Microdrive under the name 'run' you can set up the spooler by just typing the keyword RUN once the computers are turned on.
This program could save you £50 or more for an RS232 to Centronics converter and it also makes your QL more powerful into the bargain.
"If it's so user-friendly, why does it always thrash you at games?"
Home Contents KwikPik