         PCC      0
*M*      TRAPC  M:STRAP,M:XCON,M:INT,M:STIMER,M:TTIMER HANDLER
         SPACE    2
*P*      NAME:    TRAPC
*P*      PURPOSE:
*P*               TO PROCESS THE FOLLOWING CALLS
*P*               1. M:STRAP - TO INSURE TRAP BEING SIMULATED
*P*                            IS VALID OTHER PROCESSING IN
*P*                            DONE  IN ALTCP
*P*               2. M:XCON -  TO ESTABLISH EXIT CONTROL
*P*               3. M:INT -   TO ESTABLISH USER ROUTINE ADDRESS
*P*                            TO ENTER IN RESPONSE TO AN INT
*P*                            KEYIN
*P*               4. M:STIMER - TO THE THE INTERVAL TIMER
*P*               5. M:TTIMER - TO TEST AND/OR CANCEL THE INTERVAL TIMER
         SPACE    1
*P*      DESCRIPTION:
*P*               TRAPC RESIDES IN MISOV
*P*               INITIAL DECODING IS PERFORMED IN ALTCP
*P*               FOR ALL ENTRIES WITHIN THIS MODULE, CAUSING
*P*               ENTRANCE TO UCAL WHICH IMMEDIATELY BRANCHES
*P*               TO THE APPROPRIATE ENTRY
*P*      REFERENCE:
*P*               SEE REPORTS F AND D
         PAGE
UFLAGS   SET      1
BITS     SET      1                 GET DEFINITIONS OF XN, YN, MN.
         SYSTEM   UTS
         DEF      TRAPC:            PATCHING DEF
TRAPC:   RES
         SPACE    1
*        DEFS
         SPACE    1
         DEF      MSTRAP            ENTRY TO M:STRAP PROCESSING
         DEF      MXCON             ENTRY TO M:XCON PROCESSING
         DEF      MINT              ENTRY TO M:INT PROCESSING
         DEF      MSTIMER           ENTRY TO M:STIMER PROCESSING
         DEF      MTTIMER           ENTRY TO M:TTIMER PROCESSING
         PAGE
*        REFS - DATA
         SPACE    1
         REF      S:CUN             CURRENT USER
         REF      UH:FLG            TIC BIT (X'80')
         REF      UH:FLG2           CP BREAK BIT (X'4000')
         REF      J:TCB             TCB ADDRESS
         REF      J:EXTENT          EXIT CONTROL FLAGS & ADDRESS
         REF      J:INTENT          BREAK CONTROL ADDRESS
         REF      J:TIMENT          TIME OUT ADDRESS FROM M:STIMER
         REF      J:UTIMER          TIME INTERVAL SPECIFIED ON M:STIMER
         REF      J:IDELTAT         -(TIME IN A QUANTUM)
         REF      J:DELTAT          -(TIME LEFT IN CURRENT QUANTUM)
         REF      J:OVHTIM          TIME IN MONITOR THIS CAL.
         REF      TSTACK            TSTACK
         SPACE    1
*        REFS - ROUTINES
         SPACE    1
         REF      T:ABORTM          ABORT USER FOR ILLEGAL M:STRAP LOC
         REF      CC1SET            EXIT WHEN CC1 TO BE SET
*,*                                 UPON RETURN TO CAL+1
         REF      CC0RST            EXIT WHEN CC1 TO BE RESET
*,*                                 UPON RETURN TO CAL+1
         REF      MSTRAPXIT         FINAL PROCESSING RETURN FOR
*,*                                 MSTRAP AFTER RETUN TO TMPTOSTK
         REF      TMPTOSTK          INTIAL EXIT POINT FOR MSTRAP
         PAGE
*                 SYMBOLIC 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
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
*F*      NAME:    MSTRAP
         SPACE    1
*F*      PURPOSE:
*F*               TO INSURE THAT THE TRAP BEING SIMULATED IS
*F*               X'40'-X'45' OR X'48'-X'4B'
         SPACE    1
*F*      DESCRIPTION:
*F*               ONLY TRAPS X'40'-X'45' OR X'48'-X'4B' MAY BE
*F*               SIMULATED ALL OTHERS CAUSE AN ILLEGAL TRAP
*F*               EXIT THROUGH T:ABORTM
         SPACE    1
*F*      REFERENCE:
*F*               SEE REPORT D
         PAGE
*D*      NAME:    MSTRAP
         SPACE    1
*D*      REGISTERS:
*D*               USES R1,R6,R14
*D*               NONE ARE SAVED
         SPACE    1
*D*      CALL:
*D*               SEE REPORT P
         SPACE    1
*D*      ENVIRONMENT:
*D*               MAPPED, MASTER, NO INHIBITS
         SPACE    1
*D*      OUTPUT:
*D*               R1 CONTAINS THE CONTENTS OF THE PHYSICAL
*D*               TRAP LOCATION BEING SIMULATED IF THE TRAP
*D*               BEING SIMULATED IS VALID
         SPACE    1
*D*      DESCRIPTION:
*D*               MSTRAP ACCESSES FROM THE USERS STACK
*D*               THE TRAP THAT IS BEING SIMULATED AND IF IN THE
*D*               VALID RANGE OF X'40'-X'45' OR X'48'-X'4B'
*D*               THEN RETURN IS MADE TO ALTCP TO MOVE THE
*D*               TEMP STACK TO THE USER'S STACK AND VALIDATE
*D*               THE PSD AND PERFORM FINAL PROCESSING AT MSTRAPXIT
*D*               IF THE TRAP IS NOT VALID THEN AN ABORT EXIT IS
*D*               MADE TO T:ABORTM WITH AN ERROR CODE OF A302
         SPACE    2
*E*      ERROR:   A302
*E*      MESSAGE: DONT SIMULATE THAT TRAP
*E*      DESCRIPTION:
*E*               AN ATTEMPT WAS MADE TO SIMULATE A TRAP NOT IN
*E*               THE RANGE OF X'40'-X'45' OR X'48'-X'4B'
         PAGE
MSTRAP   EQU      %
         LW,R1    J:TCB             TCB ADDRESS
         LW,14    =X'020000A3'      ERROR IF ILLEGAL TRAP
         LW,1     0,1
         LW,1     0,1
         CI,R1    X'40'
         BL       T:ABORTM
         CI,R1    X'45'
         BG       CHKMORE                                               759
ALLOK    EQU      %                                                     759
         LW,1     0,1
         LI,6     MSTRAPXIT         RETURN TO MSTRAPXIT
         B        TMPTOSTK
CHKMORE  EQU      %                                                     759
         CI,R1    X'48'                                                 759
         BL       T:ABORTM
         CI,R1    X'4B'                                                 759
         BG       T:ABORTM
         B        ALLOK                                                 759
         PAGE
*F*      NAME:    MXCON
         SPACE    1
*F*      PURPOSE:
*F*               TO PROCESS THE M:XCON SERVICE CALL
         SPACE    1
*F*      DESCRIPTION:
*F*               THE EXIT CONTROL ADDRESS MAY BE SPECIFIED,
*F*               MODIFIED, OR RESET VIA THIS SERVICE CALL
         SPACE    5
*D*      NAME:    MXCON
         SPACE    1
*D*      REGISTERS:
*D*               R6 IS NOT MODIFIED
*D*               ALL OTHER REGISTERS ARE NOT SAVED
         SPACE    1
*D*      CALL:
*D*               SEE REPORT P
         SPACE    1
*D*      ENVIRONMENT:
*D*               MAPPED,MASTER MODE, NO INHIBITS
         SPACE    1
*D*      INPUT:
*D*               R6 CONTAINS WORD 0 OF THE FPT (ONLY WORD)
*D*               FORMAT BIT 8 = 1 INDICATES LAST SPECIFIED
*D*                      BITS 15-31 = NEXT EXIT CONTROL ADDRESS OR 0
         SPACE    1
*D*      OUTPUT:
*D*               USERS REGISTER 8 IN THE TSTACK CONTAINS THE
*D*               PREVIOUS EXIT CONTROL ADDRESS AND J:EXTENT
*D*               CONTAINS THE NEW ADDRESS AND CURRENT SETTING OF
*D*               THE LAST BIT FROM THE FPT - UNLESS A LAST HAS
*D*               HAS BEEN PREVIOUSLY AND THE USER IS NOT IN
*D*               AN EXIT CONTROL IN PROGRESS SITUATION
*D*               ALSO IF A COMMAND PROCESSOR IS REQUESTING EXIT CONTROL
*D*               THEN THE BIT IN J:EXTENT IS ALSO SET INDICATING
*D*               THIS (Y1 BIT)
         SPACE    1
*D*      DESCRIPTION:
*D*               UPON ENTRY THE PREVIOUS EXIT CONTRO ADDRESS IS FETCHED
*D*               FROM J:EXTENT AND STORED IN THE USERS R8 IN THE TSTACK
*D*               IF THE Y2 BIT OF J:EXTENT IS SET INDICATING
*D*               EXIT CONTROL IN PROGRESS THEN THE NEW ADDRESS
*D*               OR 0 IS STORED UNCONDITIONALLY IN J:EXTENT ALONG
*D*               WITH BIT 8  (LAST BIT) FROM THE FPT
*D*               OTHERWISE A TEST IS MADE OF THE Y008 BIT TO SEE
*D*               IF LAST HAS BEEN PREVIOUSLY SPECIFIED.
*D*               IF SO, THEN AN EXIT IS MADE TO CC1SET TO EFFECT A
*D*               RETURN TO CAL+1 WITH CC1
*D*               IF NOT, THE STORE IS DONE AND UH:FLG (TIC) IS CHECKED
*D*               TO SEE IF EXIT CONTROL IS BEING REQUESTED
*D*               BY A COMMAND PROCESSOR WHICH WILL
*D*               CAUSE THE Y1 BIT OF J:EXTENT TO BE SET AND EXIT MADE
*D*               THROUGH CC0RST TO EFFECT A RETURN TO THE CAL+1
*D*               WITH CC1 RESET
         PAGE
MXCON    EQU      %
         LI,R2    0
         LI,R3    X'1FFFF'
         LS,R2    J:EXTENT
         LI,R1    -7
         STW,R2   *TSTACK,R1
         LW,R1    J:EXTENT
         CW,R1    Y2                SEE IF CAN REPLACE J:EXTENT
         BANZ     REPLACE           YES;EXIT CON IN PROGRESS
         LW,R1    J:EXTENT
         CW,R1    Y008              SEE IF LAST PREV.SPEC.
         BANZ     CC1SET            YES;RTN TO CAL+1 WITH CC1 SET
*  M:XCON 0,LAST AND M:XCON 0   SHOULD BE DIFFERENTIATED
REPLACE  EQU      %
         LW,R7    Y008
         OR,R7    M17               PRODUCE X'0081FFFF'
         STS,R6   J:EXTENT
*  IF C.P. ASKING FOR EXIT CONTROL, REMEMBER IT
* OTHERWISE NO ACTION
         LB,R7    J:EXTENT
         LW,R1    S:CUN
         LH,R2    UH:FLG,R1
         CI,R2    TIC
         BAZ      NTIC
         LI,R2    X'10'
         OR,R2    R7
         B        %+3
NTIC     LI,R2    X'EF'
         AND,R2   R7
         STB,R2   J:EXTENT
         B        CC0RST            CLEAR CC BEFORE RTN TO CAL+1
         PAGE
*F*      NAME:    MINT
         SPACE    1
*F*      PURPOSE:
*F*               TO PROCESS AN M:INT SERVICE CALL
         SPACE    1
*F*      DESCRIPTION:
*F*               MINT PROCESS THE FPT FOR THE M:INT CALL
*F*               AND SETS THE ADDRESS INTO J:INTENT AS WELL AS FLAGS
*F*               APPROPRIATE TO THE ISSURER OF THE CALL
         SPACE    1
*F*      REFERENCE:
*F*               SEE REPORT D
         SPACE    5
*D*      NAME:    MINT
         SPACE    1
*D*      REGISTERS:
*D*               USES R1,R3,R4,R6,R11,R14
*D*               NONE ARE SAVED
         SPACE    1
*D*      ENVIRONMENT:
*D*               MAPPED,MASTER INHIBITS ONLY IF AND WHEN
*D*               NEED TO SET X'4000' BIT IN UH:FLG2
         SPACE    1
*D*      INPUT:
*D*               R6 CONTAINS WORD0 OF THE FPT (ONLY WORD)
*D*               FORMAT  BIT 8 - COMMAND PROCESSOR ISSUING
*D*               BREAK CONTROL BUT NOT WANTING BREAK CONTROL TO
*D*               BE SET IN UH:FLG2
*D*               BITS 15-31 BREAK CONTROL ADDRESS
         SPACE    1
*D*      OUTPUT:
*D*               J:INTENT ADDRESS OF INT HANDLER (BITS 15-31)
*D*                        BIT 1 SET UNLESS NO ADDRESS SPECIFIED IN FPT
*D*               UH:FLG2 - X'4000' BIT SET TO INDICATE
*D*                         CP BREAK CONTROL IF TIC SET IN UH:FLG
*D*                         AND BIT 8 OF FPT NOT SET
         SPACE    1
*D*      DESCRIPTION:
*D*               UPON ENTRY THE ADDRESS IS OBTAINED FROM THE FPT
*D*               1. IF NON ZERO THEN THE Y8 BIT IS SET AND UH:FLG (TIC)
*D*                  IS EXAMINED.
*D*               2. IF A COMMAND PROCESSOR IS IS CONTROL,BIT 8 OF
*D*                  FPT IS EXAMINED TO SEE IF THE COMMAND PROCESSOR
*D*                   BREAK BIT IN UH:FLG2 IS TO BE SET
*D*                   THUS A CP CAN SUBSTITUTE ITS BREAK CONTROL
*D*                   ADDRESS FOR A USER SUPPLIED ONE & CAUSE THE USER'S
*D*                   TO BE LATER REPLACED WITHOUT THE CP BREAK CONTROL
*D*                   FLAG BEING SET
*D*               3. IN ALL CASES AFTER THESE CHECKS ARE MADE THE VALUE
*D*                   IS STORED IN J:INTENT AND J:TCB TESTED
*D*                   IF ZERO THEN THE ADDRESS IN USERS R0 IN THE TSTACK
*D*                   IS STORED IN J:TCB
*D*               4. A DESTRUCT EXIT IS THEN MADE
         PAGE
MINT     LW,1     6
         AND,6    M17
         BEZ      INT05
         OR,6     Y8
         LW,4     S:CUN
         LH,3     UH:FLG,4
         CI,3     TIC
         BANZ     INT30
INT05    STW,6    J:INTENT
         LW,6     J:TCB             DOES HE HAVE A TCB
         BNEZ     INT20
         LW,6     TSTACK+5          USE USER R0 IS
         STW,6    J:TCB             TCB ADDRESS
INT20    DESTRUCT
*
INT30    CW,1     Y008
         BANZ     INT05             DONT SET CP'S BRK CONTROL
         DISABLE
         LH,3     UH:FLG2,4
         OR,3     X4000             SET CP BREAK BIT
         STH,3    UH:FLG2,4
         ENABLE
         B        INT05
         PAGE
*F*      NAME:    MSTIMER
*F*      PURPOSE: TO PROCESS THE M:STIMER SERVICE CALL.
*F*      DESCRIPTION: MSTIMER STORES TIMEOUT ADDRESS IN J:TIMENT AND
*F*               TIMEOUT INTERVAL INTO J:UTIMER FROM AN M:STIMER FPT.
*F*      REFERENCE: SEE CP-V/BP REF MANUAL AND REPORT D.
*D*      NAME:    MSTIMER
*D*      REGISTERS: ALL VOLATILE.
*D*      CALL:    OVERLAY MISOVSEG,MSTIMER#
*D*      ENVIRONMENT: MASTER MAPPED.
*D*      INPUT:   R6= FPT WORD 0 BITS 8-31.
*D*                   BITS 13-14=UNIT (0 MINUTES, 1 SECONDS, 2 TICS)
*D*                   BITS 15-31=TIMEOUT ROUTINE ADDRESS.
*D*               R7=>WORD 1 OF FPT (INTERVAL SPECIFIED).
*D*               R11=RETURN ADDRESS.
*D*      OUTPUT:  J:TIMENT= ADDRESS OF ROUTINE; SIGNBIT=1 FOR ACTIVE.
*D*               J:UTIMER= TIME INTERVAL IN TICS (1/500 SECOND).
*D*      DESCRIPTION: THE ROUTINE ADDRESS PLUS SIGN BIT IS STORED IN
*D*               J:TIMENT, AND THE INTERVAL IS CONVERTED TO TICS
*D*               AND STORED INTO J:UTIMER.
MSTIMER  EQU      %
         LI,R1    X'1FFFF'
         AND,R1   R6                R1 = TIMEOUT ROUTINE ADDRESS
         OR,R1    Y8                     WITH SIGN BIT SET.
         SLS,R6   -17
         AND,R6   M2                R6 = TYPE OF UNIT OF INTERVAL.
         LW,D2    0,R7              D2 = TIME INTERVAL.
         MW,D2    MPLRS,R6          D2 = TIME INTERVAL IN TICS.
         AW,D2    J:OVHTIM            FUDGE IT UP BY MONITOR TIME
         AW,D2    J:DELTAT            AND BY TIME USED IN CURRENT
         SW,D2    J:IDELTAT           PARTIAL QUANTUM.
         STW,D2   J:UTIMER            STORE TIME INTERVAL.
         STW,R1   J:TIMENT            STORE USER ROUTINE ADDRESS.
         DESTRUCT                   ---> EXIT.
         PAGE
*F*      NAME:    MTTIMER
*F*      PURPOSE: TO PROCESS THE M:TTIMER SERVICE CALL.
*F*      DESCRIPTION: MTTIMER PROCESSES THE FPT FOR THE TEST TIMER
*F*               CALL, COMPUTING REMAINING TIME INTO USER'S SR1(R8)
*F*               AND CANCELING CURRENT M:STIMER IF REQUESTED.
*F*      REFERENCE: SEE CP-V/BP REF MANUAL AND REPORT D.
*D*      NAME:    MTTIMER
*D*      REGISTERS: ALL MAY BE USED. (1,4,6,13 CURRENTLY USED).
*D*      CALL:    OVERLAY MISOVSEG,MTTIMER#
*D*      ENVIRONMENT: MASTER MAPPED.
*D*      INPUT:   R6= WORD 0 BITS 8-31 OF FPT.
*D*                   BIT 23 SET MEANS 'CANCEL'.
*D*                   BITS 30-31=UNIT (0 MINUTES, 1 SECONDS, 2 TICS).
*D*               R11=RETURN ADDRESS.
*D*               J:UTIMER,J:DELTAT,J:IDELTAT HOLD TIME INTERVALS.
*D*               J:TIMENT SAYS WHETHER M:STIMER IN PROGRESS.
*D*               TOP 16 WORDS OF STACK ARE USER'S REGISTERS.
*D*      OUTPUT:  J:TIMENT=0 IF 'CANCEL' SPECIFIED.
*D*               USER SR1 (R8) = INTERVAL LEFT IN UNITS SPECIFIED.
*D*      DESCRIPTION: IF 'CANCEL' WAS SPECIFIED, J:TIMENT IS ZEROED.
*D*               TIME REMAINING IN CURRENT M:STIMER INTERVAL IS --
*D*               ZERO IF J:TIMENT BIT 0 WAS OFF (NO M:STIMER GOING)
*D*               J:UTIMER+J:DELTAT-J:IDELTAT OTHERWISE.
*D*               THIS IS CONVERTED TO USER-SPECIFIED UNITS AND
*D*               RETURNED IN USER'S SR1 (R8).
MTTIMER  EQU      %
         LI,D2    0                 D2 = TIMELEFT (0 IF NO M:STIMER)
         LW,R1    J:TIMENT
         CI,R6    X'100'              WAS 'CANCEL' SPECIFIED...
         BAZ      %+2               --->NO.
         LI,R1    0                   YES, CANCEL M:STIMER IF ANY.
         XW,R1    J:TIMENT          R1 = M:TTIMER-IN-PROGRESS FLAG.
         BGEZ     MTTIMER3          ---> NO M:TTIMER, RETURN 0.
         LW,D2    J:UTIMER          D2 = TIME LEFT IN M:TTIMER
         SW,D2    J:OVHTIM               INTERVAL. REDUCE TO REFLECT
         SW,D2    J:DELTAT               MONITOR TIME AND TIME USED
         AW,D2    J:IDELTAT              IN CURRENT QUANTUM.
         AND,R6   M2                R6 = UNITS DESIRED.
         DW,D2    MPLRS,R6          D2 = TIME LEFT IN PROPER UNIITS.
MTTIMER3 LI,R7    SR1-15              (POINT TO USER'S SR1)
         STW,D2   *TSTACK,R7          REPORT TIME LEFT TO USER SR1.
         DESTRUCT                   --->EXIT.
MPLRS    DATA     500               (0) SECONDS   500 TICS/SECOND.
         DATA     500*60            (1) MINUTES   500 TICS/SECOND.
         DATA     1                 (2) TICS
         DATA     1                 (3) UNDEFINED; TICS FOR NOW.
         END

