         DEF      MCST              MODULLE BASE
MCST     CSECT    1
***********************************************************
*M*      SAT      SATISFY PREFS FROM LIBRARIES
**************************************************************
*P*      NAME:    SAT
*P*      PURPOSE: SATISFIES PREFS FROM LIBRARIES
*P*      DESCRIPTION: CALLED  BY PS1 AFTER EACH TREE SEGMENT
*P*               THE SATISFY-REFERENCE LOGIC WORKS AS FOLLOWS: AFTER
*P*               EACH SEGMENT'S ELEMENT FILES HAVE BEEN READ AND ITS
*P*               REF/DEF STACK BUILT,SATREF IS CALLED TO SATISFY THE
*P*               SEGMENT'S PREFS BY SEARCHING THE SPECIFIED LIBRARIES.
*P*               THUS IT ATTEMPTS TO SATISFY ALL THE PREFS IT CAN IN
*P*               A LOWER SEGMENT BEFORE STARTING TO BUILD THE REF/DEF
*P*               STACK FOR A HIGHER SEGMENT. THE ASSOCIATION OF A CORE
*P*               LIBRARY IS TRIGGERED BY ONE OF TWO CONDITIONS:
*P*               1- A PREF TO 9INITIAL(FORTRAN) OR 9DBINIT(FORT DEBUG)
*P*               2- THE PRESENCE OF A :PN IN THE UNSAT LIST ON THE
*P*                  !LOAD CARD.
*P*      REFERENCE: THE OVERLAY LOADER TECHNICAL MANUAL HAS A MORE
*P*               DETAILED DESCRIPTION AND FLOW CHARTS.
***********************************************************************
         SYSTEM   SIG7FDP
         PCC      0
MODE     EQU      1
CFU      EQU      1
BPMLIB   EQU      0                 1=BUILD BPM LIB UNDER CP-V
*BPMLIB=1 MUST BE USED ONLY WITH MODE=1 AND THEN JUST TO
*FORM A LOADER TO USE IN BUILDING BPM LIBRARIES UNDER CP-V.
         REF      ADLEF             ADD IBRARY E.F.
         REF      SEGBSR4           SEGLOAD AND B *SR4
         REF      Y0008
         REF      TXLIB             TEXTC ':LIB'
         REF      TXBLNK            A WORD OF BLANKS
         REF      EFNAME            NAME FIELD OF OPENEF  FPT
         REF      EFACCNT           ACCOUNT FIELD OF OPENEF  FPT
         REF      EFPASS            PASSWORD FIELD OF OOPENEF  FPT
         REF      ER6X              CANNOT OPEN E.F.
         REF      TSTACK            LOADER'S TEMP STACK
         REF      UNSATFLG          UNSAT TABLE FLAGS FROM LOCCT
         REF      UNSATTBL          ADDR IN LOCCT OF UNSATS
         REF      CROM1             CURRENT ROM DISP (FROM R2)
         PAGE
BGEZ     EQU      X'681'
BE       EQU      X'683'
BNEZ     EQU      X'693'
BGE      EQU      X'681'
BL       EQU      X'691'
BAZ      EQU      X'684'
BCR8     EQU      X'688'
BCR10    EQU      X'68A'
BLE      EQU      X'682'
BEZ      EQU      X'683'
BNC      EQU      X'688'
         REF      MESSAGE           ROUTINE TO PRINT ERROR MESSAGE
*,*                                 AND ERROR CODE ON LOADER ERRORS.
         REF      IOMSG
         REF      CODE
*        QUIT     ERROR,CONDITION,OUTPUT
QUIT     CNAME
         PROC
LF       EQU      %
         LOCAL    O
         DO1      AF(2)]=0
         GEN,12,20 AF(2),O
         DO1      NUM(AF)=3
         STW,AF(3) CODE
         LI,R4    AF(1)
         DO       AF(3)=SR3
         B        IOMSG
         ELSE
         B        MESSAGE
         FIN
O        EQU      %
         PEND
         PAGE
*                 SYMBOLIC REGISTER DEFINITIONS.
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
*                 DATA CONSTANTS
         REF      MN1
         REF      M8
         REF      M6
         REF      M24
         REF      Y4
         REF      Y01
         REF      Y002
         REF      Y0002
         REF      Y0006
         REF      Y0007
*                 STATIC DATA AREAS
         REF      CLOSE
         REF      M:EF
         REF      OPENEF
         REF      PRINT
         REF      SETEF
         REF      TXM:STAR
*                 CONSTANTS
K1       EQU      1
K2       EQU      2
K3       EQU      3
K4       EQU      4
K40      EQU      X'40'
         REF      ER21
         REF      NRWACCT
         REF      NUNSTDIS
         REF      RFDFDIS
         REF      ROMSIZE
         REF      NXROMDIS
         REF      ROM1DIS
         REF      TREESIZE
*                 SUBROUTINES
*                 DYNAMIC DATA
         REF      BUF
         REF      CORELIB
         REF      CSEG1
         REF      DECLBAS
         REF      DECLSTK
         REF      FASTSRCH
         REF      RDPTRS
         REF      RDSYMS
         REF      LOCCT
         REF      EXPRSTK
         REF      RFDFBAS
         REF      RFDFSTK
         REF      PBUF
         DEF      SAT               SEARCH LIBRARIES FOR PREFS
SAT      EQU      %
*                                   THIS ROUTINE SATISFIES PREF'S.
         PSW,SR4  *R0
         LW,R3    LOCCT
         LW,R4    NUNSTDIS,R3
         AND,R4   M8
*                                   EXIT IF NO ACCOUNTS SPECIFIED.
         BEZ      SATEXIT
         SCS,R4   -8                PUT COUNT IN HIGH BYTE
USEARCH  PSW,R4   *R0               SAVE COUNTING REG
         LB,R5    UNSATFLG,R4       GET DISP TO THOS ENTRY
         AND,R5   M6                SCRUB FLAGS
         LC       UNSATFLG,R4       IS THERE A NAME
         BCS,8    GETNAME           ITS THERE, GO GET IT
         LCI      2
         LM,SR1   TXLIB             LET DEFAULT LIB BE ':LIB'
         B        GOTNAME
GETNAME  LCI      3
         LM,SR1   *UNSATTBL,R5      GET LIB NAME FROM UNSAT TABLE
         AI,R5    3                 POINT PAST LIB NAME
         LCI      3
GOTNAME  STM,SR1  EFNAME            PUT LIB NAME INTO OPEN FPT
         LCI      2                 GET UNSAT ACCNT
         LM,D3    *UNSATTBL,R5
         STM,D3   EFACCNT
         AI,R5    2                 AND PASSWORD
         LM,SR3   *UNSATTBL,R5
         STM,SR3  EFPASS
         CW,SR1   TXLIB
         BNE      %+2
         CD,D3    TX:SYS
         BNE      %+2
         BAL,R6   STCORELIB         DO CORE LIB NOW
         LW,D4    MN12              IS THIS A CORE LIBRARY
         CS,D3    TX:P0
         BNE      ITSACN
         LI,R6    SATEREX1          SET RETURN FROM CORELIBER
         LC       CORELIB           HAVE WE DONE IT ALREADY
         BCS,12   SATEREX1          YES
         LW,R3    EFACCNT
         SLS,R3   -8
         MTB,3    R3                MAKE GOOD NAME
         B        GETCORELIB
ITSACN   EQU      %
         LI,SR1   ER6X              SET ERR,ABN ADDRS.
         CAL1,1   OPENEF
UNSAT    LI,SR1   UNSAT5            AND FOR READS
         CAL1,1   SETEF
         LI,R3    M24               START AT MAK
         LI,SR1   0                 INIT STACK
UNSAT2   BAL,R6   PREFNX            GET NEXT PREF
         B        UNSAT4            END OF STACK
         LW,R5    *SR1              GET NOT IN LIB FLAG
         CI,R5    1
         BANZ     UNSAT2            NOT IN LIB
         AI,SR1   3                 POINT TO NAME
         LCI      2
         LM,R5    *SR1              LOAD NAME
         LW,R7    M24
         XW,R5    R6
         CS,R6    0,R3              CHECK ORDER
         BG       UNSAT3            NOT SMALLER
         BL       %+4
         LI,R7    -1
         LW,R6    R5
         CS,R6    1,R3              CHECK SECOND WORD
         BG       UNSAT3
         LW,R3    SR1               SET NEW POONTER
UNSAT3   AI,SR1   -3                RESET POINTER
         B        UNSAT2
UNSAT4   CI,R3    M24               ANY PREFS LEFT
         BE       UNSAT6            NO
         LB,D3    *R3               YES, GET NAME'S COUNT
         ANLZ,SR3 %-1               BA(KEY)
         LI,SR4   BA(PBUF)+2        MOVE REF/DEF NAME TO PBUF AND...
         STB,D3   SR4               ...PRECEDE IT W/ ONE BLANK TO USE...
         AI,D3    1                 ...AS KEY FOR READING :LIB.
         SLS,D3   8
         AI,D3    X'40'
         CI,D3    X'F40'             ARE WE  TOO  BIG
         BLE      %+2               INO
         LI,D3    X'F40'
         STH,D3   PBUF
         MBS,SR3  1
         LI,R5    0
         STW,R5   BUF+2
         CAL1,1   READEF
         B        ADDLLM            NAME IN DICT, GO GET LEF
READEF   GEN,8,24 16,M:EF
         DATA     X'FC000010',UNSAT5,UNSAT5
         DATA     BUF,12,PBUF,0
UNSAT5   LW,SR1   R3                RESTORE POINTER
         AI,SR1   -3
         MTW,1    -3,R3
         B        UNSAT             CONTINUE SEARCH
UNSAT6   LI,SR1   0                 INIT STACK
UNSAT7   BAL,R6   PREFNX            GET NEXT PREF
         B        SATEND            END OF STACK
         LW,R6    *SR1
         AND,R6   MN1               RESET FLAG
         STW,R6   *SR1
         B        UNSAT7
*  STACK SEARCH SUBR
PREFNX   CI,SR1   0                 START STACK
         BNE      PREFNX1           NO
         LW,SR1   CSEG1             YES, SET UP BASE AND TOP
         AI,SR1   RFDFDIS
         INT,SR2  *SR1,R1
         LW,SR1   *SR1,R1
         LH,SR1   SR1
         SLS,SR2  1
         AW,SR1   SR2
         XW,SR1   SR2
         B        PREFNX2
PREFNX1  LB,R5    *SR1              TO NEXT ITEM
         AW,SR1   R5
         CW,SR1   SR2               END OF STACK
         BGE      *R6
PREFNX2  LW,R5    *SR1              NO
         AND,R5   Y0007
         CW,R5    Y0002             IS IT PREF
         BNE      PREFNX1           NO, GET NEXT
         AI,SR1   3
         LW,R5    *SR1
         AI,SR1   -3
         DO       CFU=1
         CW,R5    TXM:STAR
         BE       PREFNX1           DON'T SEARCH FOR M:*
         FIN
         AI,R6    1                 YES, RETURN
         B        *R6
SATEND   EQU      %
         LI,R5    M:EF
         CAL1,1   CLOSE
SATEREX1 EQU      %
         PLW,R4   *R0
         AI,R4    1                 TO NEXT ENTRY IN UNSATFLGS
         MTB,-1   R4                COUNT COUNT
         BNEZ     USEARCH
SATEXIT  EQU      %
         BAL,R6   STCORELIB
         PLW,SR4  *R0
         BAL,R5   SEGBSR4           BACK TO PASS1
         TEXTC    'PS1'
         PAGE
*                                   FOUND THE NAME IN THE DICTIONARY
*                                   ADD THE LOAD MODULE NAME TO THE
*                                   END OF THE APPROPRIATE SEGMENTS
*                                   ROM TABLE. THIS REQUIRES MOVING ANY
*                                   OF THE ROM TABLE WHICH IS HIGHER IN
*                                   MEMORY AND ALL STACKS UP 8
*                                   LOCATIONS, AND CHAGING ALL
*                                   POINTERS TO THESE TABLES.
ADDLLM   LW,R4    CSEG1
         AI,R4    ROM1DIS
         LW,R4    *R4,R1
         LH,R4    R4
         LI,R7    K40
FNDLSTRM AI,R4    NXROMDIS
         LW,D4    *R4,R2
         STS,R7   *R4,R2
         AI,R4    5
         CI,D4    X'40'
         BANZ     FNDLSTRM
         INT,D4   *TSTACK           GET CURRENT UNSAT ENTRY#
         SLS,D4   2                 SHIFT 2 BITS
         AI,D4    X'20'
         LI,R5    3
         STB,D4   BUF+2,R5
         LW,R5    RFDFSTK
         SW,R5    R4
         LW,R6    R4
         AI,R6    ROMSIZE+1
         ANLZ,R7  MOVROMT1+1        WILL MOVE CAUSE A COLLISION
         CW,R7    EXPRSTK         WITH THE EXPRESSION STACK.
         BL       NOCRASH
         SW,R7    EXPRSTK           # OF WDS THAT OVERFLOW IN R7
*E*      ERROR:   0200-21
*E*      MESSAGE: NO ROOM TO ADD LIBRARY LOAD MODULE TO ROM TABLE.
*E*      DESCRIPTION: THE ADDITION OF ONE MORE ROM TABLE ENTRY WILL
*E*               CAUSE THE LOADER TO EXCEED THE AVAILABLE AMOUNT
*E*               OF MEMORY.
*E*      REGISTERS: R7 HAS NUMBER OF WORDS THAT OVERFLOWED.
         QUIT     ER21,,R7          PRINT ERROR AND R7
NOCRASH  EQU      %
         CW,R7    RDPTRS            DID WE COLLIDE WITH THE SORT TBL
         BL       %+2               NO, NO PROBLEM
         DATA     FASTSRCH          YES..GIVE UP ON IT
         LW,R7    R5
         SW,R7    R2
         AI,R7    K1
MOVROMT1 LW,D3    *R4,R5
         STW,D3   *R6,R5
         BDR,R5   %+1
         BDR,R7   MOVROMT1
         MTW,0    FASTSRCH          ARE WE USING BINARY INSERTION ALG.
         BNEZ     NOTFAST2          NO
         LW,R7    RDSYMS
         LI,D3    ROMSIZE+1         UPDATE ALL SORT TABLE POINTERS.
         B        %+2
         AWM,D3   *RDPTRS,R7
         BDR,R7   %-1
         AWM,D3   *RDPTRS
NOTFAST2 EQU      %
         ANLZ,D1  MOVROMT1
         LW,R4    BUF+2
MOVROMT3 CI,R4    K40
         BAZ      MOVROMT2
         LW,R7    R2
         LW,D3    R2
         AI,D3    7
         LW,R4    R6
         AI,R4    -1
MOVROMT4 LW,R5    *R6,R7
         STW,R5   *R4,R7
         AI,R7    1
         CW,R7    D3
         BNE      MOVROMT4
         AI,R6    7
         AW,R4    R2
         LW,R4    2,R4
         B        MOVROMT3
MOVROMT2 LW,R4    R1
         LW,R4    -1,R4
         LW,R6    CSEG1
         AW,R6    R1
         AI,R6    TREESIZE
         LI,R5    ROM1DIS
         LW,D3    Y0008
         AW,R5    R1
         LI,R7    K4                (ROMSIZE+1)/2
FXROMPTR CW,R5    R4
         BG       ADROMENT
         CW,R5    R6
         BL       FIXRDPTR
         AWM,D3   *R5
FIXRDPTR AI,R5    3                 RFDFDIS-ROM1DIS
         AWM,R7   *R5
         AI,R5    8                 TREESIZE-RFDFDIS+ROM1DIS
         B        FXROMPTR
ADROMENT LI,R7    ROMSIZE+1
         AWM,R7   DECLBAS
         AWM,R7   DECLSTK
         AWM,R7   RFDFSTK
         AWM,R7   RFDFBAS
         AW,R3    R7
         AI,D1    K1
         LCI      3
         LM,R5    BUF
         STM,R5   *D1
         MTW,ROMSIZE CROM1          POOINT TO PROPER NAME
         AI,D1    K3
         LCI      2
         LM,D3    EFACCNT           GET LIBRARY ACCOUNT
         STM,D3   *D1
         AI,D1    K2
         LCI      2
         LM,D3    EFPASS            GET LIBRARY PASSWORD
         STM,D3   *D1
         BAL,SR4  ADTXT             GEN A MESSAGE
         DATA     BUF               NAME..
         DATA     TCOF              OF..
         DATA     M:EF+23           LIBNAME..
         DATA     TCDOT             .
         GEN,8,24 8,EFACCNT         LIBACCT..
         DATA     TCASSOC           ASSOCIATED FOR..
         PZE      *R3               DEFNAME..
         BAL,SR4  ADLEF             ADD IT IN
*                                   GO BACK FOR THE NEXT PREF.MUST START
*                                   AT TOP OF STACK AGAIN IN CASE A SREF
*                                   HAS BECOME A PREF.
         B        UNSAT
MFD      DATA     X'FD'
TCOF     TEXTC    ' OF '
TCDOT    TEXTC    '.'
TCASSOC  TEXTC    ' ASSOCIATED FOR '
*
ADTXT    LI,R5    BA(PBUF)+2
         LI,R4    ' '
         STH,R4   PBUF
ADTXT1   LB,R4    *SR4
         STB,R4   R5                SAVE COUNT IF NONT TEXTC
         LW,R4    *SR4
         BGZ      %+3
         LW,R4    *R4               INDIRECT
         AND,R5   M24               HAS NO COUNT
         SLS,R4   2                 BYTE ADDRESS
         LB,D4    0,R4              GET COUNT
         MTB,0    R5                IF WE NEED ONE
         BNEZ     %+3
         STB,D4   R5
         AI,R4    1
         MBS,R4   0
         MTB,0    *SR4              SCRUB BLANKS IF TEZXT OR INDIR
         BEZ      %+5
         AI,R5    -1
         LC       0,R5
         BCR,11   %-2
         AI,R5    1
         AI,SR4   1                 TO NEXT PIECE
         LH,R4    *SR4              IF THERE'S NO REG FIELD
         CI,R4    X'F0'
         BAZ      ADTXT1
         AI,R5    -BA(PBUF)-1       MAKE COUNT
         STB,R5   PBUF
         LI,R5    PBUF
         CAL1,2   PRINT
         B        *SR4
         PAGE
         DO       MODE=1
*                 THIS ROUTINE GETS AND ASSOCIATES A CORE
*                                  LIBRARY IN :SYS ACCOUNT.  THE
*                 LIBRARY NAME IS IN WORD CORELIB.
STCORELIB EQU     %
         LW,SR1   CORELIB
         BLEZ     *R6
         CW,SR1   Y4                HAS A CORE LIBRARY BEEN LOADED
         BANZ     *R6               BRANCH IF YES
         LW,R3    TXC:P0
         AND,SR1  M8
         CI,SR1   'N'
         BNE      %+2               9DBINIT
         AI,R3    1                 9INITIAL
GETCORELIB PSW,R6 *R0               SAVE RETURN
         STW,R3   OPENEF+8          LIBRARY NAME
         LCI      2
         LM,R4    TX:SYS
         STM,R4   OPENEF+12
         LI,D1    1
         LI,D2    3
         STS,D1   OPENEF+1
         LI,SR1   ABNCORE
         CAL1,1   OPENEF
         BAL,SR4  ADTXT             OUTPUT MESSAGE
         DATA     R3                :PN
         DATA     CMESS              ASSOCIATED.
         BAL,SR4  ADLEF             GO DO IT
         LI,R5    M:EF
         CAL1,1   CLOSE
CORELIBX LW,D3    TXLIB             RESTORE LIB NAME IF
         STW,D3   EFNAME            UNSAT,:SYS CALED US
         PLW,R6   *R0
         B        0,R6
         BOUND    8
TX:SYS   TEXT     ':SYS    '
TXC:P0   TEXTC    ':P0'
MN12     DATA     X'FFFFF0FF'
TX:P0    TEXT     ':P0 '
CMESS    TEXTC    ' ASSOCIATED.'
INACM    TEXTC    ' INACCESSIBLE'
ABNCORE  BAL,SR4  ADTXT
         DATA     R3
         DATA     INACM
         LI,R3    0                 CLEAR CORELIB
         STW,R3   CORELIB
         B        CORELIBX
         RES      200
         FIN
         END

