program convert;

uses crt;

var
  f1,f2,f3:file of char;
  ch:char;
  t,i,l,m:longint;
  ar:array [0..$8025] 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,ar[t]);
    t:=t+1;
  end;

  writeln('scan 2 - 2225 bytes');
  for i:=$44 to $8f4 do {copy part 1 to out}
  begin
    read(f1,ch);
    read(f2,ar[t]);
    t:=t+1;
  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,' bytes');
  for i:=$8f7 to $8f6+l do {copy part 2 to out}
  begin
    read(f1,ch);
    read(f2,ar[t]);
    t:=t+1;
  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,ar[t]);
    t:=t+1;
  end;

  writeln('reading vat.');
  for i:= $fa6f-m+1 to $fa70 do  {fa6f} {copy part 3 to array}
  begin
    read(f1,ch);
    read(f2,ar[t]);
    t:=t+1;
  end;
*)
  writeln('final scan');
  while not eof(f1) do
  begin
    read(f1,ar[t]);
    t:=t+1
  end;

  writeln('making alterations');
{  for i:=$8000 to $8007 do ar[i]:=chr($00);}
  for i:=$800c to $800d do ar[i]:=chr($00);
{  for i:=$8010 to $801a do ar[i]:=chr($00);}

  writeln('writing data to disk');
  for i:=$0000 to $8024 do write(f3,ar[i]);
  close(f1);
  close(f2);
  close(f3);
end.
