VirtualAcorn Technical support:
Printing directly from BASIC programs
This article was originally published in RISCWorld Magazine.
Printing from BASIC
I quite often get asked if VirtualAcorn products can print from BASIC. the answer, of course, is yes. Provided the application concerned is using the RISC OS printing method. However, what people really tend to mean is "Can I print from my old single tasking BASIC program that I wrote 22 years ago on the BBC?" The answer to this has always been no, you can't. The best idea is to update the program so it either works in the desktop, or saves a file out that can subsequently be printed by another application.
Now of course the above isn't a very helpful answer. I do however point out that what someone really want to do is print out text directly. This method was great on dot matrix printers but many modern inkjet printers don't support text only printing any longer, but a surprising number of laser printers do. So anyway lets get to the point.I was contacted by Stuart Tyrell (of STD and AdvantageSix fame) who had run into the same problem, but had sat down and come up with a solution. The solution, like all good ideas was very simple, worked perfectly and yet seemed totally bonkers. Stuart provide me with a sample piece of code as follows:
10 : REM Printer Test 2 for VA
20 : REM Stuart Tyrrell
30 : REM
40 : REM Set printer type 50 to point to the printer
50 : REM To check the printer name:
60 : REM a) Install the printer under Windows
70 : REM b) Run "showprinters" in the printing directory in RISC OS
80 : REM c) Replace the bit after HostFS:: with the printer name
90 : *SET PrinterType$50 HostFS::Panasonic_KX_P7110_PCL6
100 : :
110 : REM Now select this printer type
120 : *FX 5,50
130 : :
140 : REM Turn off the printer ignore character, otherwise everything
150 : REM appears on one line!
160 : *fx 182,255,0
170 : :
180 : REM Print something!
190 : VDU 2
200 : FOR T=1 TO 10
210 : PRINT SPC(T*4);"test!!!"
220 : NEXT
230 : :
240 : REM Don't forget the page feed, especially on a laser!
260 : VDU 12
261 : :
262 : REM Bye!
270 : VDU 3
As you can see the program sets up a printer type of 50, and then opens this printer, prints some text, then closes the printer. What had me stumped was that I couldn't see how it was working, especially as Windows itself can't do this trick! Eventually I realised what was happening. When a VirtualAcorn prints it dumps data directly into the Windows print queue, by-passing most of the Windows printing system. The file that is generated by RISC OS simply gets sent straight to the printer with no further processing. So provided the printer "knows" what to do with plain text, it will print it. Of course most printers sold these days are so called GDI printers, meaning they have no God Damn Intelligence, and can't print "raw" text files. So before trying this method on your own programs make sure your printer can handle plain text files.
It's a very trivial task to alter any single tasking program that prints out text to work on VirtualAcorn and I thank Stuart for his creative solution to a long running issue for some users.