Printer Drivers for the PSION programs

First published in Sinclair QL World, November 1986

The PSION Suit for the QL is an excellent package, catering for most day to day needs in a simple and uncluttered manner. The versatility and usefulness of the package can be greatly enhanced with the aid of some 'multitasking' facility: the capability of loading some or all of the programs together, and by a few key presses to switch between them. This capability requires extra memory, of course. RAM-discs for the fast transfer of data between the programs also increases the performance considerably.

Using the export and import commands supplied by ARCHIVE, ABACUS, EASEL and QUILL, is one way of transferring data between them, another way is by using the print commands: by printing data to a file. To ensure that the resulting file contains data in a desirable format the printer drivers will have to be modified.

Here I would like to share with you some uses to which the printer drivers can be put to. The table below lists various settings for which you may find some use, and most important, may give you some ideas for further development or different uses.

Printer Drivers
  Dfault Basic ArchProg ArchFile MailMerge
DRIVER NAME LX80 BASIC APRG AFILE MAIL
PORT SER1 SER1 SER1 SER1 SER1
BAUD RATE 9600 9600 9600 9600 9600
PARITY NONE NONE NONE NONE NONE
LINES/PAGE 66 0 255 0 0
CHARS/LINE 80 255 160 80 80
CONT FORMS NO YES YES YES YES
EOL CODE CR, LF LF CR, LF ", CR, LF, " ", CR, LF, l, p, r, i, n, t, "
PREAMBLE NONE NONE NONE ",l,$,",CR,LF," p, r, o, c, , M, E, R, CR, LF
POSTAMBLE FF, ESC, @ NONE SUB ", CR, LF, SUB ", CR, LF, e, n, d, p, r, o, c
BOLD ON ESC, E NONE NONE NONE ", +, B, o, n, $, +, "
BOLD OFF ESC, F NONE NONE NONE ", +, B, o, f, $, +, "
UNDER ON ESC, -, 1 NONE NONE NONE ", +, U, o, n, $, +, "
UNDER OFF ESC, -, 0 NONE NONE NONE ", +, U, o, f, $, +, "
SUB ON ESC, S, 1 NONE NONE NONE  
SUB OFF ESC, T NONE NONE NONE etc
SUPER ON ESC, S, 0 NONE NONE NONE  
SUPER OFF ESC, T NONE NONE NONE  
TRANS 1 £, ESC, R, ETX, #, ESC, R, NUL {, d, e, f, p, r, o, c, {, p, r, o, c, ", ' ^, l, p, r, i, n, t, "
TRANS 2 ↓, ESC, 9 }, e, n, d, d, e, f }, e, n, d, p, r, o, c NONE {, ", +
TRANS 3 ↑, ESC, 8 [, r, e, p, [, w, h, i, l, e, NONE }, +, "
TRANS 4 «, ESC ], e, n, d, r, e, p, ], e, n, d, w, h, i, l, e NONE [, ", ;, :
TRANS 5 \, FF     NONE ], :, l, e, t, , d, $, =, "
TRANS 6 NONE YOU YOU NONE ", '
TRANS 7 NONE THINK THINK NONE YOU
TRANS 8 NONE OF OF NONE THINK
TRANS 9 NONE SOMETHING SOMETHING NONE OF
TRANS 10 NONE     NONE SOMETHING

To make testing and development of these printer driver settings easier, I modified the INSTALL_bas program supplied with QUILL so that it would:

  1. install on any medium ( disc, RAM-disc etc )
  2. install the printer data under any name, not only printer_dat
  3. Re-run
  4. 'multitask' ( By using a Superbasic compiler ).

The latter made testing and debugging a simple affair as the INSTALL_exe program could be run together with the PSION programs.

All this is however not necessary if you just want to copy the settings as listed:

  1. Copy your INSTALL_bas, INSTALL_dat and printer_dat files onto a fresh disc/cartridge.
  2. Make a copy of your current printer_dat file under a new name
    eg COPY mdv1_printer_dat to mdv1_DFAULT_dat
      
  3. Run the INSTALL_bas program and enter the list you want
  4. Install this as the new printer_dat file and exit the program
  5. Copy this printer_dat file to a new file with a name of your choice
  6. Re-run the install program ( RUN )

Instructions on how to operate INSTALL_bas can be found in the QL manual under the Information section.

Here follows a description of each of the printer drivers together with instructions and suggestions for use.

Dfault

Basically four different types of usage are described here in ever further removed relation to a printer drivers intended purpose. This first one is just a plain driver for an EPSON LX80 ( or compatible ) printer. However there are two special features included in this driver. The first one is of more general application: the translation ( see TRANS 2 ) of the « ( CTRL + SHIFT X ) symbol into ESC. This enables control codes to be inserted in your QUILL documents on par with other word processors. Thus typing «4 ( on a line of its own, or it will mess up your margins!) will cause the italic character set on an EPSON printer to be used.

The | ( UP arrow ) and | ( DOWN arrow ) translation into ESC 9 and 8 ( EPSON control codes for paper-out sensor disable/enable respectively ) have a more esoteric function, they could well be utilized for something more useful. However, if you, like myself have a parallel printer interface on the expansion board and PSION version 2.00 software, then this is something for you. Since you cannot install a centronics printer to use with the PSION suite directly you have to print to a file named _PAR ( note the underscore ). This makes the programs look for a device named "par" and print to it as if it where a file.A similar procedure also holds good for printing spreadsheets from ABACUS. ( Note that the DIP switches should be set to ignore the paper-out sensor. )

Basic

QUILL has its function as a Superbasic ( SB ) editor. Transliteration is only one of a host of possibilities - eg change all occurrences of mdv into flp - for those who upgrade to disc drives. This is faster and surer than by hand for long, complex programs. Other uses are tidying programs, editing or even writing whole SB programs. Remember you then have a full screen editor with advanced editing facilities. Programs can be typed in using the normal keyword abbreviations eg defproc So_and_so. Another short-form method can be seen by studying the BASIC driver listing. There you see that certain characters have been translated into common SB keywords ( note that some of the translations end on a space! ). Thus, the procedure Train could be written like this:

{Train
  [puff:print'PUFF ';:]puff
}

Here follows a short principle program for removing line numbers from a SB program for editing in QUILL:

OPEN#3, mdv1_PROG_bas
OPEN_NEW#4, mdv2_PROG_exp
REPeat loop
 IF EOF(#3): CLOSE#3: CLOSE#4: STOP
 INPUT#3, l$: PRINT#4, l$((' ' INSTR l$) + 1 to )
END REPeat loop

Similarly, the following method may be used for restoring the line numbers after editing ( again in principle ):

OPEN#3, mdv2_PROG_lis
OPEN_NEW#4, mdv1_PROG1_bas
FOR l = 1 to 32766
 IF EOF(#3): CLOSE#3: CLOSE#4: STOP
 INPUT#3, l$: PRINT#4, l! l$
END FOR l

Aprg

In the same way as for SB, ARCHIVE procedures and programs may be written from QUILL or even from within an ARCHIVE program itself. The possibilities of search and selection criteria you may include within in your ARCHIVE program may be increased manifold utilizing this method. Say that within a program you wish to make a selection of fields from a data base. You have of course catered for your less bizarre needs in the usual manner with statements like:

input 'Input search field number ';n
input "Input search string ';string$
search fieldv(n)=string$

However this may not always be enough. How about this, ( using the GAZET_dbf file supplied with your QL ):

proc sirch
 rem *** If all else fails ***
 input 'Input statements ';scrit$
 rem *** eg "search continent$='AFRICA' and pop>20"
 kill 'mdv1_printer_dat'
 backup 'mdv1_APRG_dat' as 'mdv1_printer_dat'
 spoolon 'ram1_proc_prg'
 lprint 'proc special' : rem *** or lprint '{special' See TRANS1
 lprint scrit$
 lprint 'endproc':rem *** or lprint '}' See TRANS2
 spooloff
 merge 'ram1_proc'
 error special
 if errnum(): print "Error in statement":sirch: endif
endproc

This can all be done, then, without leaving the shell program. Just as an example...

Afile

This is a slightly different kettle of fish. A foretaste of ways of using the drivers has already been given.

To start with the PREAMBLE entry: The first two lines printed in the file will look like this

"l$"
"

due to the given preamble setting. The EOL code, ( End Of Line ) prints the following to the file:

   "
"

Now if we take these codes together, add some text and finish with the POSTAMBLE settings a QUILL document looking like this

Wait till you see "MAILMERGE"
It's really useful

would be printed to file looking like this:

"l$"
"Wait till you see 'MAILMERGE'"
"It's really useful"

Now if you remember reading the "full discussion" on import and export in the QL manual Information section, you will see that this is the format of a single variable (l$) export file. You may add as many lines as you please, but they are all elements of the variable l$.

If you need to add large amounts of edited text into an ARCHIVE file, this is one way of doing it:

Back to GAZET_dbf. Perhaps you wish to have some notes on some of the countries which could be refered to by key words or just simple string searches. You could of course create a new file with a large number of fields but this, more often than not, imposes unnecessary complications and restrictions on this particular type of data: On some countries you may wish to have a large amount of notes, maybe adding to them every time you come back from a visit there; on others you may not wish to have any and thus, I find, a single line text file suits the purpose best.

The gazette file and the text file could have the following structures:

GAZET_dbfGAZTEXT_dbf
logical nameg
country$NORWAY
continent$EUROPE
capital$OSLO
languages$NORWEGIAN
currency$KRONE
pop4
gdp5288
area324
ref102
logical namet
line0
text$ 
ref102

The umbilical cord between these two files is ref, which has to be added on to the gazette file. (This may easily be achieved by exporting GAZET_dbf to file and then importing the file into ABACUS by column. On row one of the column after area, add the text ref. Then, on the next row enter the formula

col=row()-2 from 2 to 152

This gives each record a unique reference number. Export the file by column again and import it into ARCHIVE.) Now:

  1. Type your text using QUILL as you would typing any other document, and edit it to your hearts desire. The following points may however be worth considering: Left margins are translated by QUILL into spaces, so unless you don't mind storing a few K of empty spaces, don't use left margins. Don't use a right margin greater than 79 or it will ruin your display.
  2. Once the text is ready backup your AFILE_dat file as printer_dat
  3. Print the document to file. ( eg TEMP_exp )
  4. Import this file into ARCHIVE as say TEMP_dbf:
    import "temp" as "TEMP" logical 'x'
     
  5. open the gazette file and find the name of the country you wish to attach the text to so as to discover it's ref number:
    open"GAZET"logical"g"
    search country$='NORWAY':rem *** for example
    let reference=ref
     
    You now have Norway's ref number in the variable reference
  6. To get the highest line number of any previous text
    open"GAZTEXT"logical"t"
    select ref=reference
    order line;a:last
     
  7. Now empty the contents of the temporary file, adding line numbers and the reference number into the text file
    use"x":first
    while not eof()
     let line_number=line_number+1
     let t.ref=reference
     let t.line=line_number
     let t.text$=l$
     append"t":next
    endwhile
      

Mail

This final driver is also the furthest removed utilisation of the printer drivers from their intended purpose. It turns the combination QUILL/ARCHIVE into a powerful and intelligent mailmerge duo. But it may also be used for other purposes than mere mailmerge. The facilities shown here are just the bare basics. No doubt more powerful and elegant solutions can be found and other features may easily be added.

The principle is simple enough, yet some explanation may still be necessary:

The idea is to use QUILL to type and edit a letter to satisfaction, using squiggly brackets { } and field names to insert variables into the document eg

Dear {title$} {sname$},

etc... This document, then, must be printed to file using the MAIL_dat driver as printer_dat. The above line will then be translated into

lprint"Dear "+title$+" "+sname$+","

because each EOL code is translated into

"
lprint"

and each { is translated into

"+

while each } is translated into

+"

It is important to note that the mailmerge document must start with a ^ ( or what ever other symbol you choose. See TRANS1 ) as the driver data are limited to a maximum of ten items per line. Thus the whole PREAMBLE code is taken up with the ARCHIVE initialising procedure, proc MER, and there would be no quotes or anything to justify the EOL closing quote. So this symbol must be on the very first line above any header, and, unless you specifically wish it otherwise, alone on the line. As you see, ^ translates as lprint" for no other reason than as an excuse for the inevitable closing quotes.

The best way of ensuring that you get your preambles right every time, is to construct a MAIL_doc skeleton document and save it as such:

Set the top and bottom margins at zero Set the header left containing the ^ as the first character Include in the header any other controls eg NLQ.

If you now study the various other printer settings like BOLD ON and so on, you see that they translate as inserting variables into the lprint statements. These variables are not defined by the printer driver, so they must be filled in by the ARCHIVE program.

The following shows how to set about using MAIL:

  1. Type and edit your letter to satisfaction using the MAIL_doc skeleton as described above.
  2. Where ever you wish to use a variable insert it between squiggly brackets as explained. You needn't only use field variables; any function or other variable using values assigned by the ARCHIVE program will do, like {date(2)}
  3. Install the MAIL driver as printer_dat and print the document to RAM-disc or an other medium as MAIL_prg
  4. Switch to ARCHIVE and merge "MAIL" into your program

The procedure below take care of the essentials:

proc output
 merge drive$+"MAIL"
 kill "mdv1_printer_dat"
 rem *** restore the proper printer driver ***
 backup "mdv1_DFAULT_dat" as "mdv1_printer_dat
 let esc$=chr(27)
 rem *** Assign control codes. See list
 let bon$=esc$+"E"
 let uof$=esc$+"-0"
 let NLQ$=esc$+"x1"
 etc...
 MER
endproc

where MER, of course, refers to the merged MAIL file.

Advanced facilities

There is no reason why other of ARCHIVE's keywords should not be utilized. That is the meaning of TRANS 4 to 5. The square brackets [ and ] neutralize the inevitability of the lprint" statements.

The [ translates as ";: and the ] as :let d$=" ( dummy$ ) leaving a 'hole' in the document for keywords thus:

lprint"";: one statement : another :let d$="": lprint" etc..."

However, a number of spaces constituting your margin or indent will be automatically inserted in the lprint statements, and these therefore will have to be taken into consideration. Alternatively, program lines within the document could be written with the indent set to zero.

Obviously, it is not possible here to provide further documentation as the possibilities are so many. The best way is to experiment and discover for your self what you require. As a last illustration of some of the possibilities see the letter below.

^
{date(2)}

{cname$}
{street$}
{town$}
{district$} {code$}


Dear Sirs,

We enclose our account for

£{str(amount,0,2)},

now {str(months,2,2)} months overdue.
[if months<3]
We feel you may have overlooked this, and shall be glad of a remittance
as soon as possible.
[else:if months=3]
You will appreciate that we cannot run a business unless we receive
payment for goods delivered. You are requested to settle this account as
soon as possible.
[else]
Unless payment is received within seven days we regret we have no
alternative but to issue a writ without further notice.
[endif:endif]



Yours faithfully,

Update, March 2ooo

You can also use the printer driver to convert a document to simple html:


Html
DRIVER NAME HTML
PORT SER1
BAUD RATE 9600
PARITY NONE
LINES/PAGE 0
CHARS/LINE 80
CONT FORMS YES
EOL CODE <BR>, LF
PREAMBLE <HTML>
POSTAMBLE </HTML>
BOLD ON <STRONG>
BOLD OFF </STRONG>
UNDER ON <U>
UNDER OFF </U>
SUB ON <a name=>
SUB OFF </a>
SUPER ON <a href=>
SUPER OFF </a>
TRANS 1 <, &lt;
TRANS 2 >, &gt;
TRANS 3 &, &amp;
TRANS 4  
TRANS 5  
TRANS 6 YOU
TRANS 7 THINK
TRANS 8 OF
TRANS 9 SOMETHING
TRANS 10  

Note: Subscript sets an anchor, while Superscript marks a reference to the anchor. Names for the references will have to be filled in by hand later.

Print the document to file, as described above, and then display in your favourite browser.