home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
info
/
dostips6.arc
/
EGAPRINT
< prev
next >
Wrap
Text File
|
1987-01-03
|
6KB
|
216 lines
Printing EGA Graphics
(PC Magazine Vol 6 No 2 Jan 27, 1987 PC Tutor)
The Programming/Utilities columns on the Enhanced Graphics
Adapter ("Exploring the EGA," Vol 5 No 14 and 15) had nothing about
printing EGA graphics displays on the printer.
The topic of printing EGA graphics displays was avoided since
it's a subject that reveals nothing very interesting about the EGA
itself. It's principally a printer problem.
There is no real standard for implementing graphics on printers.
If an EGA graphics screen dump program were to be written, it would
probably be for the IBM Graphics Printer and compatibles, since it's
as close to a standard as exists. But even IBM Graphics Printers
don't do well printing 16-color graphics. The printer does not have
enough resolution to use different dot densities for different colors.
However, if you're doing EGA graphics programming in BASIC, it's
fairly easy to write your own screen dump subroutine to do what you
want it to. This requires some familiarity with the graphics control
sequences of your printer. The QuickBASIC 2.0 subroutine below is
one such demonstration program.
' Printing EGA Graphics Screens from QuickBASIC 2.0
'
SCREEN 9 ' Use 10 for EGA on monochrome
FOR I% = 1 TO 100
CIRCLE (INT(640*RND),INT(350*RND)),INT(100*RND),INT(16*RND)
NEXT I%
CALL PRINTSCREEN
SCREEN 0 ' Restore to normal
END
' PRINTSCREEN Subroutine
'
SUB PRINTSCREEN STATIC
WIDTH LPRINT 255
LPRINT
FOR ROW% = 0 TO 349 STEP 8
LPRINT CHR$(9); SPC(4);
LPRINT CHR$(27); "L"; CHR$(128); CHR$(2);
FOR COL% = 0 TO 640
BYTE% = 0
FOR PIXEL% = 0 TO 7
IF POINT(COL%,ROW%+PIXEL%) > 0 THEN
BYTE% = BYTE% OR 2^(7-PIXEL%)
END IF
NEXT PIXEL%
LPRINT CHR$(BYTE%);
NEXT COL%
LPRINT CHR$(27); "J"; CHR$(24);
NEXT ROW%
END SUB
The top of the program switches to an EGA graphics mode, draws 100
random circles, and then calls the PRINTSCREEN subroutine.
(You could also write this program in BASICA 3.2 if you added
line numbers and used a GOSUB instead of a CALL.)
As written, the PRINTSCREEN subroutine works only with the IBM
Graphics Printer and compatibles. The line:
LPRINT CHR$(27); "L"; CHR$(128); CHR$(2);
switches to the 120-dot-per-inch graphics mode and prepares the
printer to accept 640 bytes of graphics data. The horizontal
resolutino of the EGA graphics modes 15 and 16 (represented in BASIC
as 10 and 9) is 640. The 640 is calculated from the last two numbers
in the CHR$ functions: 640 equals 2 times 256 plus 128.
Each of the 640 bytes of graphics data sent to the printer
contains 8 bits, 1 for each of 8 vertical pixels. The byte is
assembled by reading the pixels from the screen using the POINT
function. Any pixel that is black gets a bit set to 0. Any pixel
that is not black gets a bit set to 1. This byte is then sent to
the printer:
LPRINT CHR$(BYTE%);
After the whole row of 640 bytes has been sent to the printer,
8 of the 350 display scan lines have been printed, and it is time to
do a carriage return. Since the vertical resolution of the IBM
Graphics Printer is 1/72 inch, 8 dots are 1/9 inch high, which means
the line spacing must be 24/216 inch:
LPRINT CHR$(27); "J"; CHR$(24);
Now it's time for the next 8 rows of pixels.
Keeping the graphics screen dump in the same BASIC program that
generates the graphics has some significant advantages. Your program
can control when the screen is printed. You could pass parameters to
the subroutine to print only part of the screen, or you could print it
over at the left or right of the page and add some text in the margin.
If you'd rather have a graphics screen dump routine triggered by
Shift-PrtSc, the EGAGRAF.SCR file below creates EGAGRAF.COM with DEBUG.
This is a remain-resident program that works only with the IBM Graphics
Printer and compatibles. Run:
DEBUG < EGAGRAF.SCR
EGAGRAF.COM remains resident in memory until you reboot. When you hit
the Shift-PrtSc combination in video mode 15 (equivalent to BASIC's
mode 9, i.e., EGA 640 by 350 graphics on a monochrome display) or 16
(BASIC's mode 10, i.e., EGA 640 by 350 graphics on an Enhanced Color
Display), the resident program will print the contents of the screen.
Like the QuickBASIC subroutine shown above, EGAGRAF.COM prints a
dot for every color except the background. This causes white-on-black
graphics (or, in the case of the monochrome display, green-on-black
graphics) to be printed as black on white. This reversal of colors is
normal when printing graphics. If you want black printed as black and
all other colors not printed, change the CMC line to NOP, instead.
EGAGRAF.SCR:
N EGAGRAF.COM
A
JMP 01C2
DW 00,00
DB 02,0D,0A
DB 09,09,20,20,20,20,1B,4C,80,02
DB 03,1B,4A,18
PUSH AX
PUSH BX
PUSH DS
MOV AH,0F
INT 10
AND AL,7F
CMP AL,0F
JB 0135
CMP AL,10
JA 0135
MOV AX,0050
MOV DS,AX
CMP BYTE PTR [0000],01
JNZ 013D
POP DS
POP BX
POP AX
CS:
JMP FAR [0103]
MOV BYTE PTR [0000],01
STI
PUSH CX
PUSH DX
MOV BX,0107
CALL 0199
SUB DX,DX
MOV BX,010A
CALL 0199
SUB CX,CX
MOV BX,0800
PUSH BX
SUB BH,BH
MOV AH,0D
INT 10
POP BX
CMP DX,015E
JNB 0169
CMP AL,01
CMC
RCL BL,1
INC DX
DEC BH
JNZ 0158
MOV AL,BL
CALL 01A8
SUB DX,+08
INC CX
CMP CX,0280
JB 0155
MOV BX,0114
CALL 0199
ADD DX,+08
CMP DX,015E
JB 014D
MOV BYTE PTR [0000],00
POP DX
POP CX
POP DS
POP BX
POP AX
IRET
CS:
MOV CL,[BX]
SUB CH,CH
INC BX
CS:
MOV AL,[BX]
CALL 01A8
LOOP 019E
RET
PUSH AX
PUSH DX
SUB DX,DX
SUB AH,AH
INT 17
TEST AH,29
POP DX
POP AX
JZ 01C1
MOV BYTE PTR [0000],FF
ADD SP,+02
JMP 0193
RET
MOV AX,3505
INT 21
MOV [0103],BX
MOV [0105],ES
MOV DX,0118
MOV AX,2505
INT 21
MOV DX,01C2
INT 27
RCX
DC
W
Q