***********************************************************************
*M*      READBI   READS DEVICE ASSIGNED TO M:BI DCB AND GENERATES A BI FILE
***********************************************************************
*P*
*P*      NAME:    READBI
*P*
*P*      PURPOSE:     TO READ THE DEVICE ASSIGNED TO THE
*P*                   M:BI DCB AND  GENERATE A BI FILE
*P*                   WITH THE RELOCATABLE OBJECT MODULES
*P*                   READ.
*P*
*P*      DESCRIPTION: READ BI IS CALLED BY CCIR AFTER A
*P*                   LOAD OR OVERLAY CONTROL COMMAND HAS
*P*                   BEEN PROCESSED WHICH SPECIFIED A
*P*                   BI OPTION. A STAR B FILE (SYSID B)
*P*                   IS CREATED FROM RELOCATABLE OBJECT
*P*                   MODULES WHICH ARE READ THROUGH THE
*P*                   M:BI DCB.
*P:
*P*      REFERENCE:   BATCH PROCESSING REFERENCE MANUAL.
*P*
       CSECT       1
       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            ENTRY POINT TO READBI
         SPACE    1
         REF      M:BI              INPUT-ADDRESS OF DCB THROUGH WHICH
*,*                                 BI IS READ
         REF      M:X1              OUTPUT-ADDRESS OF DCB THROUGH WHICH
*,*                                 THE STAR B FILE IS WRITTEN
         REF      M:C               INPUT-ADDRESS TO DETERMINE IF M:C AND
*,*                                 M:BI ASSIGNED TO THE SAME DEVICE
         REF      GETDCBA           GET DCB ADDRESS
         REF      OPNSTARF          OPEN STAR FILE B(SYSIDB)
         REF      Y008              MASK
         REF      Y08               CONSTANT
         REF      EXPBINM           ERROR MESSAGE
         REF      CCBEF             OUTPUT-BIT 8; DISPLACEMENT IN JIT
*,*                                 FOR WHICH BUFFER FULL FLAG IS SET
         REF      RDBIECOD          ERROR CODE CONSTANT
         REF      TREETADR          INPUT-TREE TABLE ADDRESS USED FOR
*,*                                 BI INPUT BUFFER
         REF      ALOCCT            INPUT-LOCCT ADDRESS USED IN LOCATING
*,*                                 TREE TABLE ADDRESS
         REF      GETLOC20          RETURN TO CCIR
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
         B        READBI7
*
*
READBIER6 EQU     %
         CI,SR3   6                 CHECK IF EOF ON BI DEVICE
         BNE      READBIER8         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    Y08               CHECK IF CFE MODE
         CW,R3    *R5               IF SO, ERROR BINARY NOT FOUND
         BANZ     READBIER7
         LW,R3    Y008              YES
         STS,R3   CCBEF,R5          SET CC BUFFER FULL FLAG
         B        READBIER2
*
READBIER7 EQU     %
*E*      MESSAGE: EXPECTED BINARY WASN'T ENCOUNTERED ON BI DEVICE
*E*      DESCRIPTION: EXPECTED BINARY WASN'T FOUND AND A CONTROL COMMAND
*E*                   READ. THIS LEADS TO SKIPPING OF THE CONTROL
*E*                         COMMAND
         LI,R4    2                 GET LISTING DEVICE
         LI,SR3   EXPBINM
         B        READBI7
READBIER8 EQU     %
*E*      MESSAGE:     I/O ERROR/ABNORMAL IN READBI SUBROUTINE
*E*
*E*      DESCRIPTION: READ BI WAS UNABLE TO CREATE A STAR
*E*                   B FILE.
         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

