Joystick Oki Draw (Joystick Color Drawing)

Type
Graphics
Category
Nine-colour joystick paint program with Okimate 10 printer dump
Author
Denis Schaffer
Published in
Antic, January 1989 (Vol. 7, No. 9)
Year
1989
Language
Atari BASIC
Requirements
Any Atari 8-bit with a GTIA chip, Atari BASIC, joystick in port 1; disk drive to save pictures; Okimate 10 colour printer for printouts (optional)
A black GRAPHICS 10 screen with a square spiral of thick lines in purple, blue, brown, yellow, grey, green and dark grey, and a small white dot at top right showing the cursor size

About the program

Antic printed this in January 1989 as Joystick Oki Draw: "From screen to Okimate 10, in nine colors". The program's own title screen calls it Joystick Color Draw, and on the magazine disk it's COLOR.BAS. Denis Schaffer, a civil engineer, wrote it while he was studying for a master's degree at MIT. It's a simple paint program for the joystick. Its special feature was printing your pictures in colour on Okidata's inexpensive Okimate 10 printer.

There are nine colours, from red, orange and yellow to purple, white, black and grey, and two drawing modes. Mode 1 gives 80 × 48 blocks, like a GRAPHICS 5 screen. The article recommended it for small children, because it's easier to use and the printout fills the width of the page. Mode 2 uses the full 80 × 192 resolution of GRAPHICS 10, for more detailed pictures. Its printouts take up less than half the page, so if you change SIDE=0 to SIDE=1 in line 40, it prints two copies side by side, which is handy for invitations. That doesn't take any extra time or ribbon.

What you need

The program works on any memory size. GRAPHICS 10 is one of the GTIA modes, so very early 400/800 machines with the older CTIA chip can't show it properly. You need a disk drive to save and load pictures. Only the Okimate 10 works for printing.

Typing it in

It's almost all plain BASIC. The instruction screen uses inverse letters ({inv}…{/inv}: type them with the Atari or inverse key). The only tricky line is 1200. Its string "hhh{inv}*{/inv}LV{inv}d{/inv}" is a tiny machine-language routine: three PLAs, TAX, and JMP $E456, which is a jump into the operating system's CIO routine. The magazine listing carried TYPO II codes, which aren't in the disk version.

How to use it

After the instructions, type 1 or 2 for the mode, then a filename (just press RETURN for DRAWFILE). The cursor flashes in the middle of the screen. Push the joystick to draw, and hold the button down to erase. Other keys:

  • Space bar — next colour.
  • Inverse key — toggle between drawing and moving without drawing.
  • > / < — faster or slower cursor, and SHIFT gives the maximum or minimum.
  • + / – (mode 2) — taller or shorter brush, and SHIFT goes to the largest or smallest. The white mark at the top right shows the size.
  • TAB twice — clear the screen.
  • S, L and P — save, load and print.

How it works

  • Drawing. Each "pixel" is PLOT X,Y:DRAWTO X,Y+W, so a mode 1 block is four scan lines tall. The cursor moves in steps of W+1 rows and wraps round the screen edges (lines 220–270). It flashes by being erased and redrawn with a delay loop. In move-only mode, LOCATE remembers the colour under the cursor and puts it back as the cursor passes.
  • Keys. Line 280 checks location 764 (the last key pressed), and lines 630–790 decode the internal key codes, for example 33 for the space bar, 39 for the inverse key and 44 for TAB.
  • Fast saving. Instead of PUTting 7,680 bytes one at a time, lines 1120–1200 write the mode number, then fill in IOCB #4's control block directly (address 896): a "put characters" or "get characters" command, the screen address from locations 88–89 and a length of 30 pages. The machine-language stub then calls CIO, and the whole screen goes to or from disk in one operation.
  • Colour printing. Lines 380–620 build three strings for each band of the picture, one for each colour of the Okimate's ribbon (yellow, red and blue), from the colour of each pixel. Mixed colours come from printing more than one pass on the same spot.

Variations to try

Change the palette POKEs in line 360 to choose your own nine colours. If you don't have an Okimate, you could replace the print routine with a dump for a black-and-white Epson-compatible printer.

Listing

10 REM JOYSTICK COLOR DRAWING
20 REM BY DENIS SCHAFFER
30 REM (c)1988, ANTIC PUBLISHING
40 SIDE=0
45 GOTO 300
50 PLOT X,Y:IF FLAG=1 OR MODE$="1" THEN DRAWTO X,Y+W
60 RETURN
70 Y=0:GOTO 90
80 IF FLAG=-1 THEN 120
90 TRAP 70:COLOR 0:GOSUB 50:FOR D=1 TO DELAY:NEXT D:COLOR C:GOSUB 50
100 IF STRIG(0)=0 THEN COLOR 0:GOSUB 50:COLOR C
110 GOSUB 210:GOTO 80
120 IF FIRST=1 THEN FIRST=0:LOCATE X,Y,TEMP
130 DX=X:DY=Y
140 IF FLAG=1 THEN 80
150 GOSUB 210
160 IF (DX=X AND DY=Y) THEN 140
170 TX=X:TY=Y:X=DX:Y=DY
180 COLOR TEMP:GOSUB 50:X=TX:Y=TY:LOCATE X,Y,TEMP:COLOR 0:GOSUB 50
190 FOR D=1 TO DELAY:NEXT D:COLOR C:GOSUB 50
200 GOTO 80
210 S=STICK(0):POKE 77,0
220 X=X+(S=5 OR S=6 OR S=7)-(S=9 OR S=10 OR S=11)
230 Y=Y+(W+1)*((S=5 OR S=9 OR S=13)-(S=6 OR S=10 OR S=14))
240 IF X>78 THEN X=0
250 IF X<0 THEN X=78
260 IF Y+W>191 THEN Y=0
270 IF Y<0 THEN Y=191-W
280 IF PEEK(764)<>255 THEN GOSUB 630
290 RETURN
300 FLAG=1:DELAY=0:W=3:DIM Y$(474),R$(474),B$(474),DRAWFIL$(14),TEMPFIL$(12),POW(6),MODE$(1),BL$(6),PT$(6)
310 TEMPFIL$="":DRAWFIL$="D:DRAWFILE"
320 GOSUB 920
330 FOR T=0 TO 6:POW(T)=2^T:NEXT T
340 FOR T=1 TO 6:BL$(T)=CHR$(0):PT$(T)=CHR$(127):NEXT T
350 C=1:GRAPHICS 10
360 POKE 705,66:POKE 706,38:POKE 707,218:POKE 708,195:POKE 709,130:POKE 710,85:POKE 711,13:POKE 712,3
370 GOSUB 880:X=39:Y=96:COLOR C:GOTO 80
380 FOR ROW=0 TO 188 STEP 4:FOR COL=0 TO 78:LOCATE COL,ROW,K:T=COL*6+1:Y$(T)=PT$:R$(T)=PT$:B$(T)=PT$
390 IF K=1 OR K=5 OR K=6 OR K=7 THEN Y$(T)=BL$
400 IF K=3 OR K=4 OR K=5 OR K=7 THEN R$(T)=BL$
410 IF K=1 OR K=2 OR K=3 OR K=7 THEN B$(T)=BL$
420 POKE 77,0:NEXT COL
430 ? #3;CHR$(153);Y$
440 ? #3;R$
450 ? #3;B$;CHR$(155):NEXT ROW:? #3;CHR$(145)
460 TRAP 470:CLOSE #3
470 RETURN
480 TRAP 460:LPRINT "":OPEN #3,8,0,"P:":? #3;CHR$(27);CHR$(37):IF MODE$="1" THEN 380
490 COUNT=6:FOR ROW=0 TO 189 STEP 7:FOR COL=0 TO 79:L=127:R=127:B=127:T=COL*3+1
500 IF ROW=189 THEN COUNT=2:L=7:R=7:B=7
510 FOR SCAN=0 TO COUNT:POKE 77,0
520 LOCATE COL,ROW+SCAN,K
530 IF K=1 OR K=5 OR K=6 OR K=7 THEN L=L-POW(SCAN)
540 IF K=3 OR K=4 OR K=5 OR K=7 THEN R=R-POW(SCAN)
550 IF K=1 OR K=2 OR K=3 OR K=7 THEN B=B-POW(SCAN)
560 NEXT SCAN:Y$(T)=CHR$(L):R$(T)=CHR$(R):B$(T)=CHR$(B):Y$(T+1)=Y$(T):R$(T+1)=R$(T):B$(T+1)=B$(T)
570 Y$(T+2)=Y$(T):R$(T+2)=R$(T):B$(T+2)=B$(T)
580 NEXT COL
590 IF SIDE=1 THEN 612
595 ? #3;CHR$(153);Y$(1,237)
600 ? #3;R$(1,237)
610 ? #3;B$(1,237);CHR$(155):GOTO 620
612 ? #3;CHR$(153);Y$(1,237);BL$;Y$(1,237)
614 ? #3;R$(1,237);BL$;R$(1,237)
618 ? #3;B$(1,237);BL$;B$(1,237);CHR$(155)
620 NEXT ROW:? #3;CHR$(145):GOTO 460
630 PK=PEEK(764):POKE 764,255
640 IF PK=14 AND MODE$="2" THEN 800
650 IF PK=6 AND MODE$="2" THEN 820
660 IF PK=78 AND MODE$="2" THEN W=0:GOTO 880
670 IF PK=70 AND MODE$="2" THEN W=50:GOTO 880
680 IF PK=33 THEN 840
690 IF PK=44 THEN 890
700 IF PK=55 THEN DELAY=DELAY-1:GOTO 860
710 IF PK=54 THEN DELAY=DELAY+1:RETURN
720 IF PK=119 THEN DELAY=0
730 IF PK=118 THEN DELAY=50
740 IF PK=39 THEN FLAG=-FLAG:FIRST=1:RETURN
760 IF PK=62 THEN GOSUB 1120
770 IF PK=0 THEN GOSUB 1170
780 IF PK=10 THEN GOSUB 480
790 POKE 77,0:RETURN
800 W=W-1:IF W<0 THEN W=0
810 GOTO 880
820 W=W+1:IF W>50 THEN W=50
830 GOTO 880
840 C=C+1:IF C=9 THEN C=1
850 RETURN
860 IF DELAY<0 THEN DELAY=0
870 RETURN
880 COLOR 0:PLOT 79,0:DRAWTO 79,50:COLOR 7:PLOT 79,0:DRAWTO 79,W:RETURN
890 IF PEEK(764)=255 THEN 890
900 IF PEEK(764)=44 THEN POP :POKE 764,255:GOTO 350
910 POKE 764,255:RETURN
920 GRAPHICS 0:POKE 710,0:POSITION 16,0:? "JOYSTICK":POSITION 15,1:? "COLOR DRAW"
930 POSITION 14,2:? "{inv}INSTRUCTIONS{/inv}":? ""
940 ? "{inv}Spacebar{/inv} - Changes the color of cursor";
950 ? "{inv}Reverse{/inv} {inv}Video{/inv} - Draw/Non-draw. Holding    down the trigger in draw mode         causes cursor to erase"
960 ? "{inv}S{/inv} - Saves the screen to the disk"
970 ? "{inv}L{/inv} - Loads a file from the disk"
980 ? "{inv}P{/inv} - Prints a picture on a 'Okimate'"
990 ? "{inv}>{/inv} - Speeds up cursor {inv}Shift >{/inv} sets         cursor to maximum speed"
1000 ? "{inv}<{/inv} - Opposite of {inv}>{/inv}"
1010 ? "{inv}+{/inv} - In mode 2, increases size of          cursor. {inv}Shift +{/inv} sets size to max."
1020 ? "    Size is shown at upper right of       screen"
1030 ? "{inv}-{/inv} - Opposite of {inv}+{/inv}"
1040 ? "{inv}TAB{/inv} - Press twice to erase the screen  "
1050 ? "Do you want to draw using MODE {inv}1{/inv} 48x79or {inv}2{/inv} 192x79 ";:INPUT MODE$
1060 IF MODE$<>"1" AND MODE$<>"2" THEN 1050
1070 GRAPHICS 0:POKE 710,0
1080 ? "What is the name of the file you want to save or load. Default is 'DRAWFILE'":INPUT TEMPFIL$
1090 IF LEN(TEMPFIL$)=0 THEN 1110
1100 DRAWFIL$(3)=TEMPFIL$
1110 RETURN
1120 TRAP 1220:CLOSE #4:OPEN #4,8,0,DRAWFIL$:IO=896:PUT #4,VAL(MODE$):POKE IO+2,11
1130 GOTO 1190
1170 TRAP 1220:CLOSE #4:OPEN #4,4,0,DRAWFIL$:GET #4,T:MODE$=STR$(T):IO=896:POKE IO+2,7
1190 POKE IO+4,PEEK(88):POKE IO+5,PEEK(89):POKE IO+8,0:POKE IO+9,30
1200 JNK=USR(ADR("hhh{inv}*{/inv}LV{inv}d{/inv}"),64)
1220 TRAP 1230:CLOSE #4
1230 RETURN

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: COLOR.BAS.

Credits