{  Written in Personal Pascal by JDEisenberg }

program diskmod;

type
   buftyp=packed array[0..511] of 0..255;
var
   buf,buf2:^buftyp;
   multi:record case boolean of
           true:(ipart:long_integer);
           false:(ppart:^buftyp);
         end;
   hexstr,s:string;
   ch:char;
   i,j,k:integer;
   filler:long_integer;
   devno,sectno,trackno,sideno,count:integer;
   f:file of buftyp;

function floprd(where,filler:long_integer;devno,sectno,trackno,sideno,count:
   integer):integer;
XBIOS(8);

function flopwr(where,filler:long_integer;devno,sectno,trackno,sideno,count:
   integer):integer;
XBIOS(9);

{ Procedure SHOWHEX and DUMP_RESULTS are for debugging.
  You may want to keep them around. }

procedure showhex(n:integer);
begin
   write(hexstr[(n div 16)+1],hexstr[(n mod 16)+1],' ');
end;

procedure dump_results;
var i,j,n:integer;
begin
   for i:=0 to 15 do begin
      showhex(i*16); write(': ');
      for j:=0 to 15 do begin
         showhex(buf^[i*16+j]);
      end;
      write('  ');
      for j:=0 to 15 do begin
         n:=buf^[i*16+j];
         if (n>31) then write(chr(n)) else write('.');
      end;
      writeln;
   end;
end;

begin
   new(buf);
   new(buf2);
   reset(f,'BLOCK0.DAT');
   buf^:=f^;
   hexstr:='0123456789ABCDEF';
   close(f);
   writeln('ST to IBM Disk modifier by JDEisenberg');
   writeln('Written in Personal Pascal');
   writeln('Portions of this product are Copyright (c) 1986,1987');
   writeln('by OSS and CCD.  Used by permission of OSS.');
   writeln;
   writeln('This program modifies double-sided Atari ST');
   writeln('disks so that they can be read on an IBM');
   writeln('3.5 inch drive.  The resulting disk will not');
   writeln('be able to boot on the ST or the IBM, but can');
   writeln('be read or written on either.');

   repeat
      writeln;
      writeln('Place disk to be modified in drive A and press RETURN,');
      writeln('or press ESC to exit.');
      read(ch);
      if (ch=' ') then begin
         multi.ppart:=buf2;
         i:=floprd(multi.ipart,filler,0,1,0,0,1);
         writeln('Read of original boot sector returns ',i);
         if (i=0) then begin
            if (buf2^[26]=1) then begin
               writeln('Sorry, but the disk you are trying to update');
               writeln('is single-sided.');
            end else begin
               for i:=11 to 29 do
                  buf^[i]:=buf2^[i];
               multi.ppart:=buf;
               i:=flopwr(multi.ipart,filler,0,1,0,0,1);
               if (i=0) then writeln('Update successful.') else
               writeln('Error while writing boot sector: ',i);
            end;
         end;
      end
   until (ch=chr(27));
   writeln;
   dispose(buf2);
   dispose(buf);
end.




