home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / C128CPM / ZBRAW11.ARC / ZBCNV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-16  |  3.2 KB  |  129 lines

  1. /*
  2. Z Blaster Convert 1.1
  3.  
  4. (C) 1994 Steve Goldsmith
  5. All Rights Reserved
  6.  
  7. Z Blaster Convert 8 bit .SND file to 4 bit .RAW
  8.  
  9. Compiled with HI-TECH C 3.09 (CP/M-80).
  10.  
  11. To compile with HI-TECH C and SG C Tools source on same disk use:
  12. C ZBCNV.C -LC128
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <stat.h>
  18. #include <cpm.h>
  19. #include <hitech.h>
  20. #include <cia.h>
  21.  
  22. #define appBufSize 8192 /* size of conversion buffer */
  23.  
  24. void disphelp(void);
  25. void disptime(void);
  26. void convert(char *SndFileName, char *RawFileName);
  27.  
  28. uchar *appBufPtr;                  /* conversion buffer */
  29. FILE  *appSndFile, *appRawFile;
  30. static ciaTODRec appTODZero = {0,0,0,0};
  31. ciaTODRec appTODTime;
  32.  
  33. /*
  34. Main program parses command line, converts params and converts .SND file to
  35. .RAW file.
  36. */
  37.  
  38. main(int argc, char *argv[])
  39. {
  40.   puts("\nZ Blaster Convert 1.1 05/15/94 (C) 1994 Steve Goldsmith");
  41.   if (argc == 3)
  42.   {
  43.     appBufPtr = (uchar *) malloc(appBufSize); /* alloc converions buffer */
  44.     if (appBufPtr != NULL)
  45.     {
  46.       bdos(45,0x0FE);                /* bdos return and display error mode */
  47.       convert(argv[1],argv[2]);      /* convert raw file */
  48.       free(appBufPtr);               /* dispose buffer */
  49.     }
  50.   }
  51.   else
  52.     disphelp();
  53. }
  54.  
  55. /*
  56. Display program help.
  57. */
  58.  
  59. void disphelp(void)
  60. {
  61.   puts("\nZBCNV {U:D:}filespec {U:D:}filespec");
  62.   puts("\nZBCNV FILENAME.SND FILENAME.RAW (.SND is 8 bit and .RAW is 4 bit)");
  63. }
  64.  
  65. /*
  66. Display CIA 2 TOD clock in HH:MM:SS format.
  67. */
  68.  
  69. void disptime(void)
  70. {
  71.   ciaTODStr TODStr;
  72.  
  73.   gettodcia(cia2,appTODTime);    /* get tod time */
  74.   todstrcia(appTODTime,TODStr);  /* convert to string */
  75.   TODStr[8] = 0;                 /* drop 1/10th seconds */
  76.   printf(", %s\n",TODStr);       /* display time */
  77. }
  78.  
  79. /*
  80. Convert 8 bit raw data to 4 bit raw data.
  81. */
  82.  
  83. void convert(char *SndFileName, char *RawFileName)
  84. {
  85.   struct stat  StatRec;
  86.   ushort I, BytesRead;
  87.   ulong  CnvBytes, CnvStep, CnvNext;
  88.  
  89.   if (stat(SndFileName,&StatRec) == 0)
  90.   {
  91.     if ((appSndFile = fopen(SndFileName,"rb")) != NULL)
  92.     {
  93.       if ((appRawFile = fopen(RawFileName,"wb")) != NULL)
  94.       {
  95.         CnvBytes = 0;
  96.         CnvStep = StatRec.st_size / 10; /* progress steps */
  97.         CnvNext = CnvStep;
  98.         printf("\nConverting %s, %ld bytes, ..........,\b\b\b\b\b\b\b\b\b\b\b",
  99.         SndFileName,StatRec.st_size);
  100.         settodcia(cia2,appTODZero);
  101.         do
  102.         {
  103.           BytesRead = fread(appBufPtr,sizeof(uchar),appBufSize,appSndFile);
  104.           for (I = 0; I < BytesRead; I += 2) /* pack 2 8 bit samples into 1 byte */
  105.             appBufPtr[I >> 1] = ((appBufPtr[I] >> 4) << 4) |
  106.             (appBufPtr[I+1] >> 4);
  107.           fwrite(appBufPtr,sizeof(uchar),BytesRead >> 1,appRawFile);
  108.           CnvBytes += BytesRead;
  109.           while (CnvBytes >= CnvNext)
  110.           {
  111.             printf("*"); /* show progress */
  112.             CnvNext += CnvStep;
  113.           }
  114.         }
  115.         while (BytesRead == appBufSize);
  116.         fclose(appRawFile);
  117.         disptime();
  118.       }
  119.       else
  120.         puts("\nUnable to open output file.");
  121.       fclose(appSndFile);
  122.     }
  123.     else
  124.       puts("\nUnable to open input file.");
  125.   }
  126.   else
  127.     puts("\nUnable to open input file.");
  128. }
  129.