Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 9, NO. 1 / JANUARY 1983 / PAGE 224

MX-80 graphics from Pascal. R.A. Dousette.

MX-80 Graphics from Pascal

The Epson MX-80 printer comes with a limited graphics capability. It has 64 graphics characters as shown in Figure 1. Better resolution graphics are available, but the cost for the hardware approaches $100.

I would like to have the ability to do graphics, but my need doesn't justify this expenditure. Fourtunately, the graphics character set can be easily used from Apple Pascal to produce graphics that are adequate for my applications.

The Pascal graphics screen has a 192(down) by 280(across) resolution. Each MX-80 graphics character has a three (down) by two(across) resolution. Thus, if 66 lines of 80 graphics characters are printed on each page, the printed page will have a resolution of 198 by 160 dots.

In one dimension, the MX-80 will accommodate the graphics page. Going across, however, there isn't enough room to accommodate the graphics page.

The MX-80 accommodates four print sizes. They are normal size (80 characters per line), double-wide (40 characters per line), compressed (132 characters per line), and compressed doublt-wide (66 characters per line). By using these different print sizes, the page resolution can be changed. Double-width characters give a 198 X 80 display, compressed characters give a 198 $x 264 display, and double-width compressed characters give a 198 X 132 display.

Use of any of the resolutions causes some distortion of the image. The distortion is least if 80 graphics characters per line are used, in which case, the horizontal dimension is shrunk by about 10%.

Figure 1 shows the ASCII codes and the corresponding graphics characters. The graphics characters have ASCII codes 160 through 223. The appropriate code is determined by adding to 160 the appropriate power of two for each of the pixels to be printed. The example in Figure 2 shows how the ACII code of 185 is assigned to one character.

I have written a Pascal procedure named DRAW that transfers portion of the graphics screen to the printer. The procedure accepts four integer arguments, XMIN, XMAX, YMIN, and YMAX, that define a window into the graphics screen. This procedure has an internal procedure, SETCODE, that assigns the ASCII code for each block of six dots from the graphics screen by use of the Boolean function SCREENBIT.

SCREEBIT is contained in the TURTLEGRAPHICS unit. The reference SCRENBIT(I, J) looks at the graphics screen pixel with coordinates I and J and then returns a value of TRUE if the location on the screen isn't black. Otherwise it returns the value FALSE.

By examining a 2 X 3 matrix of screen pixels, it is possible to determine the ASCII code of the graphics character that reproduces the pattern on the graphics screen.

Procedure DRAW initially sets a Boolean variable GRAFERROR as FALSE. Then, it tests the coordinates of the screen window for consistency. If the coordinates aren't correct, GRAFERROR is set at TRUE and the procedure is existed.

Some editing is also done on XMIN and XMAX. For CHARSET to work correctly on the rightmost edge of the picture, XMAX-XMIN must be an odd integer. If not odd, the procedure expands the window by half a character.

The procedure assumes normal width characters. No provision for double-width characters is made. Possible changes in the procedure include adding double-width characters and rotating the image through 90 degrees before printing it.

The program Printdemo demonstrates the use of this procedure. I borrowed the butterfly from the APPLE3:GRAFDEMO program that comes with the Language System. The program prints the butterflies in both normal (Figure 3) and compressed (Figure 4) formats.

I also drew two geometric figures by rotating a square (Figure 5) and, in the last case, expanding the square (Figure 6) as it rotates.

The GRAFRANDOM procedure illustrates a random walk (Figure 7). It can be interpreted as the result of a coin toss experiment; with each successive toss of the coin, the total count of heads is divided by the number of tosses and the resulting ratio is plotted. The horizontal line through the graph is the 50% level. As the number of coin tosses increases, the ratio tends towards 50% (Figure 8).

The resulting graphics aren't as pretty as those from Graftrax-80, and they lose all shading because colors other than black are treated the same. They are, however, adequate for what I want, and they have the enormous consolition of being free.

Table: Figure 1. ASCII Codes Of Graphics Characters

Table: Figure 2. Assignment Of ASCII Codes

Table:

Photo: Figure 3.

Photo: Figure 4.

Photo: Figure 5.

Photo: Figure 6.

Photo: Figure 7.

Photo: Figure 8.