***********************************************************************
*M*      OPNSTARF OPENS SYSTEM(STAR) FILES AND REGULAR FILES
***********************************************************************
*P*
*P*      NAME:    OPNSTARF
*P*
*P*      PURPOSE: TO OPEN A SPECIFIED SYSTEM FILE OR TO OPEN A REGULAR
*P*               FILE USING EITHER THE M:X1 DCB OR SPECIFIED DCB.
*P*
*P*      DESCRIPTION: SEE FUNCTION PREAMBLES FOR OPNSTARF, OPNF, AND
*P*               OPNFD.
*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      OPNSTARF          OPEN SYSTEM/STAR FILE (*SYSIDX)
         DEF      OPNF              OPEN SPECIFIED FILE
         DEF      OPNFD             OPEN SPECIFIED FILE USING THE
*,*                                 SPECIFIED DCB
         REF      M:X1              DCB USED TO OPEN SPECIFIED FILE
         REF      SYSID             INPUT-USED TO CREATE SPECIFIED
*,*                                 SYSTEM FILE NAME
         REF      XFFFF             MASK
         REF      Y03               MASK
         PAGE
*F*
*F*      NAME:    OPNSTARF
*F*
*F*      PURPOSE: TO OPEN THE SPECIFIED SYSTEM FILE THROUGH THE M:X1 DCB
*F*
*F*      DESCRIPTION: THE SYSTEM FILE NAME IS CONSTRUCTED USING THE
*F*               CURRENT JOB ID FROM WORD 0 OF THE JIT AND THE
*F*               SPECIFIED SYSTEM ID FILE. THE FILE IS OPENED
*F*               THROUGH THE M:X1 DCB. IF THE FUNCTION IS INOUT AND THE
*F*               FILE DOES NOT EXIST, THE FILE IS OPENED IN THE
*F*               OUT MODE.
*F*
**********************************************************************
*                                                                    *
*        OPNSTARF -  OPEN  STAR    FILE   (*SYSIDX)                  *
*                                                                    *
*        ENTER WITH                                                  *
*                 (R2) = FUNCTION                                    *
*                 (R3) = ORGANIZATION                                *
*                 (R4) = LETTER NAME OF FILE (A,B,D,G,L,OR T)        *
*                 (R5) = JIT ADR                                     *
*                 (D3) = ERROR ADR  TO BE PUT IN DCB IF OPENED       *
*                 (D4) = ABNORMAL   ADR TO BE PUT IN DCB IF OPENED   *
*        EXIT WITH                                                   *
*                 (R1) = ADR OF M:X1  DCB                            *
*                 (R2) = FUNCTION FILE OPENED IN  IF OPENED          *
*                 (SR3) =  0  IF FILE OPENED                         *
*                 (SR3) =  I/O  ERROR OR ABNORMAL IF NOT OPENED      *
*                                                                    *
*        IF FUNCTION  SPECIFIED IS INOUT AND FILE DOES NOT EXIST,    *
*                 FILE IS OPENED IN OUT MODE                         *
*                                                                    *
*                                                                    *
*                                                                    *
OPNSTARF EQU      %
         PUSH     SR4
         LW,D1    SYSID,R5
         AND,D1   XFFFF             (D1) = CURRENT SYSTEM ID
         SLS,D1   8
         AW,D1    Y03
         AW,D1    R4
         PUSH     D1
         LW,R4    TSTACK
         LI,D2    0                                                     904
         LI,D1    0                                                     904
         BAL,SR4  OPNFM1            OPEN STAR FILE
         PULL     R4
         B        GETLOC20          EXIT
         REF      GETLOC20
         PAGE
*F*
*F*      NAME:    OPNF
*F*
*F*      PURPOSE: TO OPEN THE SPECIFIED FILE USING THE M:X1 DCB
*F*
*F*      DESCRIPTION: THE SPECIFIED FILE IS OPENED USING THE M:XI
*F*               DCB. IF THE FUNCTION IS INOUT AND THE FILE DOES NOT
*F*               EXIST, THE FILE IS OPENED IN THE OUT MODE.
*F
OPNF     EQU      %
         LW,D4    D3                ABN = ERR
         LI,R2    1                 FCN = IN
OPNFM1   LI,R1    M:X1              DCB
**********************************************************************
*                                                                    *
*        OPNF -   OPEN  FILE  ROUTINE                                *
*                                                                    *
*                 OPENS SPECIFIED DCB TO SPECIFIED FILE              *
*                                                                    *
*        ENTER WITH                                                  *
*                 (R1) = ADR OF DCB                                  *
*                 (R2) = FUNCTION                                    *
*                 (R3) = ORGANIZATION                                *
*                 (R4) = ADR OF FILE NAME                            *
*                 (R5) = ADR OF JIT                                  *
*                 (D1) = ADR OF ACCOUNT NUMBER OR 0                     904
*                 (D2) = ADR OF PASSWORD  OR 0                          904
*                 (D3) = ERROR ADR TO BE PUT IN DCB IF OPENED        *
*                 (D4) = ABNML ADR TO BE PUT IN DCB IF OPENED        *
*                                                                    *
*        EXIT WITH                                                   *
*                 (SR3)=  0  IF DCB  OPENED                          *
*                 (SR3)=  I/O ERROR OR ABNORMAL  CODE IF NOT OPENED  *
*                                                                    *
*        IF  FUNCTION  SPECIFIED IS INOUT AND FILE DOES NOT EXIST,   *
*                 IT IS OPENED IN THE OUT MODE                       *
*                                                                    *
*                                                                    *
*F*
*F*      NAME:    OPNDF
*F*
*F*      PURPOSE: TO OPEN THE SPECIFIED FILE USING THE SPECIFIED DCB
*F*
*F*      DESCRIPTION: THE SPECIFIED FILE IS OPENED USING THE SPECIFIED
*F*               DCB. IF THE FUNCTION IS INOUT AND THE FILE DOESN'T
*F*               EXIST, THE FILE IS OPENED IN THE OUT MODE.
*F*
OPNFD    EQU      %
         PUSH     2,R6
         BUMP     OPNPLSIZ,R7       RES. SPACE FOR OPEN PLIST           904
         LW,R7    TSTACK
         AI,R7    -OPNPLSIZ+1       (R7) = ADR OF OPEN PLIST
         LI,R6    0
         PUSH     4,D1                                                  904
         LI,D1    OPNPLSIZ
OPNF2    EQU      %
         LW,D2    OPNFPLST,R6       MOVE STATIC PLIST
         STW,D2   *R7,R6                          TO TEMP STACK
         AI,R6    1
         BDR,D1   OPNF2
*
         LB,D1    *R4               (D1) = NO. OF BYTES IN FILE NAME
         AI,D1    4
         SLS,D1   -2                (D1) = NO.OF WORDS IN FILE NAME
         LW,D2    R7
         AI,D2    OPNPLFLN          (D2) = ADR OF FILE NAME IN PLIST
         LI,R6    2
         STB,D1   *D2,R6
         AI,D2    1
         LI,R6    0
OPNF4    EQU      %
         LW,D3    *R4,R6            MOVE FILE NAME
         STW,D3   *D2,R6                            TO PLIST
         AI,R6    1
         BDR,D1   OPNF4
         STW,R3   OPNPLORG,R7       STORE  ORGANIZATION IN PLIST
         PULL     4,D1                                                  904
         CI,D1    0                                                     904
         BE       OPNF6                                                 904
         LW,R3    *D1                                                   904
         STW,R3   OPNPLACN+1,R7                                         904
         AI,D1    1                                                     904
         LW,R3    *D1                                                   904
         STW,R3   OPNPLACN+2,R7                                         904
         LI,R3    X'200'                                                904
         AWM,R3   OPNPLACN,R7                                           904
         CI,D2    0                                                     904
         BE       OPNF6                                                 904
         AWM,R3   OPNPLPSW,R7                                           904
         LW,R3    *D2                                                   904
         STW,R3   OPNPLPSW+1,R7                                         904
         AI,D2    1                                                     904
         LW,R3    *D2                                                   904
         STW,R3   OPNPLPSW+2,R7                                         904
OPNF6    EQU      %
         LI,SR3   0
         STW,R2   OPNPLFUN,R7       STORE  FUNCTION IN PLIST
         LI,D1    OPNPLSIZ
         CAL1,1   *R7               OPEN  DCB
OPNF7    EQU      %
         CAL1,1   SETDCB            SET ERR AND ABN ADR IN DCB
*
OPNF8    EQU      %
         BUMP     -OPNPLSIZ,D1      FREE PLIST STORAGE
         PULL     2,R6
         B        *SR4              EXIT
         PAGE
*
*        HANDLES  ERROR AND ABNORMAL  RETURNS FROM OPEN
*
*
OPNFERAB EQU      %
         SLS,SR3  -17
         CI,SR3   X'1428'**-1       WAS EXECUTE FILE OPENED
         BNE      OPNFER5           NO
         LI,SR3   0                 YES, SET=0  (FILE OPENED)
         B        OPNF7
OPNFER5  EQU      %
         SLS,SR3  -7
         CI,SR3   3                 CHECK IF FILE DOES NOT EXIST
         BNE      OPNF8             NO
         CI,R2    4                 YES, CHECK IF OPENING IN INOUT MODE
         BNE      OPNF8             NO
         LI,R2    2                 YES, TRY TO OPEN IN OUT MODE
         B        OPNF6
         PAGE
*
*        OPNF  PLIST
*
*
OPNFPLST EQU      %
         GEN,1,7,24  1,X'14',1      CODE, DCB ADR
         DATA     X'CF4801F1'       PLIST INDICATORS
         DATA     OPNFERAB          ERR ADR
         DATA     OPNFERAB          ABN ADR
         DATA     10                TRIES
OPNPLORG EQU      %-OPNFPLST
         DATA     0                 ORG
         DATA     2                 ACCESS
OPNPLFUN EQU      %-OPNFPLST
         DATA     0                 FUNCTION
         DATA     2                 FILE
         DATA     31                KEYM
OPNPLFLN EQU      %-OPNFPLST
         DATA     X'01000008'       FILE NAME
         RES      8
OPNPLACN EQU      %-OPNFPLST                                            904
        DATA      X'02000002'
         DATA     0
         DATA     0
OPNPLPSW EQU      %-OPNFPLST                                            904
         DATA     X'03000002'       PASSWORD
         DATA     0
         DATA     0
         DATA     X'04000000'       EXPIRE DATE
         DATA     X'05000000'       READ ACCN
         DATA     X'06000000'       WRITE ACCN
         DATA     X'07000000'       INSN
         DATA     X'08010000'       OUTSN
OPNPLSIZ EQU      %-OPNFPLST
         PAGE
*
*        SETDCB   PLIST
*
*
SETDCB   EQU      %
         GEN,1,7,24  1,06,1
         DATA     X'C0000000'
         GEN,1,31 1,D3
         GEN,1,31 1,D4
         END

