home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol134 / bintohex.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-04-29  |  1.7 KB  |  87 lines

  1. {$E+,T-}
  2.  
  3. program bintohex
  4. ;
  5. const
  6.      TheHEADER = 'CP/M Binary File to ASCII Hex File Program';
  7.      TheVERSION= 'Version -- October 10, 1982.';
  8.      TheTRAILER= 'Binary to Hex File conversion done.';
  9.      hexinit   = '0123456789ABCDEF';
  10.  
  11. type 
  12.      sector    = packed array [1..128] of char;
  13.      filestring= string 14;
  14.  
  15. var 
  16.      ofilename ,
  17.      ifilename : filestring;
  18.  
  19.      hexfile   ,
  20.      binfile   : file of sector;
  21.      
  22.      hexbuf    ,
  23.      binbuf    : sector;
  24.  
  25.      hextab    : string 16;
  26.  
  27.      i         ,
  28.      j         ,
  29.      k         : integer;
  30.  
  31.  
  32.  
  33. function OpenInp: boolean
  34. ;
  35. begin  {* OpenInp *}
  36.      OpenInp := true;
  37.      write('INPUT FILE? ');
  38.      read(ifilename);
  39.      reset(ifilename,binfile);
  40.      if EOF(binfile) then begin
  41.           writeln(' ... file is empty...');
  42.           OpenInp := false;
  43.      end; 
  44. end;  {* OpenInp *}
  45.  
  46.  
  47.  
  48. function OpenOut:boolean
  49. ;
  50. begin  {* OpenOut *}
  51.      OpenOut := true;
  52.      write('OUTPUT FILE? ');
  53.      read(ofilename);
  54.      rewrite(ofilename,hexfile);
  55. end;  {* OpenOut *}
  56.  
  57.  
  58.  
  59.  
  60. begin  {* BintoHex *}
  61.      writeln(TheHEADER);
  62.      writeln(TheVERSION);
  63.  
  64.      hextab := Hexinit;
  65.  
  66.      repeat
  67.      until OpenInp;
  68.      writeln('------> File opened.');
  69.  
  70.      repeat
  71.      until OpenOut;
  72.      writeln('------> File opened.');
  73.  
  74.      while  not EOF(binfile) do begin
  75.           read(binfile,binbuf);
  76.           for i := 0 to 1 do begin
  77.                for j := 1 to 64 do begin
  78.                     k := ord(binbuf[i*64+j]);
  79.                     hexbuf[2*j-1] := hextab[(k div 16)+1];
  80.                     hexbuf[2*j]   := hextab[(k mod 16)+1];
  81.                end;
  82.                write(hexfile,hexbuf);
  83.           end;
  84.      end;
  85.      writeln(TheTRAILER);
  86. end.  {* BintoHex *}
  87.