* CATALOG NO. 704987  SIGMA 5/7 SORT             OVERLAY 2              P2  0000
*  VERSION C00                                                          P2  0001
         SYSTEM   SIG7FDP                                               P2  0002
         SYSTEM   BPM                                                   P2  0003
PGMSEG2  CSECT    0                                                     P2  0004
*                                                                       P2  0005
         PAGE                                                           P2  0006
*                                                                       P2  0007
*                                                                       P2  0008
*  THIS SEGMENT PERFORMS THE INTERNAL SORT.  IT DISTRIBUTES STRINGS     P2  0009
*       AS REQUIRED FOR THE POLYPHASE MERGE AND ALTERNATES THE STRING   P2  0010
*       SEQUENCE AS REQUIRED BY THE READ BACKWARD FEATURE               P2  0011
*                                                                       P2  0012
         REF      BCT0,BFVB1,BINEBC,CCT0,CSO,CNVRT,FCT0,FCT1,FCT2,FCT3  P2  0013
         REF      FCT4,F:SCRF17,ILT1,INPORD,KRASC,KRDSC,OBRAD,OS1,RWMOV
         REF     OB1,ID1
         REF      STT0,ILT0                                             P2  0015
         REF      CRSF
         REF      ENDSORT
         DEF      SBC                                                   P2  0017
         SREF     S:INPUT
         PAGE
*                                                                       P2  0018
X1       EQU      1                                                     P2  0019
X2       EQU      2                                                     P2  0020
X3       EQU      3                                                     P2  0021
X4       EQU      4                                                     P2  0022
X5       EQU      5                                                     P2  0023
X6       EQU      6                                                     P2  0024
X7       EQU      7                                                     P2  0025
R0       EQU      8                                                     P2  0026
R1       EQU      9                                                     P2  0027
R2       EQU      10                                                    P2  0028
RA       EQU      10                                                    P2  0029
RB       EQU      11                                                    P2  0030
RC       EQU      12                                                    P2  0031
RD       EQU      13                                                    P2  0032
RE       EQU      14                                                    P2  0033
RF       EQU      15                                                    P2  0034
S:SORTP2 EQU      SBC                                                   P2  0035
SORTP2   EQU      S:SORTP2                                              P2  0036
*                                                                       P2  0037
         PAGE                                                           P2  0038
*                                                                       P2  0039
ORHOLD   DATA     0                 0 REQ ORDER 1 OPPOSING ORDER        P2  0040
TNEO     DATA     0                                                     P2  0041
*                                                                       P2  0042
         BOUND    8                                                     P2  0043
*                                                                       P2  0044
SELECT   DATA     0                                                     P2  0045
SELNXT   DATA     0                                                     P2  0046
THOLD    DATA,4   0,0,0,0,0,0,0,0,0                                     P2  0047
         DATA,4   0,0,0,0,0,0,0,0,0
LEVNUM   DATA,4   0                                                     P2  0048
*                                                                       P2  0049
*                                                                       P2  0050
*  THIS ROUTINE CONROLS THE EXECUTION OF THE SEGMENT 2 ROUTINES         P2  0051
*  WHEN THIS ROUTINE IS ENTERED THE FIRST RECORD FOR THE 'NEXT'         P2  0052
*       STRING HAS BEEN SELECTED AND ITS STT0 AND RCW ENTRIES ARE       P2  0053
*       IN BCT0+9 AND BCT0+10 RESPECTIVELY                              P2  0054
*                                                                       P2  0055
SBCR     DATA     0                                                     P2  0056
*                                                                       P2  0057
SBC      STW,X5   SBCR              SAVE RETURN ADDRESS                 P2  0058
         LI,5     ENDP2
         STW,5    ENDSORT
         LI,X1    1                                                     P2  0059
         LI,X5    2                 SET PHASE COUNT TO TWO              P2  0060
         STH,X5   CCT0,X1                                               P2  0061
         LW,X5    KSRD2             INITIALIZE READ ROUTINE             P2  0062
         LW,X6    CRSF             IS IT CO-RESIDENT
         BNEZ     SBC2             YES.
         MTW,0    FCT0+17           WAS FILE A SHORT ONE (EOF READ)
         BL       %+2               NO                                  P2  0064
SBC05    RES      0
         LW,X5    KSRD1             YES:  TURN READ OFF                 P2  0065
         STW,X5   SREAD+1                                               P2  0066
*                        GO SELECT THE NEXT OUTPUT FILE, PERFORM        P2  0067
SBC1     BAL,X5   SBK         THE POLYPHASE DISTRIBUTION CALCULATION    P2  0068
*                        GO PERFORM THE INTERNAL SORT TO PRODUCE        P2  0069
         BAL,X5   ISC         ONE OUTPUT STRING                         P2  0070
*                        GO PERFORM THE END OF STRING BOOKKEEPING       P2  0071
         BAL,X5   EOS         AND TEST FOR 'END OF INTERNAL SORT'       P2  0072
*                        EOS RETURNS HERE IF THE 'END OF INTERNAL       P2  0073
         B        SBC1        SORT' CONDITION DOES NOT EXIST            P2  0074
*                        EOS RETURNS HERE IF THE 'END OF INTERNAL       P2  0075
         BAL,X5   EIS         SORT' CONDITION DOES EXIST                P2  0076
*                        RETURN CONTROL TO SEGMENT 0                    P2  0077
         B        *SBCR                                                 P2  0078
*                                                                       P2  0079
SBC2     RES      0
         MTW,0    FCT0+17          WAS FILE A SHORT ONE
         BGE      SBC05+1          NO
         B        SBC05            YES. EOF READ
         PAGE                                                           P2  0080
*                                                                       P2  0081
*                                                                       P2  0082
*  THIS ROUTINE PERFORMS THE CALCULATIONS AND SETS THE CONTROL          P2  0083
*       ITEMS NECESSARY TO EFFECT A POLYPHASE DISTRIBUTION OF           P2  0084
*       STRINGS FROM THE INTERNAL SORT.  IT ALSO CONTROLS THE           P2  0085
*       ALTERNATION OF STRING SEQUENCES WITHIN A FILE FOR THE           P2  0086
*       READ BACKWARDS FEATURE, SELECTS THE NEXT OUTPUT FILE,           P2  0087
*       AND OPENS IT.                                                   P2  0088
*                                                                       P2  0089
SBKR     DATA,4   0                 RESET TO ZERO BY EIS                P2  0090
*                                                                       P2  0091
SBK      LI,X1    1                                                     P2  0092
         LH,X6    ILT0              FCT ORDINATE                        P2  0093
         LH,X7    ILT0,X1           NUMBER OF TAPE DRIVES (FILES)       P2  0094
         XW,X5    SBKR              SAVE RETURN ADDRESS                 P2  0095
         BE       SBKI              THIS THE FIRST TIME THROUGH         P2  0096
*                                                                       P2  0097
         AWM,X1   ILT0,X6           COUNT STRING JUST WRITTEN           P2  0098
         AI,X7    1                                                     P2  0099
*                                                                       P2  0100
SBK1     BDR,X7   SBK2              HAVE ALL TAPES BEEN EXAMINED        P2  0101
         BAL,X5   IDLCAL            YES:  GO CALCULATE NEW IDEAL LEVEL  P2  0102
         LH,X7    ILT0,X1               AND ROTATE ILT0 AND FCT0-4.     P2  0103
         LI,X6    0                                                     P2  0104
*                                                                       P2  0105
SBK2     AI,X6    1                 INCREMENT FCT ORDINATE BY 1         P2  0106
         CH,X6    ILT0,X1           IS THE ORDINATE MODULO NUMBER OF    P2  0107
         BLE      SBK3              NO:BYPASS SEQUENCE CONTROL  /TAPES  P2  0108
         LI,X6    1                 YES:                                P2  0109
         LW,RB    SELNXT            ALTERNATE SEQUENCE CONTROL.  SET    P2  0110
         STD,RB   SELECT                NEXT SEQUENCE = CURRENT SEQUENCEP2  0111
SBK3     LW,RA    ILT0,X6                                               P2  0112
         LH,RC    RA                IDEAL NUMBER                        P2  0113
         LH,RB    RA,X1                                                 P2  0114
         CW,RB    RC                IS ACTUAL NUMBER LESS THAN IDEAL    P2  0115
         BGE      SBK1              NO:  GO LOOK AT NEXT ENTRY          P2  0116
         LW,X7    X6                YES:  SELECT THIS UNIT              P2  0117
         AI,X7    1                 DOES THE SEQUENCE ALTERNATE BETWEEN P2  0118
         CH,X7    ILT0,X1               THIS STRING AND THE NEXT STRING P2  0119
         BLE      SBK4+1            NO:  BYPASS ALTERNATING SEQUENCE    P2  0120
         LW,RA    KRDSC                                    /SIG7-4137/*EP2  0121
         CW,RA    SELECT                                                P2  0122
         BNE      SBK4              NOT EQUAL                           P2  0123
         LW,RA    KRASC                                    /SIG7-4137/*EP2  0124
SBK4     STW,RA   SELNXT            SET SELNXT OPPOSITETO SELECT        P2  0125
         STH,X6   ILT0              SET CURRENT FILE'S FCT ORDINATE     P2  0126
         LI,X7    1                                                     P2  0127
         BAL,X5   OS1               GO:  OPEN OUTPUT STRING             P2  0128
         B        *SBKR                                                 P2  0129
*                                                                       P2  0130
         PAGE                                                           P2  0131
*                                                                       P2  0132
*                                                                       P2  0133
*  THIS REGION CONTROLS THE EXECUTION OF THE COMPARISON ROUTINES,       P2  0134
*       RCR AND RCRD,AS DICTATED BY THE ENTRIES IN THE SORT TOUR-       P2  0135
*       NAMENT CONTROL TABLE (STT0).  IT PROCESSES STT0.                P2  0136
*                                                                       P2  0137
*  EACH CYCLE THROUGH STT0 PRODUCES ONE RECORD SELECTED FOR OUTPUT.     P2  0138
*                                                                       P2  0139
*  AS EACH RECORD IS SELECTED,  IT IS WRITTEN (MOVED TO THE OUTPUT      P2  0140
*       BUFFER) AND A REPLACEMENT RECORD IS READ (MOVED FROM THE        P2  0141
*       INPUT BUFFER INTO THE AREA JUST VACATED BY THE MOST RECENT      P2  0142
*       SELECTEE.                                                       P2  0143
*                                                                       P2  0144
*  WHEN THIS ROUTINE IS FIRST ENTERED THE FIRST RECORD HAS BEEN         P2  0145
*       SELECTED.  IT'S STT0 INFORMATION IS PASSED IN BCT0+9 AND        P2  0146
*       BCT0+10.                                                        P2  0147
*                                                                       P2  0148
*  THE WRITE, READ, COMPARE SEQUENCE IS TERMINATED WHEN A RECORD        P2  0149
*       IS SELECTED WHICH IS FLAGGED AS A 'NEXT STRING' OR 'NULL'       P2  0150
*       (EOF) RECORD.                                                   P2  0151
*                                                                       P2  0152
         PAGE                                                           P2  0153
*                                                                       P2  0154
ISCR     DATA     0                                                     P2  0155
*                                                                       P2  0156
ISC      STW,X5   ISCR              SAVE RETURN ADDRESS                 P2  0157
         LW,X5    BCT0+9            ZERO RECS INPUT        /SIG7-1040/*CP2  0158
         BE       ISC11             YES                    /SIG7-1040/*CP2  0159
         LH,X5    BCT0+1,X1         ONE REC INPUT          /SIG7-1040/*CP2  0160
         BE       ISC12             YES: FINISH UP         /SIG7-1040/*CP2  0161
ISC1     MTW,1    BCT0+6            COUNT RECORD BEFORE WRITING IT      P2  0162
*                                                                       P2  0163
         BAL,X5   SWRITE            GO:  WRITE RECORD                   P2  0164
*                                   READ AND COMPARE, SET THE LEVEL     P2  0165
         BAL,X5   SREAD                 INDICATOR AND MOVE INTO CORE    P2  0166
*                                                                       P2  0167
*  THE PREVIOUSLY SELECTED RECORD HAS BEEN REPLACED BY A NEW RECORD.    P2  0168
*       THE LEVEL INDICATOR IN BCT0+9 HAS BEEN SET TO THIS STRING,      P2  0169
*       NEXT STRING, OR NULL (END OF FILE).  BEGIN THE TRIP THROUGH     P2  0170
*       STT0.                                                           P2  0171
*                                                                       P2  0172
         LH,X7    BCT0+9                                                P2  0173
         SLS,X7   -1                                                    P2  0174
ISC2     AND,X7   =X'FFF'                                               P2  0175
          STW,X7  TNEO                                                  P2  0176
         LW,RE    *STT0,X7          PARTNERS LEVEL,FEO,AND ADDRESS      P2  0177
         LW,RF    BCT0+9                                                P2  0178
         OR,RF    RE                                                    P2  0179
         AND,RF   =X'60000000'                                          P2  0180
         BE       ISC5              BOTH RECORDS CURRENT STRING:  COMPARP2  0181
         LW,RF    =X'60000000'                                          P2  0182
         CS,RE    BCT0+9                                                P2  0183
         BE       ISC8              BOTH RECORDS NEXT STRING OR NULL    P2  0184
         BGE      ISC4              NO EXCHANGE                         P2  0185
ISC3     XW,RE    BCT0+9            EXCHANGE                            P2  0186
         STW,RE   *STT0,X7                                              P2  0187
         LH,X7    *BCT0+9                                               P2  0188
         STH,X7   *RE               NEXT ENTRY ORDINATE                 P2  0189
         CI,X7    0                 IS THERE ANOTHER LEVEL OF COMPARISONP2  0190
         BNE      ISC2              YES:  RETURN TO COMPARE             P2  0191
*  AT THIS POINT A RECORD HAS BEEN SELECTED                             P2  0192
*                                                                       P2  0193
ISC10    LC       BCT0+9                                                P2  0194
         BCR,X6   ISC1                                                  P2  0195
         B        *ISCR             END OF STRING/END OF INTERNAL SORT  P2  0196
*                                                                       P2  0197
ISC4     LH,X7    *RE               NO EXCHANGE:                        P2  0198
         BNE      ISC2              GO PROCESS NEXT TOURNAMENT ENTRY    P2  0199
         B        ISC10             A RECORD HAS BEEN SELECTED          P2  0200
*                                                                       P2  0201
ISC5     LI,X4    X'1FFFF'                                              P2  0202
         LI,X5    X'1FFFF'                                              P2  0203
         AND,X4   BCT0+9            PREDICTED WINNER'S CORE ADDRESS     P2  0204
         AND,X5   *STT0,X7                                              P2  0205
         BAL,R1   *SELECT           COMPARE RECORDS ON KEYS             P2  0206
ISC6     BL       ISC7              EXCHANGE NECESSARY                  P2  0207
         LW,X7    TNEO              NO EXCHANGE REQUIRED                P2  0208
         LW,RE    *STT0,X7                                              P2  0209
         B        ISC4                                                  P2  0210
*                                                                       P2  0211
ISC7     LW,X7    TNEO              PREPARE FOR EXCHANGE                P2  0212
          LW,RE    *STT0,X7                                             P2  0213
         B        ISC3              GO EXCHANGE RECORDS                 P2  0214
*                                                                       P2  0215
ISC8     CS,RF    BCT0+9                                                P2  0216
         BNE      ISC9              NOT NULL (END OF FILE)              P2  0217
         B        ISC4              NULL BYPASS COMPARE:  NO EXCHANGE   P2  0218
*                                                                       P2  0219
ISC9     LI,X4    X'1FFFF'                                              P2  0220
         LI,X5    X'1FFFF'                                              P2  0221
         AND,X4   BCT0+9            PREDICTED                           P2  0222
         AND,X5   *STT0,X7                                              P2  0223
         BAL,R1   *SELNXT                                               P2  0224
         B        ISC6                                                  P2  0225
*                                                                       P2  0226
*        ZERO INPUT                                        /SIG7-1040/*CP2  0227
ISC11    LW,X5    =X'60000000'                             /SIG7-1040/*CP2  0228
         STW,X5   BCT0+9            SET EOF FLAG           /SIG7-1040/*CP2  0229
         B        *ISCR                                    /SIG7-1040/*CP2  0230
*        ONE REC IN                                        /SIG7-1040/*CP2  0231
ISC12    MTW,1    BCT0+6            COUNT REC BEFORE WRITE /SIG7-1040/*CP2  0232
         BAL,X5   SWRITE            WRITE IT               /SIG7-1040/*CP2  0233
         B        ISC11                                    /SIG7-1040/*CP2  0234
*                                                          /SIG7-1040/*CP2  0235
         PAGE                                                           P2  0236
*                                                                       P2  0237
*  THIS ROUTINE CLEARS ALL THE 'NEXT STRING' INDICATORS FROM STT0       P2  0238
*       ENTRIES, LEAVING UNTOUCHED THE 'NULL' (END OF FILE)             P2  0239
*       INDICATORS.  IT ALSO CLEARS THE NEXT STRING INDICATOR           P2  0240
*       FROM THE ENTRY IN BCT0+9.  IF THE ENTRY IN BCT0+9 CONTAINS      P2  0241
*       A 'NULL' INDICATOR, THIS ROUTINE RETURNS CONTROL TO THE         P2  0242
*       RETURN ADDRESS PLUS ONE.  (THIS IS THE END OF INTERNAL SORT     P2  0243
*       CONDITION).  IF THE BCT0+9 ENTRY DOES NOT CONTAIN A 'NULL'      P2  0244
*       INDICATOR, CONTROL IS RETURNED TO THE RETURN ADDRESS TO         P2  0245
*       PROCESS THE NEXT STRING.                                        P2  0246
*                                                                       P2  0247
*  AT ENTRY TO THIS ROUTINE, BCT0+9 AND BCT0+10 CONTAIN ALL THE         P2  0248
*       STT0 INFORMATION FOR THE LAST RECORD SELECTED.                  P2  0249
*                                                                       P2  0250
         PAGE                                                           P2  0251
*                                                                       P2  0252
EOSR     DATA     0,0                                                   P2  0253
*                                                                       P2  0254
EOS      STW,X5   EOSR                                                  P2  0255
         LH,X6    ILT0              FCT ORDINATE                        P2  0256
         LI,X7    0                 CLOSE IS FOR A STRING               P2  0257
         BAL,X5   CSO               GO:  CLOSE STRING                   P2  0258
         LW,RF    =X'40000000'      IS THE CURRENT RECORD A 'NULL)      P2  0259
         AND,RF   BCT0+9                (END OF FILE) RECORD            P2  0260
         BE       EOS1              NO:  GO PERFORM END OF STRING BKKPNGP2  0261
         LH,X6    ILT0              YES:  FCT ORDINATE                  P2  0262
         MTW,1    ILT0,X6           COUNT STRING JUST WRITTEN           P2  0263
         MTW,1    EOSR              ADD ONE TO RETURN ADDRESS           P2  0264
         B        *EOSR             GO:  PROCESS END OF INTERNAL SORT   P2  0265
*                                                                       P2  0266
*  THE LAST SELECTEE BELONGS TO A VALID STRING.  IT IS NOW MARKED       P2  0267
*       'NEXT STRING' BY BIT 2 OF BCT0+9 BEING A ONE.  ALL OTHER        P2  0268
*       RECORDS IN CORE ARE SIMILARLY FLAGGED BY BIT 2 OF THEIR         P2  0269
*       RESPECTIVE STT0 ENTRIES.  THESE BITS WILL NOW ALL BE RESET      P2  0270
*       TO ZERO.                                                        P2  0271
*                                                                       P2  0272
EOS1     LI,X1    1                                                     P2  0273
         LH,X6    BCT0+1,X1         NUMBER OF TOURNAMENT ENTRIES        P2  0274
         LW,RF    =X'FFFFFFF'                                           P2  0275
         LW,RD    =X'60000000'                                          P2  0276
         LI,RE    0                 SET THE LOW ORDER BIT OF THE        P2  0277
EOS2     BDR,X6   EOS3                  LEVEL INDICATOR OF EACH         P2  0278
         CS,RD    *STT0                                                 P2  0279
         BE       EOS25                                                 P2  0280
         LS,RE    *STT0                 STT0 ENTRY TO A ZERO            P2  0281
         STW,RE   *STT0                                                 P2  0282
EOS25    LS,RE    BCT0+9                                                P2  0283
         STW,RE   BCT0+9                                                P2  0284
         B        *EOSR                                                 P2  0285
*                                                                       P2  0286
EOS3     CS,RD    *STT0,X6                                              P2  0287
         BE       EOS2                                                  P2  0288
         LS,RE    *STT0,X6                                              P2  0289
         STW,RE   *STT0,X6                                              P2  0290
         B        EOS2                                                  P2  0291
*                                                                       P2  0292
         PAGE                                                           P2  0293
*                                                                       P2  0294
*                                                                       P2  0295
*  THIS ROUTINE PRINTS THE MESSAGES:                                    P2  0296
*                    SORTIN=XXXXXX (NUMBER OF RECORDS INTO THE SORT) ANDP2  0297
*                    P=XX (NUMBER OF MERGE PHASES NECESSARY TO          P2  0298
*                         PRODUCE THE FINAL OUTPUT).                    P2  0299
*                                                                       P2  0300
*  AFTER PRINTING THESE MESSAGES, THIS ROUTINE ADJUSTS ILT0 TO REFLECT  P2  0301
*       THE ACTUAL NUMBER OF STRINGS WRITTEN SHOWING A COUNT OF 'ZERO   P2  0302
*       LENGTH' STRINGS.  BEFORE EXITING THE INPUT FILE DCB ADDRESS     P2  0303
*       IN FCT0+8 IS REPLACED BY THE ADDRESS OF S:SCRF8, THE SORT       P2  0304
*       SCRATCH FILE DCB ASSOCIATED WITH THE EIGHTH TAPE AVAILABLE.     P2  0305
*                                                                       P2  0306
         PAGE                                                           P2  0307
*                                                                       P2  0308
EISR     DATA     0                                                     P2  0309
*                                                                       P2  0310
EIS      STW,X5   EISR              SAVE RETURN ADDRESS                 P2  0311
         LI,X5    0                                                     P2  0312
         STW,X5   IDLCALR           INITIALIZE IDLCALR                  P2  0313
         STW,X5   BCT0+7                                                P2  0314
*                                                                       P2  0315
*  BEGIN PROCESSING ILT0 TO PRODUCE FOR EACH ENTRY THE IDEAL NUMBER     P2  0316
*       PLUS A COUNT OF 'ZERO' OR 'DUMMY' STRINGS.                      P2  0317
*                                                                       P2  0318
         LI,X1    1                                                     P2  0319
         LH,X5    ILT0,X1           NUMBER OF ENTRIES                   P2  0320
EIS2     LW,X6    ILT0,X5                                               P2  0321
         LH,RA    X6                IDEAL NUMBER                        P2  0322
         SH,RA    X6,X1                 MINUS ACTUAL NUMBER             P2  0323
         AW,X6    RA                                                    P2  0324
         STH,RA   X6                                                    P2  0325
         STW,X6   ILT0,X5                                               P2  0326
         BDR,X5   EIS2                                                  P2  0327
*                                                                       P2  0328
EIS3     LH,X5    ILT0,X1                                               P2  0329
         LI,X4    0                 CLEAR OUTPUT TAPE ILT0 ENTRY        P2  0330
         STW,X4   ILT0+1,X5         CLEAR OUTPUT TAPE ILT0 ENTRY        P2  0331
         LI,6     DA(F:SCRF17)
         STH,6    FCT0+17,1
         LI,X4    X'FFFF'                                               P2  0334
         STW,X4   EOSR+1            SET WORD TO LARGE NUMBER            P2  0335
*                                                                       P2  0336
EIS5     LW,RA    ILT0,X5           FIND THE SMALLEST NUMBER OF ZERO    P2  0337
         LH,RB    RA                    STRINGS ON ANY TAPE.  IE, THAT  P2  0338
         CW,RB    EOSR+1                NUMBER WHICH WHEN SUBTRACTED    P2  0339
         BGE      EIS4                 GROM THE ZERO STRING COUNTS WILL P2  0340
         STW,RB   EOSR+1                PRODUCE AT LEAST ONE COUNT OF   P2  0341
EIS4     BDR,X5   EIS5                                                  P2  0342
*                                                                       P2  0343
EIS6     AWM,X1   ILT0                                                  P2  0344
         LH,X5    ILT0,X1                                               P2  0345
         LW,X4    EOSR+1                THE ILT0 ENTRY FOR THE FIRST    P2  0346
         STH,X4   ILT1,X5           BEGINNING OF TAPE  DUMMY STRINGS    P2  0347
         STH,X4   X4                    MERGE OUTPUT                    P2  0348
         LCW,RA   X4                                                    P2  0349
EIS7     BDR,X5   EIS8              EXIT IF DONE                        P2  0350
         B        EIS9                                                  P2  0351
*                                                                       P2  0352
EIS8     AWM,RA   ILT0,X5           SUBTRACT THIS NUMBER FROM EACH      P2  0353
         B        EIS7                  INPUT ILT0 ENTRY                P2  0354
*                                                                       P2  0355
EIS9     LH,X6    ILT0,X1                                               P2  0356
         LI,X5    X'FFFF'                                               P2  0357
         AND,X5   FCT0,X6                                               P2  0358
         SLS,X5   1                                                     P2  0359
         STW,X5   SWRITER                                               P2  0360
         M:OPEN   *SWRITER                                              P2  0361
         M:REW    *SWRITER                                              P2  0362
         BDR,X6   %+1                                                   P2  0363
EIS10    LW,X5    ILT0,X6                                               P2  0364
         LH,RA    X5                DUMMY STRING COUNT                  P2  0365
         LH,RB    X5,X1             TOTAL STRING COUNT                  P2  0366
         CW,RA    RB                                                    P2  0367
         BGE      EIS11                                                 P2  0368
         LI,X7    1                                                     P2  0369
         BAL,X5   CSO                                                   P2  0370
EIS11    BDR,X6   EIS10                                                 P2  0371
         B        *EISR                                                 P2  0372
*                                                                       P2  0373
         PAGE                                                           P2  0374
*                                                                       P2  0375
*                                                                       P2  0376
*  THIS ROUTINE WRITES ONE RECORD                                       P2  0377
*                                                                       P2  0378
SWRITER  DATA     0                                                     P2  0379
*                                                                       P2  0380
SWRITE   STW,X5   SWRITER           SAVE RETURN ADDRESS                 P2  0381
         LH,X6     ILT0                                                 P2  0382
         LI,X7    X'1FFFF'                                              P2  0383
         AND,X7   BCT0+9            RECORD ADDRESS                      P2  0384
         LI,R0    X'FFFF'                                               P2  0385
         AND,R0   0,X7              RECORD LENGTH                       P2  0386
         SLS,X7   2                 CONVERT TO BYTE ADDRESS             P2  0387
         LW,X5    CRSF               CHECK IF CO-RESIDENT
         BEZ      SWRTX              NO. GO TO P2A
         BAL,5    BFVB1                                                 P2  0388
         B        *SWRITER          RETURN TO CALLER                    P2  0389
SWRTX    RES      0
         BAL,X5   OB1              GO WRITE RECORD
         B        *SWRITER         RETURN
*                                                                       P2  0390
         PAGE                                                           P2  0391
*                                                                       P2  0392
*                                                                       P2  0393
*  THIS ROUTINE SETS THE FIRST ENTRY CONDITIONS FOR THE POLYPHASE       P2  0394
*       READ BACKWARD OPERATION                                         P2  0395
*                                                                       P2  0396
SBKI     STW,X1   ORHOLD            SET OPPOSING SEQUENCE TO INDICATOR  P2  0397
         LI,RB    2                 INITIALIZE THE MERGE PHASE COUNT    P2  0398
         STW,RB   LEVNUM                                                P2  0399
         STH,X1   ILT0              SET LAST ENTRY TO 1 (SELECT FILE 2) P2  0400
         STW,X1   X6                                                    P2  0401
         LW,RB    KRDSC                                    /SIG7-4137/*EP2  0402
         STD,RB   SELECT                RCRD (OPPOSING SEQUENCE).       P2  0403
         LI,RA    X'20000'                                              P2  0404
SBKI1    BDR,X7   SBKI2                                                 P2  0405
         STH,X1   ILT0+1            SET IDEAL NUMBER TO 1               P2  0406
         LH,X7    ILT0,X1                                               P2  0407
         B        SBK1-1                                                P2  0408
*                                                                       P2  0409
SBKI2    STW,RA   ILT0+1,X7                                             P2  0410
         B        SBKI1                 COUNTS TO  2                    P2  0411
*                                                                       P2  0412
         PAGE                                                           P2  0413
*                                                                       P2  0414
*                                                                       P2  0415
*  THIS ROUTINE CALCULATES THE NEXT IDEAL NUMBER OF STRINGS FOR         P2  0416
*       EACH DEVICE TO SATISFY THE DISTRIBUTION REQUIREMENTS FOR        P2  0417
*       A POLYPHASE MERGE.  IT BYPASSES THOSE LEVELS--EVERY N-TH        P2  0418
*       LEVEL(N=NUMBER OF FILES AVAILABLE)-- WHERE ALL ENTRIES          P2  0419
*       ARE ODD NUMBERS AND IT ROTATES THE FCT0-4 ENTRIES AND THE       P2  0420
*       ACTUAL NUMBER FIELD OF THE ILT0 TABLE                           P2  0421
*                                                                       P2  0422
IDLCALR  DATA     0                                                     P2  0423
*                                                                       P2  0424
IDLCAL   STW,X5   IDLCALR           SAVE RETURN ADDRESS                 P2  0425
         MTW,1    LEVNUM            COUNT THIS MERGE PHASE              P2  0426
         LI,X6    0                                                     P2  0427
         STW,X6   THOLD                                                 P2  0428
         LH,X7    ILT0,X1                                               P2  0429
         LI,X5    3                                                     P2  0430
         LI,X6    2                                                     P2  0431
         LW,RA    ILT0,X7           SET HOLDING REGISTER TO LAST ENTRY  P2  0432
         STH,RA   THOLD,X1                                              P2  0433
IDLC1    STH,RA   ILT0,X6               SAME VALUE INTO FIRST ENTRY     P2  0434
         AI,X6    2                                                     P2  0435
         BDR,X7   IDLC2                                                 P2  0436
         B        IDLC3                                                 P2  0437
IDLC2    LH,RA    ILT0,X5                                               P2  0438
         AW,RA    THOLD                                                 P2  0439
         AI,X5    2                                                     P2  0440
         B        IDLC1                                                 P2  0441
*                                                                       P2  0442
IDLC3    LW,RA    ILT0+1                                                P2  0443
         AND,RA   ILT0+2                                                P2  0444
         AND,RA   =X'10000'         ARE THERE TWO ODD NUMBERED ENTRIES  P2  0445
         BE       IDLC5             NO:                                 P2  0446
         LI,7     17
IDLC4    LW,RA    ILT0,X7                                               P2  0448
         STW,RA   THOLD,X7          SAVE ACTUALN LEVEL NUMBER FOR       P2  0449
         SCS,RA   16                    USE LATER                       P2  0450
         STW,RA   ILT0,X7                                               P2  0451
         BDR,X7   IDLC4                                                 P2  0452
         B        IDLCAL+1          GO COMPUTE THE NEXT LEVEL           P2  0453
*                                                                       P2  0454
IDLC5    LW,RA    THOLD+1           MUST ILT0 (ACTUAL NUMBERS) BE       P2  0455
         BE       IDLC8             NO:                       /RESTORED P2  0456
         LH,X7    ILT0,X1           YES:                                P2  0457
         LI,RB    X'FFFF'                                               P2  0458
IDLC6    LW,RA    THOLD,X7          RESTORE ILT0 (RIGHT HALF WORD)      P2  0459
         STS,RA   ILT0,X7                                               P2  0460
         BDR,X7   IDLC6                                                 P2  0461
*                                                                       P2  0462
IDLC8    LH,X7    ILT0,X1                                               P2  0463
*        LINE 484 REMOVED FOR UTS                                       P2  0464
         LW,RA    FCT0,X7                                               P2  0465
         LW,RB    FCT1,X7                                               P2  0466
         LW,RC    FCT2,X7                                               P2  0467
         LW,RD    FCT3,X7                                               P2  0468
         LW,RE    FCT4,X7                                               P2  0469
         LI,RF    X'FFFF'                                               P2  0470
         AND,RF   ILT0,X7                                               P2  0471
         LCI      6                    UTS CHANGE                       P2  0472
         STM,R2   THOLD+2              UTS CHANGE                       P2  0473
IDLC9    BDR,X7   IDLC10                                                P2  0474
         B        IDLC11                                                P2  0475
IDLC10   LW,RA    FCT0,X7           ROTATE FCT0-FCT4 AND ILT0           P2  0476
*        LINE 497 REMOVED FOR UTS                                       P2  0477
         LW,RB    FCT1,X7                                               P2  0478
         LW,RC    FCT2,X7                                               P2  0479
         LW,RD    FCT3,X7                                               P2  0480
         LW,RE    FCT4,X7                                               P2  0481
         LI,X5    X'FFFF'                                               P2  0482
         LS,X4    ILT0,X7                                               P2  0483
*        LINE 504 REMOVED FOR UTS                                       P2  0484
         STW,RA   FCT0+1,X7                                             P2  0485
         STW,RB   FCT1+1,X7                                             P2  0486
         STW,RC   FCT2+1,X7                                             P2  0487
         STW,RD   FCT3+1,X7                                             P2  0488
         STW,RE   FCT4+1,X7                                             P2  0489
         STS,X4   ILT0+1,X7                                             P2  0490
         B        IDLC9                                                 P2  0491
*                                                                       P2  0492
IDLC11   LH,X7    ILT0,X1                                               P2  0493
         LCI      6                   UTS CHANGE                        P2  0494
         LM,R2    THOLD+2                                               P2  0495
         STW,RA   FCT0+1                                                P2  0496
         STW,RB   FCT1+1                                                P2  0497
         STW,RC   FCT2+1                                                P2  0498
         STW,RD   FCT3+1                                                P2  0499
         STW,RE   FCT4+1                                                P2  0500
         STH,RF   ILT0+1,X1                                             P2  0501
         LI,7     17
         LI,RA    0                                                     P2  0503
         STW,RA   THOLD,X7                                              P2  0504
         BDR,X7   %-1                                                   P2  0505
         B        *IDLCALR          EXIT                                P2  0506
*                                                                       P2  0507
         PAGE                                                           P2  0508
*                                                                       P2  0509
*  THIS ROUTINE READS ONE RECORD AND SETS THE RCW.                      P2  0510
*                                                                       P2  0511
SREADR   DATA     0,0,0                                                 P2  0512
*                                                                       P2  0513
SREAD    STW,X5   SREADR            SAVE RETURN ADDRESS                 P2  0514
         LI,X6    17
         LI,X7    0                 SET TO NO MOVE                      P2  0515
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BEZ      SREADX            NO. GO TO P2A FOR READ
         BAL,11   S:INPUT                                               P2  0516
         LI,1     1                                                     P2  0517
         MTW,1    INPORD                                                P2  0518
         CI,7     0                                                     P2  0519
         BNE      SREAD2            NOT EOF                             P2  0520
SREAD0   RES      0
         LW,X5    KSRD1                                                 P2  0521
         STW,X5   SREAD+1               END OF FILE HENCEFORTH.         P2  0522
SREAD1   LW,X5    =X'60000000'      SET NUL (EOF) INDICATOR             P2  0523
         OR,X5    BCT0+9                                                P2  0524
         STW,X5   BCT0+9                                                P2  0525
         B        *SREADR                                               P2  0526
SREADX   RES      0
         BAL,X5   ID1                IN BUFFER IN X7
         LI,X1    1
         MTW,0    FCT0,X6          IS END OF FILE (IS FILE CLOSED)
         BL       SREAD2           NO
         B        SREAD0
*                                                                       P2  0527
KSRD1    B        SREAD1                                                P2  0528
KSRD2    LI,6     17
*                                                                       P2  0530
SREAD2   LW,RA    X7                SOURCE ADDRESS                      P2  0531
         LI,RB    X'1FFFF'                                              P2  0532
         AND,RB   BCT0+9            DESTINATION ADDRESS                 P2  0533
         SLS,RB   2                 CONVERTED TO BYTES                  P2  0534
         AI,RB    8                  SKIP RCW'S            /SIG7-2254/*DP2  0535
         LW,RC    R0                ACTUAL RECORD LENGTH                P2  0536
         AI,R0    X'F'               ACCT FOR RCW'S AND MAK/SIG7-2254/*DP2  0537
*                                    E INPUT ORDER         /SIG7-2254/*DP2  0538
         AND,R0   =X'FFFC'              RECORD LENGTH A MULTIPLE OF 4   P2  0539
         CW,12    FCT4
         BLE      SREAD4            YES:  GO MOVE RECORD                P2  0541
         LW,RC    FCT4              NO:  TRUNCATE RECORD                P2  0542
         LW,R0    FCT4                                                  P2  0543
         AND,8    =X'3'              IS IT EVEN WORD MULT
         BNEZ     %+3                NO
         LW,8     FCT4              ALREADY EVEN WORD MULT
         B        SREAD4-1
         LW,8     FCT4
         SLS,8    -2                TO WORDS
         AI,8     1                 UP TO NEXT WORD
         SLS,8    2                 TO BYTES
         AI,RC    -12                                      /SIG7-2254/*DP2  0544
SREAD4   STW,RC   SREADR+2                                              P2  0545
         BAL,R1   RWMOV                                                 P2  0546
         LW,X7    SREADR+2          ACTUAL RECORD LENGTH                P2  0547
         STW,R0   *BCT0+9           STORE RCW                           P2  0548
         LI,RA    X'1FFFF'                                              P2  0549
         AND,RA   BCT0+9            GET RECORD'S ADDRESS                P2  0550
         LW,RB    R0                                                    P2  0551
         SLS,RB   -2                                                    P2  0552
         AW,RB    RA                PLUS RECORD'S ADJUSTED LENGTH       P2  0553
         AI,RB    -1                    MINUS ONE                       P2  0554
         STH,X7   *RB               CREATE TRAILING RCW                 P2  0555
         STH,R0   *RB,X1                AND                             P2  0556
         LW,4     INPORD            CREATE LOW ORD KEY     /SIG7-2254/*DP2  0557
         STW,4    *BCT0+9,1                                /SIG7-2254/*DP2  0558
         LW,X4    OBRAD             PREDICTED WINNER,S BYTE ADDRESS     P2  0559
         LI,X5    X'1FFFF'                                              P2  0560
         SLS,X4   -2                CONVERT TO WORD ADDRESS             P2  0561
         AND,X5   BCT0+9            PREDICTED LOSER'S WORD ADDRESS      P2  0562
         BAL,R1   *SELECT           GO COMPARE REDORDS ON KEYS          P2  0563
         BGE      SREAD5            NEW RECORD IN THIS STRING           P2  0564
         LW,X7    =X'20000000'      NEW RECORD IN NEXT STRING           P2  0565
         OR,X7    BCT0+9            SET NEXT STRING INDICATOR           P2  0566
         STW,X7   BCT0+9                INTO BCT0+9                     P2  0567
ENDP2    RES      0
SREAD5   B        *SREADR           EXIT                                P2  0568
*                                                                       P2  0569
         PAGE                                                           P2  0570
*                                                                       P2  0571
*                                                                       P2  0572
         END                                                            P2  0573

