         SYSTEM   SIG6
         SYSTEM   BPM
*
*    MODULE   E1
*
         DEF      PHASE4,MRGS15,PHS15
         REF      FIT0,FIT1,FIT2,FIT3,FIT4,FIT5,FIT6,INEOF,ILT0
         REF      BINEBC,RRN0,E1R,CO1
         REF      ILT2,RCDLN,RCDAD,BCT0,MTC0,MTC1,MTC2,MTC3,CNVRT
         REF      COMPR,S:OUT,TRKSB,WTERR,WTABN,RDERR,RDABN
         REF      ENDSNAP
         REF      CRSF,OU1
         REF      RSTOR,EXTRD,EXTOP
         REF      EXAMEN
         SREF     MRGS10X,SRTFX
         SREF     S:OUTPUT,SRT:FINX
BINBCD   EQU      BINEBC
         PAGE
*
PHASE4   RES      0
         LI,15    ENDP3
         STW,15   ENDSNAP
         LW,15    FIT5             NUMBER OF DCB'S
         STW,15   N
         AI,15    -1
         STW,15   N-1
PHS10    RES      0
         BAL,15   SELNOT
         BAL,15   OPIST
         LW,6     CRSF             IS IT CO-RESIDENT
         BEZ      SRTFX            NO.
PHS15    RES      0
         BAL,15   MVGN
         BAL,15   MRGST
         BAL,15   CLIST
SRT:FIN  RES      0
         LI,1     1                  INDEX USED BY SORT
         LI,7     0
         MTW,0    CRSF             IS IT CO-RESIDENTT
         BEZ      SRT:FINX         NO.
         BAL,11   S:OUTPUT         SHOW EOF
         MTW,-1   BCT0+1           ADJUST NUMBER OF RECS IN
         B        E1R
*
         DATA     0
N        DATA     0
*
SELNOTR  DATA     0
*
SELNOT   RES      0
         STW,15   SELNOTR
         LI,10    0
         STW,10   ILT2
         LW,3     FIT5              NUMBER OF DCB'S
SELN10   RES      0
         LW,15    ILT0,3            ADDRESS OF ILT1
         LW,4     *15
         BEZ      SELN20
         MTW,1    ILT2              COUNT INPUT
         LW,5     ILT2
         STW,3    ILT2,5            FIT ORDINAL
SELN20   RES      0
         AI,3     -1
         BEZ      SELN30            DONE
         B        SELN10
*
SELN30   RES      0
         LW,15    ILT2
         BEZ      SRT:FIN
         B        *SELNOTR
*
MVGNR    DATA     0
*
MVGN     RES      0
         STW,15   MVGNR
         LW,15    BCT0+1
         CI,15    1
         BG       MVG05
         MTW,1    MVGNR
         B        *MVGNR
MVG05    RES      0
         LW,2     ILT2
         LW,6     ILT2,2
         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
MVG20    RES      0
         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
         STW,1    14
         SAS,14   16
         AWM,14   MTC2,1
         LW,5     MTC1,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
         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    BCT0+1
         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
         LW,7     BCT0+6            RECORD ADDRESS
         LH,8     *BCT0+6           RECORD LENGTH
         AI,7     2                 SKIP RECORD CONTROL WORDS
         SAS,7    2                 CONVERT TO BYTE ADDRESS
         STW,1    ONESAV            SAVE REGISTER ONE
         LI,1     1                  INDEX USED BY SORT
         LW,11    CRSF             IS IT CO-RESIDENT
         BEZ      MRGS10X          NO.
         BAL,11   S:OUTPUT          WRITE REC
MRGS15   RES      0
         LW,1     ONESAV
         MTW,1    BCT0+2
         BAL,15   RDST
         LW,15    RCDAD
         STW,15   BCT0+6
         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     MTC3,1
         BNEZ     MRGS201
         LW,4     BCT0+7
         BL       *MRGSTR
MRGS201  LW,4     BCT0+6
         LW,5     MTC1,1
         BAL,9    COMPR             GO COMPARE RECORDS
         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
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
         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            GRAN AMT USED SO FAR
         LH,10    RSTOR,6           AMT USER ORIG REQ
         AND,10   =X'FFFF'
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
         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 SINGLE BUFFER FLAG
         LW,6     BCT0+8
         B        PRD40
PRD10    RES      0
         LW,15    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
         AI,10    7                 SET TO DCB WORD 7
         MTB,0    *10               GET BITS 00-07 WORD 7
         BNE      PRD201
         AI,10    -5                WANT DCB WORD 2
         LH,9     *10               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)
* THIS AREA LOOKS AT END OF BUF TO SEE IF END REC, IF NOT ALTERNATE BUF
         LW,15    FIT6,6
         LW,14    *15
         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              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   EXTRD             NO SO EXTEND
         LW,15    FIT4,6            TOTAL GRAN COUNT
         AH,15    BCT0+29           ADD IO INCR
         STW,15   FIT4,6            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
INLENGTH DATA     0
IADR     DATA     0
OPISTR   DATA     0
*
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
         MTW,15   *14
         BAL,15   EXTOP             GET BACK PROPER FILE NAME
         BDR,6    OPI10
         B        *OPISTR
*
CLISTR   DATA     0
*
CLIST    RES      0
         STW,15   CLISTR
         LW,6     ILT2
CLI10    RES      0
         LW,15    ILT0,6
         MTW,15   *15
         BDR,6    CLI10
         B        *CLISTR
*
ONESAV   DATA     0
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.
ENDP3    RES      0
         DATA     0                 END THIS OVLY FOR THIS PRCT TYPE
         END

