Classic Computer Magazine Archive COMPUTE! ISSUE 8 / JANUARY 1981 / PAGE 118

Spooling For PET With 2040 Disk Drive

T.M. Peterson

Tired of waiting for your slow (aren't they all?!) printer to output that long listing, letter, or whatever; so you can get back to playing STAR DREK? Well, why not let that "intelligent" peripheral (the 2040) help you out? In IBM-speak it's called ‘spooling’ : you send the print file out to some lesser entity (in this case, the Commodore 2040 floppy disk drive) and let the big-shot CPU get on with the important stuff—like balancing your checkbook(?).

The idea is very simple, just tell the printer to ‘listen’ and the 2040 to ‘talk,’ and stand back so they can do their respective things. Of course, there are a couple preliminaries: you have to set up a disk file containing the image of the file you want printed and then tell the 2040 that's the file it's supposed to ‘talk.’ The first part is very easy—let's take a program listing, for example: You probably now do something like this

OPEN 4, 4 : CMD 4 : LIST
PRINT #4,; : CLOSE 4

The only change necessary would be to open the output file to the disk with an appropriate filename, e.g.:

OPEN 4, 8, 8, "0 : ← any name →, S, W" : CMD 4 : LIST
PRINT #4,; : CLOSE 4

and, in this case, DON'T FORGET TO CLOSE THE FILE or you may lose it entirely!

The next part is to tell the 2040 you want to access this file:

OPEN 4, 8, 8, "←whatever name you used→, S,R"

Now you're ready for ‘no hands’ hardcopy! First, you tell the 2040 to ‘talk’ the file you've just opened :

POKE 165, 72 : SYS 61668 : POKE 165, 104 : SYS 61668

To explain the above line: 165 is the address of the IEEE bus output character buffer. 72 (64 + 8) is the ‘talk’ address for device 8 (That's the 2040, unless you've changed the address jumpers). 104 (96 + 8) is the secondary address (or channel) corresponding to the second ‘8’ in the last OPEN statement above. And 61668 is the beginning of the ROM routine which outputs a command to the IEEE bus. This routine conveniently leaves the ATN line on the bus down, so the 2040 won't start ‘talking’ just yet.

Next you tell the printer (device #4 in this example) to ‘listen’ and you make the PET forget it was supposed to be sending its output to the IEEE bus :

OPEN 5,4 : CMD 5 : POKE 176, 3 : POKE 174, 0

At this point the 2040 will start ‘talking’; the printer, printing; and the PET will be ‘READY.’ for whatever you want—except you can't use the IEEE bus! Therefore, unless you're going to load from cassette (YUK!), you'd better LOAD whatever disk program file you need before executing the last two lines of ‘direct’ code above.

Finally, when the clatter over at the printer stops, you can close the open disk file (and turn off that pesky LED) either by re-initializing the drive or with the following:

OPEN 1, 8, 8 : CLOSE 1

Here, the important thing is to use the same secondary address as was used in the OPEN which accessed the disk file. Notice the filename is unnecessary.