home *** CD-ROM | disk | FTP | other *** search
/ World of Graphics / WOGRAPH.BIN / 587.ICONLOAD.C < prev    next >
C/C++ Source or Header  |  1992-05-24  |  6KB  |  145 lines

  1. /*┌────────────────────────────────────────┐
  2.   │ ICONLOAD - Example of loading an icon  │
  3.   │ to a VGA display.                      │
  4.   │                                        │
  5.   │ Copyright (C) 1992 by Rimrock Software │
  6.   │ All rights reserved.                   │
  7.   │                                        │
  8.   │ Compiled with Borland C++, version 3.0 │
  9.   │                                        │
  10.   │ NOTE: no attempt is made to determine  │
  11.   │ display adapter type.  Do not attempt  │
  12.   │ to run this program unless you have an │
  13.   │ VGA display.                           │
  14.   └────────────────────────────────────────┘*/
  15. #include <stdio.h>
  16. #include <conio.h>
  17. #include <dos.h>
  18. #include <string.h>
  19.  
  20. #define LINES *((unsigned char far *) 0x00000485)
  21.  
  22.         /* LINES is a pointer to a BIOS RAM variable that contains  */
  23.         /* the current number of bytes it takes to make up a dis-   */
  24.         /* play character.  We use this value to adjust the icon    */
  25.         /* size as it is read in, so the icon is correctly displayed*/
  26.         /* no matter what display font is being used.               */
  27.  
  28. /*┌──────────────────────────────────────┐
  29.   │ Load an icon into the display adapter│
  30.   └──────────────────────────────────────┘*/
  31. void load_icon(unsigned char *chr, unsigned char_num)
  32. {
  33.    struct REGPACK r;
  34.    int i;
  35.  
  36.    r.r_es = FP_SEG(chr);
  37.    r.r_bp = FP_OFF(chr);        /* character address in ES:BP            */
  38.    r.r_bx = LINES << 8;         /* bytes per char in BH, 0 in BL         */
  39.    r.r_cx = 8;                  /* number of chars to load               */
  40.    r.r_dx = char_num;           /* which char will be loaded (0-255)     */
  41.    r.r_ax = 0x1100;             /* function 11h, subfunction 00h         */
  42.    intr(0x10,&r);               /* go load the character                 */
  43. }
  44.  
  45. /*┌──────────────────────────────────────┐
  46.   │ Display an icon generated with the   │
  47.   │  Rimrock Icon Editor                 │
  48.   └──────────────────────────────────────┘*/
  49. void main(int argc, char *argv[])
  50. {
  51.    FILE *fptr;                          /* file pointer   */
  52.    unsigned char icon_array[256];       /* icon storage   */
  53.    char s[81];                          /* file storage   */
  54.    int i;                               /* index variable */
  55.    int start;
  56.  
  57.    if(argc != 2)                        /* check for command line argument */
  58.    {
  59.       puts("\nSyntax:\n\n   LOADICON filename.ext\n\n");
  60.       puts("filename.ext is an icon file generated by RIE.\n\n");
  61.       exit(1);
  62.    }
  63.  
  64.    if((fptr = fopen(argv[1],"r")) == NULL) /* attempt to open the file */
  65.    {
  66.       printf("Can't open %s.\007\n",argv[1]);
  67.       exit(2);
  68.    }
  69.  
  70.    for(i=0; ; i++)                      /* gobble up junk lines */
  71.    {
  72.       fgets(s,80,fptr);
  73.       if(strstr(s,"IcnT") == NULL)      /* look for a start to the icon */
  74.       {
  75.          if(i >= 11)                    /* tried long enough. bail out */
  76.          {
  77.             printf("\n%s is not an icon file.\007\n",argv[1]);
  78.             exit(3);
  79.          }
  80.       }
  81.       else
  82.          break;                         /* found the start of the data */
  83.    }
  84.  
  85.    memset(icon_array, 0, 256);
  86.  
  87.    start = ((LINES * 8) - 64) / 4;
  88.  
  89.    fscanf(fptr,"\n");
  90.    for(i=start; i<start+8; i++)
  91.       fscanf(fptr,"0x%x,",&icon_array[i]); /* read line 1 (0-7) */
  92.    fscanf(fptr,"\n");
  93.    for( ; i<start+16; i++)
  94.       fscanf(fptr,"0x%x,",&icon_array[i]); /* read line 2 (8-15) */
  95.    fscanf(fptr,"\n");
  96.    for( ; i<start+24; i++)
  97.       fscanf(fptr,"0x%x,",&icon_array[i]); /* read line 3 (16-23) */
  98.    fscanf(fptr,"\n");
  99.    for( ; i<start+32; i++)
  100.       fscanf(fptr,"0x%x,",&icon_array[i]); /* read line 4 (24-31) */
  101.    fscanf(fptr,"\n");
  102.  
  103.    start += ((LINES * 8) / 2);
  104.  
  105.    for(i = start; i<start+8; i++)
  106.       fscanf(fptr,"0x%x,",&icon_array[i]); /* read line 5 (32-39) */
  107.    fscanf(fptr,"\n");
  108.    for( ; i<start+16; i++)
  109.       fscanf(fptr,"0x%x,",&icon_array[i]); /* read line 6 (40-47) */
  110.    fscanf(fptr,"\n");
  111.    for( ; i<start+24; i++)
  112.       fscanf(fptr,"0x%x,",&icon_array[i]); /* read line 7 (48-55) */
  113.    fscanf(fptr,"\n");
  114.    for( ; i<start+31; i++)
  115.       fscanf(fptr,"0x%x,",&icon_array[i]); /* read line 8 (56-62) */
  116.    fscanf(fptr,"0x%x",&icon_array[i]);     /* read line 8 (63) */
  117.    fclose(fptr);                        /* close the file */
  118.  
  119.         /* An icon is composed of characters from the upper 128 characters */
  120.         /* of the display set, arranged in a 2 x 4 matrix:                 */
  121.         /*       1st 5th                                                   */
  122.         /*       2nd 6th                                                   */
  123.         /*       3rd 7th                                                   */
  124.         /*       4th 8th                                                   */
  125.         /* When displaying an icon, this is exactly how you would do it.   */
  126.         /* (See SAMPLE.TXT for an example of laying out an icon in text.)  */
  127.         /* Characters 192-223 (0xc0-0xdf) of the display set are special.  */
  128.         /* In this range, the rightmost bits of each character is          */
  129.         /* duplicated as a 9th bit.  The purpose of this is to allow you   */
  130.         /* to create things with these characters and not have any breaks  */
  131.         /* in what you've created. For instance, when you draw a box, the  */
  132.         /* box will consist of continuous lines.  Since our icon consists  */
  133.         /* of characters that are meant to be continuous, characters 1     */
  134.         /* through 4  MUST be in the range of 192-223.  Characters 5       */
  135.         /* through 8  MUST NOT be in this range.  For this reason, we have */
  136.         /* chosen characters 220-223 for 1-4 and 224-227 for 5-8. This     */
  137.         /* makes them easy to load, since you can load all 8 at once.      */
  138.         /* To verify proper loading, run the EXAMPLE.BAT file              */
  139.  
  140.    load_icon(icon_array,0xdc);
  141.  
  142.    exit(0);                             /* and that's it, folks. */
  143. }
  144.  
  145.