MYFLIP: Page Flipping Only the Top Rows

Type
Graphics
Category
Partial-screen page flipping with a custom display list
Author
TGB1718
Published in
AtariAge forums, "Page flipping example" thread (May 2024)
Year
2024
Language
Atari BASIC
Requirements
Any 8-bit Atari with Atari BASIC; page 6 free
Black GRAPHICS 2 screen: the letters D, C, A and B arranged in a diamond at top left in two colours, with THIS IS FIXED and SCREEN 3 in large letters below

About the program

In May 2024 an AtariAge member posted a GRAPHICS 2 page-flipping demo, based on Antic's page-flipping tutorial, in which four digits rotate round a square (our entry "Page Flipping Demo (GRAPHICS 2)"). Only the top three text rows changed between frames, so he asked whether he really had to reserve a whole screen for every frame. TGB1718 replied that you don't: give the display list a separate LMS (Load Memory Scan) instruction for the animated rows and another for the rest. He posted MYFLIP.BAS, which does the job with three GRAPHICS 2 screens' worth of memory instead of eight, and letters (A, b, C, d) in place of the digits.

What you need

Any Atari with Atari BASIC. The custom display list lives in page 6 (1536 onwards), so don't run it alongside anything else that uses that area.

Typing it in

  • Lines 1 and 2 must give I$ and P$ exactly 36 characters each: 12 three-character pieces of the animation, spaces included. Each frame prints three of these pieces as the top three rows.
  • The mix of upper and lower case in line 2 is deliberate. In GRAPHICS 2, case selects the colour, so the four letters show in different colours.
  • Lines 1000 and 2000 start with REM POSITION 0,0. The POSITION was commented out because the frames are printed one after another down the screen.

How it works

  1. Storing the frames (lines 4000–4100). The program opens GRAPHICS 2+16 and prints four frames down the screen. Each frame is 3 rows × 20 bytes = 60 bytes, so four fill the 240-byte screen exactly, and line 4030 records each frame's address in D(0)–D(3). It then lowers RAMTOP by two pages (512 bytes) and opens a fresh screen for frames 5–8, and does the same again for a third, final screen that holds the fixed text.
  2. A new display list (lines 5000–5030, DATA 10030–10050). Three blank-line bytes (112), then 71,lo,hi: an LMS instruction for mode 7 (GRAPHICS 2) whose address bytes sit at 1540–1541, followed by two more mode-7 rows. Then a second LMS (71) at 1545–1546 with nine more mode-7 rows, and finally 65,0,6, Jump and wait for Vertical Blank back to $0600.
  3. Pointing it at the right places. Line 66 sets the second LMS to the final screen + 60, skipping its first three rows, so "THIS IS FIXED" and the "SCREEN n" counter appear below the animation. Line 70 switches ANTIC to the new list by POKEing 560/561.
  4. Flipping. The main loop (lines 100–140) just POKEs the two address bytes of the first LMS with D(I) for I = 0…7. Nothing is redrawn, and only two bytes change per frame.

TGB1718 noted that you may sometimes see a flicker. If BASIC changes the two bytes while ANTIC is halfway through drawing, one frame mixes old and new addresses. The cure, as he said, is to update display lists in a vertical-blank routine.

Listing

1 DIM I$(36):I$=" ":I$(36)=" ":I$(2)=I$:DIM P$(36):P$=" ":P$(36)=" ":P$(2)=P$
2 I$="A b   d Cd A   C bC d   b Ab C   A d":P$=" A d b C  d C A b  C b d A  b A C d "
3 DIM D(8):GOSUB 4000
4 POSITION 0,6:? #6;"THIS IS FIXED"
5 MYDL=1536+4:MYDH=1536+5
6 DLS=1536+9:DLH=1536+10
20 GOSUB 5000
30 DL=PEEK(560)+PEEK(561)*256
66 TDS=PEEK(DL+4)+PEEK(DL+5)*256:TDS=TDS+60
67 TDH=INT(TDS/256):TDL=INT((TDS/256-TDH)*256)
68 POKE DLS,TDL:POKE DLH,TDH
70 POKE 560,0:POKE 561,6
100 FOR I=0 TO 7
110 Z=D(I):GOSUB 4200
115 POSITION 0,8:? #6;"SCREEN ";I
120 GOSUB 3000
130 NEXT I
140 GOTO 100
999 REM PRINT ANIMATION EVEN FRAME
1000 REM 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 REM 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 PRINT ALL LINES ON 2 SCREENS
3000 FOR J=0 TO 200:NEXT J:RETURN
4000 GRAPHICS 2+16:POSITION 0,0
4010 I=1:GOSUB 1000:GOSUB 2000:I=4:GOSUB 1000:GOSUB 2000
4020 FOR K=0 TO 3
4029 REM SAVE 3 LINE ADDRESSES
4030 D(K)=(PEEK(88)+PEEK(89)*256)+(K*60)
4040 NEXT K
4060 POKE 106,PEEK(106)-2:GRAPHICS 2+16
4065 I=7:GOSUB 1000:GOSUB 2000:I=10:GOSUB 1000:GOSUB 2000
4070 FOR K=0 TO 3
4079 REM SAVE 3 LINE ADDRESSES
4080 D(K+4)=(PEEK(88)+PEEK(89)*256)+(K*60)
4090 NEXT K
4091 REM FINAL SCREEN FOR NOMAL TEXT
4095 POKE 106,PEEK(106)-2:GRAPHICS 2+16
4100 RETURN
4199 REM POKE DL WITH LINE START ADDRESS
4200 DLHI=INT(Z/256):DLLO=INT(((Z/256)-DLHI)*256)
4210 POKE MYDL,DLLO:POKE MYDH,DLHI
4230 RETURN
4999 REM READ IN DISPLAY LIST
5000 RESTORE 10030:I=0
5010 READ A:IF A=-1 THEN 5030
5020 POKE 1536+I,A:I=I+1:GOTO 5010
5030 RETURN
10000 REM MY DISPLAY LIST,PAGE 6
10030 DATA 112,112,112,71,112,154,7,7,71,172
10040 DATA 154,7,7,7,7,7,7,7,7,7
10050 DATA 65,0,6,-1

Credits