home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MSMOUSE1.ZIP / EGA.ZIP / MOVE.ZIP / FLOW.C next >
Encoding:
C/C++ Source or Header  |  1989-02-10  |  6.0 KB  |  210 lines

  1. /*------------------------------------------------------------------
  2.  *  FLOW.C
  3.  *
  4.  *  Written by Eric Fogelin
  5.  *  September 19, 1988
  6.  *
  7.  *  Demonstrates mouse functions and EGA animation using paging
  8.  *
  9.  *  C 5.1 Make File:
  10.  *
  11.  *      flow.exe: flow.c
  12.  *        cl flow.c
  13.  *
  14.  *   QuickC Program List:
  15.  *
  16.  *      FLOW.C
  17.  *
  18.  *--------------------------------------------------------------------*/
  19.  
  20. #include <bios.h>
  21. #include <dos.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <graph.h>
  25.  
  26. #define VIDEO 0x10
  27. #define MOUSE 0x33
  28. #define LBUTTON 1
  29. #define RBUTTON 2
  30.  
  31. #define MINBOXSIZE 8
  32. #define MAXBOXSIZE 48
  33.  
  34. void delay(int);
  35.  
  36. int delta = 1;
  37. int box = 16;
  38.  
  39. char far paltable[16];
  40.  
  41. main ()
  42. {
  43.     union REGS inregs, outregs;
  44.     struct SREGS segregs;
  45.     unsigned int i, x, y;
  46.     unsigned int color;
  47.  
  48.     _setvideomode( _ERESCOLOR );            /* EGA 640x350 16 color */
  49.  
  50.     /* Check that EGA Register Interface installed */
  51.     inregs.h.ah = 0xfa;                     /* Interrogate driver */
  52.     inregs.x.bx = 0;
  53.     int86x( VIDEO, &inregs, &outregs, &segregs );
  54.     if ( outregs.x.bx == 0 )
  55.         {
  56.         printf( "EGA Register Interface not installed\n" );
  57.         exit( 1 );
  58.         }
  59.  
  60.     inregs.x.ax = 0;                        /* Initialize Mouse */
  61.     int86( MOUSE, &inregs, &outregs );
  62.  
  63.     inregs.x.ax = 1;                        /* Show Mouse */
  64.     int86( MOUSE, &inregs, &outregs );
  65.  
  66.     /* Read palette write-only registers in EGA mode */
  67.     inregs.h.ah = 0xf2;
  68.     inregs.x.cx = 0x0010;
  69.     inregs.x.dx = 0x18;
  70.     segregs.es = (unsigned int)(((unsigned long)paltable >> 16) & 0xffff);
  71.     inregs.x.bx = (unsigned int)(((unsigned long)paltable) & 0xffff);
  72.     int86x( VIDEO, &inregs, &outregs, &segregs );
  73.  
  74.     /* Now that we got 'em, print 'em out */
  75.     printf( "Default Palette Set\n\n" );
  76.     for( i = 0; i < 16; i++ )
  77.         printf( "Palette reg.%x: %x\n", i, paltable[i] & 0xff );
  78.     printf( "\nClick and drag using left mouse button..." );
  79.  
  80.     /* Wait until left button on mouse is held down */
  81.     do
  82.         {
  83.         inregs.x.ax = 3;                    /* Check button status */
  84.         int86( MOUSE, &inregs, &outregs );
  85.         } while( !(outregs.x.bx & LBUTTON) );  /* Loop 'til left pressed */
  86.  
  87.     inregs.x.ax = 2;                        /* Hide Mouse */
  88.     int86( MOUSE, &inregs, &outregs );
  89.  
  90.     _clearscreen( _GCLEARSCREEN );          /* Clear display */
  91.  
  92.     inregs.x.ax = 1;                        /* Show Mouse */
  93.     int86( MOUSE, &inregs, &outregs );
  94.  
  95.     /* Initialize and get current mouse position. */
  96.     x = y = color = 0;
  97.     inregs.x.ax = 3;
  98.     int86( MOUSE, &inregs, &outregs );
  99.  
  100.     /* Draw rectangles at current mouse position while changing colors */
  101.     do
  102.         {
  103.         /* Only draw new rectangle in new color if mouse has moved */
  104.         if ( (x != outregs.x.cx) || (y != outregs.x.dx) )
  105.             {
  106.  
  107.             /* Bump up color, but only cyle from 1-14.  Do not affect
  108.                palette registers 0 (black) and 15 (intense white). */
  109.             color++;
  110.             if (color >= 15)
  111.                 color = 1;
  112.             _setcolor( color );
  113.  
  114.             /* Save current mouse position for later use */
  115.             x = outregs.x.cx;
  116.             y = outregs.x.dx;
  117.  
  118.             box += delta;
  119.             if ((box < MINBOXSIZE) || (box > MAXBOXSIZE))
  120.                delta = -delta;
  121.  
  122.             inregs.x.ax = 2;                /* Hide Mouse */
  123.             int86( MOUSE, &inregs, &outregs );
  124.  
  125.             _rectangle( _GFILLINTERIOR, x, y, x+box, y+box );
  126.  
  127.             inregs.x.ax = 1;                /* Show Mouse */
  128.             int86( MOUSE, &inregs, &outregs );
  129.             }
  130.  
  131.         inregs.x.ax = 3;                    /* Check button status */
  132.         int86( MOUSE, &inregs, &outregs );
  133.  
  134.         } while( outregs.x.bx & LBUTTON );  /* Loop 'til left released */
  135.  
  136.     /* Cycle palette registers 1-14.  Do not affect palette register
  137.        0 (black) and palette register 15 (intense white). */
  138.  
  139.     do
  140.         {
  141.  
  142.         /* Setup palette change using EGA.SYS */
  143.         inregs.h.ah = 0xf3;
  144.         inregs.x.cx = 0x0010;
  145.         inregs.x.dx = 0x18;
  146.         segregs.es = (unsigned int)(((unsigned long)paltable >> 16) & 0xffff);
  147.         inregs.x.bx = (unsigned int)(((unsigned long)paltable) & 0xffff);
  148.  
  149.         /* Make sure not in vertical retrace */
  150.         while( inp(0x3da) & 8 )
  151.             ;
  152.  
  153.         /* Wait for beginning of vertical retrace */
  154.         while( !(inp(0x3da) & 8) )
  155.             ;
  156.  
  157.         /* Now we are guaranteed to be in vertical retrace period.
  158.            Now is the time to make the palette register changes. */
  159.         int86x( VIDEO, &inregs, &outregs, &segregs );
  160.  
  161.         /* Assure EGA's ACR is pointing to AAR */
  162.         inp( 0x3da );
  163.  
  164.         /* Activate new palette */
  165.         outp( 0x3c0, 0x20 );
  166.  
  167.         /* Rotate only palette registers 1-14, leave 0 and 15 be */
  168.         for( i=15; i>1; i-- )
  169.             paltable[i] = paltable[i-1];
  170.  
  171.         paltable[1] = paltable[15];
  172.  
  173.         /* Put intense white (0x3f) back into reg. 15 */
  174.         paltable[15] = 0x3f;
  175.  
  176.         /* Delay for 1/18.2 second */
  177.         delay( 1 );
  178.  
  179.         inregs.x.ax = 3;                    /* Get mouse status */
  180.         int86( MOUSE, &inregs, &outregs );
  181.  
  182.     } while( !(outregs.x.bx & RBUTTON) );   /* Loop 'til right pressed */
  183.  
  184.     inregs.x.ax = 2;                        /* Hide Mouse cursor */
  185.     int86( MOUSE, &inregs, &outregs );
  186.  
  187.     _clearscreen( _GCLEARSCREEN );
  188.     _setvideomode( _DEFAULTMODE );
  189. }
  190.  
  191.  
  192. /* Delay for a number of clock ticks */
  193. void delay( ticks )
  194. int ticks;
  195. {
  196.     long end_tick, now_tick;
  197.     unsigned midnight_flag;
  198.  
  199.     _bios_timeofday( _TIME_GETCLOCK, &now_tick );
  200.     end_tick = now_tick + (long) ticks;
  201.  
  202.     do
  203.         {
  204.         midnight_flag = _bios_timeofday( _TIME_GETCLOCK, &now_tick );
  205.         if ( midnight_flag )
  206.             end_tick -= 1573040;
  207.         }
  208.     while ( now_tick < end_tick );
  209. }
  210.