Page Flipping Demo (GRAPHICS 2)
- Type
- Demo
- Category
- Animation technique — display-list page flipping
- Author
- Luis Baeza (lbaeza)
- Published in
- AtariAge forums, "Page flipping example" thread (May 2024); based on the page-flipping tutorial in Antic Vol. 2 No. 10
- Year
- 2024
- Language
- Atari BASIC
- Requirements
- Any 8-bit Atari with 48K or more and Atari BASIC (line 146 assumes RAMTOP = 160)
About the program
Page flipping means drawing several complete screens in memory ahead of time and then showing them one after another just by telling ANTIC where to look. The CPU doesn't redraw anything, so the animation is instant and flicker-free. In May 2024 Luis Baeza (posting as lbaeza on AtariAge) wrote this compact demonstration, based on the page-flipping tutorial in Antic Vol. 2 No. 10. The digits 1–4 chase each other round a little diamond in the top corner of a GRAPHICS 2 screen. His first version showed garbage on screen, and the thread explained why. The listing below is his corrected version, posted in the same thread, which runs cleanly.
Typing it in
Plain ASCII, but the spaces inside the strings in lines 130 and 140 matter. Each string is 36 characters: twelve 3-character rows, three rows per frame. Type them exactly:
- line 130:
"1 2+ 3 spaces +4 34 1+ 3 spaces +3 23 4+ 3 spaces +2 12 3+ 3 spaces +1 4" - line 140:
" 1 4 2 3+ 2 spaces +4 3 1 2+ 2 spaces +3 2 4 1+ 2 spaces +2 1 3 4 "
Line 146 clears pages 152–159 (addresses 38912–40959), which assumes the usual RAMTOP of 160 on a 48K/64K machine. On other configurations, change it to FOR I=RT*256 TO RT*256+2047.
How it works
- Reserve memory (line 143): RAMTOP (location 106) is lowered by 8 pages. BASIC and the OS then leave the top 2K alone, which is room for eight 256-byte frames.
- Clear it (line 146): the OS only clears memory for the screen it sets up. Without this line the reserved pages still hold old junk, which was the cause of the garbage in the first version.
- Draw each frame (lines 150–220): pointing SAVMSC (88/89) at a reserved page makes
PRINT #6write there instead of to the visible screen. Each frame is three rows of a GRAPHICS 2 screen. A GRAPHICS 2 screen needs 240 bytes, so one page per frame is enough. - Flip (lines 250–370): the display list starts with three blank-line instructions, then an LMS (load memory scan) instruction with a two-byte address at DLIST+4/+5. The program sets the low byte to 0 and then just changes the high byte to
RT,RT+1…RT+7with a short pause between. Every change shows a different frame immediately.
Variations to try
- Speed it up or slow it down with the
200in line 3000. - In the same thread, TGB1718 posted a variant that builds its own display list in page 6. It gives the top three rows their own LMS instruction, flips only those rows between frames, and adds a second LMS so the rest of the screen ("THIS IS FIXED") stays put. That needs far less memory. It's worth trying once this version makes sense.
- For flicker-free flipping in a game, change the LMS bytes in a vertical-blank routine instead of from BASIC.
Listing
100 REM PAGE FLIPPING DEMO
101 REM ***
104 REM INITIALIZE ANIMATION FRAMES
105 REM I$ CONTAINS ODD FRAMES, P$ EVEN FRAMES
110 DIM I$(36):I$=" ":I$(36)=" ":I$(2)=I$
120 DIM P$(36):P$=" ":P$(36)=" ":P$(2)=P$
130 I$="1 2 4 34 1 3 23 4 2 12 3 1 4"
140 P$=" 1 4 2 3 4 3 1 2 3 2 4 1 2 1 3 4 "
141 REM RESERVE FREE MEMORY FOR FRAMES
143 RT=PEEK(106)-8:POKE 106,RT
145 GRAPHICS 2+16
146 FOR I=38912 TO 40959:POKE I,0:NEXT I
149 REM DRAW 1ST EVEN FRAME
150 POKE 88,0:POKE 89,RT:I=1:GOSUB 1000
159 REM DRAW 1ST ODD FRAME
160 POKE 88,0:POKE 89,RT+1:GOSUB 2000
169 REM DRAW 2ND EVEN FRAME
170 POKE 88,0:POKE 89,RT+2:I=4:GOSUB 1000
179 REM DRAW 2ND ODD FRAME
180 POKE 88,0:POKE 89,RT+3:GOSUB 2000
189 REM DRAW 3RD EVEN FRAME
190 POKE 88,0:POKE 89,RT+4:I=7:GOSUB 1000
199 REM DRAW 3RD ODD FRAME
200 POKE 88,0:POKE 89,RT+5:GOSUB 2000
209 REM DRAW 4TH EVEN FRAME
210 POKE 88,0:POKE 89,RT+6:I=10:GOSUB 1000
219 REM DRAW 4TH ODD FRAME
220 POKE 88,0:POKE 89,RT+7:GOSUB 2000
249 REM DLIST= DISPLAY LIST ADDRESS
250 DLIST=PEEK(560)+256*PEEK(561)
258 REM ASSIGN ADDRESS OF 1ST LINE
259 REM OF DISPLAY DATA IN DLIST TO SCREEN MEMORY
260 POKE 88,PEEK(DLIST+4):POKE 89,PEEK(DLIST+5)
278 REM ASSIGN 0 TO MSB OF ADDRESS OF 1ST LINE
279 REM OF DISPLAY DATA IN DLIST
280 POKE DLIST+4,0
288 REM ASSIGN THE BEGINNING OF RESERVED MEMORY + INCREMENT TO LSB
289 REM OF ADDRESS OF 1ST LINE OF DISPLAY DATA IN DLIST
290 POKE DLIST+5,RT:GOSUB 3000
300 POKE DLIST+5,RT+1:GOSUB 3000
310 POKE DLIST+5,RT+2:GOSUB 3000
320 POKE DLIST+5,RT+3:GOSUB 3000
330 POKE DLIST+5,RT+4:GOSUB 3000
340 POKE DLIST+5,RT+5:GOSUB 3000
350 POKE DLIST+5,RT+6:GOSUB 3000
360 POKE DLIST+5,RT+7:GOSUB 3000
370 GOTO 290
999 REM PRINT ANIMATION EVEN FRAME
1000 POSITION 0,0
1010 ? #6;I$(I*3-2,I*3)
1020 ? #6;I$((I+1)*3-2,(I+1)*3)
1030 ? #6;I$((I+2)*3-2,(I+2)*3)
1050 RETURN
1999 REM PRINT ANIMATION ODD FRAME
2000 POSITION 0,0
2010 ? #6;P$(I*3-2,I*3)
2020 ? #6;P$((I+1)*3-2,(I+1)*3)
2030 ? #6;P$((I+2)*3-2,(I+2)*3)
2050 RETURN
2999 REM PAUSE LOOP
3000 FOR P=1 TO 200:NEXT P:RETURN
Credits
- Program listing: Page Flipping Demo (GRAPHICS 2) — program listing (AtariAge forums, "Page flipping example" thread (May 2024); based on the page-flipping tutorial in Antic Vol. 2 No. 10) — Luis Baeza (lbaeza)
- Picture: One of the eight frames. Each flip only changes the high byte of the display list's LMS address. — Luis Baeza (lbaeza) (program); screenshot by the site
- AtariAge forum — Page flipping example (thread 367119) — AtariAge forum members
- Antic Vol. 2 No. 10 — page flipping tutorial (linked in the thread) — Luis Baeza (lbaeza)
