const     pb   = $91;
          pa   = $93;
          cb   = $90;
          ca   = $92;

var       cbm  : byte;
          name : string [ 122 ];
          fil  : file;
          ptr,
          i    : integer;
          key  : boolean;
          arr  : array [ 0 .. 127 ] of byte;
          cs   : integer;

procedure portini;

begin

   port [ ca ] := $4f;
   port [ cb ] := $cf;
   port [ cb ] := $2; { pb0 > busy / pb1 > strobe }
   port [ pb ] := 1;

end;


function parein : byte;

begin

   key := false;
   port [ pb ] := 0;
   repeat until ( port [ pb ] = 2 ) or keypressed ;
   parein := port [ pa ];
   port [ pb ] := 1;
   repeat until ( port [ pb ] = 1 ) or keypressed ;
   if keypressed
   then begin
        read ( name );
        key := true;
        end;

end;


begin

   portini;
   write( 'Filename : ' );
   readln( name );
   assign( fil , name );
   rewrite ( fil );
   cs := 0;
   repeat
   begin
      ptr := 0;
      repeat
      begin
         arr [ ptr ] := parein;
         ptr := ptr + 1;
      end
      until ( ptr = 128 ) or ( key = true );
   write ( ' Block ' );
   if key
      then for i := ptr - 1 to 127 do
           arr [ i ] := 0;
   for i := 0 to 127 do
      cs := ( cs + arr [ i ] ) mod 256;
   blockwrite ( fil , arr , 1 );
   end;
   until key = true;
   close ( fil );
   writeln;
   writeln( ' Summe = ' , cs );

end.