         PCC     0
*****************************************************************
*
*M*      S5SIM    SIGMA 5 EXTENDED INSTRUCTION SET SIMULATOR
*
*****************************************************************
*P*
*P*      NAME:    S5SIM
*P*
*P*      PURPOSE: TO PROVIDE SIGMA 5 USERS WHO HAVE PURCHASED
*P*               MAP AND FLOATING POINT MODULES WITH THE OTHER
*P*               INSTRUCTIONS NORMALLY CONSIDERED NECESSARY FOR
*P*               AN EFFECTIVE CP-V INSTALLATION. SUCH INSTRUCTIONS
*P*               INCLUDE THE BYTESTRING, PACKED DECIMAL, AND
*P*               CONVERT INSTRUCTIONS.
*P*
*P*      METHOD:  DURING BOOT-TIME INITIALIZATION, INITIAL AND
*P*               BOOTSUBR DETERMINE IF SUCH INSTRUCTIONS EXIST
*P*               ON THE RUNNING MACHINE, AND IF NOT, THEY INSERT
*P*               THE APPROPRIATE XPSD'S INTO TCATCH TO SEND US
*P*               HERE ON A 40 OR 41 TRAP.  IF AFTER CHECKING THE
*P*               TRAPPED INSTRUCTION, WE FIND THAT IT WAS A GOOD
*P*               INSTRUCTION, WE DROP DOWN AND SIMULATE IT FOR
*P*               THE USER. IF A NON-EXISTENT OR PROTECTION TYPE
*P*               TRAP, WE GO TO THE REGULAR TRAP PROCESSOR
*P*               ROUTINE.
*P*               THE SIMULATOR PUSHES THE USERS REGISTERS ONTO
*P*               TSTACK, AND USES THEM AS WORK AREA TO PERFORM
*P*               THE SIMULATION.  IF THERE IS NO ROOM IN THE
*P*               TSTACK, A SINGLE USER ABORT 79-02 WILL OCCUR.
*P*               (THE SUA 79-02 WILL ONLY OCCUR IF STACK OVERFLOWS
*P*               WHILE IN THE SIMULATOR).
*P*               AS A VISUAL INDICATOR THAT THE SIMULATOR IS
*P*               RUNNING, ALL THREE FLOATING POINT MODE BITS
*P*               IN THE PSD ARE SET UPON ENTRY, AND RESET
*P*               (OR RESTORED THEIR FORMER VALUE) ON EXIT.
*P*               THE SIMULATOR EXECUTES IN MASTER-PROTECTED
*P*               MODE WHENEVER THE TRAPPED OLD PSD IS SLAVE OR
*P*               MASTER-PROTECTED, TO INSURE MEMORY PROTECTION.
*P*               AS ADDITIONAL MEMORY PROTECTION, THE BOOT-TIME
*P*               ROUTINES DETERMINE WHERE THE SIMULATORS ARE AND
*P*               SET MEMORY ACCESS LOCKS ON BOTH SIDES OF THE
*P*               SIMULATOR, BUT NOT WHERE THE SIMULATOR WILL
*P*               RESIDE.  THE PSECT AND TRAILING ZEROES IN THE
*P*               MODULE WILL ASSURE THAT IT IS THE ONLY MODULE
*P*               IN THE UNPROTECTED TWO PAGES.
*P*               WE ASSUME THAT SLAVE AND UNMAPPED MODE IS AN
*P*               INVALID CONDITION.
*P*               THE SIMULATORS KNOW NOTHING ABOUT SIGMA 9-TYPE
*P*               REAL EXTENDED ADDRESSING (>128K).
*P*
*P*      NOTICE:
*P*               THERE ARE SEVERAL 'DEF'D ENTRY POINTS IN THE SIMULATOR
*P*               BEGINNING WITH F00 S5SIM.  THESE ENTRY POINTS ARE
*P*               RECOGNIZED BY BOOTSUBR AND BOOTSUBR, WHEN INSTALLING
*P*               THE PSD IN X'40' FOR THE SIMULATOR, RUNS THROUGH A
*P*               REF/DEF TABLE, REPLACING THE REF'ED LOCATION IN THE
*P*               MONITOR (WHICH CONTAINS A BYTE STRING INSTRUCTION)
*P*               WITH A BRANCH TO ONE OF THESE DEF'ED LOCATIONS.
*P*               FOR EXAMPLE, THERE IS A ROUTINE IN RDF WHICH
*P*               COMPARES KEYS USING A CBS INSTRUCTION.  BOOTSUBR
*P*               WILL REPLACE THE INSTRUCTION WITH A BRANCH TO
*P*               AN EQUIVALENT ROUTINE TO DO THE CBS (AND SETUP)
*P*               DIRECTLY, THUS SAVING DISABLE TIME, TRAP OVERHEAD
*P*               TIME, STACK SPACE, AND GENERALIZED REGISTER SETUP
*P*               FOR THE STANDARD CBS ROUTE.
*P*
*P*      NOTICE:
*P*               IN THE ABOVE VEIN, TWO ROUTINES WERE ADDED TO THE
*P*               LOADER IN F00, TO PERFORM A SIMILAR FUNCTION FOR
*P*               SIGMA 5 USERS.  SEE F00 LDR LISTING FOR DETAILS.
*P*
*P*      NOTICE:
*P*               IN ORDER TO IMPROVE RESPONSE TIME FOR ONLINE AND
*P*               REAL-TIME USERS, A SPECIAL PROVISION HAS BEEN MADE
*P*               IN THE SIMULATOR WHICH RETURNS TO THE SCHEDULER
*P*               SO THAT A MAPPED, SLAVE USER CAN BE INTERRUPTED OUT
*P*               OF HIS COMPUTE-BOUND (SIMULATOR BOUND) QUANTUM IF
*P*               A HIGHER PRIORITY USER HAS INTERRUPTED US.
*P*
*P*
*P*      NOTICE!
*P*               TO PATCH THE SIMULATORS, ONE MUST USE THE
*P*               ZERO-FILLED AREA AT THE END OF THE SIMULATORS
*P*               BECAUSE THEY ARE EXECUTE-ACCESSIBLE TO THE
*P*               USER, WHEREAS THE MONITOR PATCH AREA (MPATCH)
*P*               IS NOT.
*P*
*****************************************************************
         PAGE
*
*        PROC GENERATES DATA WITHOUT LISTING
*
FILLERUP CNAME
         PROC
         LIST     0
         DO1      AF(1)
         DATA     AF(2)
         LIST     1
         PEND
         PAGE
S5PROC   SET      1
         SYSTEM  UTS
         SPACE   2
*    AT9 = 0 FOR TRAP40 (SIG5);  AT9 = 1 FOR TRAP41 (SIG9/MOD3)
AT9      EQU     0
*    MPR = 0 TO REF AS MANY CONSTANTS AS POSSIBLE;  MPR = 1 TO
*    ASSEMBLE ALL CONSTANTS LOCALLY.
MPR      EQU     0
*    DCE = 0 TO OMIT DECIMAL INSTR'NS & EBS;  DCE = 1 NOT TO OMIT THEM;
*    DCE = 2 TO OMIT ALL ELSE (JUST KEEP DEC & EBS).
DCE      EQU     1
*    DGCK = 0 TO OMIT SOME DEC DIGIT CHECKING;  DGCK = 1 NOT TO OMIT IT
DGCK     EQU     1
*    ASCI = 0 TO OMIT CODE THAT ALLOWS GENERATION OF ANSCII ZONE/SIGN
*    CODES;  ASCI = 1 NOT TO OMIT IT.
ASCI     EQU     0
*    RPR = 0 TO OMIT CODE FOR CHECKING READ-PROTECTION OF SOURCE
*    OPERAND OF MEMORY-STORING BYTESTRING INSTRUCTIONS WITH DESTIN-
*    ATION OPERAND IN REGISTERS;  RPR = 1 NOT TO OMIT IT.
RPR      EQU     1
*    FC = FLOATING CONTROL LIGHTS TO TURN ON DURING INSTR'N SIMULATION.
FC       EQU     7
         SPACE   2
         DEF      NOPPGMX
         DEF      UNIMPX
         DEF      SIM5BEG
         DEF      SIM5END
         DEF      S5SIM:
         DEF      S5SIM
         DEF      S53A67            * EXTERNAL ENTRY POINT
         DEF      S5RDFMBS          * EXTERNAL ENTRY POINT
         DEF      S5RECTRAN         * EXTERNAL ENTRY POINT
         DEF      S5KEYTRAN         * EXTERNAL ENTRY POINT
         SPACE    2
*
*        REGISTER DEFINITIONS
*
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
         SPACE    2
         REF      NOPPSD
         REF      NOPPGM
         REF      UNIMP
         REF      STKOVF
         REF      FIXOVF
         REF      FLTFLT
         REF      DECFLT
         REF      S:HIR             * SCHEDULER SERVICE NEEDED FLAG WORD
         REF      T:SSEM            * SPECIAL EXIT FROM SIMULATOR
         DO      AT9
         REF     UNIMPPSD
         ELSE
UNIMPX   EQU     UNIMP
         FIN
         REF      TSTACK
         REF      PULLE1
         REF      S:CLOCK4
         REF      J:SIMSP
         DO      RPR
         REF     J:JAC,JOVVP
         FIN
         DO      1-MPR
         REF     Y004,X1,Y008,Y8,Y3,Y1,M7,Y07,DOUBLEONE
         REF      M2
         DO      DCE>0
         REF     YF,YE,YC,Y4,Y2,XF0,M4,XN2
         DO      ASCI
         REF     Y08
         FIN
         FIN
         FIN
         SPACE   2
         PAGE
         DATA     0                 * THIS IS PURELY FOR DEF'S BENEFIT
         PSECT    0                 * BECAUSE WE WANTED TO DO THIS
NOPPGMX  EQU     %             TRAP40 NEW PSD POINTS HERE
S5SIM:   EQU     %
S5SIM    EQU      %
         DO      AT9
         BCS,10  NOPPGM        BR (NO INTERCEPT) IF NONEXIS/PRIVIL INSTR
         FIN
         STCF    PULLE1+1      SAVE TRAP40 NEW CC
         STW,4   PULLE1        WE ARE NOW MAPPED & INHIBITED
         LW,4    NOPPSD
         CW,4    Y004
         BANZ    NOPPM0        IF TRAP OLD PSD WAS UNMAPPED,
         LPSD,0  NOPUM          THEN UNMAP
NOPPM0S  CW,4     Y008
         BANZ     NOPPM1            BR IF TRAP OLD PSD SLV UNMAP
NOPPM0   EQU     %
         DO      1-AT9
         LC      PULLE1+1
         BCR,7   NOPPM2        BR IF TRAP BECAUSE OF NONEXISTENT INSTR
         BCS,2   NOPPM1        BR IF TRAP BECAUSE OF PRIVILEGED INSTR
         FIN
         AND,4   Y008M17
         CLM,4   NOPLM         DID THE TRAP OCCUR IN THE SIMULATOR
         BCS,9   NOPPM1        NO
         LI,4    X'1FFFF'      MAYBE: USE J:SIMSP TO MAKE SURE
         AND,4   J:SIMSP
         AI,4    15
         CW,4    TSTACK
         BNE     NOPPM1        NO
         AI,4    -17           YES, ENVIRONMENT IS ALREADY STACKED
         OR,4    X1            POINT TO OLD PSD WORD 1
         XW,4    PULLE1        USE SAME RBLOCK AS STACKED ENVIRONMENT
         LRP     *PULLE1
         LB,8    PULLE1+1      GET TRAP NEW CC
NOPPM0A  LI,1    0             INDICATE TRAP40
NOPPM0B  EQU     %
         DO      FC>0
         LFI     0             TURN OFF FLOATING CONTROL LIGHTS
         FIN
*-----------------*
         DISABLE                    MAKE SURE INHIBITS ARE SET
*-----------------*
         LI,3    1             RESTORE OLD J:SIMSP
         AND,3   J:SIMSP
         LH,3    NOPLH,3
         LW,4    *TSTACK,3
         XW,4    J:SIMSP
         LI,10   -19           WE MUST UNSTACK ENVIRONMENT, SINCE
         MSP,10  TSTACK        RBLOCK PTR MAY BE NONZERO
         LI,2    -1            GET OLD PSD
         LD,10   *4,2
         STD,10  NOPPSD,1      STORE OLD PSD BACK IN 'TCATCH'
         LW,1     TRAPLOCS,1        * GET ADDR IN 'ENTRY'
         STW,1   PULLE1
         STB,8   PULLE1+1      SAVE TRAP NEW CC
         LCI     0             GET REGS
         LM,0    ,4
         LC      PULLE1+1      GET TRAP NEW CC
         LRP     X0            NOW MAKE SURE RBLOCK PTR = 0
         B       *PULLE1       ENTER 'ENTRY' FRONT END
         SPACE    5
*
*        THIS IS TRANSFER VECTOR FOR BRANCHING INTO 'ENTRY'
*        PARALLEL TO TRAP LOCATION PSD'S
*
         SPACE
TRAPLOCS EQU      %
         DATA     NOPPGM,0
         DATA     UNIMP,0
         DATA     STKOVF,0
         DATA     FIXOVF,0
         DATA     FLTFLT,0
         DATA     DECFLT,0
         SPACE    2
         SPACE   1
NOPPM1   LW,4    PULLE1        WE ARENT INTERESTED IN THIS TRAP40, SO
         LC      PULLE1+1       PRETEND WE NEVER INTERCEPTED IT
         B       NOPPGM
         SPACE   1
         DO      AT9
UNIMPX   STW,4   PULLE1        TRAP41 NEW PSD POINTS HERE
         LW,4    UNIMPPSD      WE ARE NOW MAPPED & INHIBITED
         CW,4    Y004
         BANZ    NOPPM2        IF TRAP OLD PSD WAS UNMAPPED,
         LPSD,0  UNIUM          THEN UNMAP
UNIMP1   EQU      %
         CW,4     Y008
         BAZ      NOPPM2            BR UNLESS TRP OLD PSD SLV UNMAP
UNIM1    LW,4     PULLE1            PRETEND WE NEVER GOT TRAP
         LCI      0
         B        UNIMP
         FIN
         SPACE   1
NOPPM2   EQU      %
         LI,4    X'F0'         TEST RBLOCK PTR IN TRAP OLD PSD
         DO      AT9
         AND,4   UNIMPPSD+1
         ELSE
         AND,4   NOPPSD+1
         FIN
         BE      NOPPM20       SAVE TIME IF RBLOCK PTR = 0
         CI,4    X'10'
         DO      AT9
         BG      UNIM1         BR IF NONEXISTENT RBLOCK
         ELSE
         BG      NOPPM1        BR IF NONEXISTENT RBLOCK
         FIN
         LW,4    PULLE1
         DO      AT9
         LRP     UNIMPPSD+1    SWITCH TO TRAP OLD RBLOCK
         ELSE
         LRP     NOPPSD+1      SWITCH TO TRAP OLD RBLOCK
         FIN
         STW,4   PULLE1
NOPPM20  LI,4    19            TEST TSTACK SPACE
         CH,4    TSTACK+1
         BLE     NOPPM2AA
         LW,4    PULLE1        NOT ENOUGH: SUA 79
*
*S*      SCREECH CODE:              79-02
*,*
*,*      CALLED FROM:               S5SIM
*,*
*,*      MESSAGE: SIMULATORS CAUSED TSTACK OVERFLOW
*,*
*,*      REGISTERS: Registers at time of simulation
*,*
*,*      REMARKS:   Due to simulators needing TSTACK space during
*,*               simulation, multiple trap control or other
*,*               multi-push conditions may cause this error
*,*               to occur.  This screech code can only occur
*,*               if S5SIM is installed in running system.
*
         SUA      X'79',X'02'
*
*
*
NOPPM2AA MSP,4   TSTACK        PUSH STANDARD ENVIRONMENT
         LI,4    -15
         AW,4    TSTACK
         XW,4    PULLE1
         LCFI    0,FC               TURN ON FLOATING CONTROL LIGHTS
         STM,0   *PULLE1
         LW,4    PULLE1
         DO      AT9
         LD,0    UNIMPPSD
         ELSE
         LD,0    NOPPSD
         FIN
         LI,3    -1
         STD,0   *4,3
         LI,3    1             STICK OLD CONTENTS OF J:SIMSP IN THE WORD
         AND,3   4              REMAINING JUST ABOVE/BELOW THE STACKED
         LH,3    NOPLH,3        OLD PSD
         LW,2    J:SIMSP
         STW,2   *TSTACK,3
         CW,1    Y07           KEEP 'OR' OF OLD PSD INHIBITS
         BAZ     %+2            IN R4 BIT 9
         OR,4    Y004
         CW,0    Y004          KEEP OLD PSD SLAVE/MAP/DECMASK/ASCII BITS
         BAZ     %+3            IN R4 BITS 0/1/2/4
         AND,1   Y008          REMEMBER MASTER-PROTECTED AS SLAVE
         OR,0    1
         LH,3    0
         STB,3   4
         STW,4   J:SIMSP       STORE NEW J:SIMSP (ALSO KEEP IN R4)
         LW,3    0             SET UP FOR ANLZ LOOP
NOPPM2A  CI,3    X'1FFF0'
         BANZ    %+2           IF INSTRUCTION WAS IN REGS,
         AW,3    4              THEN POINT TO IT IN STACK
         STW,3   PULLE1
         CI,4    0
         BGE     NOPPM2B       IF TRAP OLD PSD WAS SLAVE OR MSTR-PRTCTD,
         LPSD,0  NOPMA1         THEN GET MASTER-PROTECTED (PSD BIT 40)
SIM5BEG  EQU     %
NOPPM2B  LCI     5             RESTORE ALL REGS FOR ANLZ
NOPPM2B1 LM,0    ,4            R5-R15 ARE UNTOUCHED
         ANLZ,3  *PULLE1       ANLZ INSTRUCTION THAT CAUSED THE TRAP
         BCS,1   NOPPM2B3      BR IF IMMEDIATE-ADDRESSING
         BCR,2   NOPPM2B2      BR UNLESS INDIRECT-ADDRESSING
         LI,0    TSTACK        WATCH OUT: WEVE BUMPED TSTACK
         LI,1    X'1FFFF'
         CS,0    *PULLE1
         BNE     NOPPM2B2      BR UNLESS INDIRECT THRU TSTACK
         BCS,8   %+3           BR IF WORD-ADDRESSING (CC FROM ANLZ)
         AI,3    -19*4         ADJUST BA
         B       NOPPM2B2
         AI,3    -19           ADJUST WA
         DO      AT9
NOPPM2B2 CW,3    Y07           TEST HI-ORD BYTE OF ANLZ RESULTS
         BAZ     NOPPM2B4      BR UNLESS SIG9 ANLZ FOUND AN ERROR
         LW,4    J:SIMSP       RESTORE OUR R4
         B       MEMPV         TREAT AS MEM PRT VIOL
         ELSE
         B       NOPPM2B2
         FIN
NOPPM2B3 LW,3    *PULLE1       IMMED: GET INSTRUCTION ITSELF
         BLE     NOPPM2D       BR IF INDIRECT OR ZERO
NOPPM2B4 LW,4    J:SIMSP       RESTORE OUR R4
         LB,1    *PULLE1       GET OPCODE
         AND,1   M7            REMOVE INDIRECT BIT
         CI,1    X'67'
         BNE     NOPPM2C       BR UNLESS EXU
         BAL,10  UNMDA         IF WE ARE MASTER-PROTECTED, THEN
         LW,10   10,4           TURN IT OFF SO WE CAN STW IN PULLE1
*-----------------*
         DISABLE
*-----------------*
         B       NOPPM2A       LOOP TO UNWIND EXU CHAIN
NOPPM2C  LI,7    1             GET 4-BIT 'R' FIELD FROM EFFECTIVE INSTR
         LB,7    *PULLE1,7     AT LAST WE CAN UNINHIBIT,
         CW,4    Y004           UNLESS INHIBITS WERE SET IN TRP OLD PSD,
         BANZ    %+2            IN WHICH CASE WE MUST NEVER UNINHIBIT
*-----------------*
         ENABLE                     R3 HAS EFFECTIVE ADDR FROM ANLZ(OR INSTR)
*-----------------*
         SLS,7   -4            R7 HAS REGISTER NUMBER ('R')
         DO      DCE>0
         CI,1    X'76'         R1 HAS OPCODE
         BGE     DCFRNT        BR IF DECIMAL INSTRUCTION
         FIN
         LW,2    *4,7          NO: GET CONTENTS OF 'R' AND 'RU1'
         LI,5    1
         OR,5    7             R2 HAS CONTENTS OF 'R'
         LW,5    *4,5          R5 HAS CONTENTS OF 'RU1'
         DO      DCE=2
         CI,1    X'63'
         BE      BYFRNT        BR IF EBS
         ELSE
         CLM,1   DOPC1
         BCR,9   BYFRNT        BR IF BYTESTRING INSTRUCTION
         CLM,1   DOPC2
         BCR,9   CVFRNT        BR IF CONVERT INSTRUCTION
         FIN
NOPPM2D  LW,4    J:SIMSP
         DO      AT9
NOPPM3   LI,8    0             SET TRAP NEW CC
         LI,1    2             INDICATE TRAP41
         BAL,10  UNMDA         GET OUT OF MASTER-PROTECTED MODE
         B       NOPPM0B       REJOIN NORMAL TRAP PROCESSING
         ELSE
NOPPM3   LI,8    X'80'         INDICATE INVALID OPCODE
         B       NOPPM3A       JOIN NORMAL TRAP40 PROCESSING
NOPPM2B2 EQU      NOPPM2B4
         FIN
         SPACE   1
*    FRONT END FOR BYTESTRING INSTRUCTIONS
BYFRNT   EQU     %
         DO      DCE<2
         LB,6    BYTB1,1
         BE      NOPPM3        BR IF UNRECOGNIZED OPCODE
         FIN
         DO      RPR
         SD,8    8             CLEAR R8-R9
         FIN
         LB,0    5             GET BYTECOUNT FROM 'RU1'
         BNE     BYFR2         BR UNLESS BYTECOUNT = 0
         DO      1-RPR
         SD,8    8             CLEAR R8-R9
         FIN
         DO      DCE<2
         CI,1    X'1F'         BC = 0, SO INSTRUCTION IS A NO-OP,
         BANZ    BYFR1          EXCEPT FOR SETTING CC FOR CBS OR TTBS
         SLS,1   -5
         LW,9    BYTB2,1       GET MASK FOR UPDATING CC
         FIN
BYFR1    BAL,10  UNMDA
         B       STSCC
BYFR2    LI,11   0             BYTECNT NONZERO: SUPPOSE DEST NOT IN REGS
         LI,10   X'7FFFF'      FIND RIGHTMOST BYTE OF DEST STRING
         AND,10  5
         AW,10   0
         AI,10   -1
         CI,5    X'7FFC0'
         BANZ    %+2           BR UNLESS DEST BEGINS IN REGS
         AI,10   X'7FFC0'
         CI,10   X'80000'
         BAZ     BYFR3         BR UNLESS DEST OVERLAPS THRU REG 0 OR 15
         CI,1    1             IF INSTR STORES MEMORY (TBS, MBS, EBS),
         BANZ    MEMPV          THEN TREAT REG OVERLAP AS MEM PRT VIOL
BYFR3    CI,5    X'7FFC0'
         BANZ    BYFR4         BR UNLESS DEST BEGINS IN REGS
         CI,1    1
         BAZ     BYFR3A        BR UNLESS MEMORY-STORE (TBS, MBS, EBS)
         DO      RPR
         CI,4    0
         BGE     BYFR3A        BR IF TRAP OLD PSD WAS MASTER
         BAL,10  UNMDA0        GET OUT OF MASTER-PROTECTED MODE
         LW,9    Y8            INDICATE WE MUST TEST SOURCE READ-PRTCT'N
         ELSE
         BAL,10  UNMDA         GET OUT OF MASTER-PROTECTED MODE
         FIN
BYFR3A   ANLZ,11 BARG0         R11 HAS BA OF STACKED R0
         AW,5    11            ADJUST DEST ADDR TO STACKED REGS
BYFR4    LW,1    7
         BE      BYFR5         BR IF 'R' = 0 (IN WHICH CASE R1 NOW = 0)
         AW,3    2             GET TRUE SOURCE LOC IN R3 (C'R' + OFFSET)
         LI,1    1             INDICATE 'R' NONZERO
BYFR5    CI,3    X'7FFC0'
         DO      DCE=2
         BANZ    EBSX          BR UNLESS SOURCE IN REGS
         ELSE
         DO      RPR
         BANZ    BYFR6         BR UNLESS SOURCE IN REGS
         ELSE
         BANZ    BYFRNT,6      BR UNLESS SOURCE IN REGS
         FIN
         FIN
         ANLZ,3  BARG0X3       ADJUST SOURCE ADDR TO STACKED REGS
         DO      DCE<2
         DO      RPR
BYFR6    OR,1    9
         BGE     BYFRNT,6      BR UNLESS WE MUST TEST SOURCE ACCESS
         CI,6    EBSX-BYFRNT   MAYBE EBS WONT READ ALL (OR ANY) SOURCE
         BE      BYFRNT,6      BR IF EBS
         BAL,10  TRDPS         TEST READ-PROTECTION
         CI,1    1
         BAZ     BYFRNT,6      BR IF 'R' = 0
         LW,14   3             SAVE R3
         AW,3    0
         AI,3    -1            POINT TO LAST SOURCE BYTE
         BAL,10  TRDPS         TEST READ-PROTECTION
         LW,3    14            RESTORE R3
         FIN
         B       BYFRNT,6      SELECT INDIVIDUAL OPERATION
         SPACE   1
*    MOVE BYTESTRING
MBSX     LW,12    2                 SAVE SOURCE ADDRESS
         AW,12    0                 INCR BY AMOUNT TO MOVE
         CI,1     1
         BAZ      MBSXB             BR IF 'R' = 0
         CI,0     7
         BLE      MBSXB             NO SPEED-UP IF SMALL MOVE
         LI,10    X'3'
         AND,10   5
         BEZ      MBSX7             DEST ALREADY AT WORD BOUND
         AI,10    -4                - # BYTES TO WORD BOUND
         AW,0     10                DECR TOTAL BYTE COUNT
MBSX5    LB,8     0,3               MOVE ONE BYTE
         STB,8    0,5
         AI,3     1
         AI,5     1
         BIR,10   MBSX5
*
MBSX7    LW,10    0
         SLS,10   -2                # INTEGRAL WORDS REMAINING
         LI,2     X'3'
         AND,2    3                 SOURCE BYTE ALIGNMENT
         SLS,3    -2                FORM SOURCE AND DEST WORD
         SLS,5    -2                  ADDRESSES
         BEZ      MBSXW             IF R2=0, SOURCE AND DEST ALIGNED
*
         SLS,2    3                 R1 = 8, 16, OR 24
MBSXN    LW,8     0,3               GET CURRENT WORD
         LW,9     1,3                AND NEXT
         SLD,8    0,2               ALIGN DEST WORD IN R8
         STW,8    0,5
         AI,3     1
         AI,5     1
         BDR,10   MBSXN
         SLS,2    -3                RECOVER SOURCE BYTE DISPL
         B        MBSXWX
*
MBSXW    LW,8     0,3               SOURCE AND DEST ALIGNED THE SAME
         STW,8    0,5
         AI,3     1
         AI,5     1
         BDR,10   MBSXW
*
MBSXWX   SLS,5    2                 DEST TO BYTE
         AND,0    M2                # REMAINING BYTES
         BEZ      MBX               NONE
         SLS,3    2                 CONVERT TO BA
         AW,3     2                 ADD IN BYTE DISPLACEMENT
*
MBSXB    LB,8     0,3               TRANSFER BYTE-AT-A-TIME
         STB,8    0,5
         EXU      BYTB3,1           INCR R2 & R3 IF 'R' NON-ZERO
         AI,5     1
         BDR,0    MBSXB
MBX      LW,2     12                RESTORE UPDATED SOURCE ADDR
MB1      LI,9     0                 DON'T CHANGE CC'S
MB2      BAL,10   UNMDA             GET OUT OF MASTER-PROTECTED
         B        BYEND
         SPACE   1
*    COMPARE BYTESTRING
CBSX     AW,2     0                 INCR SOURCE TO END
CBSX2    LB,8     0,3
         CB,8    ,5
         BE      CB2           BR UNLESS INEQUALITY FOUND
         STCF    8
CB1      LW,9    Y3            UPDATE CC3-CC4
         SW,2     0                 DECR SOURCE BY # BYTES REMAINING
         B       MB2           FINISH UP
CB2      EXU     BYTB3,1
         AI,5    1
         BDR,0    CBSX2             LOOP BYTEWISE; FALL THRU IF STRINGS EQUAL
         B       CB1
         SPACE   1
*    TRANSLATE BYTESTRING
TBSX     LB,6    ,5
         AW,6    3
         LB,8    ,6
         STB,8   ,5
         AI,5    1
         BDR,0   TBSX          LOOP BYTEWISE
         B       MB1
         SPACE   1
*    TRANSLATE AND TEST BYTESTRING
TTBX     EXU     BYTB4,1       GET MASK IN R8
TT1      LB,6    ,5
         AW,6    3
         LB,6    ,6
         AND,6   8
         BE      TT3           BR UNLESS STOPPER HIT
         STB,6   2
         OR,8    Y1
TT2      LW,9    Y1            UPDATE CC4
         B       MB2           FINISH UP
TT3      AI,5    1
         BDR,0   TT1           LOOP BYTEWISE; FALLTHRU IF NO STOPPER HIT
         B       TT2
         FIN
         SPACE   1
*    EDIT BYTESTRING
         DO      DCE=0
EBSX     EQU     BYFRNT
         ELSE
EBSX     LI,6    -1            GET TRAP OLD PSD
         LD,8    *4,6          KEEP CC IN R8
         LI,14   0             R14 HOLDS MARKING VALUE FOR R1 (0 = NONE)
EBS1     LB,6    ,5            GET (NEXT) PATTERN BYTE
         CLM,6   ECODS
         BCS,9   EBS6          BR UNLESS ONE OF 4 SPECIAL EDIT CODES
         DO      RPR
         CI,1    0
         BGE     %+2           BR UNLESS WE MUST TEST SOURCE ACCESS
         BAL,10  TRDPS         TEST AC FOR EACH DIGIT FETCHED
         FIN
         LB,10   ,3            GET (NEXT) SOURCE DIGIT
         LC      8
         BCS,4   %+2           BR IF DIGIT IS RIGHT HALF OF BYTE
         SLS,10  -4            LEFT HALF: SHIFT
         OR,10   XF0           INSERT EBCDIC ZONE
         DO      DGCK
         LW,12   10            SAVE FOR LEGALITY TEST
         FIN
         DO      ASCI
         CW,4    Y08
         BAZ     %+2           BR UNLESS TRAP OLD PSD ANSCII BIT SET
         AI,10   X'30'-X'F0'   CHANGE EBCDIC ZONE TO ANSCII
         FIN
         CI,10   X'F'
         BAZ     %+2           BR IF DIGIT IS ZERO
         OR,8    Y2            NONZERO: SET CC3
         LW,15   5             SET UP POSSIBLE MARKING VALUE
         SW,15   11
         CI,6    X'22'
         BG      EBS2          BR IF IMMEDIATE SIGNIFICANCE START
         BE      EBS5          BR IF FIELD SEPARATOR
         LC      8
         BCS,1   EBS3          BR IF CC4 SET (SIGNFCNCE ALREADY STARTED)
         CI,10   X'F'
         BANZ    EBS2          BR IF NONZERO DIGIT
         LB,10   2             GET FILL CHARACTER
         CI,6    1
         BAZ     EBS3          BR IF DIGIT SELECT
         AI,15   1             ADD 1 TO MARKING VALUE
EBS2     LW,14   15            MARK
         OR,8    Y1            SET CC4 (START SIGNIFICANCE)
EBS3     LC      8
         BCS,4   EBS3A         BR IF CC2 SET
         LB,6    ,3
         AND,6   M4
         LB,6    DSGNS,6
         BE      EBS4          BR UNLESS RIGHT HAF OF SORCE BYTE IS SIGN
         OR,8    Y9            SUPPOSE NEGATIVE: SET CC1 & CC4
         CI,6    1
         BANZ    %+2
         AND,8   YE            POSITIVE: RESET CC4
         EOR,8   Y4            DONT INVERT CC2 (TWO EOR'S = NO-OP)
EBS3A    AD,2    DOUBLEONE     BUMP SOURCE BA (BOTH TRUE & UNDISPLACED)
EBS4     EOR,8   Y4            INVERT CC2
         DO      DGCK
         CI,12   X'FA'
         BL      EBS8          BR UNLESS ILLEGAL DIGIT
         B       DILDG
         ELSE
         B       EBS8          GO STORE ZONED DIGIT OR FILL CHAR
         FIN
EBS5     AND,8   Y4            FIELD SEP.: RESET CC1,CC3,CC4
         B       EBS7          GO STORE FILL CHAR
EBS6     LI,10   ' '           NON-EDIT CODE: GET EBCDIC BLANK
         DO      ASCI
         CW,4    Y08
         BAZ     %+2           BR UNLESS TRAP OLD PSD ANSCII BIT SET
         LI,10   X'20'         GET ANSCII BLANK
         FIN
         LC      8
         BCS,1   EBS8A         IF CC4 SET, DONT STORE ANYTHING;  ELSE,
         BCS,8   EBS8           IF CC1 SET, STORE BLANK
EBS7     LB,10   2             STORE FILL CHAR
EBS8     STB,10  ,5            REPLACE PATTERN (DEST) BYTE
EBS8A    AI,5    1             BUMP DEST BA
         BDR,0   EBS1          LOOP ON BYTECOUNT
         LW,9    YF            UPDATE CC1-CC4
         BAL,10  UNMDA
         CI,14   0             UPDATE R1 IF NEEDED
         BE      BYEND
         STW,14  1,4
         FIN
         SPACE   1
*    FINISH UP & EXIT
BYEND    SW,5    11            READJUST ENDING DEST ADDR IF IN REGS
         STB,0   5             COMBINE REMAINING BYTECOUNT WITH IT
         EXU     BYTB5,1       STORE UPDATED SOURCE ADDR IN 'R' UNLS R=0
STODD    OR,7    X1
         STW,5   *4,7          STORE UPDATED DEST ADDR & COUNT IN 'RU1'
STSCC    LI,3    -2            GET PSD LOC (EVEN)
         AND,3   4
         STS,8   -2,3          STORE CC
         MTW,1   -2,3          BUMP PSD INSTRUCTION ADDRESS
*-----------------*
         DISABLE                    MAKE SURE INHIBITS ARE SET
*-----------------*
         AND,4   YFFX1
         BGE     NOPPM4A       BR UNLESS TRAP OLD PSD WAS SLAVE
         MTW,0   *S:CLOCK4
         BL      NOPPM4A       BR UNLESS CLOCK4 COUNTER HAS RUN OUT
         LI,8    X'40'         TRIGGER CLOCK4 EZ
         WD,8    X'1700'
*
*        CHECK TO SEE IF A HIGHER PRIORITY INTERRUPT NEEDS
*        SERVICING....IF SO, AND THE USER WE ARE SERVINCING
*        IS SLAVE MAPPED (NON-MASTER, I.E. NON-MONITOR),
*        DRIVE TO THE SCHEDULER WITH THE ENVIRONMENT
*        SETUP IN THE TSTACK CORRECTLY....OTHERWISE,
*        JUST RETURN TO THE USER
*
*                                                     JLJ 06/29/78
*
NOPPM4A  EQU      %
         LH,5     NOPLH,4           *  RESTORE OLD
         LW,5     *TSTACK,5         *  J:SIMSP FROM
         STW,5    J:SIMSP           *  THE TSTACK
*
         MTW,0    S:HIR             *  ** HIGHER PRIORITY TO BE SVSD?
         BLEZ     NOPPMSP           *  NO/---> GO TO USER
*
         LW,5     Y004              *  YES/--> CHECK MASTER MAPPED
         LS,5     -2,3              *  GET MAP BIT FROM TRAPPED PSD.
         BCR,2    NOPPMSP           *  IF RESET...TO USER
*
         LPSD,0   SCHEDPSD          * GO TO SCHEDULER VIA LPSD
*                                   * (SIMPLE BRANCH WONT WORK HERE)
SCHEDPSD :PSD     (IA,T:SSEM),(MAP),(INH)
*
*
NOPPMSP  EQU      %
         LI,2    -19           EXIT: PULL ENVIRONMENT & LOAD OLD PSD
         MSP,2   TSTACK         (AVOID T:SSE AND T:PULLE)
         LI,2    2
         AW,2    TSTACK
         STW,2   PULLE1
         LCI     0
         LM,0    2,2
         LPSD,8  *PULLE1
         SPACE   1
         DO      DCE<2
*    FRONT END FOR CONVERSION INSTRUCTIONS
CVFRNT   LI,12   32
         AW,12   3             GET WA OF FAR END OF TABLE + 1
         LI,6    -32           SET ITERATION COUNT
         LI,0    0             CLEAR ACCUMULATOR FOR RESULT
         B       CVTB1,1       SELECT INDIVIDUAL OPERATION
CVTB1    EQU     %-X'28'
         B       CVSX
         SPACE   1
*    CONVERT BY ADDITION
CVAX     SLS,5   1             SHIFT OFF (NEXT) BIT IN 'RU1'
         BCR,8   CVA2          BR UNLESS BIT WAS SET
         AW,0    *12,6         ADD CORRESP. VALUE FROM TABLE TO ACCUM.
         BCR,8   CVA2          BR UNLESS CARRY-OUT
         OR,12   Y8
CVA2     BIR,6   CVAX          LOOP
         CI,0    0
         STCF    8             GET SIGN OF ACCUMULATED RESULT
         OR,8    12
         LW,9    YB            UPDATE CC1, CC3-CC4
         BAL,10  UNMDA
         STW,0   *4,7          STORE RESULT IN 'R'
         B       STSCC         FINISH UP
         SPACE   1
*    CONVERT BY SUBTRACTION
CVSX     LI,3    -1            GET MASK FOR CS
CVS1     SLS,0   1             SHIFT ACCUMULATOR TO NEXT BIT POSITION
         CS,2    *12,6
         BL      CVS2          BR UNLESS SUBTRACTION POSSIBLE
         SW,2    *12,6         SUBTRACT TABLE VALUE FROM 'R'
         AI,0    1             SET CORRESPONDING BIT IN ACCUMULATOR
CVS2     BIR,6   CVS1          LOOP
         LW,5    0
         STCF    8             GET SIGN OF RESULT
         LW,9    Y3            UPDATE CC3-CC4
         BAL,10  UNMDA
         STW,2   *4,7          STORE UNCONVERTED REMAINDER BACK IN 'R'
         B       STODD         GO STORE RESULT IN 'RU1' AND FINISH UP
         FIN
         SPACE   1
         DO      DCE>0
*    FRONT END FOR DECIMAL INSTRUCTIONS
DCFRNT   LB,6    DCTB1,1
         BE      DSAX          BR IF DSA
         CI,1    X'77'
         BG      DCFR1         BR UNLESS PACK OR UNPK
         AW,7    7
         BG      %+2
         LI,7    32
         LI,2    15
         BDR,7   DCFR2
DCFR1    CI,7    0
         BG      %+2
         LI,7    16
DCFR2    AW,3    7             R7 HAS EFF. DEC. OPRND LENGTH (BYTECOUNT)
         AI,3    -1            POINT TO RIGHTMOST (LO-ORDER) BYTE OF EDO
         CI,3    X'7FFC0'
         BANZ    DCFRNT,6      BR UNLESS LO-ORDER BYTE OF EDO IS IN REGS
         LI,5    X'77'
         CS,5    1
         BNE     DCFR3         BR UNLESS INSTR STORES MEMORY (UNPK, DST)
         CI,3    X'80000'      DOES EDO OVERLAP R0 FROM HI ADDRS
         BANZ    MEMPV         YES: TREAT AS MEM PRT VIOL
         BAL,10  UNMDA         GET OUT OF MASTER-PROTECTED MODE
DCFR3    ANLZ,3  BARG0X3       ADJUST EDO ADDR TO STACKED REGS
         B       DCFRNT,6      SELECT INDIVIDUAL OPERATION
         SPACE   1
*    PACK DECIMAL
PACKX    SD,12   12            CLEAR DECA
         LD,14   12
         LB,1    ,3            GET SIGN CODE
         SLS,1   -4
         BAL,8   D15SG1        NORMALIZE & STORE SIGN IN DECA
         LI,5    4             INIT SHIFT INDEX
PK1      LB,0    ,3            GET (NEXT) BYTE
         AND,0   M4            ISOLATE NUMERIC PORTION
         DO      DGCK
         CI,0    X'A'
         BGE     DILDG         BR IF ILLEGAL DIGIT
         FIN
         SLS,0   ,5            PACK INTO DECA
         AWM,0   ,2
         AI,5    4
         BAL,10  PU2
         BDR,7   PK1           LOOP ON BYTECOUNT
         LW,11   15
         B       DND2          FINISH UP
         SPACE   1
*    UNPACK DECIMAL
UNPKX    BAL,8   D15SG         NORMALIZE SIGN CODE
         SLS,0   4             SHIFT FOR 1ST ZONE
         LI,5    -4            INIT SHIFT INDEX
UN1      LW,6    ,2            GET (NEXT) DIGIT FROM DECA
         SLS,6   ,5
         LS,0    6             COMBINE WITH ZONE
         STB,0   ,3            STORE (NEXT) BYTE
         AI,5    -4
         BAL,10  PU2
         LI,0    X'F0'         ZONE AFTER 1ST (EBCDIC)
         DO      ASCI
         CW,4    Y08
         BAZ     %+2           BR UNLESS TRAP OLD PSD ANSCII BIT SET
         LI,0    X'30'         ZONE AFTER 1ST (ANSCII)
         FIN
         BDR,7   UN1           LOOP ON BYTECOUNT
         SAS,2   2             GET ENDING DECA INDEX
         SAS,5   -3
         AW,2    5
         AI,2    3
         B       DT2           CHECK WHETHER NONZERO DIGIT LEFT UNSTORED
         SPACE   1
PU2      CI,5    31
         BANZ    %+3
         AI,2    -1
         LI,5    0
         BDR,3   *10
         SPACE   1
*    DECIMAL LOAD
DLX      BAL,6   DPRE1         GET EDO
         LCI     4             MOVE EDO TO DECA
         LM,12   8
         LI,8    0
         B       DND2          FINISH UP
         SPACE   1
*    DECIMAL STORE
DSTX     BAL,8   D15SG         NORMALIZE SIGN CODE
         LI,2    63            INIT DECA INDEX
DT1      LB,0    ,2            MOVE (NEXT) BYTE FROM DECA TO EDO
         STB,0   ,3
         SD,2    DOUBLEONE
         BDR,7   DT1           LOOP ON BYTECOUNT
DT2      LW,9    YC            UPDATE CC1-CC2
DT3      CI,2    48
         BL      BYFR1
         LB,0    ,2
         BE      %+2           BR UNLESS NONZERO DIGIT LEFT UNSTORED
         OR,8    Y4
         BDR,2   DT3
         SPACE   1
*    DECIMAL SUBTRACT
DSX      BAL,6   DPRE          GET EDO & NORMALIZE SIGNS
         EOR,11  X1            INVERT SIGN OF EDO
         B       DAS1           AND CONTINUE SAME AS ADD
*    DECIMAL ADD
DAX      BAL,6   DPRE          GET EDO & NORMALIZE SIGNS
DAS1     LI,1    X'F0'
         LI,7    4
         BAL,6   DCPR          COMPARE OPERANDS
         B       DAS3          BR IF SIGNS UNLIKE
         BAL,6   DA1           SIGNS ALIKE: ADD MAGNITUDES
         LW,8    2
         BE      DND1          FINISH UP UNLESS CARRY-OUT (I.E., OVRFLW)
         B       DOVFL
DAS3     BGE     DAS4          SIGNS UNLIKE: BR UNLESS |DECA|<|EDO|
         XW,8    12            SWAP
         XW,9    13
         XW,10   14
         XW,11   15
DAS4     BAL,6   DS1           SUBTRACT MAGNITUDES
         B       DND           FINISH UP
         SPACE   1
*    DECIMAL COMPARE
DCX      BAL,6   DPRE          GET EDO & NORMALIZE SIGNS
         EOR,11  X1            INVERT SIGN OF EDO
         BAL,6   DCPR          COMPARE OPERANDS
         B       DC2           BR IF SIGNS WERE ORIGINALLY ALIKE
         AD,8    12            SIGNS WERE UNLIKE: RESULT IS SIMPLY SIGN
         BCS,11  DC1            IN R15, EXCEPT FOR CASE OF COMPARING 0:0
         AND,11  MNSGN
         LD,0    14
         AND,1   MNSGN
         AD,10   0
         BCR,11  DC2           BR IF BOTH OPERANDS ARE ZERO
DC1      LCI     2
DC2      STCF    8             STORE RESULT OF COMPARING |DECA|:|EDO|
         BAL,10  UNMDA
         AND,8   Y3
         BE      DND6          BR IF OPERANDS EQUAL
         CI,15   1
         BAZ     DND6          BR UNLESS DECA NEGATIVE
         EOR,8   Y3            INVERT RESULT
         B       DND6          FINISH UP
         SPACE   1
*    DECIMAL DIVIDE
DDX      BAL,5   DMDP          SETUP
         CI,12   0
         BL      DOVFL
         CD,8    12
         BG      DD3
DOVFL    LW,8    Y4            INDICATE OVERFLOW
         B       DCCFLT
DD1      AI,15   1             BUILD QUOTIENT DIGIT BY COUNTING SBTRC'NS
         LI,7    2
         BAL,6   DS1           SUBTRACT MAGNITUDES
DD2      CI,12   0
         BL      DD1
         CD,8    12
         BLE     DD1           LOOP IF ANOTHER SUBTRACTION POSSIBLE
DD3      BAL,5   DSL2          SHIFT DIVIDEND AND QUOTIENT LEFT
         BDR,10  DD2           LOOP TO BUILD NEXT DIGIT
         LI,8    0
         CW,14   15
         BCS,7   DD4           BR UNLESS QUOTIENT ZERO
         AND,11  XN2           FORCE SIGN POSITIVE
         B       DND3          FINISH UP
DD4      OR,15   11            INSERT SIGN
         B       DND4          FINISH UP
         SPACE   1
*    DECIMAL MULTIPLY
DMX      BAL,5   DMDP          SETUP
DM1      BAL,5   DSR2          SHIFT PRODUCT AND MULTIPLICAND RIGHT
DM2      CI,15   X'F'
         BAZ     DM3           BR IF MULTIPLIER DIGIT ZERO
         AI,15   -1            NO: DECREMENT IT
         LI,7    2
         BAL,6   DA1           ADD MAGNITUDES (ACCUMULATE PRODUCT)
         B       DM2           LOOP ON SAME MULTIPLIER DIGIT
DM3      BDR,10  DM1           LOOP FOR NEXT MULTIPLIER DIGIT
         OR,15   11            DONE: INSERT SIGN
         SPACE   1
DND      LI,8    0
DND1     LI,11   0
DND2     LD,0    14
         AND,1   MNSGN
         AD,0    12
         BCS,11  DND4          BR UNLESS RESULT ZERO
         AND,15  XN2           FORCE SIGN POSITIVE
DND3     OR,15   11
         B       DND5
DND4     OR,8    Y2            RESULT NONZERO: SUPPOSE POSITIVE
         CI,15   1
         BAZ     DND5          BR UNLESS RESULT NEGATIVE
         EOR,8   Y3            INVERT CC
DND5     BAL,10  UNMDA
         LCI     4             STORE UPDATED R12-R15
         STM,12  12,4
DND6     LW,9    YF            UPDATE CC1-CC4
         B       STSCC         FINISH UP
         SPACE   1
*    DECIMAL SHIFT ARITHMETIC
DSAX     BAL,8   D15SG
         LW,11   0             KEEP SIGN IN R11
         SLS,3   -2
         LI,7    1
         LAH,7   3,7           GET ABSOLUTE VALUE OF SHIFT COUNT
         BE      DSA2          BR IF NO SHIFTING TO BE DONE
         CI,7    31
         BLE     %+2
         LI,7    31            CHOP TO MAX 31
         CI,3    X'8000'
         BANZ    DSR1          BR IF SHIFT COUNT NEGATIVE
         AND,15  MNSGN
DSL1     OR,0    12            ACCUMULATE LEFTMOST DIGIT FOR OVRFLW TEST
         BAL,5   DSL2          SHIFT DECA LEFT ONE DIGIT
         BDR,7   DSL1          LOOP ON SHIFT COUNT
         CW,0    YF
         BAZ     DSA3          BR UNLESS THERE WAS OVERFLOW
         OR,8    Y4            NOTE OVERFLOW
         B       DSA3
DSR1     BAL,5   DSR2          SHIFT DECA RIGHT ONE DIGIT
         BDR,7   DSR1          LOOP ON SHIFT COUNT
DSA2     AND,15  MNSGN
DSA3     OR,15   11            INSERT SIGN
         B       DND2          FINISH UP
         SPACE   1
DSL2     LW,3    YF            SHIFT DIGITS IN R12-R15 LEFT ONE DIGIT
         LW,2    14
         STS,2   12
         SLD,14  4
         SCD,12  4
         B       ,5            RETURN
DSR2     LW,0    13            SHIFT DIGITS IN R12-R15 RIGHT ONE DIGIT
         STS,0   15
         SLD,12  -4
         SCD,14  -4
         B       ,5            RETURN
         SPACE   1
DA1      LI,2    0             ADD DIGITS IN R8-- TO DIGITS IN R12--
DA2      AW,2    7,7
         AND,2   1
         LW,0    11,7
         AND,0   1
         SCS,1   1
         AW,0    2
         LI,2    0
         BCS,8   %+3
         CS,0    TENS
         BL      DA3
         AW,0    SIXS          CARRY
         LW,2    ONES
DA3      SCS,1   -1
         STS,0   11,7
         SCS,1   4
         CI,1    X'F'
         BAZ     DA2           LOOP: NEXT DIGIT IN SAME WORD
         BDR,7   DA2           LOOP: NEXT WORD
         B       ,6            RETURN (R2 NONZERO IFF CARRY-OUT)
DS1      LI,2    0             SUBTRCT DIGITS IN R8-- FROM DGTS IN R12--
DS2      LW,0    11,7          (MAGNITUDES HAVE ALREADY BEEN TESTED)
         AND,0   1
         AW,2    7,7
         AND,2   1
         SW,0    2
         LI,2    0
         BCS,8   DS3
         AND,0   1             BORROW
         AW,0    TENS
         LW,2    ONES
DS3      STS,0   11,7
         SCS,1   4
         CI,1    X'F'
         BAZ     DS2           LOOP: NEXT DIGIT IN SAME WORD
         BDR,7   DS2           LOOP: NEXT WORD
         B       ,6            RETURN
         SPACE   1
DCPR     LI,3    1             COMPARE DECA (R12-R15) WITH EDO (R8-R11)
         LW,2    11            FIRST LOOK AT SIGNS
         CS,2    15
         BE      1,6           RETURN+1 IF SIGNS ALIKE
         LI,3    -1            SIGNS UNLIKE: COMPARE MAGNITUDES
         LI,5    -3
DCPR1    LW,2    15,5
         CS,2    11,5
         BNE     ,6            RETURN+0 WITH RESULT IN CC
         BIR,5   DCPR1         LOOP: NEXT WORD
         CI,5    1
         BE      ,6            RETURN+0 WITH RESULT IN CC
         LI,3    X'FFFF0'      AVOID SIGN BITS WHEN COMPARING MAGNITUDES
         B       DCPR1
         SPACE   1
DPRE     BAL,8   D15SG         R12-R15 ARE STILL SAME AS BEFORE TRAP
DPRE1    SD,8    8             COLLECT EFF. DEC. OPERAND INTO R8-R11
         LI,10   0
         LB,11   ,3            GET LO-ORDER BYTE
         LI,1    X'F'          NORMALIZE SIGN CODE
         AND,1   11
         LB,0    DSGNS,1
         BE      DILDG         BR IF ILLEGAL SIGN CODE
         DO      ASCI
         CW,4    Y08
         BAZ     %+2           BR UNLESS TRAP OLD PSD ANSCII BIT SET
         AI,0    -2            CHANGE EBCDIC SIGN TO ANSCII
         FIN
         LI,1    X'F'
         STS,0   11
         DO      DGCK
         CI,11   X'A0'
         BGE     DILDG         BR IF ILLEGAL DIGIT
         FIN
         LI,2    47            INIT DECA INDEX
         B       DPRE3         ENTER LOOP
DPRE2    LB,0    ,3            GET NEXT BYTE
         DO      DGCK
         CI,0    X'A0'
         BGE     DILDG         BR IF ILLEGAL DIGIT
         CS,0    TENS
         BGE     DILDG         BR IF ILLEGAL DIGIT
         FIN
         STB,0   ,2
DPRE3    SD,2    DOUBLEONE
         BDR,7   DPRE2         LOOP: NEXT BYTE
         B       ,6            RETURN (LEAVE MASK IN R1)
         SPACE   1
D15SG    LI,1    X'F'          NORMALIZE SIGN IN R15
         AND,1   15
D15SG1   LB,0    DSGNS,1
         BE      DILDG         BR IF ILLEGAL SIGN CODE
         DO      ASCI
         CW,4    Y08
         BAZ     %+2           BR UNLESS TRAP OLD PSD ANSCII BIT SET
         AI,0    -2            CHANGE EBCDIC SIGN TO ANSCII
         FIN
         LI,1    X'F'          REPLACE IN R15
         STS,0   15
         B       *8            RETURN (LEAVE SGN ALSO IN R0 & MSK IN R1)
         SPACE   1
DMDP     CI,7    8             SET UP FOR DEC MULTIPLY OR DIVIDE
         BG      DILDG         BR IF ILLEGAL COUNT
         BAL,6   DPRE
         LD,8    10            MOVE EDO (CANT BE > 2 REGS)
         SLD,8   -4
         AND,11  X1            KEEP SIGN OF RESULT IN R11
         EOR,11  15
         AND,11  M4
         LI,10   16            SET ITERATION COUNT FOR OUTER LOOP
         B       ,5            RETURN
         SPACE   1
DILDG    LW,8    Y8            INDICATE ILLEGAL DIGIT OR SIGN CODE
DCCFLT   LW,9    YC            FAULT: UPDATE CC1-CC2
         BAL,10  UNMDA         GET OUT OF MASTER-PROTECTED MODE
         LC      4
         BCR,2   STSCC         BR UNLESS TRAP OLD PSD ALLOWS DEC TRAP
         LI,3    -2            GET PSD LOC (EVEN)
         AND,3   4
         STS,8   -2,3          UPDATE (OLD) CC
         LI,8    0             SET TRAP NEW CC
         LI,1    10            INDICATE TRAP45
         B       NOPPM0B       REJOIN NORMAL TRAP PROCESSING
         FIN
         SPACE   1
         DO      RPR
TRDPS    LD,12   6             TEST ACCESS CODE FOR BA IN R3
         LI,6    X'7FFFF'      PRESERVE ALL INDEX REGS
         AND,6   3
         SLS,6   -11           SHIFT BA TO PA
         CI,6    JOVVP         IF BELOW LOWER LIMIT OF AC IMAGE,
         BL      MEMPV          THEN ASSUME READ-PROTECTION VIOLATION
         LI,7    3             SPLIT PA INTO BYTE OFFSET & REMAINDER
         AND,7   6
         SLS,6   -2
         LB,6    J:JAC,6       GET BYTE FROM AC IMAGE
         LB,7    ACBTS,7       GET 2 TEST BITS
         CS,7    6
         STD,12  6
         BNE     *10           RETURN UNLESS AC CODE = 11
         FIN
         SPACE   1
MEMPV    LI,8    X'10'         INDICATE MEM PROTECTION VIOLATION
NOPPM3A  LI,10   NOPPM0A       SET EXIT FOR UNMDA
         SPACE   1
UNMDA    CI,4    0
         BGE     *10           RTRN UNLESS TRAP OLD PSD WAS SLAVE
UNMDA0   CW,4    Y004           OR MASTER-PROTECTED
         BAZ     %+2           BR UNLESS WE MUST STAY INHIBITED
         LPSD,0  NOPMA2        GET OUT OF MASTER-PROTECTED
         LPSD,0  NOPMA3        GET OUT OF MASTER-PROTECTED
UNMDA1   B       *10           RETURN
         SPACE   1
         DO      DCE<2
BYTB1    EQU     %-X'10'
         DATA,1  TTBX-BYFRNT,TBSX-BYFRNT,0,0
X0       DATA    0,0,0,0,0,0,0
         DATA,1  CBSX-BYFRNT,MBSX-BYFRNT,0,EBSX-BYFRNT
         BOUND   4
BYTB2    EQU     %-2
         DATA    X'10000000',X'30000000'
BYTB3    NOP
         AI,3     1
BYTB4    LI,8    X'FF'
         LB,8    2
         FIN
BYTB5    NOP
         STW,2   *4,7
         DO      DCE>0
DCTB1    EQU     %-X'1D'
         DATA,1  0,0,PACKX-DCFRNT,UNPKX-DCFRNT
         DATA,1  DSX-DCFRNT,DAX-DCFRNT,DDX-DCFRNT,DMX-DCFRNT
         DATA,1  0,DCX-DCFRNT,DLX-DCFRNT,DSTX-DCFRNT
         BOUND   4
         SPACE   1
DSGNS    DATA    0,0,X'00000C0D',X'0C0D0C0C'
MNSGN    DATA    X'FFFFFFF0'
Y9       DATA    X'90000000'
TENS     DATA    X'AAAAAAAA'
SIXS     DATA    X'66666666'
ONES     DATA    X'11111111'
         FIN
         DO      DCE<2
YB       DATA    X'B0000000'
         FIN
         DO      RPR
ACBTS    DATA    X'C0300C03'
         FIN
YFFX1    DATA    X'FF000001'
Y008M17  DATA    X'0081FFFF'
NOPLH    GEN,16,16  -18,-16
BARG0    LB,0    *4
BARG0X3  LB,0    *4,3
         BOUND   8
         DO      DCE<2
DOPC1    DATA    X'40',X'63'
DOPC2    DATA    X'28',X'29'
         FIN
         DO      DCE>0
ECODS    DATA    X'20',X'23'
         FIN
NOPLM    GEN,15,17  0,SIM5BEG
         GEN,15,17  0,SIM5END
NOPUM    GEN,8,2,5,17 0,0,0,NOPPM0S
         GEN,4,4,1,23  1,7,0,0
         DO      AT9
UNIUM    GEN,8,2,5,17 0,0,0,UNIMP1
         GEN,4,4,1,23  1,7,0,0
         FIN
NOPMA1   GEN,8,2,5,17  X'57',1,0,NOPPM2B1
         GEN,4,4,1,23  1,7,1,0
NOPMA2   GEN,8,2,5,17  0,1,0,UNMDA1
         GEN,4,4,1,23  1,7,0,0
NOPMA3   GEN,8,2,5,17  0,1,0,UNMDA1
         GEN,4,4,1,23  1,0,0,0
         DO      MPR
Y8       DATA    X'80000000'
Y3       DATA    X'30000000'
Y1       DATA    X'10000000'
Y07      DATA    X'7000000'
Y008     DATA    X'800000'
Y004     DATA    X'400000'
M7       DATA    X'7F'
         DO      DCE>0
XN2      DATA    -2
YF       DATA    X'F0000000'
YE       DATA    X'E0000000'
YC       DATA    X'C0000000'
Y4       DATA    X'40000000'
Y2       DATA    X'20000000'
XF0      DATA    X'F0'
M4       DATA    X'F'
M2       DATA     X'3'
         DO      ASCI
Y08      DATA    X'8000000'
         FIN
         FIN
         BOUND   8
DOUBLEONE DATA   1,1
X1       EQU     DOUBLEONE
         FIN
         PAGE
*
*        THIS ROUTINE SUBSTITUTES INLINE CODE FOR A CBS ROUTINE
*        IN RDF (BOOTSUBR REPLACES A DEF'D LOCATION WITH A
*        BRANCH HERE AT BOOT TIME)
*
         SPACE    1
S53A67   EQU      %
         PUSH     2,R2              * SAVE R2 & R3
         LW,R2    R0                *
         CB,R0    0,R4              *
         BE       S53A66A           ***
         BL       S53A66            ***
         LB,R2    0,R4              *
         OR,R0    Y3                *
         SPACE    1                 *
S53A66   EQU      %                 *
         EOR,R0   Y2                *
         SPACE    1                 *
S53A66A  EQU      %
         AI,R4    1                 *
         LB,R3    0,R4              *
         CB,R3    0,R5              *
         BNE      S53A66B           *
         SPACE    1                 *
         AI,R5    1                 *
         BDR,R2   S53A66A           *
         SPACE    1                 *
S53A67X  EQU      %
         PULL     2,R2              * GET BACK R2 & R3
         LC       R0                * AND CONDITION CODES
         B        0,R1              * RETURN
         SPACE
S53A66B  EQU      %
         STCF     R0                * SAVE CC'S FROM COMPARE
         B        S53A67X           * GET OUT
         PAGE                       *
*                                   *
*
*        THIS ROUTINE REPLACES A MBS IN RDF....NOTE THAT IT USES
*        A COMMON MBS-STYLE ROUTINE AFTER SETTING UP THE REGISTERS
*        AND THAT IT SHARES THIS ROUTINE WITH THE IORT (RECTRAN)
*        SUBSTITUTE
*
         SPACE    1
S5RDFMBS EQU      %
         PUSH     9,R12             * SAVE R12-R4
         LW,R1    R2                * GET COUNT IN R1
         LD,R2    R12               * AND SOURCE/DEST IN R2/R3
         BAL,R0   S5LOCALMBS        * GO DO MOVE BYTESTRING
         PULL     9,R12             * GET BACK REGS
         AW,R12   R2                * ADD COUNT TO SOURCE BA
         AW,R13   R2                * AND DESTINATION BA
         LI,R2    0                 * ZERO THE COUNT
         B        0,R4              * AND RETURN TO CALLER (NOT
*                                   * NECESSARILY RDF)
         SPACE    3
*
*        RECTRAN GOES HERE FROM IORT ON A SIGMA 5.....NOTE
*        DOUBLE PULL ON RETURN TO SAVE TIME
*
         SPACE    1
S5RECTRAN EQU     %
         PUSH     9,R12             * SAVE R12-R4
         LW,R1    R2                * COUNT IN R1
         LD,R2    R14               * SOURCE/DEST IN R2/R3
         BAL,R0   S5LOCALMBS        * **** DO THE MBS
         PULL     9,R12             * GET BACK REGISTERS
         PULL     5,R14             * AND DO A RECTRAN RETURN
         B        *R11              * GO BACK TO RECTRAN CALLER
         PAGE
*
*        THIS IS THE GENERALIZED SUBSTITUTE BYTE STRING MOVER
*        COME HERE ON
*                 BAL,0             .....
*
*        R1=BYTE COUNT
*        R2=SOURCE BYTE ADDRESS
*        R3=DESTINATION BYTE ADDRESS
*
         SPACE
S5LOCALMBS EQU    %
         SPACE    1
         CI,R1    7                 * IS COUNT <= 7....SKIP SETUP
         BLE      LCL6              * AND DO BYTE AT A TIME
         SPACE    1
         LI,R4    X'3'              * GET DESTINATION OFFSET IN BYTES
         AND,R4   R3                *
         BEZ      LCL2              * IF ALREADY WORD ADDR, SKIP SETUP
         SPACE    1
         AI,R4    -4                * MODIFY BYTE COUNT IN R1
         AW,R1    R4                * AND SETUP LOOP COUNTER
         SPACE    1
LCL1     EQU      %
         LB,R15   0,R2              * GET-A-BYTE
         STB,R15  0,R3              * STORE-A-BYTE
         AI,R2    1                 * UP INDEX
         AI,R3    1                 * UP INDEX
         BIR,R4   LCL1              * AND BACK FOR MORE
         SPACE    1
LCL2     EQU      %
         LW,R14   R1                * GET COUNT IN R14
         SLS,R14  -2                * AND WORD COUNT
         LI,R4    X'3'              * GET MASK IN R4 TO FIND
         AND,R4   R2                * SOURCE OFFSET IN BYTES
         SLS,R2   -2                * SOURCE IN WORD ADDR
         SLS,R3   -2                * DEST IN WORD ADDR
         BEZ      LCL4              * IF R4 = 0 THEN SOURCE =WADDR
         SPACE
         SLS,R4   3                 * NOW R4 = 8,16 OR 24 (SHIFT COUNT)
         SPACE    1
LCL3     EQU      %
         LW,R12   0,R2              * GET-A-WORD
         LW,R13   1,R2              * AND ITS NEIGHBOR
         SLD,R12  0,R4              * SHIFTED BY COUNT IN R4
         STW,R12  0,R3              * AND STORED IN DESTINATION
         AI,R2    1                 * UP THE INDEX
         AI,R3    1                 * AND THE OTHER INDEX
         BDR,R14  LCL3              * AND TRY AGAIN
         SLS,R4   -3                * PUT R4 BACK IN SHAPE
         B        LCL5              * GO TO CLEANUP
         SPACE    1
LCL4     EQU      %                 * SPECIAL FOR PRE-ALIGNED
         LW,R12   0,R2              * GET-1
         STW,R12  0,R3              * STORE-1
         AI,R2    1                 * UP INDEX
         AI,R3    1                 * AND AGAIN
         BDR,R14  LCL4              * BACK FOR MORE
*                                   * FALL INTO LCL5
         SPACE    1
LCL5     EQU      %
         SLS,R3   2                 * BACK TO BYTE ADDRESS
         AND,R1   M2                * GET LAST 2 BITS (OFFSET AMT)
         BEZ      *R0               * IF NO MORE...KISS IT BYE-BYE
         SPACE
         SLS,R2   2                 * GET BA OF SOURCE, TOO
         AW,R2    R4                * AND MAKE COUNTS ALRIGHT
         SPACE
LCL6     EQU      %
         LB,R12   0,R2              * FINISH UP THE LAST FEW (OR THE
         STB,R12  0,R3              * SHORT CASE <=7)
         AI,R2    1
         AI,R3    1                 * UP COUNTERS
         BDR,R1   LCL6              * AND BACK
         B        *R0               * RETURN TO CALLER
         PAGE
*
*        THIS ROUTINE REPLACES MBS IN RDF THAT
*        MOVES KEYS...SINCE WE KNOW THAT ITS LESS THAN 32 JUST
*        DO A BYTE-BY-BYTE...SAVES TIME (MAYBE)
*
         SPACE    1
S5KEYTRAN EQU     %
         PUSH     1,R1              * SAVE R1
         SPACE
         LB,R1    R5                * GET COUNT FROM R5
         CI,R1    0                 * IS IT = 0
         BEZ      S5KEYTRANOUT      * YEP, SKIP MOVE
         LB,R1    0,R4              * START-EM MOVING
         STB,R1   0,R5              *
         AI,R4    1                 *
         AI,R5    1                 * UP INDICES
         MTB,-1   R5                * DOWN COUNT
         BNEZ     %-5               * CBAK FOR MORE
         SPACE
S5KEYTRANOUT EQU  %
         PULL     1,R1              * GET SAVED REG BACK
         B        0,R1              * RETURN
         PAGE
ENDžOFžPROCEDURE EQU %
*
*        FILL OUT THE REST OF TWO PAGE SEGMENT WITH ZEROES
*        TO ENSURE PROTECTED MONITOR IF NECESSARY
*
         FILLERUP 1024-(ENDžOFžPROCEDURE-S5SIM:),0
SIM5END  EQU      %-1
         END

