         DEF      CLOCK4:           PATCHING DEF
CLOCK4:  RES
*        704754   SIGMA 5/7         BPM M:CLOCKI
         SYSTEM   UTS
         DEF      CLOCKI
         DEF      1SEC:EP
CLOCKI   EQU      %
*
*
*                   FOLLOWING FUNCTIONS:
*                        1. UPDATE TIME AND DATE
*                        2. DECREMENT MRT EVERY MINUTE
*                        3. INCREMENT CEXT EVERY 1/100 MINUTE.
*                   CLOCK RESOLUTION = 4 KILOCYCLES
*
*                                   PROGRAMMERS - D. HEYING, P. HEINRICH
*
*                 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
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
D1       EQU      12
D2       EQU      13
D4       EQU      15
*
         PAGE
*
*                 DEFS AND REFS FOR OBJECT MODULE.
*
*                 DEFS.
*
         DEF      HALFSEC
*
         REF      T:SAVE
         REF      C:TIC
         REF      E:WU,SW,SB:HQ,UB:FL
         REF      T:RUE,U:MISC
         REF      TINC,TIME,DATE
         REF      YFA,M16
         REF      T:COCHC
         REF      T:SSEC
         REF      T:SYSTEMLOAD
         REF      Y04
         REF      S:MBSF
         REF      1MIN
         REF      S:EVF
         REF      S:SEVF
         REF      IOCLINC
         REF      IOCLOCK
         REF      CTRIG
         REF      CLK3PSD
         REF      OCWRITE           PRINT TEXTC ON OC
         REF      DCT25             DEVICE SIO COUNTER
         REF      TEMPT
         REF      CLOCKTMP
         REF      RTICBCLKHDR
         REF      C:CTUN
         REF      M17,Y1,Y004
         REF      CSED%RTRY%CNT
         REF      ENBSR4            RETURN ON R11 ENABLED
         SREF     UINTQ
         SREF     RPWPCLK           ENTRY POINT FOR DELAYED RPWP
         PAGE
*                 IMMEDIATE CONSTANTS USED BY MONITOR.
K1       EQU      1
KA       EQU      10
KF       EQU      15
KF0      EQU      X'F0'
KF1      EQU      X'F1'
KF6      EQU      X'F6'
K1F3     EQU      X'1F3'
K2F4     EQU      X'2F4'
KF000    EQU      X'F000'
KF0F0    EQU      X'F0F0'
KF0F1    EQU      X'F0F1'
KF6F0    EQU      X'F6F0'
*
*                                   ICB TABLE DEFINITIONS USED
ICBUN    EQU      28                BYTE DISPLACEMENT
ICBCLK   EQU      2                 WORD DISPLACEMENT
ICBLNK   EQU      0                 WORD DISPLACEMENT
ICBSTAT  EQU      0                 WORD DISPLACEMENT
ICBBLNK  EQU      4                 WORD DISPLACEMENT
ICBSYSEP EQU      3                 WORD DISPLACEMENT
ICBTUN   EQU      1                 WORD DISPLACEMENT
STATO    EQU      Y1                'ONESHOT' BIT MASK
STATSY   EQU      Y004
*
1SEC     EQU      600               MAX. TIMER UNITS (IE., 1.2 SEC.)
*
         PAGE
*
*                 AT THIS POINT WE ARE USING REG BLOCK 0
*                   AND ARE UNMAPPED.
*
*                                   CC SET TO 6 BY INT PSD
         PSM,13   TSTACK            SAVE 13,14,15,0,1,2
         LD,0     CLK3PSD           GET PSD
         BAL,2    T:SAVE            SAVE STANDARD ENV
*
         LI,14    X'80'
         WD,14    X'1300'
*
CK0      RES      0
         LW,2     RTICBCLKHDR       PICK UP FIRST ICB ON CHAIN
         BEZ      CK:SCREECH1       ERROR IF THERE ARE NONE
         LI,3     1SEC              1.2 SECOND MAXIMUM INTERVAL
CK1      LCW,10   C:CTUN            CURRENT TIMER-UNITS
         AWM,10   ICBCLK,2          DECREMENT ICBCLK
         BLZ      CK:SCREECH2       ERROR IF ICBCLK GOES NEGATIVE
         LW,8     ICBCLK,2          HAS IT GONE TO ZERO?
         BEZ      CKZERO            YES
CK7      CW,8     3                 IS REMAINDER < PREVIOUS MIN. VALUE?
         BGE      CK2               NO
         LW,3     8                 NEW MINIMUM VALUE
CK2      LW,2     ICBLNK,2          PICK UP FORWARD LINK
         AND,2    M17               IS THERE ONE?
         BNEZ     CK1               YES
         LW,8     C:CTUN            CURRENT TIMER-UNITS
         AWM,8    C:TIC             ADD IT TO TOTAL TICS SINCE STARTUP
         AWM,8    C:MSM             ADD IT TO TICS SINCE MIDNIGHT
         STW,3    C:CTUN            NEW MINIMUM VALUE
         AWM,3    TINC              ADD IT TO TINC (E.A. OF CLOCK3)
*
*                 IF COUNTER REACHED 0 WHILE SYSTEM WAS IN DISABLED
*                 CODE, THE COUNTER WILL GO NEGATIVE;     WE KEEP ADDING
*                 THE NEW C:CTUN VALUE AND GOING THROUGH CLOCK CODE
*                 UNTIL THERE IS A POSITIVE # OF CLOCK PULSES TO GO
*                 BEFORE THE NEXT CLOCK INTERRUPT.
*
         BLEZ     CK0
         LI,13    X'80'
         WD,13    X'1400'           ENABLE CLOCK3
         B        T:SSEC
         PAGE
CKZERO   EQU      %                 ICBCLK=0 PROCESSING ROUINE
         STD,2    CLOCKTMP          SAVE CRITICAL REGS (2 & 3)
         LW,8     ICBSTAT,2
         CW,8     STATSY            IS THIS A SYSTEM ICB?
         BAZ      CK3               NO
         LW,12    ICBSYSEP,2        PICK UP SYSTEM ENTRY POINT
         BAL,11   *12               EXECUTE SYSTEM CODE
         B        CK4               THAT'S ALL FOR A SYSTEM ICB
CK3      ;
         LW,1     2                 PASS ICB ADR. TO UINTQ
         DISABLE                    **************************************
         BAL,11   UINTQ             REPORT EVENT & BUILD DO-LIST ENTRY
*                                   RETURN 'ENABLED'
CK4      LD,2     CLOCKTMP          RESTORE CRITICAL REGS (2 & 3)
         LW,7     ICBSTAT,2         PICK UP ICBSTAT
         CW,7     STATO             ONESHOT BIT SET?
         BAZ      CK6               NO
         LW,5     M17
         LI,6     ICBLNK
         LI,7     ICBBLNK
         DISABLE                    **********************************
         LW,4     *2,6              PICK UP FORWARD LINK IN CURRENT ICB
         AND,4    M17               MASK ADR. FIELD
         LW,8     *2,7              PICK UP BACK LINK IN CURRENT ICB
         BEZ      CK:SCREECH3       IMPOSSIBLE SITUATION
         STS,4    *8,6              NEW FORWARD LINK FOR THIS GUY
         LW,4     4                 IS THERE A FORWARD LINK?
         BEZ      CK5               NO: MUST BE LAST GUY IN THE CHAIN
         STW,8    *4,7              NEW BACK-LINK FOR THIS GUY
         B        CK6
CK5      STW,8    RTICBCLKHDR+1     NEW CHAIN TAIL
CK6      ENABLE                     **********************************
         LW,8     ICBTUN,2          PICK UP INITIALIZATION VALUE
         STW,8    ICBCLK,2          RESET CLOCK IN ICB
         B        CK7
         PAGE
CK:SCREECH1   EQU %
         SCREECH  X'43',1           NO ACTIVE ICB'S
CK:SCREECH2   EQU %
         SCREECH  X'43',2           ICBCLK WENT NEGATIVE
CK:SCREECH3   EQU %
         SCREECH  X'43',3           TRYING TO FREE ICBSYS1 (CLOCK3)
         PAGE
1SEC:EP  EQU      %
*
*
*
*                                   THIS IS THE EFFECTIVE ADDRESS OF THE
*                                   ICBSYSEP FIELD OF THE SYSTEM ICB
*                                   ASSOCIATED WITH CLOCK3 (COUNTER
*                                   EQUALS ZERO) PROCESSING.  THIS
*                                   ROUTINE IS ENTERED EVERY 1.2 SECONDS
*                                   ON A 'BAL,11'.  THE CRITICAL REG-
*                                   ISTERS HAVE BEEN PRESERVED BY THE
*                                   CALLING ROUTINE.  ALL THAT NEED BE
*                                   PRESERVED IS THE RETURN ADR. IN 11.
*
         PUSH     11
*
         BAL,1    T:WAKEUP          WAKE ITEM UP
         REF      ERRLOG5,C:MSM,C:TINC,ERRLOG
         BAL,5    ERRLOG5           FLUSH THE ERRORLOG BUFFERS
         LI,5     3                 CAUSES 3 RETRIES ....
         STW,5    CSED%RTRY%CNT     ...OF HARDWARE FAULTS
         MTW,+1   S:SEVF            PERMIT SWAP SCHEDULE IF PREVIOUS
*                                   FAILURE
*
*  GO TO COC TO CHECK FOR LINES THAT SHOULD BE INITIALIZED OR THAT
*  SHOULD BE TIMED OUT
*  ASSUME THAT T:COCHC DESTROYS ALL REGISTERS
*
         BAL,R11  T:COCHC
*
*  THIS CODE SMOOTHS PAGE STEALER PEAKS
         REF      S:STLC,INCSTL
         DISABLE
         LW,3     S:STLC
         BLZ      %+2
         BAL,11   INCSTL
         ENABLE
         LI,11    CK23              SET RETURN IF RPWPCLK CALLED
         LI,8     RPWPCLK           DETERMINE IF IT EXISTS
         BNEZ     *8                IF SO, GO THERE
CK23     EQU      %
         SREF     H%AKTIM           TIMING DELAY ON IDLE
         LI,11    CK25              HASP LINES - CALL IT
         LI,8     H%AKTIM           .7 SECONDS AVERAGE
         BNEZ     *8                ALL REGS ARE ZAPPED
CK25     EQU      %
*
*   I/O TIME-OUT CLOCK ROUTINE
*
*        CELL 'IOCLOCK' IS INCREMENTED EVERY 4.8 SECS.
*
         MTW,-1   IOCLINC           DEC PULSE COUNTER
         BNEZ     CK28              NOT 4.8 SECS YET
*
*        KEEP REMOTE BATCH SYMBIONTS BUSY
         SREF     RBSS
         LI,14    CK26             RETURN ADDRESS
          LI,8     RBSS             RBSS     WONT BE DEFFED IF
         BNEZ     *8               SYSTEM ISNT REMOTE BATCH
CK26     EQU       %
*
         LW,11    C:TINC            CHECK FOR CATCH UP MODE
         AI,11    1SEC              ARE WE MUCH BEHIND
         BLZ      %+2               YES SKIP I/O TIME CLOCK
         MTW,1    IOCLOCK           INC I/O TIME-OUT CLOCK
         DEF      HOTCARD:
         REF      SNDDX,RBLIMS,DCT4,DCT1,SSIG,SAQNSERT
HOTCARD: B        CK27A             BYPASS AUTO CARD READER
         LI,8     4                 DEVICE TYPE = CR
         LB,3     SNDDX
CK26A    LB,6     SNDDX,3
         BEZ      CK27
         CLM,6    RBLIMS
         BCR,9    CK27
         CB,8    DCT4,6
         BNE      CK27
         LH,7     DCT1,6            DEVICE ADDR OF CR
         TIO,4    *7
         BCS,12   CK27              SKIP IF BUSY
         CW,5     Y1                DEVICE AUTOMATCC
         BAZ      CK27              SKIP IF CR MANUAL
         LB,1     SSIG,3
         BNEZ     CK27
         LI,1     'I'               INITIATE CR
         STB,1    SSIG,3
         BAL,11   SAQNSERT
CK27     BDR,3    CK26A             CHECK MORE CARD READERS
CK27A    EQU      %
         LI,14    4
         STW,14   IOCLINC           RESET PULSE COUNTER
         LW,8     Y04
         BAL,11   CTRIG
*
*
*
*        T:BTSCHED MOVED TO MODULE COOP.
*                 TO ALLOW THE MONITOR TO FLOAT IN SIZE
*               ABOVE THE .8000 BOUNDARY IMPLIED BY THE
*               NEED TO HAVE MAPPED SERVICE ROUTINES EXIST
*               1-TO-1 WITH THE USER, ALL MAPPED SERVICE
*               ROUTINES NOW EXIST IN TOTALLY MAPPED SERVICE
*               MODULES,AND UNMAPPED(INTURRUPT) ROUTINES
*               EXIST IN SEPERATE MODULES THAT ARE
*               LOCCT'ED TO THE ROOT TOP AND MAY EXTEND
*               BEYOND .8000 .
*
*
         REF      T:BTSCHED         BATCH SCHEDULE ROUTINE
*
         LI,14    0                 *CLEAR MBS FLAG AND
         XW,14    S:MBSF            * SEE IF BATCH SCHEDULE NECCESSARY
         BEZ      CK28              *..NOT NEEDED
         BAL,11   T:BTSCHED         * CHECK MORE THEN SCHEDULE MAYBE
*
CK28     EQU      %
         MTW,-1   1MIN              1MINUTE ELAPSED
         BGZ      CK30              BRANCH IF NO
*
         LI,14    50
         STW,14   1MIN              RESTORE MINUTE COUNTER
*
         BAL,R11  DATESTIME         UPDATE TIME AND DATE
PFRQ     SET      1
         DO       PFRQ
         MTW,-1   S:PFNI            DECREMENT  SHARED PROC NORMALIZATION CTR
         BGEZ     CK29              NOT RUN OUT YET
         LW,0     SL:PFNI           REFRESH
         STW,0    S:PFNI            COUNTER VALUE
         LI,3     PPROCS            NUMBER OF SHARED PROCS
         LH,0     PH:FRQ,3          GET FREQUENCY
         SLS,0    -1                DIVIDE BY 2
         STH,0    PH:FRQ,3          REPLACE
         BDR,3    %-3               CONTINUE FOR ALL PROCS
CK29     RES      0
         REF      SL:PFNI,S:PFNI,PPROCS,PH:FRQ
         FIN      PFRQ
*
*
         BAL,11   T:SYSTEMLOAD
*
CK30     EQU      %
         PULL     11
         B        *11               RETURN TO ICB-PROCESSING ROUTING
         PAGE
*
DATESTIME EQU     %
*                 1 MINUTE PASSED. UPDATE TIME AND DATE.
         INT,R2   TIME
         AI,R3    K1
         CB,R3    YFA
         BNE      CLK2
*                 INCREMENT MINUTES TO MULT. OF 10.
         AI,R3    KF6
         CI,R3    KF6F0
         BNE      CLK2
*                 HOUR EXPIRED, UPDATE
         MTW,-1   DCT25             FORCE TIME PRINTOUT ON HOUR
         LI,R3    KF0F0
         AI,R2    K1
         CB,R2    YFA
         BNE      CLK3
         AI,R2    KF6
CLK3     CI,R2    K2F4
         BNE      CLK2
*
*        AT END OF DAY RESET ERROR LOGGING TIME COUNTERS
*
         LI,14    0                 ZAP C:MSM
         STW,14   C:MSM             SO'S ERRLOG GETS CORRECT NEW TIME
*
*
*
         LI,R2    KF0
         INT,D1   DATE
         LW,D4    D1
         SLS,D4   -8
         MI,D4    KA
         LI,R4    KF
         AND,R4   D1
         AW,R4    D4
         LH,D4    MNTB1,R4
         AND,D4   M16
         AI,D2    K1
         CB,D2    YFA
         BNE      CLK4
         AI,D2    KF6
CLK4     CW,D2    D4
         BLE      CLK5
*                 MONTH GONE, UPDATE IT
         LI,D2    KF0F1
         AI,D1    K1
         CB,D1    YFA
         BNE      CLK6
         AI,D1    KF6
CLK6     CI,D1    K1F3
         BNE      CLK5
*                 END OF YEAR, UPDATE
         LI,D1    KF1
         MTW,1    DATE+1
*                 PUT AWAY MONTH AND DAY
CLK5     AI,D1    KF000
         STH,D1   D2
         STW,D2   DATE
*                 PUT AWAY TIME.
CLK2     AI,R2    KF000
         CI,3     '59'              HOUR ABOUT TO TICK OVER
         BNE      NOTHOUR           NO
         LI,13    X'2303'           ON THE HOUR
         STH,13   3                 CREATE ERROR LOG MSG
         LI,6     3                 LOC OF MSG
         BAL,5    ERRLOG            INJECT TIME STAMP INTO LOG
NOTHOUR  EQU      %
         STH,R2   R3
         STW,R3   TIME
*        OUTPUT TIME OF DAY ON OC EVERY MINUTE
         LI,R2    X'0715'           SET COUNT AND NEW-LINE
         SLD,2    16                MERGE WITH HH
         AI,R3    X'157A'           ADD FOLLOWING NEW-LINE AND ':'
         SCS,R3   -8                SEPARATE HH:MM WITH ':'
         STD,R2   TEMPT             SAVE IN TEMPT
         LW,R1    DCT25+1           GET ACTIVITY CNT FOR OC
         XW,R1    DCT25             SAVE AND GET OLD VALUE
         CW,R1    DCT25+1           COMPARE OLD AND NEW
         BE       *R11              SAME VALUE, DONT PRINT TIME
         MTW,1    DCT25             BUMP REMEMBERED VAL FOR TIME OUTPUT
         LI,R7    0                 SET FLAG FOR OCWRITE
         LI,R1    TEMPT             ADDRESS OF MESSAGE
         B        OCWRITE           PRINT TIME ON OC
         PAGE
*        THIS ROUTINE IS INVOKED BY THE CLOCK3 ROUTINE, SO  CLOCK IS
*        DISABLED I.E. THE CODE IS NON-REENTVANT
*
T:WAKEUP EQU      %
         LI,7     SW                SLEEP STATE NUMBER
         LI,6     X'7FFFF'           (MASK FOR CHECKING SLEEP-DONE)
         DISABLE                                 **** INHIBIT ****
         LB,5     SB:HQ,7           GET HEAD OF SLEEP Q AGAIN
         BEZ      0,1               THEY ALL DISAPPEARED
WAKE15   MTW,-1   U:MISC,5          DECREMENT SLEEP INTERVAL REMAINING
         CW,6     U:MISC,5          IS INTERVAL USED UP...
         BANZ     %+2               ---> NO.
         LI,7     0                 CLEAR FLAG
         LB,5     UB:FL,5           FLINK FORWARD
         BNE      WAKE15            AND CONTINUE
         ENABLE                                  **** UNINHIBIT ****
         PUSH     1                 SAVE RETURN REGISTER
         BDR,7    WAKE26            TEST REPORT NEED FLAG
WAKE20   LW,13    S:EVF             GET EVENT FLAG
         LI,7     SW                SLEEP STATE NUMBER
         LB,5     SB:HQ,7           GET HEAD OF SLEEP Q
         BEZ      WAKE26            NONE LEFT
WAKE22   DISABLE                                     **** INHIBIT ****
         CW,13    S:EVF             CHECK FOR ANY STATE Q ACTIVITY
         BNE      WAKE20            YES RECYCLE
         LB,7     UB:FL,5           SAVE FLINK TO NEXT USER
         LW,1     U:MISC,5          TEST CLOCK FOR RUNOUT
         CI,1     X'7FFFF'          CHECK FOR NON-ZERO
         BANZ     WAKE25            NOT YET
         LI,6     E:WU              WAKEUP EVENT CODE
         BAL,11   T:RUE             REPORT WAKEUP TO SCHEDULER
*                                                  **** UNINHIBIT ****
         AI,13    2                 BUMP EVENT COUNTER BY 2 IF REPORT
WAKE25   LW,5     7                 GET FLINK
         BNE      WAKE22            AND CONTINUE IF ANY LEFT
WAKE26   RES      0
*
         REF      SGB
         REF      E:SYMD
         REF      R:SYMD
         REF      SB:RQ
         PULL     11
         MTW,0    SGB               CHECK FOR SYMBIONT GRANS AVAIL
         BEZ      ENBSR4            NO
         LI,6     E:SYMD            SYMBIONT DISC AVAIL EVENT
         LI,5     R:SYMD            RESOURCE INDEX
         LB,5     SB:RQ,5           GET HEAD OF SUB-QUEUE
         BEZ      ENBSR4            NONE
         B        T:RUE             WADE INTO T:RUE
         PAGE
*
HALFSEC  EQU      10
*
MNTB1    DATA,2   0,'31','28','31','30','31','30','31','31','30','31'
         DATA,2   '30','31'
         BOUND    4
CLOCKISZ EQU      %-CLOCKI
         END

