*                 CATALOG NO. 704908 - SIGMA 5/7 BPM M:READBI
       CSECT       1
*
*
*        READBI  -READS  BI DEVICE  AND WRITES INFORMATION INTO
*
*                 FILE ON DISC
*
*
       PAGE
         SYSTEM   SIG7FDP
*                 SYMBOLIC REGISTER DEF'S.
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
*                 CHANGE STACK POINTER AMOUNT SPEC. BY 1ST ARGUMENT.
*                 SECOND ARGUMENT SPEC. AVAILABLE REGISTER.
BUMP     CNAME
         PROC
LF       LI,AF(2) AF(1)
         MSP,AF(2)  TSTACK
         PEND
*                 PUSH OR PULL N WORDS SPECIFIED BY 1ST ARGUMENT INTO
*                 REG'S STARTING AT 2ND ARGUMENT.
PUSH     CNAME    X'9',X'B'
PULL     CNAME    X'8',X'A'
         PROC
         DO       NUM(AF)=1
LF       GEN,1,7,4,3,17 0,NAME(1),AF(1),0,TSTACK
         ELSE
         DO       AF(1)=1
LF       GEN,1,7,4,3,17  0,NAME(1),AF(2),0,TSTACK
         ELSE
         DO       AF(1)=16
LF       LCI      0
         ELSE
LF       LCI      AF(1)
         FIN
         GEN,1,7,4,3,17  0,NAME(2),AF(2),0,TSTACK
         FIN
         FIN
         PEND
         REF      TSTACK
         PAGE
         DEF      READBI
         SPACE    3
         REF      M:BI,M:X1
         REF      M:C                                                   908
         REF      GETDCBA                                               908
         REF      OPNSTARF
         REF      Y008
         REF      CCBEF
         REF      RDBIECOD
         REF      TREETADR
         REF      ALOCCT
         SPACE    3
ARS      EQU      4
         PAGE
*
*
*        READBI
*
*        ENTER WITH
*                 (R5) = JIT ADR
*
*        CALLING SEQUENCE
*
*        BAL,SR4  READBI
*        ERROR EXIT    (SR3) = MESSAGE ERROR CODE
*        NORMAL EXIT
*
READBI   EQU      %
         PUSH     SR4
         CAL1,1   OPNBIDCB          OPEN BI DCB
         CAL1,1   SETBIDCB          SET ERR/ABN ADR IN BI DCB
         LI,R2    2                 SET FUNC. TO OUT
         LI,R3    1                 SET ORG TO SEQUENTIAL
         LI,R4    'B'               SET NAME TO  'B'
         LI,D3    READBIER          ERR ADR FOR DCB
         LI,D4    READBIAB          ABN ADR FOR DCB
         BAL,SR4  OPNSTARF          OPEN FILE  *SYSIDB
         CI,SR3   0                 CHECK IF FILE GOT OPENED
         BNE      READBIER8         NO
         LW,R2    ALOCCT,R5
         LW,SR2   TREETADR,R2
READBI2  EQU      %
         LI,D1    -2                INIT EOD COUNTER
READBI4  EQU      %
         CAL1,1   RDBIPL            READ BI DEVICE
         LW,R3    M:BI+ARS
         SLS,R3   -17               (R3) = BYTE COUNT FROM READ
         CAL1,1   WTBIPL            WRITE INFORMATION TO *SYSID FILE
         B        READBI2
         PAGE
*
*        PROCESS   I/O  ERR /ABN  RETURNS
*
READBIER,READBIAB EQU    %
         LB,SR3   SR3               (SR3) = I/O ERR/ABN CODE
         CI,SR3   5                 CHECK IF EOD
         BNE      READBIER6         NO
         BIR,D1   READBI4           BRANCH IF 1ST EOD
READBIER2 EQU     %
         MTW,1    *TSTACK           INCREMENT RETURN
         REF      GETLOC20
         B        READBI7
*
*
READBIER6 EQU     %
         CI,SR3   6                 CHECK IF EOF ON BI DEVICE
         BNE      READBIER7         NO
         PUSH     R6                                                    908
         LI,R6    M:C                                                   908
         BAL,D4   GETDCBA                                               908
         STW,R1   R2                                                    908
         LI,R6    M:BI                                                  908
         BAL,D4   GETDCBA                                               908
         PULL     R6                                                    908
         CW,R1    R2                CHECK IF BI AND C HAVE SAME ASSIGN  908
         BNE      READBIER2                                             908
         LW,R3    Y008              YES
         STS,R3   CCBEF,R5          SET CC BUFFER FULL FLAG
         B        READBIER2
*
READBIER7 EQU     %
READBIER8 EQU     %
         LI,SR3   RDBIECOD          SET READ BI ERROR CODE
         LI,R4    2                                                     908
READBI7  RES      0
         LH,R2    M:BI              CHECK IF DCB HAS BEEN OPENED
         CI,R2    X'20'
         BAZ      %+2               DO NOT CLOSE A CLOSED DCB
         CAL1,1   CLSMBI            CLOSE BI DCB
         LH,R2    M:X1
         CI,R2    X'20'
         BAZ      %+2
         CAL1,1   CLSMX1            CLOSE MX1 DCB
         B        GETLOC20
         PAGE
*
*        GET  BI  BUFFER  PAGE   PLIST
*
GETPAGE  EQU      %
         GEN,8,24 8,1
*
*        FREE BI BUFFER PAGE PLIST
*
FREEPAGE EQU      %
         GEN,8,24 9,1
*
*        OPEN  BI  DCB  PLIST
*
OPNBIDCB EQU      %
         GEN,8,24 X'14',M:BI
         DATA     X'C1000000'
         DATA     READBIER8
         DATA     READBIER8
         DATA     1
*
*        SET M:BI DCB READ ERR/ABN ADR'S
*
SETBIDCB EQU      %
         GEN,8,24 6,M:BI
         DATA     X'C0000000'
         DATA     READBIER
         DATA     READBIAB
*
*        READ   BI  DEVICE    PLIST
*
RDBIPL   EQU      %
         GEN,8,24 X'10',M:BI
         DATA     X'F0000010'
         DATA     READBIER
         DATA     READBIAB
         GEN,8,24 X'80',SR2
         DATA     120
*
*        WRITE    *SYSIDB FILE PLIST
*
WTBIPL   EQU      %
         GEN,8,24 X'11',M:X1
         DATA     X'F0000010'
         DATA     READBIER
         DATA     READBIAB
         GEN,8,24 X'80',SR2
         GEN,8,24 X'80',R3
*
*        CLOSE   BI  DCB  PLIST
*
CLSMBI   EQU      %
         GEN,8,24 X'15',M:BI
         DATA     X'80000000'
         DATA     2
*
*        CLOSE   AND SAVE   *SYSIDB  FILE  PLIST
*
CLSMX1   EQU      %
         GEN,8,24 X'15',M:X1
         DATA     X'80000000'
         DATA     2
         END

