         SYSTEM   SIG7FDP                                               C:SRT
         SYSTEM   BPM
*        CONTROLLER FOR CO-RESIDENT SORT                                C:SRT
*                                                                       C:SRT
*        REGISTERS                                                      C:SRT
R14      EQU      14
R2       EQU      2                                                     C:SRT
R3       EQU      3                                                     C:SRT
R4       EQU      4                                                     C:SRT
R5       EQU      5                                                     C:SRT
R6       EQU      6                                                     C:SRT
R7       EQU      7                                                     C:SRT
R8       EQU      8                                                     C:SRT
L1       EQU      11                                                    C:SRT
*                                                                       C:SRT
RET      DATA     0                 RETURN TO USER                      C:SRT
SRET     DATA     0                 RETURN TO SORT                      C:SRT
SAV1%6   RES       6                                                    C:SRT
SAV9%F   RES       7                                                    C:SRT
ISCNT    DATA     0
CRSIO    DATA     0                                                     C:SRT
MASK     DATA     X'0001FFFF'                                           C:SRT
CRSF     DATA     X'FF000000'                                           SRT
REC      DATA     0                 MBS INSTRUCTIONS                    C:SRT
RECNT    DATA     0                                                     C:SRT
FILEADR  DATA     0
         DEF      C:SRT,C:WSR,C:RSR                                     C:SRT
         REF      C:ABA
         REF      I::%
         REF      C:ALLC
         REF      S:SORTC           SORT ENTRY                          C:SRT
         DEF      S:INPUT,S:OUTPUT  SORT RETURNS                        C:SRT
         PAGE                                                           C:SRT
C:SRT    RES      0                                                     C:SRT
         STW,L1   RET               SAVE RETURN TO USER                 C:SRT
         STB,R5   CRSIO                                                 C:SRT
         STW,R6   FILEADR
SRT%1    RES      0
         LW,R5    ISCNT
         LW,R6     I::%,R5
         BEZ      SRT%2
         MTW,1    ISCNT
         LW,R3    0,R6
         BAL,L1   C:ALLC
         B        SRT%1
SRT%2    RES      0
         LI,R7    0                 INPUT OR OUTPUT                     C:SRT
         LW,R6    FILEADR
         BAL,L1   S:SORTC           INITIATE SORT                       C:SRT
         CI,R6    0
         BE       *RET
         LB,R8    CRSF
         BEZ      *RET
         LI,R8    13
         STB,R8   10
         BAL,R8   C:ABA
         B        *RET              RETURN TO ATEND OPTION              C:SRT
*                                                                       C:SRT
*        RETURN TO SORT WITH INPUT RECORD                               C:SRT
*        R7 : ADDRESS OF RECORD TO BE PASSED                            C:SRT
*        R8 : RECORD SIZE (BYTES)                                       C:SRT
*                                                                       C:SRT
C:WSR    RES      0                                                     C:SRT
         STW,L1   RET               SAVE RETURN TO USER                 C:SRT
         CI,R6    0                                                     C:SRT
         BE       EOW               END OF INPUT TO SORT                C:SRT
         LW,R6    6,R6              RECORD SIZE,RECORD ADDRESS FROM I:  C:SRT
         LW,R8    R2                RECORD SIZE                         C:SRT
         LB,R7    CRSIO                                                 C:SRT
         CI,R7    1                 CHECK SORT OPTIONS                  C:SRT
         BNE      WSR%1             NOT USING                           C:SRT
         LH,R8    R6                LOAD RECORD SIZE                    C:SRT
         SLS,R8   -1                SHIFT OFF LAST BIT                  C:SRT
WSR%1    RES      0                                                     C:SRT
         AND,R6   MASK              STRIP RECORD SIZE                   C:SRT
         SLS,R6   2                 WA(RECORD) TO BA                    C:SRT
         LW,R7    R6                                                    C:SRT
         B         LMSRET           RETURN TO SORT                      C:SRT
*                                                                       C:SRT
*        RETURN TO SORT FOR OUTPUT RECORD                               C:SRT
*        R6 : ADDRESS OF RECEIVING FIELD                                C:SRT
*                                                                       C:SRT
C:RSR    RES      0                                                     C:SRT
         STW,L1   RET               SAVE RETURN TO USER                 C:SRT
         LW,R4    REC               SOURCE ADDRESS
         BEZ      RSR%0
         CI,R7    512
         BNE      RSR%00
         LB,R7    CRSF
         BEZ       LMSRET           RETURN TO SORT                      C:SRT
         MTW,1    RET
         B        *RET
RSR%0    RES      0
         LI,R2    1
         STW,R2   REC
         STB,R2   CRSF
         MTW,1    RET
         B         LMSRET           RETURN TO SORT                      C:SRT
RSR%00   RES      0
         LW,R2    RECNT             RECORD SIZE
         LW,R8    R2
         LW,R5    6,R6              RECORD ADDRESS FROM I:
         AND,R5   MASK              STRIP RECORD SIZE
         SLS,R5   2                 RECORD ADDRESS TO BA
RSR%1    RES      0
         CI,R8    255                                                   C:SRT
         BLE      RSR%2             NOT > 255 BYTES
         LI,R7    255                                                   C:SRT
         STB,R7   R5                STORE 255                           C:SRT
         MBS,R4   0                 MOVE 255 BYTES                      C:SRT
         AI,R8    -255              DECREMENT RECORD SIZE BY 255        C:SRT
         B        RSR%1             REPEAT
RSR%2    RES      0
         STB,R8   R5                STORE ACTUAL OR REMAINING SIZE      C:SRT
         MBS,R4   0                 MBS LESS THAN 255                   C:SRT
         LI,R7    1
         B         LMSRET           RETURN TO SORT                      C:SRT
*        END OF INPUT TO SORT                                           C:SRT
EOW      RES      0                                                     C:SRT
         LI,R7    0                 NO MORE DATA RECORDS FOR SORT       C:SRT
         B         LMSRET           RETURN TO SORT                      C:SRT
*                                                                       C:SRT
*                                                                       C:SRT
*                                                                       C:SRT
         PAGE                                                           C:SRT
S:INPUT  RES      0                                                     C:SRT
         STW,L1   SRET              SAVE RETURN TO SORT                 C:SRT
         LCI       6                                                    C:SRT
         STM,1     SAV1%6           SAVE REG 1-- REG 6                  C:SRT
         LCI       7                                                    C:SRT
         STM,9     SAV9%F           SAVE REG 9 -- REG F                 C:SRT
         B        *RET              RETURN TO USER FOR MORE             C:SRT
*        RETURN FROM SORT LOOKING FOR MORE                              C:SRT
*                                                                       C:SRT
*        RETURN FROM SORT WITH RECORD                                   C:SRT
*        R7: ADDRESS OF OUTPUT RECORD                                   C:SRT
*        R8: RECORD SIZE (BYTES)                                        C:SRT
*                                                                       C:SRT
S:OUTPUT RES      0                                                     C:SRT
         STW,L1   SRET                                                  C:SRT
         STW,R7   REC               SAVE SORCE ADDRESS
         LCI       6                                                    C:SRT
         STM,1     SAV1%6           SAVE REG 1-- REG 6                  C:SRT
         LCI       7                                                    C:SRT
         STM,9     SAV9%F           SAVE REG 9 -- REG F                 C:SRT
         LW,R2    R8
         XW,R2    RECNT                                                 C:SRT
         BNEZ     *RET                                                  C:SRT
         LW,R2    RECNT                                                 C:SRT
         B        *RET              RETURN TO USER
LMSRET   RES       0                                                    C:SRT
         LCI       6                                                    C:SRT
         LM,1      SAV1%6           LOAD REG 1 -- REG 6                 C:SRT
         LCI       7                                                    C:SRT
         LM,9      SAV9%F           LOAD REG 9 -- REG F                 C:SRT
         B         *SRET            RETURN                              C:SRT
         END                                                            C:SRT
