home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / graphics / sprtools_1 / c / chmode < prev    next >
Encoding:
Text File  |  1998-04-06  |  1.9 KB  |  83 lines

  1. /************************************************************************
  2.  *                                    *
  3.  * Changes the mode number of a sprite                    *
  4.  * for use with non standard modes, doesnt affect sprite data.        *
  5.  *                                    *
  6.  * Version 1.00 (10-Sep-1993)                        *
  7.  *         1.50 (21-Jun-1994)     New sprite type,xres,yres added        *
  8.  *         1.51 (06-Apr-1998)     File opened as binary             *
  9.  *                                    *
  10.  * (C) 1993-8 DEEJ Technology PLC                    *
  11.  *                                    *
  12.  ************************************************************************/
  13.  
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include "io.h"
  18. #include "sprite.h"
  19.  
  20. int main(int argc, char** argv)
  21. {
  22.         FILE      *file;
  23.         int        mode;
  24.         spritefile sprite;
  25.  
  26.         if(argc!=3 && argc!=5)
  27.         {
  28.                 fprintf(stderr,"%s: <sprite file> "
  29.                                "{ <new mode> | <type> <xres> <yres> }\n",
  30.                                argv[0]);
  31.                 return(0);
  32.         }
  33.  
  34.     if(argc == 3)
  35.     {
  36.             mode = atoi(argv[2]);
  37.     }
  38.     else
  39.     {
  40.             int type, xres, yres;
  41.  
  42.         type = atoi(argv[2]);
  43.         xres = atoi(argv[3]);
  44.         yres = atoi(argv[4]);
  45.  
  46.         if(type<0 || type>8)
  47.         {
  48.                 fprintf(stderr, "Bad type\n");
  49.                 return(1);
  50.         }
  51.         if(xres!=90 && xres!=45)
  52.         {
  53.                 fprintf(stderr, "Bad xres\n");
  54.                 return(1);
  55.         }
  56.         if(yres!=90 && yres!=45)
  57.         {
  58.                 fprintf(stderr, "Bad yres\n");
  59.                 return(1);
  60.         }
  61.  
  62.         mode = ((unsigned)type << 27) |
  63.                (xres <<  1)           |
  64.                (yres << 14)           | 1;
  65.     }
  66.  
  67.         if((file = fopen(argv[1],"rb+"))==0)
  68.         {
  69.                 fprintf(stderr,"Could not open sprite file\n");
  70.                 return(1);
  71.         }
  72.  
  73.         read_struct(LE, (BYTE*)&sprite, spritefile_descr, file);
  74.  
  75.         sprite.mode = mode;
  76.  
  77.         rewind(file);
  78.  
  79.         write_struct(LE, (BYTE*)&sprite, spritefile_descr, file);
  80.  
  81.         fclose(file);
  82. }
  83.