Authors
Publication
Pub Details
Date
Pages
BASIC Terms
The Epson printer manual for the JX-80 printer has some good programs that are adaptable to Sinclair BASIC. One of interest is a method of sending to the printer data that has been stored in arrays. The following program calculates the plot of a small circle. The calculations are for one quarter segment of a circle. This is converted into a mirror replica horizontally, and this half circle is then converted into another mirror replica, making a full circle. This is then sent to the printer in rows of 7 dots. It produces the printout in 6 passes.
The program gives a running record of the 21 rows of pixels as it reads each row and stores the results in an array. It then shows the print head rows being printed. This is done on the screen as only the circle is printed on the printer.
Some line comments will better illustrate the program. Line 5 is for my Oliger printer driver. Use whatever is required to get ASCII output correctly to your printer.
Line 7 sets the left margin for my Epson work alike printer (Panasonic KX-P1080i. Not required if you want to print without a left margin. I use this to use other parts of a page when experimenting.
Line 10 sets “N” for 21. When using 7 pins in the print head, “N” must be in increments of 7. The array is dimensioned here.
Line 30 assigns the circle formula to “D”. Circle formula? This formula calculates the distance between each pixel by taking the square root of the horizontal distance + the vertical distance. Remember the formula for the hypotenuse of a right triangle? The method used by this program is to determine each pixel position within the square encompassing the circle. Pixels that are to be black are called 1s and white are 0s.
Line 40 simply calls a pixel near 20 a “1”, otherwise it is “0”.
Line 60 is the counter and prints out a running record on the screen.
Line 70 is the printer code for my printer for line spacing. It is using 7/72 which is the CHR$ 7 part.
Lines 80, 90, and 100 change the order in which the array is read, toggling the order in which the array is read. First it is read upside down when Z=1, then right side up when Z=2.
Lines 110-160 are as follows. Line 110 loads the array rows from beginning “B” to end “E” in sets of seven. Line 120 prints a screen record of the computer’s progress. Line 130 enters Graphic Mode and reserves “N” columns for graphics, “N” being the width of the array. Line 150 accesses the subroutine that calculates the pin patterns for each column. Line 160 closes the loop for each pass “P” of the print head.
Line 170 can be deleted as it simply cleans out the printer buffer with the Reset.
Lines 170-220 convert the ones and zeros to pin firing sequences. The firing pattern is calculated for eacy column of 7 pins. It examines the array vertically, one cell at a time. When it encounters a “1”, it adds the appropriate power of 2 to “F”. The ABS (P+6*S-R) is the difference between the current row “R” and the last row in this pass of the print head (P*S-A). and finally, line 220 sends “F” to the printer as a graphics pin pattern.
WARNING: This a slow method of producing a print out of any shape of figure.
BASIC Listing
5 LET /p=O/G: POKE 23300,60: POKE 23301,3
7 LPRINT CHR$ 27;"l";CHR$ 20
10 LET N=21: DIM A(N,N)
20 FOR R=1 TO N: FOR C=1 TO N
30 LET D=SQR (R↑2+C↑2)
40 IF INT (D+.5)=20 THEN LET A(R,C)=1
50 NEXT C
60 PRINT "T MINUS ";N-R: NEXT R
70 LPRINT CHR$ 27;"1";CHR$ 7;
80 LET B=N: LET E=7: LET S=-1
90 FOR Z=1 TO 2
100 IF Z=2 THEN LET B=1: LET E=N-6: LET S=1
110 FOR P=B TO E STEP 7*S
120 PRINT "LOADING ROWS ";P;" TO ";P+6*S
130 LPRINT CHR$ 27;"*";CHR$ 5;CHR$ (2*N);CHR$ 0;
140 FOR C=N TO 1 STEP -1: GO SUB 180: NEXT C
150 FOR C=1 TO N: GO SUB 180: NEXT C
160 LPRINT : NEXT P: NEXT Z
170 LPRINT CHR$ 27;"@"
180 LET F=0: FOR R=P TO P+6*S STEP S
190 IF A(R,C)=1 THEN LET F=F+2↑ABS (P+6*S-R)
200 NEXT R
220 LPRINT CHR$ F;: RETURN
Products
Media
Image Gallery
Source Code
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.