home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / sprtools / c / chmode < prev    next >
Encoding:
Text File  |  1994-07-18  |  1.8 KB  |  82 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.  *                                    *
  9.  * (C) 1993,4 DEEJ Technology PLC                    *
  10.  *                                    *
  11.  ************************************************************************/
  12.  
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "io.h"
  17. #include "sprite.h"
  18.  
  19. int main(int argc, char** argv)
  20. {
  21.         FILE      *file;
  22.         int        mode;
  23.         spritefile sprite;
  24.  
  25.         if(argc!=3 && argc!=5)
  26.         {
  27.                 fprintf(stderr,"%s: <sprite file> "
  28.                                "{ <new mode> | <type> <xres> <yres> }\n",
  29.                                argv[0]);
  30.                 return(0);
  31.         }
  32.  
  33.     if(argc == 3)
  34.     {
  35.             mode = atoi(argv[2]);
  36.     }
  37.     else
  38.     {
  39.             int type, xres, yres;
  40.  
  41.         type = atoi(argv[2]);
  42.         xres = atoi(argv[3]);
  43.         yres = atoi(argv[4]);
  44.  
  45.         if(type<0 || type>8)
  46.         {
  47.                 fprintf(stderr, "Bad type\n");
  48.                 return(1);
  49.         }
  50.         if(xres!=90 && xres!=45)
  51.         {
  52.                 fprintf(stderr, "Bad xres\n");
  53.                 return(1);
  54.         }
  55.         if(yres!=90 && yres!=45)
  56.         {
  57.                 fprintf(stderr, "Bad yres\n");
  58.                 return(1);
  59.         }
  60.  
  61.         mode = ((unsigned)type << 27) |
  62.                (xres <<  1)           |
  63.                (yres << 14)           | 1;
  64.     }
  65.  
  66.         if((file = fopen(argv[1],"r+"))==0)
  67.         {
  68.                 fprintf(stderr,"Could not open sprite file\n");
  69.                 return(1);
  70.         }
  71.  
  72.         read_struct(LE, (BYTE*)&sprite, spritefile_descr, file);
  73.  
  74.         sprite.mode = mode;
  75.  
  76.         rewind(file);
  77.  
  78.         write_struct(LE, (BYTE*)&sprite, spritefile_descr, file);
  79.  
  80.         fclose(file);
  81. }
  82.