home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / ega / cega.arc / KC_PAL.C < prev    next >
Text File  |  1986-02-22  |  7KB  |  288 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*  Program:     PAL, version 1.01                                            */
  4. /*                                                                            */
  5. /*  Description: This program gives the user the ability to change the        */
  6. /*               palettes on the IBM's Enhanced Graphic Adapter.              */
  7. /*                                                                            */
  8. /*  Author:      Kent Cedola                                                  */
  9. /*               2015 Meadow Lake Court, Norfolk VA, 23518                    */
  10. /*                                                                            */
  11. /*  Language:    Microsoft's C, V3.0                                          */
  12. /*                                                                            */
  13. /*  Date Coded:  August 28, 1985.                                             */
  14. /*                                                                            */
  15. /******************************************************************************/
  16.  
  17. #include <stdio.h>
  18. #include <mcega.h>
  19.  
  20. #define UP_ARROW    (256 + 72)
  21. #define DOWN_ARROW  (256 + 80)
  22. #define LEFT_ARROW  (256 + 75)
  23. #define RIGHT_ARROW (256 + 77)
  24.  
  25. main()
  26. {
  27.  
  28.   register unsigned x,y;
  29.  
  30.   int      ch,i,x1,y1;
  31.  
  32.   unsigned pal[8][2];
  33.   char     buf[16];
  34.  
  35. /*
  36.     Initialize EGA graphic library and check for the present of an EGA.
  37. */
  38.  
  39.   gpparms();
  40.  
  41.   if (GDTYPE == 4)                      /* Give monochrome user bad news */
  42.     {
  43.     perror("Sorry, must have a Color Display not monochrome!");
  44.     exit(1);
  45.     }
  46.   else if (GDTYPE != 5)                 /* Tell non-EGA users no can run */
  47.     {
  48.     perror("Enhanced Color Adapter and Display not found!");
  49.     exit(2);
  50.     };
  51.  
  52.   if (GDMEMORY == 64)                   /* We need lots of EGA memory   */
  53.     {
  54.     printf("This program will work much better with 128k+ EGA memory!");
  55.     printf("    Hit any key to continue!");
  56.     getch();
  57.     };
  58.  
  59.   gpinit();                             /* We are now in graphic mode!  */
  60.  
  61. /*
  62.     Setup screen
  63. */
  64.  
  65.   gpcolor(CYAN);
  66.   gotoxy( 2, 1); gprintf("KC-PAL 2.00");
  67.   gotoxy(26, 1); gprintf("Set the Palettes of IBM's EGA");
  68.   gotoxy(67, 1); gprintf("KC-GRAPHICS");
  69.  
  70.   for (y = 0; y < 2; y++)
  71.     for (x = 0; x < 8; x++)
  72.       {
  73.       gpcolor(y*8+x);
  74.       gpmove(x*72+32,139-y*61);
  75.       gpbox(x*72+103,199-y*61);
  76.  
  77.       if ((pal[x][y] = gprdpal(y*8+x)) == -1)
  78.         {
  79.         pal[x][y] = y * 56 + x;
  80.         gppal(y*8+x,y*56+x);
  81.         }
  82.       gpcolor(CYAN);
  83.       gotoxy(x*9+6,15-y*11);
  84.       sprintf(buf,"C# %2d",pal[x][y]);
  85.       gprintf(buf);
  86.       };
  87.  
  88.   gpcolor(GREEN);
  89.   gpmove( 0,   0);
  90.   gprect(639,349);
  91.   gpmove( 4,   3);
  92.   gprect(635, 38);
  93.   gpmove( 4,  41);
  94.   gprect(635,346);
  95.   gpmove( 31, 77);
  96.   gprect(608,200);
  97.  
  98.   gpcolor(WHITE);
  99.  
  100.   gotoxy(18,17);
  101.   gprintf("Palette Selected XX, Color XX, RGB = (X,X,X).");
  102.  
  103.   gotoxy(10,19);
  104. gprintf("Use the arrow keys to select a palette.  Use +, -, R, G, B, or");
  105.   gotoxy(06,20);
  106. gprintf("numeric keys to change the current color. Hit the SPACE BAR to reset");
  107.   gotoxy(06,21);
  108. gprintf("the palettes to the their default values. Use the program EGASAV.COM");
  109.   gotoxy(06,22);
  110. gprintf("to retain changes while using other programs. Hit the 'ESC' key to");
  111.   gotoxy(06,23);
  112. gprintf("exit. Send comments (SASE) to 2015 Meadow Lake Ct., Norfolk VA 23518");
  113.  
  114. /*
  115.     Start the program logic here
  116. */
  117.  
  118.   x = 0;
  119.   y = 0;
  120.  
  121.   xoropt(x,y);
  122.   newcolor(x,y,pal[x][y]);
  123.  
  124.   while (1)
  125.     {
  126.     gpcolor(2);
  127.  
  128.     if ((ch = getch()) == 0)
  129.       ch = 0x100 | getch();
  130.  
  131.     switch (ch)
  132.       {
  133.       case UP_ARROW:
  134.         xoropt(x,y);
  135.         y = (y + 1) % 2;
  136.         xoropt(x,y);
  137.         break;
  138.  
  139.       case LEFT_ARROW:
  140.         xoropt(x,y);
  141.         x = --x % 8;
  142.         xoropt(x,y);
  143.         break;
  144.  
  145.       case RIGHT_ARROW:
  146.         xoropt(x,y);
  147.         x = ++x % 8;
  148.         xoropt(x,y);
  149.         break;
  150.  
  151.       case DOWN_ARROW:
  152.         xoropt(x,y);
  153.         y = (y + 1) % 2;
  154.         xoropt(x,y);
  155.         break;
  156.  
  157.       case '0':
  158.       case '1':
  159.       case '2':
  160.       case '3':
  161.       case '4':
  162.       case '5':
  163.       case '6':
  164.       case '7':
  165.       case '8':
  166.       case '9':
  167.         pal[x][y] = (pal[x][y] * 10) % 100 + (ch - '0');
  168.         if (pal[x][y] > 63)
  169.           pal[x][y] %= 10;
  170.         break;
  171.  
  172.       case 'R':
  173.       case 'r':
  174.         i = (pal[x][y] >> 4 & 2 | pal[x][y] >> 2 & 1) + 1 & 3;
  175.         pal[x][y] = (pal[x][y] & 0x1B) | ((i & 2) << 4 | (i & 1) << 2);
  176.         break;
  177.  
  178.       case 'G':
  179.       case 'g':
  180.         i = (pal[x][y] >> 3 & 2 | pal[x][y] >> 1 & 1) + 1 & 3;
  181.         pal[x][y] = (pal[x][y] & 0x2D) | ((i & 2) << 3 | (i & 1) << 1);
  182.         break;
  183.  
  184.       case 'B':
  185.       case 'b':
  186.         i = (pal[x][y] >> 2 & 2 | pal[x][y] & 1) + 1 & 3;
  187.         pal[x][y] = (pal[x][y] & 0x36) | ((i & 2) << 2 | i & 1);
  188.         break;
  189.  
  190.       case '+':
  191.         pal[x][y] = (pal[x][y] + 1) % 64;
  192.         break;
  193.  
  194.       case '-':
  195.         pal[x][y] = (pal[x][y] - 1) % 64;
  196.         break;
  197.  
  198.       case ' ':
  199.         for (y1 = 0; y1 < 2; y1++)
  200.           for (x1 = 0; x1 < 8; x1++)
  201.             {
  202.             pal[x1][y1] = y1 * 56 + x1;
  203.             if (x != x1 || y != y1)
  204.               {
  205.               gppal(y1*8+x1,y1*56+x1);
  206.               gpcolor(CYAN);
  207.               gotoxy(x1*9+9,15-y1*11);
  208.               sprintf(buf,"%2d",pal[x1][y1]);
  209.               gprintf(buf);
  210.               }
  211.             };
  212.  
  213.         break;
  214.  
  215.       case 27:
  216.         gpterm();
  217.  
  218.         for (y = 0; y < 2; y++)
  219.           for (x = 0; x < 8; x++)
  220.             gppal(y*8+x,pal[x][y]);
  221.  
  222.         exit();
  223.           break;
  224.  
  225.       default:
  226.         putch('\007');
  227.         break;
  228.       }
  229.     newcolor(x,y,pal[x][y]);
  230.     }
  231. }
  232.  
  233. xoropt(x,y)
  234.   unsigned x,y;
  235. {
  236.   int x1,y1,x2;
  237.  
  238.   x1 = x * 72 + 40;
  239.   x2 = x1 + 56;
  240.  
  241.   y1 = 210 - y * 154;
  242.  
  243.   gpcolor(GREEN);
  244.   gpmerge(3);
  245.  
  246.   gpmove(x1,y1);
  247.   gpbox(x2,y1+13);
  248.  
  249.   gpmerge(0);
  250. }
  251.  
  252. newcolor(x,y,c)
  253.   unsigned x,y,c;
  254. {
  255.   char buf[16];
  256.  
  257.   xoropt(x,y);
  258.  
  259.   gpcolor(CYAN);
  260.  
  261.   sprintf(buf,"%2d",c);
  262.   gotoxy(x*9+9,15-y*11);
  263.   gprintf(buf);
  264.   gotoxy(45,17);
  265.   gprintf(buf);
  266.  
  267.   sprintf(buf,"%2d",y*8+x);
  268.   gotoxy(35,17);
  269.   gprintf(buf);
  270.  
  271.   gotoxy(56,17);
  272.   sprintf(buf,"%d",c >> 4 & 2 | c >> 2 & 1);
  273.   gprintf(buf);
  274.  
  275.   gotoxy(58,17);
  276.   sprintf(buf,"%d",c >> 3 & 2 | c >> 1 & 1);
  277.   gprintf(buf);
  278.  
  279.   gotoxy(60,17);
  280.   sprintf(buf,"%d",c >> 2 & 2 | c & 1);
  281.   gprintf(buf);
  282.  
  283.   gppal(y*8+x,c);
  284.  
  285.   gpcolor(GREEN);
  286.   xoropt(x,y);
  287. }
  288.