home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MSMOUSE1.ZIP / EGA.ZIP / PAGE.ZIP / DANCE.C
Encoding:
C/C++ Source or Header  |  1989-02-10  |  3.3 KB  |  134 lines

  1. /*------------------------------------------------------------------
  2.  *  DANCE.C
  3.  *
  4.  *  Demonstrates mouse functions and EGA animation using paging
  5.  *
  6.  *  C 5.1 Make File:
  7.  *
  8.  *      dance.exe: dance.c
  9.  *        cl dance.c
  10.  *
  11.  *   QuickC Program List:
  12.  *
  13.  *      DANCE.C
  14.  *
  15.  *--------------------------------------------------------------------*/
  16.  
  17. #include <dos.h>
  18. #include <bios.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <graph.h>
  22.  
  23. #define MOUSE 0x33
  24.  
  25. void delay(int);
  26.  
  27. main ()
  28. {
  29.         union REGS inregs, outregs;
  30.         unsigned int i, j, page, color, box;
  31.         int row, col, x, y;
  32.  
  33.         /* Set 320 x 200, 16 color graphics mode */
  34.         _setvideomode( _MRES16COLOR );
  35.  
  36.         /* Initialize Mouse */
  37.         inregs.x.ax = 0;
  38.         int86 (MOUSE, &inregs, &outregs);
  39.  
  40.         /* Draw squares on all 8 pages */
  41.         row = 100;
  42.         col = 160;
  43.         color = rand() & 0xf;
  44.         page = 0;
  45.         do
  46.             {
  47.             do
  48.                 {
  49.                 x = (rand() & 0x7) - 4;
  50.                 y = (rand() & 0x7) - 3;
  51.                 box = (rand() & 0xf) + 1;
  52.                 if ((x == 0) && (y == 0))
  53.                     y = -3;
  54.                 } while (((abs(y) * 8) <= box) || ((abs(y) * 8) <= box));
  55.  
  56.             do
  57.                 {
  58.                 if (((box+row) < 200) && ((box + col) < 320))
  59.                     {
  60.                     _setcolor( color );
  61.                     _setactivepage( page );
  62.                     _rectangle( _GFILLINTERIOR,col,row,col + box,row + box);
  63.                     }
  64.  
  65.                 page++;
  66.                 if (page > 7)
  67.                     page = 0;
  68.  
  69.                 row += y;
  70.                 col += x;
  71.  
  72.                 } while ((!(col > 319)) && (!(col < 0)) &&
  73.                          (!(row < 0)) && (!(row > 199)));
  74.  
  75.             color = rand() & 0xf;
  76.             col = (rand() & 0xff) + 32;
  77.             row = (rand() & 0x7f) + 36;
  78.  
  79.             /* Check button status */
  80.             inregs.x.ax = 3;
  81.             int86 (MOUSE, &inregs, &outregs);
  82.  
  83.             /* Loop 'til left pressed */
  84.             } while (!(outregs.x.bx & 1));
  85.  
  86.         /* Loop and display each page */
  87.         page = 0;
  88.         do
  89.             {
  90.             page++;
  91.  
  92.             if (page > 7)
  93.                 page = 0;
  94.  
  95.             _setvisualpage( page );
  96.  
  97.             /* Delay for about 1/18.2 seconds */
  98.             delay(1);
  99.  
  100.             /* Check button status */
  101.             inregs.x.ax = 3;
  102.             int86 (MOUSE, &inregs, &outregs);
  103.  
  104.             /* Loop 'til right pressed */
  105.             } while (!(outregs.x.bx & 2));
  106.  
  107.         /* Hide Mouse cursor */
  108.         inregs.x.ax = 2;
  109.         int86 (MOUSE, &inregs, &outregs);
  110.  
  111.     _clearscreen( _GCLEARSCREEN );
  112.     _setvideomode( _DEFAULTMODE );
  113. }
  114.  
  115.  
  116. /* Delay for a number of clock ticks */
  117. void delay(ticks)
  118. int ticks;
  119. {
  120.     long end_tick, now_tick;
  121.     unsigned midnight_flag;
  122.  
  123.     _bios_timeofday( _TIME_GETCLOCK, &now_tick );
  124.     end_tick = now_tick + (long) ticks;
  125.  
  126.     do
  127.         {
  128.         midnight_flag = _bios_timeofday( _TIME_GETCLOCK, &now_tick );
  129.         if (midnight_flag)
  130.             end_tick -= 1573040;
  131.         }
  132.     while ( now_tick < end_tick );
  133. }
  134.