A tutorial with four demonstration programs. For BASIC programmers who want to know about the ACTION! programming language, and for ACTION! users who want to pick up some tips. The first BASIC listing will run on any Atari computer The remaining listings are written in ACTION! and require the ACTION! cartridge. But BASIC programmers can compare these printed listings with the first listing and get some idea why the year-old ACTION! is increasingly becoming the language of choice for serious Atari programmers. NOTE. Antic Disk subscribers can run listing 4 without ACTION! We have provided a runtime binary file. Use the "L" option from DOS for the file, SPLASH.EXE.
SPLASH1 (listing 1) is a BASIC program that demonstrates artifacting in Graphics 8. It is an extension of a short program on Antic's public domain disk GRAPHICS & SOUND #1.
Type in listing 1, check it with TYPO II and SAVE a copy. When you RUN it, use your joystick to choose a point on the GR.8 screen. Pressing the trigger puts a "splash" of lines emanating from this center to all borders. The step size between lines can be changed by simply pressing [5]. The program lets you put as many splashes on the screen as you wish before clearing to start over. It's kind of fun-no violence, no winning score, just pretty.
SPLASH2 (listing 2) is the same program, but in ACTION!. If you look at both listings, it is easy to see which PROCedures correspond to which BASIC subroutines. That's because I made a point of keeping SPLASH 2 as structured as possible within the confines of BASIC.
A major advantage of ACTION! is that it is a structured, procedure oriented language. It is like many of the best languages for larger computers, such as Pascal. If nothing else, working with ACTION! will improve your programming style. But there is even more...
ACTION! was designed for use on microcomputers, so certain important abilities are built in and easily accessed. It is easier to PEEK and POKE. Relocating an ARRAY is so simple that I've redone the Operating System line plotting routine to execute twice as fast. (More about this later.)
The BASIC command POKE 710,0 in line 202 sets the background color to black on the GR.8 screen. The ACTION! equivalent is c2 = 0 at the top of Setup. This is because of the earlier declaration BYTE c2 = 710. This establishes c2 as a BYTE variable with values 0-255. More importantly, it's placed at memory location 710 (the register for color 2). Likewise, since we have BYTE key= 764, the conditional key<255 in ACTION! is the same as the BASIC PEEK(764)<255.
If that's all there were, it wouldn't seem like much. But not the least of ACTION! features is that it is a compiled language. The listing of SPLASH2 is technically just the source code. It could be written on any word processor. To run it, you must first compile it. This takes less than 2 seconds. The compiled version (object code) is full-fledged 6502 machine language; the same lightning-fast code made with assembly language. With that in mind, look at the ACTION! listing. I think it's easier to read than BASIC. And yet, it is still just about as powerful as any assembly language.
If you tried to improve this speed in BASIC, you'd be sunk. You'd have to write extensive USR routines in assembly language. In ACTION! things are different. You can easily write specialized routines to replace what's in the OS and gain speed.
The procedure BLine is an implementation of Bresenham's Algorithm-one of the fastest known. But the real workhorse is the short procedure Dot. It takes advantage of the way that ACTION! treats arrays. The declaration BYTE ARRAY row creates the CARDinal pointer row to the values of the array. Then the assignment row = adrow(y) makes this point to the beginning of the 40 bytes of the y-th row of the screen (see PROC Gr8( )). It is then fairly easy to move to the correct byte at row(xb) and alter it appropriately using mask arrays for the correct position xr.
These Dot and BLine routines are fairly easily adapted to other situations. The last program SPLASH4 (listing 4) works in the 4 colors of a GR.7 + screen. My file GR7PLUS at the top has the changes needed for these procedures. Even more speed is gained since some CARDinal variables can now be replaced by faster BYTE types. The PROCedure Gr7plus simply alters the GR.8 display list so that the graphics area becomes GR.7+.
The program SPLASH4 will let you put splashes on the screen in any of the four available colors. I've also made it easy to alter these. Simply press H L to alter the Hue and Luminence of the current color.
In ACTION!, like any other procedure oriented language, it is very easy to use part of one program in another. There is no worry about line number compatibility For example, you can use my files GR8 and GR7PLUS in any of your own programs. It is easy and rewarding to build up your own library of useful routines. If you're serious about programming your Atari, then I strongly recommend that you get into ACTION!.
(Next month's Antic will include a fast-moving ACTION! bonus game.- ANTIC ED)
Listing 2
; SPLASH 2 ; Paul Chabot ; MODULE BYTE c1=709,c2=710,bor=712,cur=752 ,key=764,trow=656,tcol=657,y,s CARD x PROC Setup() Graphics(8):c2=0:c1=14:cur=1:color=1 bor=16*Rand(16)+2:x=120:y=60:s=7 PrintE(" GR.8 S P L A S H ") PrintE("CENTER 120 , 60 STEP 7 ") PrintE(" [joystick] [S] ") RETURN PROC Splash() CARD i bor=16*Rand(16)+2 FOR i=0 TO 319 STEP s DO Plot(x,y):DrawTo(i,0) Plot(x,y):DrawTo(i,159) OD FOR i=0 TO 159 STEP s DO Plot(x,y):DrawTo(319,i) Plot(x,y):DrawTo(0,i) OD RETURN PROC IncStep() s==+1:bor=16*Rand(16)+2 IF s>16 THEN s=1 FI trow=1:tcol=25:PrintB(s):Print(" ") RETURN PROC Joystick() BYTE st trow=3:tcol=2 Print("[trigger] - SPLASH ") DO trow=1:tcol=9:st=Stick(0) PrintC(x):Print(" , "):PrintB(y):Print(" ") WHILE Stick(0)=15 DO IF Strig(0)=0 THEN RETURN FI IF key<255 THEN key=255:IncStep() FI OD st=Stick(0) IF st=7 AND x<319 THEN x==+1 ELSEIF st=11 AND x>0 THEN x==-1 ELSEIF st=13 AND y<159 THEN y==+1 ELSEIF st=14 AND y>0 THEN y==-1 FI OD RETURN PROC Main() DO key=255:Setup() DO Joystick():Splash() trow=3:tcol=2 Print("[A]-Another [C]-Clear") WHILE key=255 DO OD IF key=18 THEN EXIT FI key=255 OD OD RETURN