         SYSTEM   SIG6
         SYSTEM   BPM
*
*
*    MODULE    C1
*                                                             *
         DEF      PHASE3
         REF      FIT0,FIT1,FIT2,FIT3,FIT4,FIT5,ILT0,RRN0
         REF      FIT8
         REF      S:IN,INEOF,MTC0,MTC1,MTC2,MTC3,RCDLN,RCDAD
         REF      ILT2,OUTAD,MSRCAD,STCAD,PMSRCD,SRTMIN,C1R,BCT0
         REF      FIT6,COMPR,RDABN,RDERR,WTABN,WTERR
         REF      IN1,CRSF
         REF      EXAMEN
         REF      EXTRD,EXTWT,EXTOP,RSTOR
         REF      ENDSNAP
         SREF     S:INPUT
         REF      STRNGBRK
LEVCNT   DATA     0
CYCLE    DATA     0
TCYCL    DATA     0
         DATA     0
N        DATA     0
OUTDCB   DATA     0
EOC      DATA     0
TCYCT    DATA     0
REMBR    DATA     0
NMIN3    DATA     0
CYC1     DATA     0
RCT1     DATA     0
VGCTR    DATA     0
SREC     DATA     0
TOURN    DATA     0
PSTC     DATA     0
SRTMRG   DATA     0
SIXSV    DATA     0
ONTWSV   DATA     0,0
ONESAVE  DATA     0                 HOLD R 1, USED AS INDEX ELSEWHERE
         PAGE
*
SRT:MOV  RES      0
         STW,1    ONESAVE
         LW,1     CRSF             IS IT CO-RESIDENT
         BNEZ     SRT:CRS          YES.
         LI,1     1                  INDEX USED BY SORT
         BAL,11   S:IN              GET A REC
         LW,1     ONESAVE           RESTORE
SRT:ART  RES      0
         CI,7     0
         BE       SRT:EOF
         LW,14    INEOF
         BG       SRT:A
         B        MOVE
SRT:0    RES      0
         STW,7    RCDAD             SAVE RECORD BYTE ADDRESS
         STW,8    RCDLN             SAVE RECORD BYTE LENGTH
SRT:A    RES      0
         LW,11    TOURN
         BEZ      ISC15
         AND,11   =X'1'
         BEZ      VGN32
         B        VGN35
*
SRT:EOF  RES      0
         MTW,1    INEOF
         B        SRT:A
SRT:CRS  RES      0
         BAL,11   S:INPUT
         LW,1     ONESAVE          RESTORE
         B        SRT:ART          CHECK FOR EOF
*
MOVE     RES      0
         STW,7    10
         LW,11    SIXSV
         STW,8    12
         CI,12    255
         BG       MV2
MV1      RES      0
         STB,12   11
         MBS,10   0
         B        SRT:0
*
MV2      RES      0
         LI,13    255
MV3      RES      0
         STB,13   11
         AI,12    -255
         MBS,10   0
         CI,12    255
         BLE      MV1
         B        MV3
*
PHASE3   RES      0
         LI,11    ENDP2
         STW,11   ENDSNAP           IN CASE OF DUMP
         LW,11    CRSF             IS IT CO-RESIDENT
         BNEZ     PHS310           YES.
         BAL,11   IN1               OPEN INPUT FIRST TIME
PHS310   RES      0
         BAL,15   SELOUT
         BAL,15   RRNILT
         BAL,15   VGEN
PHS320   RES      0
         BAL,15   ISC
         BAL,15   EOS
         LW,15    EOC
         BE       PHS340
         BAL,15   MGCTL
PHS330   RES      0
         LI,15    0
         STW,15   EOC
         STW,15   VGCTR
          STW,15   ILT2
         STW,15   INPCTR
         LW,15    INEOF
         BE       PHS310
         B        PHS330-1
*
PHS340   RES      0
         LW,15    INEOF             IS INPUT AT END OF FILE
         BG       PHS360
PHS350   RES      0
         BAL,15   SELOUT
         BAL,15   RRNILT
         B        PHS320
*
PHS360   RES      0
         LB,15    BCT0+7
         CI,15    3
         BL       PHS350
         B        PHS330-1
         PAGE
*
SELOUR   DATA     0
*
SELOUT   RES      0
         STW,15   SELOUR
         LW,15    N
         BG       SEL10             NOT FIRST TIME THROUGH
         LW,15    FIT5
         STW,15   N
         AI,15    -1
         STW,15   N-1
         STW,15   CYCLE
         STW,15   TCYCL
         STW,15   CYC1
         AI,15    -1
         STW,15   RCT1
         MTW,1    OUTDCB            DCB ORDINAL = 1
         MTW,1    FIT0+8
         B        *SELOUR
*
SEL10    RES      0
         LW,15    LEVCNT
         BG       SEL60             LEVEL 1 ATTAINED
         MTW,1    OUTDCB            WORKING ON LEVEL 1
         LW,6     OUTDCB
         CW,6     N
         BG       SEL30             GO RESET TO 1
SEL20    RES      0
         STW,6    FIT0+8
         MTW,15   TCYCL
         BG       SEL50             NOT END OF 1 STRING DISTRIBUTION
         MTW,15   CYCLE
         BG       SEL40
         LW,15    N-1               LEVEL 1 HAS BEEN ACHIEVED
         STW,15   CYCLE
         STW,15   TCYCL
         MTW,1    LEVCNT
         MTW,1    TCYCL
         B        SEL60
*
SEL30    RES      0
         LI,6     1
         STW,6    OUTDCB
         B        SEL20
*
SEL40    RES      0
         LW,15    N-1
         STW,15   TCYCL             RESET TCYCL
         B        *SELOUR
*
SEL50    RES      0
         LW,15    TCYCL
         CI,15    1
         BG       *SELOUR
         STW,15   EOC               FORCE TOURNAMENT FLUSH
         B        *SELOUR
*
SEL60    RES      0                 LEVEL 1 OR GREATER
         LW,15    TCYCT             HAS FIRST DISTRIBUTION BEEN DONE
         BG       SEL90             YES
         LW,6     OUTDCB
         STW,6    FIT0+8
         MTW,15   OUTDCB
         BG       SEL70
         LW,15    N
         STW,15   OUTDCB
SEL70    RES      0
         MTW,15   TCYCL
         BG       SEL80
         LI,15    1
         STW,15   TCYCT
         LW,15    N-1
         STW,15   TCYCL
         AI,15    -2
         STW,15   NMIN3
         LW,15    OUTDCB
         AI,15    1
         CW,15    N
         BG       SEL107
SEL103   RES      0
         STW,15   REMBR
         B        *SELOUR
*
SEL107   RES      0
         LI,15    1
         B        SEL103
*
SEL80    RES      0
         LW,15    TCYCL
         CI,15    1
         BG       *SELOUR
         STW,15   EOC
         B        *SELOUR
*
SEL90    RES      0
         LW,15    LEVCNT
         CI,15    2
         BE       SEL130
         LW,6     OUTDCB
         STW,6    FIT0+8
         MTW,15   OUTDCB
         BG       SEL100
         LW,15    N
         STW,15   OUTDCB
SEL100   RES      0
         MTW,15   TCYCL
         BG       SEL80
         LW,15    N-1
         STW,15   TCYCL
         MTW,15   NMIN3
         BG       *SELOUR
         LW,6     REMBR
         STW,6    FIT0+8
         AI,6     -1
         BG       SEL110
         LW,6     N
SEL110   RES      0
         STW,6    OUTDCB
         LW,15    N
         AI,15    -2
         STW,15   NMIN3
         LW,15    FIT0+8
         AI,15    1
         CW,15    N
         BLE      SEL120
         LI,15    1
SEL120   RES      0
         STW,15   REMBR
         B        *SELOUR
*
SEL130   RES      0
         LW,15    TCYCT
         CI,15    2
         BE       SEL140
         MTW,1    TCYCT
         LW,15    N-1
         STW,15   TCYCL
         AI,15    -1
         STW,15   NMIN3
         LW,15    OUTDCB
         STW,15   REMBR
         STW,15   OUTDCB
         AI,15    -1
         BG       %+2
         LW,15    N
         STW,15   FIT0+8
         B        *SELOUR
*
SEL140   RES      0
         LW,15    OUTDCB
         STW,15   FIT0+8
         AI,15    1
         CW,15    N
         BLE      %+2
         LI,15    1
         STW,15   OUTDCB
         MTW,15   TCYCL
         BG       SEL80
         LW,15    N-1
         STW,15   TCYCL
         LW,15    OUTDCB
         AI,15    2
         CW,15    N
         BLE      %+2
         SW,15    N
         STW,15   OUTDCB
         AI,15    -1
         BG       %+2
         LW,15    N
         STW,15   FIT0+8
         MTW,15   NMIN3
         BG       *SELOUR
         LW,15    REMBR
         STW,15   FIT0+8
         AI,15    1
         CW,15    N
         BLE      %+2
         LI,15    1
         STW,15   OUTDCB
         STW,15   REMBR
         LW,15    N-1
         AI,15    -1
         STW,15   NMIN3
         B        *SELOUR
*
VGENR    DATA     0
*
VGEN     RES      0
         STW,15   VGENR
         LW,15    BCT0+9
         AI,15    3
         SAS,15   -2
         STW,15   SREC              RCD LENGTH IN WORDS
         LW,15    PMSRCD
         STW,15   MSRCAD
         LW,15    BCT0+5
         STW,15   TOURN
         LW,15    STCAD
         STW,15   PSTC
         LW,6     FIT5
         LI,15    0
         STW,15   CHTBL,6
         BDR,6    %-1
*
VGN20    RES      0
         LI,1     0                 STT0 INDEX
VGN30    RES      0
         LCI      2
         STM,1    ONTWSV
         LW,7     MSRCAD            RECORD BASE ADDRESS
         SAS,7    2                     AS BYTE ADDRESS
         AI,7     8                 SKIP RECORD CONTROL WORDS
         STW,7    SIXSV             SAVE FOR MOVE ROUTINE
         B        SRT:MOV           GO GET RECORD
VGN32    RES      0
         LCI      2
         LM,1     ONTWSV
         MTW,1    BCT0+1            COUNT INPUT RECORD
         MTW,1    VGCTR
         LW,15    INEOF
         BG       VGEOFO
         BAL,15   RCDMVI            GO MOVE RECORD TO MASS STORAGE
         LW,15    MSRCAD
         STW,15   *STCAD,1          STORE IN STT0
         AW,15    SREC              UPDATE MEMORY ADDRESS FOR
         STW,15   MSRCAD                NEXT RECORD
         MTW,15   TOURN             COUNT DOWN FOR TOURNAMENT
         BEZ      VGEOFO
         LCI      2
         STM,1    ONTWSV
         LW,7     MSRCAD            RECORD BASE ADDRESS
         SAS,7    2                     AS BYTE ADDRESS
         AI,7     8                 SKIP RECORD CONTROL WORD
         STW,7    SIXSV             SAVE FOR MOVE ROUTINE
         B        SRT:MOV           GO GET RECORD
VGN35    RES      0
         LCI      2
         LM,1     ONTWSV
         MTW,1    VGCTR
         MTW,1    BCT0+1            COUNT RECORD JUST READ
         LW,15    INEOF             IS END OF FILE
         BG       VGEOF1
         BAL,15   RCDMVI            MOVE RECORD TO MASS STORAGE
         STW,1    7
         AI,7     1
         LW,15    MSRCAD
         STW,15   *STCAD,7
         AW,15    SREC              UPDATE FOR NEXT RECORD
         STW,15   MSRCAD
         LW,4     *STCAD,1
         LW,5     *STCAD,7
         BAL,9    COMPR             GO COMPARE RECORDS
         STW,1    7
         BGE      VGN40             NO EXCHANGE NECESSARY
         AI,7     1
         LW,14    *STCAD,1
         LW,15    *STCAD,7          EXCHANGE WINNER AND LOSER ADDRESSES
         XW,14    15
         STW,14   *STCAD,1
         STW,15   *STCAD,7
         AI,7     1
         B        VGN40+1
VGN40    RES      0
         AI,7     2
         STW,1    2
         STH,1    2
         STW,2    *STCAD,7
         AI,1     3
         MTW,15   TOURN             COUNT DOWN TOURNAMENT
         BEZ      VGN50             TOURNAMENT IS FULL
         B        VGN30             GO GET NEXT PAIR OF RECORDS
*
VGN50    RES      0
         LI,2     0
VGN60    RES      0
         STW,1    7
         LW,5     *STCAD,2
         STW,5    *STCAD,1
         AI,2     3
         LW,6     *STCAD,2
         AI,7     1
         STW,6    *STCAD,7
         AI,7     1
         AI,2     -1
         LW,15    *STCAD,2          FEO
         AND,15   =X'3FFF0000'
         AI,2     3
         LW,14    *STCAD,2
         AND,14   =X'3FFF0000'
         SCS,14   16
         OR,15    14
         STW,15   *STCAD,7
         AI,2     -2
         STW,1    *STCAD,2          STORE NEO
         AI,2     -3
         STW,1    *STCAD,2          STORE NEO
         AI,2     2
         LW,15    *STCAD,2
         AND,15   =X'C000FFFF'
         STW,15   *STCAD,2
         AI,2     3
         LW,15    *STCAD,2
         AND,15   =X'C000FFFF'
         STW,15   *STCAD,2
         AI,2     1
         STW,5    4
         STW,6    5
         BAL,9    COMPR             GO COMPARE RECORDS
         STW,1    7
         BGE      VGN70             NO EXCHANGE
         AI,7     1
         LW,14    *STCAD,1
         LW,15    *STCAD,7
         XW,14    15
         STW,14   *STCAD,1
         STW,15   *STCAD,7
         AI,7     1
         LW,15    *STCAD,7
         SCS,15   16
         STW,15   *STCAD,7
VGN70    RES      0
         CW,2     1
         BGE      VGN80
         AI,1     3
         B        VGN60
*
VGN80    RES      0
         LW,15    *STCAD,1
         STW,15   BCT0+6
         LI,2     0
         STW,2    *STCAD,1
         AI,1     2
         LW,15    *STCAD,1
         AND,15   =X'FFFF0000'
         SCS,15   16
         STW,15   BCT0+7
         LW,15    *STCAD,1
         AND,15   =X'FFFF'
         STW,15   *STCAD,1
         B        *VGENR
VGEOFO   RES      0
         STW,15   INEOF
         LW,10    VGCTR
         CI,10    2
         BL       *VGENR            ZERO RECORDS
         CI,10    4
         BL       VG010
         LI,2     0
         B        VGN50
*
VG010    RES      0
         LI,1     0
         LI,2     0
         B        VGN80
*
VGEOF1   RES      0
         STW,15   INEOF
         LW,10    VGCTR
         CI,10    2
         BLE      VGE2              ONLY ONE RECORD
         LW,14    *PSTC,1
         STW,1    2
         STH,1    2
         AI,1     1
         STW,14   *PSTC,1
         AI,1     1
         LW,14    *PSTC,1
         OR,2     =X'C0000000'
         STW,2    *PSTC,1
         AI,1     1
         B        VGN50
*
VGE2     RES      0
         LW,14    *PSTC
         STW,14   BCT0+6
         AI,1     1
         STW,14   *PSTC,1
         LI,14    0
         STW,14   *PSTC
         OR,14    =X'C0000000'
         AI,1     1
         STW,14   *PSTC,1
         B        *VGENR
RCDMV    RES      0
         LW,11    BCT0+6
         LW,10    RCDLN
         STW,10   9
         AI,10    11
         AND,10   =X'FFFFFFFC'
         STW,10   *BCT0+6
         STH,9    *BCT0+6
         AI,11    1
         LW,10    BCT0+1
         STW,10   *11
         AI,11    1
         B        *15
*
RCDMVI   RES      0
         LW,10    RCDLN
         STW,10   11
         AI,10    11
         AND,10   =X'FFFFFFFC'
         STW,10   *MSRCAD
         STH,11   *MSRCAD
         LW,11    MSRCAD
         AI,11    1
         LW,10    BCT0+1
         STW,10   *11
         B        *15
*
ISCR     DATA     0
ISC99    DATA     0                 LOOP VALUE, #REC REFILLED IN TOURN
*
ISC      RES      0
         STW,15   ISCR
         LW,15    VGCTR
         CI,15    1
         BE       ISC110
         CI,15    2
         BE       ISC100            ONE RECORD INTO SORT
*
ISC10    RES      0
         BAL,15   WTSTI
         LW,15    INEOF             IS INPUT AT END OF FILE
         BG       ISC60
         LW,15    EOC
         BG       ISC60             MUST FLUSH TOURNAMENT
         STW,1    ONTWSV
         LW,7     BCT0+6            RECORD BASE ADDRESS
         SAS,7    2                     AS BYTE ADDRESS
         AI,7     8                 SKIP RECORD CONTROL WORD
         STW,7    SIXSV             SAVE FOR MOVE ROUTINE
         B        SRT:MOV           GO GET REPLACEMENT RECORD
ISC15    RES      0
         LW,1     ONTWSV
         MTW,1    BCT0+1
         LW,15    INEOF
         BG       ISC60
         BAL,15   RCDMV
* A STRING BREAK WILL BE FORCED WHEN THE ORIGINAL TOURN AND 4X TOURN REFILLS
*  (5X TOTAL) IS REACHED ON DCB1 OR ANY SUCCEEDING DCBS (DCB1 IS 1ST)
*  STARTING WITH BASE LEVEL 1. IF NO NORMAL BREAK OCCURS (USUALLY AT 2X)
* A FORCE WILL OCCUR.
         LW,15    ISC99             LOOP COUNT
         CW,15    STRNGBRK          HAVE WE GONE 4X TOURN
         BLE      ISC16             NO
         B        ISC20-1           YES SET END TOURN FLAG
ISC16    RES      0
         MTW,1    ISC99             UP LOOP COUNT
         LW,4     OUTAD
         LW,5     BCT0+6
         BAL,9    COMPR             GO COMPARE RECORDS
         BGE      ISC30             RECORD IS IN THIS STRING
         LW,15    =X'80000000'      NO:  SET NEXT STRING INDICATOR
ISC20    RES      0
         OR,15    BCT0+7
         STW,15   BCT0+7
ISC30    RES      0
         LW,1     BCT0+7
         AI,1     2
         LW,14    *PSTC,1           LI FEO
         LW,15    =X'C0000000'      ARE BOTH RECORDS ON SAME LEVEL
         AI,1     -2
         CS,14    BCT0+7
         BE       ISC70             YES GO COMPARE
         BG       ISC50             MANDATORY ACCEPT
ISC40    RES      0
         AI,1     1
         LCI      2                 EXCHANGE ENTRIES
         LM,10    BCT0+6
         LM,12    *PSTC,1
         STM,10   *PSTC,1
         STM,12   BCT0+6
         AI,1     -1
ISC50    RES      0
         LW,1     *PSTC,1
         BEZ      ISC80             RECORD IS SELECTED
         B        ISC30+1
*
ISC60    RES      0
         LW,15    =X'C0000000'
         OR,15    BCT0+7            SET EMPTY INDICATOR
         STW,15   BCT0+7
         B        ISC30
ISC70    RES      0
         LW,4     BCT0+6
         AI,1     1
         LW,5     *PSTC,1
         AI,1     -1
         BAL,9    COMPR             GO COMPARE RECORDS
         BL       ISC40             MUST EXCHANGE
         B        ISC50             NO EXCHANGE
ISC80    RES      0
         LW,15    BCT0+7
         BL       *ISCR
         B        ISC10
*
ISC100   RES      0
         BAL,15   WTSTI
*
ISC110   RES      0
         LW,15    =X'C0000000'
         STW,15   BCT0+7
         B        *ISCR             GET OUT
*
*
*
*
EOSR     DATA     0
*
EOS      RES      0
         STW,15   EOSR
         LI,15    0
         STW,15   ISC99              CLEAR LOOP COUNT
         BAL,15   CLSTI
         LW,3     BCT0+5
         LI,4     2
         LW,15    =X'3FFFFFFF'
         LW,13    =X'C0000000'
         LW,14    =X'C0000000'
EOS10    RES      0
         LW,12    *PSTC,4
         CS,12    14
         BE       EOS20
         AND,12   15
         STW,12   *PSTC,4
EOS20    RES      0
         AI,4     3
         BDR,3    EOS10
         LW,12    BCT0+7
         CS,12    14
         BE       EOS40
         AND,12   15                CHECK CURRENT SELECTEE
         STW,12   BCT0+7
EOS40    RES      0
         B        *EOSR
MGCTLR   DATA     0
*
MGCTL    RES      0
         STW,15   MGCTLR
         BAL,15   MFPTST            GO SEE IF READY FOR FINAL MERGE
         BAL,15   SELNOT            SETUP INPUT AND OUTPUT DCB
         B        MGC10
         B        *MGCTLR           NO MERGE POSSIBLE
*
MGC10    RES      0
         BAL,15   OPIST
         BAL,15   OPOST
         BAL,15   MVGN              GO SETUP MTC TABLE
         BAL,15   MRGST             GO MERGE STRINGS
         BAL,15   CLOST             GO CLOSE OUTPUT STRING
         BAL,15   CLIST             GO CLOSE ALL INPUT STRINGS
         B        MGCTL+1
*
RRNILT   RES      0
         LW,6     FIT0+8
         LW,14    ILT0,6
         MTW,1    *14               COUNT ENTRY ABOUT TO BE MADE
         LW,5     *14
         MTW,1    *14,5
         LW,14    RRN0,6
         MTW,1    *14
         LW,5     *14
         LW,13    FIT4,6
         STW,13   *14,5
         LW,14    FIT5,6
         STW,14   FIT0+1
         LI,14    4
         STW,14   FIT0+4
         B        *15
*
*
SELNOTR  DATA     0
*
SELNOT   RES      0
         STW,15   SELNOTR
         LI,10    0                 STRING LENGTH
         STW,10   INPCTR            INITIALIZE ZERO CRITICAL COUNTERS
         STW,10   ILT2                  AND PARAMETERS
         STW,10   FIT0+8
         LW,3     FIT5              NUMBER OF DCB'S
         LW,15    ILT0,3            ADDRESS OF ILT1
         LW,4     *15
         BG       SELN10
         AI,3     -1
         BEZ      SELN70            NO ENTRIES MERGE IMPOSSIBLE
         B        SELNOT+6
*
SELN10   RES      0
         LW,10    *15,4             FIRST STRING LENGTH
         AI,3     -1
         BEZ      SELN30            ALL STRINGS EXAMINED
SELN20   RES      0
         LW,15    ILT0,3
         LW,4     *15
         BEZ      SELN10+1
         LW,11    *15,4
         BEZ      SELN10+1
         CW,10    11
         BL       SELN10+1
         STW,11   10
         B        SELN10+1
*
SELN30   RES      0                 10 CONTAINS STRING LENGTH
         LW,3     FIT5              NUMBER OF DCB'S
         LW,15    ILT0,3
         LW,4     *15
         CW,10    *15,4
         BE       SELN50
SELN40   RES      0
         AI,3     -1
         BEZ      SELN60            DONE WITH COUNT
         B        SELN30+1
*
SELN50   RES      0
         MTW,1    INPCTR            COUNT EQUAL STRINGS
         B        SELN40
*
SELN60   RES      0
         LW,15    INPCTR
         CW,15    N-1
         BE       SELN130
         LW,15    INEOF
         BG       SELN72
SELN70   RES      0
         MTW,1    SELNOTR           MERGE IMPOSSIBLE
         B        *SELNOTR
*
SELN72   RES      0
         LW,3     FIT5
         LW,15    ILT0,3
         LW,5     *15
         CI,5     2
         BG       SELN80
         BDR,3    SELN72+1
         LW,3     FIT5
SELN74   RES      0
         LW,15    ILT0,3
         LW,14    *15
         BEZ      SELN75
         BDR,3    SELN74
         B        SELN80
*
SELN75   RES      0
         LW,3     FIT5
         LW,15    ILT0,3
         LW,14    *15
         BG       %+2
         STW,3    FIT0+8
         CI,14    2
         BNE      SELN76
         MTW,1    ILT2
         LW,5     ILT2
         STW,3    ILT2,5
SELN76   RES      0
         BDR,3    SELN75+1
         B        *SELNOTR
*
SELN80   RES      0                 END OF FILE
         STW,10   11
         LW,3     FIT5
         LW,15    ILT0,3
         LW,4     *15
         LW,14    *15,4
         CW,11    14
         BGE      %+2
         STW,14   11
         BDR,3    SELN80+2
         CW,10    11
         BNE      SELN84            FOUND ONE
         LW,3     FIT5
         LI,12    8
SELN82   RES      0
         LW,15    ILT0,3
         CW,12    *15
         BLE      %+2
         LW,12    *15
         BDR,3    SELN82
         LW,3     FIT5
SELN83   RES      0
         LW,15    ILT0,3
         CW,12    *15
         BNE      %+3
         STW,3    FIT0+8
         B        SELN90
         BDR,3    SELN83
         B        SELN90
*
SELN84   RES      0
         LI,12    8
         LW,3     FIT5
SELN85   RES      0
         LW,15    ILT0,3
         LW,4     *15
         LW,14    *15,4
         CW,11    14
         BNE      SELN86
         CW,12    4
         BLE      SELN86
         STW,4    12
SELN86   RES      0
         BDR,3    SELN85
         LW,3     FIT5
SELN87   RES      0
         LW,15    ILT0,3
         LW,4     *15
         CW,11    *15,4
         BNE      SELN88
         CW,12    4
         BNE      SELN88
         STW,3    FIT0+8
         B        SELN90
SELN88   RES      0
         BDR,3    SELN87
SELN90   RES      0
         LW,3     FIT5              NUMBER OF DCB'S
SELN100  RES      0
         LW,15    ILT0,3
         LW,4     *15
         CW,10    *15,4
         BE       %+2
         B        SELN120
         CW,3     FIT0+8
         BE       SELN110
         MTW,1    ILT2
         LW,5     ILT2
         STW,3    ILT2,5            SET INPUT DCB ORDINAL
SELN110  RES      0
         AI,3     -1
         BEZ      *SELNOTR          EXIT
         B        SELN100
*
SELN120  RES      0
         LW,11    FIT0+8
         BG       SELN110           OUTPUT DCB ALREADY SELECTED
         STW,3    FIT0+8            SET OUTPUT DCB
         B        SELN110
*
SELN130  RES      0
         CI,10    1
         BE       SELN90
         LW,15    INEOF
         BG       SELN72
         LW,3     FIT5
         LI,9     0
         LI,14    1
SELN140  RES      0
         LW,15    ILT0,3
         CW,14    *15
         BNE      %+2
         MTW,1    9
         BDR,3    SELN140
         CW,9     N-1
         BE       SELN160
SELN150  RES      0
         MTW,15   RCT1
         BG       SELN70
         MTW,1    RCT1
         MTW,15   CYC1
         BG       SELN90
         LW,15    N-1
         STW,15   CYC1
         B        SELN90
SELN160  RES      0
         LW,15    LEVCNT
         BE       SELN70
         MTW,1    LEVCNT
         B        SELN70
*
MVGNR    DATA     0
*
MVGN     RES      0
         STW,15   MVGNR
         LW,6     FIT5
         LI,15    0
         STW,15   CHTBL,6
         BDR,6    %-1
MVG05    RES      0
         LW,2     ILT2
         LW,6     ILT2,2
         STW,6    BCT0+8
         LW,15    FIT6,6
         BEZ      %+2
         BAL,15   PRDR
         BDR,2    MVG05+1
         LI,1     0
         LW,2     ILT2              NUMBER OF STRINGS
MVG10    RES      0
         LW,6     ILT2,2
         STW,6    MTC0,1
         STW,6    BCT0+8
         BAL,15   PRDR
         BAL,15   RDST              MTC0=FIT ORDINAL     WINNER/LOSER
         LW,15    RCDAD             MTC2=FEO AND LI      WINNER/LOSER
         STW,15   MTC1,1            MTC3=WINNER ADDRESS THEN NEO
         STW,1    MTC2,1
         BDR,2    MVG40
         B        MVOT1             ODD NUMBER OF STRINGS
*
MVG40    RES      0
         LW,6     ILT2,2
         STW,6    BCT0+8
         BAL,15   PRDR
         BAL,15   RDST
         SAS,6    16
         AWM,6    MTC0,1
         SAS,6    -16
         LW,5     RCDAD
         STW,5    MTC3,1
         STW,5    4
         LW,5     MTC1,1
         STW,1    14
         SAS,14   16
         AWM,14   MTC2,1
         BAL,9    COMPR             GO COMPARE RECORDS
         BGE      MVG60             NO EXCHANGE
*
         LW,15    MTC0,1            FIT ORDINALS
         SCS,15   16
         STW,15   MTC0,1
         LW,15    MTC3,1
         XW,15    MTC1,1
         STW,15   MTC3,1
         LW,15    MTC2,1
         SCS,15   16
         STW,15   MTC2,1
MVG60    RES      0
         AI,1     1
         BDR,2    MVG10
         LI,2     0
         CI,1     3
         BL       MVOT21            TWO STRINGS OR NONE
MVOT10   RES      0
         LW,15    MTC0,2
         AND,15   =X'FFFF0000'
         STW,15   MTC0,1
         LW,15    MTC0+1,2
         AND,15   =X'FFFF0000'
         SCS,15   16
         AWM,15   MTC0,1
         LW,15    MTC0,2
         AND,15   =X'FFFF'
         STW,15   MTC0,2
         LW,15    MTC0+1,2
         AND,15   =X'FFFF'
         STW,15   MTC0+1,2
         LW,5     MTC3,2
         STW,5    MTC3,1
         LW,6     MTC3+1,2
         STW,6    MTC1,1
         STW,1    MTC3,2
         STW,1    MTC3+1,2
         LW,15    MTC2,2
         AND,15   =X'3FFF0000'
         STW,15   MTC2,1
         LW,15    MTC2+1,2
         AND,15   =X'3FFF0000'
         SCS,15   16
         AWM,15   MTC2,1
         LW,15    MTC2,2
         AND,15   =X'C000FFFF'
         STW,15   MTC2,2
         LW,15    MTC2+1,2
         AND,15   =X'C000FFFF'
         STW,15   MTC2+1,2
         STW,5    4
         STW,6    5
         BAL,9    COMPR             GO COMPARE RECORDS
         BGE      MVOT20            NO EXCHANGE
         LW,15    MTC0,1
         SCS,15   16
         STW,15   MTC0,1
         LW,15    MTC1,1
         XW,15    MTC3,1
         STW,15   MTC1,1
         LW,15    MTC2,1
         SCS,15   16
         STW,15   MTC2,1
MVOT20   RES      0
         AI,2     2
         CW,2     1
         BE       MVOT30            DONE
         AI,1     1
         B        MVOT10
*
MVOT30   RES      0
         LW,15    MTC3,1
         STW,15   BCT0+6
         LI,15    0
         STW,15   MTC3,1
         LW,15    MTC2,1
         AND,15   =X'3FFF0000'
         SCS,15   16
         STW,15   BCT0+7
         LW,15    MTC2,1
         AND,15   =X'C000FFFF'
         STW,15   MTC2,1
         LW,15    MTC0,1
         AND,15   =X'FFFF0000'
         SCS,15   16
         STW,15   BCT0+8
         LW,15    MTC0,1
         AND,15   =X'FFFF'
         STW,15   MTC0,1
         B        *MVGNR            EXIT
*
MVOT1    RES      0
         LW,15    ILT2
         CI,15    1
         BE       MVOT11
         LW,15    MTC2,1
         STH,15   15
         OR,15    =X'C0000000'
         STW,15   MTC2,1
         LW,15    MTC1,1
         STW,15   MTC3,1
         LW,15    MTC0,1
         STH,15   15
         STW,15   MTC0,1
         AI,1     1
         LI,2     0
         B        MVOT10
*
MVOT11   RES      0
         LW,15    MTC0,1
         AND,15   =X'FFFF'
         STW,15   BCT0+8
         LW,15    MTC2,1
         AND,15   =X'FFFF'
         STW,15   BCT0+7
         OR,15    =X'C0000000'
         STW,15   MTC2,1
         LW,15    MTC1,1
         STW,15   BCT0+6
         LI,15    0
         STW,15   MTC3,1
         B        *MVGNR            EXIT
*
MVOT21   RES      0
         LW,15    VGCTR
         CI,15    2
         BL       *MVGNR            EXIT
         LI,2     0
         LW,15    ILT2
         CI,15    2
         BG       MVOT10
         LI,1     0
         B        MVOT30
*
MRGSTR   DATA     0
*
MRGST    RES      0
         STW,15   MRGSTR
MRGS10   RES      0
         BAL,15   WTST          GO WRITE SELECTEE
         BAL,15   RDST
         LW,15    BCT0+7
         BL       MRGS60
         LB,15    BCT0+7
         LI,1     X'FFFF'
         AND,1    BCT0+7            FEO
         LW,14    MTC2,1
         SCS,14   8
         AND,14   =X'FF'
MRGS20   RES      0
         CW,15    14
         BL       MRGS30            MANDATORY ACCEPT
         BG       MRGS40            MANDATORY EXCHANGE
         LW,4     BCT0+6
         LW,5     MTC1,1
         BAL,9    COMPR
         BL       MRGS40            GO EXCHANGE
*
MRGS30   RES      0                 NO EXCHANGE
         LW,1     MTC3,1            NEO
         BEZ      MRGS50            A RECORD HAS BEEN SELECTED
         LB,15    BCT0+7
         LW,14    MTC2,1
        SCS,14   8
        AND,14   =X'FF'
         B        MRGS20
*
MRGS40   RES      0
         LW,15    BCT0+8            FIT ORDINAL AND LI
         XW,15    MTC0,1
         STW,15   BCT0+8
         LW,15    BCT0+6
         XW,15    MTC1,1            ADDRESS
         STW,15   BCT0+6
         LW,15    BCT0+7
         XW,15    MTC2,1            FEO
         STW,15   BCT0+7
         B        MRGS30
*
MRGS50   RES      0
         LW,15    BCT0+7
         BL       *MRGSTR           END OF ALL STRINGS
         B        MRGS10
*
MRGS60   RES      0
         LI,1     X'FFFF'
         AND,1    BCT0+7
         LB,15    BCT0+7
         LW,14    MTC2,1
         SCS,14   8
         AND,14   =X'FF'
         B        MRGS20
CHTBL    RES      0
         DATA     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
*
INPCTR   DATA     0
RDSTR    DATA     0
*
RDST     RES      0
         STW,15   RDSTR
         LW,6     BCT0+8             ILT FIT ORDINAL
         MTB,0    ENDSTRNG,6           ARE WE AT END OF STRING
         BNEZ     RD20               YES
         LW,15    FIT3,6            CURRENT BYTE OFFSET
         LW,14    FIT1,6
         CW,15    *14
         BL       RD10              NO:  BYPASS PHYSICAL READ
*
         BAL,15   PRDR
RD10     RES      0
*
         SAS,15   -2
         AW,15    FIT1,6
         STW,15   RCDAD
         STW,15   BCT0+6
         LW,15    *RCDAD
         AND,15   =X'FFFF'
         STW,15   RCDLN
         AWM,15   FIT3,6
         LW,15    RCDAD             GOOD REC ADDR
         LW,7     RCDLN             GOOD REC LEN
         AND,7    =X'FFFF'          MASK OUT LEFT HALF
         SLS,7    -2                LENGTH (RIGHT) ALWAYS WORD MULTPLE
         AW,15    7                 POINT TO BEGIN OF NEXT REC
         LW,7     *15               GET REC LEN OF NEXT REC
         CI,7     X'10'             END REC HAS LENGTH X'10'
         BNE      *RDSTR
         AI,15    2
         LW,7     *15
         CW,7     =C'SORT'
         BNE      *RDSTR
         AI,15    1
         LW,7     *15
         CW,7     =C' END'
         BNE      *RDSTR
         LI,15    X'10'
         AWM,15   FIT3,6            UPDATE CNT TO SHOW END OF BLK
         LI,15    1
         STB,15   ENDSTRNG,6         SET END STRNG FLAG FOR DCB
         B        *RDSTR
RD20     RES      0
         LI,15    0
         STB,15   ENDSTRNG,6        SET OFF FLAG
         LW,15    =X'C0000000'
         OR,15    BCT0+7
         STW,15   BCT0+7            SET FLAG 'C0'
         B        *RDSTR
*
PRDRR    DATA     0
*
PRDR     RES      0
         STW,15   PRDRR
         LW,15    FIT5,6
         STW,15   INDCB
         LW,15    FIT4,6            AMT USED SO FAR
         LH,10    RSTOR,6           AMT ORIG REQ
         AND,10   =X'FFFF'           MASK SIGN EXTENT
PRDR01   RES      0
         SW,15    10
         BGEZ     PRDR011
         LW,15    FIT4,6            USE ORIG VAL ,NO EXTENTS YET
         B        PRDR013
PRDR011  RES      0
         CW,15    10                ARE WE IN RANGE
         BL       PRDR013
         SW,15    10                TRY AGAIN
         B        PRDR011
PRDR013  RES      0
         STW,15   IADR              GRAN POS FOR IO
         LW,15    FIT1,6
         STW,15   INBUF
         LW,15    FIT2,6
         STW,15   INLENGTH
         LW,15    FIT6,6
         BEZ      %+2
         B        PRD10
         M:READ   *INDCB,(BUF,*INBUF),(SIZE,*INLENGTH),(BTD,0),;
                  (BLOCK,*IADR),(ABN,RDABN),(ERR,RDERR)
         MTB,1    ENDTABLE        SET FLAG ON SINGLE BUF
         B        PRD40
*
PRD10    RES      0
         LW,10    CHTBL,6
         BG       PRD101
         STW,6    CHTBL,6
         B        PRD30
PRD101   LW,10    INDCB             DCB WORD ADDR
         LI,8     PRD201+1          RETURN ADDR
         BAL,9    EXAMEN             SEE IF ERR OR ABN IN DCB FOR THIS
         AI,10    7                 SET ADDR TO DCB WORD 7
         MTB,0    *10               GET BITS 00-07 WORD 7
         BNE      PRD201            NO, SO DO CHECK
         AI,10    -5                SET DCB ADDR TO WORD 2
         LH,9     *10               WANT BITS 8-14 WORD 2 (TYC)
         AND,9    =X'00FE'          MASK ALL BUT TYC
         CI,9     2                 00-02 NORMAL  TYC
         BLE      %+2
PRD201   M:CHECK  *INDCB,(ABN,RDABN),(ERR,RDERR)
         LW,14    *15
* THIS AREA LOOKS AT END OF BUF TO SEE IF END REC, IF NOT ALTERNATE BUF
         SAS,14   -2
         AW,15    14
         AI,15    -4                BACK TO PREV REC
         LW,14    *15
         CI,14    X'10'             IS IT A SORT END REC
         BNE      PRD30
         AI,15    2                 EXAMINE A LITTLE FURTHER
         LW,14    *15
         CW,14    =C'SORT'
         BNE      PRD30
         AI,15    1
         LW,14    *15
         CW,14    =C' END'
         BNE      PRD30
         B        PRD35
PRD30    RES      0
         M:READ   *INDCB,(BUF,*INBUF),(SIZE,*INLENGTH),(BTD,0),;
                  (BLOCK,*IADR)
PRD35    RES      0
         LW,15    FIT6,6
         XW,15    FIT1,6
         STW,15   FIT6,6
PRD40    RES      0
         LW,15    IADR              CURR GRAN COUNT
         AH,15    BCT0+29           ADD NEXT IO SIZE
         AND,15   =X'7FFFFFFF'       MASK SIGN EXT IF ANY
         LH,9     RSTOR,6           AMT RESERVED BY USER
         AND,9    =X'FFFF'           MASK SIGN EXTENSION
         CW,15    9                 ARE WE UNDER MULTIPLE OF GRAN
         BL       %+2
         BAL,15   EXTRD             NO SO EXTEND
         LW,15    FIT4,6            AMT USED SO FAR
         AH,15    BCT0+29           ADD IO INCREMENT
         STW,15   FIT4,6            NEW TOTAL FOR NEXT IO
* TO KEEP SORT/END REC OUT OF RCDAD, WHEN IT IS ONLY REC IN BLOCK
         MTB,0    ENDTABLE          IS THIS A SINGLE BUFF OPR
         BEZ      PRD41             YES
         LI,15    0                 SET FLAG OFF
         STB,15   ENDTABLE
         B        PRD42
PRD41    RES      0
         LB,15    ENDTABLE,6        SEE IF FIRST TIME DBL BUFF
         BEZ      PRD45             YES
PRD42    RES      0
         LW,15    FIT1,6             IO BUF ADDR
         AI,15    1                 PAST BLK CTL WORD
         STW,15   7                 BEGIN OF FIRST DATA REC
         LW,15    *7                SEE REC CTL WORD
         CI,15    X'10'
         BNE      PRD50             NOT A SORT END REC
         MTW,2    7
         LW,15    *7                SEE FIRST WORD OF REC ITSELF
         CW,15    =C'SORT'
         BNE      PRD50
         MTW,1    7                 SEE SECOND WORD OF REC
         LW,15    *7
         CW,15    =C' END'
         BNE      PRD50
         B        RD20              END STRING ONLY REC IN BUF
PRD45    RES      0
         STB,6    ENDTABLE,6        SET TO NON ZERO
PRD50    RES      0
         LI,15    4
         STW,15   FIT3,6
         B        *PRDRR
INDCB    DATA     0
INBUF    DATA     0
IADR     DATA     0
INLENGTH DATA     0
*
WTSTIR   DATA     0
WTSTI    RES      0
         STW,15   WTSTIR
         LW,12    BCT0+6
         LW,14    *12               RCD LENGTH
         AND,14   =X'FFFF'
         AW,14    FIT0+4
         CW,14    FIT0+5
         BL       WTI10
         LW,6     FIT0+8
         BAL,15   PWTRI
         LW,15    FIT0+4
         SAS,15   -2
         AW,15    FIT0+2
         STW,15   OUTAD
WTI10    RES      0
         LW,14    *BCT0+6
         AND,14   =X'FFFF'
         CI,14    255
         BG       WTI30
WTI20    RES      0
         LW,13    FIT0+2
         SAD,12   2
         AW,13    FIT0+4
         STB,14   13
         MBS,12   0
         LW,15    FIT0+4
         SAS,15   -2
         AW,15    FIT0+2
         STW,15   OUTAD
         AWM,14   FIT0+4
         B        *WTSTIR
*
WTI30    RES      0
        LW,15     FIT0+4
         SAS,15   -2
         AW,15    FIT0+2
         STW,15   OUTAD
         LW,13    FIT0+2
         SAD,12   2
         AW,13    FIT0+4            SIDR NR. 7
         AWM,14   FIT0+4
         LI,15    255
WTI40    RES      0
         STB,15   13
         AI,14    -255
         MBS,12   0
         CI,14    255
         BG       WTI40
         STB,14   13
         MBS,12   0
         B        *WTSTIR
PWTRIR   DATA     0
*
PWTRI    RES      0
         STW,15   PWTRIR
         LW,15    FIT0+4
         AI,15    16                SORT END LENGTH
         CW,15    FIT0+5
         BG       PWTRI00                NOT ENOUGH ROOM
         SLS,15   -2                TO WORDS
         AW,15    FIT0+2             BUF BASE ADDR
         LI,6     4                 ZERO OUT NEXT 4 WORDS
         LI,14    0
PWTRI0   RES      0
         AI,15    -1                 TO NEXT WORD
         STW,14   *15               ZERO OUT WORD
         BDR,6    PWTRI0            DO NEXT
PWTRI00  RES      0
         LW,6     FIT0+8            REST INDEX REG
         LW,15    FIT0+2
         STW,15   OBUF
         LW,15    FIT0+4
         STW,15   *FIT0+2
         LW,15    FIT4,6            TOTAL AMT USED SO FAR
         CW,15    FIT8,6             MAX USED (GRAN) SO FAR
         BLE      %+2
         STW,15   FIT8,6            RESET WITH BIGGER VALUE
         LH,10    RSTOR,6           AMT USER ORIG REQ
         AND,10   =X'FFFF'
PWTRI01  RES      0
         SW,15    10
         BGEZ     PWTRI011
         LW,15    FIT4,6            USE ORIG VAL ,NO EXTENTS YET
         B        PWTRI013
PWTRI011 RES      0
         CW,15    10                ARE WE IN RANGE
         BL       PWTRI013
         SW,15    10                TRY AGAIN
         B        PWTRI011
PWTRI013 RES      0
         STW,15   FIT0+6            NOW HAS GRAN POS INTO THE FILE
         LW,15    FIT0+3
         BEZ      %+2
         B        PWI10
         M:WRITE  *FIT0+1,(BUF,*OBUF),(SIZE,*FIT0+5),(BTD,0),;
                  (BLOCK,*FIT0+6),(ABN,WTABN),(ERR,WTERR)
         B        PWI40
*
PWI10    RES      0
         LW,15    CHTBL,6
         BG       PWI101
         STW,6    CHTBL,6
         B        PWI301+1
PWI101   LW,10    FIT0+1            DCB WORD ADDR
         LI,8     PWI301+1          RETURN ADDR
         BAL,9    EXAMEN             SEE IF ERR OR ABN IN DCB FOR THIS
         AI,10    7                 SET ADDR TO DCB WORD 7
         MTB,0    *10               GET BITS 00-07 WORD 7
         BNE      PWI301            NO, SO DO CHECK
         AI,10    -5                SET DCB ADDR TO WORD 2
         LH,9     *10               WANT BITS 8-14 WORD 2 (TYC)
         AND,9    =X'00FE'          MASK ALL BUT TYC
         CI,9     2                 00-02 NORMAL  TYC
         BLE      %+2
PWI301   M:CHECK  *FIT0+1,(ABN,WTABN),(ERR,WTERR)
         M:WRITE  *FIT0+1,(BUF,*OBUF),(SIZE,*FIT0+5),;
                  (BTD,0),(BLOCK,*FIT0+6)
         LW,15    FIT0+3
         XW,15    FIT0+2
         STW,15   FIT0+3
PWI40    RES      0
         LW,6     FIT0+8
         LW,15    FIT0+6            CURR GRAN COUNT
         AH,15    BCT0+29           ADD NEXT IO SIZE
         AND,15   =X'7FFFFFFF'        MASK SIGN EXT IF ANY
         LH,9     RSTOR,6           AMT RESERVED BY USER
         AND,9    =X'FFFF'           MASK SIGN EXTENSION
         CW,15    9                 ARE WE UNDER MULTIPLE OF GRAN
         BL       %+2
         BAL,15   EXTWT             NO SO EXTEND
         LW,15    FIT4,6            GRANULE NUMBER
         AH,15    BCT0+29           INCR FOR RAND BLK/CNT
         STW,15   FIT4,6            UP BY INCR VAL FOR NEXT IO
         LI,15    4
         STW,15   FIT0+4
         B        *PWTRIR
WTSTR    DATA     0
*
WTST     RES      0
         STW,15   WTSTR
         LW,6     FIT0+8            DCB ORDINAL
         LW,12    BCT0+6
         LW,14    *12
         AND,14   =X'FFFF'
         AW,14    FIT3,6
         CW,14    FIT2,6            IS ENOUGH ROOM FOR RECORD
         BL       WT10
         BAL,15   PWTR
         LI,14    4
         STW,14   FIT3,6
WT10     LW,14    *BCT0+6
         AND,14   =X'FFFF'
         CI,14    255               IS MORE THAN ONE MBS NEEDED
         BG       WT30
WT20     RES      0
         LW,13    FIT1,6
         SAD,12   2
         AW,13    FIT3,6
         STB,14   13
         MBS,12   0
         AWM,14   FIT3,6
         B        *WTSTR
*
WT30     RES      0
         LW,13    FIT1,6            SIDR NR. 7
         SAD,12   2                 SIDR NR. 7
         AW,13    FIT3,6            SIDR NR. 7
         AWM,14   FIT3,6
         LI,15    255
WT40     RES      0
         STB,15   13
         AI,14    -255
         MBS,12   0
         CI,14    255
         BG       WT40
         STB,14   13
         MBS,12   0
         B        *WTSTR
*
PWTRR    DATA     0
*
PWTR     RES      0
         STW,15   PWTRR
         LW,6     FIT0+8
         LW,14    FIT3,6
         LW,15    FIT1,6
         STW,14   *15               SET PHYSICAL RECORD LENGTH
         AI,14    16                 SEE IF SORT END WILL FIT
         CW,14    FIT2,6            BUF SIZE
         BG       PWT05                NOT ENOUGH ROOM
         SLS,14   -2                TO WORDS
         AW,14    FIT1,6            BUF BASE ADDR
         LI,6     4                 INDEX
         LI,15    0
PWT03    RES      0
         AI,14    -1                ZERO OUT WORD
         STW,15   *14
         BDR,6    PWT03
PWT05    RES      0
         LW,6     FIT0+8              RESET INDEX REG
         LW,14    FIT5,6
         STW,14   ODCB
         LW,14    FIT1,6
         STW,14   OBUF
         LW,15    FIT4,6
         CW,15    FIT8,6             MAX USED (GRAN) SO FAR
         BLE      %+2
         STW,15   FIT8,6            RESET WITH BIGGER VALUE
         LH,10    RSTOR,6           AMT USER ORIG REQ
         AND,10   =X'FFFF'
PWTR01   RES      0
         SW,15    10
         BGEZ     PWTR011
         LW,15    FIT4,6            USE ORIG VAL ,NO EXTENTS YET
         B        PWTR013
PWTR011  RES      0
         CW,15    10                ARE WE IN RANGE
         BL       PWTR013
         SW,15    10                TRY AGAIN
         B        PWTR011
PWTR013  RES      0
         STW,15   OADR
         LW,14    FIT2,6
         STW,14   OLENGTH
         LW,15    FIT6,6
         BEZ      %+2
         B        PWT10
         M:WRITE  *ODCB,(BUF,*OBUF),(SIZE,*OLENGTH),(BTD,0),;
                  (BLOCK,*OADR),(ABN,WTABN),(ERR,WTERR)
         B        PWT102
*
PWT10    RES      0
         LW,15    CHTBL,6
         BG       PWT10A
         STW,6    CHTBL,6
         B        PWT101+1
PWT10A   LW,10    ODCB              DCB WORD ADDR
         LI,8     PWT101+1          RETURN ADDR
         BAL,9    EXAMEN             SEE IF ERR OR ABN IN DCB FOR THIS
         AI,10    7                 SET ADDR TO DCB WORD 7
         MTB,0    *10               GET BITS 00-07 WORD 7
         BNE      PWT101            NO, SO DO CHECK
         AI,10    -5                SET DCB ADDR TO WORD 2
         LH,9     *10               WANT BITS 8-14 WORD 2 (TYC)
         AND,9    =X'00FE'          MASK ALL BUT TYC
         CI,9     2                 00-02 NORMAL  TYC
         BLE      %+2
PWT101   M:CHECK  *ODCB,(ABN,WTABN),(ERR,WTERR)
         M:WRITE  *ODCB,(BUF,*OBUF),(SIZE,*OLENGTH),;
                  (BTD,0),(BLOCK,*OADR)
         LW,15    FIT6,6
         XW,15    FIT1,6
         STW,15   FIT6,6
PWT102   RES      0
         LW,15    OADR              REL GRAN POS INTO THIS FILE FOR DCB
         AH,15    BCT0+29           ADD NEXT IO SIZE
         AND,15   =X'7FFFFFFF'           MASK SIGN EXT, IF ANY
         LH,9     RSTOR,6           AMT RESERVED BY USER
         AND,9    =X'FFFF'           MASK SIGN EXTENSION
         CW,15    9                 ARE WE UNDER MULTIPLE OF GRAN
         BL       %+2
         BAL,15   EXTWT             NO, SO EXTEND
         LW,15    FIT4,6            TOTAL GRAN COUNT FOR DCB
         AH,15    BCT0+29           UP BY IO INCR
         STW,15   FIT4,6             NEW TOTAL GRAN COUNT FOR NXT IO
         LI,15    4
         STW,15   FIT3,6
         B        *PWTRR
ODCB     DATA     0
OBUF     DATA     0
OLENGTH  DATA     0
OADR     DATA     0
*
*
OPISTR   DATA     0
* RETURN ADDR IN CSECT 0, CANT STW IN CSECT 1
CLISTR   DATA     0
OPOSTR   DATA     0
CLOSTR   DATA     0
         CSECT    1
*
OPIST    RES      0
         STW,15   OPISTR
         LW,6     ILT2              NR. OF INPUT DCB'S
OPI10    RES      0
         LW,7     ILT2,6            FIT/RRN0 ORDINAL
         LW,14    RRN0,7
         LW,5     *14
         LW,13    *14,5             RELATIVE RECORD NR.
         STW,13   FIT4,7
         BAL,15   EXTOP             GET PROPER FILE NAME IF NECESS
         BDR,6    OPI10
         B        *OPISTR
*
*
CLIST    RES      0
         STW,15   CLISTR
         LW,6     ILT2
CLI10    RES      0
         LW,4     ILT2,6
         LW,15    ILT0,4
         LW,5     *15
         LI,14    0
         STW,14   *15,5
         MTW,15   *15
         LW,14    RRN0,4
         LW,5     *14
         LW,13    *14,5
         STW,13   FIT4,4
         MTW,15   *14
         BAL,15   EXTOP             GET PROPER FILE NAME IF NECESS
         BDR,6    CLI10
         B        *CLISTR
*
*
OPOST    RES      0
         STW,15   OPOSTR
         LW,6     FIT0+8
         LW,15    FIT4,6
         LW,14    RRN0,6
         MTW,1    *14
         LW,7     *14
         STW,15   *14,7
        LI,15    4
        STW,15   FIT3,6
         LW,15    FIT1,6
         XW,15    FIT1+1
         STW,15   FIT1,6
         LW,15    FIT6,6
         XW,15    FIT6+1
         STW,15   FIT6,6
         B        *OPOSTR
*
*
CLOST    RES      0
         STW,15   CLOSTR
         LW,6     FIT0+8
         LW,15    FIT3,6
         AI,15    16
         CW,15    FIT2,6
         BL       CLOST05
         BAL,15   PWTR
CLOST05  RES      0
         LW,15    FIT3,6
         SAS,15   -2
         AW,15    FIT1,6
         LI,14    16
         STW,14   *15
         AI,15    1
         LI,14    0
         STW,14   *15
         AI,15    1
         LW,14    =C'SORT'
         STW,14   *15
         AI,15    1
         LW,14    =C' END'
         STW,14   *15
         LI,15    16
         AWM,15   FIT3,6
         BAL,15   PWTR
         LW,15    FIT6,6
         BEZ      CLS10
         LW,10    ODCB              DCB WORD ADR
         LI,8     CLS10             RETURN ADDR
         BAL,9    EXAMEN             SEE IF ERR OR ABN IN DCB FOR THIS
         AI,10    7                 SET ADDR TO DCB WORD 7
         MTB,0    *10               GET BITS 00-07 WORD 7
         BNE      CLS00             NO, SO DO CHECK
         AI,10    -5                SET DCB ADDR TO WORD 2
         LH,9     *10               WANT BITS 8-14 WORD 2 (TYC)
         AND,9    =X'00FE'          MASK ALL BUT TYC
         CI,9     2                 00-02 NORMAL  TYC
         BLE      %+2
CLS00    M:CHECK  *ODCB,(ABN,WTABN),(ERR,WTERR)
CLS10    RES      0
         LI,12    0
         LW,6     FIT0+8
         LW,15    ILT0,6
         MTW,1    *15
         LW,5     *15
         LW,4     ILT2
         LW,4     ILT2,4
         LW,14    ILT0,4
         LW,3     *14
         LW,13    *14,3
         MW,12    N-1
         STW,13   *15,5
         LW,15    FIT1,6
         XW,15    FIT1+1
         STW,15   FIT1,6
         LW,15    FIT6,6
         XW,15    FIT6+1
         STW,15   FIT6,6
         B        *CLOSTR
*
*
CLSTI    RES      0
         STW,15   CLOSTR
         LW,15    FIT0+4            BYTE DISPLACEMENT
         AI,15    16
         CW,15    FIT0+5
         BL       CLST05
         LW,6     FIT0+8
         BAL,15   PWTRI
CLST05   RES      0
         LW,15    FIT0+4
         SAS,15   -2
         AW,15    FIT0+2
         LI,14    16
         AWM,14   FIT0+4
         STW,14   *15
         AI,15    1
         LI,14    0
         STW,14   *15
         AI,15    1
         LW,14    =C'SORT'
         STW,14   *15
         AI,15    1
         LW,14    =C' END'
         STW,14   *15
         LW,6     FIT0+8
         MTW,1    ILT2
         LW,5     ILT2
         STW,6    ILT2,5
         BAL,15   PWTRI
         LW,15    FIT0+3
         BEZ      CLST10
         LW,10    FIT0+1            DCB WORD ADR
         LI,8     CLST10
         BAL,9    EXAMEN             SEE IF ERR OR ABN IN DCB FOR THIS
         AI,10    7                 SET ADDR TO DCB WORD 7
         MTB,0    *10               GET BITS 00-07 WORD 7
         BNE      CLST09            NO, SO DO CHECK
         AI,10    -5                SET DCB ADDR TO WORD 2
         LH,9     *10               WANT BITS 8-14 WORD 2 (TYC)
         AND,9    =X'00FE'          MASK ALL BUT TYC
         CI,9     2                 00-02 NORMAL  TYC
         BLE      %+2
CLST09   M:CHECK  *FIT0+1,(ABN,WTABN),(ERR,WTERR)
CLST10   RES      0
         B        *CLOSTR
         USECT    CLOSTR
*
MFPTSTR  DATA     0
*
MFPTST   RES      0
         STW,15   MFPTSTR
         LW,7     FIT5              NR OF DCB'S
         LW,15    ILT0,7            ADDRESS OF ILT1
         LW,14    *15               NR. OF STRINGS ON DCB
         CI,14    1
         BG       *MFPTSTR          NO FINAL PASS
         BDR,7    MFPTST+2
         LW,15    INEOF             IS END OF INPUT
         BEZ      *MFPTSTR          FIRST TIME THROUGH
         B        C1R
*
ENDSTRNG DATA     0,0,0,0,0         1 IN BYTE POS, END STRNG FOR DCB
ENDTABLE DATA     0,0,0,0,0         NON ZERO NOT 1ST TIME, 1ST BYTE
*          IF NON ZERO MEANS SINGLE BUFFERED.
ENDP2    RES      0
         DATA     0                 END OF THIS OVERLAY FOR THIS PR TYPE
         END

