Tic Toc Flip

Type
Graphics
Category
Page-flipping animation demo
Author
Gene Levine
Published in
Antic, September 1985 (Vol. 4, No. 5), Power Programming
Year
1985
Language
Atari BASIC
Requirements
32K RAM with disk (24K with cassette), Atari BASIC
Nested blue and purple rectangles in GRAPHICS 5, skewed so they close in towards the right, with a small yellow tick-tock shape near the centre

About the program

Page flipping means drawing several complete screens in memory in advance and then showing them one after another, which gives animation far faster than BASIC could ever draw it. Antic called Gene Levine's Tic Toc Flip "the best demonstration of the page flipping animation technique that we've seen". The program draws eleven full-screen GRAPHICS 5 pictures of nested boxes, each one slightly skewed and coloured, and then flips through them back and forth. The result is a pyramid that sways from side to side in time with a "tick tock" sound.

Typing it in

The listing is plain Atari BASIC with no special characters. Antic printed TYPO II checksums beside each line of the magazine listing, and they are not part of the program. Always leave with ESC, because that restores locations 106 and 561. If you press BREAK instead, BASIC is left with almost no free memory. RESET also puts things right.

How to use it

RUN it and wait while the eleven screens are drawn. Each one is visible as it is built, in a different random border colour. The animation then starts. Press + to speed it up, - to slow it down and ESC to stop.

How it works

  • Building the screens (line 100). Before each GRAPHICS 5+16, RAMTOP (location 106) is lowered by another 8 pages (2K). The OS therefore builds each new screen and its display list in a fresh 2K block below the last one.
  • One byte per flip. Every screen is built the same way, so each display list sits at the same offset within its own 8-page block. That means you can switch screens by changing only the high byte of the display-list pointer in location 561 (SDLSTL+1) by 8. Lines 20–25 step through the screens in one direction and then the other, playing a click with SOUND at each end.
  • Drawing (lines 200–310). Each screen gets twelve nested rectangles whose left and right edges shift by a growing amount, plus a small "tick-tocker" box that moves down 4 pixels on each successive screen.
  • Line 40 is the delay loop, and it also reads the keyboard through location 764. Remove the GOSUB 40 calls in lines 20 and 25 to see how fast raw page flipping really is.

Levine noted that you could also blank the screen while drawing (POKE 559,0 in line 100) to speed up setup, and that the high-resolution modes use so many pages per screen that they are of little use for this trick, even with 64K.

Listing

5 REM TIC-TOC-FLIP
6 REM BY GENE LEVINE
7 REM (c) 1985, ANTIC PUBLISHING
10 POKE 106,PEEK(740):GOTO 2000
19 REM ANIMATION LOOP
20 FOR L=0 TO 87 STEP 8:POKE 561,H1-L:GOSUB 40:NEXT L:SOUND 0,25,10,14
25 FOR L=0 TO 71 STEP 8:POKE 561,H11+8+L:GOSUB 40:NEXT L:SOUND 0,33,10,14
30 POKE 77,0:GOTO 20
39 REM SPEED SET & ESC
40 SOUND 0,0,0,0:FOR DELAY=1 TO S:IF PEEK(764)<29 THEN GOSUB 50
45 NEXT DELAY:RETURN
50 IF PEEK(764)=14 AND S<70 THEN S=S+0.3:REM '-' TO SLOW DOWN
55 IF PEEK(764)=6 AND S>0 THEN S=S-0.2:REM '+' TO SPEED UP
60 IF PEEK(764)=28 THEN 9999:REM ESC TO STOP
65 POKE 764,255:RETURN
99 REM SCREEN DRAW SETUP
100 POKE 106,T-TX:GRAPHICS 5+16:POKE 559,34:POKE 712,PEEK(53770):LFT=16:RIT=63:BOT=47:TOP=0:TX=TX+8
199 REM DRAW BOX
200 FOR L=1 TO 12:FOR K=1 TO 2:COLOR K:PLOT LFT,TOP:DRAWTO RIT,TOP:DRAWTO RIT,BOT:DRAWTO LFT,BOT:DRAWTO LFT,TOP
205 BOT=BOT-1:TOP=TOP+1:LFT=LFT+X:RIT=RIT-XX:NEXT K:NEXT L:X=X+0.32:XX=XX-0.32
299 REM DRAW TICK-TOCKER
300 COLOR 3:PLOT 38,V:DRAWTO 41,V:DRAWTO 41,VV:DRAWTO 38,VV:DRAWTO 38,V
305 PLOT 39,V-1:DRAWTO 40,V-1:PLOT 39,VV+1:DRAWTO 40,VV+1
310 V=V+4:VV=VV+4:RETURN
999 REM D.L. HIGH BYTES
1000 GOSUB 100:COLOR 1:PLOT 39,0:DRAWTO 40,0:H1=PEEK(561)
1005 FOR Q=2 TO 11:GOSUB 100:NEXT Q
1010 COLOR 1:PLOT 39,47:DRAWTO 40,47:H11=PEEK(561)
1499 REM SET COLORS & TURN ON SCREEN
1500 POKE 712,0:POKE 708,146:POKE 709,66:POKE 710,214:POKE 559,34:GOTO 20
1999 REM INITIALIZE VARIABLES
2000 DH=PEEK(561):T=PEEK(106):TX=0:V=1:VV=6:X=-0.6:XX=2+0.6:S=10:GOTO 1000
9998 REM EXIT
9999 POKE 561,DH:POKE 106,T:GRAPHICS 0:REM RESET DL HIGH BYTE & MEM TOP

Download

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

Credits