Printer Programming

See all articles from SINCUS v6 n4

– OR – Adapting Software to Printers

The article about printer control in the October Issue brought forth enough response to indicate that a more comprehensive reference should be attempted. Apparantly many users are having problems in this area. One nice Lady wrote her thanks, and several Gents wanted more information. But John Oliger wrote and pointed out a couple of mistakes. These will be corrected in the text of the following.

Why doesn’t software writers include enough programming to make the software print “right out of the box” with ALL TYPES of printers? Well, that would be nice, but would likely require about 38K of programming, and our TS-2068 has only 38K of FREE memory to start with. So, usually a software is designed to print with a type of printer that is “compatable with” several brands, and instructions given to make program line changes to adapt to other printers. There are several DOT MATRIX printer brands that use the “EPSON STANDARD”, which usually means that the printer maker copied the Epson “Control Codes”. Two “Standards” widely used with Daisy Wheel printers are “QUEME Compatable” and “DIABLO Compatable”.

In order for a computer to communicate with a printer, both devices must understand a common language. That common language is called ASCII (American Standard Code for Informaton Interchange). Page number 239 of the TS-2068 User manual gives the ASCII Codes and calls them “The Charactor Set”. Actually there are more codes in ASCII than the TS-2068 uses, and a few of the codes in the TS-2068 CHR SET are not standard ASCII, but for printer control, the codes in the User Manual will suffice.

So, we have the “common language”, which is ASCII. The computer understands it and so does the printer. Now there are two jobs that the printer must do. One is to PRINT CHARACTERS, and the other is to SWITCH its own modes of printing. To PRINT characters the printer must be able to receive and to respond rapidly to “streams of characters” sent by the computer. The charcters are processed by a “printer driver”, a machine language software that is supplied by the manufacturer of the “PRINTER INTERFACE”. Since the TS-2068 contains only a printer driver for the little TS-2040 printer, ALL interfaces for large printers are supplied by our Cottage Industries. Some of these are “Serial Interfaces”, but most are CENTRONICS PARALLEL interfaces.

We will delay the discussion of Serial (RS-232) interfaces until the next issue of UP-DATE. For this discussion we will deal only with CENTRONICS PARALLEL interfaces, and only with the OLIGER and AERCO interfaces. These two “CPI” devices have become the dominant ones for the TS-2068, the most simple to use, and they use a minimal amount of computer memory for their printer driver code. In fact, the Disk Drive controller hardware contains the printer driver code in its EPROM, thus using no computer memory at all. These interfaces provide the electronics circuitry to process character streams and coded directions to a printer and to RECEIVE the “interrupt signals” from the printer.

The software “driver code” is an extension of the TS-2068 ROM, which lacks the “built in instructions” necessary to send data and commands to the printer. While the Oliger and Aerco CPI interfaces are different in circuitry, the driver codes supplied with each can be used with the other interface. Now lets get to the two functions of these CPI interfaces. One function, and the most complicated, is the processing of Character streams to the printer. Actually this is the most simple to use. <LPRINT> does it! You dont see the many complicated functions that take place, and you dont have to worry about it.

The other CPI function is to “Process Control Codes to the Printer”, to make it do such things as Change from Elite Style to Pica Style, Roll up a Page, or the other mechanical functions that the printer does. The Interface uses “OUT PORT 127” as the communications path to the printer, and the path back from the printer for “interrupts”. So, the “ASCII COMMAND” that a printer needs to do a desired function is sent “OUT through PORT 127”. A typical direct command to click up a line space is <OUT 127,10>. “10 decimal” is the industry standard ASCII CODE for printers to perform a LINE FEED. There are 32 “single character codes”, 0 through 31, in the TS-2068 Character set that can be “sent out” in this manner.

Actually there are 255 character codes that can be sent out to the printer, but only 32 can be sent out “without a character being printed”. All of the other 223 codes will cause something to be printed. Example, <OUT 127,65> will result in the character “A” being printed. This is because ASCII CODE 65 is assigned to the character “A”, and the interface processes data characters to be printed. Some printers use as many as 80 ASCII CODES to perform internal changes. For example, a Diablo Daisy Wheel printer uses ASCII CODE 79 to “SET BOLD PRINT”. BUT <OUT 127,79> PRINTS a “O”! The solution to “sending printable ASCII CODES” to the printer is to first send the “ESC COMMAND”.

The “ESC” code is “27”. So, using the above example, <OUT 127,27> then <OUT 127,65> will command the Diablo printer to SET BOLD PRINT. The ESC code (27) tells the printer to “Expect a CONTROL CODE NEXT”. Printer manuals vary as to how their CONTROL CODES are given. Most manuals have a table of control codes with numbers given in both HEXADECIMAL and DECIMAL. A typical such expression would be given in brackets as (18,4D)H (27,77)D. The first group is given in Hex and the second group in Decimal. In this case, our TS-2068 command would be <OUT 127,27> <OUT 127,77>. Another way that the SAME command group could be presented is <ESC M>. “ESC=27 and the Character Code of “M” is 77″.

Still another way given in some printer manuals is <LPRINT CHR$(27)+M>, which isn’t the correct way of sending such codes with the TS-2068, but can be intrepeted as OUT 127,27:OUT 127,77. So, with all of these different ways of saying the same thing, it’s no wonder that printer manuals are confusing! Incidentally, that ONE command group is used by Epson printers to SET ELITE PRINT MODE. Command codes to perform a single function may be as many as six codes chained together. Example: (27,120,1)D (155,120,1)D. The “D” for Decimal may or may not be present. That command group SETS HI QUALITY MODE for Epson printers. The command for the Aerco and Oliger CPI would be <OUT 127,27: OUT 127,120: OUT 127,1: OUT 127,155: OUT 127,120: OUT 127,1>, quite a long group of OUTs to do just one switching function!

Now its gonna get longer, because that group of six OUT commands execute in about 100 milliseconds, and the printer requires much more time than that to respond to SWITCHING commands. For Software programming lines to Command the printer, we must have a “CHECK OF THE PRINTER STATUS” routine TO SEE IF THE PRINTER IS BUSY before sending a control code. When the printer is busy it places a interrupt signal on IN PORT 127. If the printer is busy then the software must wait until the printer is READY before sending the control code. The correct way to do this with the Oliger CPI is to use the loop given in the interface manual, which is <100 IF INKEY$ #3=”B” THEN GO TO 100> <102 RETURN>. Then a control code group such as (27,45) would be programmed in a line as: <50 GO SUB 100: OUT 127,27: GO SUB 100: OUT 127,45>. The line 100 will loop itself until the printer is READY, then the line 100 IF condition will be FALSE and the RETURN will allow the next OUT command to execute.

The above “INKEY$ #3” polls the IN PORT 127 for the bits used by printers to signal its status to the computer. But, this procedure requires a interface driver that processes the INKEY #3 syntax. If you use another type of interface you should check its manual for a PRINTER STATUS CHECK routine. The use of INKEY$ #3 returns a “improper I/O device” report when used with some other interfaces. If you get such a report code you can turn OFF the printer and type <PRINT IN 127>. Then use that number in the status check routine. My system produces 253 when the printer is BUSY. Mr. Oliger tells me that all bits of IN PORT 127 are not not controlled the same with all models of the TS-2068. His words are quoted: “A program loop such as the example given (100 IF IN 127=253 THEN GO TO 100) (102 RETURN) should not be used and this is not how the printer interface manual instructs this to be done. This is the kind of thing that works with one computer but not on another, because all of the bits on IN PORT 127d are not used, and thus are floating. The function INKEY$ #3 should be used for this purpose as detailed on page 6 of the Oliger Interface manual.”

Pardon me for digressing into the complicated. This is supposed to be a SIMPLE treatsie about how to clear the fog in printer manuals and CONTROL your printer with program lines. We will get back to that. Other interfaces such as TASMAN and A&J use LPRINT CHR$ instead of OUT 127. Many printer manuals express their EXAMPLE commands in this manner, LPRINT CHR$ 27, as the ESC command, instead of OUT 127,27. Thats alright if you know how to intrepet such red herrings. The Oliger and Aerco interfaces just wont work with LPRINT CHR$, and must have OUT 127,number.

To sum up: When ESC is given, it means OUT 127,27. When a letter character is given as a command code, look up the ASCII code for the letter on page 239 of the TS-2068 User Manual and use the CODE number as the command. When constructing program lines to Command the Printer, each OUT 127 should be preceeded with <GO SUB> to the “STATUS CHECK” routine, which for the Oliger and Aerco CPI is <100 IF INKEY$ #3=”B” THEN GO TO 100> then a following line <102 RETURN>. The line numbers can be of your choosing. There is no limit as to the number of “chained commands” that can be in one program line. Many printers require as many as six chained commands to perform one function change of the printer.

You cannot use HEXIDECIMAL numbers in your OUT 127 command. HEX numbers must be converted to decimal, if not given in the printer manual. Page 239 of the TS-2068 User manual gives the codes in both Hex and Decimal. Printer control sequences given in a printer manual, such as: (ESC * 0 2) must be intrepeted by looking up the codes for “*” (42), for “0” (79), for “2”, (50). We know that ESC is 27. So, the chained commands would be entered in a program line as follows: <500 GO SUB 100: OUT 127,42: GO SUB 100: OUT 127,79: GO SUB 100: OUT 127,50: RETURN >. GO SUB 100 would be to the INKEY$ #3 routine to check the printer status.

Your printer and the software can both be OK, but all you get is partial lines of print that lap over onto the next line, because of improper printer switch settings. Most softwares completely control the printer and require that no MARGINS be set at the printer, the auto PAGE ADVANCE be turned OFF, the printer LINE JUSTIFICATION be turned OFF, the PORPORTIONAL PRINT PRINT SPACING be turned OFF, and for letter size pages, the LINES PER PAGE setting at the printer should be 60 lines per page. Then the software and the printer wont be fighting each other to control margins, character spacing, and page length. Let the software do the controlling, and let the printer be DUMB, just responding to “Simon Sez” commands given by the software.

The printer switch that sets a LINE FEED with each CARRIAGE RETURN should be ON. Then a line feed will occur each time a line is printed. A Carriage Return command is sent by the sotware each time a line has printed, or the “partial last line” of a paragraph. Now this just about sums up “everything that anyone will ever need to know about Commanding printers with the Oliger and Aerco CP Interfaces”. Next issue we will discuss a RS-232 Serial interface. In the meantime perhaps someone would like to send in a treatsie about “printer commanding with the TASMAN CPI. Permission is hereby given for TSUG Clubs to make re-prints of this article or excerpts thereof.

TS2068 cartoon, "Took A Booting... But Kept On Computing!" - Artwork by Wes B.
TS2068 cartoon, "Took A Booting… But Kept On Computing!" – Artwork by Wes B.

Thanks:
TO: TS2068 UPDATE-THE USER’S NEWS FOR ALLOWING THE RE-PRINTING OF THE ARTICLE-“PRINTER PROGRAMMING”