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

  1. /*------------------------------------------------------------------
  2.  *  EGALIB.C
  3.  *
  4.  *  Demonstrates functions F1, F2, and F3 of the EGA Register
  5.  *  Interface.  Each EGA color plane is filled with random bits.
  6.  *  Beofre quitting, the program shuffles the colors extremely
  7.  *  quickly while the left mouse button is held down.
  8.  *
  9.  *  C 5.1 Make File:
  10.  *
  11.  *      egalib.exe: egalib.c
  12.  *        cl egalib.c
  13.  *
  14.  *   QuickC Program List:
  15.  *
  16.  *      EGALIB.C   (Note: turn off pointer checking)
  17.  *
  18.  *--------------------------------------------------------------------*/
  19.  
  20. #include <dos.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <conio.h>
  24.  
  25. #define MOUSE 0x33
  26. #define VIDEO 0x10
  27.  
  28. char far paltable[16] = {0, 1, 2, 3, 4, 5, 0x14, 7, 0x38, 0x39,
  29.                          0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f};
  30.  
  31. main ()
  32. {
  33.     union REGS inregs, outregs;
  34.     struct SREGS segregs;
  35.     int i, mode, answer, limit, offset, plane;
  36.     char c;
  37.     unsigned int far *videoptr;
  38.  
  39.     printf ("Enter video mode (13, 14, 16) or 0 to end: ");
  40.     scanf ("%d", &mode);
  41.  
  42.     while ((mode == 13) || (mode == 14) || (mode == 16))
  43.         {
  44.  
  45.         /* set the video mode */
  46.         inregs.x.ax = mode;
  47.         int86 (VIDEO, &inregs, &outregs);
  48.  
  49.         /* reset the mouse */
  50.         inregs.x.ax = 0;
  51.         int86 (MOUSE, &inregs, &outregs);
  52.  
  53.         /* show the cursor */
  54.         inregs.x.ax = 1;
  55.         int86 (MOUSE, &inregs, &outregs);
  56.  
  57.         /* Write Register Range */
  58.         inregs.h.ah = 0xf3;
  59.         inregs.x.cx = 0x0010;
  60.         inregs.x.dx = 0x18;
  61.         segregs.es = (unsigned int)(((unsigned long)paltable >> 16) & 0xffff);
  62.         inregs.x.bx = (unsigned int)(((unsigned long)paltable) & 0xffff);
  63.  
  64.         /* Make sure not in vertical retrace */
  65.         while (inp(0x3da) & 8)
  66.             ;
  67.  
  68.         /* Wait for beginning of vertical retrace */
  69.         while (!(inp(0x3da) & 8))
  70.             ;
  71.  
  72.         /* Make the palette register changes */
  73.         int86x (VIDEO, &inregs, &outregs, &segregs);
  74.  
  75.         /* Write One Register */
  76.         inregs.h.ah = 0xf1;
  77.         inregs.h.bl = 0x20;
  78.         inregs.x.dx = 0x18;
  79.  
  80.         /* Make sure not in vertical retrace */
  81.         while (inp(0x3da) & 8)
  82.             ;
  83.  
  84.         /* Wait for beginning of vertical retrace */
  85.         while (!(inp(0x3da) & 8))
  86.             ;
  87.  
  88.         /* Call the EGA Register Interface */
  89.         int86x (VIDEO, &inregs, &outregs, &segregs);
  90.  
  91.         switch (mode)
  92.             {
  93.             case 13:
  94.                 limit = 3999;
  95.                 break;
  96.             case 14:
  97.                 limit = 7999;
  98.                 break;
  99.             default:
  100.                 limit = 13999;
  101.             }
  102.  
  103.         for (plane = 1; plane < 9; plane *= 2)
  104.             {
  105.  
  106.             /* Write One Register */
  107.             inregs.x.ax = 0xf100;
  108.             inregs.x.bx = plane * 256 + 2;
  109.             inregs.x.dx = 8;
  110.             int86 (VIDEO, &inregs, &outregs);
  111.  
  112.             /* hide mouse cursor */
  113.             inregs.x.ax = 2;
  114.             int86 (MOUSE, &inregs, &outregs);
  115.  
  116.             for (videoptr = (unsigned int far *)0xa0000000;
  117.                  videoptr <= (unsigned int far *)0xa0000000 + limit;
  118.                  videoptr++)
  119.                 *videoptr = rand() + rand();
  120.  
  121.             /* show mouse cursor */
  122.             inregs.x.ax = 1;
  123.             int86 (MOUSE, &inregs, &outregs);
  124.  
  125.             /* loop, getting the mouse status */
  126.             do
  127.                 {
  128.                 inregs.x.ax = 3;
  129.                 int86 (MOUSE, &inregs, &outregs);
  130.  
  131.                 /* until either mouse button is pressed */
  132.                 } while (!(outregs.x.bx & 3));
  133.             }
  134.  
  135.         printf ("Enter video mode (13, 14, 16) or 0 to end: ");
  136.         scanf ("%d", &mode);
  137.         }
  138.  
  139.     printf("Press and hold left button\n");
  140.     printf("Press right button to quit\n");
  141.  
  142.     do
  143.         {
  144.  
  145.         /* shuffle the color shades */
  146.         for (i=0; i<16; i++)
  147.             paltable[i] = (char)rand() & 0x7f;
  148.  
  149.         /* Write Register Range */
  150.         inregs.h.ah = 0xf3;
  151.         inregs.x.cx = 0x0010;
  152.         inregs.x.dx = 0x18;
  153.         segregs.es = (unsigned int)(((unsigned long)paltable >> 16) & 0xffff);
  154.         inregs.x.bx = (unsigned int)(((unsigned long)paltable) & 0xffff);
  155.  
  156.         /* Make sure not in vertical retrace */
  157.         while (inp(0x3da) & 8)
  158.             ;
  159.  
  160.         /* Wait for beginning of vertical retrace */
  161.         while (!(inp(0x3da) & 8))
  162.             ;
  163.  
  164.         /* Make the palette register changes */
  165.         int86x (VIDEO, &inregs, &outregs, &segregs);
  166.  
  167.         /* Write One Register */
  168.         inregs.h.ah = 0xf1;
  169.         inregs.h.bl = 0x20;
  170.         inregs.x.dx = 0x18;
  171.  
  172.         /* Make sure not in vertical retrace */
  173.         while (inp(0x3da) & 8)
  174.             ;
  175.  
  176.         /* Wait for beginning of vertical retrace */
  177.         while (!(inp(0x3da) & 8))
  178.             ;
  179.  
  180.         /* Call the EGA Register Interface */
  181.         int86x (VIDEO, &inregs, &outregs, &segregs);
  182.  
  183.         do
  184.             {
  185.  
  186.             /* get mouse status */
  187.             inregs.x.ax = 3;
  188.             int86 (MOUSE, &inregs, &outregs);
  189.  
  190.             /* loop until either button is pressed */
  191.             } while (!(outregs.x.bx & 3));
  192.  
  193.     /* quit if right button was pressed */
  194.     } while (!(outregs.x.bx & 2));
  195.  
  196.     /* Read Register Range */
  197.     inregs.h.ah = 0xf2;
  198.     inregs.x.cx = 0x0010;
  199.     inregs.x.dx = 0x18;
  200.     segregs.es = (unsigned int)(((unsigned long)paltable >> 16) & 0xffff);
  201.     inregs.x.bx = (unsigned int)(((unsigned long)paltable) & 0xffff);
  202.     int86x (VIDEO, &inregs, &outregs, &segregs);
  203.  
  204.     /* hide the mouse cursor */
  205.     inregs.x.ax = 2;
  206.     int86 (VIDEO, &inregs, &outregs);
  207.  
  208.     /* printout the palette colors */
  209.     for (i = 0; i < 16; i++)
  210.         printf ("Palette reg.%x: %x\n", i, paltable[i] & 0xff);
  211. }
  212.