Controlling Your Printer

Authors

Publication

Pub Details

Date

Pages

See all articles from SyncWare News v1

In this series of articles, I’ll try to give you some information to help you use your printer system “to the max.” We’ll start with a discussion of the ASCII character set, and follow with some information about the Memotech Centronics Interface (CIF) which will demonstrate rudimentary methods of controlling the operation of your printer, In the next issue, we’ll take what we know and develop some BASIC programs to do graphic screen dumps and write letters. You should then be able to adapt the programming to your system and needs,

Our goal throughout this series will be to complement rather than replace your ZX81, CIF (or SIF) and printer manuals; keep them handy as you will refer to them often, Our discussions will be general enough to apply to either the Centronics parallel (CIF) or RS232 Serial (SIF) interfaces by Memotech, though we will refer only to CIF.

First, a discussion of the ASCII character set is in order. This is the set of codes virtually all printers (and most computers) use for data transmission. Like the Sinclair character set, ASCII consists of 256 codes – but here the similarity ends. Compare the Sinclair set (Appendix A of ZX81 manual) with the ASCII table in your printer manual. They aren’t even close! So it’s quite apparent that translation is necessary; more about that later. To avoid confusion in this discussion, we will use CHR$ to refer to Sinclair characters (only) and ASCII$ to refer to ASCII characters, Printer manuals usually give examples using CHR$. NOTE: By our definition these should be mentally changed to ASCII$.

The ASCII code was originally designed for 7bit interface, leaving the 8th bit free for future expansion. Thus, only the first 128 codes are really standardized. The first 32 codes (0-31) are not “characters” at all, but are various CONTROL CODES. These perform such functions as line feed, carriage return, change character width, etc. ASCII$ 127 (DEL) is also a sort of control character (deletes last character sent). They have various mnemonic labels, but with the exception of ESCape and DELete these will probably not be of much use to you. Consult your printer manual for a description of each of these functions.

This leaves 95 codes for characters, plenty for upper & lower case letters, numerals, and symbols. But what’s an equipment designer to do if the public clamors for even more available characters? Bright idea No. 1: use the eighth bit as well, for a total of 256 codes. Refer again to your printer manual for the characters that “live” in the high block; they will include block graphics, math symbols, etc. To insure 7~bit compatibility, the lower block remains the same; furthermore, the control codes are duplicated in the high block (128-159, 255). As a result, there are two codes for each control function in 8-bit systems; e.g. ESC can be. called either with ASCII$ 27 or ASCII$ 155.

Great! Now we’ve got oodles of available characters (190 to be exact), but we still have only 33 control codes. Bright idea No. 2; assign a special control code (ESCape) that tells the printer that the next character is a control code. ASCII$ 32-126 can then be used either “as-is” (characters) or to specify a control code (when prefaced by ESC = ASCII$ 27/155). We thus have up to 128 control codes available. The diagram below should help clarify this.

The “usual” codes are shown (for our purposes) as “group I,” and the “extended” codes as “group II.” So how do we get Memotech’s CIF to send these various groups? Let’s start with the easy ones and work up.

Group I Characters

These characters are directly accessible using LPRINT. For example, LPRINT “X” and LPRINT CHR$ 61 will both print an upper-case X. The CIF automatically translates CHR$ into ASCII$ using its built-in conversion table. Inverse letters are printed lower-case. Inverse symbols (except inverse period CHR$ 155) are redefined as various useful symbols as #, %, !, @, etc. Three of the graphics symbols (CHR$ 6, 136, and 137) are used for I/F control (HRG, etc.) and are off-limits. The other graphics are ignored (they’re Group II characters, and are covered later). These “quirks” also exist using LLIST and COPY – which is why you should use CHR§ (N) instead of “graphic” (e.g. PRINT CHR$ 134, not PRINT “[graphic on Y]”) if you want the program LLISTable. COPY is only useful for screen-dumping alpha-numerics. As a side note, your printer is itself a sophisticated computing system, complete with CPU(s), RAM, and operating system, and yes it can be crashed like any computer. If you like crash graphics you’ll love some of the printouts you get when you do a no-no. Often the computer will stay up, and you just have to re-initialize printer using the ON-OFF switch.

Controls Group I

These are also easy to access. Along the lines of “Bright Idea No. 2,” Memotech provides an easy access by defining an “escape code” (CHR$ 155 inverse period) that allows you to imbed control codes 0-32 in your text. CHR$ 155 flags the INTERFACE that the following character is a control. The numbers and letters 0-9, A-V are automatically translated to ASCII$ 0-31. (Subtracts 28 from Sinclair code in this special case.) Note that even though the same number is used as for the upper ASCII ESC code (a nice touch, perhaps serendipitous) the printer itself need not see this CHR$ 155 as it doesn’t require ESC to access the Group I controls.

Group Il Controls – Characters

I’m lumping these together, since as far as the CIF is concerned they are handled identically. Since they are “untranslatable” by CIF, Memotech provided a “back door” with which you can send ASCII codes directly – including but not limited to the “standard” characters below 128. This is done by POKEing ASCII code into a 1 REM statement (which must be the first thing in your program) and then executing (send to printer) when you use the command LPRINT CHR$ 6 (or LPRINT “[{graphic on T]”), Everything from address 16514 on is sent to printer un-translated. By prefacing codes with ESC (good old ASCII$ 27/155), we can send controls as well.

Since what you’re putting into this 1 REM statement is in ASCII, when you LIST 1 your screen won’t show anything near what will be printed. Some codes will goof up the LIST routine, so you should avoid listing it anyway. (By the way, if you’re having trouble following this, refer to the CIF manual and the “Hello Badger” example.)

Conversion Table

Gee, why not make up a custom conversion table for your specific printer? Good idea. That will provide the basis for graphics dumps and math symbols, etc. We’ll close this installment with an example of how to accomplish this. Play with it, figure out how it works, and see if that won’t help spruce up your printed output! Next time you get my solution to graphic dumps and a “Caveman WP,” but until then, why not work up your very own?

1 REM XXXXXXXXXXXXXXXXXXXXXXXX (255 X characters)
10 FOR A=16600 TO 16855
20 PRINT (STR$ (A-600))(3 TO );"=";
30 INPUT B
40 PRINT (STR$( (B+1000))(2 TO );":";
50 POKE A,B
60 IF A=16687 OR A=16675 THEN GOTO 80
70 NEXT A
80 COPY
90 CLS
100 IF A<16856 THEN GOTO 70

Enter and RUN the conversion table loader. When you’re prompted with a Sinclair code, enter the corresponding ASCII code from your printer manual. E.g., Sinclair code 00 = “space” = ASCII code 32, etc. If you have the printer on-line, it will COPY each screen when complete.

The following table, which I wrote for Gemini 10/10X, assigns special characters to the various Sinclair tokens. You may have to change the codes over 160 to accommodate your machine. Then, overwrite the loader with the TEST program and add the 8000 subroutine that allows this fancy printing. RUN the TEST program after SAVEing to tape. What you’ll get is a self-test of your modified character set. Then you may enter strings to your heart’s delight; graphics are a snap now, as are the “specials.” Can you write a screen-dump subroutine?

10 LET Z$=""
20 FOR B=0 TO 255
30 LET Z$=Z$+CHR$ B
40 IF LEN Z$=64 THEN GOTO 70
50 NEXT B
60 IF B=257 THEN GOTO 100
70 GOSUB 8000
80 LET Z$=""
90 GOTO 50
100 PRINT "GRAPHIX TYPEWRITER"
110 PRINT "ENTER A STRING UP TO 80 CHAR."
120 INPUT Z$
130 IF LEN Z$>80 THEN LET Z$=Z$( TO 80)
140 PRINT Z$
150 GOSUB 8000
160 GOTO 120
8000 REM GRAPHICS PRINT
8010 FOR A=16514 TO 16513+LEN Z$
8020 POKE A,PEEK (16600+CODE Z$(A-16513))
8030 NEXT A
8040 POKE A,0
8050 LPRINT CHR$ 6
8060 RETURN

Products

 

Downloadable Media

 
Scroll to Top