/***************************************************************************\
      PONG.C

		Run on any Z-World board
		
      Demonstration of output to the STDIO window.

\***************************************************************************/

int     px,py;                          /* Current Position     */
int     dx,dy;                          /* Current Direction    */
int     nx,ny;                          /* New Position         */

main ()
{
   cls ();                         /* Clear Screen         */
   gotoxy ( 37,2 );                /* Position Cursor      */
   inv ();                         /* Set Inverted Type    */
   printf ( "Pong" );              /* Title                */

   delay ( 5000 );                 /* Pause                */
   cls ();

   px = 1; py = 0;                 /* Position Ball        */
   dx = 1; dy = 1;                 /* Give Direction       */

   while (1) 
   {
		hitwd();
      gotoxy ( px,py );           /* Draw Ball            */
      printf ( "\x01" );

      nx = px + dx;               /* Try New Position     */
      ny = py + dy;

      if (nx < 1 || nx > 76)      /* Avoid Collision      */
         dx = -dx;
      if (ny < 0 || ny > 4)
         dy = -dy;

      nx = px + dx;               /* Next Position        */
      ny = py + dy;

      delay ( 10 );               /* Small Visual Delay   */

      gotoxy ( px,py );           /* Erase Ball           */
      printf ( " " );

      px = nx; py = ny;           /* Move Ball            */
   }
}

/* Display Item in Watch Window */

watch ()
{       
   printf ( "\x1BW(%d,%d) <%d,%d>\n",px,py,dx,dy );
}

/* Clear Screen */
cls ()
{       
   printf ( " \x1Bt" );            /* Space Opens Window   */
}

/* Set For Inverted Text */

inv ()
{       
   printf ( "\x1BG2" );
}

/* Position Cursor */

gotoxy (int x, int y)
{       
   x += 0x20;
   y += 0x20;
   printf ( "\x1B=%c%c",x,y );
}

/* Delay by Busy Waiting */

delay (int time)
{   
   int     i;

   while (time--){
		hitwd();
      for (i=0;i<0x10;i++);
   }
}