MODULE READBLK;
{ 4-Mar-82 }
(*$M BLOCKR*)
(*$M **)

(*$I FIBDEF.LIB*)
VAR
  RESULTIO:	EXTERNAL INTEGER;

EXTERNAL FUNCTION @BDOS(FUNC:INTEGER; PARM:WORD):INTEGER;

PROCEDURE
   BLOCKR(VAR F:FIB;SZ:INTEGER;BA:WORD;VAR R:INTEGER;NB,RB:INTEGER);
VAR
  PTR   : INTEGER;
  I,J   : INTEGER;
  extent: integer;

BEGIN
  f.option := frandom;
  PTR := ORD(BA);
  IF rb >= 0
  THEN BEGIN
    extent := shr (rb, 7);  { bits 7 to 11+ specify extent requested
                              by user, while bits 0 to 6 specify the
                              relative sector within that extent. }
    F.FCB[32] := CHR(RB & $7F);		         (* RELATIVE BLOCK *)
    IF ord (f.fcb [12]) <> extent
    THEN BEGIN
         f.fcb [12] := chr (extent);              { set extent number }
         resultio := @bdos (15, wrd (addr (f.fcb))) { open new extent }
         END
    END;
  FOR I := 1 TO shr (nb, 7) DO  {TO NB DIV 128} {# of specified sectors }
    BEGIN
      J := @BDOS(26,WRD(PTR));                       (* SETDMA address*)
      J := @BDOS(20,WRD(ADDR(F.FCB)));        (* do a SEQUENTIAL READ *)
      PTR := PTR + 128
    END;
  R := J;
END;

MODEND.

