home *** CD-ROM | disk | FTP | other *** search
/ MS DOS Archives 1 / MS-DOS_Archives_Volume_One_Walnut_Creek.iso / msdos / graphics / disppix.arc / disppix.c next >
Text File  |  1989-06-05  |  4KB  |  131 lines

  1. /* DISPPIX by Jonathan Joshua    06-04-1989
  2.  
  3.     This program will display a Degas .PI{1,2,3} file on
  4.     a properly equipped IBM-PC.
  5.  
  6.     Written in MS QuickC 2.0.
  7.  
  8.     Thanks to mmcabe@mtus5 and dal@syntel.
  9.  
  10. */
  11.  
  12.  
  13. /* WARNING: Compile without DEBUG option.  Strange results if
  14.         compiled with DEBUG.  I don't know why!
  15. */
  16.  
  17.  
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <graph.h>
  22.  
  23.  
  24. main(int argc, char **argv)
  25. {
  26.     unsigned int mode, i, i2, c, x = 0, y = 0;
  27.     unsigned int t1, t2, t3, t4;
  28.     unsigned int word1, word2, word3, word4;
  29.     unsigned long colormap[16];
  30.     unsigned int mask[16];
  31.     FILE *pixfil;
  32.     short resinf[3] = {_MRES16COLOR, _HRES16COLOR, _VRES2COLOR};
  33.  
  34.     if (argc < 2)      /* Need more input */
  35.     {
  36.              printf("Usage is: DISPPIX filename.PI{1,2,3}.\n");
  37.              exit(-1);
  38.     }
  39.  
  40.     if ((pixfil = fopen(argv[1], "rb")) == NULL)   /* File open? */
  41.     {
  42.              printf("File not found!\n");
  43.              exit(-1);
  44.     }
  45.  
  46.     fgetc(pixfil);                                  /* First byte is garbage */
  47.     mode = fgetc(pixfil);                           /* Get the resolution */
  48.     if (_setvideomode(resinf[mode]) == 0)           /* Enough res? */
  49.     {
  50.          printf("Sorry, resolution required not available.\n");
  51.          exit(-1);
  52.     }
  53.  
  54.     mask[0] = 32768;            /* We don't want to compute this stuff later */
  55.     for(i=1;i<16;++i)
  56.          mask[i] = (unsigned)(int) mask[i-1]/2;
  57.  
  58.     for(i=0;i<16;++i)          /* Read palette info and convert to EGA/VGA */
  59.     {
  60.          colormap[i] = (fgetc(pixfil)*0x09);
  61.          colormap[i] += (((c=fgetc(pixfil)) & 0xf0)*0x90);
  62.          colormap[i] += ((c & 0x0f)*0x90000);
  63.     }
  64.  
  65.     _remapallpalette(colormap);      /* If you are colorblind leave this out */
  66.  
  67.     switch(mode)                     /* 3 cases instead of 1 nasty one */
  68.     {
  69.        case 2: for(i=0;i<16000;++i) /* 6440x400x2 */
  70.                {
  71.                   word1=(fgetc(pixfil)<<8)+fgetc(pixfil); /* What's the word */
  72.                   for(i2=0;i2<16;++i2)
  73.                     {
  74.                        if ((word1 & mask[i2]) != 0)         /* Simple bitmap */
  75.                            _setcolor(1);
  76.                        else
  77.                            _setcolor(0);
  78.                        _setpixel(x,y+40);
  79.                        x++;
  80.                        if ((x %= 640) == 0)
  81.                           y++;
  82.                     }
  83.                }
  84.                break;
  85.        case 1: for(i=0;i<8000;++i)  /* 640x200x4 */
  86.                {
  87.                   word1=(fgetc(pixfil)<<8)+fgetc(pixfil); /* Get 1 word */
  88.                   word2=(fgetc(pixfil)<<8)+fgetc(pixfil); /* Do it again */
  89.                   for(i2=0;i2<16;++i2)
  90.                   {
  91.                      t1 = (word1 & mask[i2])>>(15-i2);  /* Convert bitplanes */
  92.                      t2 = (word2 & mask[i2])>>(15-i2);  /* to color value    */
  93.                      _setcolor(t1 | (t2 << 1));
  94.                      _setpixel(x,y);
  95.                      ++x;
  96.                      if ((x %= 640) == 0)
  97.                         y++;
  98.                   }
  99.                }
  100.                break;
  101.  
  102.        case 0: for(i=0;i<4000;++i)  /* 320x200x16 */
  103.                {
  104.                   word1=(fgetc(pixfil)<<8)+fgetc(pixfil);
  105.                   word2=(fgetc(pixfil)<<8)+fgetc(pixfil);
  106.                   word3=(fgetc(pixfil)<<8)+fgetc(pixfil);
  107.                   word4=(fgetc(pixfil)<<8)+fgetc(pixfil);
  108.                   for(i2=0;i2<16;++i2)
  109.                   {
  110.                      t1 = (word1 & mask[i2])>>(15-i2); /* 4 bitplanes for */
  111.                      t2 = (word2 & mask[i2])>>(15-i2); /* this one        */
  112.                      t3 = (word3 & mask[i2])>>(15-i2);
  113.                      t4 = (word4 & mask[i2])>>(15-i2);
  114.                      _setcolor(t1 | (t2 << 1) | (t3 << 2) | (t4 << 3));
  115.                      _setpixel(x,y);
  116.                      ++x;
  117.                      if ((x %= 320) == 0)
  118.                         y++;
  119.                   }
  120.                }
  121.                break;
  122.  
  123.     }
  124.  
  125.     getchar();                    /* Hit return to end */
  126.  
  127.     _setvideomode(_DEFAULTMODE);  /* Be nice and reset things */
  128.     fclose(pixfil);
  129.  
  130.     exit(0);      /* Outta' here on good behavior */
  131. }