* CATALOG NO 704985-0    SIGMA 5/7 SORT           OVERLAY 0             P0  0000
*  VERSION C00                                                          P0  0001
         SYSTEM   SIG7FDP                                               P0  0002
         SYSTEM   BPM                                                   P0  0003
PGMSEG0  CSECT    0                                                     P0  0004
*                                                                       P0  0005
         PAGE                                                           P0  0006
*                                                                       P0  0007
         DEF      SCR0,SCR2,SIN27
         DEF      ALLBL,CKDEC,ER2,GIL1
         DEF      SETCD10,SETCD43,SIN121,SIN145,SIN2R
         DEF      SIN222,SIN24,SIN281,SIN295
         REF      BCT0,BNEBC,CCT0,CNVRT,CPER,EBCBN,FCT0,FCT1,FCT2,FCT3  P0  0009
         REF      FCT4,ILT0,KLNGC,KRASC,KRDSC,KTTL,MASAD,OS1            P0  0010
         REF      NUMPGS
         REF      ENDSORT
         REF      RLKCM,SC5,SINTMP,SIN1R,STT0                           P0  0011
         REF      STFP,STEP,CRSF                                        P0  0012
         SREF     SCR1X,IDC1,IDC,SIN21X,SIN122X,SIN2X,SIN24X
         SREF     SIN293X,SIN214X,SIN230X,SEQRCD,SEQLNG
         REF      DCBTABLE,HEDBUF
         REF      DUMPMEM
*                                                                       P0  0013
         PAGE                                                           P0  0014
*                                                                       P0  0015
X0       EQU      0                                                     P0  0016
X1       EQU      1                                                     P0  0017
X2       EQU      2                                                     P0  0018
X3       EQU      3                                                     P0  0019
X4       EQU      4                                                     P0  0020
X5       EQU      5                                                     P0  0021
X6       EQU      6                                                     P0  0022
X7       EQU      7                                                     P0  0023
R0       EQU      8                                                     P0  0024
R1       EQU      9                                                     P0  0025
R2       EQU      10                                                    P0  0026
R3       EQU      11                                                    P0  0027
R4       EQU      12                                                    P0  0028
R5       EQU      13                                                    P0  0029
R6       EQU      14                                                    P0  0030
R7       EQU      15                                                    P0  0031
SR1      EQU      8                                                     P0  0032
SR2      EQU      9                                                     P0  0033
SR3      EQU      10                                                    P0  0034
RA       EQU      10                                                    P0  0035
RB       EQU      11                                                    P0  0036
RC       EQU      12                                                    P0  0037
RD       EQU      13                                                    P0  0038
RE       EQU      14                                                    P0  0039
RF       EQU      15                                                    P0  0040
R13      EQU      13                                                    P0  0041
R14      EQU      14                                                    P0  0042
PRAMLOC  EQU      SIN1R+1                                               P0  0043
BINEBC   EQU      BNEBC                                                 P0  0044
SETCD4   EQU      SETCD10                                               P0  0045
*                                                                       P0  0046
*                                                                       P0  0047
         PAGE                                                           P0  0048
         BOUND    8                                                     P0  0049
DIGLIM   DATA,4   X'0'                                                  P0  0050
         DATA,4   X'9'                                                  P0  0051
*                                                                       P0  0052
SKLIM    DATA,4   X'10000'                                              P0  0053
         DATA,4   X'1060000'                                            P0  0054
*                                                                       P0  0055
* CODE DELETED
*                                                                       P0  0057
*                                                                /VALUESP0  0058
KSRTC    DATA,4   51                KEY START                           P0  0059
*                                                                       P0  0060
         PAGE                                                           P0  0061
*                                                                       P0  0062
SCR1R    DATA     0                                                     P0  0063
*                                                                       P0  0064
*                                                                       P0  0065
SIN2R    DATA     0                                                     P0  0066
*                                                                       P0  0067
SCR0     STW,X5   SCR1R             SAVE RETURN ADDRESS                 P0  0068
         LCI      3
         STM,5    SIN1R             SAVE REG 6,7  FOR LATER
         LI,5     ENDP0
         STW,5    ENDSORT           IN CASE OF DUMP
         M:GP     1
         STW,9    STT0
         LW,5     CRSF               IS IT CO-RES
         BEZ      SCR1X             NO
SCR2     RES      0
         M:FP     1
         BAL,X5   SIN1              EDIT AND CONFIGURATION CHECKS       P0  0069
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BGZ      SCR1              YES.
         M:TRAP   (IGNORE,DEC)      SET TRAP TO IGNORE DECIMAL ERRORS
SCR1     RES      0
* CODE DELETED
         LW,X5    CPER                                                  P0  0071
         BNE      *SCR1R                                                P0  0072
         BAL,X5   SIN2              INITIALIZE TABLES                   P0  0076
         B        *SCR1R                                                P0  0077
         PAGE                                                           P0  0078
*                                                                       P0  0079
*  THIS ROUTINE EDITS THE INPUT PARAMETERS,PERFORMS LEGALITY AND        P0  0080
*        CONSISTENCY CHECKS, AND ANALYZES THE MACHINE CONFIGURATION     P0  0081
*        TO DETERMINE WHETHER OR NOT THE MINIMUM REQUIREMENTS FOR A     P0  0082
*        SORT TO RUN OBTAIN.                                            P0  0083
*                                                                       P0  0084
*  AT ENTRY TO SIN1:                                                    P0  0085
*        REGISTER:  5=THE RETURN ADDRESS                                P0  0086
*                   6=LOCATION IN COMMON MEMORY OF THE PARAMETER LIST   P0  0087
*                   7=LOCATION OF THE INPUT FILE'S DCB                  P0  0088
*                                                                       P0  0089
         PAGE                                                           P0  0090
*                                                                       P0  0091
SIN1     RES      0
         STW,5    SIN1R             SAVE RETURN ADDR
         PAGE
*                                                                       P0  0094
*  THIS REGION TESTS THE VALIDITY OF THE LOGICAL RECORD LENGTH          P0  0095
*                 PARAMETER (USER FORMATTED FILES ONLY).                P0  0096
         BAL,R1   GILRL             GO GET INPUT LOGICAL RECORD LENGTH  P0  0097
         LI,X5    4                 CHARACTER COUNT                     P0  0098
         BAL,R1   CKDEC             CHECK LEGAL DIGITS:  NO ZONE BITS   P0  0099
         B        SETCD3            INVALID DIGIT IN INPUT LRL          P0  0100
SINE2    CI,X6    X'1'                                     /SIG7-1044/*CP0  0101
         BL       SETCD10           NOT MIN VALU (1 CHAR)  /SIG7-1044/*CP0  0102
         STW,X6   BCT0+8            SAVE INPUT RECORD LENGTH            P0  0103
         LW,X6    CRSF              CHECK IF CO-RESIDENT
         BEZ      SIN21X            NO.
         PAGE
* THIS REGION CHECKS COL 40
SIN121   RES      0
         LI,6     39
         LB,5     *PRAMLOC,6
         CI,5     X'40'
         BE       SIN145
         CI,5     X'C1'
         BL       SETCDH
         CI,5     X'C9'
         BL       SIN145
         CI,5     X'F3'
         BL       SETCDH
         CI,5     X'F9'
         BG       SETCDH
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BEZ      SIN122X           NO.
         PAGE
*                                                                       P0  0104
* THIS ROUTINE CHECKS COL 41-43 FOR CORE SIZE SPECIFIED                 SORTP0
* IF OK, IT STORES IT IN FPT OF M:GP, AND ASKS FOR AMOUNT USER WANTS    SORTP0
SIN145   LI,5     40                    FOR COL 41-43                   SORTP0
         LI,7     3                 3 COLS TO CHECK                     SORTP0
         BAL,9    ALLBL             IF BLANK USE 512                    SORTP0
         B        SIN15             YES BYPASS TEST                     SORTP0
         LI,5     10                                                    SORTP0
         LW,6     *PRAMLOC,5          36L 41 44                         SORTP0
         LI,5     3                                                     SORTP0
         BAL,9    CKDEC             CHECK FOR VALID DIGITS              SORTP0
         B        SETCDB            INVALID DIGIT                       SORTP0
         OR,6     =X'F0F0F0F0'                                          SORTP0
         SLS,6    -8                EBCBN NEED RIGHT JUST               SORTP0
         CW,6     =X'00F0F0F0'           ZERO BYPASS
         BE       SIN15              YES
         STW,6    CNVRT                                                 SORTP0
         BAL,9    EBCBN             GET IT BINARY                       SORTP0
         LW,6     CNVRT+1           BINARY CORE REQUEST                 SORTP0
         OR,6     =X'08000000'      STE UP M:GP FPT                     SORTP0
         STW,6    GETPG             CHANGE M:GP CORE REQUEST            SORTP0
         PAGE                                                           P0  0105
*                                                                       P0  0106
*  THIS REGION TESTS THE VALIDITY OF NUMBER OF SORT KEYS PARAMETER.     P0  0107
*                 THIS IS A REQUIRED PARAMETER.  IT MUST BE IN THE      P0  0108
*                  RANGE 1<NUMBER OF KEYS<16.                           P0  0109
SIN15    BAL,R1   GNSKY             GET NUMBER OF SORT KEYS             P0  0110
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BGZ      SINE5             YES.
         LW,R1    BCT0+8
         STW,R1   CNVRT
         BAL,R1   EBCBN
         LW,R1    CNVRT+1
         AI,9     12
         STW,R1   SEQLNG
SINE5    RES      0
         LI,X5    2                                                     P0  0111
         BAL,R1   CKDEC             CHECK FOR VALID DIGITS              P0  0112
         B        SETCD9            INVALID DIGIT IN NUMBER OF KEYS     P0  0113
         CLM,X6   SKLIM             IS NUBER:  1<NUMBER<16              P0  0114
         BCS,R1   SETCDA            NO:  ERROR                          P0  0115
SINE6    SCS,X6   16                                                    P0  0116
         STW,X6   CNVRT                                                 P0  0117
         BAL,R1   EBCBN                                                 P0  0118
         LW,X6    CNVRT+1                                               P0  0119
SINE61   STW,X6   SINTMP+2          SAVE NUMBER                         P0  0120
         LI,X5    0                                                     P0  0121
         STW,X5   SINTMP+3          COUNT KEYS                          P0  0122
SIN16    MTW,15   SINTMP+2                                              P0  0123
         BL       *SIN1R            ALL DONE                            P0  0124
         MTW,1    SINTMP+3          COUNT KEY                           P0  0125
         LW,R1    SINTMP+3                                              P0  0126
         STW,R1   CNVRT+1                                               P0  0127
         BAL,X5   BINEBC                                                P0  0128
         LW,R1    CNVRT+1                                               P0  0129
         STH,R1   EOE+1                                                 P0  0130
         STH,R1   EOF+1                                                 P0  0131
         LW,X5    KSRTC                                                 P0  0132
         BAL,R1   KSTRT             CHECK STARTING POSITION OF KEY 1    P0  0133
*                                                                       P0  0134
         LW,X5    KLNGC                                                 P0  0135
         BAL,R1   KBLNG             CHECK BYTE LENGTH OF KEY 1          P0  0136
*                                                                       P0  0137
         LI,X5    10                INCREMENT LOCATION                  P0  0138
         AWM,X5   KSRTC                      FOR                        P0  0139
         AWM,X5   KLNGC                               NEXT              P0  0140
         B        SIN16                                  KEY            P0  0141
         PAGE                                                           P0  0142
*                                                                       P0  0143
*  THIS ROUTINE INITIALIZES TABLES, SETS SIZE AND ADDRESS LIMITATIONS   P0  0144
*        FOR THE REMAINDER OF THE SORT, AND PERFORMS ALL SIZE AND       P0  0145
*        CONFIGURATION CHECKS.                                          P0  0146
*                                                                       P0  0147
         PAGE                                                           P0  0148
*                                                                       P0  0149
SIN2     STW,X5   SIN2R                                                 P0  0150
*                                                                       P0  0151
*                                                                       P0  0152
         LI,X1    1                 SET PHASE COUNT INDICATOR T0 1      P0  0153
         STH,X1   CCT0,X1           INICATING SEGMENT 1 EXECUTION       P0  0154
         LW,X6    CRSF              CHECK IF CO-RESIDENT
         BEZ      SIN2X             NO.
         STW,X1   BCT0+17           SET BLOCKING FACTOR = 1
*                                                                       P0  0156
         PAGE                                                           P0  0157
*                                                                       P0  0158
*  THIS REGION SETS ALL LOGICAL RECORD LENGTHS INTO BCT0.               P0  0159
*                                                                       P0  0160
SIN24    BAL,R1   GILRL             GET INPUT FILES RECORD LENGTH       P0  0161
         STW,X6   CNVRT                                                 P0  0162
         BAL,R1   EBCBN             GO:  CONVERTEBCDIC TO BINARY        P0  0163
         LW,X6    CNVRT+1                                               P0  0164
         LI,X7    0                                                     P0  0165
         STW,X6   RLKCM             SAVE RECORD LENGTH FOR KEY ERROR    P0  0166
         SLD,X6   -2                CONVERT TO WORDS                    P0  0167
         SLS,X7   -30                   AND BYTE INCREMENT              P0  0168
         STH,X6   BCT0+4            SET INTO BCT0 FOR LATER USE         P0  0169
         STH,X7   BCT0+15           INPUT BYTE INCREMENT                P0  0170
         LW,R1    CRSF              CHECK IF CO-RESIDENT
         BEZ      SIN24X            NO.
         STH,6    BCT0+4,1          OUTPUT LOGICAL RECORD LENGTH        P0  0173
         STH,X7   BCT0+15,X1        OUTPUT BYTE INCREMENT               P0  0174
*                                                                       P0  0175
         PAGE
*
*  THIS REGION SETS UP FOR KEY PARAMTER PROCESSING LATER.  IT
*       GENERATES THE STANDARD KTTO TABLE.
*
SIN27    RES       0
         BAL,R1   GNSKY             GO GET NUMBER OF SORT KEYS          P0  0178
         SLS,X6   -16               RIGT JUSTIFIED                      P0  0179
         STW,X6   CNVRT                 INTO CNVRT                      P0  0180
         BAL,R1   EBCBN             GO:  CONVERT EBCDIC TO BINARY       P0  0181
         LW,X6    CNVRT+1           SET THE NUMBER OF SORT KEYS         P0  0182
         STH,X6   BCT0+5,X1             INTOMBCT0 FOR LATER USE         P0  0183
*                                                                       P0  0184
         PAGE                                                           P0  0185
*                                                                       P0  0186
*  THIS REGION OBTAINS THE NUMBER OF TAPE DRIVES AVAILABLE AND          P0  0187
*       SETS THIS NUMBER INTO BCT0.                                     P0  0188
*                                                                       P0  0189
         LI,X6    39                                                    P0  0190
         LB,X5    *PRAMLOC,X6       NUMBER OF TAPE UNITS AVAILABLE      P0  0191
         CI,5     X'C8'
         BLE      SIN280
         AND,5    =X'0F'
         B        SIN281
SIN280   CI,5     X'40'
         BE       SIN283             CHECK FOR ANSI TAPES
         CI,5     X'C1'
         BNE      %+3
         LI,5     X'0A'
         B        SIN281
         CI,5     X'C2'
         BNE      %+3
         LI,5     X'0B'
         B        SIN281
         CI,5     X'C3'
         BNE      %+3
         LI,5     X'0C'
         B        SIN281
         CI,5     X'C4'
         BNE      %+3
         LI,5     X'0D'
         B        SIN281
         CI,5     X'C5'
         BNE      %+3
         LI,5     X'0E'
         B        SIN281
         CI,5     X'C6'
         BNE      %+3
         LI,5     X'0F'
         B        SIN281
         CI,5     X'C7'
         BNE      %+3
         LI,5     X'10'
         B        SIN281
         LI,5     X'11'             ASSUME H
SIN281   STH,X5   BCT0+1                INTO BCT0 FOR LATER USE         P0  0195
         STW,X5   ILT0                                                  P0  0196
         AI,X5    -1                                                    P0  0197
*                                                                       P0  0198
         LW,X7    CRSF             CHECK IF CO-RESIDENT
         BEZ      SIN285           NO.
SIN282   LW,X7    FCT0,X5           REWIND ALL SCRATCH TAPES            P0  0199
         SLS,X7   1                DW TO W ADDRESS
         STW,X7   CNVRT+1                                               P0  0201
         M:OPEN   *CNVRT+1          THIS ALLOWS ASSIGN  PARAMETERS IN DCP0  0202
         M:REW    *CNVRT+1                                              P0  0203
         BDR,X5   SIN282                                                P0  0204
*                                                                       P0  0205
         B        SIN285
SIN283   RES      0
         LW,X5    CRSF               CHECK IF CO-RESIDENT
         BNEZ     ASKTAPE            YES. GO CHECK FOR TAPES
         LI,5     6                  6 MAX DEFAULT
         B        SIN281
*
         PAGE                                                           P0  0206
*                                                                       P0  0207
*  THIS REGION COMPUTES SORT/MERGE BUFFER LENGTHS AND TESTS FOR         P0  0208
*       MINIMUM CORE REQUIREMENTS.                                      P0  0209
*                                                                       P0  0210
SIN285   RES      0
,GETPG   M:GP     512               CHANGED IF COL 41-43 SPECIFIED      SORTP0
         STW,R1   NUMPGS           SAVE FOR MESSAGE PRINT
SIN29    STW,SR2  KRASC                                    /SIG7-4137/*EP0  0215
         OR,8     =X'9000000'                                           P0  0216
         STW,8    STFP                                                  P0  0217
         STW,8    STEP                                                  P0  0218
         MTW,0    DUMPMEM           HAS USER SPEC DUMP
         BEZ      SIN2855           NO
         LW,7     8                 NUM OF PAGES
         SAS,7    9                 TO WORDS
         AW,7     9                 ADD BEGIN WORD ADDR TO GET END
         AI,7     -1
         STW,7    DUMPMEM           SAVE END VALUE
SIN2855  RES      0
         AW,SR2   KTTL                                     /SIG7-4137/*EP0  0219
         STW,SR2  KRDSC                                    /SIG7-4137/*EP0  0220
         AW,SR2   KTTL                                     /SIG7-4137/*EP0  0221
         STW,SR2  STT0                                     /SIG7-4137/*EP0  0222
         LW,X6    CRSF              CHECK IF CO-RESIDENT
         BGZ      SIN292            YES.
         SLS,SR2  2
         STW,SR2  SEQRCD
SIN292   RES      0
*                                                            /MEMORY    P0  0223
         LW,SR2   SR1                                                   P0  0224
         MI,SR1   512               DEVELOPE NUMBER OF WORDS AVAILABLE  P0  0225
         STW,SR2  BCT0+11               FOR THE SORT/MERGE OPERATION    P0  0226
         AW,SR2   KRASC                                    /SIG7-4137/*EP0  0227
         STW,SR2  BCT0+12               INTO BCT0 FOR LATER USE         P0  0228
         LW,6     BCT0+11                                  /SIG7-4137/*EP0  0229
         SW,6     KTTL                                     /SIG7-4137/*EP0  0230
         SW,6     KTTL                                     /SIG7-4137/*EP0  0231
         STW,6    BCT0+11                                  /SIG7-4137/*EP0  0232
         LW,X7    CRSF              CHECK IF CO-RESIDENT
         BEZ      SIN293X           NO
SIN295   SH,X6    BCT0+2            INPUT BUFFER LENGTH                 P0  0233
         MTW,1    SMALLSW
         SH,X6    BCT0+2                TIMES 2                         P0  0234
         BL       SETCD45           NOT ENOUGH ROOM FOR INPUT BUFFERS   P0  0235
         MTW,-1   SMALLSW
*                                                                       P0  0236
         STW,X6   BCT0+13           AVAILABLE CORE MINUS INPUT BUFFERS  P0  0237
         DH,X6    =X'60004'         DIVIDE BY 6                         P0  0238
         LH,X7    BCT0+4                                                P0  0239
         AH,X7    BCT0+4            2 TIMES SORT/MERGE RECORD LENGTH    P0  0240
         MTH,0    BCT0+15           IS THERE A BYTE INCR
         BEZ      %+2               NO
         AI,7     2                  UP TO NEXT WORD X2
         AI,7     6                  PLUS 3                /SIG7-2254/*DP0  0241
         CW,X7    X6                IS THERE ROOM FOR OUTPUT BUFFERS    P0  0242
         BLE      SIN210            YES                                 P0  0243
*                                                                       P0  0244
         LW,X6    X7                NO:  SET X6 = OUTPUT BUFFER LENGTH  P0  0245
SIN210   STH,X6   BCT0+3            STORE APPROXIMATE BUFFER LENGTH     P0  0246
         LH,X5    BCT0+4            SORT/MERGE RECORD LENGTH            P0  0247
         MTH,0    BCT0+15           IS THERE A BYTE INCR
         BEZ      %+2               NO
         AI,5     1                 UP TO NEXT WORD
         AI,5     3                                        /SIG7-3374/*EP0  0248
*                                                                       P0  0249
         STH,X5   BCT0+14           OPERATIONS RECORD LENGTH            P0  0250
         DH,X6    BCT0+14           ADJUST BUFFER LENGTH TO ACCOMODATE  P0  0251
         MH,X6    BCT0+14           EXACT MAXIMUM RECORD LENGTH         P0  0252
         LW,X6    BCT0+13           LENGTH OF CORE AVAILABLE FOR MASS   P0  0253
         SW,X6    X7                    STORAGE OF RECORDS DURING SORT  P0  0254
         SLS,X7   -1                DIVIDE BY 2                         P0  0255
         STH,X7   BCT0+3            EXACT OUTPUT BUFFER LENGTH (SORT)   P0  0256
         AI,5     2                                        /SIG7-2254/*DP0  0257
         STH,5    BCT0+14,1          REC LENGTH PLUS 3     /SIG7-2254/*DP0  0258
         DH,X6    BCT0+14,X1                                            P0  0259
         AND,X6   =X'FFFE'                                              P0  0260
         CI,X6    X'FFE'                                                P0  0261
         BLE      %+2                                                   P0  0262
         LI,X6    X'FFE'                                                P0  0263
         STH,X6   BCT0+1,X1         SET INTO BCT0 FOR LATER USE         P0  0264
         CI,X6    4                 IS THERE ROOM FOR 4 RECORDS IN THE  P0  0265
         BGE      SIN211            YES:  PERFORM MERGE TESTS           P0  0266
*                                                                       P0  0267
         LH,X6    BCT0+14           NO:  IS OUTPUT BUFFER AS SMALL      P0  0268
         MTW,2    SMALLSW
         CH,X6    BCT0+3                 AS IT CAN GET                  P0  0269
         BG       SETCD45           YES:  ERROR                         P0  0270
         MTW,-2   SMALLSW
*                             SET UP FOR MINIMUM OUTPUT BUFFERS         P0  0271
         LH,X5    BCT0+14,X1        OPERATIONAL RECORD LENGTH           P0  0272
         MH,X5    =X'60004',X1      TIMES 4                             P0  0273
         LW,X6    BCT0+13           AVAILABLE CORE MINUS INPUT BUFFERS  P0  0274
         SW,X6    X5                MINUS 4 RECORD LENGTHS              P0  0275
         LH,X7    BCT0+14,X1        EXACT BUFFER LENGTH                 P0  0276
         SLS,X7   1                 TIMES 2                             P0  0277
         B        SIN210            GO MAKE MINIMUM FIT                 P0  0278
*                                                                       P0  0279
SIN211   LW,X6    BCT0+11           NUMBER OF WORDS AVAILABLE           P0  0280
         AI,X6    -20               MINUS MTT0,MTT1 SPACE               P0  0281
         DH,X6    BCT0+1            DIVIDED BY NUMBER OF TAPES AVAILABLEP0  0282
         SLS,X6   -1                TIMES 2                             P0  0283
         CI,X6    X'1FFF'          MAX WRITE SIZE ALLOWED IN WORDS
         BLE      SIN211A          WITHIN RANGE
         LW,X6    BCT0+11          WORDS AVAILABLE
         AI,X6    -50              ARBIT REDUCE BY 50 WORDS
         STW,X6   BCT0+11          WORDS AVAILABLE
         B        SIN211           TRY AGAIN
SIN211A  RES      0
         STW,6    7                                        /SIG7-5125/*FP0  0284
         MTW,3    SMALLSW
*                                                                       P0  0287
         CH,X6    BCT0+14           NO:  IS MERGE SIZE AT LEAST A RECORDP0  0288
         BL       SETCD45           NO:  ERROR                          P0  0289
         MTW,-3   SMALLSW
*                                                                       P0  0290
         DH,X6    BCT0+14           COMPUTE BEST FIT OF BUFFER LENGTH   P0  0291
         MH,X6    BCT0+14               TO LOGICAL RECORD LENGTH        P0  0292
         CH,X7    BCT0+3            IS SORT BLOCK SMALL ENOUGH          P0  0285
         BGE      SIN212            YES:  BYPASS REDUCTION TESTS        P0  0286
         STH,X7   BCT0+3                                                P0  0293
SIN212   STH,X7   BCT0+3,X1         STORE MERGE BUFFER LENGTH           P0  0294
         MTW,4    SMALLSW
         CH,X7    BCT0+2,X1         IS THERE ROOM FOR THE OUTPUT BUFFER P0  0295
         BL       SETCD45           NO: ERROR                           P0  0296
         MTW,-4   SMALLSW
         MTW,0    BCT0+15           IS REC LEN A WORD MULTIPLE
         BEZ      SIN2120           YES
         LH,6     BCT0+3            OUT BUFFERSIZE
         LH,7     BCT0+4             OUT REC SIZE
         AI,7     4                 3 CTL WORDS + 1 ROUND UP
         MTW,5    SMALLSW
         CW,6     7                 IS OUT BUF AT LEAST 1 REC
         BL       SETCD45           NO
         MTW,-5   SMALLSW
SIN2120  RES      0
*                                                                       P0  0297
         PAGE                                                           P0  0298
*                                                                       P0  0299
*  THIS REGION SETS ACTUAL BUFFER ADDRESSES , THE STT0 ADDRESS, AND     P0  0300
*       THE MASS RECORD STORAGE BEGINNING ADDRESS INTO THE TABLES.      P0  0301
*                                                                       P0  0302
         LW,X6    STT0              BEGINNING ADDRESS OF AVAILABLE      P0  0304
         STW,6    FCT1+17
         AH,X6    BCT0+2            PLUS BUFFER LENGTH =                P0  0306
         STW,6    FCT2+17
         AH,X6    BCT0+2                                                P0  0308
         LH,X7    BCT0+1            NUMBER OF TAPES AVAILABLE           P0  0309
         AI,X7    -1                 MINUS 1                            P0  0310
         STH,X7   ILT0,X1          TAPES AVAIL TO SORT
         LW,R1    X6                                                    P0  0312
         AH,R1    BCT0+3                                                P0  0313
SIN213   STW,R1   FCT2,X7                                               P0  0314
         STW,X6   FCT1,X7                                               P0  0315
         BDR,X7   SIN213                                                P0  0316
*                                                                       P0  0317
SIN214   AH,R1    BCT0+3                                                P0  0318
         STW,R1   STT0                                                  P0  0319
         XW,R1    X6                                                    P0  0320
         LI,X1    1                                                     P0  0321
         LH,X5    BCT0+2                                                P0  0322
         STW,X5   FCT1              SET INPUT BUFFER LENGTH             P0  0323
         LH,X5    BCT0+3                                                P0  0324
         STW,X5   FCT2              SET OUTPUT BUFFER LENGTH            P0  0325
         LH,X5    BCT0+4            SET INPUT LOGICAL RECORD LENGTH     P0  0326
         STW,X5   FCT3                                                  P0  0327
         LH,X5    BCT0+4,X1         SET OUTPUT LOGICAL RECORD LENGTH    P0  0328
         AI,5     3                 PLUS 3                 /SIG7-2254/*DP0  0329
         STW,X5   FCT4                                                  P0  0330
         LW,X5    BCT0+12                                               P0  0331
         SW,X5    STT0                                                  P0  0332
         DH,X5    BCT0+14,X1                                            P0  0333
         AND,X5   =X'FFFE'                                              P0  0334
         CI,X5    X'FFE'                                                P0  0335
         BLE      %+2                                                   P0  0336
         LI,X5    X'FFE'                                                P0  0337
         STH,X5   BCT0+1,X1         NUMBER OF RECORDS IN TOURNAMENT     P0  0338
         AW,X5    STT0                                                  P0  0339
         STW,X5   MASAD                                                 P0  0340
         MTW,6    SMALLSW
         CI,X5    4                                                     P0  0341
         BL       SETCD45                                               P0  0342
         MTW,-6   SMALLSW
         LW,X6    CRSF              CHECK IF CO-RESIDENT
         BEZ      SIN214X           NO.
         PAGE
SIN222   RES      0
*                                                                       P0  0343
         LI,5     76
SIN224   LW,X4    FCT1-1,X5         CONVERT ALL WORD ADDRESSES          P0  0353
         SLS,X4   2                     TO BYTE ADDRESSES IN THE        P0  0354
         STW,X4   FCT1-1,X5             FCT TABLES                      P0  0355
         BDR,X5   SIN224                                                P0  0356
         LH,X4    BCT0+15                                               P0  0357
         AWM,X4   FCT3                                                  P0  0358
         LH,4     BCT0+15,1         OUT BYTE DISP
         AWM,4    FCT4
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BEZ      SIN230X           NO. GO TO TAPE MODUALE
         B        *SIN2R                                                P0  0359
SMALLSW  DATA     0                  IF NON ZERO ATTEMPT TO MAKE MIN FIT
         PAGE                                                           P0  0360
GILRL    LW,X6    *PRAMLOC          GET INPUT FILE'S RECORD LENGTH      P0  0361
         LI,X5    1                     INTO X6                         P0  0362
GIL1     LW,X7    *PRAMLOC,X5                                           P0  0363
         SLD,X6   8                                                     P0  0364
         B        *R1                                                   P0  0365
*                                                                       P0  0366
GKSTR    LW,X6    PRAMLOC                                               P0  0367
         SLS,X6   2                                                     P0  0368
         AW,X6    X5                SOURCE                              P0  0369
         LW,X7    =X'4000000'       COUNT                               P0  0370
         AI,X7    BA(SINTMP+4)      DESTINATION                         P0  0371
GKST1    LI,RC    0                                                     P0  0372
         STW,RC   SINTMP+4                                              P0  0373
         MBS,X6   0                                                     P0  0374
         LW,X6    SINTMP+4                                              P0  0375
         B        *R1                                                   P0  0376
*                                                                       P0  0377
GNSKY    LI,X5    24                                                    P0  0378
         LH,X6    *PRAMLOC,X5       NUMBER OF SORT KEYS                 P0  0379
         SLS,X6   16                LEFT JUSTUFIED IN X6                P0  0380
         B        *R1                                                   P0  0381
*                                                                       P0  0382
GKLNG    LW,X6    PRAMLOC                                               P0  0383
         SLS,X6   2                                                     P0  0384
         AW,X6    X5                SOURCE  ADDRESS                     P0  0385
         LW,X7    =X'3000000'       COUNT                               P0  0386
         AI,X7    BA(SINTMP+4)      DESTINATION                         P0  0387
         B        GKST1                                                 P0  0388
*                                                                       P0  0389
         PAGE                                                           P0  0390
*                                                                       P0  0391
KSTRTR   DATA     0                                                     P0  0392
*                                                                       P0  0393
KSTRT    STW,R1   KSTRTR                                                P0  0394
         BAL,R1   GKSTR             GO GET KEY 1 STARTING BYTE          P0  0395
         LI,X5    4                 COUNT                               P0  0396
         BAL,R1   CKDEC             GO CHECK FOR LEGAL DIGITS           P0  0397
         BAL,R1   SETCDE            INVALID DIGIT IN STARTING BYTE      P0  0398
         CI,X6    X'1'                                                  P0  0399
         BL       SETCD4            LESS THAN 1                         P0  0400
         B        *KSTRTR                                               P0  0401
*                                                                       P0  0402
KBLNGR   DATA     0                                                     P0  0403
*                                                                       P0  0404
KBLNG    STW,R1   KBLNGR            SAVE RETURN                         P0  0405
         BAL,R1   GKLNG             GO GET KEY LENGTH                   P0  0406
         LI,X5    3                                                     P0  0407
         BAL,R1   CKDEC            CHECK FOR VALID DIGITS               P0  0408
         BAL,R1   SETCDF            ILLEGAL DECIMAL DIGIT IN KEY LENGTH P0  0409
         CI,X6    X'1'                                                  P0  0410
         BL       SETCD4            LESS THAN 1                         P0  0411
         SLS,6    -8                                       /SIG7-4137/*EP0  0412
         STW,6    CNVRT                                    /SIG7-4137/*EP0  0413
         BAL,R1   EBCBN                                    /SIG7-4137/*EP0  0414
         LW,6     CNVRT+1                                  /SIG7-4137/*EP0  0415
         AWM,6    KTTL                                     /SIG7-4137/*EP0  0416
         SLS,6    -2                                       /SIG7-4137/*EP0  0417
         AWM,6    KTTL                                     /SIG7-4137/*EP0  0418
         B        *KBLNGR                                               P0  0419
*                                                                       P0  0420
*                                                                       P0  0421
         PAGE                                                           P0  0422
*                                                                       P0  0423
* THIS ROUTINE CKECKS FOR ILLEGAL DIGITS IN SORT CTL CARD  /SIG7-6227/*F4985
* THE ONLY VALID ARE F0-F9 EXCEPT C0-C9 ON UNIT OUT BLK    /SIG7-6227/*F4985
* 5 IS INDEX REG, 7=FF OUT BLK ,6 WORD TO BE CHECKED       /SIG7-6227/*F4985
* 9=ERROR ,9+1 NORMAL RETURN                               /SIG7-6227/*F4985
CKDEC    STW,6    SINTMP+4                                 /SIG7-6227/*F4985
         MTW,15   5                  DECREMENT BY 1        /SIG7-6227/*F4985
         CI,7     X'FF'              OUT BLK FACTOR COBOL  /SIG7-6227/*F4985
         BE       CKDEC4             IS SIGNED             /SIG7-6227/*F4985
         LI,7     X'F0'                BLANK TO ZERO       /SIG7-6227/*F4985
CKDEC1   LB,6     SINTMP+4,5         BYTE TO BE CHECKED    /SIG7-6227/*F4985
         CI,6     X'40'                                    /SIG7-6227/*F4985
         BNE      %+3                                      /SIG7-6227/*F4985
         STB,7    SINTMP+4,5         PUT  F0 IN PLACE OF 40/SIG7-6227/*F4985
         B        CKDEC2                                   /SIG7-6227/*F4985
         CI,6     X'F0'                                    /SIG7-6227/*F4985
         BL       *9                 ERROR                 /SIG7-6227/*F4985
         CI,6     X'F9'                                    /SIG7-6227/*F4985
         BG       *9                 ERROR                 /SIG7-6227/*F4985
CKDEC2   MTW,15   5                  DECREMENT BY 1        /SIG7-6227/*F4985
         CI,5     -1                 END?                  /SIG7-6227/*F4985
         BE       CKDEC3             YES                   /SIG7-6227/*F4985
         B        CKDEC1             GO DO NEXT BYTE       /SIG7-6227/*F4985
CKDEC3   AI,9     1                  RETURN PLUS 1, ALL OK /SIG7-6227/*F4985
         LW,6     SINTMP+4          RET 6 WITH DATA NO ZONE/SIG7-6227/*F4985
         AND,6    =X'F0F0F0F'                              /SIG7-6227/*F4985
         B        *9                                       /SIG7-6227/*F4985
* ONLY HERE FOR RIGHT (UNITS) BYTE OF OUTPUT BLK FACTOR.   /SIG7-6227/*F4985
CKDEC4   LB,6     SINTMP+4,5         BYTE TO BE EXAMINED   /SIG7-6227/*F4985
         LI,7     X'F0'                                    /SIG7-6227/*F4985
         CI,6     X'40'                                    /SIG7-6227/*F4985
         BNE      CKDEC5                                   /SIG7-6227/*F4985
         STB,7    SINTMP+4,5           MAKE ZERO           /SIG7-6227/*F4985
         B        CKDEC2                                   /SIG7-6227/*F4985
CKDEC5   CI,6     X'C0'                                    /SIG7-6227/*F4985
         BL       *9                                       /SIG7-6227/*F4985
         CI,6     X'CA'                     C0-C9 OK       /SIG7-6227/*F4985
         BL       CKDEC2                    C0-C9 OK       /SIG7-6227/*F4985
         CI,6     X'F0'                                    /SIG7-6227/*F4985
         BL       *9                  ERROR                /SIG7-6227/*F4985
         CI,6     X'FA'                                    /SIG7-6227/*F4985
         BL       CKDEC2              F0-F9 OK             /SIG7-6227/*F4985
         B        *9                         ERROR         /SIG7-6227/*F4985
         PAGE                                                          RP0  0445
*     THIS REGION TESTS TO SEE IF AN ARGUMENT IS ALL BLANKS            RP0  0446
*                 IF IT IS ALL BLANK   -  NORMAL RETURN                RP0  0447
*                 IF IT IS NON-BLANK  -  NORMAL RETURN PLUS ONE        RP0  0448
*                 UPON ENTRY:  X5  BYTE DISPLACEMENT WITHIN PRAMLOC    RP0  0449
*                              X7  NO OF BYTES IN ITEM                 RP0  0450
ALLBL    AI,R1    1                                                    RP0  0451
ALLBL1   LB,X6    *PRAMLOC,X5       GET BYTE                           RP0  0452
         CI,X6    C' '              COMPARE WITH BLANK                 RP0  0453
         BNE      *R1               IF NON BLANK                       RP0  0454
         AI,X5    1                 SET UP FOR NEXT BYTE               RP0  0455
         BDR,X7   ALLBL1            EXAMINED ENTIRE ITEM               RP0  0456
         MTW,15   R1                                                   RP0  0457
         B        *R1                                                  RP0  0458
*                 ILLEGAL DECIMAL DIGIT IN INPUT RECORD LRL             P0  0459
SETCD3   RES      0
         LI,15    1
         BAL,R2   ER2                                                   P0  0461
         AI,R1    1                                                     P0  0462
         B        SINE2                                                 P0  0463
*                 ILLEGAL DECIMAL DIGIT IN NUMBER OF KEYS               P0  0464
SETCD9   RES      0
         LI,15    9
         BAL,R2   ER2                                                   P0  0466
         LI,X7    17                SPEC ERR               /SIG7-1162/*CP0  0467
         B        SC5               GO ABORT               /SIG7-1162/*CP0  0468
*                                                                       P0  0469
SETCDA   RES      0
         LI,15    10
         BAL,R2   ER2                                                   P0  0471
         LI,X6    16                                                    P0  0472
         B        SINE61                                                P0  0473
SETCDB   RES      0
         LI,15    11
         BAL,10   ER2               PRINT MSG                           SORTP0
         B        SIN15             CONT CARD SCAN                      SORTP0
*                                                                       P0  0474
SETCDE   RES      0
         LI,15    14
         BAL,R2   ER2                                                   P0  0476
         AI,R1    2                                                     P0  0477
         B        *R1                                                   P0  0478
*                                                                       P0  0479
SETCDF   RES      0
         LI,15    15
         BAL,R2   ER2                   LENGTH                          P0  0481
         AI,R1    2                                                     P0  0482
         B        *R1                                                   P0  0483
SETCDH   RES      0
         LI,15    1
         BAL,10   ER2
         B        SIN145
*                                                                       P0  0484
SETCD10  RES      0
         LI,15    X'10'             PARAM VALUE NOT LEGAL MIN
         BAL,R2   ER2                                                   P0  0486
         AI,R1    2                                                     P0  0487
         B        *R1                                                   P0  0488
*                                                                      RP0  0489
SETCD45  LI,X7    4                 MEMORY OVERFLOW        /SIG7-1162/*CP0  0490
         B        SC5               GO AOBORT              /SIG7-1162/*CP0  0491
*                                                                       P0  0492
SETCD43  LI,X7    14                NOT ENOUGH SCRATCH     /SIG7-1162/*CP0  0493
         B        SC5               GO AOBRT               /SIG7-1162/*CP0  0494
*                                                                       P0  0495
EO1      TEXTC    'DCBS PARAMETER NOT VALID'
EO3      TEXTC    'INPUT RECORD LENGTH'
EO5      TEXTC    'IN/OUT BLOCKING'
EO6      TEXTC    'FORWARD SP FILE'
EO8      TEXTC    'OUTPUT RECORD LENGTH'
EO9      TEXTC    'NUMBER OF KEYS INVALID'
EOA      TEXTC    'NOT 1--16 KEYS'
EOB      TEXTC    'INVALID CORE SIZE'
EOE      TEXTC    'KEYXX:  START'
EOF      TEXTC    'KEYXX:  LENGTH'
EO13     TEXTC    'SLICE SIZE'                                         R
EO10     TEXTC    'PARAMETER VALUE LESS THAN THE LEGAL MINIMUM VALUE'
ERTBL    DATA,4   0,EO1,0,EO3,0,EO5,EO6,0,EO8,EO9
         DATA,4   EOA,EOB,,,EOE,EOF
         DATA,4   EO10,0,0,EO13                                        R
         PAGE                                                           P0  0503
*                                                                       P0  0504
ER2R     DO1      9                                                     P0  0505
         DATA     0                                                     P0  0506
*                                                                       P0  0507
ER2      STW,R2   ER2R              SAVE RETURN ADDRESS                 P0  0508
         LCI      7                                                     P0  0509
         STM,X6   ER2R+1                                                P0  0510
         LI,X6    X'11'             SPECIFICATION ERROR                 P0  0511
         STW,X6   CPER              CAUSE ABORT AFTER THIS PHASE        P0  0512
         XW,RF    X7                                                    P0  0513
         LW,R1    ERTBL,X7                                              P0  0514
         STW,R1   ER2R+8                                                P0  0515
         M:PRINT  (MESS,*ER2R+8)    PRINT MESSAGE                       P0  0516
         LCI      7                                                     P0  0517
         LM,X6    ER2R+1                                                P0  0518
         B        *ER2R             RETURN                              P0  0519
         PAGE                                                           P0  0520
*                                                                       P0  0521
ASW      DATA     0
*
ASKTAPE  LI,X5    0
ASK1     LW,X6    DCBTABLE,X5       GET DCB ADDRESS
         SLS,X6   1                 DW TO WORD ADDRESS
         STW,X6   ASW
         BCR,0    ASK3
*
ASK2     AI,X5    1
         LI,5     6                  6 MAX DEFAULT
         BL       ASK1
ASK21    CI,X5    2
         BCS,X1   SETCD43           NO:  ERROR
         BCR,0    SIN281
*
ASK3     M:SETDCB *ASW,(ERR,AWER)   TEMP ERROR RETURN      /SIG7-0740/*C4986
         M:WRITE  *ASW,(BUF,HEDBUF),(SIZE,20),(ERR,AWER)   /SIG7-0740/*C4986
         M:REW    *ASW              REWIND TO OVERWRITE
         M:SETDCB *ASW,(ERR,0)      LET MONITOR HANDLE ERR /SIG7-0740/*C4986
         BCR,0    ASK2
*
AWER     LB,X6    SR3
         CI,X6    X'49'             IS IT NO MORE TAPES
         BCR,X3   ASK21             YES:  EXIT WITH COUNT
         CI,X6    X'47'             IS IT NO TAPES OR MANY /SIG7-0740/*C4986
         BCR,X3   ASK21             YES: EXIT WITH COUNT   /SIG7-0740/*C4986
         CI,X6    X'55'             IS IT TOO MANY OPEN    /SIG7-0740/*C4986
         BCR,X3   ASK21             YES: EXIT WITH COUNT   /SIG7-0740/*C4986
ENDP0    RES      0
         BCR,0    ASK2              NO:  IGNORE
         PAGE
*
         END

