home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************/
- /* The New Aladdin --- Collection 287 */
- /* */
- /* Reference Shelf by Bo Davis */
- /*********************************************************/
-
- /*********************/
- /* Global Varables */
- /*********************/
-
- long *screen_memory;
- int rez;
- int rotate [4];
- int palette [16];
-
- /***************************/
- /* Reserve Screen Memory */
- /***************************/
-
- screen_memory = (long *) ((Malloc (32256L) + 255) & 0xffffff00);
-
- /***********************************/
- /* Call to Decompression Routine */
- /***********************************/
-
- uncompress_graphic ("filename.ext", screen_memory, &rez, rotate, palette);
-
- /***************************************************/
- /* SUBROUTINE TO DECOMPRESS A TINY GRAPHICS FILE */
- /***************************************************/
-
- uncompress_graphic (pathname, graphic_storage, rez, rotation, palette_array)
-
- char *pathname;
- int graphic_storage [];
- char *rez;
- char *rotation;
- int *palette_array;
-
- {
- int data_word;
- int control_byte;
- int count;
- int control_cnt;
- int data_cnt;
- int *data_info;
- int slx, scx, cx, dx;
- int x;
- int p, q;
- int repeat;
- int graph_file;
-
- short *control_info;
-
- control_info = (short *) Malloc (10667L);
- data_info = (int *) Malloc (32000L);
-
- graph_file = Fopen (pathname, 0);
- Fread (graph_file, 1L, rez);
- if (*rez > 2)
- Fread (graph_file, 4L, rotation);
- Fread (graph_file, 32L, palette_array);
- Fread (graph_file, 2L, &control_cnt);
- Fread (graph_file, 2L, &data_cnt);
- Fread (graph_file, (long) control_cnt, control_info);
- Fread (graph_file, (long) (data_cnt * 2), data_info);
- Fclose (graph_file);
-
- slx = scx = cx = dx = 0;
-
- while (cx < control_cnt)
- {
- control_byte = (int) control_info [cx];
-
- if (control_byte < 0)
- {
- count = -control_byte;
- repeat = 0;
- }
- else if (control_byte == 0)
- {
- p = control_info [++cx] * 256;
- q = control_info [++cx];
- if (q < 0)
- q += 256;
- count = p + q;
- repeat = 1;
- }
- else if (control_byte == 1)
- {
- p = control_info [++cx] * 256;
- q = control_info [++cx];
- if (q < 0)
- q += 256;
- count = p + q;
- repeat = 0;
- }
- else
- {
- count = control_byte;
- repeat = 1;
- }
- if (repeat)
- {
- data_word = data_info [dx++];
- for (x = 0; x < count; x++)
- {
- graphic_storage [scx] = data_word;
- if ((scx += 80) > 15999)
- {
- scx -= 15996;
- if (scx > 79)
- scx -= 79;
- }
- }
- }
- else
- for (x = 0; x < count; x++, dx++)
- {
- graphic_storage [scx] = data_info [dx];
- if ((scx += 80) > 15999)
- {
- scx -= 15996;
- if (scx > 79)
- scx -= 79;
- }
- }
- cx++;
- }
-
- Mfree (data_info);
- Mfree (control_info);
- }
-