home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / MOD15V12.ZIP / SOURCES / 1531.C next >
C/C++ Source or Header  |  1996-01-15  |  3KB  |  111 lines

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <dos.h>
  5. #include <stdlib.h>
  6.  
  7. char *destname (char *name) {
  8.   char *buf = "            " ;
  9.  
  10.   strcpy (buf, name) ;
  11.   buf[strlen(buf)-3] =  110 ;  /* change the 3 last chars into "nst" */
  12.   buf[strlen(buf)-2] =  115 ;
  13.   buf[strlen(buf)-1] =  116 ;
  14.   return buf;
  15.   }
  16.  
  17. int main (int nbparam, char *param[] ) {
  18.   FILE *src, *dest ;
  19.   unsigned char buf1 [599], buf2 [479], buf3 [32000] ;
  20.   int i=0,j=0,s ;
  21.  
  22.   printf ("\n        > SoundTracker to ProTracker (NoiseTracker) Converter, ver 1.2 <\n") ;
  23.   printf ("                         Coded by Magic Fred / TFL-TDV                  \n \n") ;
  24.   if (nbparam != 2) {
  25.     printf ("\n It converts an old 15-Samples Amiga SoundTracker module\n") ;
  26.     printf (" into a 31-Samples ProTracker/FastTracker 4-channels module.") ;
  27.     printf ("\n \n Syntax: 1531 <filename> \n \n") ;
  28.     exit (0) ;
  29.     }
  30.  
  31.   if (strcmp (destname (param [1]),param [1]) == 0) {
  32.     printf("This file's extension is already ""NST"" ! \n") ;
  33.     printf("Is this a 15-samples module ? If yes, rename it as ""*.MOD"".\n");
  34.     printf("\nMaybe the filename is just illegal. ") ;
  35.     printf("Please read info file. \n \n") ;
  36.     exit (1) ;
  37.     }
  38.  
  39.   if ((src=fopen(param[1],"rb")) == NULL) {
  40.     printf ("File '%s' not found in current directory.\n",param[1]) ;
  41.     printf ("Type 1531 without any parameter for help\n \n");
  42.     exit (1) ;
  43.     }
  44.   if ((dest=fopen(destname(param[1]),"wb")) == NULL) {
  45.     printf ("Cannot open destination file. \n \n") ;
  46.     exit (1) ;
  47.     }
  48.  
  49.  
  50.   /* Convertion : */
  51.  
  52.   /* To raise the header from 15 to 31 samples, a block of 480 zeroes
  53.     (names & parameters for 16 new samples) must be created. This is
  54.     created here, and my 'advertising' is inserted in sample names) */
  55.  
  56.   for ( i=0 ; i<480 ; i++ )
  57.     buf2 [i] = 0 ;
  58.  
  59.   memmove (buf2+180,"======================",22) ;
  60.   memmove (buf2+210,"I This Sound Tracker I",22) ;
  61.   memmove (buf2+240,"I (15samples) module I",22) ;
  62.   memmove (buf2+270,"I has been converted I",22) ;
  63.   memmove (buf2+300,"I into a Pro Tracker I",22) ;
  64.   memmove (buf2+330,"I (31samples) module I",22) ;
  65.   memmove (buf2+360,"I with  MAGIC FRED's I",22) ;
  66.   memmove (buf2+390,"I mod15v12.zip ,   a I",22) ;
  67.   memmove (buf2+420,"I TFL-TDV release... I",22) ;
  68.   memmove (buf2+450,"======================",22) ;
  69.  
  70.   /* Read module header */
  71.  
  72.   for ( i=0 ; i<600 ; i++ ) {
  73.     buf1 [i] = getc (src) ;
  74.     if (feof(src) != 0) {
  75.       printf ("Too early eof error -Is this a mod ? \n \n") ;
  76.       exit (1) ;
  77.     } }
  78.  
  79.   /* Insert 16 fake samplenames & parameters contained in buf2 */
  80.  
  81.   for ( i=0 ; i<470 ; i++ )
  82.     putc ( buf1 [i] , dest ) ;
  83.   for ( i=0 ; i<480 ; i++ )
  84.     putc ( buf2 [i] , dest ) ;
  85.   for ( i=470 ; i<600 ; i++ )
  86.     putc ( buf1 [i] , dest ) ;
  87.  
  88.   /* Add "M.K." label */
  89.  
  90.   putc (77,dest) ;
  91.   putc (46,dest) ;
  92.   putc (75,dest) ;
  93.   putc (46,dest) ;
  94.  
  95.   /* Copy rest of module */
  96.  
  97.   while (feof(src) == 0) {
  98.     buf3 [j] = getc(src) ;
  99.     j++ ;
  100.     if (j == 32000) {
  101.       for (i=0 ; i<32000 ; i++) putc (buf3 [i] , dest) ;
  102.       j = 0 ;
  103.       }
  104.     }
  105.   for (i=0 ; i<=j ; i++)
  106.     putc (buf3 [i] , dest) ;
  107.  
  108.   printf("Converted module is '%s'.\n\n",destname (param[1]) ) ;
  109.  
  110.   return 0 ;
  111. }