home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / MIDNIGHT.LZH / MIDNIGHT / UTIL / CONV_SND.C next >
C/C++ Source or Header  |  1993-01-11  |  1KB  |  62 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <tos.h>
  5. #include <ext.h>
  6. #include <string.h>
  7. #include <portab.h>
  8.  
  9.  
  10. void main( int argc, char **argv )
  11. {
  12.     FILE *f1,*f2;
  13.     long fh;
  14.     long size,i;
  15.     UWORD c,pos;
  16.     UBYTE *p;
  17.  
  18.     if( argc<2 ) return;
  19.     f1= fopen( argv[1],"rb" );
  20.     f2= fopen( "CONV_SND.SH","w" );
  21.     if( !f1 || !f2 )
  22.     {    fclose( f1 );
  23.         fclose( f2 );
  24.         return;
  25.     }
  26.  
  27.     fh= fileno( f1 );
  28.     size= Fseek( 0,fh,2 );
  29.     Fseek( 0,fh,0 );
  30.     p= (UBYTE*)Malloc( size );
  31.     if( !p ) goto ex;
  32.     Fread( fh,size,p );
  33.  
  34.     fprintf( f2,"/* Daten von: %s */\n\nUWORD name[] =\n\t{",argv[1] );
  35.  
  36.     if( !(Kbshift(-1)&0x1) )
  37.         for( pos=i=0;i<size+1;i++,pos&=15 )
  38.         {    if( pos==0 ) fprintf( f2,"\n\t\t" );
  39.             c= ((c<<8)&0xff00)|(Kbshift(-1)&0x2?(-p[i]&0xff):p[i]);
  40.             if( pos++ & 1 )
  41.             {    fprintf( f2,"0x%04X",c );
  42.                 if( size-i>1 ) fprintf( f2,"," );
  43.             }
  44.         }
  45.     else
  46.         for( pos=0,i=size-1;i>=-1;i--,pos&=15 )
  47.         {    if( pos==0 ) fprintf( f2,"\n\t\t" );
  48.             c= (c<<8)|p[i];
  49.             if( pos++ & 1 )
  50.             {    fprintf( f2,"0x%04X",c );
  51.                 if( i>1 ) fprintf( f2,"," );
  52.             }
  53.         }
  54.  
  55.     fprintf( f2,"\n\t};\n\nSND_str Name = { ((UBYTE*)&name),NULL,\
  56. ((UBYTE*)&name)+%ld,7000,1 };\n",size );
  57.  
  58.     Mfree( p );
  59. ex:    fclose(f2);
  60.     fclose(f1);
  61. }
  62.