home *** CD-ROM | disk | FTP | other *** search
/ The New Aladdin Col 287 Atari ST / The_New_Aladdin_Col_287_Disk-A.ST / DECOMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-11-20  |  3.1 KB  |  134 lines

  1. /*********************************************************/
  2. /*         The New Aladdin  ---  Collection 287          */
  3. /*                                                       */
  4. /*              Reference Shelf by Bo Davis              */
  5. /*********************************************************/
  6.  
  7. /*********************/
  8. /*  Global Varables  */
  9. /*********************/
  10.  
  11. long *screen_memory;
  12. int  rez;
  13. int  rotate [4];
  14. int  palette [16];
  15.  
  16. /***************************/
  17. /*  Reserve Screen Memory  */
  18. /***************************/
  19.  
  20. screen_memory = (long *) ((Malloc (32256L) + 255) & 0xffffff00);
  21.  
  22. /***********************************/
  23. /*  Call to Decompression Routine  */
  24. /***********************************/
  25.  
  26. uncompress_graphic ("filename.ext", screen_memory, &rez, rotate, palette);
  27.  
  28. /***************************************************/
  29. /*  SUBROUTINE TO DECOMPRESS A TINY GRAPHICS FILE  */
  30. /***************************************************/
  31.  
  32. uncompress_graphic (pathname, graphic_storage, rez, rotation, palette_array)
  33.  
  34. char *pathname;
  35. int  graphic_storage [];
  36. char *rez;
  37. char *rotation;
  38. int  *palette_array;
  39.  
  40. {
  41.   int data_word;
  42.   int control_byte;
  43.   int count;
  44.   int control_cnt;
  45.   int data_cnt;
  46.   int *data_info;
  47.   int slx, scx, cx, dx;
  48.   int x;
  49.   int p, q;
  50.   int repeat;
  51.   int graph_file;
  52.   
  53.   short *control_info;
  54.   
  55.   control_info = (short *) Malloc (10667L);
  56.   data_info = (int *) Malloc (32000L);
  57.   
  58.   graph_file = Fopen (pathname, 0);
  59.   Fread (graph_file, 1L, rez);
  60.   if (*rez > 2) 
  61.     Fread (graph_file, 4L, rotation);
  62.   Fread (graph_file, 32L, palette_array);
  63.   Fread (graph_file, 2L, &control_cnt);
  64.   Fread (graph_file, 2L, &data_cnt);
  65.   Fread (graph_file, (long) control_cnt, control_info);
  66.   Fread (graph_file, (long) (data_cnt * 2), data_info);
  67.   Fclose (graph_file);
  68.   
  69.   slx = scx = cx = dx = 0;
  70.   
  71.   while (cx < control_cnt)
  72.   {
  73.     control_byte = (int) control_info [cx];
  74.     
  75.     if (control_byte < 0)
  76.     {
  77.       count = -control_byte;
  78.       repeat = 0;
  79.     }
  80.     else if (control_byte == 0)
  81.     {
  82.       p = control_info [++cx] * 256;
  83.       q = control_info [++cx];
  84.       if (q < 0)
  85.         q += 256;
  86.       count = p + q;
  87.       repeat = 1;
  88.     }
  89.     else if (control_byte == 1)
  90.     {
  91.       p = control_info [++cx] * 256;
  92.       q = control_info [++cx];
  93.       if (q < 0)
  94.         q += 256;
  95.       count = p + q;
  96.       repeat = 0;
  97.     }
  98.     else
  99.     {
  100.       count = control_byte;
  101.       repeat = 1;
  102.     }
  103.     if (repeat)
  104.     {
  105.       data_word = data_info [dx++];
  106.       for (x = 0; x < count; x++)
  107.       {
  108.         graphic_storage [scx] = data_word;
  109.         if ((scx += 80) > 15999)
  110.         {
  111.           scx -= 15996;
  112.           if (scx > 79)
  113.             scx -= 79;
  114.         }
  115.       }
  116.     }
  117.     else
  118.       for (x = 0; x < count; x++, dx++)
  119.       {
  120.         graphic_storage [scx] = data_info [dx];
  121.         if ((scx += 80) > 15999)
  122.         {
  123.           scx -= 15996;
  124.           if (scx > 79)
  125.             scx -= 79;
  126.         }
  127.       }
  128.     cx++;
  129.   }
  130.   
  131.   Mfree (data_info);
  132.   Mfree (control_info);
  133. }
  134.