Classic Computer Magazine Archive ANTIC VOL. 4, NO. 5 / SEPTEMBER 1985

Power Programming

Tic Toc Flip

Eye-popping demonstration

by Gene Levine

This short BASIC pmgram is the best demonstration of the page flipping animation technique that we've seen. It will run on all Atari computers with 32K disk or 24K cassette.

Page flipping is a technique in which two or more screen pictures are drawn in memory and then pointed to by altering the display address of the display list. The accompanying article assumes a degree of familiarity with the concept of page flipping . For more information on this subject, refer to "Page Flipping" by David Plotkin (Antic, January 1984). -ANTIC ED

It's easier to think of page flipping as screen flipping, because you are not really flipping a page at a time. Actually you are flipping the multiple of pages needed to make a screen of the particular graphics mode you are using.

A page is a 256-byte chunk of memory. Four pages would thus be 1024 bytes or 1K. The number of pages used for a particular screen display depends on which graphic mode you choose (See the Table at the end of this article.) Tic Toc Flip uses 11 Graphics 5 + 16 screens and requires 8 pages for each screen display.

Memory Management

The more memory a graphics mode requires, the more pages it needs, and that means less screens are available to flip. More RAM means more pages available, so those users with less than 48K will be very limited in flipping applications. In fact, even with 64K, you'll find the high resolution modes of little use for this kind of animation.

Type in Listing 1, check it with TYPO II and SAVE a copy before running it.

When RUN, the program will draw a series of nested boxes. After drawing each screen in a different color, Tic Toc Flip will animate the screens into a tipsy pyramid with a "tick tock" sound.

You can speed up the animation by pressing [+], and slow it down by pressing [-]. To end the program, press [ESC] which will reset the initial values of locations 106 and 561. If these are not reset, the program will have little if any memory left to use.

Program Analysis

The DISPLAY LIST is a set of instructions the computer uses to display data to the screen. Since the display data can be stored in free areas of memory, a screen can be recalled instantly.

This is accomplished in the subroutine beginning at line 100 which subtracts multiples of 8 pages (variable TX) from RAMTOP and then sets up another Graphics 5+16 screen.

Lines 200 through 310 do the plotting and drawing, incrementing the horizontal and vertical variables with each pass, before RETURNing. A variable is made of PEEK(561) for the first and last screens so that the pages may be added or subtracted for back and forth movement.

Line 1500 sets colors 1-3 and will turn the screen on. The screen may be turned off at line 100 by POKEing 559 with a 0 instead of 34. This will speed up the drawing process somewhat.

Lines 20 to 30 are the animation loop. The FOR NEXT loops increment and deincrement PEEK(561) by dividing 88 (11 screens times the 8 pages required for a GR. 5+16 screen) by 8 and adding or subtracting that value from PEEK(561) for the back and forth movement.

Line 40 is GOSUBed with each screen call to set the desired speed. Try removing the GOSUB 40 commands from lines 20 and 25 if you want to see the real speed of flipping.

Line 2000 initializes the following variables:

DH - PEEK(561) default of 156
T - PEEK(106) default of 160
TX - the amount subtracted from T
V & VV - vertical offset variables
X & XX - horizontal offset variables
S - speed variable

The program has been structured for speed of execution. The closer to the top of a program, the faster a loop or GOSUB will execute. This is why the animation loops are at the very top. The screen draw routine is next so that it may draw as fast as possible.

Pages Per Mode Table

The following table was prepared with 32271 bytes of user memory. The results reflect the absolute maximum of screens available for flipping that I could squeeae into a bare bones program. Results will not only differ with more or less RAM but with more or less programming code.

GR. MODE       Number of Screens       Number of Pages
0                             31                        4
1                             31                        4
2                             62                        2
3                             62                        2
5                             15                        8
7                              4                       32
8 11,15                   .    3                       32
Gene Levine is the author of "Hypnosis with Brainwave Synchronization" which is marketed by XLENT software. A former artist, he is currently employed as a house painter.

Listing: TICFLIP.BAS Download