home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / gallery / subdirs.exe / TEXTURE / BIN2INC.PAS < prev    next >
Pascal/Delphi Source File  |  1993-07-10  |  2KB  |  95 lines

  1. {$V-}
  2.  
  3. uses dos;
  4.  
  5. var I : File;
  6.     O : Text;
  7.     NI,xNI,nNI,NO : string;
  8.     d,nm,e : string;
  9.  
  10.     data : array[0..9] of byte;
  11.     InFileSize, LIM, k : longint;
  12.     count : integer;
  13.  
  14. function ToHex( var V; len : byte ) : string;
  15. const Hex : string = '0123456789abcdef';
  16. type BArray = array[1..16] of byte;
  17. var s : string;
  18.     i,k : integer;
  19.     b : byte;
  20. begin
  21.   s[1] := '0'; k := 2;
  22.   for i := len downto 1 do begin
  23.     b := BArray(V)[i];
  24.     s[k] := Hex[(b div 16)+1]; inc(k);
  25.     s[k] := Hex[(b mod 16)+1]; inc(k);
  26.   end;
  27.   s[k] := 'h';
  28.   s[0] := chr(k);
  29.   ToHex := s;
  30. end;
  31.  
  32. begin
  33.   writeln('BIN2INC. Binary to include file converter // A.R-M. 7/93');
  34.   writeln;
  35.   if paramcount<1 then begin
  36.     write('Binary input file name [.BIN]: '); readln(NI);
  37.   end else NI := ParamStr(1);
  38.  
  39.   FSplit( NI, d,nNI,e );
  40.   if e='' then e := '.BIN';
  41.   xNI := nNI+e;
  42.   NI := d+xNI;
  43.  
  44.   if paramcount<2 then begin
  45.     write('.INC output file name [',nNI,'.INC]: '); readln(NO);
  46.   end else NO := ParamStr(2);
  47.  
  48.   FSplit( NO, d,nm,e );
  49.   if nm='' then nm := nNI;
  50.   if e='' then e := '.INC';
  51.   NO := d+nm+e;
  52.  
  53.   assign(I,NI); reset(I,1);
  54.   assign(O,NO); rewrite(O);
  55.   writeln(O,'; data file created from "',xNI,'" by BIN2INC, ARM 7/93');
  56.   writeln(O);
  57.  
  58.  
  59.   InFileSize := FileSize(I);
  60.  
  61.   if InFileSize>10 then begin
  62.     write(O,' DT ');
  63.     count := 0;
  64.     LIM := InFileSize div 10;
  65.     for k := 1 to LIM do begin
  66.       blockread(I, data, 10);
  67.       write(O, ToHex(data,10));
  68.       inc (count);
  69.       if count=8 then begin
  70.         writeln(O);
  71.         if k<LIM then write(O,' DT ');
  72.         count := 0
  73.        end else
  74.         if k<LIM then write(O,',');
  75.     end;
  76.   end;
  77.   if count<>0 then writeln(O);
  78.  
  79.   LIM := InFileSize mod 10;
  80.   if LIM>0 then begin
  81.     write(O,' DB ');
  82.     count := InFileSize mod 10;
  83.     blockread(I, data, count);
  84.     for k := 1 to count-1 do write(O, ToHex(data[k-1],1),',');
  85.     writeln(O,toHex(data[k-1],1));
  86.   end;
  87.  
  88.   writeln(O);
  89.   close(O);
  90.   close(I);
  91.  
  92.   writeln('"',nm+e,'" successfully created.');
  93. end.
  94.  
  95.