Classic Computer Magazine Archive COMPUTE! ISSUE 34 / MARCH 1983 / PAGE 203

PET Quickplot

Matt Ganis

This machine language subroutine, when added to any BASIC program, will perform fast, high-resolution drawing or plotting on PET/CBM's of any memory size, any version of BASIC (see Programs 2 and 3 for the variations). Program 1 checks your memory size and places itself in the correct location at the top of RAM and reports to you the SYS address to use from BASIC programs.

Program 1, the BASIC loader for "Quickplot/" can be RUN and then, to get an idea of its graphics capabilities, try Programs 4 and 5 for demonstrations. When you give a value for X and Y, that point on the PET screen is illuminated with the appropriate character from the table. This series of characters effectively creates an 80 x 40 resolution for the screen. In order to plot a point, say (20, 10), just execute SYS (address given by loader), 20, 10 and there it appears.

The program is set up to avoid any negative values. The lower left-hand corner of the screen is 0, 0 (line zero, column zero). The way the value of X and Y is given to the machine language plotting routine is the most interesting feature of Quick-plot. There is a short subroutine, three machine language JSR's long, which is contained in line 500 of Program 1. It jumps to three PET ROM routines in a row.

The first jump is to a ROM routine called "checkcom," which looks through the line in BASIC for a comma. Then we jump to "evaexp" which evaluates expressions. It can handle both numbers and variables. Finally, "fltfix" gives a numerical value expressed as an integer, anything to the right of the decimal point is dropped, and the number can be found divided between its high byte in the accumulator and low byte in the Y register.

After the program thus recovers the coordinates, it decides which of the characters (see the table) is appropriate and then figures out the screen address.

The method used here to pass values from a SYS to a machine language subroutine could easily be adapted to other machine language work. Just disassemble the three JSR's in line 500 which apply to your computer. Jot them down if you ever need to send numbers conveniently from BASIC to machine language.

The plot characters

Character Index Binary Representation
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111

Program 1: BASIC Loader

100 TP = PEEK(53) - 1
110 FOR T = 0 TO 220
120 READ A$
130 IF A$ = "*" THEN A = TP : GOTO 150
140 A = VAL(A$)
150 POKE T + TP * 256, A
160 NEXT T
170 POKE 53, TP : PRINT "{CLEAR}USE SYS" TP * 256 : NEW
180 DATA 32, 185, *, 140, 211, *, 141, 212, *, 32
190 DATA 185, *, 140, 213, *, 141, 214, *, 173, 212
200 DATA *, 208, 11, 173, 214, *, 208, 6, 32, 35
210 DATA *, 32, 60, *, 96, 24, 78, 211, *, 144
220 DATA 4, 169, 1, 208, 2, 169, 4, 141, 215, *
230 DATA 24, 78, 213, *, 144, 3, 14, 215, *, 96
240 DATA 56, 169, 24, 237, 213, *, 141, 216, *, 169
250 DATA 40, 141, 218, *, 169, 0, 141, 217, *, 32
260 DATA 133, *, 173, 219, *, 24, 109, 211, *, 144
270 DATA 3, 238, 220, *, 133, 1, 173, 220, *, 24
280 DATA 105, 128, 133, 2, 160, 0, 162, 0, 177, 1290 DATA 221, 195, *, 240, 7, 232, 224, 16, 208, 244
300 DATA 162, 0, 138, 13, 215, *, 170, 189, 195, *
310 DATA 145, 1, 96, 169, 0, 141, 219, *, 141, 220
320 DATA *, 24, 78, 216, * , 144, 25, 24, 173, 219
330 DATA *, 109, 218, *, 141, 219, *, 144, 3, 238
340 DATA 220, *, 24, 173, 220, *, 109, 217, *, 141
350 DATA 220, * , 24, 14, 218, *, 46, 217, *, 173
360 DATA 216, * , 208, 213, 96
500 DATA 32, 245, 190, 32, 152, 189, 32, 45, 201, 96
510 DATA 32, 108, 124, 225, 123, 98, 255, 254, 126, 127
520 DATA 226, 251, 97, 252, 236, 160, 0, 0, 0, 0
530 DATA 0, 0, 0, 0, 0, 0

Program 2: Use this line for Upgrade BASIC.

500 DATA 32, 248, 205, 32, 159, 204, 32, 210, 214, 96

Program 3: Use this line for Original BASIC.

500 DATA 32, 17, 206, 32, 184, 204, 32, 208, 214, 96

Program 4: Example Sine Wave

10 FOR X = 0 TO 79
20 Y% = 24 * SIN (6.28 * X / 80) + 24
30 SYS 32512, X, Y%
40 NEXT X

Program 5: Example plot of a circle centered at (40, 24) and radius 10

10 X = 40 : Y = 24 : R = 10
20 FOR T = l TO 360
30 X% = X + R * COS (T * 3.14 / 180)
40 Y% = Y + R * SIN (T * 3.14 / 180)
50 SYS 32512, X%, Y%
60 NEXT T