DOS Printer Toggle (PC World November 1983 Star-Dot-Star) Are you frustrated when a particular program will not support a print style or size that you would like to use for output? Do you sometimes wish that you could toggle your printer into any mode directly from DOS? A simple solution is available. Since a device name can be substituted for a file name, it is permissible to type COPY CON: LPT1:, which tells DOS to send input from the keyboard (CON:) directly to the printer. Realizing this, it is a simple step to key in the ASCII numbers of the characters needed to put the printer into any type style or size by using the key in combination with the numeric keypad. Here is an example that switches an Epson printer from normal pica into italics by sending the sequence followed by 4. Note that (ASCII 27) must have the value 128 added to it (27 + 128 = 155); otherwise DOS will react to the character. The printer will recognize ASCII 155 as having the same meaning as ASCII 27. COPY CON: LPT1: (Alt>155(on keypad)4(on keypad) The screen will look like this: COPY CON: LPT1:" /^D (/ = symbol for cents, c with a slash ^Z through it) 1 file(s) copied Now when you encounter a program that refuses to use the type style you prefer, have its output printed to a disk file for later printing. Then toggle the printer directly from DOS and type COPY filespec LPT1:" and the disk file will be printed in the chosen typeface. This technique is particularly powerful if you have a keyboard enhancement program such as ProKey -- all the commonly used printer toggles can be save as a ProKey files and invoked at any time with a single keystroke. For example, the toggle for compressed type could become C and proportional type could be P. ----------------------------------------------------------------- Easy Printer Control (from PC Magazine Vol 4 No 7 April 2, 1985 User-to-User) Resetting your printer control codes to use its special features can be frustrating. Most people resort to writing short BASIC programs to send the codes to the printer. The DEBUG utility can be used to create fast and tiny assembly language programs to do the job without loading the BASIC interpreter each time you reset your printer. With the procedure below and your printer manual, you can create routine settings for your printer as COM modules that load and run almost instantly. The program is created by DEBUG via the following procedure (hit Enter after each line): 1. Type DEBUG FILENAME.COM (substituting the name you want in place of FILENAME.COM). This starts DEBUG and tells it to use the filename you want to call your program . If it is a new file, a "File not found" error message will be returned. Ignore it. 2. Type A to start DEBUG's line-by-line assembler routine. 3. Type MOV AH,5 to tell the program it will be writing to the printer. 4. Type MOV DL,xx and then INT 21 to transfer a particular character, xx, to the printer. Hexadecimal notation is used for the character xx. For example, an ESC character would be represented as 1B in the instruction. You should repeat this two-instruction sequence as many times as necessary to send the control sequence you want to the printer. Most printer control sequences are two to six characters long. 5. Type INT 20 to end your program and let it return to DOS. Press the Enter key without putting in a new instruction to get back to the DEBUG command analyzer from the line-by-line assembler. 6. Type RCX and the x to load the CX register with the length, x, or your program to be written to disk. The length, x, is the number of bytes, in hex, of the program you assembled. In this program each instruction was 2 bytes long, so x would be 8, C, 10, 14, 18, 1C, and so on, depending on the number of times you repeated the two- instruction write to the printer for each character. 7. Type W followed by Enter to write your program to the file, and then Q and Enter to quit DEBUG. The 12-byte program below sends an ESC BELL (hex 1B 07) that will cause most printers to sound a bell or beep. It makes a good test to see if you understood the DEBUG procedure. The program is run by typing in the name of the COM module you created, PRTBELL and pressing Enter. Editor's Note: This is a handy way to send printer control codes. It takes up far less space on disk than a BASIC program and BASIC itself, and works much more quickly. Remember that the example below sends two characters, an ESC and a CHR$(7). If you're sending additional codes in the same .COM file and adding MOV DL, x and INT 21 instructions, remember to increase the value you're putting in the CX register. PRTBELL.COM: Hit Enter after each line, including the blank before RCX. A>DEBUG PRTBELL.COM -A -MOV AH,5 -MOV DL,1B -INT 21 -MOV DL,07 -INT 21 -INT 20 - -RCX -C -W -Q ---------------------------------------------------------------- Better Yet ... (PC Magazine Vol 4 No 14 July 9, 1985 Power User) This letter describes an even more general way to "quickly" write COM programs that send command sequences to your printer. In PC Vol 4 No 7 (above), a way was presented to send printer instructions while in DOS by using DEBUG to create a COM file. The BASIC program PRINPREP makes this almost effortless. The PRINPREP program creates a file, named whatever you want, with a filename extension of ".DAT", which contains the responses that DEBUG requires to create the COM file. It also creates a BATCH file (same name, but with a .BAT extension) that starts DEBUG using the .DAT file for input. When you run the .BAT program and DEBUG is done you have a COM file of the same name, and the .BAT and .DAT files are gone. Be sure DEBUG.COM is on the same disk with PRINPREP.BAS. Editor's Note: You can use it to send any printer command sequence you need to use. Just keep entering the ASCII characters or character codes. You need to send codes for control characters especially escape (which is character 27). Two or three digit numbers will be treated as ASCII character codes and single digit numbers will be treated as an ordinary character. Running the BATCH file will use the .DAT file to create the COM file. Be aware that you'll get an error message from DOS when the BATCH file finishes -- it's erased itself by then and DOS gets somewhat lost. When DOS invites you to "Insert disk with batch file and press any key when ready," hit Ctrl-Break and, in response to the query "Terminate batch job (Y/N)?", type Y and you will be back in DOS ready to run the COM file you just created. 100 'Program to make .COM programs for printer command sequences 110 ' 120 COLOR 7,1:CLS:LOCATE 5,1:I=1 130 INPUT "Enter .COM filename:>",A$:IF A$="" THEN 130 140 OPEN "O",1,A$+".DAT" 150 PRINT #1,"A" 160 PRINT #1,"MOV AH,5" 170 PRINT:PRINT "Enter Printer Command Sequences:" 180 PRINT TAB(4); "* Ordinary Characters or Punctuation Marks" 190 PRINT TAB(4); "* 2 or 3 Digit Numbers for ASCII Character Codes" 200 PRINT TAB(4); " (Use leading zeroes for one-digit numbers)":PRINT 210 PRINT "Press to quit.":PRINT 220 PRINT:INPUT "Enter Character of 2/3-digit ASCII code:>",C$ 230 IF C$="" THEN GOTO 300 240 IF LEN(C$)>1 AND VAL(C$)>0 or C$="00" THEN GOTO 260 250 C$=STR$(ASC(C$)) 260 D$=HEX$(VAL(C$)):IF LEN(D$)=1 THEN D$="0"+D$ 270 PRINT #1,"MOV DL,";D$ 280 PRINT #1,"INT 21" 290 I=I+1:GOTO 220 300 PRINT #1,"INT 20":PRINT #1,"RCX" 310 N=(I-1)*4+4 320 PRINT #1,HEX$(N) 330 PRINT #1,"W" 340 PRINT #1,"Q" 350 CLOSE 360 OPEN "O",1,A$+".BAT" 370 PRINT #1,"DEBUG %0.COM < %0.DAT" 380 PRINT #1,"DEL %0.DAT" 390 PRINT #1,"DEL %0.BAT" 400 CLOSE 410 SYSTEM --------------------------------------------------------------- DOS Note: Using BASIC 2.0, it is possible to duplicate the function of the Ctrl-PrtSc key combinatino under program control. To turn ON echo of screen output to the printer: DEF SEG:POKE &H758,&HFF To turn this printer echo OFF: DEF SEG:POKE &H758,0 This only works with BASIC 2.0 under DOS 2.0. ----------------------------------------------------------------- Perforation Problems (PC Magazine Vol 4 No 15 July 23, 1985 Power User) Many programs don't bother to skip over the perforations when printing on continuous form paper, and that can make a real mess, with characters printed half on one page and half on the next. You can change the DIP switch settings on an Epson MX, RX, or FX printer to enable a "skip over perforation" of about 1/2 inch on either side, but that's time consuming and can ruin the efforts of programs that are smart enough to skip the page breaks. There is a better way. Make a pair of batch files (call them PGBRKON.BAT and PGBRKOFF.BAT). Run PGBRKON before you print your listing and PGBRKOFF afterwards. PGBRKON copies a file named PGBRK.BEG (see below) to the printer, which enables a "skip over perforation," and PGBRKOFF copies a file named PGBRK.END to the printer, which disables it. This is PGBRKON.BAT: copy pgbrk.beg prn: This is PBGRKOFF.BAT: copy pgbrk.end prn: All you need are the two files, and the BASIC program below generates them for you. PGBRK.BAS will generate files that tell your Epson printer to skip over SKIPLINE% lines. The lines will be divided evenly between the current and next pages. If SKIPLINES% is set to 12, six lines will be skipped on one page and six on the next. The only restriction to correct operation is that SKIPLINES% cannot be less than 0 or greater than 127. Editor's Note: This can save aggravation, especially when listing programs from BASIC or another program editor. PGBRK.BAS is modified slightly to work correctly for all IBM printers (including the new Proprinter) and all compatibles, such as the Centronics GLP, Okidata Plug 'N' Play and Riteman Blue Plus as well as Epson. - - - - - 10 'PGBRK.BAS: Program to create PGBRK.BEG and PGBRK.END 20 SKIPLINES%=12 30 OPEN "PGBRK.BEG" FOR OUTPUT AS 1 40 PRINT #1,USING "\ \";CHR$(27)+"N"CHR$(SKIPLINES%); 50 CLOSE 1 60 OPEN "PGBRK.END" FOR OUTPUT AS 1 70 PRINT #1,USING "\ \";CHR$(140)+CHR$(27)+"O"; 80 CLOSE 1 90 END ----------------------------------------------------------------- Printer Resets Removed (PC World July 1985 Star-Dot-Star) When compiled BASIC programs run, they reset the printer to its power-on defaults. This is a nuisance when you want special printer settings to remain in effect while the compiled BASIC program executes. Printer reset commands can be eliminated from compiled BASIC programs. Make a backup copy of each program before you try to modify it. Copy the program onto a blank disk and rename it so that the extension is something other than .EXE. The command "COPY filename.EXE B:*.TMP" will perform both actions at once. Put a copy of DEBUG in drive A:, and use it to load the renamed program with the command "DEBUG B:filename.TMP". Then use DEBUG to search for the offending instructions, MOV AH,01 and INT 17. To do this, type the command "S 100 FFFF B4 01 CD 17" at the DEBUG prompt and DEBUG will display the location of the stored printer reset command. To eliminate the printer reset command, type the command "E xxxx:yyyy B4 02", replacing xxxx:yyyy with the contents of the line displayed during the prior step. For example, if DEBUG had displayed 4356:3A27, you would type "E 4356:3A27 B4 02". Finally, save the modified program with "W", exit DEBUG (Q) and rename the file so its extension is once again .EXE by using the command "REN B:filename.TMP *.EXE". The program will never again reset the printer, so special printer features will remain in effect until you decide to turn them off. Editor's Note: You can use the same technique to take care of almost any program that resets the printer, including BASIC and BASICA, versions 1.0 and 1.1. BASIC 2.0 and later versions do not reset the printer.) This patch replaces the printer reset command with a request for printer status. ----------------------------------------------------------------- Printer Control Sequences (PC Magazine Vol 4 No 19 Sept 17, 1985 Power User) The earliest attempts of PC users to send control sequences to their printers used the COPY command. For instance, COPY CON PRN can be used to enter the control sequences directly from the keyboard. This technique precludes typing an Escape code, however, since DOS interprets an Escape code by ignoring everything typed on the line and starting over again. Creating a 1-byte file called ESCAPE containing the Escape code (ASCII 027) helps somewhat when using the COPY command, for it could then be executed as, COPY ESCAPE+CON PRN. Only the remainder of the control sequence after Escape would need be typed in. You can also create tiny files containing entire control sequences with names like FORMFEED, COMPRESS, DOUBLE, and EMPHASIZ to turn features on, and COMPOFF, DOUBOFF, and EMPHOFF to turn features off. In this way, all you would have to enter is, COPY COMPRESS PRN. On a PC-XT hard disk, however, every file, no matter how small, takes up at least 4K bytes of space. Thus, these seven files to give you a simple printer control would use up 28K! The following articles provide different ways to control printers that solve the problems with the COPY command. A few ground rules: 1. The control sequences are for the IBM Personal Computer Graphics Printer. If your printer is not compatible, consult your printer manual for its equivalent control sequences. 2. The notation {###} is a three-digit number. This notation means: press the Alt key, type the three numbers on the number pad, and then release the Alt key. (It doesn't matter if NumLock is on or off.) Do not type the brackets. These keystrokes generate the character for the three-digit ASCII code you've typed. If the code is 128 or above, you'll probably see a foreign letter or graphics symbol on the screen. The ASCII code {000} cannot be entered this way but can be generated under DOS 2.0 with the F7 key. 3. Some control characters below 032, in particular the Escape (027) code, cannot be entered on the DOS command level. However, IBM, Epson and compatible printers allow adding 128 to the control character. Most of the examples take advantage of this feature. When creating batch files with EDLIN, you can enter ASCII codes below 032 by typing a Ctrl-V followed by the appropriate capital letter or symbol. For instance, Ctrl-A (ASCII 001) can be entered by typing Ctrl-V followed by A. An Escape code (027) is entered by Ctrl-V followed by the left bracket ([). The ASCII code 000 can be entered by pressing Ctrl-V followed by @, or, more simply, by pressing the F7 key. 4. DOS 2.0 or above is required for all methods shown below that use redirection (>PRN) and for the batch file examples. - - - - - Verified Printer Set-Up Using LPRINT in BASIC to send control codes to a printer is slow. An alternative method includes verification. If you want compressed print (ASCII code 015 or 143), for example, just issue the following at the DOS prompt: COPY {143} > PRN. DOS things that {143} is the name of a file. It won't find that file, so it writes the filename and the error message "File not found. 0 File(s) copied." But the redirection to PRN causes this filename and message to be printed on the printer. Because the "filename" is a control character, it switches the printer to compressed print. You can tell that the printer has been set to compressed print because the error message will be printed that way. You then advance your paper to the next full page to print any file you wish. - - - - - Very Tiny Print An obscure feature of the IBM/Epson printers combines compressed mode, subscript mode, and a 15/216-inch line spacing. This is one of the smallest, yet clearest, typestyles available on any printer, allowing 14.4 lines per inch (almost 160 lines per page). The printer is initialized for this miniature print with the following command at the DOS prompt: COPY {143} {155} S {001) {155} 3 {015} > PRN. - - - - - ECHO to Printer The DOS ECHO command can be used to generate printer control sequences. For example, ECHO {155} W1 > PRN changes printing to double width on the IBM Graphics Printer. ECHO also prints a carriage return and line feed, but you can live with that. The PRINTER.BAT file below provides a printer control batch file. You can expand and customize it as you see fit. You may want, for example, to shorten the names of the parameters to reduce typing time. When PRINTER is entered with no parameters, it prints the short help message at the end of the file. Entering a parameter by itself turns the feature on, and a parameter followed by OFF turns it off. Multiple parameters can also be entered. The batch file command SHIFT is used to retrieve and interpret each successive parameter. If your printer is currently in compressed mode, for instance, you can turn off that mode and begin printing in emphasized double-width with the command: PRINTER COMP OFF EMPH DOUB. The IF statement is case sensitive, so if you generally use lower case on the DOS command level, type the keywords (EMPH, DOUB, OFF, etc.) in lower case in the batch file. The IBM Graphics Printer does not have a "reset" control sequence that turns off all features and brings the print back to the default settings. A printer reset has to be done through software. But you can write a batch file called RESET.BAT that uses DEBUG to provide a software reset for the PC, as shown below. RESET.BAT loads DEBUG with keyboard input redirected from RESET.BAT itself. Don't worry about the error message when DEBUG loads. Lines 2 through 6 of RESET.BAT create a small program to reset the printer, the "g" runs the program, and "q" terminates DEBUG. You can also create a faster-acting RESET.COM file by replacing the "g" command with the following: n RESET.COM rcx 9 w Then run the batch file to create the permanent command. You can delete RESET.BAT after RESET.COM has been created. PRINTER.BAT: echo off if /%1==/ goto HELP :CHECKMORE if /%1==/ goto END if /%2==/OFF goto TURNOFF if %1==EMPH echo {155} E > prn if %1==DOUB echo {155} W1 > prn if %1==COMP echo {143} > prn if %1==TINY echo {143} {155} S {001} {155} 3 {015} > prn shift goto CHECKMORE :TURNOFF if %1==EMPH echo {155} F > prn if %1==DOUB echo {155} W0 > prn if %1==COMP echo {146} > prn if %1==TINY echo {146} {155} T {155} 3$ > prn shift shift goto CHECKMORE :HELP echo Parameters: EMPH (Emphasized), DOUB (Double-Width) echo COMP (Compressed), TINY (Tiny Print). echo To turn feature off, follow parameter with: OFF. :END RESET.BAT: goto END a mov dx,0 mov ah,1 int 17 int 20 (blank line here; just hit carriage return) g q :END debug < reset.bat - - - - - SideKick Printer Control You can generate printer control sequences using SideKick. Create a notepad called PRINTER and turn on the graphics mode with the SideKick command Ctrl-QG. Then, set up a table with commonly used control sequences. Typing in the Alt sequences must be done quickly or the SideKick menu will pop up! Now call up the notepad from within your applications program, block off the appropriate control sequence with the SideKick block commands Ctrl-KB (or F7) and Ctrl-KK (or F8), and then do a Ctrl-KP, which prints the block. The control sequence is then sent to the printer. A condensed version of a SideKick notepad is shown below. ASCII codes of 128 and above can be entered with the Alt key and the number pad. ASCII codes below 032 are entered as Ctrl-key combinations, but they must be preceded by a Ctrl-P. The ^P^E in the example below means type P and E with the Ctrl key held down. The SideKick notepad will show an E in reverse video. The ASCII code for Escape (027) can be entered directly in a SideKick notepad by type ^P^ (a Ctrl-P followed by Ctrl-[). ON OFF Emphasized {155} E {155} F Double Width {155} W1 {155} W0 Compressed {143} {146} Skip Perforation {155} N^P^E {155} O