Classic Computer Magazine Archive COMPUTE! ISSUE 40 / SEPTEMBER 1983 / PAGE 209

Easy Atari
Page Flipping

Chris Allen

Here's a short program that lets you display one screen creation while drawing another offscreen. Put them together and you've got page flipping.

Have you ever wished that you could just POKE a couple of locations and have a complicated picture appear on your Atari? This demo program will show you how to use page flipping - changing the addresses that tell the Atari where screen memory is. Page flipping will allow you to show one picture and, at the same time, draw another picture offscreen. You don't see it drawn: it just "appears" instantly.
    Page flipping allows you to draw offscreen using the normal graphics commands (PLOT, DRAWTO, etc.), or, if you use a text mode, to PRINT normally. You don't have to do any spectacular POKEing.
    The method is simple. The Atari keeps two separate two-byte registers for the address of screen memory. The first register, locations 88 and 89 (decimal), is used solely for PRINTing, PLOTting, etc.; it is not concerned with display. The second register, bytes five and six of the display list (located by PEEK(560) + PEEK(561)*256), is used only for display. Having two locations simplifies matters - changing the first register allows you to draw offscreen, while changing the display list register will "flip" your new screen into view.
    A few cautions are in order. First, page flipping uses a lot of memory. Since one GRAPHICS 7 screen uses 3200 bytes, two such pictures are impossible on an 8K machine. However, GRAPHICS 5 uses only 800 bytes, ideal for computers with limited memory. Second, be sure to clear any garbage from the area you have reserved for your new screen. Third, if you modify the display list, be aware that your new display list may not have the screen address register in the same location as a normal list. (If you can change the display list, you should be able to handle this minor problem.)
    Now that the warnings are out of the way, let's do some page flipping. First, type in this short program:

20 GOSUB 200
60 END
200 COLOR 1:FOR I=0 TO 79:PLOT I,0:D

When you run it, notice that you can see the screen being filled in. Now add these lines to enable page flipping:

5 POKE 106,PEEK(106)-4:SCREEN2=PEEK(
25 B=PEEK(560)+PEEK(561)*256
30 FOR I=1 TO 100

40 FOR J=1 TO 200:NEXT J
50 FOR J=1 TO 200:NEXT J

    The picture is drawn offscreen, where you can't see it. By switching values in the display register (B+5 is the sixth, or high byte), you can alternate or "flip" between screens. Here's a lineby-line explanation:

Line 5 reserves memory for the second screen and sets up a pointer to the reserved area.
Line 15 sets a pointer to the present screen, then flips the draw register over to screen two.
Line 25 finds the start of the display list.
Lines 30-55 simply loop 100 times, alternating the screen displayed each time.

    Although we changed only the high byte, the low byte (88 or B+4) can also be changed. (Try changing just B + 4 - and you're screen scrolling.)