         DEF      PFSR:
PFSR:    EQU      %
         SYSTEM UTS
*****CAT.NO. 704596***********
* POWER ON-OFF INTERRUPT ROUTINES
         DEF      BEGINOFF,BEGINON
         DEF      WAIT
         DEF      PFSRIO
         REF      Y05,CTRIG,IOCTQ
         SREF     PFSRARM,PFSRTRIG,PFSRENAB,MONORG
*
         REF      POWROFF,POWROFF2
         REF      DCTSIZ,DCT1,DCT4
         REF      Y004,DCT13,HGP,TB:FLGS,RESTRTIO,FORCEIO
         REF      COCINIT
         REF      LMA
         REF      T:XMMC
         REF      S:CUN
         REF      RCVPSD
         REF      SREGS,SREGS1,PFSRSW
         REF      RT:PWOFF,RT:PWON
         REF      BALANCE
         REF      TINC,J:DELTAT,XPSD46,OFFCNTER,ONCNTER
         DEF      PFSR46
*
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
TY       EQU      1
*
RP0      EQU      POWROFF2+3
RP1      EQU      POWROFF+3
*
*
PFSR46   LPSD,1   TIOPSD            CLEAR PDF
TIOPSD   :PSD     (IA,TIOLOOP),INH
DELAYPSD :PSD     (IA,DELAY),INH
         PAGE
BEGINOFF EQU      %                 SAVE REGS
         STM,R0   SREGS1            SAVE REGISTER BLOCK ONE
         MTW,1    BALANCE
* JUST SAVED RP=1, NOW SAVE RP=0
         LRP      RP0
         LCI      0
         STM,R0   SREGS             SAVE REGISTER BLOCK ZERO
         MTW,4    X'51'             MODIFY POWROFF XPSD
         RD,0     0                 READ THE SENSE SWITCHES
         STCF     R1
         STW,R1   PFSRSW            SAVE SENSE SWITCH SETTINGS ON 560
*
*
         BIF,S7   SIG7A             DO NOT SAVE INTERRUPTS ON SIG7
         LI,R2    MONORG-X'52'+X'F' NUMBER OF INTERRUPT CELLS
         SLS,R2   -4                BOUND UP TO A FULL GROUP OF INTERRUPTS
         CI,R2    1                 ONLY GROUP ZERO
         BE       KRD4              YES
KRD1     RD,R1    X'1100',R2        READ ARMED FLIP-FLOP
         STH,R1   PFSRARM,R2        SAVE IN HALF WORD TABLE
         RD,R1    X'1200',R2        READ TRIGGER FLIP-FLOP
         STH,R1   PFSRTRIG,R2       SAVE
         RD,R1    X'1400',R2        READ ENABLE/DISABLE FLIP-FLOP
         STH,R1   PFSRENAB,R2       SAVE
         CI,R2    2                 SAVED GROUP TWO
         BNE      %+3               NO
KRD4     LI,R2    0                 YES-THERE IS NO GROUP ONE
         B        KRD1              SAVE GROUP ZERO
         BDR,R2   KRD1              SAVE ALL GROUPS BELOW MONORG
SIG7A    EQU      %
*
*
         LI,R7    X'FFF0'
         WD,R7    X'1100'           DISARM,DISABLE GROUP 0 INTS.
         LI,R7    DCTSIZ            HALT ALL I/O
MORE     LH,R2    DCT1,R7
         HIO,0    *R2
         TDV,R4   *R2               GET TDV STATUS
         STCF     R4                SAVE CC FROM TDV
         OR,R5    Y004              SET DATA TRANSMISION ERROR
         STD,R4   DCT13,R7          INTO DCT13
NOTBUSY  BDR,R7   MORE
         BAL,11   RT:PWOFF          USER-SUPPLIED REAL-TIME ROUTINE
WAIT     MTW,1    OFFCNTER          COUNT THIS OFF INTERRUPT
         WAIT                       WAIT HERE FOR POWER ON INT.
         B        %-1
*
*
*
BEGINON  EQU      %
         MTW,1    ONCNTER           COUNT THIS ON INTERRUPT
         MTW,0    BALANCE           OFF ENVIR. PRESENT
         BNEZ     BEGINON5          YES
         LW,R1    OFFCNTER          NO-PUT COUNTERS IN REGS
         LW,R2    ONCNTER
         SCREECH  X'30'             UNBLNCD POWON AND POWOFF
BEGINON5 EQU      %
         LI,R1    100
         BDR,R1   %                 DELAY ABOUT 100 MICRO SEC
*
*
         LI,R1    X'38F0'           GROUP ZERO MASK FOR SIG7
         BIF,S7   SIG7B             DO RESTORE INTERRUPTS ON SIG7
         LI,R6    MONORG-X'52'      NUMBER OF INTERRUPT CELL
         LI,R7    0
         SLD,R6   -4                NUMBER OF GROUPS
         SCS,R7   4                 IS THERE A PARTIAL GROUP
         BNOV     %+2               NO
         AI,R6    1                 YES-BOUND UP NUMBER OF GROUPS
         CI,R6    1                 ONLY GROUP ZERO
         BE       KRD5              YES
         LI,R1    X'FFFF'           MASK FOR INTERRUPT CELLS IN A GROUP
         LCW,R7   R7
         SLS,R1   16,R7             SHIFT MASK FOR SYSGENED CELLS
KRD2     WD,R1    X'1100',R6        DISARM EVERY CELL
         WD,R1    X'1400',R6        ENABLE EVERY CELL
         LH,R2    PFSRARM,R6
         AND,R2   R1                ARM FLIP-FLOP
         LH,R3    PFSRTRIG,R6
         AND,R3   R1                TRIGGER FLIP-FLOP
         OR,R2    R3                CELLS THAT MUST BE AEMED
         WD,R2    X'1200',R6        ARM AND ENABLE
         WD,R3    X'1700',R6        TRIGGER
         LH,R2    PFSRARM,R6        ARM FLIP-FLOP
         EOR,R2   R1                FLIP THE BIT
         AND,R2   R3                ADVANCE TO ACTIVE ONLY THESE CELLS
         WD,R2    X'1000',R6        SET ACTIVE
         LH,R4    PFSRENAB,R6       ENABLE/DISABLE FLIP-FLOP
         AND,R4   R1
         WD,R4    X'1600',R6        ENABLE/DISABLE
         LI,R1    X'FFFF'           MASK FOR ALL CELLS IN AGROUP
         CI,R6    2                 JUST SET GROUP TWO
         BNE      KRD3              NO
KRD5     LI,R6    0                 NO GROUP ONE
         LI,R1    X'FFF0'           MASK FOR GROUP ZERO
         B        KRD2              RESTORE GROUP ZERO
KRD3     BDR,R6   KRD2              RESTORE ALL GROUPS
         B        %+2
SIG7B    EQU      %
         WD,R1    X'1200'           ARM AND ENABLE GROPU ZERO
         LI,R0    100
         STW,R0   TINC
         STW,R0   J:DELTAT          PUT INITIAL VALUE INTO CLOCKS
*                                   WHILE POWER ON INT HIGH
         LPSD,3   DELAYPSD          CLEAR POWER ON INT
DELAY    LI,R1    X'7FFFF'
         BDR,R1   %                 DELAY FOR THINGS TO QUIET DOWN
         LW,R1    XPSD46
         XW,R1    X'46'             INTERCEPT TRAP 46
         STW,R1   XPSD46
*
TIOLOOP  AIO,0    0
         BCR,8    %-1               ACKNOWLEDGE ALL INTERRUPTS
         LI,R6    HGP               START OF ROTATING DEVICES
PFSR1    LW,R5    1,R6
         CI,R5    X'4000'           PRIVATE ROTATING DEVICE
         BANZ     PFSR2             YES-MAY NOT BE THERE
         LH,R5    R5                DCTX OF PUBLIC ROTATING DEVICE
         LH,R5    DCT1,R5           ADDRESS OF PUBLIC ROTATING DEVICE
         TIO,0    *R5
         BCS,X'C' %-1               DELAY UNTILL DEVICE BACK UP
PFSR2    LW,R6    *R6
         BNEZ     PFSR1             FLINK TO NEXT ROTAING DEVICE
*
*
         LW,R1    XPSD46
         XW,R1    X'46'
         STW,R1   XPSD46            RESTORE TRAP 46
         LW,R1    PFSRSW            SENSE SWITCH SETTINGS FOR 560
         WD,R1    0                 SET SENSE SWITCHES ON 560
         LW,SR1   Y05               TRIGGER CONTROL TASK NUMBER 5
         LH,R1    IOCTQ+1           SPACE COUNT CONTROL TASK STACK
         CI,R1    X'7FFF'           ANY SPACE
         BANZ     %+2               YES-CTRIG CAN PUSH TASK NO.
         PLW,R0   IOCTQ             MAKE ROOM FOR PFSR ENTRY
         BAL,SR4  CTRIG             RESTART DEVICES AFTER PFSR
         BAL,11   RT:PWON           USER-SUPPLIED REAL-TIME ROUTINE
         BAL,11   LMA               LOAD LOCKS MAP AND ACCESS
         LW,4     S:CUN             CURRENT USER #
         BAL,11   T:XMMC            LOAD MAP ACCESS FOR USER
         LI,R1    0
         STW,R1   BALANCE           CLEAR
         STW,R1   OFFCNTER                ALL
         STW,R1   ONCNTER                     COUNTERS
*
*
*
*
         BAL,11   COCINIT           INITIALIZE COC
         LCI      0
         LM,R0    SREGS             RESTORE REGISTER BLOCK ZERO
*JUST PULLED RP=0 FOR SYS OR USR, NOW GET RP=1 FOR COC
         LRP      RP1
         LCI      0
         LM,R0    SREGS1            RESTORE REGISTER BLOCK ONE
         MTW,-4   X'51'             RESET POWROFF XPSD
         LPSD,8   POWROFF           RETURN
         PAGE
*                                   CONTROL TASK FOR PFSR
*                                   TO RESTART I/O
PFSRIO   EQU      %
         PUSH     SR4
         LI,R1    DCTSIZ
PFSR3    CI,R1    TY                TY DCTX
         BE       PFSR4             YES-RESTART IT
         LB,R2    DCT4,R1           TYPE CODE
         LB,R2    TB:FLGS,R2        FLAGS FOR DEVICE TYPE
         CI,R2    X'C0'             ROTATING DEVICE
         BL       PFSR5             NO
PFSR4    PUSH     R1
         BAL,SR4  RESTRTIO          YES-GO SEE IF BUSY
         BAL,R2   FORCEIO           IF BUSY RE-START IO
         PULL     R1
PFSR5    BDR,R1   PFSR3             CYCLE THROUGH DCTS
         PULL     SR4
         B        *SR4              RETURN
         END

