This article takes you step by step through the design of a graphics dump routine.

Let's look at some techniques involved in copying the graphics window to a printer.

First of all, we have to match the number of columns in the graphics display to the number of columns on the printer. My printer is 80 columns, so GRAPHICS 4 and GRAPHICS 5 (both 80 column modes) are a natural fit. If your printer is different, don't worry. We'll come back to that question later. Let's take the easy situation first, then modify the program as necessary.

For an 80 column printer, the simplest case is GRAPHICS 4: 80 columns by 40 rows, just two colors. We must make the graphics cursor look at each pixel on the screen and tell us whether it is blank (background color) or displays a spot of light. This is easy to do with a double FOR-NEXT loop and Atari's LOCATE command. See Listing 1. At the start, Y = 0 (line 10). This corresponds to the top row of the screen. Line 20 then increases X from 0 to 79, one step at a time. Line 30, LOCATE X, Y, Z, causes the cursor to move across all 80 columns (X values) for this value of Y. It also returns the value of Z, the pixel color, at each location. If Z = 0, this is background color, a blank spot. If Z = 1, a spot of color is found on the screen. The cursor then moves on to the next column (NEXT X). When it reaches the end of the row (X = 79), it moves to the next row (Y = 1) and starts a new horizontal scan (X = 0 to 79 again). See Program 1.

Now all we have to do is tell the printer what to print. If the screen is blank at a given location (Z = 0), we tell the printer to print a blank space, and then go on to the next X:

40 IF Z = 0 THEN LPRINT CHR$(32) ; : GOTO 60

Don't forget the semicolon. It prevents carriage return. If there is a spot of color at this location, Z is not zero, and we want the printer to print something. You can select any character you want by consulting the list of ASCII characters and numbers for your printer. Let's pick the *, ASCII number 42, and add:

50 LPRINT CHR$(42);

Now we have a complete program for copying the GRAPHICS 4 graphics window to an 80 column printer. (Program 2.)

In case you have trouble with no carriage return, try adding:

65 IF X = 79 THEN LPRINT CHR$(13)

If you get no line feed, make it:

65 IF X = 79 THEN LPRINT CHR$(10)

If necessary, use both:

65 IF X = 79 THEN LPRINT CHR$(13) : LPRINT CHR$(10)

With Graphics 5

We can easily expand our program to take care of GRAPHICS 5, a four-color mode. The same FOR-NEXT loops and LOCATE statement work. All we need to do is to select a different printer character for each color, and add some more IF-THEN statements to make the printer character correspond to the color at each location. One setup for three characters plus the blank is shown in Program 3. You can change the printed characters to suit yourself.

This program uses high line numbers, starting at 31000, so it can be merged with a program already in RAM without line number interference. Line 31000 is insurance: it makes sure that the printer head starts at the left-hand margin.

It is convenient to record this program on a cassette using the LIST"C command. You can then enter it into RAM using the ENTER"C command without destroying your main program already in RAM. Adding:

line no. GOSUB 31000

to your main program will now cause your graphics display to print out. Program 3 will work for GRAPHICS 4 and GRAPHICS 5.

What if you have a 40 column printer? Use GRAPHICS 3 (40 columns by 20 rows) to set up your display. Change lines 31010 and 31020 to match the cursor scan to the graphics display:

31010 FOR Y = 0 TO 1931020 FOR X = 0 TO 39

and line 31080 to:

31080 IF X = 39 THEN LPRINT CHR$(13)

A problem can turn up if the last statement in your main program is Atari's XI0 "fill" command:

XI0 18, #6, 0, 0, "S:"

It makes the computer think that ports are open to read, not write, and it shows

ERROR-131, IOCB write only

when the printer subroutine starts. You can fix this by inserting the following line after the last X10 statement:

PLOT X, Y : DRAWTO X + 1, Y

where X,Y and X + 1, Y are any two points within your filled area so the screen display is not changed. The print routine then runs fine.

What can you do with this? Copy graphs or charts of data, or plan ahead for your 1981 Christmas cards. Try running Program 4 along with Program 3!

Line 29999 of Program 4 is not a necessary part of the printer copying routine. It merely provides a line to which the program can RETURN from line 31110, and ends the run. Without line 29999, an ERROR message will appear, but only after the printout has been completed.