Page 1 of 1

z88dk: Creating flicker-free animation on the ZX80

Posted: Fri Aug 24, 2018 8:49 pm
by RobertK
Fabrizio wrote: Tue Aug 21, 2018 6:28 pm ZX80 flickerfree in C is possible in very simple games that loop over the same instructions all the time.
Thanks for your explanation, now I finally understand why DStar has smooth flicker-free animation and why I couldn't make it: in my game there are just too many other things going on inside the main game loop.

To prove that, I now made a very simple demo (it just fills the screen from right to left by plotting every pixel), and there you have it: a flicker-free animation on the ZX80.

May I encourage all z88dk developers to experiment with this technique? The ZX80 definitively needs more action games! :)

Code: Select all

/* Plotting "Animation" Test by RobertK, 2018-08-24

   Demonstrates how flicker-free animation can be achieved on the ZX80,
   provided that there is not too much other logic done inside the loop.
   In this sample, only plotting of one pixel and an in_KeyPressed() 
   check are done inside the loop.

   Compile command for the following targets (use latest nightly build, not 1.99B):
  
   === ZX81 (64×48) ===
   zcc +zx81 -startup=2 -o plotani_ZX81 -create-app plotani.c
   
   === ZX80 (64×48) ===
   zcc +zx80 -o plotani_ZX80 -create-app plotani.c
 
*/

#include <stdio.h>		// required for printf()
#include <graphics.h>	// contains plot() and point() functions

#define KEYPRESS_CODE_X 1278	// x key on both the ZX81 and ZX80

void main()
{ 
  int x,y;
  int xMax, yMax;
  int exit=0;
  
  // determine the screen dimensions for this system
  // coordinates go from 0 to this max value
  xMax=getmaxx();
  yMax=getmaxy();
  
  #if defined(__ZX80__)
	gen_tv_field_init(0);	// has to be called once for screen-refreshing on the ZX80
  #endif

  // check if the screen dimensions for this platform have been defined above
  if (xMax>0 && yMax>0)
  { 

	  while(exit<1)
	  {
		  printf("%c",12); // clear the screen  
		  printf("*** plotting (%d x %d) ***\n\n\n",xMax+1,yMax+1);
		  printf("press x to exit...");

		  for (x = xMax; x >=0 && exit<1; x--)
		   for (y = 0; y <=yMax && exit<1; y++)
		   {
			plot(x,y);
			
			// ZX80: make the screen visible (as the ZX80 only runs in FAST mode, 
			// the screen is normally only visible during fgetc_cons() calls)
			#if defined(__ZX80__)
				gen_tv_field();
			#endif
			
			if (in_KeyPressed(KEYPRESS_CODE_X)>0) exit=1;
		   }
	  }
  }
  
  printf("%c",12); // clear the screen 
  printf("done.\n");
  fgetc_cons();	// wait for keypress
}

Re: z88dk: Creating flicker-free animation on the ZX80

Posted: Sat Aug 25, 2018 6:45 pm
by Fabrizio
Indeed, but this does not make flickerfree animation impossible.
It just makes it VERY hard. After trying many times, I have given up and settled for a turn-based version of my game, which is equally fun to play. This even convinced me to make turn-based versions possible for all other systems.

Re: z88dk: Creating flicker-free animation on the ZX80

Posted: Sun Aug 26, 2018 3:31 pm
by stefano
long lasting operations (e.g. fp math operations) simply couldn't fit between two displlay refresh cycles. this would require a whole special library variant and lots of experiments :(

Re: z88dk: Creating flicker-free animation on the ZX80

Posted: Mon Aug 27, 2018 12:51 am
by Fabrizio
My game code does not do any floating point operations.
The problem is the complexity of the code (the cyclomatic complexity may also play a role).
It must be possible to implement a slow mode but I guess it would be extremely complex.

Re: z88dk: Creating flicker-free animation on the ZX80

Posted: Mon Aug 27, 2018 5:17 pm
by nihirash
Some math operation may be replaced with tables of scaled integers(for example sin or cos) - I think getting value from array isn't hard operation.