271 fff000c4372dfe0f3308ff7005f ^6وووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووو ^1 U S I N G P R I N T E R S W I T H A M O S . ^2 by Jeff Tullin. ^6وووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووو ^4 The great thing about standards, as someone once said, is that there ^4are so many of them. Nowhere is that more true, it seems, than in ^4the world of printers, and their control codes. Printers and Amigas ^4have always been uneasy bedpartners, and due to one or two little ^4quirks, even more so when using AMOS. I've been doing a bit of ^4investigating into the use of the printer from AMOS, and I came up ^4with one or two surprises! ^6But first, a little history.. ^1 Way back in the early days of home computing, wordprocessors tended ^1to concentrate upon the bare job of getting letters out on the page. ^1The fancy effects like underlining, bold, italics and so on were ^1either ignored, assumed to be EPSON compatible (and hard cheese if ^1your printer was not), or handled by some obscure system of escape ^1code sequence inserting functions. (An escape code sequence is a ^1sequence of numbers which, when sent to the printer, tell the printer ^1to do something.) The advantage of this last system was that, ^1provided you had a good manual for the printer, and could follow the ^1instructions, every feature of your printer was open for use from ^1within your WP. The problem was that it tended to get in the way of ^1your work, and you really did have to know your way around the ^1printer manual. ^4 People are inherently lazy, however, and started to expect the ^4wordprocessor to include built in commands to handle these special ^4printer effects. To do this, and be worth it's salt, the ^4wordprocessor had to be able to send the correct codes to a variety ^4of printers. For example, the escape code sequence to begin ^4underlining is quite different on IBM compatible printers to that on ^4Epson compatible. (which are by far the most common in use with the ^4Amiga). ^6 Thus, the printer driver was born. The wordprocessor sent a ^6'standard' escape code sequence to its printer driver, the printer ^6driver thought to itself - 'Ah ha! Escape A! That means they want ^6to use double height letters. Now, I'm an IBM driver, so when I hear ^6(Escape A), what I send to the printer is actually 27, followed by ^632, then...' and so on. Each wordprocessor had its own printer ^6drivers, and they were legion. Every other program with printer ^6output would also use its own, and there was little common ground. ^6Most Atari ST wordprocessors still work in this fashion. ^1 The designers of many multitasking operating systems, the Amiga ^1among them, decided that it would be a good idea if all your programs ^1could have access to a common pool of resources, like printer drivers ^1and fonts, and so establish some standard method of output, and ^1reduce the memory overheads inplied by having a different driver for ^1every application. So, the Amiga printer driver standard was ^1created, adapted from the ANSI standard from America, and most ^1programs will use this medium to communicate with your printer. ^4 You use Preferences to choose the printer driver which most closely ^4resembles your own printer, and for most purposes, this will work ^4with little trouble for 'normal' text. (Graphics, on the other hand, ^4are a whole new can of worms, and are beyond the scope of this ^4article.) The printer and device drivers are an integral part of ^4using Amigados, and most books on the subject will cover them in far ^4too much detail for the average Amiga user. ^6 AMOS isolates you from the nitty gritty of the Amigados operating ^6system, (Look! - I got round to AMOS eventually! ), but as a ^6consequence, you do not often come across the information you need to ^6access this sort of feature. Without at least a list of the ANSI ^6codes, you may will find it tricky to get the results you want on ^6paper from within an AMOS program. ^1 Here is where I hit upon the fist surprise. AMOS does NOT Lprint ^1through the printer drivers! Instead, provided I understand this ^1correctly, it opens a port to the Parallel device, sends data to ^1that, AND NEVER CLOSES THE PORT! Now this causes all sorts of ^1problems if you want to do anything fancy with the printer, and I'll ^1try to explain why. ^4 There are three main ways to send data from your program to the ^4printer port. The first (the normal) way is to use AMOS's LPRINT ^4command, Eg. LPRINT "Hello" ^6 You can achieve the same effect by opening a channel to the PAR: ^6device, directly accessing the parallel port, Eg. ^1 OPEN OUT 1,"PAR:" : PRINT #1, data ^4The third is similar, but opens a port to the PRINTER DRIVER, by: ^1 OPEN OUT 1,"PRT:" : PRINT #1, data ^4 (Note: I ignore the serial port for this article - once the serial ^4port is configured correctly for speed and parity etc., then all ^4references to PAR: could equally apply to SER:) ^6 We'll look at LPRINT first, the 'legal' way to talk to the printer. ^6The only way to set printer effects via LPRINT is to look them up in ^6your printer manual, lets use DOUBLESTRIKE as an example. For the ^6LC10 printer, and many others, the correct sequence of codes is ESC ^6G. You can send this by LPRINT CHR$(27),"G"; This works fine, but it ^6ties you to writing your program for only one type of printer. One ^6further restriction, due to a bug in AMOS, is that you can not (yet) ^6send CHR$(0) to the printer through LPRINT. This effectively rules ^6out several types of printer command. ^1Far better to make use of the PRINTER DRIVER to achieve the most ^1common effects like italics and underline. ^4 You are restricted in the number of things which you can ask of the ^4printer, by the number of commands which the printer drivers ^4understand. (About 80, but many of these are obscure things that ^4most people would never dream existed.) As printers become more and ^4more advanced, and their features increase, so the complexity of the ^4escape code sequences they understand increases, and the differences ^4between different manufacturers becomes more pronounced. ^6 The printer drivers 'cherry pick' the most common printer effects ^6and cater for them alone. If your printer supports variable width ^6triple height lettering and you want to send something to set that ^6effect - forget it. You just can't do it, because there is no ^6standard printer driver call for that effect. So, just what can you ^6ask the printer to do? The Amiga Introduction Manual that came with ^6your machine sets out a list of the available ANSI style commands. ^6It is on page D-2 of my manual (1.2), and to save you looking for the ^6moment, here are some examples. (Note: ESC is the same as CHR$(27) ^6in AMOS Basic) ^2 So as not to confuse the magazine's driver program, all the left ^2square brackets used in the control codes have been replaced with *. ^2Please take this into account when reading the rest of this article! ^7 SEQUENCE FEATURE ^5 ESC c Reset printer ^5 ESC E Line feed & carriage return. ^5 ESC *3m Turn on italics. ^5 ESC *23m Turn off italics. ^5 ESC *4m Underline on. ^5 ESC *24m Underline off. ^5 ESC *1m Boldface on. ^5 ESC *22m Boldface off ^7 .... and several more. ^1 To use these and the others from within AMOS, you could issue the ^1commands: ^4 OPEN OUT 1,"PRT:" ^4 PRINT #1,CHR$(27)+"*1m" ;(which sets BOLD print.), ^4 CLOSE 1 ^1replacing the "*1m" with the correct string for the effect you want. ^2See PS at end of article! ^6 The printer driver will change this string into the right ones for ^6your printer, and all is well. (You can open and close this port as ^6many times as you wish during the program, but if you have already ^6used LPRINT anywhere in your program, this will produce an I/O error, ^6as the PAR: port is left open by the LPRINT command.) ^1 So thats how to use the ANSI codes, but what do you do if you REALLY ^1want to use that quadruple size text mode, or redefine a character? ^1(And here I speak from experience, having written the LC10 , LC200, ^1and LC24-200 character defining programs, plug plug!) You have to dig ^1through the manual, find the escape code sequence you need, and send ^1it to the printer. But NOT by using LPRINT, or PRINT #1 to PRT: If ^1you do, what happens is that the printer driver sits there and goes - ^1"You what? Sorry guv, I don't follow that at all! Lets pretend you ^1didn't say that, and get on with the next bit". The best that can ^1happen is that it just ignores your carefully written sequence. More ^1likely, the poor printer will get a belly full of data that IT won't ^1understand, and just sits there bleeping, or starts printing reams of ^1garbage. ^4 No, to send that sort of specialised escape code sequence, you are ^4forced to send it directly to the PAR: device, using the OPEN OUT ^4method shown earlier. Using this method, you can send any data you ^4like, as an 8 bit byte. LPRINT CHR$(0) becomes PRINT #1,0 , which is ^4a good example of something that LPRINT won't do. You can then ^4achieve anything which your printer is capable of. ^6 But, my advice is this. DONT, unless you must. Using the PAR: ^6device ties you to a fixed escape sequence output. If you change ^6printer, or use escape code sequences that relate ONLY to one type of ^6printer, then if you want to distribute your program at all, there is ^6bound to be someone whose printer will not accept the data, and so ^6one less user for your application. Even if you keep the program to ^6yourself, who is to say you will keep that printer forever? ^1 For a general program, make use of the ANSI effects available to you ^1through PRT:, and save anything else for your own experiments, unless ^1you fancy distributing your program with dozens of drivers to cater ^1for all those different printers. ^4 On a general note, I would advise anyone NOT to bother with the ^4Printer Driver Generator programs floating around in PD. They are ^4utterly useless for anything other than text work, producing huge ^4drivers which DONT cope with graphics at all. Far better find an ^4existing driver for a similar printer, and suffer any failings that ^4come with it. ^6 (I notice that many Epson drivers interpret BOLD codes to mean ^6doublestrike, only if you are in draft mode first, sending ESC E to ^6turn it on, and ESC F to turn it off. This seems to have no effect ^6if you are already in NLQ mode on 9 pin printers, for instance, and I ^6prefer to get the real 'black' effect you get from ESC G and ESC H, ^6as this prints NLQ text in 4 passes (on my machine at least!). So, ^6one tip for the experts is to try something I did for the driver for ^6my LC10, which is to use a file ZAP program to edit the printer ^6driver directly on disc. (Only try this if you KNOW what you are ^6doing!) Starting with the EpsonXOld driver, I went through the file ^6byte by byte, and changed all ESC E to ESC G, and ESC F to ESC H. ^6(There were two occurences) This gives me a great bold effect in NLQ ^6mode.) ^1 Anyhow, that (briefly) covers the handling of text effects on the ^1printer. Before I wind up, though, it would be a good idea to cover ^1the things that have to be on the disc to make the printer work at ^1all. This is a common problem for people who start out to make their ^1own stand-alone discs, but find that the printer seems not to work if ^1you have not booted up from workbench first. ^7 To print from a stand alone disc, you need: ^5 Devs (the directory) ^5 Devs/system-configuration ^5 Devs/printer.device ^5 Devs/parallel.device (or serial.device if appropriate) ^5 Devs/printers (the directory) ^5 Devs/printers/(the printer driver will be called ^5 something like EpsonX, NECpinwriter ^5 or similar, and MUST be named in the ^5 system-configuration file, created ^5 by Preferences.) ^7.. as well as all the other files and directories your program needs. ^1 One final tip: some people find it hard to change the preferences on ^1their own non-workbench discs. Try this.. Boot up your own disc in ^1drive DF0:, holding down CTRL and D, to stop the startup-sequence ^1from running. When the CLI prompt appears, put the Workbench disc in ^1DF1:, and when it is ready, type DF1:Prefs/preferences (which is ^1where preferences lives in WB1.3) Edit the preferences until you are ^1happy with them, then when you save, the program saves the ^1system-configuration file to your own disc. ^4Remember, even if it doesn't work first time, you will learn a lot by ^4trying to fix it! ^3 Happy printing. ^4 Jeff. ^1P.S. from Jeff, to turn on NLQ, use:- ^1Print#1,CHR$(27)+"*z"+CHR$(34)+"z" ^6وووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووووو \