home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1994 September / Simtel-MSDOS-Sep1994-CD2.iso / disc2 / turbopas / hexcom.pas < prev    next >
Pascal/Delphi Source File  |  1987-07-20  |  2KB  |  68 lines

  1. (* ******************************************************************** *)
  2. (* HexCom - Load a HEX (Hex dump file) and makes it a COM file.         *)
  3. (* Author - Victor Lee , Queen's University, Kingston, Ontario, CANADA  *)
  4. (*                       Network id -  VIC at QUCDN                     *)
  5. (* Date   - 1986 Feb 12                                                 *)
  6. (* Note :   See ComHex to convert  COM file into HEX file.              *)
  7. (* ******************************************************************** *)
  8. Program HexCom ;
  9. type  blocks = array [1..128] of char ;
  10.       S2 = string[2] ;
  11.  var
  12.     i : byte ;
  13.     ComName,HexName : string[14] ;
  14.     FN    : string[8] ;
  15.     REC   : string[64] ;
  16.     abyte : byte ;
  17.     Afile : file of byte ;
  18.     Bfile : Text ;
  19.    count,Rcount : integer ;
  20. label  exit ;
  21.  
  22.  function HexNum(char1,char2:char) : byte ;
  23.  var Hi,Low :byte ;
  24.       tempbyte : byte ;
  25.     begin (* hex *)
  26.     Hi := ord(char1) ;
  27.     Low := ord(char2);
  28.     If Hi > $40 then Hi := Hi + 9 ;
  29.     Hi := Hi shl 4 ;
  30.     If Low> $40 then Low:= Low + 9 ;
  31.     Low := Low and $0F ;
  32.     hexNum := Hi + Low ;
  33.     end;
  34.  
  35.     Begin (* Com Load *)
  36.     Writeln('Enter Name of HEX File to Load into COM file ');
  37.     Readln(FN);
  38.     ComName := FN + '.COM' ;
  39.     HexName := FN + '.HEX' ;
  40.     Assign (Afile,ComName);
  41.     Assign (Bfile,HexName);
  42.     Reset(Bfile);
  43.     Rewrite(Afile);
  44.     count := 0 ;
  45.     Rcount := 0 ;
  46.     Writeln('Converting File: ',HexName,' file size =',FileSize(Afile));
  47.     Write(' 64 byte record makes 32 bytes .  Record count = ');
  48.     While Not Eof(Bfile) Do
  49.       Begin (* read  a record *)
  50.       Readln(Bfile,Rec) ;
  51.       writeln('rec=',Rec);
  52.       i := 1 ;
  53.       While i < length(Rec) do
  54.          Begin (* load file *)
  55.          abyte := HexNum(Rec[i],Rec[i+1]) ;
  56.          i := i + 2 ;
  57.          write(Afile,abyte);
  58.          count := count + 1 ;
  59.          End;
  60.       Rcount := Rcount + 1 ;
  61.       Write(RCount ,'  ');
  62.       End ; (* read a record  *)
  63.   exit :
  64.    Close(Afile) ;
  65.    Writeln('Number of 64 byte records read =',Rcount +1);
  66.    Writeln('New file ',ComName,' created.  File size is ',count);
  67.    End. (* Com Load *)
  68.