Page 2 of 2

Re: Double buffer grey scale?

Posted: Wed May 31, 2017 5:35 pm
by KayBee
Gray effect aside, I would love to see how you are double buffering for smoother animation. Please share an example.

Thank you.

KB

Re: Double buffer grey scale?

Posted: Sun Aug 20, 2017 8:58 pm
by monzamess
I would also like to see how double buffering is done on ZX81. I am just playing around with z88dk right now and not getting too far with that.

Re: Double buffer grey scale?

Posted: Sun Aug 20, 2017 9:05 pm
by Lardo Boffin
Sorry I missed the earlier question!

Conceptually it is pretty easy (in low resolution mode) - the location of the screen file is held in a system variable.

Create a second screen file with an identical structure and when you have finished building it change the system variable to point to the second screen file.

Now update the original screen file and when finished change the system variable back to the original location.

Repeat.

I have an example I can post (it is fairly rudimentary but works) but it will be a few days before I will be able to.

Re: Double buffer grey scale?

Posted: Wed Sep 06, 2017 11:31 pm
by Lardo Boffin
Sorry it took a while to get time to post this!

I have attached a few files which show a double buffering example, albeit a very simple one!

Everything required to modify or build the files is in the attachments. To build it on a Windows PC open CMD and navigate to the folder where you put the files. Type zxasm animation01 and press enter. You can then run the animation01.p in EightyOne etc.

The process is: -

Fill buffer one with black squares
Fill buffer two with black squares
Place one white dot in buffer two
Repeatedly switch between the two buffers by changing the value of D_FILE and DF_CC (these variables tell the ZX81 ROM display routine where to look for the screen data)

Buffer one is just a location in memory big enough to hold a full screen of data (although you could do less than a full screen as required)
Buffer two is a different location, again big enough to hold the full screen

Buffer one and two are defined in the file screen.asm. If you look you will basically see two complete ZX81 1K screens

The animation comes from rapidly switching between the two buffers merely by changing the value of D_FILE and DF_CC, as the example below: -

Code: Select all

   ld bc,bufferOne              ;set the current screen to buffer one
   ld (D_FILE),bc	        ;set D_File to the location of buffer one
   inc bc                       ;increment bc by 1
   ld (DF_CC),bc                ;set DF_CC to address of bugffer one plus 1
After calling this code the next time the screen is displayed it will be using the data in buffer one.

If you were to do this in a game for example you would do the following: -

1) Display a menu screen (in buffer one) and do the following when the game starts: -
2) Build buffer two while buffer one is being displayed
3) Display buffer two when it is finished
4) Check for user input
5) Build buffer one to show the next frame of animation (based on user input)
6) Display buffer one when it is finished
7) Check for user input and then jump to step 2

Any questions feel free to ask although I am no expert on this!

Lardo

Re: Double buffer grey scale?

Posted: Wed Sep 06, 2017 11:50 pm
by Lardo Boffin
This example bounces three little characters up and down by a pixel.

Re: Double buffer grey scale?

Posted: Thu Sep 07, 2017 4:06 am
by monzamess
Great! Hoping I have some time this weekend to really check it out!

Re: Double buffer grey scale?

Posted: Thu Sep 07, 2017 4:39 pm
by Moggy
In a similar vain I once did a fairly simple animation of a piston rising and falling inside a cylinder by building up two differing display files and placing them above a lowered ramtop, then LDIR'ing them back alternately which gave the effect of a single cylinder engine working at real speed.

Re: Double buffer grey scale?

Posted: Thu Sep 07, 2017 7:38 pm
by Andy Rea
excuse me for jumping in and ( kinda ) hi-jacking the thread... a while ago i wrote a little animation that used page flipping 8 pages if i remeber correctly by chaging page each frame it creates a very nice illusion of fluid movement, iirc it is much better viewed on a real CRT display due to the persistence of vision effect.

i believe the source code is in this zip here to

link to post viewtopic.php?f=6&t=609&p=5321&hilit=moreball#p5321

regards Andy

Re: Double buffer grey scale?

Posted: Thu Sep 07, 2017 9:24 pm
by Moggy
Andy Rea wrote: Thu Sep 07, 2017 7:38 pm excuse me for jumping in and ( kinda ) hi-jacking the thread... a while ago i wrote a little animation that used page flipping 8 pages if i remeber correctly by chaging page each frame it creates a very nice illusion of fluid movement, iirc it is much better viewed on a real CRT display due to the persistence of vision effect.

i believe the source code is in this zip here to

link to post viewtopic.php?f=6&t=609&p=5321&hilit=moreball#p5321

regards Andy
Hells teeth I remember this little bugger, what ever you do don't stare to long at it after half a bottle of scotch like I did. :oops: