Jump to content
IGNORED

Page flipping example


Recommended Posts

Posted (edited)

Hi team

 

The following is based on this Page Flipping tutorial found here:

https://www.atarimagazines.com/v2n10/Pageflipping.html

 

I made my own example of Page Flipping. It shows numbers 1 through 4 rotating on a square pattern.

Check out the attached listing and disk image if you want to see it running.

Problem is, on line 143 I am supposed to reserve memory, like this:

 

143 RT=PEEK(106)-32:POKE 106,RT
 

How much memory should I reserve? According to this webpage: 

 

https://gury.atari8.info/refs/graphics_modes.php

 

1 screen of GRAPHICS 2 takes 240 bytes of memory. Since my animation is comprised of 8 frames, I need 240*8=1920 bytes, or 7 pages. This is the value I should subtract to PEEK(106) on line 143. However, if I do this, screen is filled with garbage. I had to keep incrementing this value up to 32, which makes possible to see the animation with no problems, until frame 8, where you can still see some garbage on screen.

 

Why didn't subtracting 7 to PEEK(106) do the trick?

 

Another question: Am I forced to reserve memory for a full GRAPHICS 2 screen, even though I am only changing the first 3 lines between animation frames?

 

Please let me know.


Kind regards,

Luis.

 

PS: Here's the 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)-32:POKE 106,RT
145 GRAPHICS 2+16
149 REM DX.W 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+4:GOSUB 2000
169 REM DRAW 2ND EVEN FRAME
170 POKE 88,0:POKE 89,RT+8:I=4:GOSUB 1000
179 REM DRAW 2ND ODD FRAME
180 POKE 88,0:POKE 89,RT+12:GOSUB 2000
189 REM DRAW 3RD EVEN FRAME
190 POKE 88,0:POKE 89,RT+16:I=7:GOSUB 1000
199 REM DRAW 3RD ODD FRAME
200 POKE 88,0:POKE 89,RT+20:GOSUB 2000
209 REM DRAW 4TH EVEN FRAME
210 POKE 88,0:POKE 89,RT+24:I=10:GOSUB 1000
219 REM DRAW 4TH ODD FRAME
220 POKE 88,0:POKE 89,RT+28: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+4:GOSUB 3000
310 POKE DLIST+5,RT+8:GOSUB 3000
320 POKE DLIST+5,RT+12:GOSUB 3000
330 POKE DLIST+5,RT+16:GOSUB 3000
340 POKE DLIST+5,RT+20:GOSUB 3000
350 POKE DLIST+5,RT+24:GOSUB 3000
360 POKE DLIST+5,RT+28: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 

 

PAGEFLIP.atr

Edited by lbaeza
Grammar
Link to comment
Share on other sites

The problem is likely when crossing a 4K boundary with the display data, and also the display list can't cross a 1K boundary.

Gr. 2 uses 240 bytes for display and another 20 for display list so will use more than a page in total meaning these problems are possible.

For a Graphics 2 array you'd need to space each occurrence 2 pages apart on a boundary divisible by 2.

Your RAMTOP values then might be 160, 158, 156, 154 etc.

 

Link to comment
Share on other sites

There are some cases where certain values of 106 (RAMTOP) cause issues due to hardware alignment requirements, but this doesn't seem to be one of them. It looks like the only issue here is needing to clear the additional pages. The OS will only clear enough memory for the graphics mode, so when you change 88 (SAVMSC) to point to the rest of the reserved memory, that memory still has whatever junk was there previously. Issuing a clear to start when drawing the other pages should fix that.

 

Rows can be shared when page flipping, but you'll have to rewrite the display list pointed to by 560 (SDLSTL/SDLSTH). It requires inserting an additional LMS (load memory scan) instruction into the display list to reset the memory scan counter where you need the "split". The two bytes being changed at DLIST+4 and +5 are the address in the LMS instruction that the OS puts at the start of the display list.

 

  • Thanks 1
Link to comment
Share on other sites

Posted (edited)

Thanks for your comments!
After reading them, I added the following line:

 

146 FOR I=38912 TO 40959:POKE I,0:NEXT I
 

Frame 1 is stored at page 152 (152*256=38912) and Frame 8 is stored at page 159 (159*256=40704), ending at 40959.

And this seems to have solved the issue.

In addition to that, given that one screen of GRAPHICS 2 requires 240 bytes, 1 have "rounded" this to 256 bytes, i.e. 1 page.

So  the increment added to RT on lines from 150 to 220 is 1, and the same is done from lines 290 to 360.

Here's the updated listing that works OK:

 

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 

 

Regards,

Luis.

Edited by lbaeza
Link to comment
Share on other sites

On 5/25/2024 at 11:47 PM, lbaeza said:

Another question: Am I forced to reserve memory for a full GRAPHICS 2 screen, even though I am only changing the first 3 lines between animation frames?

You could use a modified Display list to do a LMS for the top 3 lines from different memory locations, and then another

LMS at line 4 for the rest of the screen at a fixed address , but setting this up for the display may prove quite complex.

Link to comment
Share on other sites

1 hour ago, TGB1718 said:

LMS at line 4 for the rest of the screen at a fixed address , but setting this up for the display may prove quite complex.

Not necessarily.
If you open a GR. 2 screen and do not use its first three lines, you have 60 spare bytes which can be overwritten with modified DL-bytes.

Just edit the automatically created DL using POKES. Its address can be found with PEEK(561)*256+PEEK(560).

  • Like 1
Link to comment
Share on other sites

This is a modified version that only uses 3 screens to get the same effect.

Occasionally you might see some flicker, this is due to poking the new line addresses

in BASIC, to eliminate this, you would normally update Display Lists in a VBI routine.

 

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

MYFLIP.BAS

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...