home *** CD-ROM | disk | FTP | other *** search
/ The Amiga Game Guide / AmigaGameGuide_CD.iso / PC / Tools / chunker / source / machine.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  4KB  |  195 lines

  1. /*************************************************************************
  2.  *
  3.  * Chunker/DeChunk
  4.  *
  5.  * Copyright ©1995 Lee Kindness
  6.  * cs2lk@scms.rgu.ac.uk
  7.  *
  8.  * machine.c
  9.  *  Initilisation code plus any other machine dependant code.
  10.  */
  11.  
  12. #include "machine.h"
  13.  
  14.  
  15. #ifdef BUILD_AMIGA
  16.  
  17. /*************************************************************************
  18.  * OS_sprintf() - Equivalent to sprintf(). Implemented using the exec 
  19.  *  RawDoFmt command. Note that "\x16\xC0\x4E\x75" represents MC68000
  20.  *  instructions:
  21.  *
  22.  *    move.b  d0,(a3)+
  23.  *    rts
  24.  */
  25.  
  26. void OS_sprintf(char *buffer, char *format, ...)
  27. {
  28.     RawDoFmt(format, (APTR)(&format+1), (void (*))"\x16\xC0\x4E\x75", buffer);
  29. }
  30.  
  31. #endif /* BUILD_AMIGA */
  32.  
  33.  
  34. /*************************************************************************
  35.  * InitSystem() - Called from main() to initilise and check any system
  36.  *  options or dependancies.
  37.  */
  38.  
  39. int InitSystem( void )
  40. {
  41. #ifdef BUILD_AMIGA
  42.     if( (((struct Library *)SysBase)->lib_Version >= 36) &&
  43.         (((struct Library *)DOSBase)->lib_Version >= 36) )
  44.         return( 1 );
  45.     else
  46.         return( 0 );
  47. #else
  48.     return( 1 );
  49. #endif
  50. }
  51.  
  52.  
  53. /*************************************************************************
  54.  * FreeSystem() - Called from main() to delalocate anything allocated
  55.  *  by InitSystem.
  56.  */
  57.  
  58. void FreeSystem( void )
  59. {
  60. }
  61.  
  62.  
  63. /*************************************************************************
  64.  * GetChunkerArgs() - Parse command line arguments for Chunker
  65.  */
  66.  
  67. #define ARG_CSOURCE argv[1]
  68. #define ARG_CDEST argv[2]
  69. #define ARG_CSIZE argv[3]
  70. #define NUM_CARGS 4
  71.  
  72. struct Args *GetChunkerArgs(int argc, char **argv)
  73. {
  74.     struct Args *args = NULL;
  75. #ifdef BUILD_AMIGA
  76. #define CHUNKER_TEMP "SOURCE/A,DESTBASENAME/A,SIZE/N/A"
  77. #define OPT_CSOURCE 0
  78. #define OPT_CDEST 1
  79. #define OPT_CSIZE 2
  80. #define OPT_CMAX 3
  81.     if( args = (struct Args *)OS_malloc(sizeof(struct Args)) )
  82.     {
  83.         STRPTR argsa[OPT_CMAX] = {0, 0, 0};
  84.         
  85.         if( args->arg_RAHandle = ReadArgs(CHUNKER_TEMP, (LONG *)&argsa, NULL) )
  86.         {
  87.             args->arg_Filename = argsa[OPT_CSOURCE];
  88.             args->arg_Basename = argsa[OPT_CDEST];
  89.             args->arg_Size = *((unsigned long *)argsa[OPT_CSIZE]);
  90.         } else
  91.         {
  92.             OS_free((char *)args);
  93.             args = NULL;
  94.             PrintFault(IoErr(), "Chunker");
  95.         }
  96.     }
  97. #else
  98.     if( argc == NUM_CARGS )
  99.     {
  100.         if( atol(ARG_CSIZE) )
  101.         {
  102.             if( args = (struct Args *)OS_malloc(sizeof(struct Args)) )
  103.             {
  104.                 args->arg_Filename = ARG_CSOURCE;
  105.                 args->arg_Basename = ARG_CDEST;
  106.                 args->arg_Size = atol(ARG_CSIZE);
  107.             }
  108.         } else
  109.             OS_printf("3rd argument must be an integer\n");
  110.     } else
  111.         OS_printf("Usage:\n chunker <file> <basename> <size>\n");
  112. #endif    
  113.     return( args );
  114. }
  115.  
  116.  
  117. /*************************************************************************
  118.  * FreeChunkerArgs() - Free Arguments for chunker
  119.  */
  120.  
  121. void FreeChunkerArgs(struct Args *args)
  122. {
  123.     if( args )
  124.     {
  125. #ifdef BUILD_AMIGA
  126.         if( args->arg_RAHandle )
  127.             FreeArgs(args->arg_RAHandle);
  128. #endif
  129.         OS_free((char *)args);
  130.     }    
  131. }
  132.  
  133.  
  134. /*************************************************************************
  135.  * GetDeChunkArgs() - Parse command line arguments for dechunk
  136.  */
  137.  
  138. #define ARG_DDEST argv[1]
  139. #define ARG_DSOURCE argv[2]
  140. #define NUM_DARGS 3
  141.  
  142. struct Args *GetDeChunkArgs(int argc, char **argv)
  143. {
  144.     struct Args *args = NULL;
  145. #ifdef BUILD_AMIGA
  146. #define DECHUNK_TEMP "DESTINATION/A,BASENAME/A"
  147. #define OPT_DDEST 0
  148. #define OPT_DBASE 1
  149. #define OPT_DMAX 2
  150.     if( args = (struct Args *)OS_malloc(sizeof(struct Args)) )
  151.     {
  152.         STRPTR argsa[OPT_DMAX] = {0, 0};
  153.         
  154.         if( args->arg_RAHandle = ReadArgs(DECHUNK_TEMP, (LONG *)&argsa, NULL) )
  155.         {
  156.             args->arg_Filename = argsa[OPT_DDEST];
  157.             args->arg_Basename = argsa[OPT_DBASE];
  158.         } else
  159.         {
  160.             OS_free((char *)args);
  161.             args = NULL;
  162.             PrintFault(IoErr(), "DeChunk");
  163.         }
  164.     }
  165. #else
  166.     if( argc == NUM_DARGS )
  167.     {
  168.         if( args = (struct Args *)OS_malloc(sizeof(struct Args)) )
  169.         {
  170.             args->arg_Filename = ARG_DDEST;
  171.             args->arg_Basename = ARG_DSOURCE;
  172.         }
  173.     } else
  174.         OS_printf("Usage:\n dechunk <outputfile> <basename>\n");
  175. #endif    
  176.     return( args );
  177. }
  178.  
  179.  
  180. /*************************************************************************
  181.  * FreeDeChunkArgs() - Free Arguments for chunker
  182.  */
  183.  
  184. void FreeDeChunkArgs(struct Args *args)
  185. {
  186.     if( args )
  187.     {
  188. #ifdef BUILD_AMIGA
  189.         if( args->arg_RAHandle )
  190.             FreeArgs(args->arg_RAHandle);
  191. #endif
  192.         OS_free((char *)args);
  193.     }    
  194. }
  195.