-------------------------- The Printer Is Your Slave! -------------------------- The printer is a DEVICE, yet so many people don't know how to use it. This article will discuss the fun stuff that you can do by using, (and abusing) keywords and bugs in Basic to master the printer. There are alot of nifty things that a printer can do, that no one seems to know about. Tis first trick I will tell you about came around back in the dawn of the computer age, when Computers didn't have screens. They displayed everything my printing it. These printers were so big, they were in separate rooms from the computer. Early hackers at MIT, because computers weren't complex enough to warrent the creation of viruses, made programs that looped, spitting out pages of paper. They did this with little known ASCII character 12. 12, when sent to the printer, tells the printer to spit out a page of paper. The thing is ASCII code 12 is a STANDARD. This means EVERY printer EVER made will eject a page when it gets it. Form a 1979 Epson dot matrix to a 1998 HP LaserJet pro. This is a good thing to know, because with modern laser jets, they don't eject the page they are printing on until that whole page is filled up, or you manually tell the printer to eject the page (you have to push a button). Ok, you think, what can I do to use this in my programs? Simple, if you have any printing in your program, finish it with a "LPRINT CHR$(12)" command. In fact, as you will read in the article "Your OS on Steriods" next issue, I made and compiled a little program, now called "Eject.exe", that spews a page from your printer. Another cool thing is called IBM/Epson Control Codes. These bad boys let you do cool things to stuff being sent to the printer. Almost all printers use these codes, unless they are very old (late 60's to mid 70's), these codes should work. These codes allow for weird stuff like underlining, bold text, and changing the number of characters per inch. You can really mess up your printer with these, and it stays that way until you turn off your printer. Most IBM/Epson codes begin with ESC (ASCII character 27), followed by other ASCII characters. Here are some: Function BASIC CODE: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Begin Italics LPRINT CHR$(27);CHR$(52); End Italics LPRINT CHR$(27);CHR$(53); Begin Underlining LPRINT CHR$(27);CHR$(45);CHR$(49) End Underlining LPRINT CHR$(27);CHR$(45);CHR$(48) Begin Bold LPRINT CHR$(27);CHR$(69); End Bold LPRINT CHR$(27);CHR$(70); Clear Printer Buffer LPRINT CHR$(24); ***This printer buffer is the one inside your printer, and in NO way is realted to the MS-DOS "PRINT" command GRAPHICS. Everyone thinks that the printer can only print text. Wrong! All printers can print graphics. These is some way you can send "graphics data" to your printer after use some IBM/Epson Control Code, but my old printer manual (1987) doesn't say what format it is in. So I tried a lot of stuff. I tried GETting a picture into an array "gfx" and then used "LPRINT gfx ", but it didn't work. I tried sending one byte of data to the printer using a FOR-NEXT loop. I tried then BSAVing the graphic and then opening the file in binary format, and sending it that way. Nothing worked. So the only way I could print graphics was to display them on the screen with PUT or using LINEs, CIRCLEs, etc, and then printing the screen. Please know that for this to work, you MUST run "graphics.com" in DOS. I have it in my Config.sys to load up. It is a TSR, and only takes a small about of memory. The final thing I want to tell you about is about printing the screen. There are 3 ways I know of to do this. The first and easiest is to simple press [SHIFT] + [PRT SC] (yours my not be "prn sc", but you should be able to figure out which key I mean). This prints the screen to LPT1, and if it doesn't exist, well, nothing happens, DOS doesn't return an error message. The other two methods seem pointless when you have a key on the keyboard for printing the screen. Well, the only reason I include this next example is because you can can test to see if the printer is working or not. The following is a Qbasic code bit I got from Qbasic's help file. It is a simple (their words, not mine, I know jack about CALL absolutes) Call absolute to print the screen. I am not going to say how it works, Assembly confuses the HELL out of me, and this is Machine code, a step LOWER than Assembly. Basiclly, this puts the numbers 205, 5, 203 into memory in a% space in memory, an then uses Call absolute to run the program. 205, 5, 203 are the machine code numbers of an Assembly program. You really don't need to learn ASM, it is antoher language, and is qutie tough. I will talk About it in an upcoming issue. (from Microsoft's Qbasic 1.1 HLP file with DOS 6.22) DIM a%(2) DEF SEG = VARSEG(a%(0)) FOR i% = 0 TO 2 READ d% POKE VARPTR(a%(0)) + i%, d% NEXT i% DATA 205, 5, 203 : ' int 5 retf 'Machine-language code 'for printing screen. CALL ABSOLUTE(VARPTR(a%(0))) DEF SEG Ok, whatever. Now, Why do I do this instead of using the print screen key. Simple, error trapping. If you are printing something already (you used the DOS command PRINT, then entered Qbasic), you can tell the user that the print is being used by something else, and to wait. The best part of this is you can find out if the printer is even on. Better still, You can use the KEY statements and functions, and make it so that pressing [F12] prints the screen. The final method I mention only so I can say this is the COMPLETE record of ALL ways to print the screen. This only works on text, and I guess is usefulk if you want to print the text of a screen that has graphics. FOR row = 1 to 25 a$ = "" FOR Cl = 1 to 80 a$ = a$ + CHR$(SCREEN(row, cl)) NEXT LPRINT a$ NEXT LPRINT CHR$(12) 'eject the page -------------------------------------------------------------------------------- This tutorial originally appeared in the QBasic Developers Forum, Issue #2. This was written by Lord Acidus.