program convert;

uses crt;

var
  f1,f2,f3:file of char;
  ch:char;
  t,i,l,m:longint;
  ar:array [1..8000] of char;

begin
  t:=0;
  writeln('openning files.');
  assign(f1,'backup.bin');
  assign(f2,'backup.85b');
  assign(f3,'backup.out');
  reset(f1);
  reset(f2);
  rewrite(f3);
  writeln('scan 1');
  for i:=0 to $43 do read(f2,ch); {index 85b to start of part 1}
  for i:=0 to $345 do {copy first part to out}
  begin
    read(f1,ch);
    t:=t+1;
    write(f3,ch);
  end;
  writeln('scan 2 - 2225');
  for i:=$44 to $8f4 do  {copy part 1 to out}
  begin
    read(f1,ch);
    t:=t+1;
    read(f2,ch);
    write(f3,ch);
  end;
  l:=0;
  read(f2,ch); {index 85b counter bytes}
  l:=ord(ch);
  read(f2,ch);
  l:=l+ord(ch)*$100;
  writeln('scan 3 -',l);
  for i:=$8f7 to $8f6+l do {copy part 2 to out}
  begin
    read(f1,ch);
    t:=t+1;
    read(f2,ch);
    write(f3,ch);
  end;
  m:=0;
  read(f2,ch); {index 85b counter bytes}
  m:=ord(ch);
  read(f2,ch);
  m:=m+ord(ch)*$100;
  m:=m-1;
  writeln(m,' ',t);
  writeln('scan 4');
  for i:=$8bf7+l-1 to $fa6f-m-2 do {copy space between part 2 and 3 to out}
  begin
    read(f1,ch);
    t:=t+1;
    write(f3,ch);
  end;
{  nn:=64111;}
  writeln('reading vat.');
  for i:= $fa6f-m+1 to $fa6f do  {fa6f} {copy part 3 to array}
  begin
    read(f1,ch);
    read(f2,ch);
    t:=t+1;
    write(f3,ch);
  end;

  for i:=$7a70 to $800b do
  begin
    read(f1,ch);
    write(f3,ch);
  end;

  read(f1,ch);
  ch:=chr($8b);
  write(f3,ch);
  read(f1,ch);
  ch:=chr($f7);
  write(f3,ch);

{
  for i:=1 to m do
  begin
    ch:=ar[i];
    ar[i]:=ar[m-i+1];
    ar[m-i+1]:=ch;
  end;
  writeln('scan 6');
  for i:=$fa6f-m+1 to $fa6f do {copy part 3 from array
  begin
    read(f1,ch);
    t:=t+1;
    write(f3,ar[i-($fa6f-m)]);
  end;}

writeln('final scan');
  while not eof(f1) do {copy remaining mem from bin}
  begin
    read(f1,ch);
    t:=t+1;
    write(f3,ch);
  end;


  close(f1);
  close(f2);
  close(f3);
end.
