program CHANGE; {wandelt .COM-Files in .HEX-Files}

var fname   : string[14];
    COMFile : file;
    PZ      : integer;
    Puffer  : array[0..32767] of byte;
    Puffer1 : array[0..19000] of byte;

procedure LiesCOMFile;
  var e, fc,i,PC  : integer;
      wert        : byte;

  procedure ablegen(x:byte);
    begin Puffer[PZ]:=x; PZ:=succ(PZ); end;

  procedure ab8(xy:byte);
  var a:byte;
    begin
      a:=xy div 16;
      xy:=xy mod 16;
      if a>9 then a:=a+55 else a:=a+48;
      if xy>9 then xy:=xy+55 else xy:=xy+48;
      ablegen(a);ablegen(xy);end;

  procedure ab16(xy:integer);
    begin ab8(xy div 256);ab8(xy mod 256); end;

  begin  {LiesCOMFile}
    assign(COMFile,fname+'.COM'); reset(COMFile);
    PZ:=0;PC:=0;fc:=0;
    writeln(fname,'.COM  ->   ',fname,'.HEX');
    e:=filesize(COMFile);writeln('size:',e*128);
    blockread(COMFile,Puffer1,e);
    close(COMFile);
    e:=e*128;
     repeat
        ablegen(58);ab8(16);
        ab16(PC);ab8(0);
        for i:=0 to 15 do begin
          wert:=Puffer1[fc];
          fc:=succ(fc);
          if e<=fc then wert:=0;
          ab8(wert);
        end;
        PC:=PC+16;
        ab8(0);
        ablegen(13);
        ablegen(10);
    until e<=fc;
    ablegen(58);ab16(0);ab16(1);ab8(255);
  end; {LiesCOMFile}

procedure MachHEXFile;
  var HEXFile : file;
  begin
    assign(HEXFile,fname+'.HEX');
    rewrite(HEXFile); blockwrite(HEXFile,Puffer,1+(PZ div 128));
    close(HEXFile)
  end;

begin
  ClrSCr; writeln('INLOAD2 ver 1.0 (c) 1986 by P.K & P.U.'); writeln;
  if ParamCount=0 then begin write('Filename='); readln(fname) end
                  else fname:=ParamStr(1);
  LiesCOMFile;
  MachHEXFile
end.